作者 陈志颖

feat:共创合约增加批量删除仓储

... ... @@ -10,6 +10,8 @@ import (
type BatchOperateCooperationContractCommand struct {
// 共创合约id列表
CooperationContractIds []string `cname:"共创合约id" json:"cooperationContractIds" valid:"Required"`
// 动作
Action int32 `cname:"操作" json:"action" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId,string" valid:"Required"`
// 组织机构ID
... ...
... ... @@ -11,6 +11,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"strconv"
"time"
)
... ... @@ -479,7 +480,7 @@ func (cooperationContractService *CooperationContractService) OperateCooperation
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operateCooperationContractCommand.CooperationContractId)))
}
if err := cooperationContract.Update(map[string]interface{}{
"action": operateCooperationContractCommand,
"action": operateCooperationContractCommand.Action,
}); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
... ... @@ -493,7 +494,7 @@ func (cooperationContractService *CooperationContractService) OperateCooperation
}
}
// BatchOperateCooperationContract TODO 批量暂停或恢复共创合约
// BatchOperateCooperationContract 批量暂停或恢复共创合约
func (cooperationContractService *CooperationContractService) BatchOperateCooperationContract(batchOperateCooperationContractCommand *command.BatchOperateCooperationContractCommand) (interface{}, error) {
if err := batchOperateCooperationContractCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -508,9 +509,34 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
defer func() {
_ = transactionContext.RollbackTransaction()
}()
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
cooperationContractIds, _ := utils.SliceAtoi(batchOperateCooperationContractCommand.CooperationContractIds)
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"cooperationContractIds": cooperationContractIds,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for i, _ := range cooperationContracts {
cooperationContracts[i].Status = batchOperateCooperationContractCommand.Action
}
if cooperationContractsReturn, err := cooperationContractRepository.UpdateMany(cooperationContracts); err != nil {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationContractsReturn, nil
}
} else {
return map[string]interface{}{}, nil
}
}
return nil, nil
}
... ...
... ... @@ -630,7 +630,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&dividendsIncentivesRuleModels).WherePK().Delete(); err != nil {
... ... @@ -640,7 +640,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil {
... ... @@ -650,7 +650,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
... ... @@ -660,7 +660,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
... ... @@ -671,6 +671,64 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
return cooperationContract, nil
}
// BatchRemove 批量删除
func (repository *CooperationContractRepository) BatchRemove(cooperationContracts []*domain.CooperationContract) ([]*domain.CooperationContract, error) {
tx := repository.transactionContext.PgTx
var cooperationContractModels []*models.CooperationContract
for _, cooperationContract := range cooperationContracts {
cooperationContractModels = append(cooperationContractModels, &models.CooperationContract{
CooperationContractId: cooperationContract.Identify().(int64),
})
}
if _, err := tx.Model(&cooperationContractModels).WherePK().Delete(); err != nil {
return cooperationContracts, err
} else {
for _, cooperationContract := range cooperationContracts {
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&dividendsIncentivesRuleModels).WherePK().Delete(); err != nil {
return nil, err
}
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil {
return nil, err
}
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); 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
} else {
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
return nil, err
}
}
}
}
return cooperationContracts, nil
}
func (repository *CooperationContractRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContract, error) {
tx := repository.transactionContext.PgTx
cooperationContractModel := new(models.CooperationContract)
... ... @@ -738,6 +796,9 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
if sponsorName, ok := queryOptions["sponsorName"]; ok && sponsorName != "" {
query.Where(`(cooperation_contract.cooperation_contract_sponsor->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", sponsorName))
}
if cooperationContractIds, ok := queryOptions["cooperationContractIds"]; ok && len(cooperationContractIds.([]int64)) != 0 {
query.Where("cooperation_contract_id in (?)", pg.In(cooperationContractIds))
}
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
... ...