作者 陈志颖

refactor:优化共创合约仓储

... ... @@ -60,6 +60,8 @@ func TransformToCooperationContractDomainModelFromPgModels(
var relevantPeopleDomain []*domain.Relevant
for _, relevant := range relevantPeople {
relevantPeopleDomain = append(relevantPeopleDomain, &domain.Relevant{
RelevantId: relevant.CooperationContractRelevantId,
CooperationContractNumber: relevant.CooperationContractNumber,
UserId: relevant.UserId,
UserBaseId: relevant.UserBaseId,
Org: relevant.Org,
... ... @@ -76,6 +78,8 @@ func TransformToCooperationContractDomainModelFromPgModels(
var undertakersDomain []*domain.Undertaker
for _, undertaker := range undertakers {
undertakersDomain = append(undertakersDomain, &domain.Undertaker{
UndertakerId: undertaker.CooperationContractUndertakerId,
CooperationContractNumber: undertaker.CooperationContractNumber,
UserId: undertaker.UserId,
UserBaseId: undertaker.UserBaseId,
Org: undertaker.Org,
... ...
... ... @@ -101,6 +101,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
); err != nil {
return cooperationContract, err
}
// 新增相关人
var relevantPeopleModel []*models.CooperationContractRelevant
for _, relevant := range cooperationContract.RelevantPeople {
... ... @@ -116,14 +117,18 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
UserType: relevant.UserType,
Status: relevant.Status,
Company: relevant.Company,
UpdatedAt: time.Now(),
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Time{},
CreatedAt: time.Now(),
})
}
if len(relevantPeopleModel) > 0 {
if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
if result, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
return nil, err
} else {
log.Logger.Info("新增的相关人", map[string]interface{}{
"relevantPeopleModel": result,
})
}
}
... ... @@ -640,7 +645,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
return cooperationContract, nil
// 返回新增的合约
cooperationContractSaved, err := repository.FindOne(map[string]interface{}{
"cooperationContractId":cooperationContract.CooperationContractId,
})
if err != nil {
return nil, err
}
return cooperationContractSaved, nil
}
func (repository *CooperationContractRepository) UpdateOne(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
... ...