作者 陈志颖

refactor:优化分红预算更新仓储

@@ -568,7 +568,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -568,7 +568,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
568 Org: organization, 568 Org: organization,
569 Company: company, 569 Company: company,
570 Operator: nil, 570 Operator: nil,
571 - OperateTime: time.Now(), 571 + OperateTime: time.Time{},
572 IsCanceled: false, 572 IsCanceled: false,
573 CreatedAt: time.Now(), 573 CreatedAt: time.Now(),
574 DeletedAt: time.Time{}, 574 DeletedAt: time.Time{},
@@ -166,14 +166,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do @@ -166,14 +166,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
166 tx := repository.transactionContext.PgTx 166 tx := repository.transactionContext.PgTx
167 var dividendsEstimateModels []*models.DividendsEstimate 167 var dividendsEstimateModels []*models.DividendsEstimate
168 for _, dividendsEstimate := range dividendsEstimates { 168 for _, dividendsEstimate := range dividendsEstimates {
169 - dividendsEstimateId, err := repository.nextIdentify()  
170 - if err != nil {  
171 - return nil, err  
172 - } else {  
173 - dividendsEstimate.DividendsEstimateId = dividendsEstimateId  
174 - }  
175 dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{ 169 dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
176 - DividendsEstimateId: dividendsEstimate.DividendsEstimateId,  
177 DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus, 170 DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
178 DividendsAmount: dividendsEstimate.DividendsAmount, 171 DividendsAmount: dividendsEstimate.DividendsAmount,
179 DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber, 172 DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
@@ -192,13 +185,21 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do @@ -192,13 +185,21 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
192 IsCanceled: dividendsEstimate.IsCanceled, 185 IsCanceled: dividendsEstimate.IsCanceled,
193 CreatedAt: dividendsEstimate.CreatedAt, 186 CreatedAt: dividendsEstimate.CreatedAt,
194 DeletedAt: dividendsEstimate.DeletedAt, 187 DeletedAt: dividendsEstimate.DeletedAt,
195 - UpdatedAt: time.Now(), 188 + UpdatedAt: dividendsEstimate.UpdatedAt,
196 }) 189 })
197 } 190 }
198 - if _, err := tx.Model(&dividendsEstimateModels).WherePK().Update(); err != nil { 191 + if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {
199 return nil, err 192 return nil, err
200 } 193 }
201 - return dividendsEstimates, nil 194 + dividendsEstimatesSaved := []*domain.DividendsEstimate{}
  195 + for _, dividendsEstimateModel := range dividendsEstimateModels {
  196 + if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
  197 + return dividendsEstimates, err
  198 + } else {
  199 + dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimate)
  200 + }
  201 + }
  202 + return dividendsEstimatesSaved, nil
202 } 203 }
203 204
204 func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) { 205 func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) {
@@ -231,7 +232,15 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []* @@ -231,7 +232,15 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*
231 if _, err := tx.Model(&dividendsEstimateModels).WherePK().Update(); err != nil { 232 if _, err := tx.Model(&dividendsEstimateModels).WherePK().Update(); err != nil {
232 return nil, err 233 return nil, err
233 } 234 }
234 - return dividendsEstimates, nil 235 + dividendsEstimatesUpdated := []*domain.DividendsEstimate{}
  236 + for _, dividendsEstimateModel := range dividendsEstimateModels {
  237 + if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
  238 + return dividendsEstimates, err
  239 + } else {
  240 + dividendsEstimatesUpdated = append(dividendsEstimatesUpdated, dividendsEstimate)
  241 + }
  242 + }
  243 + return dividendsEstimatesUpdated, nil
235 } 244 }
236 245
237 func (repository *DividendsEstimateRepository) Remove(dividendsEstimate *domain.DividendsEstimate) (*domain.DividendsEstimate, error) { 246 func (repository *DividendsEstimateRepository) Remove(dividendsEstimate *domain.DividendsEstimate) (*domain.DividendsEstimate, error) {