feat(charge):增加计费记录查询功能,待测。

This commit is contained in:
徐涛
2022-08-15 11:17:21 +08:00
parent 9b2f869220
commit a48e63d798
6 changed files with 117 additions and 0 deletions

48
controller/charge.go Normal file
View File

@@ -0,0 +1,48 @@
package controller
import (
"electricity_bill_calc/repository"
"electricity_bill_calc/response"
"electricity_bill_calc/security"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
)
type _ChargesController struct {
Router *gin.Engine
}
var ChargesController *_ChargesController
func InitializeChargesController(router *gin.Engine) {
ChargesController = &_ChargesController{
Router: router,
}
ChargesController.Router.GET("/charges", security.OPSAuthorize, listAllCharges)
}
func listAllCharges(c *gin.Context) {
result := response.NewResult(c)
requestPage, err := strconv.Atoi(c.DefaultQuery("page", "1"))
if err != nil {
result.NotAccept("查询参数[page]格式不正确。")
return
}
requestKeyword := c.DefaultQuery("keyword", "")
requestBeginDate := c.DefaultQuery("begin", "")
requestEndDate := c.DefaultQuery("end", "")
charges, total, err := repository.ChargeRepo.ListPagedChargeRecord(requestKeyword, requestBeginDate, requestEndDate, requestPage)
if err != nil {
result.NotFound(err.Error())
return
}
result.Json(
http.StatusOK, "已获取到符合条件的计费记录。",
response.NewPagedResponse(requestPage, total).ToMap(),
gin.H{"records": charges},
)
}