作者 陈志颖

fix:共创合约变更记录

... ... @@ -1019,14 +1019,14 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
CooperationContractNumber: cooperationContract.CooperationContractNumber,
UserId: relevantDomain.UserId,
UserBaseId: relevantDomain.UserBaseId,
Org: relevantDomain.Org,
Org: organization,
Orgs: relevantDomain.Orgs,
Department: relevantDomain.Department,
Roles: relevantDomain.Roles,
UserInfo: relevantDomain.UserInfo,
UserType: relevantDomain.UserType,
Status: relevantDomain.Status,
Company: relevantDomain.Company,
Company: company,
})
}
... ... @@ -1114,7 +1114,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
CooperationContractNumber: cooperationContract.CooperationContractNumber,
CooperationContractId: cooperationContract.CooperationContractId,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Org: organization,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Roles: undertakerDomain.Roles,
... ... @@ -1123,7 +1123,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
Referrer: referrerDomain,
Salesman: salesmanDomain,
Status: undertakerDomain.Status,
Company: undertakerDomain.Company,
Company: company,
ContractAttachment: contractAttachments,
})
}
... ... @@ -1275,7 +1275,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, rule := range cooperationContractFound.DividendsIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
}
... ... @@ -1288,7 +1288,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, rule := range cooperationContract.DividendsIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractBytes = append(cooperationContractBytes, jsons...)
}
... ... @@ -1331,7 +1331,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, rule := range cooperationContractFound.MoneyIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
}
... ... @@ -1344,7 +1344,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, rule := range cooperationContract.MoneyIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractBytes = append(cooperationContractBytes, jsons...)
}
... ... @@ -1388,7 +1388,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, undertaker := range cooperationContractFound.Undertakers {
jsons, errs := json.Marshal(undertaker)
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
}
... ... @@ -1400,7 +1400,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, undertaker := range cooperationContract.Undertakers {
jsons, errs := json.Marshal(undertaker) //转换成JSON返回的是byte[]
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractBytes = append(cooperationContractBytes, jsons...)
}
... ... @@ -1501,9 +1501,11 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
}
// 保存共创合约变更记录
if newCooperationContractChangeLog.IncentivesRule != "" || newCooperationContractChangeLog.IncentivesRuleDetail != "" || newCooperationContractChangeLog.Undertakers != "" {
if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
}
}
if err21 := transactionContext.CommitTransaction(); err21 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err21.Error())
}
... ...
... ... @@ -82,6 +82,7 @@ func TransformToCooperationContractDomainModelFromPgModels(
undertakersDomain = append(undertakersDomain, &domain.Undertaker{
UndertakerId: undertaker.CooperationContractUndertakerId,
CooperationContractNumber: undertaker.CooperationContractNumber,
CooperationContractId: undertaker.CooperationContractId,
UserId: undertaker.UserId,
UserBaseId: undertaker.UserBaseId,
Org: undertaker.Org,
... ...
... ... @@ -327,9 +327,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
var cooperationContractRelevantPeopleToAdd []*domain.Relevant
for _, relevant := range cooperationContract.RelevantPeople {
if relevant.RelevantId != 0 {
cooperationContractRelevantPeopleToUpdate = append(cooperationContractRelevantPeopleToUpdate, relevant)
cooperationContractRelevantPeopleToUpdate = append(cooperationContractRelevantPeopleToUpdate, relevant) // 提取待更新的相关人
} else {
cooperationContractRelevantPeopleToAdd = append(cooperationContractRelevantPeopleToAdd, relevant)
cooperationContractRelevantPeopleToAdd = append(cooperationContractRelevantPeopleToAdd, relevant) // 提取待添加的相关人
}
}
... ... @@ -379,13 +379,41 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 待更新的相关人id
relevantIdsToUpdate := utils.Intersect(cooperationContractRelevantIdsFetched, cooperationContractRelevantPeopleToUpdateOrDeleteIds)
var relevantModelsToUpdate []*models.CooperationContractRelevant
var relevantDomainsToUpdate []*domain.Relevant
for _, id := range relevantIdsToUpdate {
for _, relevantModel := range cooperationContractRelevantModelsFetched {
if relevantModel.CooperationContractRelevantId == id {
relevantModelsToUpdate = append(relevantModelsToUpdate, relevantModel)
//for _, relevantModel := range cooperationContractRelevantModelsFetched {
// if relevantModel.CooperationContractRelevantId == id {
// relevantModelsToUpdate = append(relevantModelsToUpdate, relevantModel)
// }
//}
for _, relevantDomain := range cooperationContract.RelevantPeople {
if relevantDomain.RelevantId == id {
relevantDomainsToUpdate = append(relevantDomainsToUpdate, relevantDomain)
}
}
}
// domain to model
for _, relevantDomainToUpdate := range relevantDomainsToUpdate {
relevantModelsToUpdate = append(relevantModelsToUpdate, &models.CooperationContractRelevant{
CooperationContractRelevantId: relevantDomainToUpdate.RelevantId,
CooperationContractNumber: relevantDomainToUpdate.CooperationContractNumber,
UserId: relevantDomainToUpdate.UserId,
UserBaseId: relevantDomainToUpdate.UserBaseId,
Org: relevantDomainToUpdate.Org,
Orgs: relevantDomainToUpdate.Orgs,
Department: relevantDomainToUpdate.Department,
Roles: relevantDomainToUpdate.Roles,
UserInfo: relevantDomainToUpdate.UserInfo,
UserType: relevantDomainToUpdate.UserType,
Status: relevantDomainToUpdate.Status,
Company: relevantDomainToUpdate.Company,
UpdatedAt: time.Now(),
DeletedAt: time.Time{},
CreatedAt: time.Time{},
})
}
if len(relevantModelsToUpdate) > 0 {
if _, err := tx.Model(&relevantModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
... ... @@ -410,6 +438,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return nil, err
}
}
/***************************************************************/
/************************* 更新承接人 ****************************/
// 获取承接人列表
... ... @@ -431,6 +460,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 待更新相关人
var cooperationContractUndertakersToUpdate []*domain.Undertaker
// 待添加相关人
var cooperationContractUndertakersToAdd []*domain.Undertaker
for _, undertaker := range cooperationContract.Undertakers {
... ... @@ -554,6 +584,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return nil, err
}
}
/*****************************************************************/
/************************ 更新分红激励规则 **************************/
// 获取分红激励规则列表
... ... @@ -687,6 +718,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return nil, err
}
}
/***************************************************************/
/********************** 更新金额激励规则 **************************/
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
... ...
... ... @@ -12,22 +12,35 @@ import (
// Intersect 返回两个数组的交集
func Intersect(nums1 []int64, nums2 []int64) []int64 {
if len(nums1) > len(nums2) {
return Intersect(nums2, nums1)
//if len(nums1) > len(nums2) {
// return Intersect(nums2, nums1)
//}
//m := map[int64]int64{}
//for _, num := range nums1 {
// m[num]++
//}
//
//var intersection []int64
//for _, num := range nums2 {
// if m[num] > 0 {
// intersection = append(intersection, num)
// m[num]--
// }
//}
//return intersection
m := make(map[int64]int)
nn := make([]int64, 0)
for _, v := range nums1 {
m[v]++
}
m := map[int64]int64{}
for _, num := range nums1 {
m[num]++
for _, v := range nums2 {
times, _ := m[v]
if times > 0 {
nn = append(nn, v)
}
var intersection []int64
for _, num := range nums2 {
if m[num] > 0 {
intersection = append(intersection, num)
m[num]--
}
}
return intersection
return nn
}
// Intersect32 返回两个数组的交集
... ... @@ -52,20 +65,34 @@ func Intersect32(nums1 []int32, nums2 []int32) []int32 {
// Difference 求差集 slice1-并集
func Difference(slice1, slice2 []int64) []int64 {
//m := make(map[int64]int)
//nn := make([]int64, 0)
//inter := Intersect(slice1, slice2)
//for _, v := range inter {
// m[v]++
//}
//
//for _, value := range slice1 {
// times, _ := m[value]
// if times == 0 {
// nn = append(nn, value)
// }
//}
//return nn
m := make(map[int64]int)
nn := make([]int64, 0)
inter := Intersect(slice1, slice2)
for _, v := range inter {
m[v]++
}
for _, value := range slice1 {
times, _ := m[value]
for _, v := range slice1 {
times, _ := m[v]
if times == 0 {
nn = append(nn, value)
nn = append(nn, v)
}
}
return nn
}
// SliceAtoi 字符创数组转数字数组
... ...