正在显示
4 个修改的文件
包含
60 行增加
和
10 行删除
| @@ -24,6 +24,8 @@ type ConfirmMoneyIncentivesEstimateCommand struct { | @@ -24,6 +24,8 @@ type ConfirmMoneyIncentivesEstimateCommand struct { | ||
| 24 | UserId int64 `cname:"用户ID" json:"userId" valid:"Required"` | 24 | UserId int64 `cname:"用户ID" json:"userId" valid:"Required"` |
| 25 | // 用户基础数据id | 25 | // 用户基础数据id |
| 26 | UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId" valid:"Required"` | 26 | UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId" valid:"Required"` |
| 27 | + // 动作,1预算,2确定预算 | ||
| 28 | + Action int32 `cname:"确定金额激励分红动作" json:"action" valid:"Required"` | ||
| 27 | } | 29 | } |
| 28 | 30 | ||
| 29 | func (estimateMoneyIncentivesCommand *ConfirmMoneyIncentivesEstimateCommand) Valid(validation *validation.Validation) { | 31 | func (estimateMoneyIncentivesCommand *ConfirmMoneyIncentivesEstimateCommand) Valid(validation *validation.Validation) { |
| @@ -14,6 +14,7 @@ import ( | @@ -14,6 +14,7 @@ import ( | ||
| 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" | 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" |
| 15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" | 15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" |
| 16 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" | 16 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" |
| 17 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" | ||
| 17 | "strconv" | 18 | "strconv" |
| 18 | "time" | 19 | "time" |
| 19 | ) | 20 | ) |
| @@ -373,7 +374,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -373,7 +374,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
| 373 | _ = transactionContext.RollbackTransaction() | 374 | _ = transactionContext.RollbackTransaction() |
| 374 | }() | 375 | }() |
| 375 | 376 | ||
| 376 | - orderGoodIds, _ := utils.SliceAtoi(confirmDividendsIncentivesEstimateCommand.OrderGoodIds) | 377 | + orderGoodIds, err := utils.SliceAtoi(confirmDividendsIncentivesEstimateCommand.OrderGoodIds) |
| 378 | + if err != nil { | ||
| 379 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 380 | + } | ||
| 377 | 381 | ||
| 378 | // 用户REST服务初始化 | 382 | // 用户REST服务初始化 |
| 379 | //var userService service.UserService | 383 | //var userService service.UserService |
| @@ -575,13 +579,12 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -575,13 +579,12 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
| 575 | } | 579 | } |
| 576 | } | 580 | } |
| 577 | } | 581 | } |
| 578 | - var dividendsEstimatesSaved []*domain.DividendsEstimate | ||
| 579 | - for _, dividendsEstimate := range dividendsEstimates { | ||
| 580 | - if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil { | ||
| 581 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 582 | - } else { | ||
| 583 | - dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved) | ||
| 584 | - } | 582 | + log.Logger.Info("新增的分红预算单", map[string]interface{}{ |
| 583 | + "dividendsEstimates": dividendsEstimates, | ||
| 584 | + }) | ||
| 585 | + dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates) | ||
| 586 | + if err != nil { | ||
| 587 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 585 | } | 588 | } |
| 586 | if err := transactionContext.CommitTransaction(); err != nil { | 589 | if err := transactionContext.CommitTransaction(); err != nil { |
| 587 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 590 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| @@ -737,8 +740,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives | @@ -737,8 +740,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives | ||
| 737 | dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved) | 740 | dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved) |
| 738 | } | 741 | } |
| 739 | } | 742 | } |
| 740 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
| 741 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 743 | + if confirmMoneyIncentivesEstimateCommand.Action == 1 { // 只预算,不入库 |
| 744 | + return dividendsEstimatesSaved, nil | ||
| 745 | + } else if confirmMoneyIncentivesEstimateCommand.Action == 2 { // 确定预算 | ||
| 746 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 747 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 748 | + } | ||
| 749 | + return dividendsEstimatesSaved, nil | ||
| 742 | } | 750 | } |
| 743 | return dividendsEstimatesSaved, nil | 751 | return dividendsEstimatesSaved, nil |
| 744 | } | 752 | } |
| @@ -65,6 +65,7 @@ type DividendsEstimate struct { | @@ -65,6 +65,7 @@ type DividendsEstimate struct { | ||
| 65 | 65 | ||
| 66 | type DividendsEstimateRepository interface { | 66 | type DividendsEstimateRepository interface { |
| 67 | Save(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error) | 67 | Save(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error) |
| 68 | + SaveMany(dividendsEstimates []*DividendsEstimate) ([]*DividendsEstimate, error) | ||
| 68 | UpdateMany(dividendsEstimates []*DividendsEstimate) ([]*DividendsEstimate, error) | 69 | UpdateMany(dividendsEstimates []*DividendsEstimate) ([]*DividendsEstimate, error) |
| 69 | Remove(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error) | 70 | Remove(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error) |
| 70 | FindOne(queryOptions map[string]interface{}) (*DividendsEstimate, error) | 71 | FindOne(queryOptions map[string]interface{}) (*DividendsEstimate, error) |
| @@ -162,6 +162,45 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | @@ -162,6 +162,45 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | ||
| 162 | return dividendsEstimate, nil | 162 | return dividendsEstimate, nil |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | +func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) { | ||
| 166 | + tx := repository.transactionContext.PgTx | ||
| 167 | + var dividendsEstimateModels []*models.DividendsEstimate | ||
| 168 | + for _, dividendsEstimate := range dividendsEstimates { | ||
| 169 | + dividendsEstimateId, err := repository.nextIdentify() | ||
| 170 | + if err != nil { | ||
| 171 | + return nil, err | ||
| 172 | + } else { | ||
| 173 | + dividendsEstimate.DividendsEstimateId = dividendsEstimateId | ||
| 174 | + } | ||
| 175 | + dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{ | ||
| 176 | + DividendsEstimateId: dividendsEstimate.DividendsEstimateId, | ||
| 177 | + DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus, | ||
| 178 | + DividendsAmount: dividendsEstimate.DividendsAmount, | ||
| 179 | + DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber, | ||
| 180 | + DividendsEstimateTime: dividendsEstimate.DividendsEstimateTime, | ||
| 181 | + DividendsParticipateType: dividendsEstimate.DividendsParticipateType, | ||
| 182 | + DividendsType: dividendsEstimate.DividendsType, | ||
| 183 | + DividendsTypeName: dividendsEstimate.DividendsTypeName, | ||
| 184 | + OrderOrReturnedOrderNum: dividendsEstimate.OrderOrReturnedOrderNum, | ||
| 185 | + CooperationContractNumber: dividendsEstimate.CooperationContractNumber, | ||
| 186 | + DividendsUser: dividendsEstimate.DividendsUser, | ||
| 187 | + DividendsStage: dividendsEstimate.DividendsStage, | ||
| 188 | + Org: dividendsEstimate.Org, | ||
| 189 | + Company: dividendsEstimate.Company, | ||
| 190 | + Operator: dividendsEstimate.Operator, | ||
| 191 | + OperateTime: dividendsEstimate.OperateTime, | ||
| 192 | + IsCanceled: dividendsEstimate.IsCanceled, | ||
| 193 | + CreatedAt: dividendsEstimate.CreatedAt, | ||
| 194 | + DeletedAt: dividendsEstimate.DeletedAt, | ||
| 195 | + UpdatedAt: time.Now(), | ||
| 196 | + }) | ||
| 197 | + } | ||
| 198 | + if _, err := tx.Model(÷ndsEstimateModels).WherePK().Update(); err != nil { | ||
| 199 | + return nil, err | ||
| 200 | + } | ||
| 201 | + return dividendsEstimates, nil | ||
| 202 | +} | ||
| 203 | + | ||
| 165 | func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) { | 204 | func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) { |
| 166 | tx := repository.transactionContext.PgTx | 205 | tx := repository.transactionContext.PgTx |
| 167 | var dividendsEstimateModels []*models.DividendsEstimate | 206 | var dividendsEstimateModels []*models.DividendsEstimate |
-
请 注册 或 登录 后发表评论