完成获取当前系统中待审核的内容数量功能
This commit is contained in:
parent
39e404451e
commit
9ad3415cdb
34
controller/statistics.go
Normal file
34
controller/statistics.go
Normal 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})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,15 +34,15 @@ func App() *fiber.App {
|
||||||
JSONEncoder: json.Marshal, //json编码
|
JSONEncoder: json.Marshal, //json编码
|
||||||
JSONDecoder: json.Unmarshal, //json解码
|
JSONDecoder: json.Unmarshal, //json解码
|
||||||
})
|
})
|
||||||
app.Use(compress.New()) //压缩中间件
|
app.Use(compress.New()) //压缩中间件
|
||||||
app.Use(recover.New(recover.Config{
|
app.Use(recover.New(recover.Config{
|
||||||
EnableStackTrace: true,
|
EnableStackTrace: true,
|
||||||
StackTraceHandler: stackTraceHandler,
|
StackTraceHandler: stackTraceHandler,
|
||||||
})) //恢复中间件
|
})) //恢复中间件
|
||||||
app.Use(logger.NewLogMiddleware(logger.LogMiddlewareConfig{
|
app.Use(logger.NewLogMiddleware(logger.LogMiddlewareConfig{
|
||||||
Logger: logger.Named("App"),
|
Logger: logger.Named("App"),
|
||||||
})) //日志中间件
|
})) //日志中间件
|
||||||
app.Use(security.SessionRecovery) //会话恢复中间件
|
app.Use(security.SessionRecovery) //会话恢复中间件
|
||||||
|
|
||||||
controller.InitializeUserHandlers(app)
|
controller.InitializeUserHandlers(app)
|
||||||
controller.InitializeRegionHandlers(app)
|
controller.InitializeRegionHandlers(app)
|
||||||
|
@ -54,9 +54,9 @@ func App() *fiber.App {
|
||||||
controller.InitializeTopUpHandlers(app)
|
controller.InitializeTopUpHandlers(app)
|
||||||
controller.InitializeReportHandlers(app)
|
controller.InitializeReportHandlers(app)
|
||||||
|
|
||||||
|
controller.InitializeWithdrawHandlers(app) // 公示撤回
|
||||||
controller.InitializeWithdrawHandlers(app)
|
controller.InitializeFoundationHandlers(app) // 基础数据
|
||||||
controller.InitializeFoundationHandlers(app)
|
controller.InitializeStatisticsController(app) // 首页信息
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
39
service/withdraw.go
Normal file
39
service/withdraw.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user