81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"electricity_bill_calc/model"
|
|
"electricity_bill_calc/response"
|
|
"electricity_bill_calc/security"
|
|
"electricity_bill_calc/service"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func InitializeStatisticsController(router *gin.Engine) {
|
|
router.GET("/audits", security.OPSAuthorize, currentAuditAmount)
|
|
router.GET("/stat/reports", security.MustAuthenticated, statReports)
|
|
}
|
|
|
|
func currentAuditAmount(c *gin.Context) {
|
|
result := response.NewResult(c)
|
|
amount, err := service.WithdrawService.AuditWaits()
|
|
if err != nil {
|
|
result.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
result.Json(http.StatusOK, "已经获取到指定的统计信息。", gin.H{
|
|
"amounts": map[string]int64{
|
|
"withdraw": amount,
|
|
},
|
|
})
|
|
}
|
|
|
|
func statReports(c *gin.Context) {
|
|
result := response.NewResult(c)
|
|
session, err := _retreiveSession(c)
|
|
if err != nil {
|
|
result.Unauthorized(err.Error())
|
|
return
|
|
}
|
|
var (
|
|
enterprises int64 = 0
|
|
parks int64 = 0
|
|
reports []model.ParkPeriodStatistics
|
|
)
|
|
if session.Type != 0 {
|
|
enterprises, err = service.StatisticsService.EnabledEnterprises()
|
|
if err != nil {
|
|
result.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
parks, err = service.StatisticsService.EnabledParks()
|
|
if err != nil {
|
|
result.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
reports, err = service.StatisticsService.ParksNewestState()
|
|
if err != nil {
|
|
result.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
} else {
|
|
parks, err = service.StatisticsService.EnabledParks(session.Uid)
|
|
if err != nil {
|
|
result.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
reports, err = service.StatisticsService.ParksNewestState(session.Uid)
|
|
if err != nil {
|
|
result.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
}
|
|
|
|
result.Json(http.StatusOK, "已经完成园区报告的统计。", gin.H{
|
|
"statistics": gin.H{
|
|
"enterprises": enterprises,
|
|
"parks": parks,
|
|
"reports": reports,
|
|
},
|
|
})
|
|
}
|