作者 陈志颖

feat:共创合约变更记录仓储增加查询

... ... @@ -225,10 +225,27 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService)
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
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
}
if count, cooperationContractChangeLogs, err := cooperationContractChangeLogRepository.Find(tool_funs.SimpleStructToMap(searchCooperationContractChangeLogQuery)); 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 map[string]interface{}{
"grid": map[string]interface{}{
"total": count,
"list": cooperationContractChangeLogs,
},
}, nil
}
return nil, nil
}
// UpdateCooperationContractChangeLog 更新共创合约变更日志
... ... @@ -259,7 +276,7 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService)
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContractChangeLog == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractChangeLogCommand.CooperationContractChangeLogId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(updateCooperationContractChangeLogCommand.CooperationContractChangeLogId, 10)))
}
if err := cooperationContractChangeLog.Update(tool_funs.SimpleStructToMap(updateCooperationContractChangeLogCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -24,6 +24,7 @@ func (repository *CooperationContractChangeLogRepository) nextIdentify() (int64,
id, err := IdWorker.NextId()
return id, err
}
func (repository *CooperationContractChangeLogRepository) Save(cooperationContractChangeLog *domain.CooperationContractChangeLog) (*domain.CooperationContractChangeLog, error) {
sqlBuildFields := []string{
"incentives_rule",
... ... @@ -72,7 +73,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
cooperationContractChangeLog.Company,
cooperationContractChangeLog.Operator,
cooperationContractChangeLog.UpdatedAt,
cooperationContractChangeLog.DeletedAt,
nil,
cooperationContractChangeLog.CreatedAt,
); err != nil {
return cooperationContractChangeLog, err
... ... @@ -100,7 +101,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
cooperationContractChangeLog.Company,
cooperationContractChangeLog.Operator,
cooperationContractChangeLog.UpdatedAt,
cooperationContractChangeLog.DeletedAt,
nil,
cooperationContractChangeLog.CreatedAt,
cooperationContractChangeLog.Identify(),
); err != nil {
... ... @@ -109,6 +110,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
}
return cooperationContractChangeLog, nil
}
func (repository *CooperationContractChangeLogRepository) Remove(cooperationContractChangeLog *domain.CooperationContractChangeLog) (*domain.CooperationContractChangeLog, error) {
tx := repository.transactionContext.PgTx
cooperationContractChangeLogModel := new(models.CooperationContractChangeLog)
... ... @@ -118,6 +120,7 @@ func (repository *CooperationContractChangeLogRepository) Remove(cooperationCont
}
return cooperationContractChangeLog, nil
}
func (repository *CooperationContractChangeLogRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContractChangeLog, error) {
tx := repository.transactionContext.PgTx
cooperationContractChangeLogModel := new(models.CooperationContractChangeLog)
... ... @@ -136,11 +139,18 @@ func (repository *CooperationContractChangeLogRepository) FindOne(queryOptions m
return transform.TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationContractChangeLogModel)
}
}
func (repository *CooperationContractChangeLogRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractChangeLog, error) {
tx := repository.transactionContext.PgTx
var cooperationContractChangeLogModels []*models.CooperationContractChangeLog
cooperationContractChangeLogs := make([]*domain.CooperationContractChangeLog, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractChangeLogModels), queryOptions)
if operationType, ok := queryOptions["operationType"]; ok && operationType.(int32) != 0 {
query.Where("operation_type = ?", operationType)
}
if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
query.Where("cooperation_contract_number ilike ?", fmt.Sprintf("%%%s%%", cooperationContractNumber))
}
offsetLimitFlag := true
if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
offsetLimitFlag = offsetLimit.(bool)
... ... @@ -162,6 +172,7 @@ func (repository *CooperationContractChangeLogRepository) Find(queryOptions map[
return int64(count), cooperationContractChangeLogs, nil
}
}
func NewCooperationContractChangeLogRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractChangeLogRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...