feat(report):完成报表中户表列表功能。
This commit is contained in:
parent
7f95192c78
commit
ddfe88071a
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},
|
||||||
|
)
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ func Router() *gin.Engine {
|
||||||
controller.InitializeMaintenanceFeeController(router)
|
controller.InitializeMaintenanceFeeController(router)
|
||||||
controller.InitializeMeter04kVController(router)
|
controller.InitializeMeter04kVController(router)
|
||||||
controller.InitializeReportController(router)
|
controller.InitializeReportController(router)
|
||||||
|
controller.InitializeEndUserController(router)
|
||||||
controller.InitializeWithdrawController(router)
|
controller.InitializeWithdrawController(router)
|
||||||
|
|
||||||
return router
|
return router
|
||||||
|
|
40
service/end_user.go
Normal file
40
service/end_user.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"electricity_bill_calc/config"
|
||||||
|
"electricity_bill_calc/global"
|
||||||
|
"electricity_bill_calc/model"
|
||||||
|
|
||||||
|
"xorm.io/builder"
|
||||||
|
)
|
||||||
|
|
||||||
|
type _EndUserService struct{}
|
||||||
|
|
||||||
|
var EndUserService _EndUserService
|
||||||
|
|
||||||
|
func (_EndUserService) SearchEndUserRecord(reportId, keyword string, page int) ([]model.EndUserDetail, int64, error) {
|
||||||
|
cond := builder.NewCond().And(builder.Eq{"report_id": reportId})
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
cond = cond.And(
|
||||||
|
builder.Like{"customer_name", keyword}.
|
||||||
|
Or(builder.Like{"contact_name", keyword}).
|
||||||
|
Or(builder.Like{"contact_phone", keyword}).
|
||||||
|
Or(builder.Like{"meter_04kv_id", keyword}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
total, err := global.DBConn.
|
||||||
|
Table(&model.EndUserDetail{}).
|
||||||
|
Where(cond).
|
||||||
|
Count()
|
||||||
|
if err != nil {
|
||||||
|
return make([]model.EndUserDetail, 0), -1, err
|
||||||
|
}
|
||||||
|
startItem := (page - 1) * config.ServiceSettings.ItemsPageSize
|
||||||
|
endUsers := make([]model.EndUserDetail, 0)
|
||||||
|
err = global.DBConn.
|
||||||
|
Where(cond).
|
||||||
|
Limit(config.ServiceSettings.ItemsPageSize, startItem).
|
||||||
|
Asc("seq").
|
||||||
|
Find(&endUsers)
|
||||||
|
return endUsers, total, err
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user