作者 陈志颖

refactor:优化共创合约仓储

@@ -60,35 +60,39 @@ func TransformToCooperationContractDomainModelFromPgModels( @@ -60,35 +60,39 @@ func TransformToCooperationContractDomainModelFromPgModels(
60 var relevantPeopleDomain []*domain.Relevant 60 var relevantPeopleDomain []*domain.Relevant
61 for _, relevant := range relevantPeople { 61 for _, relevant := range relevantPeople {
62 relevantPeopleDomain = append(relevantPeopleDomain, &domain.Relevant{ 62 relevantPeopleDomain = append(relevantPeopleDomain, &domain.Relevant{
63 - UserId: relevant.UserId,  
64 - UserBaseId: relevant.UserBaseId,  
65 - Org: relevant.Org,  
66 - Orgs: relevant.Orgs,  
67 - Department: relevant.Department,  
68 - Roles: relevant.Roles,  
69 - UserInfo: relevant.UserInfo,  
70 - UserType: relevant.UserType,  
71 - Status: relevant.Status,  
72 - Company: relevant.Company, 63 + RelevantId: relevant.CooperationContractRelevantId,
  64 + CooperationContractNumber: relevant.CooperationContractNumber,
  65 + UserId: relevant.UserId,
  66 + UserBaseId: relevant.UserBaseId,
  67 + Org: relevant.Org,
  68 + Orgs: relevant.Orgs,
  69 + Department: relevant.Department,
  70 + Roles: relevant.Roles,
  71 + UserInfo: relevant.UserInfo,
  72 + UserType: relevant.UserType,
  73 + Status: relevant.Status,
  74 + Company: relevant.Company,
73 }) 75 })
74 } 76 }
75 // 承接人列表 77 // 承接人列表
76 var undertakersDomain []*domain.Undertaker 78 var undertakersDomain []*domain.Undertaker
77 for _, undertaker := range undertakers { 79 for _, undertaker := range undertakers {
78 undertakersDomain = append(undertakersDomain, &domain.Undertaker{ 80 undertakersDomain = append(undertakersDomain, &domain.Undertaker{
79 - UserId: undertaker.UserId,  
80 - UserBaseId: undertaker.UserBaseId,  
81 - Org: undertaker.Org,  
82 - Orgs: undertaker.Orgs,  
83 - Department: undertaker.Department,  
84 - Roles: undertaker.Roles,  
85 - Referrer: undertaker.Referrer,  
86 - Salesman: undertaker.Salesman,  
87 - UserInfo: undertaker.UserInfo,  
88 - UserType: undertaker.UserType,  
89 - Status: undertaker.Status,  
90 - Company: undertaker.Company,  
91 - ContractAttachment: undertaker.ContractAttachment, 81 + UndertakerId: undertaker.CooperationContractUndertakerId,
  82 + CooperationContractNumber: undertaker.CooperationContractNumber,
  83 + UserId: undertaker.UserId,
  84 + UserBaseId: undertaker.UserBaseId,
  85 + Org: undertaker.Org,
  86 + Orgs: undertaker.Orgs,
  87 + Department: undertaker.Department,
  88 + Roles: undertaker.Roles,
  89 + Referrer: undertaker.Referrer,
  90 + Salesman: undertaker.Salesman,
  91 + UserInfo: undertaker.UserInfo,
  92 + UserType: undertaker.UserType,
  93 + Status: undertaker.Status,
  94 + Company: undertaker.Company,
  95 + ContractAttachment: undertaker.ContractAttachment,
92 }) 96 })
93 } 97 }
94 return &domain.CooperationContract{ 98 return &domain.CooperationContract{
@@ -101,6 +101,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -101,6 +101,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
101 ); err != nil { 101 ); err != nil {
102 return cooperationContract, err 102 return cooperationContract, err
103 } 103 }
  104 +
104 // 新增相关人 105 // 新增相关人
105 var relevantPeopleModel []*models.CooperationContractRelevant 106 var relevantPeopleModel []*models.CooperationContractRelevant
106 for _, relevant := range cooperationContract.RelevantPeople { 107 for _, relevant := range cooperationContract.RelevantPeople {
@@ -116,14 +117,18 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -116,14 +117,18 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
116 UserType: relevant.UserType, 117 UserType: relevant.UserType,
117 Status: relevant.Status, 118 Status: relevant.Status,
118 Company: relevant.Company, 119 Company: relevant.Company,
119 - UpdatedAt: time.Now(), 120 + UpdatedAt: time.Time{},
120 DeletedAt: time.Time{}, 121 DeletedAt: time.Time{},
121 - CreatedAt: time.Time{}, 122 + CreatedAt: time.Now(),
122 }) 123 })
123 } 124 }
124 if len(relevantPeopleModel) > 0 { 125 if len(relevantPeopleModel) > 0 {
125 - if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil { 126 + if result, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
126 return nil, err 127 return nil, err
  128 + } else {
  129 + log.Logger.Info("新增的相关人", map[string]interface{}{
  130 + "relevantPeopleModel": result,
  131 + })
127 } 132 }
128 } 133 }
129 134
@@ -640,7 +645,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -640,7 +645,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
640 } 645 }
641 } 646 }
642 } 647 }
643 - return cooperationContract, nil 648 + // 返回新增的合约
  649 + cooperationContractSaved, err := repository.FindOne(map[string]interface{}{
  650 + "cooperationContractId":cooperationContract.CooperationContractId,
  651 + })
  652 + if err != nil {
  653 + return nil, err
  654 + }
  655 + return cooperationContractSaved, nil
644 } 656 }
645 657
646 func (repository *CooperationContractRepository) UpdateOne(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) { 658 func (repository *CooperationContractRepository) UpdateOne(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {