forked from free-lancers/electricity_bill_calc_service
修改分页检索核算报表一些细节,完成审核撤回报表功能
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"electricity_bill_calc/logger"
|
||||
"electricity_bill_calc/repository"
|
||||
"electricity_bill_calc/response"
|
||||
"electricity_bill_calc/security"
|
||||
"electricity_bill_calc/vo"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
@@ -12,10 +14,11 @@ import (
|
||||
var withdrawLog = logger.Named("Handler", "Withdraw")
|
||||
|
||||
func InitializeWithdrawHandlers(router *fiber.App) {
|
||||
router.Get("/withdraw", withdraw)
|
||||
router.Get("/withdraw", security.OPSAuthorize, withdraw)
|
||||
router.Put("/withdraw/:rid", ReviewRequestWithdraw)
|
||||
}
|
||||
|
||||
//用于检索用户的核算报表
|
||||
//用于分页检索用户的核算报表
|
||||
func withdraw(c *fiber.Ctx) error {
|
||||
//记录日志
|
||||
withdrawLog.Info("带分页的待审核的核算撤回申请列表")
|
||||
@@ -27,14 +30,55 @@ func withdraw(c *fiber.Ctx) error {
|
||||
//中间数据库操作暂且省略。。。。
|
||||
//首先进行核算报表的分页查询
|
||||
withdraws, total, err := repository.WithdrawRepository.FindWithdraw(uint(page), &keyword)
|
||||
if err != nil {
|
||||
withdrawLog.Error("检索用户核算报表失败。", zap.Error(err))
|
||||
return result.Error(http.StatusInternalServerError, err.Error())
|
||||
if err != nil {
|
||||
withdrawLog.Error("检索用户核算报表失败。", zap.Error(err))
|
||||
return result.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
//TODO: 2023-07-18 此处返回值是个示例,具体返回值需要查询数据库
|
||||
//TODO: 2023-07-18 此处返回值是个示例,具体返回值需要查询数据库(完成)
|
||||
return result.Success(
|
||||
"withdraw请求成功",
|
||||
response.NewPagedResponse(page, total).ToMap(),
|
||||
fiber.Map{"records": withdraws},
|
||||
)
|
||||
}
|
||||
|
||||
//用于审核撤回报表
|
||||
func ReviewRequestWithdraw(c *fiber.Ctx) error {
|
||||
Rid := c.Params("rid", "")
|
||||
Data := new(vo.ReviewWithdraw)
|
||||
result := response.NewResult(c)
|
||||
|
||||
if err := c.BodyParser(&Data); err != nil {
|
||||
withdrawLog.Error("无法解析审核指定报表的请求数据", zap.Error(err))
|
||||
return result.BadRequest("无法解析审核指定报表的请求数据。")
|
||||
}
|
||||
|
||||
if Data.Audit == true { //审核通过
|
||||
ok, err := repository.WithdrawRepository.ReviewTrueReportWithdraw(Rid)
|
||||
if err != nil {
|
||||
withdrawLog.Error("审核同意撤回报表失败")
|
||||
return result.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
if !ok {
|
||||
withdrawLog.Error("审核同意撤回报表失败")
|
||||
return result.NotAccept("审核同意撤回报表失败")
|
||||
} else {
|
||||
return result.Success("审核同意撤回报表成功!")
|
||||
}
|
||||
} else { //审核不通过
|
||||
ok, err := repository.WithdrawRepository.ReviewFalseReportWithdraw(Rid)
|
||||
if err != nil {
|
||||
withdrawLog.Error("审核拒绝撤回报表失败")
|
||||
return result.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
if !ok {
|
||||
withdrawLog.Error("审核拒绝撤回报表失败")
|
||||
return result.NotAccept("审核拒绝撤回报表失败")
|
||||
} else {
|
||||
return result.Success("审核拒绝撤回报表成功!")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user