作者 陈志颖

feat:完成分红预算单确定金额激励服务

... ... @@ -13,7 +13,7 @@ type ConfirmMoneyIncentivesEstimateCommand struct {
// 共创合约ID
CooperationContractId string `cname:"共创合约ID" json:"cooperationContractId" valid:"Required"`
// 分红阶段
DividendsIncentivesStage int32 `cname:"分红阶段" json:"dividendsIncentivesStage,string" valid:"Required"`
DividendsIncentivesStage int32 `cname:"分红阶段" json:"dividendsIncentivesStage" valid:"Required"`
// 承接人UID
UndertakerUids []string `cname:"承接人UID列表" json:"undertakerUids" valid:"Required"`
// 公司ID,通过集成REST上下文获取
... ...
... ... @@ -589,7 +589,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
}
// ConfirmMoneyIncentivesEstimate TODO 确定金额激励分红预算
// ConfirmMoneyIncentivesEstimate 确定金额激励分红预算
func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentivesEstimate(confirmMoneyIncentivesEstimateCommand *command.ConfirmMoneyIncentivesEstimateCommand) (interface{}, error) {
if err := confirmMoneyIncentivesEstimateCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -628,6 +628,58 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
cooperationContractRepository = value
}
// 分红预算单DAO初始化
var dividendsEstimateDao *dao.DividendsEstimateDao
if value, err := factory.CreateDividendsEstimateDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
dividendsEstimateDao = value
}
// 公司REST服务初始化
var companyService service.CompanyService
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
companyService = value
}
// 获取公司信息
var company *domain.Company
if data, err := companyService.CompanyFrom(confirmMoneyIncentivesEstimateCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
company = data
}
// 组织机构REST服务初始化
var organizationService service.OrgService
if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
organizationService = value
}
// 获取组织机构信息
var organization *domain.Org
if data, err := organizationService.OrgFrom(confirmMoneyIncentivesEstimateCommand.CompanyId, confirmMoneyIncentivesEstimateCommand.OrgId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
organization = data
}
// 分红预算仓储初始化
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
}
cooperationContractId, _ := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)
undertakerUIDs, _ := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids)
... ... @@ -640,14 +692,54 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationContractId, 10)))
}
var dividendsEstimates []*domain.DividendsEstimate
// 共创合约预算
if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
} else {
if err3 := transactionContext.CommitTransaction(); err3 != nil {
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
dividendsEstimate := &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsEstimateDetail.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
DividendsType: domain.MONEY_INCENTIVES,
DividendsTypeName: "金额激励",
OrderOrReturnedOrderNum: "",
CooperationContractNumber: cooperationContract.CooperationContractNumber,
DividendsUser: dividendsEstimateDetail.DividendsUser,
DividendsStage: dividendsEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: nil,
OperateTime: time.Now(),
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
}
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)
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return dividendsEstimateDetails, nil
return dividendsEstimatesSaved, nil
}
}
... ...
... ... @@ -44,6 +44,9 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
break
}
}
if moneyIncentivesRuleMatched == nil {
return nil, fmt.Errorf("未匹配到金额激励规则")
}
// 判断金额激励阶段是否合法
currentTime := time.Now()
... ... @@ -55,7 +58,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
for _, undertaker := range contract.Undertakers {
// 判断承接人在当前阶段是否已经分红
undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
"undertakerUid": undertaker,
"undertakerUid": undertaker.UserId,
"companyId": contract.Company.CompanyId,
"orgId": contract.Org.OrgId,
})
... ...