作者 陈志颖

fix:共创合约变更记录

@@ -1019,14 +1019,14 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1019,14 +1019,14 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1019 CooperationContractNumber: cooperationContract.CooperationContractNumber, 1019 CooperationContractNumber: cooperationContract.CooperationContractNumber,
1020 UserId: relevantDomain.UserId, 1020 UserId: relevantDomain.UserId,
1021 UserBaseId: relevantDomain.UserBaseId, 1021 UserBaseId: relevantDomain.UserBaseId,
1022 - Org: relevantDomain.Org, 1022 + Org: organization,
1023 Orgs: relevantDomain.Orgs, 1023 Orgs: relevantDomain.Orgs,
1024 Department: relevantDomain.Department, 1024 Department: relevantDomain.Department,
1025 Roles: relevantDomain.Roles, 1025 Roles: relevantDomain.Roles,
1026 UserInfo: relevantDomain.UserInfo, 1026 UserInfo: relevantDomain.UserInfo,
1027 UserType: relevantDomain.UserType, 1027 UserType: relevantDomain.UserType,
1028 Status: relevantDomain.Status, 1028 Status: relevantDomain.Status,
1029 - Company: relevantDomain.Company, 1029 + Company: company,
1030 }) 1030 })
1031 } 1031 }
1032 1032
@@ -1114,7 +1114,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1114,7 +1114,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1114 CooperationContractNumber: cooperationContract.CooperationContractNumber, 1114 CooperationContractNumber: cooperationContract.CooperationContractNumber,
1115 CooperationContractId: cooperationContract.CooperationContractId, 1115 CooperationContractId: cooperationContract.CooperationContractId,
1116 UserBaseId: undertakerDomain.UserBaseId, 1116 UserBaseId: undertakerDomain.UserBaseId,
1117 - Org: undertakerDomain.Org, 1117 + Org: organization,
1118 Orgs: undertakerDomain.Orgs, 1118 Orgs: undertakerDomain.Orgs,
1119 Department: undertakerDomain.Department, 1119 Department: undertakerDomain.Department,
1120 Roles: undertakerDomain.Roles, 1120 Roles: undertakerDomain.Roles,
@@ -1123,7 +1123,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1123,7 +1123,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1123 Referrer: referrerDomain, 1123 Referrer: referrerDomain,
1124 Salesman: salesmanDomain, 1124 Salesman: salesmanDomain,
1125 Status: undertakerDomain.Status, 1125 Status: undertakerDomain.Status,
1126 - Company: undertakerDomain.Company, 1126 + Company: company,
1127 ContractAttachment: contractAttachments, 1127 ContractAttachment: contractAttachments,
1128 }) 1128 })
1129 } 1129 }
@@ -1275,7 +1275,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1275,7 +1275,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1275 for _, rule := range cooperationContractFound.DividendsIncentivesRules { 1275 for _, rule := range cooperationContractFound.DividendsIncentivesRules {
1276 jsons, errs := json.Marshal(rule) 1276 jsons, errs := json.Marshal(rule)
1277 if errs != nil { 1277 if errs != nil {
1278 - (errs.Error()) 1278 + fmt.Printf(errs.Error())
1279 } 1279 }
1280 cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...) 1280 cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
1281 } 1281 }
@@ -1288,7 +1288,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1288,7 +1288,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1288 for _, rule := range cooperationContract.DividendsIncentivesRules { 1288 for _, rule := range cooperationContract.DividendsIncentivesRules {
1289 jsons, errs := json.Marshal(rule) 1289 jsons, errs := json.Marshal(rule)
1290 if errs != nil { 1290 if errs != nil {
1291 - (errs.Error()) 1291 + fmt.Printf(errs.Error())
1292 } 1292 }
1293 cooperationContractBytes = append(cooperationContractBytes, jsons...) 1293 cooperationContractBytes = append(cooperationContractBytes, jsons...)
1294 } 1294 }
@@ -1331,7 +1331,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1331,7 +1331,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1331 for _, rule := range cooperationContractFound.MoneyIncentivesRules { 1331 for _, rule := range cooperationContractFound.MoneyIncentivesRules {
1332 jsons, errs := json.Marshal(rule) 1332 jsons, errs := json.Marshal(rule)
1333 if errs != nil { 1333 if errs != nil {
1334 - (errs.Error()) 1334 + fmt.Printf(errs.Error())
1335 } 1335 }
1336 cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...) 1336 cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
1337 } 1337 }
@@ -1344,7 +1344,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1344,7 +1344,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1344 for _, rule := range cooperationContract.MoneyIncentivesRules { 1344 for _, rule := range cooperationContract.MoneyIncentivesRules {
1345 jsons, errs := json.Marshal(rule) 1345 jsons, errs := json.Marshal(rule)
1346 if errs != nil { 1346 if errs != nil {
1347 - (errs.Error()) 1347 + fmt.Printf(errs.Error())
1348 } 1348 }
1349 cooperationContractBytes = append(cooperationContractBytes, jsons...) 1349 cooperationContractBytes = append(cooperationContractBytes, jsons...)
1350 } 1350 }
@@ -1388,7 +1388,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1388,7 +1388,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1388 for _, undertaker := range cooperationContractFound.Undertakers { 1388 for _, undertaker := range cooperationContractFound.Undertakers {
1389 jsons, errs := json.Marshal(undertaker) 1389 jsons, errs := json.Marshal(undertaker)
1390 if errs != nil { 1390 if errs != nil {
1391 - (errs.Error()) 1391 + fmt.Printf(errs.Error())
1392 } 1392 }
1393 cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...) 1393 cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
1394 } 1394 }
@@ -1400,7 +1400,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1400,7 +1400,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1400 for _, undertaker := range cooperationContract.Undertakers { 1400 for _, undertaker := range cooperationContract.Undertakers {
1401 jsons, errs := json.Marshal(undertaker) //转换成JSON返回的是byte[] 1401 jsons, errs := json.Marshal(undertaker) //转换成JSON返回的是byte[]
1402 if errs != nil { 1402 if errs != nil {
1403 - (errs.Error()) 1403 + fmt.Printf(errs.Error())
1404 } 1404 }
1405 cooperationContractBytes = append(cooperationContractBytes, jsons...) 1405 cooperationContractBytes = append(cooperationContractBytes, jsons...)
1406 } 1406 }
@@ -1501,9 +1501,11 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1501,9 +1501,11 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1501 } 1501 }
1502 1502
1503 // 保存共创合约变更记录 1503 // 保存共创合约变更记录
  1504 + if newCooperationContractChangeLog.IncentivesRule != "" || newCooperationContractChangeLog.IncentivesRuleDetail != "" || newCooperationContractChangeLog.Undertakers != "" {
1504 if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil { 1505 if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
1505 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error()) 1506 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
1506 } 1507 }
  1508 + }
