完成获取当前系统中待审核的内容数量功能

This commit is contained in:
ZiHangQin 2023-07-26 13:43:30 +08:00
parent 39e404451e
commit 9ad3415cdb
3 changed files with 80 additions and 7 deletions

34
controller/statistics.go Normal file
View File

@ -0,0 +1,34 @@
package controller
import (
"electricity_bill_calc/logger"
"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)
}
//获取当前系统中待审核的内容数量
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})
}

View File

@ -34,15 +34,15 @@ func App() *fiber.App {
JSONEncoder: json.Marshal, //json编码
JSONDecoder: json.Unmarshal, //json解码
})
app.Use(compress.New()) //压缩中间件
app.Use(compress.New()) //压缩中间件
app.Use(recover.New(recover.Config{
EnableStackTrace: true,
StackTraceHandler: stackTraceHandler,
})) //恢复中间件
})) //恢复中间件
app.Use(logger.NewLogMiddleware(logger.LogMiddlewareConfig{
Logger: logger.Named("App"),
})) //日志中间件
app.Use(security.SessionRecovery) //会话恢复中间件
})) //日志中间件
app.Use(security.SessionRecovery) //会话恢复中间件
controller.InitializeUserHandlers(app)
controller.InitializeRegionHandlers(app)
@ -54,9 +54,9 @@ func App() *fiber.App {
controller.InitializeTopUpHandlers(app)
controller.InitializeReportHandlers(app)
controller.InitializeWithdrawHandlers(app)
controller.InitializeFoundationHandlers(app)
controller.InitializeWithdrawHandlers(app) // 公示撤回
controller.InitializeFoundationHandlers(app) // 基础数据
controller.InitializeStatisticsController(app) // 首页信息
return app
}

39
service/withdraw.go Normal file
View File

@ -0,0 +1,39 @@
package service
import (
"electricity_bill_calc/global"
"electricity_bill_calc/logger"
"electricity_bill_calc/model"
"github.com/doug-martin/goqu/v9"
"github.com/georgysavva/scany/v2/pgxscan"
"go.uber.org/zap"
)
type _WithdrawService struct {
log *zap.Logger
ds goqu.DialectWrapper
}
var WithdrawService = _WithdrawService{
logger.Named("Service", "Withdraw"),
goqu.Dialect("postgres"),
}
func (wd _WithdrawService) AuditWaits() (int64, error) {
wd.log.Info("获取当前系统中待审核的内容数量。")
ctx, cancel := global.TimeoutContext()
defer cancel()
CountWithdrawQuery, CountWithdrawQueryArgs, _ := wd.ds.
From(goqu.T("report")).
Where(goqu.I("withdraw").Eq(model.REPORT_WITHDRAW_APPLYING)).
Select(goqu.COUNT("*")).ToSQL()
var total int64
err := pgxscan.Get(ctx, global.DB, &total, CountWithdrawQuery,CountWithdrawQueryArgs...)
if err != nil {
wd.log.Error("获取当前系统中待审核的内容数量出错。")
return 0,err
}
return total,nil
}