|
@@ -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(÷ndsIncentivesRuleModels)
|
|
|
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(÷ndsIncentivesRuleModels)
|
|
|
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
|
|