...
|
...
|
@@ -9,6 +9,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
|
|
|
"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/utils"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
...
|
...
|
@@ -231,6 +232,49 @@ func (cooperationModeService *CooperationModeService) RemoveCooperationMode(remo |
|
|
}
|
|
|
}
|
|
|
|
|
|
// BatchRemoveCooperationMode 移除共创模式服务
|
|
|
func (cooperationModeService *CooperationModeService) BatchRemoveCooperationMode(batchRemoveCooperationModeCommand *command.BatchRemoveCooperationModeCommand) (interface{}, error) {
|
|
|
if err := batchRemoveCooperationModeCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var cooperationModeRepository domain.CooperationModeRepository
|
|
|
if value, err := factory.CreateCooperationModeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationModeRepository = value
|
|
|
}
|
|
|
cooperationModeIds, _ := utils.SliceAtoi(batchRemoveCooperationModeCommand.CooperationModeIds)
|
|
|
if count, cooperationModes, err := cooperationModeRepository.Find(map[string]interface{}{
|
|
|
"cooperationModeIds": cooperationModeIds,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
if cooperationMode, err := cooperationModeRepository.BatchRemove(cooperationModes); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return cooperationMode, nil
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return map[string]interface{}{}, nil
|
|
|
}
|
|
|
|
|
|
// SearchCooperationMode 查询共创模式
|
|
|
func (cooperationModeService *CooperationModeService) SearchCooperationMode(searchCooperationModeQuery *query.SearchCooperationModeQuery) (interface{}, error) {
|
|
|
if err := searchCooperationModeQuery.ValidateQuery(); err != nil {
|
...
|
...
|
@@ -312,6 +356,72 @@ func (cooperationModeService *CooperationModeService) UpdateCooperationMode(upda |
|
|
}
|
|
|
}
|
|
|
|
|
|
// OperateCooperationMode 更新共创模式服务
|
|
|
func (cooperationModeService *CooperationModeService) OperateCooperationMode(operateCooperationModeCommand *command.OperateCooperationModeCommand) (interface{}, error) {
|
|
|
if err := operateCooperationModeCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var cooperationModeRepository domain.CooperationModeRepository
|
|
|
if value, err := factory.CreateCooperationModeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationModeRepository = value
|
|
|
}
|
|
|
cooperationModeId, _ := strconv.ParseInt(operateCooperationModeCommand.CooperationModeId, 10, 64)
|
|
|
cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{"cooperationModeId": cooperationModeId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if cooperationMode == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationModeId, 10)))
|
|
|
}
|
|
|
if err := cooperationMode.Update(tool_funs.SimpleStructToMap(operateCooperationModeCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if cooperationMode, err := cooperationModeRepository.Save(cooperationMode); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return cooperationMode, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// BatchOperateCooperationMode 更新共创模式服务
|
|
|
func (cooperationModeService *CooperationModeService) BatchOperateCooperationMode(batchOperateCooperationModeCommand *command.BatchOperateCooperationModeCommand) (interface{}, error) {
|
|
|
if err := batchOperateCooperationModeCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
func NewCooperationModeService(options map[string]interface{}) *CooperationModeService {
|
|
|
newCooperationModeService := &CooperationModeService{}
|
|
|
return newCooperationModeService
|
...
|
...
|
|