正在显示
9 个修改的文件
包含
141 行增加
和
20 行删除
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + | ||
| 6 | + "github.com/beego/beego/v2/core/validation" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type OperateCooperationModeCommand struct { | ||
| 11 | + //操作人 | ||
| 12 | + Operator domain.Operator `json:"-"` | ||
| 13 | + // 共创模式ID | ||
| 14 | + CooperationModeId string `json:"cooperationModeId" valid:"Required"` | ||
| 15 | + // 共创模式状态,1启用,2禁用 | ||
| 16 | + Status int `json:"status" valid:"Required"` | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (updateCooperationModeCommand *OperateCooperationModeCommand) Valid(validation *validation.Validation) { | ||
| 20 | + | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +func (updateCooperationModeCommand *OperateCooperationModeCommand) ValidateCommand() error { | ||
| 24 | + valid := validation.Validation{} | ||
| 25 | + b, err := valid.Valid(updateCooperationModeCommand) | ||
| 26 | + if err != nil { | ||
| 27 | + return err | ||
| 28 | + } | ||
| 29 | + if !b { | ||
| 30 | + for _, validErr := range valid.Errors { | ||
| 31 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | + return nil | ||
| 35 | +} |
| @@ -76,7 +76,7 @@ func (cooperationModeService *CooperationModeService) ListCooperationMode(listCo | @@ -76,7 +76,7 @@ func (cooperationModeService *CooperationModeService) ListCooperationMode(listCo | ||
| 76 | return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 76 | return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 77 | } | 77 | } |
| 78 | var ( | 78 | var ( |
| 79 | - listData []dto.CooperationModeItem | 79 | + listData = make([]dto.CooperationModeItem, 0) |
| 80 | item dto.CooperationModeItem | 80 | item dto.CooperationModeItem |
| 81 | ) | 81 | ) |
| 82 | for _, v := range result.List { | 82 | for _, v := range result.List { |
| @@ -127,11 +127,18 @@ func (cooperationModeService *CooperationModeService) UpdateCooperationMode(upda | @@ -127,11 +127,18 @@ func (cooperationModeService *CooperationModeService) UpdateCooperationMode(upda | ||
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | // EnableCooperationMode 禁用启用共创模式 | 129 | // EnableCooperationMode 禁用启用共创模式 |
| 130 | -func (cooperationModeService *CooperationModeService) EnableCooperationMode(updateCooperationModeCommand *command.UpdateCooperationModeCommand) (interface{}, error) { | 130 | +func (cooperationModeService *CooperationModeService) EnableCooperationMode(updateCooperationModeCommand *command.OperateCooperationModeCommand) (interface{}, error) { |
| 131 | if err := updateCooperationModeCommand.ValidateCommand(); err != nil { | 131 | if err := updateCooperationModeCommand.ValidateCommand(); err != nil { |
| 132 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 132 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 133 | } | 133 | } |
| 134 | - //TODO gateway 待补充 | 134 | + creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(updateCooperationModeCommand.Operator) |
| 135 | + _, err := creationCooperationGateway.CooperationModeOperate(allied_creation_cooperation.ReqOperateCooperationMode{ | ||
| 136 | + CooperationModeId: updateCooperationModeCommand.CooperationModeId, | ||
| 137 | + Status: updateCooperationModeCommand.Status, | ||
| 138 | + }) | ||
| 139 | + if err != nil { | ||
| 140 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 141 | + } | ||
| 135 | return nil, nil | 142 | return nil, nil |
| 136 | } | 143 | } |
| 137 | 144 |
| @@ -105,7 +105,7 @@ func (gateway HttplibAlliedCreationCooperation) CooperationModeGet(param ReqCoop | @@ -105,7 +105,7 @@ func (gateway HttplibAlliedCreationCooperation) CooperationModeGet(param ReqCoop | ||
| 105 | 105 | ||
| 106 | // CooperationModeUpdate 更新共创模式 | 106 | // CooperationModeUpdate 更新共创模式 |
| 107 | func (gateway HttplibAlliedCreationCooperation) CooperationModeUpdate(param ReqCooperationModeUpdate) (*DataCooperationModeUpdate, error) { | 107 | func (gateway HttplibAlliedCreationCooperation) CooperationModeUpdate(param ReqCooperationModeUpdate) (*DataCooperationModeUpdate, error) { |
| 108 | - url := gateway.baseUrL + "/cooperation-modes" + strconv.Itoa(param.CooperationModeId) | 108 | + url := gateway.baseUrL + "/cooperation-modes/" + strconv.Itoa(param.CooperationModeId) |
| 109 | method := "put" | 109 | method := "put" |
| 110 | req := gateway.CreateRequest(url, method) | 110 | req := gateway.CreateRequest(url, method) |
| 111 | log.Logger.Debug("向业务模块请求数据:更新共创模式。", map[string]interface{}{ | 111 | log.Logger.Debug("向业务模块请求数据:更新共创模式。", map[string]interface{}{ |
| @@ -226,3 +226,34 @@ func (gateway HttplibAlliedCreationCooperation) CooperationModeBatchRemove(param | @@ -226,3 +226,34 @@ func (gateway HttplibAlliedCreationCooperation) CooperationModeBatchRemove(param | ||
| 226 | err = gateway.GetResponseData(result, &data) | 226 | err = gateway.GetResponseData(result, &data) |
| 227 | return &data, err | 227 | return &data, err |
| 228 | } | 228 | } |
| 229 | + | ||
| 230 | +// CooperationModeUpdate 更新共创模式 | ||
| 231 | +func (gateway HttplibAlliedCreationCooperation) CooperationModeOperate(param ReqOperateCooperationMode) (*DataOperateCooperationMode, error) { | ||
| 232 | + url := gateway.baseUrL + "/cooperation-modes/operate" | ||
| 233 | + method := "post" | ||
| 234 | + req := gateway.CreateRequest(url, method) | ||
| 235 | + log.Logger.Debug("向业务模块请求数据:启用或禁用共创模式。", map[string]interface{}{ | ||
| 236 | + "api": method + ":" + url, | ||
| 237 | + "param": param, | ||
| 238 | + }) | ||
| 239 | + req, err := req.JSONBody(param) | ||
| 240 | + if err != nil { | ||
| 241 | + return nil, fmt.Errorf("请求启用或禁用共创模式失败:%w", err) | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + byteResult, err := req.Bytes() | ||
| 245 | + if err != nil { | ||
| 246 | + return nil, fmt.Errorf("获取启用或禁用共创模式失败:%w", err) | ||
| 247 | + } | ||
| 248 | + log.Logger.Debug("获取业务模块请求数据:启用或禁用共创模式。", map[string]interface{}{ | ||
| 249 | + "result": string(byteResult), | ||
| 250 | + }) | ||
| 251 | + var result service_gateway.GatewayResponse | ||
| 252 | + err = json.Unmarshal(byteResult, &result) | ||
| 253 | + if err != nil { | ||
| 254 | + return nil, fmt.Errorf("解析启用或禁用共创模式:%w", err) | ||
| 255 | + } | ||
| 256 | + var data DataOperateCooperationMode | ||
| 257 | + err = gateway.GetResponseData(result, &data) | ||
| 258 | + return &data, err | ||
| 259 | +} |
| @@ -188,3 +188,16 @@ type ( | @@ -188,3 +188,16 @@ type ( | ||
| 188 | } `json:"list"` | 188 | } `json:"list"` |
| 189 | } | 189 | } |
| 190 | ) | 190 | ) |
| 191 | + | ||
| 192 | +//更新共创模式 | ||
| 193 | +type ( | ||
| 194 | + ReqOperateCooperationMode struct { | ||
| 195 | + // 共创模式ID | ||
| 196 | + CooperationModeId string `cname:"共创模式id" json:"cooperationModeId" valid:"Required"` | ||
| 197 | + // 共创模式状态,1启用,2禁用 | ||
| 198 | + Status int `cname:"状态" json:"status" valid:"Required"` | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + DataOperateCooperationMode struct { | ||
| 202 | + } | ||
| 203 | +) |
| @@ -53,6 +53,13 @@ func (controller *baseController) GetOperator() domain.Operator { | @@ -53,6 +53,13 @@ func (controller *baseController) GetOperator() domain.Operator { | ||
| 53 | Phone: loginToken.Account, | 53 | Phone: loginToken.Account, |
| 54 | Token: token, | 54 | Token: token, |
| 55 | } | 55 | } |
| 56 | + // TODO:测试数据后期删除 | ||
| 57 | + if op.UserId == 0 { | ||
| 58 | + op.UserId = 9 | ||
| 59 | + op.CompanyId = 23 | ||
| 60 | + op.OrgId = 45 | ||
| 61 | + op.UserBaseId = 5 | ||
| 62 | + } | ||
| 56 | // TODO:打印测试日志 | 63 | // TODO:打印测试日志 |
| 57 | log.Logger.Debug("operator " + json.MarshalToString(op)) | 64 | log.Logger.Debug("operator " + json.MarshalToString(op)) |
| 58 | return op | 65 | return op |
| @@ -3,6 +3,7 @@ package web_client | @@ -3,6 +3,7 @@ package web_client | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/linmadan/egglib-go/web/beego" | 4 | "github.com/linmadan/egglib-go/web/beego" |
| 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" |
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" | ||
| 6 | ) | 7 | ) |
| 7 | 8 | ||
| 8 | type baseController struct { | 9 | type baseController struct { |
| @@ -20,18 +21,26 @@ func (controller *baseController) returnPageListData(count int64, data interface | @@ -20,18 +21,26 @@ func (controller *baseController) returnPageListData(count int64, data interface | ||
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | func (controller *baseController) GetOperator() domain.Operator { | 23 | func (controller *baseController) GetOperator() domain.Operator { |
| 23 | - | ||
| 24 | - // tk, _ := middleware.FormCtxLoginToken(controller.Ctx) | ||
| 25 | - // operator := domain.Operator{ | ||
| 26 | - // UserId: tk.UserId, | ||
| 27 | - // CompanyId: tk.CompanyId, | ||
| 28 | - // OrgId: tk.OrgId, | ||
| 29 | - // UserBaseId: tk.UserBaseId, | ||
| 30 | - // } | ||
| 31 | - return domain.Operator{ | ||
| 32 | - UserId: 9, | ||
| 33 | - CompanyId: 23, | ||
| 34 | - OrgId: 45, | ||
| 35 | - UserBaseId: 1, | 24 | + token := controller.Ctx.Input.Header("X-Mmm-Accesstoken") |
| 25 | + loginToken := &domain.LoginToken{} | ||
| 26 | + err := loginToken.ParseToken(token) | ||
| 27 | + if err != nil { | ||
| 28 | + log.Logger.Error(err.Error()) | ||
| 29 | + } | ||
| 30 | + op := domain.Operator{ | ||
| 31 | + UserId: loginToken.UserId, | ||
| 32 | + CompanyId: loginToken.CompanyId, | ||
| 33 | + OrgId: loginToken.OrgId, | ||
| 34 | + UserBaseId: loginToken.UserBaseId, | ||
| 35 | + Phone: loginToken.Account, | ||
| 36 | + Token: token, | ||
| 37 | + } | ||
| 38 | + // TODO:测试数据后期删除 | ||
| 39 | + if op.UserId == 0 { | ||
| 40 | + op.UserId = 9 | ||
| 41 | + op.CompanyId = 23 | ||
| 42 | + op.OrgId = 45 | ||
| 43 | + op.UserBaseId = 5 | ||
| 36 | } | 44 | } |
| 45 | + return op | ||
| 37 | } | 46 | } |
| @@ -80,6 +80,21 @@ func (controller *CooperationModeController) ListCooperationMode() { | @@ -80,6 +80,21 @@ func (controller *CooperationModeController) ListCooperationMode() { | ||
| 80 | log.Logger.Debug("json err:" + err.Error()) | 80 | log.Logger.Debug("json err:" + err.Error()) |
| 81 | } | 81 | } |
| 82 | listCooperationModeQuery.Operator = controller.GetOperator() | 82 | listCooperationModeQuery.Operator = controller.GetOperator() |
| 83 | - cnt, data, err := cooperationModeService.ListCooperationMode(listCooperationModeQuery) | ||
| 84 | - controller.returnPageListData(cnt, data, err, listCooperationModeQuery.PageNumber) | 83 | + listCooperationModeQuery.PageNumber = 1 |
| 84 | + listCooperationModeQuery.PageSize = 999 | ||
| 85 | + _, data, err := cooperationModeService.ListCooperationMode(listCooperationModeQuery) | ||
| 86 | + controller.Response(data, err) | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +func (controller *CooperationModeController) EnableCooperationMode() { | ||
| 90 | + cooperationModeService := service.NewCooperationModeService(nil) | ||
| 91 | + removeCooperationModeCommand := &command.OperateCooperationModeCommand{} | ||
| 92 | + err := controller.Unmarshal(removeCooperationModeCommand) | ||
| 93 | + if err != nil { | ||
| 94 | + log.Logger.Debug("json err:" + err.Error()) | ||
| 95 | + } | ||
| 96 | + removeCooperationModeCommand.Operator = controller.GetOperator() | ||
| 97 | + | ||
| 98 | + data, err := cooperationModeService.EnableCooperationMode(removeCooperationModeCommand) | ||
| 99 | + controller.Response(data, err) | ||
| 85 | } | 100 | } |
| @@ -3,6 +3,7 @@ package routers | @@ -3,6 +3,7 @@ package routers | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/beego/beego/v2/server/web" | 4 | "github.com/beego/beego/v2/server/web" |
| 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client" |
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client" | ||
| 6 | ) | 7 | ) |
| 7 | 8 | ||
| 8 | // router | 9 | // router |
| @@ -30,6 +31,7 @@ func init() { | @@ -30,6 +31,7 @@ func init() { | ||
| 30 | web.Router("/v1/app/cooperation-projects/:projectId", &mobile_client.CooperationController{}, "Put:UpdateCooperationProject") | 31 | web.Router("/v1/app/cooperation-projects/:projectId", &mobile_client.CooperationController{}, "Put:UpdateCooperationProject") |
| 31 | web.Router("/v1/app/cooperation-projects/end", &mobile_client.CooperationController{}, "Post:EndCooperationProject") | 32 | web.Router("/v1/app/cooperation-projects/end", &mobile_client.CooperationController{}, "Post:EndCooperationProject") |
| 32 | web.Router("/v1/app/cooperation-projects/search", &mobile_client.CooperationController{}, "Post:SearchCooperationProject") | 33 | web.Router("/v1/app/cooperation-projects/search", &mobile_client.CooperationController{}, "Post:SearchCooperationProject") |
| 34 | + web.Router("/v1/app/cooperation-modes/", &web_client.CooperationModeController{}, "Get:ListCooperationMode") | ||
| 33 | 35 | ||
| 34 | /***** CompanyDividends 账期结算 *****/ | 36 | /***** CompanyDividends 账期结算 *****/ |
| 35 | web.Router("/v1/app/company/credit-accounts/search", &mobile_client.CooperationController{}, "Post:CreditAccountSearch") | 37 | web.Router("/v1/app/company/credit-accounts/search", &mobile_client.CooperationController{}, "Post:CreditAccountSearch") |
| @@ -10,5 +10,7 @@ func init() { | @@ -10,5 +10,7 @@ func init() { | ||
| 10 | web.Router("/v1/web/cooperation-modes/:modeId", &web_client.CooperationModeController{}, "Put:UpdateCooperationMode") | 10 | web.Router("/v1/web/cooperation-modes/:modeId", &web_client.CooperationModeController{}, "Put:UpdateCooperationMode") |
| 11 | web.Router("/v1/web/cooperation-modes/:modeId", &web_client.CooperationModeController{}, "Get:GetCooperationMode") | 11 | web.Router("/v1/web/cooperation-modes/:modeId", &web_client.CooperationModeController{}, "Get:GetCooperationMode") |
| 12 | web.Router("/v1/web/cooperation-modes/remove", &web_client.CooperationModeController{}, "Post:RemoveCooperationMode") | 12 | web.Router("/v1/web/cooperation-modes/remove", &web_client.CooperationModeController{}, "Post:RemoveCooperationMode") |
| 13 | - web.Router("/v1/web/cooperation-modes/search", &web_client.CooperationModeController{}, "Post:ListCooperationMode") | 13 | + web.Router("/v1/web/cooperation-modes/search", &web_client.CooperationModeController{}, "Post:SearchCooperationMode") |
| 14 | + web.Router("/v1/web/cooperation-modes/enable", &web_client.CooperationModeController{}, "Put:EnableCooperationMode") | ||
| 15 | + web.Router("/v1/web/cooperation-modes/", &web_client.CooperationModeController{}, "Get:ListCooperationMode") | ||
| 14 | } | 16 | } |
-
请 注册 或 登录 后发表评论