...
|
...
|
@@ -563,6 +563,24 @@ func (cooperationContractService *CooperationContractService) OperateCooperation |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
userService = value
|
|
|
}
|
|
|
|
|
|
// 获取操作人
|
|
|
var operator *domain.User
|
|
|
if data, err := userService.OperatorFrom(operateCooperationContractCommand.CompanyId, operateCooperationContractCommand.OrgId, operateCooperationContractCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operator = data
|
|
|
}
|
|
|
|
|
|
// 共创合约仓储初始化
|
|
|
var cooperationContractRepository domain.CooperationContractRepository
|
|
|
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -571,6 +589,18 @@ func (cooperationContractService *CooperationContractService) OperateCooperation |
|
|
} else {
|
|
|
cooperationContractRepository = value
|
|
|
}
|
|
|
|
|
|
// 共创合约变更记录仓储初始化
|
|
|
var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
|
|
|
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationContractChangeLogRepository = value
|
|
|
}
|
|
|
|
|
|
// 获取共创合约
|
|
|
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": operateCooperationContractCommand.CooperationContractId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -578,18 +608,42 @@ func (cooperationContractService *CooperationContractService) OperateCooperation |
|
|
if cooperationContract == nil {
|
|
|
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,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if cooperationContract, err := cooperationContractRepository.UpdateOne(cooperationContract); err != nil {
|
|
|
if cooperationContractUpdated, err := cooperationContractRepository.UpdateOne(cooperationContract); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
// 新增共创合约变更记录
|
|
|
var operationType int32
|
|
|
if operateCooperationContractCommand.Action == 1 {
|
|
|
operationType = domain.PAUSE
|
|
|
} else if operateCooperationContractCommand.Action == 2 {
|
|
|
operationType = domain.RECOVER
|
|
|
}
|
|
|
newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
|
|
|
IncentivesRule: "",
|
|
|
IncentivesRuleDetail: "",
|
|
|
OperationType: operationType,
|
|
|
Undertakers: "",
|
|
|
CooperationContractNumber: cooperationContractUpdated.CooperationContractNumber,
|
|
|
Company: cooperationContractUpdated.Company,
|
|
|
Operator: operator,
|
|
|
CreatedAt: time.Now(),
|
|
|
}
|
|
|
|
|
|
// 保存共创合约变更记录
|
|
|
if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return cooperationContract, nil
|
|
|
return cooperationContractUpdated, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -608,6 +662,7 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 共创合约仓储初始化
|
|
|
var cooperationContractRepository domain.CooperationContractRepository
|
|
|
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
|
...
|
...
|
@@ -617,7 +672,37 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper |
|
|
} else {
|
|
|
cooperationContractRepository = value
|
|
|
}
|
|
|
cooperationContractIds, _ := utils.SliceAtoi(batchOperateCooperationContractCommand.CooperationContractIds)
|
|
|
|
|
|
// 共创合约变更记录仓储初始化
|
|
|
var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
|
|
|
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationContractChangeLogRepository = value
|
|
|
}
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
userService = value
|
|
|
}
|
|
|
|
|
|
// 获取操作人
|
|
|
var operator *domain.User
|
|
|
if data, err := userService.OperatorFrom(batchOperateCooperationContractCommand.CompanyId, batchOperateCooperationContractCommand.OrgId, batchOperateCooperationContractCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operator = data
|
|
|
}
|
|
|
|
|
|
cooperationContractIds, err := utils.SliceAtoi(batchOperateCooperationContractCommand.CooperationContractIds)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "转换共创合约ID列表错误")
|
|
|
}
|
|
|
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
"cooperationContractIds": cooperationContractIds,
|
|
|
}); err != nil {
|
...
|
...
|
@@ -631,6 +716,31 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
for _, cooperationContractOperated := range cooperationContractsOperated {
|
|
|
// 新增共创合约变更记录
|
|
|
var operationType int32
|
|
|
if batchOperateCooperationContractCommand.Action == 1 {
|
|
|
operationType = domain.PAUSE
|
|
|
} else if batchOperateCooperationContractCommand.Action == 2 {
|
|
|
operationType = domain.RECOVER
|
|
|
}
|
|
|
newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
|
|
|
IncentivesRule: "",
|
|
|
IncentivesRuleDetail: "",
|
|
|
OperationType: operationType,
|
|
|
Undertakers: "",
|
|
|
CooperationContractNumber: cooperationContractOperated.CooperationContractNumber,
|
|
|
Company: cooperationContractOperated.Company,
|
|
|
Operator: operator,
|
|
|
CreatedAt: time.Now(),
|
|
|
}
|
|
|
|
|
|
// 保存共创合约变更记录
|
|
|
if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
|