作者 陈志颖

feat:共创合约增加批量删除方法

... ... @@ -428,7 +428,7 @@ func (cooperationContractService *CooperationContractService) RemoveCooperationC
}
}
// BatchRemoveCooperationContract TODO 批量移除共创合约
// BatchRemoveCooperationContract 批量移除共创合约
func (cooperationContractService *CooperationContractService) BatchRemoveCooperationContract(batchRemoveCooperationContractCommand *command.BatchRemoveCooperationContractCommand) (interface{}, error) {
if err := batchRemoveCooperationContractCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -443,10 +443,33 @@ func (cooperationContractService *CooperationContractService) BatchRemoveCoopera
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
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(batchRemoveCooperationContractCommand.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 {
cooperationContractsRemoved, err := cooperationContractRepository.BatchRemove(cooperationContracts)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationContractsRemoved, nil
} else {
return map[string]interface{}{}, nil
}
}
return nil, nil
}
// OperateCooperationContract 暂停或恢复共创合约
... ... @@ -527,17 +550,18 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
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
cooperationContractsOperated, err := cooperationContractRepository.UpdateMany(cooperationContracts)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationContractsOperated, nil
} else {
return map[string]interface{}{}, nil
}
}
return nil, nil
}
// SearchCooperationContract 查询共创合约
... ...
... ... @@ -52,6 +52,7 @@ type CooperationContractRepository interface {
Save(cooperationContract *CooperationContract) (*CooperationContract, error)
UpdateMany(cooperationContract []*CooperationContract) ([]*CooperationContract, error)
Remove(cooperationContract *CooperationContract) (*CooperationContract, error)
BatchRemove(cooperationContracts []*CooperationContract) ([]*CooperationContract, error)
FindOne(queryOptions map[string]interface{}) (*CooperationContract, error)
Find(queryOptions map[string]interface{}) (int64, []*CooperationContract, error)
}
... ...