作者 陈志颖

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

@@ -225,10 +225,27 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService) @@ -225,10 +225,27 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService)
225 defer func() { 225 defer func() {
226 _ = transactionContext.RollbackTransaction() 226 _ = transactionContext.RollbackTransaction()
227 }() 227 }()
  228 + var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
  229 + if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
  230 + "transactionContext": transactionContext,
  231 + }); err != nil {
  232 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  233 + } else {
  234 + cooperationContractChangeLogRepository = value
  235 + }
  236 + if count, cooperationContractChangeLogs, err := cooperationContractChangeLogRepository.Find(tool_funs.SimpleStructToMap(searchCooperationContractChangeLogQuery)); err != nil {
  237 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  238 + } else {
228 if err := transactionContext.CommitTransaction(); err != nil { 239 if err := transactionContext.CommitTransaction(); err != nil {
229 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 240 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
230 } 241 }
231 - return nil, nil 242 + return map[string]interface{}{
  243 + "grid": map[string]interface{}{
  244 + "total": count,
  245 + "list": cooperationContractChangeLogs,
  246 + },
  247 + }, nil
  248 + }
232 } 249 }
233 250
234 // UpdateCooperationContractChangeLog 更新共创合约变更日志 251 // UpdateCooperationContractChangeLog 更新共创合约变更日志
@@ -259,7 +276,7 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService) @@ -259,7 +276,7 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService)
259 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 276 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
260 } 277 }
261 if cooperationContractChangeLog == nil { 278 if cooperationContractChangeLog == nil {
262 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractChangeLogCommand.CooperationContractChangeLogId))) 279 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(updateCooperationContractChangeLogCommand.CooperationContractChangeLogId, 10)))
263 } 280 }
264 if err := cooperationContractChangeLog.Update(tool_funs.SimpleStructToMap(updateCooperationContractChangeLogCommand)); err != nil { 281 if err := cooperationContractChangeLog.Update(tool_funs.SimpleStructToMap(updateCooperationContractChangeLogCommand)); err != nil {
265 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 282 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -24,6 +24,7 @@ func (repository *CooperationContractChangeLogRepository) nextIdentify() (int64, @@ -24,6 +24,7 @@ func (repository *CooperationContractChangeLogRepository) nextIdentify() (int64,
24 id, err := IdWorker.NextId() 24 id, err := IdWorker.NextId()
25 return id, err 25 return id, err
26 } 26 }
  27 +
27 func (repository *CooperationContractChangeLogRepository) Save(cooperationContractChangeLog *domain.CooperationContractChangeLog) (*domain.CooperationContractChangeLog, error) { 28 func (repository *CooperationContractChangeLogRepository) Save(cooperationContractChangeLog *domain.CooperationContractChangeLog) (*domain.CooperationContractChangeLog, error) {
28 sqlBuildFields := []string{ 29 sqlBuildFields := []string{
29 "incentives_rule", 30 "incentives_rule",
@@ -72,7 +73,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -72,7 +73,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
72 cooperationContractChangeLog.Company, 73 cooperationContractChangeLog.Company,
73 cooperationContractChangeLog.Operator, 74 cooperationContractChangeLog.Operator,
74 cooperationContractChangeLog.UpdatedAt, 75 cooperationContractChangeLog.UpdatedAt,
75 - cooperationContractChangeLog.DeletedAt, 76 + nil,
76 cooperationContractChangeLog.CreatedAt, 77 cooperationContractChangeLog.CreatedAt,
77 ); err != nil { 78 ); err != nil {
78 return cooperationContractChangeLog, err 79 return cooperationContractChangeLog, err
@@ -100,7 +101,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -100,7 +101,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
100 cooperationContractChangeLog.Company, 101 cooperationContractChangeLog.Company,
101 cooperationContractChangeLog.Operator, 102 cooperationContractChangeLog.Operator,
102 cooperationContractChangeLog.UpdatedAt, 103 cooperationContractChangeLog.UpdatedAt,
103 - cooperationContractChangeLog.DeletedAt, 104 + nil,
104 cooperationContractChangeLog.CreatedAt, 105 cooperationContractChangeLog.CreatedAt,
105 cooperationContractChangeLog.Identify(), 106 cooperationContractChangeLog.Identify(),
106 ); err != nil { 107 ); err != nil {
@@ -109,6 +110,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -109,6 +110,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
109 } 110 }
110 return cooperationContractChangeLog, nil 111 return cooperationContractChangeLog, nil
111 } 112 }
  113 +
112 func (repository *CooperationContractChangeLogRepository) Remove(cooperationContractChangeLog *domain.CooperationContractChangeLog) (*domain.CooperationContractChangeLog, error) { 114 func (repository *CooperationContractChangeLogRepository) Remove(cooperationContractChangeLog *domain.CooperationContractChangeLog) (*domain.CooperationContractChangeLog, error) {
113 tx := repository.transactionContext.PgTx 115 tx := repository.transactionContext.PgTx
114 cooperationContractChangeLogModel := new(models.CooperationContractChangeLog) 116 cooperationContractChangeLogModel := new(models.CooperationContractChangeLog)
@@ -118,6 +120,7 @@ func (repository *CooperationContractChangeLogRepository) Remove(cooperationCont @@ -118,6 +120,7 @@ func (repository *CooperationContractChangeLogRepository) Remove(cooperationCont
118 } 120 }
119 return cooperationContractChangeLog, nil 121 return cooperationContractChangeLog, nil
120 } 122 }
  123 +
121 func (repository *CooperationContractChangeLogRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContractChangeLog, error) { 124 func (repository *CooperationContractChangeLogRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContractChangeLog, error) {
122 tx := repository.transactionContext.PgTx 125 tx := repository.transactionContext.PgTx
123 cooperationContractChangeLogModel := new(models.CooperationContractChangeLog) 126 cooperationContractChangeLogModel := new(models.CooperationContractChangeLog)
@@ -136,11 +139,18 @@ func (repository *CooperationContractChangeLogRepository) FindOne(queryOptions m @@ -136,11 +139,18 @@ func (repository *CooperationContractChangeLogRepository) FindOne(queryOptions m
136 return transform.TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationContractChangeLogModel) 139 return transform.TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationContractChangeLogModel)
137 } 140 }
138 } 141 }
  142 +
