123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- package v1_0
- import (
- "adm-gateway/errors"
- param_v1 "adm-gateway/param/v1"
- "adm-gateway/pb"
- v1 "adm-gateway/pb/v1"
- "net/http"
- "github.com/gin-gonic/gin"
- "git.getensh.com/common/gopkgsv2/logger"
- "git.getensh.com/common/gopkgsv2/tasker/httptasker"
- "git.getensh.com/common/gopkgsv2/util"
- "go.uber.org/zap"
- )
- // 字段管理表 t_adm_field_management
- // Field godoc
- // @Summary 字段管理
- // @Description 字段管理
- // @Tags field_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param field query string false "字段名"
- // @Param desc query string false "描述"
- // @Param page query int32 false "页码"
- // @Param page_size query int32 false "每页数量,默认10"
- // @Success 200 {object} param_v1.GetFieldListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/field [get]
- func (c *Controller) Field(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetFieldListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetFieldListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.GetFieldListResponse{}
- r := v1.FieldRequest{
- Field: req.Field,
- Desc: req.Desc,
- Page: req.Page,
- PageSize: req.PageSize,
- }
- reply, err := pb.Management.Field(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.Field"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.Field, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // Excel godoc
- // @Summary 导出EXCEL
- // @Description 导出EXCEL
- // @Tags field_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Success 200 {object} param_v1.ExcelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/field/excel [get]
- func (c *Controller) Excel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ExcelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.ExcelQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.ExcelResponse{}
- r := v1.ExcelRequest{}
- reply, err := pb.Management.Excel(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.Excel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|