作者 陈志颖

feat:共创合约增加批量更新方法

... ... @@ -688,7 +688,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 更新合约相关人
cooperationContract.RelevantPeople = relevantPeople
//TODO 获取承接人
// 获取承接人
var undertakers []*domain.Undertaker
for _, undertaker := range updateCooperationContractCommand.Undertakers {
var undertakerDomain *domain.Undertaker
... ... @@ -735,10 +735,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
ContractAttachment: nil,
})
}
//TODO 更新承接人
// 更新承接人
cooperationContract.Undertakers = undertakers
//TODO 获取分红规则列表
// 获取分红规则列表
var dividendsIncentivesRules []*domain.DividendsIncentivesRule
for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules {
dividendsIncentivesRuleId, _ := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
... ... @@ -758,10 +758,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
CreatedAt: time.Now(),
})
}
//TODO 更新分红规则列表
// 更新分红规则列表
cooperationContract.DividendsIncentivesRules = dividendsIncentivesRules
//TODO 获取金额激励规则列表
// 获取金额激励规则列表
var moneyIncentivesRules []*domain.MoneyIncentivesRule
for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules {
moneyIncentivesRuleId, _ := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
... ... @@ -782,7 +782,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
CreatedAt: time.Now(),
})
}
//TODO 更新金额激励规则列表
// 更新金额激励规则列表
cooperationContract.MoneyIncentivesRules = moneyIncentivesRules
if cooperationContract, err := cooperationContractRepository.Save(cooperationContract); err != nil {
... ...
... ... @@ -50,6 +50,7 @@ type CooperationContract struct {
type CooperationContractRepository interface {
Save(cooperationContract *CooperationContract) (*CooperationContract, error)
UpdateMany(cooperationContract []*CooperationContract) ([]*CooperationContract, error)
Remove(cooperationContract *CooperationContract) (*CooperationContract, error)
FindOne(queryOptions map[string]interface{}) (*CooperationContract, error)
Find(queryOptions map[string]interface{}) (int64, []*CooperationContract, error)
... ...
... ... @@ -591,6 +591,36 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return cooperationContract, nil
}
func (repository *CooperationContractRepository) UpdateMany(cooperationContracts []*domain.CooperationContract) ([]*domain.CooperationContract, error) {
tx := repository.transactionContext.PgTx
var cooperationContractModels []*models.CooperationContract
cooperationContractQuery := tx.Model(&cooperationContractModels)
for _, cooperationContract := range cooperationContracts {
cooperationContractModels = append(cooperationContractModels, &models.CooperationContract{
CooperationContractId: cooperationContract.CooperationContractId,
CooperationContractDescription: cooperationContract.CooperationContractDescription,
CooperationContractName: cooperationContract.CooperationContractName,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
CooperationProjectNumber: cooperationContract.CooperationProjectNumber,
CooperationContractUndertakerTypes: cooperationContract.CooperationContractUndertakerTypes,
CooperationContractSponsor: cooperationContract.CooperationContractSponsor,
CooperationModeNumber: cooperationContract.CooperationMode.CooperationModeNumber,
Status: cooperationContract.Status,
Org: cooperationContract.Org,
Company: cooperationContract.Company,
Operator: cooperationContract.Operator,
OperateTime: cooperationContract.OperateTime,
CreatedAt: cooperationContract.CreatedAt,
DeletedAt: cooperationContract.DeletedAt,
UpdatedAt: time.Now(),
})
}
if _, err := tx.Model(&cooperationContractQuery).WherePK().Update(); err != nil {
return nil, err
}
return cooperationContracts, nil
}
func (repository *CooperationContractRepository) Remove(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
tx := repository.transactionContext.PgTx
cooperationContractModel := new(models.CooperationContract)
... ...