作者 陈志颖

feat:修改共创合约仓储承接人部分

... ... @@ -10,7 +10,7 @@ var LOG_FILE = "app.log"
var LOG_PREFIX = "[allied-creation-cooperation]"
// 用户信息模块地址
var USER_MODULE_HOST = ""
var USER_MODULE_HOST = "http://127.0.0.1:8081"
func init() {
if os.Getenv("LOG_LEVEL") != "" {
... ...
... ... @@ -14,10 +14,6 @@ type CooperationContract struct {
CooperationContractName string `json:"cooperationContractName"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 合约推荐人
CooperationContractReferrer *User `json:"cooperationContractReferrer"`
// 共创合约业务员
CooperationContractSalesman *User `json:"cooperationContractSalesman"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerTypes []int32 `json:"cooperationContractUndertakerType"`
// 共创合约发起人
... ... @@ -36,10 +32,10 @@ type CooperationContract struct {
DividendsIncentivesRules []*DividendsIncentivesRule `json:"dividendsIncentivesRules"`
// 金额激励规则
MoneyIncentivesRules []*MoneyIncentivesRule `json:"moneyIncentivesRules"`
// 共创合约相关人列表
RelevantPeople []*Relevant `json:"relevantPeople"`
// 共创承接人列表
Undertakers []*Undertaker `json:"undertakers"`
// 共创合约相关人列表
RelevantPeople []*Relevant `json:"relevantPeople"`
// 操作时间
OperateTime time.Time `json:"operateTime"`
// 创建时间
... ... @@ -74,18 +70,6 @@ func (cooperationContract *CooperationContract) Update(data map[string]interface
if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
cooperationContract.CooperationContractNumber = cooperationContractNumber.(string)
}
if userId, ok := data["userId"]; ok {
cooperationContract.CooperationContractReferrer.UserId = userId.(int64)
}
if userBaseId, ok := data["userBaseId"]; ok {
cooperationContract.CooperationContractReferrer.UserBaseId = userBaseId.(int64)
}
if orgs, ok := data["orgs"]; ok {
cooperationContract.CooperationContractReferrer.Orgs = orgs.([]*Org)
}
if status, ok := data["status"]; ok {
cooperationContract.CooperationContractReferrer.Status = status.(int32)
}
if cooperationContractUndertakerType, ok := data["cooperationContractUndertakerType"]; ok {
cooperationContract.CooperationContractUndertakerTypes = cooperationContractUndertakerType.([]int32)
}
... ...
... ... @@ -2,8 +2,12 @@ package domain
// Undertaker 共创合约承接方值对象
type Undertaker struct {
// 承接人id
UndertakerId int64 `json:"relevantId"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `json:"userId,string"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 用户基本id
UserBaseId int64 `json:"userBaseId,string"`
// 用户所属组织机构
... ...
... ... @@ -15,10 +15,6 @@ type CooperationContract struct {
CooperationContractName string `comment:"共创合约名称"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 合约推荐人
CooperationContractReferrer *domain.User `comment:"合约推荐人"`
// 共创合约业务员
CooperationContractSalesman *domain.User `comment:"共创合约业务员"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerTypes []int32 `comment:"共创合约承接对象,1员工,2共创用户,3公开" pg:",array"`
// 共创合约发起人
... ...
... ... @@ -71,17 +71,17 @@ func TransformToCooperationContractDomainModelFromPgModels(
var undertakersDomain []*domain.Undertaker
for _, undertaker := range undertakers {
undertakersDomain = append(undertakersDomain, &domain.Undertaker{
UserId: undertaker.Undertaker.UserId,
UserBaseId: undertaker.Undertaker.UserBaseId,
Org: undertaker.Undertaker.Org,
Orgs: undertaker.Undertaker.Orgs,
Department: undertaker.Undertaker.Department,
Role: undertaker.Undertaker.Role,
UserInfo: undertaker.Undertaker.UserInfo,
UserType: undertaker.Undertaker.UserType,
Status: undertaker.Undertaker.Status,
Company: undertaker.Undertaker.Company,
ContractAttachment: undertaker.Undertaker.ContractAttachment,
UserId: undertaker.UserId,
UserBaseId: undertaker.UserBaseId,
Org: undertaker.Org,
Orgs: undertaker.Orgs,
Department: undertaker.Department,
Role: undertaker.Role,
UserInfo: undertaker.UserInfo,
UserType: undertaker.UserType,
Status: undertaker.Status,
Company: undertaker.Company,
ContractAttachment: undertaker.ContractAttachment,
})
}
return &domain.CooperationContract{
... ... @@ -89,8 +89,6 @@ func TransformToCooperationContractDomainModelFromPgModels(
CooperationContractDescription: cooperationContractModel.CooperationContractDescription,
CooperationContractName: cooperationContractModel.CooperationContractName,
CooperationContractNumber: cooperationContractModel.CooperationContractNumber,
CooperationContractReferrer: cooperationContractModel.CooperationContractReferrer,
CooperationContractSalesman: cooperationContractModel.CooperationContractSalesman,
CooperationContractUndertakerTypes: cooperationContractModel.CooperationContractUndertakerTypes,
CooperationContractSponsor: cooperationContractModel.CooperationContractSponsor,
CooperationMode: &domain.CooperationMode{
... ...
... ... @@ -64,8 +64,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
&cooperationContract.CooperationContractDescription,
&cooperationContract.CooperationContractName,
&cooperationContract.CooperationContractNumber,
&cooperationContract.CooperationContractReferrer,
&cooperationContract.CooperationContractSalesman,
pg.Array(&cooperationContract.CooperationContractUndertakerTypes),
&cooperationContract.CooperationContractSponsor,
&cooperationContract.CooperationMode.CooperationModeNumber,
... ... @@ -83,8 +81,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.CooperationContractDescription,
cooperationContract.CooperationContractName,
cooperationContract.CooperationContractNumber,
cooperationContract.CooperationContractReferrer,
cooperationContract.CooperationContractSalesman,
pg.Array(cooperationContract.CooperationContractUndertakerTypes),
cooperationContract.CooperationContractSponsor,
cooperationContract.CooperationMode.CooperationModeNumber,
... ... @@ -200,8 +196,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
&cooperationContract.CooperationContractDescription,
&cooperationContract.CooperationContractName,
&cooperationContract.CooperationContractNumber,
&cooperationContract.CooperationContractReferrer,
&cooperationContract.CooperationContractSalesman,
pg.Array(&cooperationContract.CooperationContractUndertakerTypes),
&cooperationContract.CooperationContractSponsor,
&cooperationContract.CooperationMode.CooperationModeNumber,
... ... @@ -219,8 +213,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.CooperationContractDescription,
cooperationContract.CooperationContractName,
cooperationContract.CooperationContractNumber,
cooperationContract.CooperationContractReferrer,
cooperationContract.CooperationContractSalesman,
pg.Array(cooperationContract.CooperationContractUndertakerTypes),
cooperationContract.CooperationContractSponsor,
cooperationContract.CooperationMode.CooperationModeNumber,
... ... @@ -237,8 +229,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return cooperationContract, err
}
// 更新相关人
/******************************* 更新相关人 ****************************/
// 查找相关人列表
var cooperationContractRelevantModelsFetched []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModelsFetched)
... ... @@ -324,16 +315,93 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return nil, err
}
//TODO 更新承接人
/************************* 更新承接人 ****************************/
// 获取承接人列表
var cooperationContractUndertakersFetched []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakersFetched)
var cooperationContractUndertakersModelsFetched []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakersModelsFetched)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
//TODO 更新分红激励规则
// 提取承接人id
var cooperationContractUndertakersIdsFetched []int64
for _, cooperationContractUndertaker := range cooperationContractUndertakersModelsFetched {
cooperationContractUndertakersIdsFetched = append(cooperationContractUndertakersIdsFetched, cooperationContractUndertaker.CooperationContractUndertakerId)
}
// 待更新相关人
var cooperationContractUndertakersToUpdate []*domain.Undertaker
// 待添加相关人
var cooperationContractUndertakersToAdd []*domain.Undertaker
for _, undertaker := range cooperationContract.Undertakers {
if undertaker.UndertakerId != 0 {
cooperationContractUndertakersToUpdate = append(cooperationContractUndertakersToUpdate, undertaker)
} else {
cooperationContractUndertakersToAdd = append(cooperationContractUndertakersToAdd, undertaker)
}
}
// 将待添加的相关人领域模型转换为数据模型
var cooperationContractUndertakersToAddModels []*models.CooperationContractUndertaker
for _, undertakerDomain := range cooperationContractUndertakersToAdd {
cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{
CooperationContractNumber: undertakerDomain.CooperationContractNumber,
UserId: undertakerDomain.UserId,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Role: undertakerDomain.Role,
UserInfo: undertakerDomain.UserInfo,
UserType: undertakerDomain.UserType,
Status: undertakerDomain.Status,
Company: undertakerDomain.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
// 添加承接人
if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil {
return nil, err
}
// 待更新或者删除的ids
var cooperationContractUndertakersToUpdateOrDeleteIds []int64
for _, cooperationContractUndertakerToUpdate := range cooperationContractUndertakersToUpdate {
cooperationContractUndertakersToUpdateOrDeleteIds = append(cooperationContractUndertakersToUpdateOrDeleteIds, cooperationContractUndertakerToUpdate.UndertakerId)
}
// 待更新的承接人id
undertakerIdsToUpdate := utils.Intersect(cooperationContractUndertakersIdsFetched, cooperationContractUndertakersToUpdateOrDeleteIds)
var undertakerModelsToUpdate []*models.CooperationContractUndertaker
for _, id := range undertakerIdsToUpdate {
for _, undertakerModel := range cooperationContractUndertakersModelsFetched {
if undertakerModel.CooperationContractUndertakerId == id {
undertakerModelsToUpdate = append(undertakerModelsToUpdate, undertakerModel)
}
}
}
if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
}
// 待删除的相关人id
undertakerIdsToDelete := utils.Difference(cooperationContractUndertakersIdsFetched, cooperationContractUndertakersToUpdateOrDeleteIds)
var undertakerModelsToDelete []*models.CooperationContractUndertaker
for _, id := range undertakerIdsToDelete {
for _, undertakerModel := range cooperationContractUndertakersModelsFetched {
if undertakerModel.CooperationContractUndertakerId == id {
undertakerModelsToDelete = append(undertakerModelsToDelete, undertakerModel)
}
}
}
if _, err := tx.Model(&relevantModelsToDelete).WherePK().Delete(); err != nil {
return nil, err
}
//TODO /************************ 更新分红激励规则 **************************/
// 获取分红激励规则列表
var dividendsIncentivesRulesFetched []*models.DividendsIncentivesRule
... ... @@ -342,7 +410,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return nil, err
}
//TODO 更新金额激励规则
//TODO /********************** 更新金额激励规则 **************************/
// 获取金额激励规则列表
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
... ...