package controller import ( "electricity_bill_calc/logger" "electricity_bill_calc/model" "electricity_bill_calc/response" "electricity_bill_calc/security" "electricity_bill_calc/service" "github.com/gofiber/fiber/v2" "go.uber.org/zap" "net/http" ) var StatisticsWithdrawLog = logger.Named("Handler", "StatisticsWithdraw") func InitializeStatisticsController(router *fiber.App) { router.Get("/audits", security.OPSAuthorize, currentAuditAmount) router.Get("/stat/reports", security.OPSAuthorize, statReports) } //获取当前系统中待审核的内容数量 func currentAuditAmount(c *fiber.Ctx) error { StatisticsWithdrawLog.Info("开始获取当前系统中待审核的内容数量") result := response.NewResult(c) amount, err := service.WithdrawService.AuditWaits() if err != nil { StatisticsWithdrawLog.Error("获取当前系统中待审核的内容数量出错", zap.Error(err)) return result.Error(http.StatusInternalServerError, err.Error()) } return result.Success("已经获取到指定的统计信息", fiber.Map{"withdraw": amount}) } func statReports(c *fiber.Ctx) error { result := response.NewResult(c) session, err := _retreiveSession(c) if err != nil { return result.Unauthorized(err.Error()) } var ( enterprises int64 = 0 parks int64 = 0 reports []model.ParkPeriodStatistics ) if session.Type != 0 { enterprises, err = service.StatisticsService.EnabledEnterprises() if err != nil { StatisticsWithdrawLog.Error(err.Error()) return result.Error(http.StatusInternalServerError, err.Error()) } parks, err = service.StatisticsService.EnabledParks() if err != nil { StatisticsWithdrawLog.Error(err.Error()) return result.Error(http.StatusInternalServerError, err.Error()) } //TODO: 2023.07.26 报表数据库结构改变,此处逻辑复杂放在最后处理 reports, err = service.StatisticsService.ParkNewestState() if err != nil { StatisticsWithdrawLog.Error(err.Error()) return result.Error(http.StatusInternalServerError, err.Error()) } } else { parks, err = service.StatisticsService.EnabledParks(session.Uid) if err != nil { StatisticsWithdrawLog.Error(err.Error()) return result.Error(http.StatusInternalServerError, err.Error()) } //TODO: 2023.07.26 报表数据库结构改变,此处逻辑复杂放在最后处理 reports, err = service.StatisticsService.ParkNewestState(session.Uid) if err != nil { StatisticsWithdrawLog.Error(err.Error()) return result.Error(http.StatusInternalServerError, err.Error()) } } return result.Success("已经完成园区报告的统计。", fiber.Map{ "statistics": fiber.Map{ "enterprises": enterprises, "parks": parks, "reports": reports, }, }) }