...
|
...
|
@@ -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,16 +97,25 @@ 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{},
|
|
|
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.Now(),
|
|
|
CreatedAt: time.Time{},
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
|
...
|
...
|
@@ -172,7 +180,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
if _, err := tx.Model(&moneyIncentivesRulesModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if _, err := tx.QueryOne(
|
|
|
pg.Scan(
|
...
|
...
|
@@ -215,7 +222,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
cooperationContract.Identify(),
|
|
|
); err != nil {
|
|
|
return cooperationContract, err
|
|
|
} else {
|
|
|
}
|
|
|
// 获取相关人列表
|
|
|
var cooperationContractRelevantModels []*models.CooperationContractRelevant
|
|
|
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
|
...
|
...
|
@@ -226,18 +233,46 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
//var cooperationContractRelevantModelsUpdate []*models.CooperationContractRelevant // 待更新的相关人
|
|
|
//var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人
|
|
|
//var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人
|
|
|
//
|
|
|
//for _, cooperationContractRelevantModels := range cooperationContractRelevantModels {
|
|
|
// for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {
|
|
|
//
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
// 更新的相关人
|
|
|
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)
|
|
|
}
|
|
|
|
|
|
// 待更新的相关人
|
|
|
//relevantIdsUpdate := utils.Intersect(relevantIdsHave, relevantIdsModify)
|
|
|
|
|
|
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 更新承接人
|
|
|
// 获取承接人列表
|
...
|
...
|
@@ -263,7 +298,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return cooperationContract, nil
|
|
|
}
|
|
|
func (repository *CooperationContractRepository) Remove(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
|
...
|
...
|
@@ -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,
|
...
|
...
|
|