123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- package ctrl_v1
- import (
- "gd_management_gateway/errors"
- "gd_management_gateway/params/param_base"
- "gd_management_gateway/params/param_v1_0"
- "gd_management_gateway/rpc_apis"
- "gd_management_gateway/rpc_apis/gd_management"
- "fmt"
- "time"
- "gd_management_gateway/common.in/httper"
- "gd_management_gateway/common.in/task"
- "gd_management_gateway/common.in/utils"
- "go.uber.org/zap"
- "github.com/astaxie/beego"
- )
- // Operations about error code
- type ErrorController struct {
- metadata interface{} // 中继元数据
- beego.Controller
- LogID string
- }
- // @Title add error code
- // @Description 添加错误码
- // @Param token header string true "token"
- // @Param uid header string true "管理员id"
- // @Param code query string true "错误码"
- // @Param msg query string true "错误消息"
- // @Success 200 {object} params.param_v1_0.ManagementAddErrorResp "响应信息"
- // @Failure 500 服务器错误
- // @router /error_code [post]
- func (u *ErrorController) ManagementAddError() {
- u.LogID = fmt.Sprintf("ManagementAddError[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.ManagementAddErrorReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_management.ManagementAddErrorReq{}
- mreq.Code = req.Code
- mreq.Msg = req.Msg
- reply, err := rpc_apis.Management.ManagementAddError(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "ManagementAddError"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.ManagementAddErrorResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- resp.Data = reply
- httper.JSON(u.Ctx, resp, u.LogID)
- SetErrorCodeMap()
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleDataTask,
- )
- }
- // @Title del error code
- // @Description 删除错误码
- // @Param token header string true "token"
- // @Param uid header string true "管理员id"
- // @Param id query int true "错误码id"
- // @Success 200 {object} params.param_v1_0.ManagementDelErrorResp "响应信息"
- // @Failure 500 服务器错误
- // @router /error_code [delete]
- func (u *ErrorController) ManagementDelError() {
- u.LogID = fmt.Sprintf("ManagementDelError[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.ManagementDelErrorReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- fmt.Printf("del request:%v\n", req)
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_management.ManagementDelErrorReq{}
- mreq.Id = req.Id
- _, err := rpc_apis.Management.ManagementDelError(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "ManagementDelError"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.ManagementDelErrorResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- SetErrorCodeMap()
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleDataTask,
- )
- }
- // @Title update error code
- // @Description 修改错误码
- // @Param token header string true "token"
- // @Param uid header string true "管理员id"
- // @Param id query int true "错误码id"
- // @Param code query string true "错误码"
- // @Param msg query string true "错误消息"
- // @Success 200 {object} params.param_v1_0.ManagementUpdateErrorResp "响应信息"
- // @Failure 500 服务器错误
- // @router /error_code [put]
- func (u *ErrorController) ManagementUpdateError() {
- u.LogID = fmt.Sprintf("ManagementUpdateError[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.ManagementUpdateErrorReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_management.ManagementUpdateErrorReq{}
- mreq.Code = req.Code
- mreq.Msg = req.Msg
- mreq.Id = req.Id
- _, err := rpc_apis.Management.ManagementUpdateError(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "ManagementUpdateError"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.ManagementUpdateErrorResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- SetErrorCodeMap()
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleDataTask,
- )
- }
- // @Title get error code list
- // @Description 获取错误码列表
- // @Param token header string true "token"
- // @Param uid header string true "管理员id"
- // @Param page_number query int true "当前页"
- // @Param is_all query bool false "是否全量返回"
- // @Success 200 {object} params.param_v1_0.ManagementGetErrorListResp "响应信息"
- // @Failure 500 服务器错误
- // @router /error_code_list [get]
- func (u *ErrorController) ManagementGetErrorList() {
- u.LogID = fmt.Sprintf("ManagementGetErrorList[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.ManagementGetErrorListReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_management.ManagementGetErrorListReq{}
- mreq.PageNumber = req.PageNumber
- mreq.IsAll = req.IsAll
- reply, err := rpc_apis.Management.ManagementGetErrorList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "ManagementGetErrorList"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.ManagementGetErrorListResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- resp.Data = reply
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleDataTask,
- )
- }
|