正在显示
4 个修改的文件
包含
53 行增加
和
19 行删除
@@ -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(÷ndsEstimateModels) | 82 | query := tx.Model(÷ndsEstimateModels) |
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,15 +1061,28 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string | @@ -1053,15 +1061,28 @@ 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 | - } | 1079 | + Limit(1). |
1080 | + SelectAndCount(); err != nil { | ||
1081 | + log.Logger.Error("合约关联的共创模式不存在", map[string]interface{}{ | ||
1082 | + "cooperationContractModel": cooperationContractModel, | ||
1083 | + }) | ||
1084 | + } else { | ||
1085 | + if countMode > 0 { | ||
1065 | // 获取分红激励规则列表 | 1086 | // 获取分红激励规则列表 |
1066 | var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule | 1087 | var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule |
1067 | dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRuleModels) | 1088 | dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRuleModels) |
@@ -1104,12 +1125,15 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string | @@ -1104,12 +1125,15 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string | ||
1104 | } | 1125 | } |
1105 | return transform.TransformToCooperationContractDomainModelFromPgModels( | 1126 | return transform.TransformToCooperationContractDomainModelFromPgModels( |
1106 | cooperationContractModel, | 1127 | cooperationContractModel, |
1107 | - cooperationModeModels, | 1128 | + cooperationModeModels[0], |
1108 | dividendsIncentivesRuleModels, | 1129 | dividendsIncentivesRuleModels, |
1109 | moneyIncentivesRuleModels, | 1130 | moneyIncentivesRuleModels, |
1110 | cooperationContractRelevantModels, | 1131 | cooperationContractRelevantModels, |
1111 | cooperationContractUndertakerModels) | 1132 | cooperationContractUndertakerModels) |
1112 | } | 1133 | } |
1134 | + } | ||
1135 | + return nil, fmt.Errorf("共创合约不存在") | ||
1136 | + } | ||
1113 | } | 1137 | } |
1114 | 1138 | ||
1115 | func (repository *CooperationContractRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContract, error) { | 1139 | func (repository *CooperationContractRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContract, error) { |
-
请 注册 或 登录 后发表评论