作者 陈志颖

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

@@ -13,7 +13,7 @@ type ConfirmMoneyIncentivesEstimateCommand struct { @@ -13,7 +13,7 @@ type ConfirmMoneyIncentivesEstimateCommand struct {
13 // 共创合约ID 13 // 共创合约ID
14 CooperationContractId string `cname:"共创合约ID" json:"cooperationContractId" valid:"Required"` 14 CooperationContractId string `cname:"共创合约ID" json:"cooperationContractId" valid:"Required"`
15 // 分红阶段 15 // 分红阶段
16 - DividendsIncentivesStage int32 `cname:"分红阶段" json:"dividendsIncentivesStage,string" valid:"Required"` 16 + DividendsIncentivesStage int32 `cname:"分红阶段" json:"dividendsIncentivesStage" valid:"Required"`
17 // 承接人UID 17 // 承接人UID
18 UndertakerUids []string `cname:"承接人UID列表" json:"undertakerUids" valid:"Required"` 18 UndertakerUids []string `cname:"承接人UID列表" json:"undertakerUids" valid:"Required"`
19 // 公司ID,通过集成REST上下文获取 19 // 公司ID,通过集成REST上下文获取
@@ -589,7 +589,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -589,7 +589,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
589 } 589 }
590 } 590 }
591 591
592 -// ConfirmMoneyIncentivesEstimate TODO 确定金额激励分红预算 592 +// ConfirmMoneyIncentivesEstimate 确定金额激励分红预算
593 func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentivesEstimate(confirmMoneyIncentivesEstimateCommand *command.ConfirmMoneyIncentivesEstimateCommand) (interface{}, error) { 593 func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentivesEstimate(confirmMoneyIncentivesEstimateCommand *command.ConfirmMoneyIncentivesEstimateCommand) (interface{}, error) {
594 if err := confirmMoneyIncentivesEstimateCommand.ValidateCommand(); err != nil { 594 if err := confirmMoneyIncentivesEstimateCommand.ValidateCommand(); err != nil {
595 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 595 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -628,6 +628,58 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -628,6 +628,58 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
628 cooperationContractRepository = value 628 cooperationContractRepository = value
629 } 629 }
630 630
  631 + // 分红预算单DAO初始化
  632 + var dividendsEstimateDao *dao.DividendsEstimateDao
  633 + if value, err := factory.CreateDividendsEstimateDao(map[string]interface{}{
  634 + "transactionContext": transactionContext,
  635 + }); err != nil {
  636 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  637 + } else {
  638 + dividendsEstimateDao = value
  639 + }
  640 +
  641 + // 公司REST服务初始化
  642 + var companyService service.CompanyService
  643 + if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
  644 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  645 + } else {
  646 + companyService = value
  647 + }
  648 +
  649 + // 获取公司信息
  650 + var company *domain.Company
  651 + if data, err := companyService.CompanyFrom(confirmMoneyIncentivesEstimateCommand.CompanyId); err != nil {
  652 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  653 + } else {
  654 + company = data
  655 + }
  656 +
  657 + // 组织机构REST服务初始化
  658 + var organizationService service.OrgService
  659 + if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
  660 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  661 + } else {
  662 + organizationService = value
  663 + }
  664 +
  665 + // 获取组织机构信息
  666 + var organization *domain.Org
  667 + if data, err := organizationService.OrgFrom(confirmMoneyIncentivesEstimateCommand.CompanyId, confirmMoneyIncentivesEstimateCommand.OrgId); err != nil {
  668 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  669 + } else {
  670 + organization = data
  671 + }
  672 +
  673 + // 分红预算仓储初始化
  674 + var dividendsEstimateRepository domain.DividendsEstimateRepository
  675 + if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
  676 + "transactionContext": transactionContext,
  677 + }); err != nil {
  678 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  679 + } else {
  680 + dividendsEstimateRepository = value
  681 + }
  682 +
631 cooperationContractId, _ := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64) 683 cooperationContractId, _ := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)
632 undertakerUIDs, _ := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids) 684 undertakerUIDs, _ := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids)
633 685
@@ -640,14 +692,54 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -640,14 +692,54 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
640 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationContractId, 10))) 692 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationContractId, 10)))
641 } 693 }
642 694
  695 + var dividendsEstimates []*domain.DividendsEstimate
  696 +
643 // 共创合约预算 697 // 共创合约预算
644 if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil { 698 if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil {
645 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) 699 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
646 } else { 700 } else {
647 - if err3 := transactionContext.CommitTransaction(); err3 != nil { 701 + for _, dividendsEstimateDetail := range dividendsEstimateDetails {
  702 + // 生成分红预算单号
  703 + dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber()
  704 + if err != nil {
  705 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  706 + }
  707 + dividendsEstimate := &domain.DividendsEstimate{
  708 + DividendsEstimateId: 0,
  709 + DividendsAccountStatus: domain.TO_BE_ACCOUNT,
  710 + DividendsAmount: dividendsEstimateDetail.DividendsAmount,
  711 + DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
  712 + DividendsEstimateTime: time.Now(),
  713 + DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
  714 + DividendsType: domain.MONEY_INCENTIVES,
  715 + DividendsTypeName: "金额激励",
  716 + OrderOrReturnedOrderNum: "",
  717 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  718 + DividendsUser: dividendsEstimateDetail.DividendsUser,
  719 + DividendsStage: dividendsEstimateDetail.DividendsStage,
  720 + Org: organization,
  721 + Company: company,
  722 + Operator: nil,
  723 + OperateTime: time.Now(),
  724 + IsCanceled: false,
  725 + CreatedAt: time.Now(),
  726 + DeletedAt: time.Time{},
  727 + UpdatedAt: time.Time{},
  728 + }
  729 + dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
  730 + }
  731 + var dividendsEstimatesSaved []*domain.DividendsEstimate
  732 + for _, dividendsEstimate := range dividendsEstimates {
  733 + if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
  734 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  735 + } else {
  736 + dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved)
  737 + }
  738 + }
  739 + if err := transactionContext.CommitTransaction(); err != nil {
648 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 740 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
649 } 741 }
650 - return dividendsEstimateDetails, nil 742 + return dividendsEstimatesSaved, nil
651 } 743 }
652 } 744 }
653 745
@@ -44,6 +44,9 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -44,6 +44,9 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
44 break 44 break
45 } 45 }
46 } 46 }
  47 + if moneyIncentivesRuleMatched == nil {
  48 + return nil, fmt.Errorf("未匹配到金额激励规则")
  49 + }
47 50
48 // 判断金额激励阶段是否合法 51 // 判断金额激励阶段是否合法
49 currentTime := time.Now() 52 currentTime := time.Now()
@@ -55,7 +58,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -55,7 +58,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
55 for _, undertaker := range contract.Undertakers { 58 for _, undertaker := range contract.Undertakers {
56 // 判断承接人在当前阶段是否已经分红 59 // 判断承接人在当前阶段是否已经分红
57 undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{ 60 undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
58 - "undertakerUid": undertaker, 61 + "undertakerUid": undertaker.UserId,
59 "companyId": contract.Company.CompanyId, 62 "companyId": contract.Company.CompanyId,
60 "orgId": contract.Org.OrgId, 63 "orgId": contract.Org.OrgId,
61 }) 64 })