作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

@@ -75,7 +75,11 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive @@ -75,7 +75,11 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
75 for _, orderGood := range orderGoods { 75 for _, orderGood := range orderGoods {
76 dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{} 76 dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{}
77 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 77 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
78 - dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber}) 78 + dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
  79 + "dividendsOrderNumber": orderGood.DividendsOrderNumber,
  80 + "companyId": orderGood.CompanyId,
  81 + "orgId": orderGood.OrgId,
  82 + })
79 if err != nil { 83 if err != nil {
80 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 84 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
81 } 85 }
@@ -615,7 +619,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -615,7 +619,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
615 for _, orderGood := range orderGoods { 619 for _, orderGood := range orderGoods {
616 dividendsEstimate := &domain.DividendsEstimate{} 620 dividendsEstimate := &domain.DividendsEstimate{}
617 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 621 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
618 - dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber}) 622 + dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
  623 + "dividendsOrderNumber": orderGood.DividendsOrderNumber,
  624 + "companyId": orderGood.CompanyId,
  625 + "orgId": orderGood.OrgId,
  626 + })
619 if err3 != nil { 627 if err3 != nil {
620 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在") 628 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
621 } 629 }
@@ -1098,7 +1106,11 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti @@ -1098,7 +1106,11 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
1098 for _, orderGood := range orderGoods { 1106 for _, orderGood := range orderGoods {
1099 dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{} 1107 dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{}
1100 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 1108 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
1101 - dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber}) 1109 + dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
  1110 + "dividendsOrderNumber": orderGood.DividendsOrderNumber,
  1111 + "companyId": orderGood.CompanyId,
  1112 + "orgId": orderGood.OrgId,
  1113 + })
1102 if err != nil { 1114 if err != nil {
1103 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1115 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1104 } 1116 }
@@ -31,3 +31,10 @@ type Relevant struct { @@ -31,3 +31,10 @@ type Relevant struct {
31 // 公司 31 // 公司
32 Company *Company `json:"company"` 32 Company *Company `json:"company"`
33 } 33 }
  34 +
  35 +func (relevant *Relevant) Identify() interface{} {
  36 + if relevant.RelevantId == 0 {
  37 + return nil
  38 + }
  39 + return relevant.RelevantId
  40 +}
@@ -37,3 +37,10 @@ type Undertaker struct { @@ -37,3 +37,10 @@ type Undertaker struct {
37 // 合同附件 37 // 合同附件
38 ContractAttachment []*Attachment `json:"contractAttachment"` 38 ContractAttachment []*Attachment `json:"contractAttachment"`
39 } 39 }
  40 +
  41 +func (undertaker *Undertaker) Identify() interface{} {
  42 + if undertaker.UndertakerId == 0 {
  43 + return nil
  44 + }
  45 + return undertaker.UndertakerId
  46 +}
@@ -53,6 +53,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -53,6 +53,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
53 // 获取分红订单 53 // 获取分红订单
54 dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{ 54 dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
55 "dividendsOrderNumber": orderGood.DividendsOrderNumber, 55 "dividendsOrderNumber": orderGood.DividendsOrderNumber,
  56 + "companyId": orderGood.CompanyId,
  57 + "orgId": orderGood.OrgId,
56 }) 58 })
57 if err2 != nil { 59 if err2 != nil {
58 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在") 60 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
@@ -440,7 +440,11 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m @@ -440,7 +440,11 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
440 DividendsUser: item.DividendsUser, 440 DividendsUser: item.DividendsUser,
441 } 441 }
442 if item.DividendsType == 1 { 442 if item.DividendsType == 1 {
443 - order, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": item.OrderOrReturnedOrderNum}) 443 + order, err := dividendsOrderRepository.FindOne(map[string]interface{}{
  444 + "dividendsOrderNumber": item.OrderOrReturnedOrderNum,
  445 + "companyId": item.Company.CompanyId,
  446 + "orgId": item.Org.OrgId,
  447 + })