1507 if err21 := transactionContext.CommitTransaction(); err21 != nil { 1509 if err21 := transactionContext.CommitTransaction(); err21 != nil {
1508 return nil, application.ThrowError(application.TRANSACTION_ERROR, err21.Error()) 1510 return nil, application.ThrowError(application.TRANSACTION_ERROR, err21.Error())
1509 } 1511 }
@@ -82,6 +82,7 @@ func TransformToCooperationContractDomainModelFromPgModels( @@ -82,6 +82,7 @@ func TransformToCooperationContractDomainModelFromPgModels(
82 undertakersDomain = append(undertakersDomain, &domain.Undertaker{ 82 undertakersDomain = append(undertakersDomain, &domain.Undertaker{
83 UndertakerId: undertaker.CooperationContractUndertakerId, 83 UndertakerId: undertaker.CooperationContractUndertakerId,
84 CooperationContractNumber: undertaker.CooperationContractNumber, 84 CooperationContractNumber: undertaker.CooperationContractNumber,
  85 + CooperationContractId: undertaker.CooperationContractId,
85 UserId: undertaker.UserId, 86 UserId: undertaker.UserId,
86 UserBaseId: undertaker.UserBaseId, 87 UserBaseId: undertaker.UserBaseId,
87 Org: undertaker.Org, 88 Org: undertaker.Org,
@@ -327,9 +327,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -327,9 +327,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
327 var cooperationContractRelevantPeopleToAdd []*domain.Relevant 327 var cooperationContractRelevantPeopleToAdd []*domain.Relevant
328 for _, relevant := range cooperationContract.RelevantPeople { 328 for _, relevant := range cooperationContract.RelevantPeople {
329 if relevant.RelevantId != 0 { 329 if relevant.RelevantId != 0 {
330 - cooperationContractRelevantPeopleToUpdate = append(cooperationContractRelevantPeopleToUpdate, relevant) 330 + cooperationContractRelevantPeopleToUpdate = append(cooperationContractRelevantPeopleToUpdate, relevant) // 提取待更新的相关人
331 } else { 331 } else {
332 - cooperationContractRelevantPeopleToAdd = append(cooperationContractRelevantPeopleToAdd, relevant) 332 + cooperationContractRelevantPeopleToAdd = append(cooperationContractRelevantPeopleToAdd, relevant) // 提取待添加的相关人
333 } 333 }
334 } 334 }
335 335
@@ -379,13 +379,41 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -379,13 +379,41 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
379 // 待更新的相关人id 379 // 待更新的相关人id
380 relevantIdsToUpdate := utils.Intersect(cooperationContractRelevantIdsFetched, cooperationContractRelevantPeopleToUpdateOrDeleteIds) 380 relevantIdsToUpdate := utils.Intersect(cooperationContractRelevantIdsFetched, cooperationContractRelevantPeopleToUpdateOrDeleteIds)
381 var relevantModelsToUpdate []*models.CooperationContractRelevant 381 var relevantModelsToUpdate []*models.CooperationContractRelevant
  382 + var relevantDomainsToUpdate []*domain.Relevant
382 for _, id := range relevantIdsToUpdate { 383 for _, id := range relevantIdsToUpdate {
383 - for _, relevantModel := range cooperationContractRelevantModelsFetched {  
384 - if relevantModel.CooperationContractRelevantId == id {  
385 - relevantModelsToUpdate = append(relevantModelsToUpdate, relevantModel) 384 + //for _, relevantModel := range cooperationContractRelevantModelsFetched {
  385 + // if relevantModel.CooperationContractRelevantId == id {
  386 + // relevantModelsToUpdate = append(relevantModelsToUpdate, relevantModel)
  387 + // }
  388 + //}
  389 + for _, relevantDomain := range cooperationContract.RelevantPeople {
  390 + if relevantDomain.RelevantId == id {
  391 + relevantDomainsToUpdate = append(relevantDomainsToUpdate, relevantDomain)
386 } 392 }
387 } 393 }
388 } 394 }
  395 +
  396 + // domain to model
  397 + for _, relevantDomainToUpdate := range relevantDomainsToUpdate {
  398 + relevantModelsToUpdate = append(relevantModelsToUpdate, &models.CooperationContractRelevant{
  399 + CooperationContractRelevantId: relevantDomainToUpdate.RelevantId,
  400 + CooperationContractNumber: relevantDomainToUpdate.CooperationContractNumber,
  401 + UserId: relevantDomainToUpdate.UserId,
  402 + UserBaseId: relevantDomainToUpdate.UserBaseId,
  403 + Org: relevantDomainToUpdate.Org,
  404 + Orgs: relevantDomainToUpdate.Orgs,
  405 + Department: relevantDomainToUpdate.Department,
  406 + Roles: relevantDomainToUpdate.Roles,
  407 + UserInfo: relevantDomainToUpdate.UserInfo,
  408 + UserType: relevantDomainToUpdate.UserType,
  409 + Status: relevantDomainToUpdate.Status,
  410 + Company: relevantDomainToUpdate.Company,
  411 + UpdatedAt: time.Now(),
  412 + DeletedAt: time.Time{},
  413 + CreatedAt: time.Time{},
  414 + })
  415 + }
  416 +
389 if len(relevantModelsToUpdate) > 0 { 417 if len(relevantModelsToUpdate) > 0 {
390 if _, err := tx.Model(&relevantModelsToUpdate).WherePK().Update(); err != nil { 418 if _, err := tx.Model(&relevantModelsToUpdate).WherePK().Update(); err != nil {
391 return nil, err 419 return nil, err
@@ -410,6 +438,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -410,6 +438,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
410 return nil, err 438 return nil, err
411 } 439 }
412 } 440 }
  441 + /***************************************************************/
413 442
414 /************************* 更新承接人 ****************************/ 443 /************************* 更新承接人 ****************************/
415 // 获取承接人列表 444 // 获取承接人列表
@@ -431,6 +460,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -431,6 +460,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
431 460
432 // 待更新相关人 461 // 待更新相关人
433 var cooperationContractUndertakersToUpdate []*domain.Undertaker 462 var cooperationContractUndertakersToUpdate []*domain.Undertaker
  463 +
434 // 待添加相关人 464 // 待添加相关人
435 var cooperationContractUndertakersToAdd []*domain.Undertaker 465 var cooperationContractUndertakersToAdd []*domain.Undertaker
436 for _, undertaker := range cooperationContract.Undertakers { 466 for _, undertaker := range cooperationContract.Undertakers {
@@ -554,6 +584,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -554,6 +584,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
554 return nil, err 584 return nil, err
555 } 585 }
556 } 586 }
  587 + /*****************************************************************/
557 588
558 /************************ 更新分红激励规则 **************************/ 589 /************************ 更新分红激励规则 **************************/
559 // 获取分红激励规则列表 590 // 获取分红激励规则列表
@@ -687,6 +718,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -687,6 +718,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
687 return nil, err 718 return nil, err
688 } 719 }
689 } 720 }
  721 + /***************************************************************/
