作者 陈志颖

feat:分红预算增加取消功能

... ... @@ -10,16 +10,18 @@ import (
// CancelDividendsEstimateCommand 取消分红预算
type CancelDividendsEstimateCommand struct {
// 承接人分红预算记录ID
DividendsEstimateId string `cname:"承接人分红预算记录ID" json:"dividendsEstimateId" valid:"Required"`
// 公司ID,通过集成REST上下文获取
// 承接人分红预算记录ID
DividendsEstimateId int64 `cname:"承接人分红预算记录ID" json:"dividendsEstimateId" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId,string" valid:"Required"`
// 组织机构ID
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID" json:"userId,string" valid:"Required"`
// 用户基础数据id
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId,string" valid:"Required"`
// 状态
IsCanceled bool `cname:"是否取消" json:"isCanceled,omitempty"`
}
func (cancelDividendsEstimateCommand *CancelDividendsEstimateCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -169,10 +169,36 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
var dividendsEstimateRepository domain.DividendsEstimateRepository
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsEstimateRepository = value
}
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": cancelDividendsEstimateCommand.DividendsEstimateId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsEstimate == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cancelDividendsEstimateCommand.DividendsEstimateId, 10)))
}
// TODO 校验是否能够取消
// 设置取消状态
cancelDividendsEstimateCommand.IsCanceled = true
if err := dividendsEstimate.Update(tool_funs.SimpleStructToMap(cancelDividendsEstimateCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if dividendsEstimate, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return dividendsEstimate, nil
}
return nil, nil
}
// BatchCancelDividendsEstimate 批量取消分红预算单
... ...
... ... @@ -46,6 +46,8 @@ type DividendsEstimate struct {
Operator *User `json:"operator"`
// 操作时间
OperateTime time.Time `json:"operateTime"`
// 取消状态
IsCanceled bool `json:"isCanceled"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 删除时间
... ... @@ -94,5 +96,8 @@ func (dividendsEstimate *DividendsEstimate) Update(data map[string]interface{})
if cooperationProjectNumber, ok := data["cooperationProjectNumber"]; ok {
dividendsEstimate.CooperationContractNumber = cooperationProjectNumber.(string)
}
if isCanceled, ok := data["isCanceled"]; ok {
dividendsEstimate.IsCanceled = isCanceled.(bool)
}
return nil
}
... ...
... ... @@ -37,6 +37,8 @@ type DividendsEstimate struct {
Operator *domain.User `comment:"操作人"`
// 操作时间
OperateTime time.Time `comment:"操作时间"`
// 取消状态
IsCanceled bool `comment:"取消状态"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 删除时间
... ...
... ... @@ -22,6 +22,7 @@ func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel
Company: dividendsEstimateModel.Company,
Operator: dividendsEstimateModel.Operator,
OperateTime: dividendsEstimateModel.OperateTime,
IsCanceled: dividendsEstimateModel.IsCanceled,
CreatedAt: dividendsEstimateModel.CreatedAt,
DeletedAt: dividendsEstimateModel.DeletedAt,
UpdatedAt: dividendsEstimateModel.UpdatedAt,
... ...
... ... @@ -42,6 +42,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
"company",
"operator",
"operate_time",
"is_canceled",
"created_at",
"deleted_at",
"updated_at",
... ... @@ -76,6 +77,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
&dividendsEstimate.Company,
&dividendsEstimate.Operator,
&dividendsEstimate.OperateTime,
&dividendsEstimate.IsCanceled,
&dividendsEstimate.CreatedAt,
&dividendsEstimate.DeletedAt,
&dividendsEstimate.UpdatedAt,
... ... @@ -96,8 +98,9 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
dividendsEstimate.Company,
dividendsEstimate.Operator,
dividendsEstimate.OperateTime,
dividendsEstimate.IsCanceled,
dividendsEstimate.CreatedAt,
dividendsEstimate.DeletedAt,
nil,
dividendsEstimate.UpdatedAt,
); err != nil {
return dividendsEstimate, err
... ... @@ -120,6 +123,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
&dividendsEstimate.Company,
&dividendsEstimate.Operator,
&dividendsEstimate.OperateTime,
&dividendsEstimate.IsCanceled,
&dividendsEstimate.CreatedAt,
&dividendsEstimate.DeletedAt,
&dividendsEstimate.UpdatedAt,
... ... @@ -140,8 +144,9 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
dividendsEstimate.Company,
dividendsEstimate.Operator,
dividendsEstimate.OperateTime,
dividendsEstimate.IsCanceled,
dividendsEstimate.CreatedAt,
dividendsEstimate.DeletedAt,
nil,
dividendsEstimate.UpdatedAt,
dividendsEstimate.Identify(),
); err != nil {
... ...
... ... @@ -81,7 +81,7 @@ func (controller *DividendsEstimateController) CancelDividendsEstimate() {
cancelDividendsEstimateCommand.OrgId = header.OrgId
cancelDividendsEstimateCommand.UserId = header.UserId
cancelDividendsEstimateCommand.UserBaseId = header.UserBaseId
dividendsEstimateId := controller.GetString(":dividendsEstimateId")
dividendsEstimateId, _ := controller.GetInt64(":dividendsEstimateId")
cancelDividendsEstimateCommand.DividendsEstimateId = dividendsEstimateId
data, err := dividendsEstimateService.CancelDividendsEstimate(cancelDividendsEstimateCommand)
controller.Response(data, err)
... ...