作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

@@ -619,6 +619,15 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -619,6 +619,15 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
619 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 619 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
620 } else { 620 } else {
621 var dividendsEstimates []*domain.DividendsEstimate 621 var dividendsEstimates []*domain.DividendsEstimate
  622 + // 统计当前分红预算单数
  623 + count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
  624 + "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
  625 + "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
  626 + })
  627 + if err != nil {
  628 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  629 + }
  630 + var countDividendsEstimate int64
622 for _, orderGood := range orderGoods { 631 for _, orderGood := range orderGoods {
623 dividendsEstimate := &domain.DividendsEstimate{} 632 dividendsEstimate := &domain.DividendsEstimate{}
624 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 633 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
@@ -637,18 +646,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -637,18 +646,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
637 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { 646 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
638 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 647 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
639 } else { 648 } else {
640 - // 统计当前分红预算单数  
641 - count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{})  
642 - if err != nil {  
643 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
644 - }  
645 -  
646 - for i, dividendsEstimateDetail := range dividendsEstimateDetails { 649 + for _, dividendsEstimateDetail := range dividendsEstimateDetails {
647 // 生成分红预算单号 650 // 生成分红预算单号
648 - dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), int64(i)) 651 + dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
649 if err != nil { 652 if err != nil {
650 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 653 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
651 } 654 }
  655 + countDividendsEstimate = countDividendsEstimate + 1
652 dividendsEstimate = &domain.DividendsEstimate{ 656 dividendsEstimate = &domain.DividendsEstimate{
653 DividendsEstimateId: 0, 657 DividendsEstimateId: 0,
654 DividendsAccountStatus: domain.TO_BE_ACCOUNT, 658 DividendsAccountStatus: domain.TO_BE_ACCOUNT,
@@ -735,7 +739,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -735,7 +739,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
735 } 739 }
736 // TODO 分析成功和失败原因 740 // TODO 分析成功和失败原因
737 successfullyCount := len(dividendsEstimatesSaved) 741 successfullyCount := len(dividendsEstimatesSaved)
738 - return fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d订单分红预算失败,失败原因:%s", countDividendsOrders, successfullyCount, 0, ""), nil 742 + return fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", countDividendsOrders, successfullyCount, 0, ""), nil
739 } 743 }
740 } 744 }
741 } 745 }
@@ -80,6 +80,12 @@ func (dao *DividendsEstimateDao) CountDividendsEstimate(queryOptions map[string] @@ -80,6 +80,12 @@ func (dao *DividendsEstimateDao) CountDividendsEstimate(queryOptions map[string]
80 tx := dao.transactionContext.PgTx 80 tx := dao.transactionContext.PgTx
81 var dividendsEstimateModels []*models.DividendsEstimate 81 var dividendsEstimateModels []*models.DividendsEstimate
82 query := tx.Model(&dividendsEstimateModels) 82 query := tx.Model(&dividendsEstimateModels)
  83 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  84 + query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
  85 + }
  86 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  87 + query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
  88 + }
83 if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { 89 if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
84 return 0, err 90 return 0, err
85 } else { 91 } else {
@@ -44,7 +44,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -44,7 +44,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
44 // 获取合约 44 // 获取合约
45 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractNumber": orderGood.CooperationContractNumber}) 45 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractNumber": orderGood.CooperationContractNumber})
46 if err != nil { 46 if err != nil {
47 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创合约不存在") 47 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
48 } 48 }
49 if cooperationContract == nil { 49 if cooperationContract == nil {
50 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber)) 50 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
@@ -112,7 +112,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -112,7 +112,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
112 Roles: undertaker.Referrer.Roles, 112 Roles: undertaker.Referrer.Roles,
113 UserInfo: undertaker.Referrer.UserInfo, 113 UserInfo: undertaker.Referrer.UserInfo,
114 UserType: undertaker.Referrer.UserType, 114 UserType: undertaker.Referrer.UserType,
115 - UserName: undertaker.Referrer.UserInfo.UserName, 115 + UserName: undertaker.Referrer.UserName,
116 UserPhone: undertaker.Referrer.UserPhone, 116 UserPhone: undertaker.Referrer.UserPhone,
117 Company: undertaker.Referrer.Company, 117 Company: undertaker.Referrer.Company,
118 }, 118 },
@@ -1041,7 +1041,15 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string @@ -1041,7 +1041,15 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string
1041 cooperationContractModel := new(models.CooperationContract) 1041 cooperationContractModel := new(models.CooperationContract)
1042 query := sqlbuilder.BuildQuery(tx.Model(cooperationContractModel), queryOptions) 1042 query := sqlbuilder.BuildQuery(tx.Model(cooperationContractModel), queryOptions)
1043 query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_id = ?", "cooperationContractId") 1043 query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_id = ?", "cooperationContractId")
1044 - query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_number = ?", "cooperationContractNumber") 1044 + if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
  1045 + query.Where("cooperation_contract.cooperation_contract_number = ?", cooperationContractNumber)
  1046 + }
  1047 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  1048 + query.Where("company->>'companyId' = '?'", companyId)
  1049 + }
  1050 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  1051 + query.Where("org->>'orgId' = '?'", orgId)
  1052 + }
