refactor(god):天神模式基本完成迁移。
This commit is contained in:
parent
fc3f931362
commit
df08c31278
|
@ -1,34 +1,40 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
"electricity_bill_calc/cache"
|
"electricity_bill_calc/cache"
|
||||||
"electricity_bill_calc/exceptions"
|
"electricity_bill_calc/exceptions"
|
||||||
"electricity_bill_calc/global"
|
"electricity_bill_calc/global"
|
||||||
|
"electricity_bill_calc/logger"
|
||||||
"electricity_bill_calc/model"
|
"electricity_bill_calc/model"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
"xorm.io/builder"
|
"github.com/uptrace/bun"
|
||||||
"xorm.io/xorm"
|
"go.uber.org/zap"
|
||||||
"xorm.io/xorm/schemas"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type _GodModeService struct{}
|
type _GodModeService struct {
|
||||||
|
l *zap.Logger
|
||||||
|
}
|
||||||
|
|
||||||
var GodModeService _GodModeService
|
var GodModeService = _GodModeService{
|
||||||
|
l: logger.Named("Service", "GodMode"),
|
||||||
|
}
|
||||||
|
|
||||||
// 从此处开始为删除报表相关的部分
|
// 从此处开始为删除报表相关的部分
|
||||||
|
|
||||||
func (_GodModeService) resetReportIndex(tx *xorm.Session, reportId string) (bool, error) {
|
func (_GodModeService) resetReportIndex(tx *bun.Tx, ctx *context.Context, reportId string) (bool, error) {
|
||||||
var report = new(model.Report)
|
var report = new(model.Report)
|
||||||
has, err := tx.ID(reportId).NoAutoCondition().Get(report)
|
err := tx.NewSelect().Model(report).Where("id = ?", reportId).Scan(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !has {
|
if report == nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, exceptions.NewNotFoundError("指定报表索引未找到。")
|
return false, exceptions.NewNotFoundError("指定报表索引未找到。")
|
||||||
}
|
}
|
||||||
|
@ -44,9 +50,9 @@ func (_GodModeService) resetReportIndex(tx *xorm.Session, reportId string) (bool
|
||||||
report.LastWithdrawAppliedAt = nil
|
report.LastWithdrawAppliedAt = nil
|
||||||
report.LastWithdrawAuditAt = nil
|
report.LastWithdrawAuditAt = nil
|
||||||
|
|
||||||
affected, err := tx.
|
res, err := tx.NewUpdate().Model(report).
|
||||||
ID(reportId).
|
WherePK().
|
||||||
MustCols(
|
Column(
|
||||||
"step_state",
|
"step_state",
|
||||||
"published",
|
"published",
|
||||||
"published_at",
|
"published_at",
|
||||||
|
@ -54,61 +60,66 @@ func (_GodModeService) resetReportIndex(tx *xorm.Session, reportId string) (bool
|
||||||
"last_withdraw_applied_at",
|
"last_withdraw_applied_at",
|
||||||
"last_withdraw_audit_at",
|
"last_withdraw_audit_at",
|
||||||
).
|
).
|
||||||
Update(report)
|
Exec(*ctx)
|
||||||
if err != nil {
|
|
||||||
|
if affected, _ := res.RowsAffected(); err != nil || affected == 0 {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return affected > 0, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_GodModeService) resetReportSummary(tx *xorm.Session, reportId string) (bool, error) {
|
func (_GodModeService) resetReportSummary(tx *bun.Tx, ctx *context.Context, reportId string) (bool, error) {
|
||||||
var summary = &model.ReportSummary{
|
var summary = &model.ReportSummary{
|
||||||
ReportId: reportId,
|
ReportId: reportId,
|
||||||
}
|
}
|
||||||
_, err := tx.ID(reportId).AllCols().NoAutoCondition().Update(summary)
|
_, err := tx.NewUpdate().Model(summary).WherePK().Exec(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
var report = new(model.Report)
|
var report = new(model.Report)
|
||||||
_, err = tx.ID(reportId).NoAutoCondition().Unscoped().Get(report)
|
err = tx.NewSelect().Model(report).WhereAllWithDeleted().Scan(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
report.StepState.Summary = false
|
report.StepState.Summary = false
|
||||||
rows, err := tx.ID(reportId).Cols("step_state").NoAutoCondition().Update(report)
|
res, err := tx.NewUpdate().Model(report).Column("step_state").Exec(*ctx)
|
||||||
|
rows, _ := res.RowsAffected()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
}
|
}
|
||||||
return rows >= 0, err
|
return rows >= 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_GodModeService) flushReportMaintenances(tx *xorm.Session, reportId string) (bool, error) {
|
func (_GodModeService) flushReportMaintenances(tx *bun.Tx, ctx *context.Context, reportId string) (bool, error) {
|
||||||
_, err := tx.
|
_, err := tx.NewDelete().Model((*model.WillDilutedFee)(nil)).
|
||||||
Where(builder.Eq{"report_id": reportId}).
|
Where("report_id = ?", reportId).
|
||||||
NoAutoCondition().
|
Exec(*ctx)
|
||||||
Delete(new(model.WillDilutedFee))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
var report = new(model.Report)
|
var report = new(model.Report)
|
||||||
_, err = tx.ID(reportId).NoAutoCondition().Unscoped().Get(report)
|
err = tx.NewSelect().Model(report).Where("id = ?", reportId).Scan(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
report.StepState.WillDiluted = false
|
report.StepState.WillDiluted = false
|
||||||
rows, err := tx.ID(reportId).Cols("step_state").NoAutoCondition().Update(report)
|
res, err := tx.NewUpdate().Model(report).
|
||||||
|
WherePK().
|
||||||
|
Column("step_state").
|
||||||
|
Exec(*ctx)
|
||||||
|
rows, _ := res.RowsAffected()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
}
|
}
|
||||||
return rows >= 0, err
|
return rows >= 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_GodModeService) resetSingleEndUserRecord(tx *xorm.Session, record *model.EndUserDetail, additionalColumns ...string) (bool, error) {
|
func (_GodModeService) resetSingleEndUserRecord(tx *bun.Tx, ctx *context.Context, record *model.EndUserDetail, additionalColumns ...string) (bool, error) {
|
||||||
record.CurrentPeriodOverall = decimal.Zero
|
record.CurrentPeriodOverall = decimal.Zero
|
||||||
record.CurrentPeriodCritical = decimal.Zero
|
record.CurrentPeriodCritical = decimal.Zero
|
||||||
record.CurrentPeriodPeak = decimal.Zero
|
record.CurrentPeriodPeak = decimal.Zero
|
||||||
|
@ -172,10 +183,11 @@ func (_GodModeService) resetSingleEndUserRecord(tx *xorm.Session, record *model.
|
||||||
}
|
}
|
||||||
columns = append(columns, additionalColumns...)
|
columns = append(columns, additionalColumns...)
|
||||||
|
|
||||||
affected, err := tx.
|
res, err := tx.NewUpdate().Model(record).
|
||||||
ID(schemas.PK{record.ReportId, record.ParkId, record.MeterId}).
|
WherePK().
|
||||||
MustCols(columns...).
|
Column(columns...).
|
||||||
Update(record)
|
Exec(*ctx)
|
||||||
|
affected, _ := res.RowsAffected()
|
||||||
if err != nil || affected == 0 {
|
if err != nil || affected == 0 {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -183,21 +195,29 @@ func (_GodModeService) resetSingleEndUserRecord(tx *xorm.Session, record *model.
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) resynchronizeEndUserArchives(tx *xorm.Session, reportId string) (bool, error) {
|
func (g _GodModeService) resynchronizeEndUserArchives(tx *bun.Tx, ctx *context.Context, reportId string) (bool, error) {
|
||||||
var currentRecords = make([]*model.EndUserDetail, 0)
|
var currentRecords = make([]*model.EndUserDetail, 0)
|
||||||
err := tx.Where(builder.Eq{"report_id": reportId}).Find(¤tRecords)
|
err := tx.NewSelect().Model(¤tRecords).
|
||||||
|
Where("report_id = ?", reportId).
|
||||||
|
Scan(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
var report = new(model.Report)
|
var report = new(model.Report)
|
||||||
has, err := tx.ID(reportId).NoAutoCondition().Unscoped().Get(report)
|
err = tx.NewSelect().Model(report).
|
||||||
if err != nil || !has {
|
Where("id = ?", reportId).
|
||||||
|
WhereAllWithDeleted().
|
||||||
|
Scan(*ctx)
|
||||||
|
if err != nil || report == nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
var latestArchives = make([]model.Meter04KV, 0)
|
var latestArchives = make([]model.Meter04KV, 0)
|
||||||
err = tx.Table(new(model.Meter04KV)).Where(builder.Eq{"park_id": report.ParkId}).Find(&latestArchives)
|
err = tx.NewSelect().Model(&latestArchives).
|
||||||
|
Where("park_id = ?", report.ParkId).
|
||||||
|
Where("enabled = ?", true).
|
||||||
|
Scan(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -217,7 +237,7 @@ func (g _GodModeService) resynchronizeEndUserArchives(tx *xorm.Session, reportId
|
||||||
record.IsPublicMeter = meter.IsPublicMeter
|
record.IsPublicMeter = meter.IsPublicMeter
|
||||||
record.WillDilute = meter.WillDilute
|
record.WillDilute = meter.WillDilute
|
||||||
success, err := g.resetSingleEndUserRecord(
|
success, err := g.resetSingleEndUserRecord(
|
||||||
tx, record,
|
tx, ctx, record,
|
||||||
"customer_name",
|
"customer_name",
|
||||||
"address",
|
"address",
|
||||||
"ratio",
|
"ratio",
|
||||||
|
@ -249,7 +269,7 @@ func (g _GodModeService) resynchronizeEndUserArchives(tx *xorm.Session, reportId
|
||||||
LastPeriodFlat: decimal.Zero,
|
LastPeriodFlat: decimal.Zero,
|
||||||
LastPeriodValley: decimal.Zero,
|
LastPeriodValley: decimal.Zero,
|
||||||
}
|
}
|
||||||
_, err = tx.Insert(newEndUser)
|
_, err = tx.NewInsert().Model(&newEndUser).Exec(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -258,34 +278,46 @@ func (g _GodModeService) resynchronizeEndUserArchives(tx *xorm.Session, reportId
|
||||||
}
|
}
|
||||||
|
|
||||||
report.StepState.Submeter = false
|
report.StepState.Submeter = false
|
||||||
rows, err := tx.ID(reportId).Cols("step_state").NoAutoCondition().Update(report)
|
res, err := tx.NewUpdate().Model(report).
|
||||||
|
WherePK().
|
||||||
|
Column("step_state").
|
||||||
|
Exec(*ctx)
|
||||||
|
rows, _ := res.RowsAffected()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
}
|
}
|
||||||
return rows >= 0, nil
|
return rows >= 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) resetEndUserRecords(tx *xorm.Session, reportId string) (bool, error) {
|
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.Where(builder.Eq{"report_id": reportId}).Find(&records)
|
err := tx.NewSelect().Model(&records).
|
||||||
|
Where("report_id = ?", reportId).
|
||||||
|
Scan(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
for _, u := range records {
|
for _, u := range records {
|
||||||
success, err := g.resetSingleEndUserRecord(tx, u)
|
success, err := g.resetSingleEndUserRecord(tx, ctx, u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return success, err
|
return success, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var report = new(model.Report)
|
var report = new(model.Report)
|
||||||
_, err = tx.ID(reportId).NoAutoCondition().Unscoped().Get(report)
|
err = tx.NewSelect().Model(report).WhereAllWithDeleted().
|
||||||
|
Where("id = ?", reportId).
|
||||||
|
Scan(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
report.StepState.Submeter = false
|
report.StepState.Submeter = false
|
||||||
rows, err := tx.ID(reportId).Cols("step_state").NoAutoCondition().Update(report)
|
res, err := tx.NewUpdate().Model(report).
|
||||||
|
WherePK().
|
||||||
|
Column("step_state").
|
||||||
|
Exec(*ctx)
|
||||||
|
rows, _ := res.RowsAffected()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
}
|
}
|
||||||
|
@ -297,46 +329,51 @@ type ReportPeriod struct {
|
||||||
Period time.Time
|
Period time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_GodModeService) isTheLatestReport(reportId string) (bool, error) {
|
func (_GodModeService) isTheLatestReport(ctx *context.Context, reportId string) (bool, error) {
|
||||||
var report = new(model.Report)
|
var report = new(model.Report)
|
||||||
has, err := global.DBConn.ID(reportId).NoAutoCondition().Get(report)
|
err := global.DB.NewSelect().Model(report).
|
||||||
|
Where("id = ?", reportId).
|
||||||
|
WhereAllWithDeleted().
|
||||||
|
Scan(*ctx)
|
||||||
|
if err != nil || report == nil {
|
||||||
|
return false, exceptions.NewNotFoundErrorFromError("指定报表索引未找到。", err)
|
||||||
|
}
|
||||||
|
var maxPeriod *time.Time
|
||||||
|
err = global.DB.NewSelect().Model((*model.Report)(nil)).
|
||||||
|
ColumnExpr("max(?)", bun.Ident("period")).
|
||||||
|
Where("park_id = ?", report.ParkId).
|
||||||
|
Scan(*ctx, maxPeriod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !has {
|
return maxPeriod.Equal(report.Period), nil
|
||||||
return false, exceptions.NewNotFoundError("指定报表索引未找到。")
|
|
||||||
}
|
|
||||||
var reports = make([]ReportPeriod, 0)
|
|
||||||
err = global.DBConn.
|
|
||||||
Table(new(model.Report)).
|
|
||||||
Where(builder.Eq{"park_id": report.ParkId}).
|
|
||||||
Find(&reports)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
maxReport := lo.MaxBy(reports, func(a, b ReportPeriod) bool {
|
|
||||||
return a.Period.After(b.Period)
|
|
||||||
})
|
|
||||||
return maxReport.Id == reportId, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_GodModeService) forceDeleteReport(tx *xorm.Session, reportId string) (bool, error) {
|
func (_GodModeService) forceDeleteReport(tx *bun.Tx, ctx *context.Context, reportId string) (bool, error) {
|
||||||
_, err := tx.Exec("delete from end_user_detail where report_id=?", reportId)
|
_, err := tx.NewDelete().Model((*model.EndUserDetail)(nil)).
|
||||||
|
Where("report_id = ?", reportId).
|
||||||
|
Exec(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("delete from will_diluted_fee where report_id=?", reportId)
|
_, err = tx.NewDelete().Model((*model.WillDilutedFee)(nil)).
|
||||||
|
Where("report_id = ?", reportId).
|
||||||
|
Exec(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("delete from report_summary where report_id=?", reportId)
|
_, err = tx.NewDelete().Model((*model.ReportSummary)(nil)).
|
||||||
|
Where("report_id = ?", reportId).
|
||||||
|
Exec(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("delete from report where id=?", reportId)
|
_, err = tx.NewDelete().Model((*model.Report)(nil)).
|
||||||
|
Where("id = ?", reportId).
|
||||||
|
Exec(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -345,20 +382,22 @@ func (_GodModeService) forceDeleteReport(tx *xorm.Session, reportId string) (boo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) ClearReportSummary(reportId string) (bool, error) {
|
func (g _GodModeService) ClearReportSummary(reportId string) (bool, error) {
|
||||||
isLatest, err := g.isTheLatestReport(reportId)
|
ctx, cancel := global.TimeoutContext()
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
isLatest, err := g.isTheLatestReport(&ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !isLatest {
|
if !isLatest {
|
||||||
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
||||||
}
|
}
|
||||||
tx := global.DBConn.NewSession()
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
if err := tx.Begin(); err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
|
|
||||||
result, err := g.resetReportSummary(tx, reportId)
|
result, err := g.resetReportSummary(&tx, &ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -368,25 +407,27 @@ func (g _GodModeService) ClearReportSummary(reportId string) (bool, error) {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
cache.AbolishRelation(fmt.Sprintf("report_%s", reportId))
|
cache.AbolishRelation(fmt.Sprintf("report:%s", reportId))
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) ClearReportMaintenances(reportId string) (bool, error) {
|
func (g _GodModeService) ClearReportMaintenances(reportId string) (bool, error) {
|
||||||
isLatest, err := g.isTheLatestReport(reportId)
|
ctx, cancel := global.TimeoutContext()
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
isLatest, err := g.isTheLatestReport(&ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !isLatest {
|
if !isLatest {
|
||||||
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
||||||
}
|
}
|
||||||
tx := global.DBConn.NewSession()
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
if err := tx.Begin(); err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
|
|
||||||
result, err := g.flushReportMaintenances(tx, reportId)
|
result, err := g.flushReportMaintenances(&tx, &ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -396,25 +437,27 @@ func (g _GodModeService) ClearReportMaintenances(reportId string) (bool, error)
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
cache.AbolishRelation(fmt.Sprintf("report_%s", reportId))
|
cache.AbolishRelation(fmt.Sprintf("report:%s", reportId))
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) ResynchronizeEndUser(reportId string) (bool, error) {
|
func (g _GodModeService) ResynchronizeEndUser(reportId string) (bool, error) {
|
||||||
isLatest, err := g.isTheLatestReport(reportId)
|
ctx, cancel := global.TimeoutContext()
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
isLatest, err := g.isTheLatestReport(&ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !isLatest {
|
if !isLatest {
|
||||||
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
||||||
}
|
}
|
||||||
tx := global.DBConn.NewSession()
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
if err := tx.Begin(); err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
|
|
||||||
result, err := g.resynchronizeEndUserArchives(tx, reportId)
|
result, err := g.resynchronizeEndUserArchives(&tx, &ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -425,25 +468,27 @@ func (g _GodModeService) ResynchronizeEndUser(reportId string) (bool, error) {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
cache.AbolishRelation("end_user_detail")
|
cache.AbolishRelation("end_user_detail")
|
||||||
cache.AbolishRelation(fmt.Sprintf("report_%s", reportId))
|
cache.AbolishRelation(fmt.Sprintf("report:%s", reportId))
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) ResetEndUserRegisterRecords(reportId string) (bool, error) {
|
func (g _GodModeService) ResetEndUserRegisterRecords(reportId string) (bool, error) {
|
||||||
isLatest, err := g.isTheLatestReport(reportId)
|
ctx, cancel := global.TimeoutContext()
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
isLatest, err := g.isTheLatestReport(&ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !isLatest {
|
if !isLatest {
|
||||||
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
||||||
}
|
}
|
||||||
tx := global.DBConn.NewSession()
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
if err := tx.Begin(); err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
|
|
||||||
result, err := g.resetEndUserRecords(tx, reportId)
|
result, err := g.resetEndUserRecords(&tx, &ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -454,40 +499,42 @@ func (g _GodModeService) ResetEndUserRegisterRecords(reportId string) (bool, err
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
cache.AbolishRelation("end_user_detail")
|
cache.AbolishRelation("end_user_detail")
|
||||||
cache.AbolishRelation(fmt.Sprintf("report_%s", reportId))
|
cache.AbolishRelation(fmt.Sprintf("report:%s", reportId))
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) ResetReport(reportId string) (bool, error) {
|
func (g _GodModeService) ResetReport(reportId string) (bool, error) {
|
||||||
isLatest, err := g.isTheLatestReport(reportId)
|
ctx, cancel := global.TimeoutContext()
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
isLatest, err := g.isTheLatestReport(&ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !isLatest {
|
if !isLatest {
|
||||||
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
||||||
}
|
}
|
||||||
tx := global.DBConn.NewSession()
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
if err := tx.Begin(); err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
var result = true
|
var result = true
|
||||||
r, err := g.resetEndUserRecords(tx, reportId)
|
r, err := g.resetEndUserRecords(&tx, &ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
result = result && r
|
result = result && r
|
||||||
r, err = g.flushReportMaintenances(tx, reportId)
|
r, err = g.flushReportMaintenances(&tx, &ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
result = result && r
|
result = result && r
|
||||||
r, err = g.resetReportSummary(tx, reportId)
|
r, err = g.resetReportSummary(&tx, &ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
result = result && r
|
result = result && r
|
||||||
r, err = g.resetReportIndex(tx, reportId)
|
r, err = g.resetReportIndex(&tx, &ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -499,25 +546,27 @@ func (g _GodModeService) ResetReport(reportId string) (bool, error) {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
cache.AbolishRelation("end_user_detail")
|
cache.AbolishRelation("end_user_detail")
|
||||||
cache.AbolishRelation(fmt.Sprintf("report_%s", reportId))
|
cache.AbolishRelation(fmt.Sprintf("report:%s", reportId))
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) DeleteReport(reportId string) (bool, error) {
|
func (g _GodModeService) DeleteReport(reportId string) (bool, error) {
|
||||||
isLatest, err := g.isTheLatestReport(reportId)
|
ctx, cancel := global.TimeoutContext()
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
isLatest, err := g.isTheLatestReport(&ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !isLatest {
|
if !isLatest {
|
||||||
return false, exceptions.NewImproperOperateError("不能删除非最新期数的报表。")
|
return false, exceptions.NewImproperOperateError("不能删除非最新期数的报表。")
|
||||||
}
|
}
|
||||||
tx := global.DBConn.NewSession()
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
if err := tx.Begin(); err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
|
|
||||||
result, err := g.forceDeleteReport(tx, reportId)
|
result, err := g.forceDeleteReport(&tx, &ctx, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -528,15 +577,19 @@ func (g _GodModeService) DeleteReport(reportId string) (bool, error) {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
cache.AbolishRelation("end_user_detail")
|
cache.AbolishRelation("end_user_detail")
|
||||||
cache.AbolishRelation(fmt.Sprintf("report_%s", reportId))
|
cache.AbolishRelation(fmt.Sprintf("report:%s", reportId))
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从此处开始为删除园区相关的内容部分
|
// 从此处开始为删除园区相关的内容部分
|
||||||
|
|
||||||
func (_GodModeService) deleteSpecificMaintenance(tx *xorm.Session, parkId, maintenanceId string) (bool, error) {
|
func (_GodModeService) deleteSpecificMaintenance(tx *bun.Tx, ctx *context.Context, parkId, maintenanceId string) (bool, error) {
|
||||||
res, err := tx.Exec("delete from maintenance_fee where park_id=? and id=?", parkId, maintenanceId)
|
res, err := tx.NewDelete().Model((*model.MaintenanceFee)(nil)).
|
||||||
|
Where("park_id = ?", parkId).
|
||||||
|
Where("id = ?", maintenanceId).
|
||||||
|
Exec(*ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@ -549,8 +602,10 @@ func (_GodModeService) deleteSpecificMaintenance(tx *xorm.Session, parkId, maint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_GodModeService) deleteAllMaintenance(tx *xorm.Session, parkId string) (bool, error) {
|
func (_GodModeService) deleteAllMaintenance(tx *bun.Tx, ctx *context.Context, parkId string) (bool, error) {
|
||||||
res, err := tx.Exec("delete from maintenance_fee where park_id=?", parkId)
|
res, err := tx.NewDelete().Model((*model.MaintenanceFee)(nil)).
|
||||||
|
Where("park_id = ?", parkId).
|
||||||
|
Exec(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@ -563,8 +618,10 @@ func (_GodModeService) deleteAllMaintenance(tx *xorm.Session, parkId string) (bo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_GodModeService) deleteAllMeters(tx *xorm.Session, parkId string) (bool, error) {
|
func (_GodModeService) deleteAllMeters(tx *bun.Tx, ctx *context.Context, parkId string) (bool, error) {
|
||||||
res, err := tx.Exec("delete from meter_04kv where park_id=?", parkId)
|
res, err := tx.NewDelete().Model((*model.Meter04KV)(nil)).
|
||||||
|
Where("park_id = ?", parkId).
|
||||||
|
Exec(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@ -577,8 +634,10 @@ func (_GodModeService) deleteAllMeters(tx *xorm.Session, parkId string) (bool, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_GodModeService) deletePark(tx *xorm.Session, parkId string) (bool, error) {
|
func (_GodModeService) deletePark(tx *bun.Tx, ctx *context.Context, parkId string) (bool, error) {
|
||||||
res, err := tx.Exec("delete from park where id=?", parkId)
|
res, err := tx.NewDelete().Model((*model.Park)(nil)).
|
||||||
|
Where("id = ?", parkId).
|
||||||
|
Exec(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@ -592,13 +651,15 @@ func (_GodModeService) deletePark(tx *xorm.Session, parkId string) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) RemoveSpecificMaintenance(parkId, maintenanceId string) (bool, error) {
|
func (g _GodModeService) RemoveSpecificMaintenance(parkId, maintenanceId string) (bool, error) {
|
||||||
tx := global.DBConn.NewSession()
|
ctx, cancel := global.TimeoutContext()
|
||||||
if err := tx.Begin(); err != nil {
|
defer cancel()
|
||||||
|
|
||||||
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
|
|
||||||
result, err := g.deleteSpecificMaintenance(tx, parkId, maintenanceId)
|
result, err := g.deleteSpecificMaintenance(&tx, &ctx, parkId, maintenanceId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -608,19 +669,20 @@ func (g _GodModeService) RemoveSpecificMaintenance(parkId, maintenanceId string)
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
cache.AbolishRelation("maintenance_fee")
|
cache.AbolishRelation(fmt.Sprintf("maintenance_fee:%s", maintenanceId))
|
||||||
cache.AbolishRelation(fmt.Sprintf("maintenance_fee_%s", maintenanceId))
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) RemoveAllMaintenance(parkId string) (bool, error) {
|
func (g _GodModeService) RemoveAllMaintenance(parkId string) (bool, error) {
|
||||||
tx := global.DBConn.NewSession()
|
ctx, cancel := global.TimeoutContext()
|
||||||
if err := tx.Begin(); err != nil {
|
defer cancel()
|
||||||
|
|
||||||
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
|
|
||||||
result, err := g.deleteAllMaintenance(tx, parkId)
|
result, err := g.deleteAllMaintenance(&tx, &ctx, parkId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -635,13 +697,15 @@ func (g _GodModeService) RemoveAllMaintenance(parkId string) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) RemoveAllMeters(parkId string) (bool, error) {
|
func (g _GodModeService) RemoveAllMeters(parkId string) (bool, error) {
|
||||||
tx := global.DBConn.NewSession()
|
ctx, cancel := global.TimeoutContext()
|
||||||
if err := tx.Begin(); err != nil {
|
defer cancel()
|
||||||
|
|
||||||
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
|
|
||||||
result, err := g.deleteAllMeters(tx, parkId)
|
result, err := g.deleteAllMeters(&tx, &ctx, parkId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -655,37 +719,35 @@ func (g _GodModeService) RemoveAllMeters(parkId string) (bool, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) erasePark(tx *xorm.Session, parkId string) (bool, error) {
|
func (g _GodModeService) erasePark(tx *bun.Tx, ctx *context.Context, parkId string) (bool, error) {
|
||||||
var reportIds = make([]string, 0)
|
var reportIds = make([]string, 0)
|
||||||
err := tx.
|
err := tx.NewSelect().Model((*model.Report)(nil)).
|
||||||
Table(new(model.Report)).
|
Where("park_id = ?", parkId).
|
||||||
Where(builder.Eq{"park_id": parkId}).
|
Column("id").
|
||||||
NoAutoCondition().
|
Scan(*ctx, &reportIds)
|
||||||
Select("id").
|
|
||||||
Find(&reportIds)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
var result = true
|
var result = true
|
||||||
for _, id := range reportIds {
|
for _, id := range reportIds {
|
||||||
r, err := g.forceDeleteReport(tx, id)
|
r, err := g.forceDeleteReport(tx, ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
result = result && r
|
result = result && r
|
||||||
}
|
}
|
||||||
r, err := g.deleteAllMaintenance(tx, parkId)
|
r, err := g.deleteAllMaintenance(tx, ctx, parkId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
result = result && r
|
result = result && r
|
||||||
r, err = g.deleteAllMeters(tx, parkId)
|
r, err = g.deleteAllMeters(tx, ctx, parkId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
result = result && r
|
result = result && r
|
||||||
r, err = g.deletePark(tx, parkId)
|
r, err = g.deletePark(tx, ctx, parkId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -695,13 +757,15 @@ func (g _GodModeService) erasePark(tx *xorm.Session, parkId string) (bool, error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) RemovePark(parkId string) (bool, error) {
|
func (g _GodModeService) RemovePark(parkId string) (bool, error) {
|
||||||
tx := global.DBConn.NewSession()
|
ctx, cancel := global.TimeoutContext()
|
||||||
if err := tx.Begin(); err != nil {
|
defer cancel()
|
||||||
|
|
||||||
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
|
|
||||||
result, err := g.erasePark(tx, parkId)
|
result, err := g.erasePark(&tx, &ctx, parkId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -711,28 +775,27 @@ func (g _GodModeService) RemovePark(parkId string) (bool, error) {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
cache.AbolishRelation("park")
|
cache.AbolishRelation(fmt.Sprintf("park:%s", parkId))
|
||||||
cache.AbolishRelation(fmt.Sprintf("park_%s", parkId))
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从此处开始为删除用户相关的部分
|
// 从此处开始为删除用户相关的部分
|
||||||
|
|
||||||
func (g _GodModeService) DeleteUser(userId string) (bool, error) {
|
func (g _GodModeService) DeleteUser(userId string) (bool, error) {
|
||||||
tx := global.DBConn.NewSession()
|
ctx, cancel := global.TimeoutContext()
|
||||||
if err := tx.Begin(); err != nil {
|
defer cancel()
|
||||||
|
|
||||||
|
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
|
||||||
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
|
|
||||||
var parkIds = make([]string, 0)
|
var parkIds = make([]string, 0)
|
||||||
err := tx.
|
err = tx.NewSelect().Model((*model.Park)(nil)).
|
||||||
Table(new(model.Park)).
|
Where("user_id = ?", userId).
|
||||||
Where(builder.Eq{"user_id": userId}).
|
WhereAllWithDeleted().
|
||||||
NoAutoCondition().
|
Column("id").
|
||||||
Unscoped().
|
Scan(ctx, &parkIds)
|
||||||
Select("id").
|
|
||||||
Find(&parkIds)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -740,7 +803,7 @@ func (g _GodModeService) DeleteUser(userId string) (bool, error) {
|
||||||
|
|
||||||
var result = true
|
var result = true
|
||||||
for _, p := range parkIds {
|
for _, p := range parkIds {
|
||||||
r, err := g.erasePark(tx, p)
|
r, err := g.erasePark(&tx, &ctx, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -748,7 +811,9 @@ func (g _GodModeService) DeleteUser(userId string) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除用户服务计费数据。
|
// 删除用户服务计费数据。
|
||||||
res, err := tx.Exec("delete from user_charge where user_id=?", userId)
|
res, err := tx.NewDelete().Model((*model.UserCharge)(nil)).
|
||||||
|
Where("user_id = ?", userId).
|
||||||
|
Exec(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -760,7 +825,9 @@ func (g _GodModeService) DeleteUser(userId string) (bool, error) {
|
||||||
result = result && (rows >= 0)
|
result = result && (rows >= 0)
|
||||||
}
|
}
|
||||||
// 删除用户详细信息数据
|
// 删除用户详细信息数据
|
||||||
res, err = tx.Exec("delete from user_detail where id=?", userId)
|
res, err = tx.NewDelete().Model((*model.UserDetail)(nil)).
|
||||||
|
Where("user_id = ?", userId).
|
||||||
|
Exec(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -772,7 +839,9 @@ func (g _GodModeService) DeleteUser(userId string) (bool, error) {
|
||||||
result = result && (rows >= 0)
|
result = result && (rows >= 0)
|
||||||
}
|
}
|
||||||
// 删除用户基本索引数据
|
// 删除用户基本索引数据
|
||||||
res, err = tx.Exec("delete from `user` where id=?", userId)
|
res, err = tx.NewDelete().Model((*model.User)(nil)).
|
||||||
|
Where("id = ?", userId).
|
||||||
|
Exec(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -789,7 +858,7 @@ func (g _GodModeService) DeleteUser(userId string) (bool, error) {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
cache.AbolishRelation(fmt.Sprintf("user_%s", userId))
|
cache.AbolishRelation(fmt.Sprintf("user:%s", userId))
|
||||||
cache.AbolishRelation("user")
|
cache.AbolishRelation("user")
|
||||||
cache.AbolishRelation("park")
|
cache.AbolishRelation("park")
|
||||||
cache.AbolishRelation("report")
|
cache.AbolishRelation("report")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user