作者 陈志颖

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

... ... @@ -568,7 +568,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
Org: organization,
Company: company,
Operator: nil,
OperateTime: time.Now(),
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
... ...
... ... @@ -166,14 +166,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
tx := repository.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
dividendsEstimateId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
dividendsEstimate.DividendsEstimateId = dividendsEstimateId
}
dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
DividendsAmount: dividendsEstimate.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
... ... @@ -192,13 +185,21 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
IsCanceled: dividendsEstimate.IsCanceled,
CreatedAt: dividendsEstimate.CreatedAt,
DeletedAt: dividendsEstimate.DeletedAt,
UpdatedAt: time.Now(),
UpdatedAt: dividendsEstimate.UpdatedAt,
})
}
if _, err := tx.Model(&dividendsEstimateModels).WherePK().Update(); err != nil {
if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {
return nil, err
}
return dividendsEstimates, nil
dividendsEstimatesSaved := []*domain.DividendsEstimate{}
for _, dividendsEstimateModel := range dividendsEstimateModels {
if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
return dividendsEstimates, err
} else {
dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimate)
}
}
return dividendsEstimatesSaved, nil
}
func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) {
... ... @@ -231,7 +232,15 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*
if _, err := tx.Model(&dividendsEstimateModels).WherePK().Update(); err != nil {
return nil, err
}
return dividendsEstimates, nil
dividendsEstimatesUpdated := []*domain.DividendsEstimate{}
for _, dividendsEstimateModel := range dividendsEstimateModels {
if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
return dividendsEstimates, err
} else {
dividendsEstimatesUpdated = append(dividendsEstimatesUpdated, dividendsEstimate)
}
}
return dividendsEstimatesUpdated, nil
}
func (repository *DividendsEstimateRepository) Remove(dividendsEstimate *domain.DividendsEstimate) (*domain.DividendsEstimate, error) {
... ...