作者 陈志颖

refactor:优化生成分红预算单

... ... @@ -24,6 +24,8 @@ type ConfirmMoneyIncentivesEstimateCommand struct {
UserId int64 `cname:"用户ID" json:"userId" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId" valid:"Required"`
// 动作,1预算,2确定预算
Action int32 `cname:"确定金额激励分红动作" json:"action" valid:"Required"`
}
func (estimateMoneyIncentivesCommand *ConfirmMoneyIncentivesEstimateCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -14,6 +14,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"strconv"
"time"
)
... ... @@ -373,7 +374,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
_ = transactionContext.RollbackTransaction()
}()
orderGoodIds, _ := utils.SliceAtoi(confirmDividendsIncentivesEstimateCommand.OrderGoodIds)
orderGoodIds, err := utils.SliceAtoi(confirmDividendsIncentivesEstimateCommand.OrderGoodIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 用户REST服务初始化
//var userService service.UserService
... ... @@ -575,13 +579,12 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
}
}
var dividendsEstimatesSaved []*domain.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved)
}
log.Logger.Info("新增的分红预算单", map[string]interface{}{
"dividendsEstimates": dividendsEstimates,
})
dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -737,8 +740,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved)
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
if confirmMoneyIncentivesEstimateCommand.Action == 1 { // 只预算,不入库
return dividendsEstimatesSaved, nil
} else if confirmMoneyIncentivesEstimateCommand.Action == 2 { // 确定预算
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return dividendsEstimatesSaved, nil
}
return dividendsEstimatesSaved, nil
}
... ...
... ... @@ -65,6 +65,7 @@ type DividendsEstimate struct {
type DividendsEstimateRepository interface {
Save(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error)
SaveMany(dividendsEstimates []*DividendsEstimate) ([]*DividendsEstimate, error)
UpdateMany(dividendsEstimates []*DividendsEstimate) ([]*DividendsEstimate, error)
Remove(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error)
FindOne(queryOptions map[string]interface{}) (*DividendsEstimate, error)
... ...
... ... @@ -162,6 +162,45 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
return dividendsEstimate, nil
}
func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) {
tx := repository.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
dividendsEstimateId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
dividendsEstimate.DividendsEstimateId = dividendsEstimateId
}
dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
DividendsAmount: dividendsEstimate.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimate.DividendsEstimateTime,
DividendsParticipateType: dividendsEstimate.DividendsParticipateType,
DividendsType: dividendsEstimate.DividendsType,
DividendsTypeName: dividendsEstimate.DividendsTypeName,
OrderOrReturnedOrderNum: dividendsEstimate.OrderOrReturnedOrderNum,
CooperationContractNumber: dividendsEstimate.CooperationContractNumber,
DividendsUser: dividendsEstimate.DividendsUser,
DividendsStage: dividendsEstimate.DividendsStage,
Org: dividendsEstimate.Org,
Company: dividendsEstimate.Company,
Operator: dividendsEstimate.Operator,
OperateTime: dividendsEstimate.OperateTime,
IsCanceled: dividendsEstimate.IsCanceled,
CreatedAt: dividendsEstimate.CreatedAt,
DeletedAt: dividendsEstimate.DeletedAt,
UpdatedAt: time.Now(),
})
}
if _, err := tx.Model(&dividendsEstimateModels).WherePK().Update(); err != nil {
return nil, err
}
return dividendsEstimates, nil
}
func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) {
tx := repository.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
... ...