error_code.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package ctrl_v1
  2. import (
  3. "gd_management_gateway/errors"
  4. "gd_management_gateway/params/param_base"
  5. "gd_management_gateway/params/param_v1_0"
  6. "gd_management_gateway/rpc_apis"
  7. "gd_management_gateway/rpc_apis/gd_management"
  8. "fmt"
  9. "time"
  10. "gd_management_gateway/common.in/httper"
  11. "gd_management_gateway/common.in/task"
  12. "gd_management_gateway/common.in/utils"
  13. "go.uber.org/zap"
  14. "github.com/astaxie/beego"
  15. )
  16. // Operations about error code
  17. type ErrorController struct {
  18. metadata interface{} // 中继元数据
  19. beego.Controller
  20. LogID string
  21. }
  22. // @Title add error code
  23. // @Description 添加错误码
  24. // @Param token header string true "token"
  25. // @Param uid header string true "管理员id"
  26. // @Param code query string true "错误码"
  27. // @Param msg query string true "错误消息"
  28. // @Success 200 {object} params.param_v1_0.ManagementAddErrorResp "响应信息"
  29. // @Failure 500 服务器错误
  30. // @router /error_code [post]
  31. func (u *ErrorController) ManagementAddError() {
  32. u.LogID = fmt.Sprintf("ManagementAddError[%d]", time.Now().UnixNano())
  33. req := &param_v1_0.ManagementAddErrorReq{}
  34. getParamsTask := func() error {
  35. httper.FillRequireParams(u.Ctx, req, u.LogID)
  36. return nil
  37. }
  38. handleDataTask := func() error {
  39. mreq := gd_management.ManagementAddErrorReq{}
  40. mreq.Code = req.Code
  41. mreq.Msg = req.Msg
  42. reply, err := rpc_apis.Management.ManagementAddError(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  43. if err != nil {
  44. l.Error("rpc",
  45. zap.String("call", "ManagementAddError"),
  46. zap.String("args", utils.MarshalJsonString(req)),
  47. zap.String("error", err.Error()))
  48. return errors.ErrorTransform(err)
  49. }
  50. resp := param_v1_0.ManagementAddErrorResp{
  51. SimpleResp: param_base.SimpleResp{
  52. Code: 0,
  53. Msg: "SUCCESS",
  54. },
  55. }
  56. resp.Data = reply
  57. httper.JSON(u.Ctx, resp, u.LogID)
  58. SetErrorCodeMap()
  59. return nil
  60. }
  61. // 执行以上定义的任务
  62. task.Do(&task.PanicRecover{
  63. Ctx: u.Ctx,
  64. LogID: u.LogID}, u.Ctx,
  65. getParamsTask, handleDataTask,
  66. )
  67. }
  68. // @Title del error code
  69. // @Description 删除错误码
  70. // @Param token header string true "token"
  71. // @Param uid header string true "管理员id"
  72. // @Param id query int true "错误码id"
  73. // @Success 200 {object} params.param_v1_0.ManagementDelErrorResp "响应信息"
  74. // @Failure 500 服务器错误
  75. // @router /error_code [delete]
  76. func (u *ErrorController) ManagementDelError() {
  77. u.LogID = fmt.Sprintf("ManagementDelError[%d]", time.Now().UnixNano())
  78. req := &param_v1_0.ManagementDelErrorReq{}
  79. getParamsTask := func() error {
  80. httper.FillRequireParams(u.Ctx, req, u.LogID)
  81. fmt.Printf("del request:%v\n", req)
  82. return nil
  83. }
  84. handleDataTask := func() error {
  85. mreq := gd_management.ManagementDelErrorReq{}
  86. mreq.Id = req.Id
  87. _, err := rpc_apis.Management.ManagementDelError(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  88. if err != nil {
  89. l.Error("rpc",
  90. zap.String("call", "ManagementDelError"),
  91. zap.String("args", utils.MarshalJsonString(req)),
  92. zap.String("error", err.Error()))
  93. return errors.ErrorTransform(err)
  94. }
  95. resp := param_v1_0.ManagementDelErrorResp{
  96. SimpleResp: param_base.SimpleResp{
  97. Code: 0,
  98. Msg: "SUCCESS",
  99. },
  100. }
  101. httper.JSON(u.Ctx, resp, u.LogID)
  102. SetErrorCodeMap()
  103. return nil
  104. }
  105. // 执行以上定义的任务
  106. task.Do(&task.PanicRecover{
  107. Ctx: u.Ctx,
  108. LogID: u.LogID}, u.Ctx,
  109. getParamsTask, handleDataTask,
  110. )
  111. }
  112. // @Title update error code
  113. // @Description 修改错误码
  114. // @Param token header string true "token"
  115. // @Param uid header string true "管理员id"
  116. // @Param id query int true "错误码id"
  117. // @Param code query string true "错误码"
  118. // @Param msg query string true "错误消息"
  119. // @Success 200 {object} params.param_v1_0.ManagementUpdateErrorResp "响应信息"
  120. // @Failure 500 服务器错误
  121. // @router /error_code [put]
  122. func (u *ErrorController) ManagementUpdateError() {
  123. u.LogID = fmt.Sprintf("ManagementUpdateError[%d]", time.Now().UnixNano())
  124. req := &param_v1_0.ManagementUpdateErrorReq{}
  125. getParamsTask := func() error {
  126. httper.FillRequireParams(u.Ctx, req, u.LogID)
  127. return nil
  128. }
  129. handleDataTask := func() error {
  130. mreq := gd_management.ManagementUpdateErrorReq{}
  131. mreq.Code = req.Code
  132. mreq.Msg = req.Msg
  133. mreq.Id = req.Id
  134. _, err := rpc_apis.Management.ManagementUpdateError(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  135. if err != nil {
  136. l.Error("rpc",
  137. zap.String("call", "ManagementUpdateError"),
  138. zap.String("args", utils.MarshalJsonString(req)),
  139. zap.String("error", err.Error()))
  140. return errors.ErrorTransform(err)
  141. }
  142. resp := param_v1_0.ManagementUpdateErrorResp{
  143. SimpleResp: param_base.SimpleResp{
  144. Code: 0,
  145. Msg: "SUCCESS",
  146. },
  147. }
  148. httper.JSON(u.Ctx, resp, u.LogID)
  149. SetErrorCodeMap()
  150. return nil
  151. }
  152. // 执行以上定义的任务
  153. task.Do(&task.PanicRecover{
  154. Ctx: u.Ctx,
  155. LogID: u.LogID}, u.Ctx,
  156. getParamsTask, handleDataTask,
  157. )
  158. }
  159. // @Title get error code list
  160. // @Description 获取错误码列表
  161. // @Param token header string true "token"
  162. // @Param uid header string true "管理员id"
  163. // @Param page_number query int true "当前页"
  164. // @Param is_all query bool false "是否全量返回"
  165. // @Success 200 {object} params.param_v1_0.ManagementGetErrorListResp "响应信息"
  166. // @Failure 500 服务器错误
  167. // @router /error_code_list [get]
  168. func (u *ErrorController) ManagementGetErrorList() {
  169. u.LogID = fmt.Sprintf("ManagementGetErrorList[%d]", time.Now().UnixNano())
  170. req := &param_v1_0.ManagementGetErrorListReq{}
  171. getParamsTask := func() error {
  172. httper.FillRequireParams(u.Ctx, req, u.LogID)
  173. return nil
  174. }
  175. handleDataTask := func() error {
  176. mreq := gd_management.ManagementGetErrorListReq{}
  177. mreq.PageNumber = req.PageNumber
  178. mreq.IsAll = req.IsAll
  179. reply, err := rpc_apis.Management.ManagementGetErrorList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  180. if err != nil {
  181. l.Error("rpc",
  182. zap.String("call", "ManagementGetErrorList"),
  183. zap.String("args", utils.MarshalJsonString(req)),
  184. zap.String("error", err.Error()))
  185. return errors.ErrorTransform(err)
  186. }
  187. resp := param_v1_0.ManagementGetErrorListResp{
  188. SimpleResp: param_base.SimpleResp{
  189. Code: 0,
  190. Msg: "SUCCESS",
  191. },
  192. }
  193. resp.Data = reply
  194. httper.JSON(u.Ctx, resp, u.LogID)
  195. return nil
  196. }
  197. // 执行以上定义的任务
  198. task.Do(&task.PanicRecover{
  199. Ctx: u.Ctx,
  200. LogID: u.LogID}, u.Ctx,
  201. getParamsTask, handleDataTask,
  202. )
  203. }