...
|
...
|
@@ -9,6 +9,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -127,7 +128,19 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
|
undertakersModel = append(undertakersModel, &models.CooperationContractUndertaker{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
Undertaker: undertaker,
|
|
|
UserId: undertaker.UserId,
|
|
|
UserBaseId: undertaker.UserBaseId,
|
|
|
Org: undertaker.Org,
|
|
|
Orgs: undertaker.Orgs,
|
|
|
Department: undertaker.Department,
|
|
|
Role: undertaker.Role,
|
|
|
UserInfo: undertaker.UserInfo,
|
|
|
UserType: undertaker.UserType,
|
|
|
Referrer: undertaker.Referrer,
|
|
|
Salesman: undertaker.Salesman,
|
|
|
Status: undertaker.Status,
|
|
|
Company: undertaker.Company,
|
|
|
ContractAttachment: undertaker.ContractAttachment,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Now(),
|
...
|
...
|
@@ -224,20 +237,26 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
return cooperationContract, err
|
|
|
}
|
|
|
|
|
|
// TODO 更新相关人
|
|
|
// 更新相关人
|
|
|
|
|
|
// 查找相关人列表
|
|
|
var cooperationContractRelevantFetched []*models.CooperationContractRelevant
|
|
|
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantFetched)
|
|
|
var cooperationContractRelevantModelsFetched []*models.CooperationContractRelevant
|
|
|
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModelsFetched)
|
|
|
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 提取相关人id
|
|
|
var cooperationContractRelevantIdsFetched []int64
|
|
|
for _, cooperationContractRelevant := range cooperationContractRelevantModelsFetched {
|
|
|
cooperationContractRelevantIdsFetched = append(cooperationContractRelevantIdsFetched, cooperationContractRelevant.CooperationContractRelevantId)
|
|
|
}
|
|
|
|
|
|
// 待更新相关人
|
|
|
var cooperationContractRelevantPeopleToUpdate []*domain.Relevant
|
|
|
|
|
|
// 待添加相关人
|
|
|
var cooperationContractRelevantPeopleToAdd []*domain.Relevant
|
|
|
|
|
|
for _, relevant := range cooperationContract.RelevantPeople {
|
|
|
if relevant.RelevantId != 0 {
|
|
|
cooperationContractRelevantPeopleToUpdate = append(cooperationContractRelevantPeopleToUpdate, relevant)
|
...
|
...
|
@@ -246,49 +265,67 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 待删除相关人,对比待更新的和数据库已有的
|
|
|
|
|
|
//var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人
|
|
|
//var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人
|
|
|
|
|
|
var relevantIdsHave []int64
|
|
|
var relevantIdsModify []int64
|
|
|
//var relevantIdsUpdate []int64
|
|
|
|
|
|
// 待更新相关人id数组
|
|
|
for _, cooperationContractRelevantModel := range cooperationContractRelevantFetched {
|
|
|
relevantIdsHave = append(relevantIdsHave, cooperationContractRelevantModel.CooperationContractRelevantId)
|
|
|
// 将待添加的相关人领域模型转换为数据模型
|
|
|
var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant
|
|
|
for _, relevantDomain := range cooperationContractRelevantPeopleToAdd {
|
|
|
cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{
|
|
|
CooperationContractNumber: relevantDomain.CooperationContractNumber,
|
|
|
UserId: relevantDomain.UserId,
|
|
|
UserBaseId: relevantDomain.UserBaseId,
|
|
|
Org: relevantDomain.Org,
|
|
|
Orgs: relevantDomain.Orgs,
|
|
|
Department: relevantDomain.Department,
|
|
|
Role: relevantDomain.Role,
|
|
|
UserInfo: relevantDomain.UserInfo,
|
|
|
UserType: relevantDomain.UserType,
|
|
|
Status: relevantDomain.Status,
|
|
|
Company: relevantDomain.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
// 添加相关人
|
|
|
if _, err := tx.Model(&cooperationContractRelevantPeopleToAddModels).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {
|
|
|
relevantIdsModify = append(relevantIdsModify, cooperationContractRelevantDomain.RelevantId)
|
|
|
// 待更新或者删除的ids
|
|
|
var cooperationContractRelevantPeopleToUpdateOrDeleteIds []int64
|
|
|
for _, cooperationContractRelevantPersonToUpdate := range cooperationContractRelevantPeopleToUpdate {
|
|
|
cooperationContractRelevantPeopleToUpdateOrDeleteIds = append(cooperationContractRelevantPeopleToUpdateOrDeleteIds, cooperationContractRelevantPersonToUpdate.RelevantId)
|
|
|
}
|
|
|
|
|
|
// 待更新的相关人
|
|
|
//relevantIdsUpdate := utils.Intersect(relevantIdsHave, relevantIdsModify)
|
|
|
// 待更新的相关人id
|
|
|
relevantIdsToUpdate := utils.Intersect(cooperationContractRelevantIdsFetched, cooperationContractRelevantPeopleToUpdateOrDeleteIds)
|
|
|
var relevantModelsToUpdate []*models.CooperationContractRelevant
|
|
|
for _, id := range relevantIdsToUpdate {
|
|
|
for _, relevantModel := range cooperationContractRelevantModelsFetched {
|
|
|
if relevantModel.CooperationContractRelevantId == id {
|
|
|
relevantModelsToUpdate = append(relevantModelsToUpdate, relevantModel)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if _, err := tx.Model(&relevantModelsToUpdate).WherePK().Update(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
var relevantPeopleModelUpdate []*models.CooperationContractRelevant
|
|
|
for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {
|
|
|
relevantPeopleModelUpdate = append(relevantPeopleModelUpdate, &models.CooperationContractRelevant{
|
|
|
CooperationContractRelevantId: cooperationContractRelevantDomain.RelevantId,
|
|
|
CooperationContractNumber: cooperationContractRelevantDomain.CooperationContractNumber,
|
|
|
UserId: cooperationContractRelevantDomain.UserId,
|
|
|
UserBaseId: cooperationContractRelevantDomain.UserBaseId,
|
|
|
Org: cooperationContractRelevantDomain.Org,
|
|
|
Orgs: cooperationContractRelevantDomain.Orgs,
|
|
|
Department: cooperationContractRelevantDomain.Department,
|
|
|
Role: cooperationContractRelevantDomain.Role,
|
|
|
UserInfo: cooperationContractRelevantDomain.UserInfo,
|
|
|
UserType: cooperationContractRelevantDomain.UserType,
|
|
|
Status: cooperationContractRelevantDomain.Status,
|
|
|
Company: cooperationContractRelevantDomain.Company,
|
|
|
UpdatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Time{},
|
|
|
})
|
|
|
// 待删除的相关人id
|
|
|
relevantIdsToDelete := utils.Difference(cooperationContractRelevantIdsFetched, cooperationContractRelevantPeopleToUpdateOrDeleteIds)
|
|
|
var relevantModelsToDelete []*models.CooperationContractRelevant
|
|
|
for _, id := range relevantIdsToDelete {
|
|
|
for _, relevantModel := range cooperationContractRelevantModelsFetched {
|
|
|
if relevantModel.CooperationContractRelevantId == id {
|
|
|
relevantModelsToDelete = append(relevantModelsToDelete, relevantModel)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if _, err := tx.Model(&relevantModelsToDelete).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//TODO 更新承接人
|
|
|
|
|
|
// 获取承接人列表
|
|
|
var cooperationContractUndertakersFetched []*models.CooperationContractUndertaker
|
|
|
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakersFetched)
|
...
|
...
|
@@ -297,6 +334,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
|
|
|
//TODO 更新分红激励规则
|
|
|
|
|
|
// 获取分红激励规则列表
|
|
|
var dividendsIncentivesRulesFetched []*models.DividendsIncentivesRule
|
|
|
dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRulesFetched)
|
...
|
...
|
@@ -305,6 +343,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
|
|
|
//TODO 更新金额激励规则
|
|
|
|
|
|
// 获取金额激励规则列表
|
|
|
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
|
|
|
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRulesFetched)
|
...
|
...
|
|