From 9860e0177215304bac20b5e9ccab263c08145220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Sat, 20 Aug 2022 17:12:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(report):=E4=BF=AE=E5=A4=8D=E5=9B=A0?= =?UTF-8?q?=E4=B8=BA=E6=B2=A1=E6=9C=89=E6=89=BE=E5=88=B0=E5=9B=AD=E5=8C=BA?= =?UTF-8?q?=E6=A6=82=E8=A7=88=E8=80=8C=E5=87=BA=E7=8E=B0=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/report.go | 8 ++++++++ service/report.go | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/controller/report.go b/controller/report.go index 156382e..921bbd7 100644 --- a/controller/report.go +++ b/controller/report.go @@ -28,6 +28,10 @@ func ensureReportBelongs(c *gin.Context, result *response.Result, requestReportI result.NotFound(err.Error()) return false } + if requestReport == nil { + result.NotFound("指定报表未能找到。") + return false + } return ensureParkBelongs(c, result, requestReport.ParkId) } @@ -105,5 +109,9 @@ func fetchReportParkSummary(c *gin.Context) { result.NotFound(err.Error()) return } + if summary == nil { + result.NotFound("指定报表未能找到。") + return + } result.Json(http.StatusOK, "已经获取到指定报表中的园区概况。", gin.H{"summary": summary}) } diff --git a/service/report.go b/service/report.go index efcfbfc..4a133f9 100644 --- a/service/report.go +++ b/service/report.go @@ -137,10 +137,13 @@ func (_ReportService) InitializeNewReport(parkId string, period time.Time) (err func (_ReportService) RetreiveReportIndex(rid string) (*model.Report, error) { reports := make([]model.Report, 0) err := global.DBConn.Where(builder.Eq{"id": rid}).Find(&reports) + if err != nil { + return nil, err + } if len(reports) > 0 { return &reports[0], nil } else { - return nil, err + return nil, nil } }