444 if err != nil { 448 if err != nil {
445 return nil, err 449 return nil, err
446 } 450 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type ContractUndertakerFeedbackRepository struct { 16 type ContractUndertakerFeedbackRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *ContractUndertakerFeedbackRepository) nextIdentify() (int64, error) { 21 func (repository *ContractUndertakerFeedbackRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -202,8 +199,13 @@ func NewContractUndertakerFeedbackRepository(transactionContext *pgTransaction.T @@ -202,8 +199,13 @@ func NewContractUndertakerFeedbackRepository(transactionContext *pgTransaction.T
202 if transactionContext == nil { 199 if transactionContext == nil {
203 return nil, fmt.Errorf("transactionContext参数不能为nil") 200 return nil, fmt.Errorf("transactionContext参数不能为nil")
204 } else { 201 } else {
  202 + idWorker, err := snowflake.NewIdWorker(1)
  203 + if err != nil {
  204 + return nil, err
  205 + }
205 return &ContractUndertakerFeedbackRepository{ 206 return &ContractUndertakerFeedbackRepository{
206 transactionContext: transactionContext, 207 transactionContext: transactionContext,
  208 + IdWorker: idWorker,
207 }, nil 209 }, nil
208 } 210 }
209 } 211 }
@@ -17,14 +17,11 @@ import ( @@ -17,14 +17,11 @@ import (
17 17
18 type CooperationApplicationRepository struct { 18 type CooperationApplicationRepository struct {
19 transactionContext *pgTransaction.TransactionContext 19 transactionContext *pgTransaction.TransactionContext
  20 + IdWorker *snowflake.IdWorker
20 } 21 }
21 22
22 func (repository *CooperationApplicationRepository) nextIdentify() (int64, error) { 23 func (repository *CooperationApplicationRepository) nextIdentify() (int64, error) {
23 - IdWorker, err := snowflake.NewIdWorker(1)  
24 - if err != nil {  
25 - return 0, err  
26 - }  
27 - id, err := IdWorker.NextId() 24 + id, err := repository.IdWorker.NextId()
28 return id, err 25 return id, err
29 } 26 }
30 27
@@ -322,8 +319,13 @@ func NewCooperationApplicationRepository(transactionContext *pgTransaction.Trans @@ -322,8 +319,13 @@ func NewCooperationApplicationRepository(transactionContext *pgTransaction.Trans
322 if transactionContext == nil { 319 if transactionContext == nil {
323 return nil, fmt.Errorf("transactionContext参数不能为nil") 320 return nil, fmt.Errorf("transactionContext参数不能为nil")
324 } else { 321 } else {
  322 + idWorker, err := snowflake.NewIdWorker(1)
  323 + if err != nil {
  324 + return nil, err
  325 + }
325 return &CooperationApplicationRepository{ 326 return &CooperationApplicationRepository{
326 transactionContext: transactionContext, 327 transactionContext: transactionContext,
  328 + IdWorker: idWorker,
327 }, nil 329 }, nil
328 } 330 }
329 } 331 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type CooperationContractChangeLogRepository struct { 16 type CooperationContractChangeLogRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *CooperationContractChangeLogRepository) nextIdentify() (int64, error) { 21 func (repository *CooperationContractChangeLogRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -198,8 +195,13 @@ func NewCooperationContractChangeLogRepository(transactionContext *pgTransaction @@ -198,8 +195,13 @@ func NewCooperationContractChangeLogRepository(transactionContext *pgTransaction
198 if transactionContext == nil { 195 if transactionContext == nil {
199 return nil, fmt.Errorf("transactionContext参数不能为nil") 196 return nil, fmt.Errorf("transactionContext参数不能为nil")
200 } else { 197 } else {
  198 + idWorker, err := snowflake.NewIdWorker(1)
  199 + if err != nil {
  200 + return nil, err
  201 + }
201 return &CooperationContractChangeLogRepository{ 202 return &CooperationContractChangeLogRepository{
202 transactionContext: transactionContext, 203 transactionContext: transactionContext,
  204 + IdWorker: idWorker,
203 }, nil 205 }, nil
204 } 206 }
205 } 207 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type CooperationContractRelevantRepository struct { 16 type CooperationContractRelevantRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *CooperationContractRelevantRepository) nextIdentify() (int64, error) { 21 func (repository *CooperationContractRelevantRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -210,8 +207,13 @@ func NewCooperationContractRelevantRepository(transactionContext *pgTransaction. @@ -210,8 +207,13 @@ func NewCooperationContractRelevantRepository(transactionContext *pgTransaction.
210 if transactionContext == nil { 207 if transactionContext == nil {
211 return nil, fmt.Errorf("transactionContext参数不能为nil") 208 return nil, fmt.Errorf("transactionContext参数不能为nil")
212 } else { 209 } else {
  210 + idWorker, err := snowflake.NewIdWorker(1)
  211 + if err != nil {
  212 + return nil, err
  213 + }
213 return &CooperationContractRelevantRepository{ 214 return &CooperationContractRelevantRepository{
214 transactionContext: transactionContext, 215 transactionContext: transactionContext,
  216 + IdWorker: idWorker,
215 }, nil 217 }, nil
216 } 218 }
217 } 219 }
@@ -16,14 +16,11 @@ import ( @@ -16,14 +16,11 @@ import (
16 16
17 type CooperationContractRepository struct { 17 type CooperationContractRepository struct {
18 transactionContext *pgTransaction.TransactionContext 18 transactionContext *pgTransaction.TransactionContext
  19 + IdWorker *snowflake.IdWorker
19 } 20 }
20 21
21 func (repository *CooperationContractRepository) nextIdentify() (int64, error) { 22 func (repository *CooperationContractRepository) nextIdentify() (int64, error) {
22 - IdWorker, err := snowflake.NewIdWorker(1)  
23 - if err != nil {  
24 - return 0, err  
25 - }  
26 - id, err := IdWorker.NextId() 23 + id, err := repository.IdWorker.NextId()
27 return id, err 24 return id, err
28 } 25 }
29 26
@@ -108,7 +105,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -108,7 +105,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
108 // 新增相关人 105 // 新增相关人
109 var relevantPeopleModel []*models.CooperationContractRelevant 106 var relevantPeopleModel []*models.CooperationContractRelevant
110 for _, relevant := range cooperationContract.RelevantPeople { 107 for _, relevant := range cooperationContract.RelevantPeople {
  108 + if relevant.Identify() == nil {
  109 + orderGoodId, err := repository.nextIdentify()
  110 + if err != nil {
  111 + return nil, err
  112 + } else {
  113 + relevant.RelevantId = orderGoodId
  114 + }
  115 + }
111 relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{ 116 relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
  117 + CooperationContractRelevantId: relevant.RelevantId,
112 CooperationContractNumber: cooperationContract.CooperationContractNumber, 118 CooperationContractNumber: cooperationContract.CooperationContractNumber,
113 UserId: relevant.UserId, 119 UserId: relevant.UserId,
114 UserBaseId: relevant.UserBaseId, 120 UserBaseId: relevant.UserBaseId,
@@ -169,7 +175,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -169,7 +175,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
169 // 新增分红激励规则 175 // 新增分红激励规则
170 var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule 176 var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
171 for _, rule := range cooperationContract.DividendsIncentivesRules { 177 for _, rule := range cooperationContract.DividendsIncentivesRules {
  178 + if rule.Identify() == nil {
  179 + ruleId, err := repository.nextIdentify()
  180 + if err != nil {
  181 + return nil, err
  182 + } else {
  183 + rule.DividendsIncentivesRuleId = ruleId
  184 + }
  185 + }
172 dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{ 186 dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
  187 + DividendsIncentivesRuleId: rule.DividendsIncentivesRuleId,
173 CooperationContractNumber: cooperationContract.CooperationContractNumber, 188 CooperationContractNumber: cooperationContract.CooperationContractNumber,
174 ReferrerPercentage: rule.ReferrerPercentage, 189 ReferrerPercentage: rule.ReferrerPercentage,
175 SalesmanPercentage: rule.SalesmanPercentage, 190 SalesmanPercentage: rule.SalesmanPercentage,
@@ -197,7 +212,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -197,7 +212,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
197 // 新增金额激励规则 212 // 新增金额激励规则
198 var moneyIncentivesRulesModel []*models.MoneyIncentivesRule 213 var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
199 for _, rule := range cooperationContract.MoneyIncentivesRules { 214 for _, rule := range cooperationContract.MoneyIncentivesRules {
  215 + if rule.Identify() == nil {
  216 + ruleId, err := repository.nextIdentify()
  217 + if err != nil {
  218 + return nil, err
  219 + } else {
  220 + rule.MoneyIncentivesRuleId = ruleId
  221 + }
  222 + }
200 moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{ 223 moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
  224 + MoneyIncentivesRuleId: rule.MoneyIncentivesRuleId,
201 CooperationContractNumber: cooperationContract.CooperationContractNumber, 225 CooperationContractNumber: cooperationContract.CooperationContractNumber,
202 MoneyIncentivesAmount: rule.MoneyIncentivesAmount, 226 MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
203 MoneyIncentivesStage: rule.MoneyIncentivesStage, 227 MoneyIncentivesStage: rule.MoneyIncentivesStage,
@@ -302,7 +326,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -302,7 +326,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
302 // 将待添加的相关人领域模型转换为数据模型 326 // 将待添加的相关人领域模型转换为数据模型
303 var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant 327 var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant
304 for _, relevantDomain := range cooperationContractRelevantPeopleToAdd { 328 for _, relevantDomain := range cooperationContractRelevantPeopleToAdd {
  329 + if relevantDomain.Identify() == nil {
  330 + relevantId, err := repository.nextIdentify()
  331 + if err != nil {
  332 + return nil, err
  333 + } else {
  334 + relevantDomain.RelevantId = relevantId
  335 + }
  336 + }
305 cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{ 337 cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{
  338 + CooperationContractRelevantId: relevantDomain.RelevantId,
306 CooperationContractNumber: relevantDomain.CooperationContractNumber, 339 CooperationContractNumber: relevantDomain.CooperationContractNumber,
307 UserId: relevantDomain.UserId, 340 UserId: relevantDomain.UserId,
308 UserBaseId: relevantDomain.UserBaseId, 341 UserBaseId: relevantDomain.UserBaseId,
@@ -401,7 +434,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -401,7 +434,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
401 // 将待添加的相关人领域模型转换为数据模型 434 // 将待添加的相关人领域模型转换为数据模型
402 var cooperationContractUndertakersToAddModels []*models.CooperationContractUndertaker 435 var cooperationContractUndertakersToAddModels []*models.CooperationContractUndertaker
403 for _, undertakerDomain := range cooperationContractUndertakersToAdd { 436 for _, undertakerDomain := range cooperationContractUndertakersToAdd {
  437 + if undertakerDomain.Identify() == nil {
  438 + undertakerId, err := repository.nextIdentify()
  439 + if err != nil {
  440 + return nil, err
  441 + } else {
  442 + undertakerDomain.UndertakerId = undertakerId
  443 + }
  444 + }
404 cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{ 445 cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{
  446 + CooperationContractUndertakerId: undertakerDomain.UndertakerId,
405 CooperationContractNumber: undertakerDomain.CooperationContractNumber, 447 CooperationContractNumber: undertakerDomain.CooperationContractNumber,
406 UserId: undertakerDomain.UserId, 448 UserId: undertakerDomain.UserId,
407 UserBaseId: undertakerDomain.UserBaseId, 449 UserBaseId: undertakerDomain.UserBaseId,
@@ -534,7 +576,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -534,7 +576,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
534 // 将待添加的分红激励规则领域模型转换为数据模型 576 // 将待添加的分红激励规则领域模型转换为数据模型
535 var dividendsIncentivesRulesToAddModels []*models.DividendsIncentivesRule 577 var dividendsIncentivesRulesToAddModels []*models.DividendsIncentivesRule
536 for _, dividendsIncentivesRuleDomain := range dividendsIncentivesRulesToAdd { 578 for _, dividendsIncentivesRuleDomain := range dividendsIncentivesRulesToAdd {
  579 + if dividendsIncentivesRuleDomain.Identify() == nil {
  580 + ruleId, err := repository.nextIdentify()
  581 + if err != nil {
  582 + return nil, err
  583 + } else {
  584 + dividendsIncentivesRuleDomain.DividendsIncentivesRuleId = ruleId
  585 + }
  586 + }
537 dividendsIncentivesRulesToAddModels = append(dividendsIncentivesRulesToAddModels, &models.DividendsIncentivesRule{ 587 dividendsIncentivesRulesToAddModels = append(dividendsIncentivesRulesToAddModels, &models.DividendsIncentivesRule{
  588 + DividendsIncentivesRuleId: dividendsIncentivesRuleDomain.DividendsIncentivesRuleId,
538 CooperationContractNumber: dividendsIncentivesRuleDomain.CooperationContractNumber, 589 CooperationContractNumber: dividendsIncentivesRuleDomain.CooperationContractNumber,
539 ReferrerPercentage: dividendsIncentivesRuleDomain.ReferrerPercentage, 590 ReferrerPercentage: dividendsIncentivesRuleDomain.ReferrerPercentage,
540 SalesmanPercentage: dividendsIncentivesRuleDomain.SalesmanPercentage, 591 SalesmanPercentage: dividendsIncentivesRuleDomain.SalesmanPercentage,
@@ -657,7 +708,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -657,7 +708,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
657 // 将待添加的金额激励规则领域模型转换为数据模型 708 // 将待添加的金额激励规则领域模型转换为数据模型
658 var moneyIncentivesRulesToAddModels []*models.MoneyIncentivesRule 709 var moneyIncentivesRulesToAddModels []*models.MoneyIncentivesRule
659 for _, moneyIncentivesRuleDomain := range moneyIncentivesRulesToAdd { 710 for _, moneyIncentivesRuleDomain := range moneyIncentivesRulesToAdd {
  711 + if moneyIncentivesRuleDomain.Identify() == nil {
  712 + ruleId, err := repository.nextIdentify()
  713 + if err != nil {
  714 + return nil, err
  715 + } else {
  716 + moneyIncentivesRuleDomain.MoneyIncentivesRuleId = ruleId
  717 + }
  718 + }
660 moneyIncentivesRulesToAddModels = append(moneyIncentivesRulesToAddModels, &models.MoneyIncentivesRule{ 719 moneyIncentivesRulesToAddModels = append(moneyIncentivesRulesToAddModels, &models.MoneyIncentivesRule{
  720 + MoneyIncentivesRuleId: moneyIncentivesRuleDomain.MoneyIncentivesRuleId,
661 CooperationContractNumber: moneyIncentivesRuleDomain.CooperationContractNumber, 721 CooperationContractNumber: moneyIncentivesRuleDomain.CooperationContractNumber,
662 MoneyIncentivesAmount: moneyIncentivesRuleDomain.MoneyIncentivesAmount, 722 MoneyIncentivesAmount: moneyIncentivesRuleDomain.MoneyIncentivesAmount,
663 MoneyIncentivesStage: moneyIncentivesRuleDomain.MoneyIncentivesStage, 723 MoneyIncentivesStage: moneyIncentivesRuleDomain.MoneyIncentivesStage,
@@ -1175,8 +1235,13 @@ func NewCooperationContractRepository(transactionContext *pgTransaction.Transact @@ -1175,8 +1235,13 @@ func NewCooperationContractRepository(transactionContext *pgTransaction.Transact
1175 if transactionContext == nil { 1235 if transactionContext == nil {
1176 return nil, fmt.Errorf("transactionContext参数不能为nil") 1236 return nil, fmt.Errorf("transactionContext参数不能为nil")
1177 } else { 1237 } else {
  1238 + idWorker, err := snowflake.NewIdWorker(1)
  1239 + if err != nil {
  1240 + return nil, err
  1241 + }
1178 return &CooperationContractRepository{ 1242 return &CooperationContractRepository{
1179 transactionContext: transactionContext, 1243 transactionContext: transactionContext,
  1244 + IdWorker: idWorker,
1180 }, nil 1245 }, nil
1181 } 1246 }
1182 } 1247 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type CooperationContractUndertakerRepository struct { 16 type CooperationContractUndertakerRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *CooperationContractUndertakerRepository) nextIdentify() (int64, error) { 21 func (repository *CooperationContractUndertakerRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -225,8 +222,13 @@ func NewCooperationContractUndertakerRepository(transactionContext *pgTransactio @@ -225,8 +222,13 @@ func NewCooperationContractUndertakerRepository(transactionContext *pgTransactio
225 if transactionContext == nil { 222 if transactionContext == nil {
226 return nil, fmt.Errorf("transactionContext参数不能为nil") 223 return nil, fmt.Errorf("transactionContext参数不能为nil")
227 } else { 224 } else {
  225 + idWorker, err := snowflake.NewIdWorker(1)
  226 + if err != nil {
  227 + return nil, err
  228 + }
228 return &CooperationContractUndertakerRepository{ 229 return &CooperationContractUndertakerRepository{
229 transactionContext: transactionContext, 230 transactionContext: transactionContext,
  231 + IdWorker: idWorker,
230 }, nil 232 }, nil
231 } 233 }
232 } 234 }
@@ -14,14 +14,11 @@ import ( @@ -14,14 +14,11 @@ import (
14 14
15 type CooperationModeRepository struct { 15 type CooperationModeRepository struct {
16 transactionContext *pgTransaction.TransactionContext 16 transactionContext *pgTransaction.TransactionContext
  17 + IdWorker *snowflake.IdWorker
17 } 18 }
18 19
19 func (repository *CooperationModeRepository) nextIdentify() (int64, error) { 20 func (repository *CooperationModeRepository) nextIdentify() (int64, error) {
20 - IdWorker, err := snowflake.NewIdWorker(1)  
21 - if err != nil {  
22 - return 0, err  
23 - }  
24 - id, err := IdWorker.NextId() 21 + id, err := repository.IdWorker.NextId()
25 return id, err 22 return id, err
26 } 23 }
27 24
@@ -221,8 +218,13 @@ func NewCooperationModeRepository(transactionContext *pgTransaction.TransactionC @@ -221,8 +218,13 @@ func NewCooperationModeRepository(transactionContext *pgTransaction.TransactionC
221 if transactionContext == nil { 218 if transactionContext == nil {
222 return nil, fmt.Errorf("transactionContext参数不能为nil") 219 return nil, fmt.Errorf("transactionContext参数不能为nil")
223 } else { 220 } else {
  221 + idWorker, err := snowflake.NewIdWorker(1)
  222 + if err != nil {
  223 + return nil, err
  224 + }
224 return &CooperationModeRepository{ 225 return &CooperationModeRepository{
225 transactionContext: transactionContext, 226 transactionContext: transactionContext,
  227 + IdWorker: idWorker,
226 }, nil 228 }, nil
227 } 229 }
228 } 230 }
@@ -17,14 +17,11 @@ import ( @@ -17,14 +17,11 @@ import (
17 17
18 type CooperationProjectRepository struct { 18 type CooperationProjectRepository struct {
19 transactionContext *pgTransaction.TransactionContext 19 transactionContext *pgTransaction.TransactionContext
  20 + IdWorker *snowflake.IdWorker
20 } 21 }
21 22
22 func (repository *CooperationProjectRepository) nextIdentify() (int64, error) { 23 func (repository *CooperationProjectRepository) nextIdentify() (int64, error) {
23 - IdWorker, err := snowflake.NewIdWorker(1)  
24 - if err != nil {  
25 - return 0, err  
26 - }  
27 - id, err := IdWorker.NextId() 24 + id, err := repository.IdWorker.NextId()
28 return id, err 25 return id, err
29 } 26 }
30 27
@@ -317,8 +314,13 @@ func NewCooperationProjectRepository(transactionContext *pgTransaction.Transacti @@ -317,8 +314,13 @@ func NewCooperationProjectRepository(transactionContext *pgTransaction.Transacti
317 if transactionContext == nil { 314 if transactionContext == nil {
318 return nil, fmt.Errorf("transactionContext参数不能为nil") 315 return nil, fmt.Errorf("transactionContext参数不能为nil")
319 } else { 316 } else {
  317 + idWorker, err := snowflake.NewIdWorker(1)
  318 + if err != nil {
  319 + return nil, err
  320 + }
320 return &CooperationProjectRepository{ 321 return &CooperationProjectRepository{
321 transactionContext: transactionContext, 322 transactionContext: transactionContext,
  323 + IdWorker: idWorker,
322 }, nil 324 }, nil
323 } 325 }
324 } 326 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type CreditAccountRepository struct { 16 type CreditAccountRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *CreditAccountRepository) nextIdentify() (int64, error) { 21 func (repository *CreditAccountRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -249,8 +246,13 @@ func NewCreditAccountRepository(transactionContext *pgTransaction.TransactionCon @@ -249,8 +246,13 @@ func NewCreditAccountRepository(transactionContext *pgTransaction.TransactionCon
249 if transactionContext == nil { 246 if transactionContext == nil {
250 return nil, fmt.Errorf("transactionContext参数不能为nil") 247 return nil, fmt.Errorf("transactionContext参数不能为nil")
251 } else { 248 } else {
  249 + idWorker, err := snowflake.NewIdWorker(1)
  250 + if err != nil {
  251 + return nil, err
  252 + }
252 return &CreditAccountRepository{ 253 return &CreditAccountRepository{
253 transactionContext: transactionContext, 254 transactionContext: transactionContext,
  255 + IdWorker: idWorker,
254 }, nil 256 }, nil
255 } 257 }
256 } 258 }
@@ -16,14 +16,11 @@ import ( @@ -16,14 +16,11 @@ import (
16 16
17 type DividendsEstimateRepository struct { 17 type DividendsEstimateRepository struct {
18 transactionContext *pgTransaction.TransactionContext 18 transactionContext *pgTransaction.TransactionContext
  19 + IdWorker *snowflake.IdWorker
19 } 20 }
20 21
21 func (repository *DividendsEstimateRepository) nextIdentify() (int64, error) { 22 func (repository *DividendsEstimateRepository) nextIdentify() (int64, error) {
22 - IdWorker, err := snowflake.NewIdWorker(1)  
23 - if err != nil {  
24 - return 0, err  
25 - }  
26 - id, err := IdWorker.NextId() 23 + id, err := repository.IdWorker.NextId()
27 return id, err 24 return id, err
28 } 25 }
29 26
@@ -332,8 +329,13 @@ func NewDividendsEstimateRepository(transactionContext *pgTransaction.Transactio @@ -332,8 +329,13 @@ func NewDividendsEstimateRepository(transactionContext *pgTransaction.Transactio
332 if transactionContext == nil { 329 if transactionContext == nil {
333 return nil, fmt.Errorf("transactionContext参数不能为nil") 330 return nil, fmt.Errorf("transactionContext参数不能为nil")
334 } else { 331 } else {
  332 + idWorker, err := snowflake.NewIdWorker(1)
  333 + if err != nil {
  334 + return nil, err
  335 + }
335 return &DividendsEstimateRepository{ 336 return &DividendsEstimateRepository{
336 transactionContext: transactionContext, 337 transactionContext: transactionContext,
  338 + IdWorker: idWorker,
337 }, nil 339 }, nil
338 } 340 }
339 } 341 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type DividendsIncentivesRuleRepository struct { 16 type DividendsIncentivesRuleRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *DividendsIncentivesRuleRepository) nextIdentify() (int64, error) { 21 func (repository *DividendsIncentivesRuleRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -202,8 +199,13 @@ func NewDividendsIncentivesRuleRepository(transactionContext *pgTransaction.Tran @@ -202,8 +199,13 @@ func NewDividendsIncentivesRuleRepository(transactionContext *pgTransaction.Tran
202 if transactionContext == nil { 199 if transactionContext == nil {
203 return nil, fmt.Errorf("transactionContext参数不能为nil") 200 return nil, fmt.Errorf("transactionContext参数不能为nil")
204 } else { 201 } else {
  202 + idWorker, err := snowflake.NewIdWorker(1)
  203 + if err != nil {
  204 + return nil, err
  205 + }
205 return &DividendsIncentivesRuleRepository{ 206 return &DividendsIncentivesRuleRepository{
206 transactionContext: transactionContext, 207 transactionContext: transactionContext,
  208 + IdWorker: idWorker,
207 }, nil 209 }, nil
208 } 210 }
209 } 211 }
@@ -178,7 +178,11 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -178,7 +178,11 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
178 // 更新分红订单产品 178 // 更新分红订单产品
179 var orderGoodsFetched []*models.OrderGood 179 var orderGoodsFetched []*models.OrderGood
180 orderGoodsQuery := tx.Model(&orderGoodsFetched) 180 orderGoodsQuery := tx.Model(&orderGoodsFetched)
181 - if err := orderGoodsQuery.Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Select(); err != nil { 181 + if err := orderGoodsQuery.
  182 + Where("company_id = ?", dividendsOrder.Company.CompanyId).
  183 + Where("org_id = ?", dividendsOrder.Org.OrgId).
  184 + Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).
  185 + Select(); err != nil {
182 return nil, err 186 return nil, err
183 } 187 }
184 188
@@ -190,6 +194,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -190,6 +194,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
190 194
191 // 待更新分红产品 195 // 待更新分红产品
192 var orderGoodsToUpdate []*domain.OrderGood 196 var orderGoodsToUpdate []*domain.OrderGood
  197 +
193 // 待添加分红产品 198 // 待添加分红产品
194 var orderGoodsToAdd []*domain.OrderGood 199 var orderGoodsToAdd []*domain.OrderGood
195 for _, good := range dividendsOrder.Goods { 200 for _, good := range dividendsOrder.Goods {
@@ -230,10 +235,10 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -230,10 +235,10 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
230 }) 235 })
231 } 236 }
232 // 添加分红订单产品 237 // 添加分红订单产品
  238 + if len(orderGoodsToAddModels) > 0 {
233 log.Logger.Info("待添加的分红订单产品", map[string]interface{}{ 239 log.Logger.Info("待添加的分红订单产品", map[string]interface{}{
234 "orderGoodsToAddModels": orderGoodsToAddModels, 240 "orderGoodsToAddModels": orderGoodsToAddModels,
235 }) 241 })
236 - if len(orderGoodsToAddModels) > 0 {  
237 if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil { 242 if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil {
238 return nil, err 243 return nil, err
239 } 244 }
@@ -491,6 +496,12 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte @@ -491,6 +496,12 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
491 if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" { 496 if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
492 query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber) 497 query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber)
493 } 498 }
  499 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  500 + query.Where("company->>'companyId' = '?'", companyId)
  501 + }
  502 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  503 + query.Where("org->>'orgId' = '?'", orgId)
  504 + }
494 if err := query.First(); err != nil { 505 if err := query.First(); err != nil {
495 if err.Error() == "pg: no rows in result set" { 506 if err.Error() == "pg: no rows in result set" {
496 return nil, fmt.Errorf("分红订单不存在") 507 return nil, fmt.Errorf("分红订单不存在")
@@ -475,7 +475,8 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne @@ -475,7 +475,8 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne
475 if _, err := tx.Model(&orderGoodModels). 475 if _, err := tx.Model(&orderGoodModels).
476 Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId). 476 Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
477 Where("org_id = ?", dividendsReturnedOrder.Org.OrgId). 477 Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
478 - Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil { 478 + Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).
  479 + Delete(); err != nil {
479 return nil, err 480 return nil, err
480 } 481 }
481 } 482 }
@@ -505,7 +506,8 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str @@ -505,7 +506,8 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
505 if err := orderGoodModelQuery. 506 if err := orderGoodModelQuery.
506 Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId). 507 Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId).
507 Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId). 508 Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
508 - Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil { 509 + Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).
  510 + Select(); err != nil {
509 return nil, fmt.Errorf("分红退货单关联的产品不存在") 511 return nil, fmt.Errorf("分红退货单关联的产品不存在")
510 } 512 }
511 // 聚合分红退货单 513 // 聚合分红退货单
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type MoneyIncentivesRuleRepository struct { 16 type MoneyIncentivesRuleRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *MoneyIncentivesRuleRepository) nextIdentify() (int64, error) { 21 func (repository *MoneyIncentivesRuleRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -202,8 +199,13 @@ func NewMoneyIncentivesRuleRepository(transactionContext *pgTransaction.Transact @@ -202,8 +199,13 @@ func NewMoneyIncentivesRuleRepository(transactionContext *pgTransaction.Transact
202 if transactionContext == nil { 199 if transactionContext == nil {
203 return nil, fmt.Errorf("transactionContext参数不能为nil") 200 return nil, fmt.Errorf("transactionContext参数不能为nil")
204 } else { 201 } else {
  202 + idWorker, err := snowflake.NewIdWorker(1)
  203 + if err != nil {
  204 + return nil, err
  205 + }
205 return &MoneyIncentivesRuleRepository{ 206 return &MoneyIncentivesRuleRepository{
206 transactionContext: transactionContext, 207 transactionContext: transactionContext,
  208 + IdWorker: idWorker,
207 }, nil 209 }, nil
208 } 210 }
209 } 211 }