field_management.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package v1_0
  2. import (
  3. "adm-gateway/errors"
  4. param_v1 "adm-gateway/param/v1"
  5. "adm-gateway/pb"
  6. v1 "adm-gateway/pb/v1"
  7. "net/http"
  8. "github.com/gin-gonic/gin"
  9. "git.getensh.com/common/gopkgsv2/logger"
  10. "git.getensh.com/common/gopkgsv2/tasker/httptasker"
  11. "git.getensh.com/common/gopkgsv2/util"
  12. "go.uber.org/zap"
  13. )
  14. // 字段管理表 t_adm_field_management
  15. // Field godoc
  16. // @Summary 字段管理
  17. // @Description 字段管理
  18. // @Tags field_management,v1.0
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "jwt token"
  22. // @Param field query string false "字段名"
  23. // @Param desc query string false "描述"
  24. // @Param page query int32 false "页码"
  25. // @Param page_size query int32 false "每页数量,默认10"
  26. // @Success 200 {object} param_v1.GetFieldListResponse
  27. // @Failure 500 {object} base.HTTPError
  28. // @Router /api/v1.0/field [get]
  29. func (c *Controller) Field(ctx *gin.Context) {
  30. // 解析参数
  31. req := &param_v1.GetFieldListRequest{}
  32. parseParamTask := func() error {
  33. err := util.ShouldBind(ctx, nil, nil, &req.GetFieldListQuery, nil)
  34. if err != nil {
  35. logger.Error("func",
  36. zap.String("call", "util.ShouldBind"),
  37. zap.String("error", err.Error()))
  38. return errors.ParamsError
  39. }
  40. return nil
  41. }
  42. // 业务处理
  43. handleServiceTask := func() error {
  44. // 响应数据
  45. resp := &param_v1.GetFieldListResponse{}
  46. r := v1.FieldRequest{
  47. Field: req.Field,
  48. Desc: req.Desc,
  49. Page: req.Page,
  50. PageSize: req.PageSize,
  51. }
  52. reply, err := pb.Management.Field(ctx.Request.Context(), &r)
  53. if err != nil {
  54. s, _ := json.MarshalToString(r)
  55. logger.Error("func",
  56. zap.String("call", "pb.management.Field"),
  57. zap.String("params", s),
  58. zap.String("error", err.Error()))
  59. return errors.ErrorTransForm(err)
  60. }
  61. if reply.List == nil {
  62. reply.List = make([]*v1.Field, 0)
  63. }
  64. resp.Data = reply
  65. ctx.JSON(http.StatusOK, resp)
  66. return nil
  67. }
  68. // 执行任务
  69. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  70. }
  71. // Excel godoc
  72. // @Summary 导出EXCEL
  73. // @Description 导出EXCEL
  74. // @Tags field_management,v1.0
  75. // @Accept json
  76. // @Produce json
  77. // @Param token header string true "jwt token"
  78. // @Success 200 {object} param_v1.ExcelResponse
  79. // @Failure 500 {object} base.HTTPError
  80. // @Router /api/v1.0/field/excel [get]
  81. func (c *Controller) Excel(ctx *gin.Context) {
  82. // 解析参数
  83. req := &param_v1.ExcelRequest{}
  84. parseParamTask := func() error {
  85. err := util.ShouldBind(ctx, nil, nil, &req.ExcelQuery, nil)
  86. if err != nil {
  87. logger.Error("func",
  88. zap.String("call", "util.ShouldBind"),
  89. zap.String("error", err.Error()))
  90. return errors.ParamsError
  91. }
  92. return nil
  93. }
  94. // 业务处理
  95. handleServiceTask := func() error {
  96. // 响应数据
  97. resp := &param_v1.ExcelResponse{}
  98. r := v1.ExcelRequest{}
  99. reply, err := pb.Management.Excel(ctx.Request.Context(), &r)
  100. if err != nil {
  101. s, _ := json.MarshalToString(r)
  102. logger.Error("func",
  103. zap.String("call", "pb.management.Excel"),
  104. zap.String("params", s),
  105. zap.String("error", err.Error()))
  106. return errors.ErrorTransForm(err)
  107. }
  108. resp.Data = reply
  109. ctx.JSON(http.StatusOK, resp)
  110. return nil
  111. }
  112. // 执行任务
  113. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  114. }