690 722
691 /********************** 更新金额激励规则 **************************/ 723 /********************** 更新金额激励规则 **************************/
692 var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule 724 var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
@@ -12,22 +12,35 @@ import ( @@ -12,22 +12,35 @@ import (
12 12
13 // Intersect 返回两个数组的交集 13 // Intersect 返回两个数组的交集
14 func Intersect(nums1 []int64, nums2 []int64) []int64 { 14 func Intersect(nums1 []int64, nums2 []int64) []int64 {
15 - if len(nums1) > len(nums2) {  
16 - return Intersect(nums2, nums1) 15 + //if len(nums1) > len(nums2) {
  16 + // return Intersect(nums2, nums1)
  17 + //}
  18 + //m := map[int64]int64{}
  19 + //for _, num := range nums1 {
  20 + // m[num]++
  21 + //}
  22 + //
  23 + //var intersection []int64
  24 + //for _, num := range nums2 {
  25 + // if m[num] > 0 {
  26 + // intersection = append(intersection, num)
  27 + // m[num]--
  28 + // }
  29 + //}
  30 + //return intersection
  31 + m := make(map[int64]int)
  32 + nn := make([]int64, 0)
  33 + for _, v := range nums1 {
  34 + m[v]++
17 } 35 }
18 - m := map[int64]int64{}  
19 - for _, num := range nums1 {  
20 - m[num]++ 36 + for _, v := range nums2 {
  37 + times, _ := m[v]
  38 + if times > 0 {
  39 + nn = append(nn, v)
21 } 40 }
22 -  
23 - var intersection []int64  
24 - for _, num := range nums2 {  
25 - if m[num] > 0 {  
26 - intersection = append(intersection, num)  
27 - m[num]--  
28 } 41 }
29 - }  
30 - return intersection 42 + return nn
  43 +
31 } 44 }
32 45
33 // Intersect32 返回两个数组的交集 46 // Intersect32 返回两个数组的交集
@@ -52,20 +65,34 @@ func Intersect32(nums1 []int32, nums2 []int32) []int32 { @@ -52,20 +65,34 @@ func Intersect32(nums1 []int32, nums2 []int32) []int32 {
52 65
53 // Difference 求差集 slice1-并集 66 // Difference 求差集 slice1-并集
54 func Difference(slice1, slice2 []int64) []int64 { 67 func Difference(slice1, slice2 []int64) []int64 {
  68 + //m := make(map[int64]int)
  69 + //nn := make([]int64, 0)
  70 + //inter := Intersect(slice1, slice2)
  71 + //for _, v := range inter {
  72 + // m[v]++
  73 + //}
  74 + //
  75 + //for _, value := range slice1 {
  76 + // times, _ := m[value]
  77 + // if times == 0 {
  78 + // nn = append(nn, value)
  79 + // }
  80 + //}
  81 + //return nn
55 m := make(map[int64]int) 82 m := make(map[int64]int)
56 nn := make([]int64, 0) 83 nn := make([]int64, 0)
57 inter := Intersect(slice1, slice2) 84 inter := Intersect(slice1, slice2)
58 for _, v := range inter { 85 for _, v := range inter {
59 m[v]++ 86 m[v]++
60 } 87 }
61 -  
62 - for _, value := range slice1 {  
63 - times, _ := m[value] 88 + for _, v := range slice1 {
  89 + times, _ := m[v]
64 if times == 0 { 90 if times == 0 {
65 - nn = append(nn, value) 91 + nn = append(nn, v)
66 } 92 }
67 } 93 }
68 return nn 94 return nn
  95 +
69 } 96 }
70 97
71 // SliceAtoi 字符创数组转数字数组 98 // SliceAtoi 字符创数组转数字数组