From 62a9fec43fb4639535f21686681f8f8b4f26bb4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Wed, 7 Sep 2022 14:04:52 +0800 Subject: [PATCH] =?UTF-8?q?enhance(god):=E6=B8=85=E9=99=A4=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E4=B8=8D=E5=90=8C=E9=83=A8=E5=88=86=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E5=90=8C=E6=97=B6=E9=87=8D=E7=BD=AE=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E8=BF=9B=E5=BA=A6=E7=8A=B6=E6=80=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/report.go | 7 ++++++- service/god_mode.go | 39 ++++++++++++++++++++++++++++++++++++--- service/report.go | 8 ++++++-- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/controller/report.go b/controller/report.go index 5456d12..216c0c8 100644 --- a/controller/report.go +++ b/controller/report.go @@ -436,7 +436,12 @@ func searchReports(c *gin.Context) { result.NotAccept("查询参数[page]格式不正确。") return } - records, totalItems, err := service.ReportService.SearchReport(requestUser, requestPark, requestKeyword, requestPeriod, requestPage) + requestAllReports, err := strconv.ParseBool(c.DefaultQuery("all", "false")) + if err != nil { + result.NotAccept("查询参数[all]格式不正确。") + return + } + records, totalItems, err := service.ReportService.SearchReport(requestUser, requestPark, requestKeyword, requestPeriod, requestPage, !requestAllReports) if err != nil { result.NotFound(err.Error()) return diff --git a/service/god_mode.go b/service/god_mode.go index 9649f90..1171f65 100644 --- a/service/god_mode.go +++ b/service/god_mode.go @@ -67,16 +67,27 @@ func (_GodModeService) resetReportSummary(tx *xorm.Session, reportId string) (bo var summary = &model.ReportSummary{ ReportId: reportId, } - rows, err := tx.ID(reportId).AllCols().NoAutoCondition().Update(summary) + _, err := tx.ID(reportId).AllCols().NoAutoCondition().Update(summary) if err != nil { tx.Rollback() return false, err } + var report = new(model.Report) + _, err = tx.ID(reportId).NoAutoCondition().Unscoped().Get(report) + if err != nil { + tx.Rollback() + return false, err + } + report.StepState.Summary = false + rows, err := tx.ID(reportId).Cols("step_state").NoAutoCondition().Update(report) + if err != nil { + tx.Rollback() + } return rows >= 0, err } func (_GodModeService) flushReportMaintenances(tx *xorm.Session, reportId string) (bool, error) { - rows, err := tx. + _, err := tx. Where(builder.Eq{"report_id": reportId}). NoAutoCondition(). Delete(new(model.WillDilutedFee)) @@ -84,6 +95,17 @@ func (_GodModeService) flushReportMaintenances(tx *xorm.Session, reportId string tx.Rollback() return false, err } + var report = new(model.Report) + _, err = tx.ID(reportId).NoAutoCondition().Unscoped().Get(report) + if err != nil { + tx.Rollback() + return false, err + } + report.StepState.WillDiluted = false + rows, err := tx.ID(reportId).Cols("step_state").NoAutoCondition().Update(report) + if err != nil { + tx.Rollback() + } return rows >= 0, err } @@ -169,7 +191,18 @@ func (_GodModeService) resetEndUserRecords(tx *xorm.Session, reportId string) (b return false, err } } - return true, nil + var report = new(model.Report) + _, err = tx.ID(reportId).NoAutoCondition().Unscoped().Get(report) + if err != nil { + tx.Rollback() + return false, err + } + report.StepState.Submeter = false + rows, err := tx.ID(reportId).Cols("step_state").NoAutoCondition().Update(report) + if err != nil { + tx.Rollback() + } + return rows >= 0, nil } type ReportPeriod struct { diff --git a/service/report.go b/service/report.go index 08726a4..e5603a0 100644 --- a/service/report.go +++ b/service/report.go @@ -430,10 +430,14 @@ func (_ReportService) PublishReport(report model.Report) (err error) { return } -func (_ReportService) SearchReport(requestUser, requestPark, requestKeyword string, requestPeriod *time.Time, requestPage int) ([]model.JoinedReportForWithdraw, int64, error) { +func (_ReportService) SearchReport(requestUser, requestPark, requestKeyword string, requestPeriod *time.Time, requestPage int, onlyPublished bool) ([]model.JoinedReportForWithdraw, int64, error) { var conditions = make([]string, 0) conditions = append(conditions, strconv.Itoa(requestPage)) - cond := builder.NewCond().And(builder.Eq{"r.published": true}) + cond := builder.NewCond() + if onlyPublished { + cond = cond.And(builder.Eq{"r.published": true}) + } + conditions = append(conditions, strconv.FormatBool(onlyPublished)) if len(requestUser) > 0 { cond = cond.And(builder.Eq{"u.id": requestUser}) conditions = append(conditions, requestUser)