fix(god):基本完成天神模式中的查询调整。
This commit is contained in:
parent
8a070d4396
commit
aa5c43e51a
|
@ -12,5 +12,5 @@ func TimeoutContext(multiply ...int64) (context.Context, context.CancelFunc) {
|
|||
ratio = multiply[0]
|
||||
}
|
||||
timeout := time.Duration(ratio*5) * time.Second
|
||||
return context.WithTimeout(context.Background(), timeout)
|
||||
return context.WithTimeout(context.TODO(), timeout)
|
||||
}
|
||||
|
|
|
@ -75,13 +75,16 @@ func (_GodModeService) resetReportSummary(tx *bun.Tx, ctx *context.Context, repo
|
|||
return false, err
|
||||
}
|
||||
var report = new(model.Report)
|
||||
err = tx.NewSelect().Model(report).WhereAllWithDeleted().Scan(*ctx)
|
||||
err = tx.NewSelect().Model(report).Where("id = ?", reportId).Scan(*ctx)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
}
|
||||
report.StepState.Summary = false
|
||||
res, err := tx.NewUpdate().Model(report).Column("step_state").Exec(*ctx)
|
||||
res, err := tx.NewUpdate().Model(report).
|
||||
Column("step_state").
|
||||
WherePK().
|
||||
Exec(*ctx)
|
||||
rows, _ := res.RowsAffected()
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
|
@ -115,7 +118,7 @@ func (_GodModeService) flushReportMaintenances(tx *bun.Tx, ctx *context.Context,
|
|||
return rows >= 0, err
|
||||
}
|
||||
|
||||
func (_GodModeService) resetSingleEndUserRecord(tx *bun.Tx, ctx *context.Context, record *model.EndUserDetail, additionalColumns ...string) (bool, error) {
|
||||
func (g _GodModeService) resetSingleEndUserRecord(tx *bun.Tx, ctx *context.Context, record model.EndUserDetail, additionalColumns ...string) (bool, error) {
|
||||
record.CurrentPeriodOverall = decimal.Zero
|
||||
record.CurrentPeriodCritical = decimal.Zero
|
||||
record.CurrentPeriodPeak = decimal.Zero
|
||||
|
@ -126,24 +129,42 @@ func (_GodModeService) resetSingleEndUserRecord(tx *bun.Tx, ctx *context.Context
|
|||
record.AdjustPeak = decimal.Zero
|
||||
record.AdjustFlat = decimal.Zero
|
||||
record.AdjustValley = decimal.Zero
|
||||
record.Overall = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.Overall.Valid = false
|
||||
record.OverallFee = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.OverallFee.Valid = false
|
||||
record.OverallProportion = decimal.Zero
|
||||
record.Critical = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.Critical.Valid = false
|
||||
record.CriticalFee = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.CriticalFee.Valid = false
|
||||
record.Peak = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.Peak.Valid = false
|
||||
record.PeakFee = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.PeakFee.Valid = false
|
||||
record.Flat = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.Flat.Valid = false
|
||||
record.FlatFee = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.FlatFee.Valid = false
|
||||
record.Valley = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.Valley.Valid = false
|
||||
record.ValleyFee = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.ValleyFee.Valid = false
|
||||
record.BasicFeeDiluted = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.BasicFeeDiluted.Valid = false
|
||||
record.AdjustFeeDiluted = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.AdjustFeeDiluted.Valid = false
|
||||
record.LossDiluted = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.LossDiluted.Valid = false
|
||||
record.LossFeeDiluted = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.LossFeeDiluted.Valid = false
|
||||
record.MaintenanceFeeDiluted = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.MaintenanceFeeDiluted.Valid = false
|
||||
record.FinalDiluted = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.FinalDiluted.Valid = false
|
||||
record.PublicConsumptionDiluted = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.PublicConsumptionDiluted.Valid = false
|
||||
record.FinalCharge = decimal.NewNullDecimal(decimal.Zero)
|
||||
record.FinalCharge.Valid = false
|
||||
|
||||
columns := []string{
|
||||
|
@ -168,7 +189,7 @@ func (_GodModeService) resetSingleEndUserRecord(tx *bun.Tx, ctx *context.Context
|
|||
"flat_fee",
|
||||
"valley",
|
||||
"valley_fee",
|
||||
"baseic_fee_diluted",
|
||||
"basic_fee_diluted",
|
||||
"adjust_fee_diluted",
|
||||
"loss_diluted",
|
||||
"loss_fee_diluted",
|
||||
|
@ -179,12 +200,11 @@ func (_GodModeService) resetSingleEndUserRecord(tx *bun.Tx, ctx *context.Context
|
|||
}
|
||||
columns = append(columns, additionalColumns...)
|
||||
|
||||
res, err := tx.NewUpdate().Model(record).
|
||||
_, err := tx.NewUpdate().Model(&record).
|
||||
WherePK().
|
||||
Column(columns...).
|
||||
Exec(*ctx)
|
||||
affected, _ := res.RowsAffected()
|
||||
if err != nil || affected == 0 {
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
}
|
||||
|
@ -203,7 +223,6 @@ func (g _GodModeService) resynchronizeEndUserArchives(tx *bun.Tx, ctx *context.C
|
|||
var report = new(model.Report)
|
||||
err = tx.NewSelect().Model(report).
|
||||
Where("id = ?", reportId).
|
||||
WhereAllWithDeleted().
|
||||
Scan(*ctx)
|
||||
if err != nil || report == nil {
|
||||
tx.Rollback()
|
||||
|
@ -233,7 +252,7 @@ func (g _GodModeService) resynchronizeEndUserArchives(tx *bun.Tx, ctx *context.C
|
|||
record.IsPublicMeter = meter.IsPublicMeter
|
||||
record.WillDilute = meter.WillDilute
|
||||
success, err := g.resetSingleEndUserRecord(
|
||||
tx, ctx, record,
|
||||
tx, ctx, *record,
|
||||
"customer_name",
|
||||
"address",
|
||||
"ratio",
|
||||
|
@ -286,7 +305,7 @@ func (g _GodModeService) resynchronizeEndUserArchives(tx *bun.Tx, ctx *context.C
|
|||
}
|
||||
|
||||
func (g _GodModeService) resetEndUserRecords(tx *bun.Tx, ctx *context.Context, reportId string) (bool, error) {
|
||||
var records = make([]*model.EndUserDetail, 0)
|
||||
var records = make([]model.EndUserDetail, 0)
|
||||
err := tx.NewSelect().Model(&records).
|
||||
Where("report_id = ?", reportId).
|
||||
Scan(*ctx)
|
||||
|
@ -301,7 +320,7 @@ func (g _GodModeService) resetEndUserRecords(tx *bun.Tx, ctx *context.Context, r
|
|||
}
|
||||
}
|
||||
var report = new(model.Report)
|
||||
err = tx.NewSelect().Model(report).WhereAllWithDeleted().
|
||||
err = tx.NewSelect().Model(report).
|
||||
Where("id = ?", reportId).
|
||||
Scan(*ctx)
|
||||
if err != nil {
|
||||
|
@ -329,10 +348,9 @@ func (_GodModeService) isTheLatestReport(ctx *context.Context, reportId string)
|
|||
var report = new(model.Report)
|
||||
err := global.DB.NewSelect().Model(report).
|
||||
Where("id = ?", reportId).
|
||||
WhereAllWithDeleted().
|
||||
Scan(*ctx)
|
||||
if err != nil || report == nil {
|
||||
return false, exceptions.NewNotFoundErrorFromError("指定报表索引未找到。", err)
|
||||
return false, exceptions.NewNotFoundErrorFromError("指定报表索引未找到,", err)
|
||||
}
|
||||
var maxPeriod time.Time
|
||||
err = global.DB.NewSelect().Model((*model.Report)(nil)).
|
||||
|
@ -378,7 +396,7 @@ func (_GodModeService) forceDeleteReport(tx *bun.Tx, ctx *context.Context, repor
|
|||
}
|
||||
|
||||
func (g _GodModeService) ClearReportSummary(reportId string) (bool, error) {
|
||||
ctx, cancel := global.TimeoutContext()
|
||||
ctx, cancel := global.TimeoutContext(12)
|
||||
defer cancel()
|
||||
|
||||
isLatest, err := g.isTheLatestReport(&ctx, reportId)
|
||||
|
@ -469,7 +487,7 @@ func (g _GodModeService) ResynchronizeEndUser(reportId string) (bool, error) {
|
|||
}
|
||||
|
||||
func (g _GodModeService) ResetEndUserRegisterRecords(reportId string) (bool, error) {
|
||||
ctx, cancel := global.TimeoutContext()
|
||||
ctx, cancel := global.TimeoutContext(48)
|
||||
defer cancel()
|
||||
|
||||
isLatest, err := g.isTheLatestReport(&ctx, reportId)
|
||||
|
@ -822,7 +840,8 @@ func (g _GodModeService) DeleteUser(userId string) (bool, error) {
|
|||
}
|
||||
// 删除用户详细信息数据
|
||||
res, err = tx.NewDelete().Model((*model.UserDetail)(nil)).
|
||||
Where("user_id = ?", userId).
|
||||
Where("id = ?", userId).
|
||||
ForceDelete().
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
|
|
Loading…
Reference in New Issue
Block a user