作者 陈志颖

feat:增加共创合约暂停恢复日志记录

... ... @@ -10,7 +10,7 @@ import (
type OperateCooperationContractCommand struct {
// 共创合约id
CooperationContractId string `cname:"共创合约id" json:"cooperationContractId" valid:"Required"`
// 操作
// 操作,1暂停,2恢复
Action int32 `cname:"操作" json:"action" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
... ...
... ... @@ -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())
}
... ...
... ... @@ -24,6 +24,8 @@ type CooperationContractChangeLog struct {
Undertakers string `json:"undertakers"`
// 公司
Company *Company `json:"company"`
// 组织机构
Org *Org `json:"org"`
// 操作人
Operator *User `json:"operator"`
// 操作时间
... ...
... ... @@ -21,6 +21,8 @@ type CooperationContractChangeLog struct {
Undertakers string `comment:"承接人"`
// 公司
Company *domain.Company `comment:"公司"`
// 组织机构
Org *domain.Org `comment:"组织"`
// 操作人
Operator *domain.User `comment:"操作人"`
// 操作时间
... ...
... ... @@ -13,7 +13,9 @@ func TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationC
CooperationContractNumber: cooperationContractChangeLogModel.CooperationContractNumber,
Undertakers: cooperationContractChangeLogModel.Undertakers,
Company: cooperationContractChangeLogModel.Company,
Org: cooperationContractChangeLogModel.Org,
Operator: cooperationContractChangeLogModel.Operator,
OperatorTime: cooperationContractChangeLogModel.OperatorTime,
UpdatedAt: cooperationContractChangeLogModel.UpdatedAt,
DeletedAt: cooperationContractChangeLogModel.DeletedAt,
CreatedAt: cooperationContractChangeLogModel.CreatedAt,
... ...
... ... @@ -33,6 +33,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
"cooperation_contract_number",
"undertakers",
"company",
"org",
"operator",
"operator_time",
"updated_at",
... ... @@ -60,6 +61,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
&cooperationContractChangeLog.CooperationContractNumber,
&cooperationContractChangeLog.Undertakers,
&cooperationContractChangeLog.Company,
&cooperationContractChangeLog.Org,
&cooperationContractChangeLog.Operator,
&cooperationContractChangeLog.OperatorTime,
&cooperationContractChangeLog.UpdatedAt,
... ... @@ -73,6 +75,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
cooperationContractChangeLog.CooperationContractNumber,
cooperationContractChangeLog.Undertakers,
cooperationContractChangeLog.Company,
cooperationContractChangeLog.Org,
cooperationContractChangeLog.Operator,
cooperationContractChangeLog.OperatorTime,
cooperationContractChangeLog.UpdatedAt,
... ... @@ -90,6 +93,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
&cooperationContractChangeLog.CooperationContractNumber,
&cooperationContractChangeLog.Undertakers,
&cooperationContractChangeLog.Company,
&cooperationContractChangeLog.Org,
&cooperationContractChangeLog.Operator,
&cooperationContractChangeLog.OperatorTime,
&cooperationContractChangeLog.UpdatedAt,
... ... @@ -103,6 +107,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
cooperationContractChangeLog.CooperationContractNumber,
cooperationContractChangeLog.Undertakers,
cooperationContractChangeLog.Company,
cooperationContractChangeLog.Org,
cooperationContractChangeLog.Operator,
cooperationContractChangeLog.OperatorTime,
cooperationContractChangeLog.UpdatedAt,
... ...