...
|
...
|
@@ -3,14 +3,13 @@ package repository |
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"github.com/linmadan/egglib-go/utils/snowflake"
|
|
|
"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"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
type CooperationContractRepository struct {
|
...
|
...
|
@@ -98,80 +97,88 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
cooperationContract.UpdatedAt,
|
|
|
); err != nil {
|
|
|
return cooperationContract, err
|
|
|
} else {
|
|
|
// 新增相关人
|
|
|
var relevantPeopleModel []*models.CooperationContractRelevant
|
|
|
for _, relevant := range cooperationContract.RelevantPeople {
|
|
|
relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
Relevant: relevant,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
// 新增相关人
|
|
|
var relevantPeopleModel []*models.CooperationContractRelevant
|
|
|
for _, relevant := range cooperationContract.RelevantPeople {
|
|
|
relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
UserId: relevant.UserId,
|
|
|
UserBaseId: relevant.UserBaseId,
|
|
|
Org: relevant.Org,
|
|
|
Orgs: relevant.Orgs,
|
|
|
Department: relevant.Department,
|
|
|
Role: relevant.Role,
|
|
|
UserInfo: relevant.UserInfo,
|
|
|
UserType: relevant.UserType,
|
|
|
Status: relevant.Status,
|
|
|
Company: relevant.Company,
|
|
|
UpdatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Time{},
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 新增承接人
|
|
|
var undertakersModel []*models.CooperationContractUndertaker
|
|
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
|
undertakersModel = append(undertakersModel, &models.CooperationContractUndertaker{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
Undertaker: undertaker,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(&undertakersModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 新增承接人
|
|
|
var undertakersModel []*models.CooperationContractUndertaker
|
|
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
|
undertakersModel = append(undertakersModel, &models.CooperationContractUndertaker{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
Undertaker: undertaker,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(&undertakersModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 新增分红激励规则
|
|
|
var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
|
|
|
for _, rule := range cooperationContract.DividendsIncentivesRules {
|
|
|
dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
ReferrerPercentage: rule.ReferrerPercentage,
|
|
|
SalesmanPercentage: rule.SalesmanPercentage,
|
|
|
DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,
|
|
|
DividendsIncentivesStage: rule.DividendsIncentivesStage,
|
|
|
DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,
|
|
|
DividendsIncentivesStageEnd: rule.DividendsIncentivesStageEnd,
|
|
|
Org: rule.Org,
|
|
|
Company: rule.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(÷ndsIncentivesRulesModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 新增金额激励规则
|
|
|
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
|
|
|
for _, rule := range cooperationContract.MoneyIncentivesRules {
|
|
|
moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
|
|
|
MoneyIncentivesStage: rule.MoneyIncentivesStage,
|
|
|
MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,
|
|
|
MoneyIncentivesStageEnd: rule.MoneyIncentivesStageEnd,
|
|
|
MoneyIncentivesTime: rule.MoneyIncentivesTime,
|
|
|
ReferrerPercentage: rule.ReferrerPercentage,
|
|
|
SalesmanPercentage: rule.SalesmanPercentage,
|
|
|
Org: rule.Org,
|
|
|
Company: rule.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(&moneyIncentivesRulesModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 新增分红激励规则
|
|
|
var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
|
|
|
for _, rule := range cooperationContract.DividendsIncentivesRules {
|
|
|
dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
ReferrerPercentage: rule.ReferrerPercentage,
|
|
|
SalesmanPercentage: rule.SalesmanPercentage,
|
|
|
DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,
|
|
|
DividendsIncentivesStage: rule.DividendsIncentivesStage,
|
|
|
DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,
|
|
|
DividendsIncentivesStageEnd: rule.DividendsIncentivesStageEnd,
|
|
|
Org: rule.Org,
|
|
|
Company: rule.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(÷ndsIncentivesRulesModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 新增金额激励规则
|
|
|
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
|
|
|
for _, rule := range cooperationContract.MoneyIncentivesRules {
|
|
|
moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
|
|
|
MoneyIncentivesStage: rule.MoneyIncentivesStage,
|
|
|
MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,
|
|
|
MoneyIncentivesStageEnd: rule.MoneyIncentivesStageEnd,
|
|
|
MoneyIncentivesTime: rule.MoneyIncentivesTime,
|
|
|
ReferrerPercentage: rule.ReferrerPercentage,
|
|
|
SalesmanPercentage: rule.SalesmanPercentage,
|
|
|
Org: rule.Org,
|
|
|
Company: rule.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(&moneyIncentivesRulesModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
} else {
|
|
|
if _, err := tx.QueryOne(
|
...
|
...
|
@@ -215,53 +222,80 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
cooperationContract.Identify(),
|
|
|
); err != nil {
|
|
|
return cooperationContract, err
|
|
|
} else {
|
|
|
// 获取相关人列表
|
|
|
var cooperationContractRelevantModels []*models.CooperationContractRelevant
|
|
|
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
|
|
|
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
// 获取相关人列表
|
|
|
var cooperationContractRelevantModels []*models.CooperationContractRelevant
|
|
|
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
|
|
|
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//var cooperationContractRelevantModelsUpdate []*models.CooperationContractRelevant // 待更新的相关人
|
|
|
//var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人
|
|
|
//var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人
|
|
|
//
|
|
|
//for _, cooperationContractRelevantModels := range cooperationContractRelevantModels {
|
|
|
// for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {
|
|
|
//
|
|
|
// }
|
|
|
//}
|
|
|
//var cooperationContractRelevantModelsUpdate []*models.CooperationContractRelevant // 待更新的相关人
|
|
|
//var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人
|
|
|
//var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人
|
|
|
|
|
|
// 更新的相关人
|
|
|
var relevantIdsHave []int64
|
|
|
var relevantIdsModify []int64
|
|
|
//var relevantIdsUpdate []int64
|
|
|
|
|
|
// 删除的相关人
|
|
|
for _, cooperationContractRelevantModel := range cooperationContractRelevantModels {
|
|
|
relevantIdsHave = append(relevantIdsHave, cooperationContractRelevantModel.CooperationContractRelevantId)
|
|
|
}
|
|
|
|
|
|
// 新增的相关人
|
|
|
for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {
|
|
|
relevantIdsModify = append(relevantIdsModify, cooperationContractRelevantDomain.RelevantId)
|
|
|
}
|
|
|
|
|
|
//TODO 更新承接人
|
|
|
// 获取承接人列表
|
|
|
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
|
|
|
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
|
|
|
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 待更新的相关人
|
|
|
//relevantIdsUpdate := utils.Intersect(relevantIdsHave, relevantIdsModify)
|
|
|
|
|
|
//TODO 更新分红激励规则
|
|
|
// 获取分红激励规则列表
|
|
|
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
|
|
|
dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRuleModels)
|
|
|
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); 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{},
|
|
|
})
|
|
|
}
|
|
|
|
|
|
//TODO 更新金额激励规则
|
|
|
// 获取金额激励规则列表
|
|
|
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
|
|
|
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
|
|
|
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 待删除的相关人
|
|
|
|
|
|
// 待新增的相关人
|
|
|
|
|
|
//TODO 更新承接人
|
|
|
// 获取承接人列表
|
|
|
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
|
|
|
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
|
|
|
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//TODO 更新分红激励规则
|
|
|
// 获取分红激励规则列表
|
|
|
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
|
|
|
dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRuleModels)
|
|
|
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//TODO 更新金额激励规则
|
|
|
// 获取金额激励规则列表
|
|
|
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
|
|
|
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
|
|
|
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
return cooperationContract, nil
|
...
|
...
|
@@ -343,8 +377,8 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
|
} else {
|
|
|
for _, cooperationContractModel := range cooperationContractModels {
|
|
|
// 获取共创模式
|
|
|
cooperationModeModels := new(models.CooperationMode)
|
|
|
cooperationModeQuery := tx.Model(cooperationModeModels)
|
|
|
cooperationModeModel := new(models.CooperationMode)
|
|
|
cooperationModeQuery := tx.Model(cooperationModeModel)
|
|
|
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil {
|
|
|
return 0, nil, err
|
|
|
}
|
...
|
...
|
@@ -374,7 +408,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
|
}
|
|
|
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
|
|
|
cooperationContractModel,
|
|
|
cooperationModeModels,
|
|
|
cooperationModeModel,
|
|
|
dividendsIncentivesRuleModels,
|
|
|
moneyIncentivesRuleModels,
|
|
|
cooperationContractRelevantModels,
|
...
|
...
|
|