forked from free-lancers/electricity_bill_calc_service
修改审核撤回报表请求细节,完成撤回电费核算功能
This commit is contained in:
@@ -15,7 +15,8 @@ var withdrawLog = logger.Named("Handler", "Withdraw")
|
||||
|
||||
func InitializeWithdrawHandlers(router *fiber.App) {
|
||||
router.Get("/withdraw", security.OPSAuthorize, withdraw)
|
||||
router.Put("/withdraw/:rid",security.OPSAuthorize, ReviewRequestWithdraw)
|
||||
router.Put("/withdraw/:rid", security.OPSAuthorize, reviewRequestWithdraw)
|
||||
router.Delete("/withdraw/:rid", security.EnterpriseAuthorize, recallReport)
|
||||
}
|
||||
|
||||
//用于分页检索用户的核算报表
|
||||
@@ -43,7 +44,7 @@ func withdraw(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
//用于审核撤回报表
|
||||
func ReviewRequestWithdraw(c *fiber.Ctx) error {
|
||||
func reviewRequestWithdraw(c *fiber.Ctx) error {
|
||||
Rid := c.Params("rid", "")
|
||||
Data := new(vo.ReviewWithdraw)
|
||||
result := response.NewResult(c)
|
||||
@@ -82,3 +83,52 @@ func ReviewRequestWithdraw(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//用于撤回电费核算
|
||||
func recallReport(c *fiber.Ctx) error {
|
||||
// 获取用户会话信息和参数
|
||||
rid := c.Params("rid", "")
|
||||
result := response.NewResult(c)
|
||||
session, err := _retreiveSession(c)
|
||||
if err != nil {
|
||||
withdrawLog.Error("无法获取当前用户的会话。")
|
||||
return result.Unauthorized(err.Error())
|
||||
}
|
||||
// 检查指定报表的所属情况
|
||||
isBelongsTo, err := repository.ReportRepository.IsBelongsTo(rid, session.Uid)
|
||||
if err != nil {
|
||||
withdrawLog.Error("检查报表所属情况出现错误。", zap.Error(err))
|
||||
return result.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
if err == nil && isBelongsTo == true {
|
||||
// 判断指定报表是否是当前园区的最后一张报表
|
||||
isLastReport, err := repository.ReportRepository.IsLastReport(rid)
|
||||
if err != nil {
|
||||
withdrawLog.Error("判断指定报表是否为当前园区的最后一张报表时出错", zap.Error(err))
|
||||
return result.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
if err == nil && isLastReport == true {
|
||||
// 申请撤回指定的核算报表
|
||||
//TODO: 2023.07.25 申请撤回指定核算报表,正确状态未处理(完成)
|
||||
ok, err := repository.ReportRepository.ApplyWithdrawReport(rid)
|
||||
if err != nil {
|
||||
withdrawLog.Error("申请撤回指定核算报表出错", zap.Error(err))
|
||||
return result.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
if ok {
|
||||
withdrawLog.Info("申请撤回指定核算报表成功")
|
||||
return result.Success("申请撤回指定核算报表成功")
|
||||
}
|
||||
} else {
|
||||
withdrawLog.Info("当前报表不是当前园区的最后一张报表")
|
||||
return result.Error(http.StatusForbidden, "当前报表不是当前园区的最后一张报表")
|
||||
}
|
||||
} else {
|
||||
withdrawLog.Info("指定的核算报表不属于当前用户。")
|
||||
return result.Error(http.StatusForbidden, "指定的核算报表不属于当前用户")
|
||||
}
|
||||
|
||||
return result.Error(http.StatusInternalServerError, "其他错误")
|
||||
}
|
||||
|
Reference in New Issue
Block a user