作者 tangxuhui
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type OperateCooperationModeCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 共创模式ID
CooperationModeId string `json:"cooperationModeId" valid:"Required"`
// 共创模式状态,1启用,2禁用
Status int `json:"status" valid:"Required"`
}
func (updateCooperationModeCommand *OperateCooperationModeCommand) Valid(validation *validation.Validation) {
}
func (updateCooperationModeCommand *OperateCooperationModeCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCooperationModeCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -76,7 +76,7 @@ func (cooperationModeService *CooperationModeService) ListCooperationMode(listCo
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var (
listData []dto.CooperationModeItem
listData = make([]dto.CooperationModeItem, 0)
item dto.CooperationModeItem
)
for _, v := range result.List {
... ... @@ -127,11 +127,18 @@ func (cooperationModeService *CooperationModeService) UpdateCooperationMode(upda
}
// EnableCooperationMode 禁用启用共创模式
func (cooperationModeService *CooperationModeService) EnableCooperationMode(updateCooperationModeCommand *command.UpdateCooperationModeCommand) (interface{}, error) {
func (cooperationModeService *CooperationModeService) EnableCooperationMode(updateCooperationModeCommand *command.OperateCooperationModeCommand) (interface{}, error) {
if err := updateCooperationModeCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
//TODO gateway 待补充
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(updateCooperationModeCommand.Operator)
_, err := creationCooperationGateway.CooperationModeOperate(allied_creation_cooperation.ReqOperateCooperationMode{
CooperationModeId: updateCooperationModeCommand.CooperationModeId,
Status: updateCooperationModeCommand.Status,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return nil, nil
}
... ...
... ... @@ -105,7 +105,7 @@ func (gateway HttplibAlliedCreationCooperation) CooperationModeGet(param ReqCoop
// CooperationModeUpdate 更新共创模式
func (gateway HttplibAlliedCreationCooperation) CooperationModeUpdate(param ReqCooperationModeUpdate) (*DataCooperationModeUpdate, error) {
url := gateway.baseUrL + "/cooperation-modes" + strconv.Itoa(param.CooperationModeId)
url := gateway.baseUrL + "/cooperation-modes/" + strconv.Itoa(param.CooperationModeId)
method := "put"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向业务模块请求数据:更新共创模式。", map[string]interface{}{
... ... @@ -226,3 +226,34 @@ func (gateway HttplibAlliedCreationCooperation) CooperationModeBatchRemove(param
err = gateway.GetResponseData(result, &data)
return &data, err
}
// CooperationModeUpdate 更新共创模式
func (gateway HttplibAlliedCreationCooperation) CooperationModeOperate(param ReqOperateCooperationMode) (*DataOperateCooperationMode, error) {
url := gateway.baseUrL + "/cooperation-modes/operate"
method := "post"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向业务模块请求数据:启用或禁用共创模式。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求启用或禁用共创模式失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取启用或禁用共创模式失败:%w", err)
}
log.Logger.Debug("获取业务模块请求数据:启用或禁用共创模式。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析启用或禁用共创模式:%w", err)
}
var data DataOperateCooperationMode
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
... ... @@ -188,3 +188,16 @@ type (
} `json:"list"`
}
)
//更新共创模式
type (
ReqOperateCooperationMode struct {
// 共创模式ID
CooperationModeId string `cname:"共创模式id" json:"cooperationModeId" valid:"Required"`
// 共创模式状态,1启用,2禁用
Status int `cname:"状态" json:"status" valid:"Required"`
}
DataOperateCooperationMode struct {
}
)
... ...
... ... @@ -53,6 +53,13 @@ func (controller *baseController) GetOperator() domain.Operator {
Phone: loginToken.Account,
Token: token,
}
// TODO:测试数据后期删除
if op.UserId == 0 {
op.UserId = 9
op.CompanyId = 23
op.OrgId = 45
op.UserBaseId = 5
}
// TODO:打印测试日志
log.Logger.Debug("operator " + json.MarshalToString(op))
return op
... ...
... ... @@ -3,6 +3,7 @@ package web_client
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
type baseController struct {
... ... @@ -20,18 +21,26 @@ func (controller *baseController) returnPageListData(count int64, data interface
}
func (controller *baseController) GetOperator() domain.Operator {
// tk, _ := middleware.FormCtxLoginToken(controller.Ctx)
// operator := domain.Operator{
// UserId: tk.UserId,
// CompanyId: tk.CompanyId,
// OrgId: tk.OrgId,
// UserBaseId: tk.UserBaseId,
// }
return domain.Operator{
UserId: 9,
CompanyId: 23,
OrgId: 45,
UserBaseId: 1,
token := controller.Ctx.Input.Header("X-Mmm-Accesstoken")
loginToken := &domain.LoginToken{}
err := loginToken.ParseToken(token)
if err != nil {
log.Logger.Error(err.Error())
}
op := domain.Operator{
UserId: loginToken.UserId,
CompanyId: loginToken.CompanyId,
OrgId: loginToken.OrgId,
UserBaseId: loginToken.UserBaseId,
Phone: loginToken.Account,
Token: token,
}
// TODO:测试数据后期删除
if op.UserId == 0 {
op.UserId = 9
op.CompanyId = 23
op.OrgId = 45
op.UserBaseId = 5
}
return op
}
... ...
... ... @@ -80,6 +80,21 @@ func (controller *CooperationModeController) ListCooperationMode() {
log.Logger.Debug("json err:" + err.Error())
}
listCooperationModeQuery.Operator = controller.GetOperator()
cnt, data, err := cooperationModeService.ListCooperationMode(listCooperationModeQuery)
controller.returnPageListData(cnt, data, err, listCooperationModeQuery.PageNumber)
listCooperationModeQuery.PageNumber = 1
listCooperationModeQuery.PageSize = 999
_, data, err := cooperationModeService.ListCooperationMode(listCooperationModeQuery)
controller.Response(data, err)
}
func (controller *CooperationModeController) EnableCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
removeCooperationModeCommand := &command.OperateCooperationModeCommand{}
err := controller.Unmarshal(removeCooperationModeCommand)
if err != nil {
log.Logger.Debug("json err:" + err.Error())
}
removeCooperationModeCommand.Operator = controller.GetOperator()
data, err := cooperationModeService.EnableCooperationMode(removeCooperationModeCommand)
controller.Response(data, err)
}
... ...
... ... @@ -3,6 +3,7 @@ package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client"
)
// router
... ... @@ -30,6 +31,7 @@ func init() {
web.Router("/v1/app/cooperation-projects/:projectId", &mobile_client.CooperationController{}, "Put:UpdateCooperationProject")
web.Router("/v1/app/cooperation-projects/end", &mobile_client.CooperationController{}, "Post:EndCooperationProject")
web.Router("/v1/app/cooperation-projects/search", &mobile_client.CooperationController{}, "Post:SearchCooperationProject")
web.Router("/v1/app/cooperation-modes/", &web_client.CooperationModeController{}, "Get:ListCooperationMode")
/***** CompanyDividends 账期结算 *****/
web.Router("/v1/app/company/credit-accounts/search", &mobile_client.CooperationController{}, "Post:CreditAccountSearch")
... ...
... ... @@ -10,5 +10,7 @@ func init() {
web.Router("/v1/web/cooperation-modes/:modeId", &web_client.CooperationModeController{}, "Put:UpdateCooperationMode")
web.Router("/v1/web/cooperation-modes/:modeId", &web_client.CooperationModeController{}, "Get:GetCooperationMode")
web.Router("/v1/web/cooperation-modes/remove", &web_client.CooperationModeController{}, "Post:RemoveCooperationMode")
web.Router("/v1/web/cooperation-modes/search", &web_client.CooperationModeController{}, "Post:ListCooperationMode")
web.Router("/v1/web/cooperation-modes/search", &web_client.CooperationModeController{}, "Post:SearchCooperationMode")
web.Router("/v1/web/cooperation-modes/enable", &web_client.CooperationModeController{}, "Put:EnableCooperationMode")
web.Router("/v1/web/cooperation-modes/", &web_client.CooperationModeController{}, "Get:ListCooperationMode")
}
... ...