forked from free-lancers/electricity_bill_calc_service
feat(report):完成报表中户表列表功能。
This commit is contained in:
40
controller/end_user.go
Normal file
40
controller/end_user.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/response"
|
||||
"electricity_bill_calc/security"
|
||||
"electricity_bill_calc/service"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitializeEndUserController(router *gin.Engine) {
|
||||
router.GET("/report/:rid/submeter", security.EnterpriseAuthorize, fetchEndUserInReport)
|
||||
}
|
||||
|
||||
func fetchEndUserInReport(c *gin.Context) {
|
||||
result := response.NewResult(c)
|
||||
requestReportId := c.Param("rid")
|
||||
if !ensureReportBelongs(c, result, requestReportId) {
|
||||
return
|
||||
}
|
||||
keyword := c.DefaultQuery("keyword", "")
|
||||
requestPage, err := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
if err != nil {
|
||||
result.NotAccept("查询参数[page]格式不正确。")
|
||||
return
|
||||
}
|
||||
endUsers, totalItem, err := service.EndUserService.SearchEndUserRecord(requestReportId, keyword, requestPage)
|
||||
if err != nil {
|
||||
result.NotFound(err.Error())
|
||||
return
|
||||
}
|
||||
result.Json(
|
||||
http.StatusOK,
|
||||
"已获取到符合条件的终端用户集合",
|
||||
response.NewPagedResponse(requestPage, totalItem).ToMap(),
|
||||
gin.H{"meters": endUsers},
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user