From 77c75bbb837656dcffc4fe9ab9def650134b3882 Mon Sep 17 00:00:00 2001 From: XiMo-210 <2831802697@qq.com> Date: Thu, 10 Aug 2023 21:07:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=B1=E7=89=A9=E6=8B=9B=E9=A2=86=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E8=AE=B0=E5=BD=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lostAndFoundRecordController.go | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/app/controllers/funcControllers/lostAndFoundRecordController/lostAndFoundRecordController.go b/app/controllers/funcControllers/lostAndFoundRecordController/lostAndFoundRecordController.go index 64e5cec..8396a93 100644 --- a/app/controllers/funcControllers/lostAndFoundRecordController/lostAndFoundRecordController.go +++ b/app/controllers/funcControllers/lostAndFoundRecordController/lostAndFoundRecordController.go @@ -24,9 +24,9 @@ import ( ) type GetRecordsData struct { - LostOrFound int `form:"lost_or_found"` - PageNum int `form:"page_num"` - PageSize int `form:"page_size"` + LostOrFound string `form:"lost_or_found"` + PageNum int `form:"page_num"` + PageSize int `form:"page_size"` } func GetRecords(c *gin.Context) { @@ -39,11 +39,21 @@ func GetRecords(c *gin.Context) { return } + var _type int + switch data.LostOrFound { + case "": + _type = 2 + case "失物": + _type = 1 + case "寻物": + _type = 0 + } + var lostAndFoundRecords []models.LostAndFoundRecord - if data.LostOrFound == 2 { + if _type == 2 { lostAndFoundRecords, err = lostAndFoundRecordServices.GetAllLostAndFoundRecord(campus, kind, data.PageNum, data.PageSize) } else { - lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecord(campus, kind, data.LostOrFound, data.PageNum, data.PageSize) + lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecord(campus, kind, _type, data.PageNum, data.PageSize) } if err != nil { _ = c.AbortWithError(200, apiException.ServerError) @@ -51,10 +61,10 @@ func GetRecords(c *gin.Context) { } var totalPageNum *int64 - if data.LostOrFound == 2 { + if _type == 2 { totalPageNum, err = lostAndFoundRecordServices.GetAllLostAndFoundTotalPageNum(campus, kind) } else { - totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNum(campus, kind, data.LostOrFound) + totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNum(campus, kind, _type) } if err != nil { _ = c.AbortWithError(200, apiException.ServerError) @@ -75,27 +85,37 @@ func GetRecordsByAdmin(c *gin.Context) { return } + var _type int + switch data.LostOrFound { + case "": + _type = 2 + case "失物": + _type = 1 + case "寻物": + _type = 0 + } + var lostAndFoundRecords []models.LostAndFoundRecord var totalPageNum *int64 publisher := getPublisher(c) if *publisher == "Admin" { - lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecordBySuperAdmin(data.LostOrFound, data.PageNum, data.PageSize) + lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecordBySuperAdmin(_type, data.PageNum, data.PageSize) if err != nil { _ = c.AbortWithError(200, apiException.ServerError) return } - totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNumBySuperAdmin(data.LostOrFound) + totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNumBySuperAdmin(_type) if err != nil { _ = c.AbortWithError(200, apiException.ServerError) return } } else { - lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecordByAdmin(*publisher, data.LostOrFound, data.PageNum, data.PageSize) + lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecordByAdmin(*publisher, _type, data.PageNum, data.PageSize) if err != nil { _ = c.AbortWithError(200, apiException.ServerError) return } - totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNumByAdmin(*publisher, data.LostOrFound) + totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNumByAdmin(*publisher, _type) if err != nil { _ = c.AbortWithError(200, apiException.ServerError) return