139 func (repository *CooperationContractChangeLogRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractChangeLog, error) { 143 func (repository *CooperationContractChangeLogRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractChangeLog, error) {
140 tx := repository.transactionContext.PgTx 144 tx := repository.transactionContext.PgTx
141 var cooperationContractChangeLogModels []*models.CooperationContractChangeLog 145 var cooperationContractChangeLogModels []*models.CooperationContractChangeLog
142 cooperationContractChangeLogs := make([]*domain.CooperationContractChangeLog, 0) 146 cooperationContractChangeLogs := make([]*domain.CooperationContractChangeLog, 0)
143 query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractChangeLogModels), queryOptions) 147 query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractChangeLogModels), queryOptions)
  148 + if operationType, ok := queryOptions["operationType"]; ok && operationType.(int32) != 0 {
  149 + query.Where("operation_type = ?", operationType)
  150 + }
  151 + if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
  152 + query.Where("cooperation_contract_number ilike ?", fmt.Sprintf("%%%s%%", cooperationContractNumber))
  153 + }
144 offsetLimitFlag := true 154 offsetLimitFlag := true
145 if offsetLimit, ok := queryOptions["offsetLimit"]; ok { 155 if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
146 offsetLimitFlag = offsetLimit.(bool) 156 offsetLimitFlag = offsetLimit.(bool)
@@ -162,6 +172,7 @@ func (repository *CooperationContractChangeLogRepository) Find(queryOptions map[ @@ -162,6 +172,7 @@ func (repository *CooperationContractChangeLogRepository) Find(queryOptions map[
162 return int64(count), cooperationContractChangeLogs, nil 172 return int64(count), cooperationContractChangeLogs, nil
163 } 173 }
164 } 174 }
  175 +
165 func NewCooperationContractChangeLogRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractChangeLogRepository, error) { 176 func NewCooperationContractChangeLogRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractChangeLogRepository, error) {
166 if transactionContext == nil { 177 if transactionContext == nil {
167 return nil, fmt.Errorf("transactionContext参数不能为nil") 178 return nil, fmt.Errorf("transactionContext参数不能为nil")