1045 if err := query.First(); err != nil { 1053 if err := query.First(); err != nil {
1046 if err.Error() == "pg: no rows in result set" { 1054 if err.Error() == "pg: no rows in result set" {
1047 return nil, fmt.Errorf("共创合约不存在") 1055 return nil, fmt.Errorf("共创合约不存在")
@@ -1053,62 +1061,78 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string @@ -1053,62 +1061,78 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string
1053 return nil, nil 1061 return nil, nil
1054 } else { 1062 } else {
1055 // 获取共创模式 1063 // 获取共创模式
1056 - cooperationModeModels := new(models.CooperationMode)  
1057 - cooperationModeQuery := tx.Model(cooperationModeModels)  
1058 - if err := cooperationModeQuery. 1064 + //cooperationModeModels := new(models.CooperationMode)
  1065 + //cooperationModeQuery := tx.Model(cooperationModeModels)
  1066 + //if err := cooperationModeQuery.
  1067 + // Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
  1068 + // Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
  1069 + // Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).
  1070 + // First(); err != nil {
  1071 + // return nil, fmt.Errorf("共创合约关联的共创模式不存在")
  1072 + //}
  1073 + var cooperationModeModels []*models.CooperationMode
  1074 + cooperationModeQuery := tx.Model(&cooperationModeModels)
  1075 + if countMode, err := cooperationModeQuery.
1059 Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId). 1076 Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
1060 Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId). 1077 Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
1061 Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber). 1078 Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).
1062 - First(); err != nil {  
1063 - return nil, fmt.Errorf("共创合约关联的共创模式不存在")  
1064 - }  
1065 - // 获取分红激励规则列表  
1066 - var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule  
1067 - dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)  
1068 - if err := dividendsIncentivesRuleQuery.  
1069 - Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).  
1070 - Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).  
1071 - Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).  
1072 - Select(); err != nil {  
1073 - return nil, fmt.Errorf("共创合约关联的分红激励规则不存在")  
1074 - }  
1075 - // 获取金额激励规则列表  
1076 - var moneyIncentivesRuleModels []*models.MoneyIncentivesRule  
1077 - moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)  
1078 - if err := moneyIncentivesRuleQuery.  
1079 - Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).  
1080 - Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).  
1081 - Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).  
1082 - Select(); err != nil {  
1083 - return nil, fmt.Errorf("共创合约关联的金额激励规则不存在")  
1084 - }  
1085 - // 获取承接人列表  
1086 - var cooperationContractUndertakerModels []*models.CooperationContractUndertaker  
1087 - cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)  
1088 - if err := cooperationContractUndertakerQuery.  
1089 - Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).  
1090 - Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).  
1091 - Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).  
1092 - Select(); err != nil {  
1093 - return nil, fmt.Errorf("合约承接人不存在")  
1094 - }  
1095 - // 获取相关人列表  
1096 - var cooperationContractRelevantModels []*models.CooperationContractRelevant  
1097 - cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)  
1098 - if err := cooperationContractRelevantQuery.  
1099 - Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).  
1100 - Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).  
1101 - Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).  
1102 - Select(); err != nil {  
1103 - return nil, fmt.Errorf("合约相关人不存在") 1079 + Limit(1).
  1080 + SelectAndCount(); err != nil {
  1081 + log.Logger.Error("合约关联的共创模式不存在", map[string]interface{}{
  1082 + "cooperationContractModel": cooperationContractModel,
  1083 + })
  1084 + } else {
  1085 + if countMode > 0 {
  1086 + // 获取分红激励规则列表
  1087 + var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
  1088 + dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
  1089 + if err := dividendsIncentivesRuleQuery.
  1090 + Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
  1091 + Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
  1092 + Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
  1093 + Select(); err != nil {
  1094 + return nil, fmt.Errorf("共创合约关联的分红激励规则不存在")
  1095 + }
  1096 + // 获取金额激励规则列表
  1097 + var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
  1098 + moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
  1099 + if err := moneyIncentivesRuleQuery.
  1100 + Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
  1101 + Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
  1102 + Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
  1103 + Select(); err != nil {
  1104 + return nil, fmt.Errorf("共创合约关联的金额激励规则不存在")
  1105 + }
  1106 + // 获取承接人列表
  1107 + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
  1108 + cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
  1109 + if err := cooperationContractUndertakerQuery.
  1110 + Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
  1111 + Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
  1112 + Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
  1113 + Select(); err != nil {
  1114 + return nil, fmt.Errorf("合约承接人不存在")
  1115 + }
  1116 + // 获取相关人列表
  1117 + var cooperationContractRelevantModels []*models.CooperationContractRelevant
  1118 + cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
  1119 + if err := cooperationContractRelevantQuery.
  1120 + Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
  1121 + Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
  1122 + Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
  1123 + Select(); err != nil {
  1124 + return nil, fmt.Errorf("合约相关人不存在")
  1125 + }
  1126 + return transform.TransformToCooperationContractDomainModelFromPgModels(
  1127 + cooperationContractModel,
  1128 + cooperationModeModels[0],
  1129 + dividendsIncentivesRuleModels,
  1130 + moneyIncentivesRuleModels,
  1131 + cooperationContractRelevantModels,
  1132 + cooperationContractUndertakerModels)
  1133 + }
1104 } 1134 }
1105 - return transform.TransformToCooperationContractDomainModelFromPgModels(  
1106 - cooperationContractModel,  
1107 - cooperationModeModels,  
1108 - dividendsIncentivesRuleModels,  
1109 - moneyIncentivesRuleModels,  
1110 - cooperationContractRelevantModels,  
1111 - cooperationContractUndertakerModels) 1135 + return nil, fmt.Errorf("共创合约不存在")
1112 } 1136 }
1113 } 1137 }
1114 1138