修改审核撤回报表请求细节,完成撤回电费核算功能
This commit is contained in:
parent
b3032638fc
commit
251c44049a
|
@ -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, "其他错误")
|
||||
}
|
||||
|
|
|
@ -678,7 +678,7 @@ func (rr _ReportRepository) IsLastReport(rid string) (bool, error) {
|
|||
defer cancel()
|
||||
|
||||
checkSql, checkArgs, _ := rr.ds.
|
||||
From(goqu.T("report")).
|
||||
From(goqu.T("report").As("r")).
|
||||
Select(goqu.COUNT("*")).
|
||||
Where(
|
||||
goqu.I("r.id").Eq(rid),
|
||||
|
|
|
@ -184,7 +184,7 @@ func (wd _WithdrawRepository) ReviewTrueReportWithdraw( rid string) (bool, error
|
|||
updateQuerySql, updateArgs, _ := wd.ds.
|
||||
Update(goqu.T("report")).
|
||||
Set(goqu.Record{
|
||||
"withdraw": 3,
|
||||
"withdraw": model.REPORT_WITHDRAW_GRANTED,
|
||||
"last_withdraw_audit_at": types.Now(),
|
||||
"published": false,
|
||||
"published_at": nil,
|
||||
|
@ -206,6 +206,7 @@ func (wd _WithdrawRepository) ReviewTrueReportWithdraw( rid string) (bool, error
|
|||
return rs.RowsAffected() > 0, nil
|
||||
}
|
||||
|
||||
//该方法用于审核拒绝报表撤回
|
||||
func (wd _WithdrawRepository) ReviewFalseReportWithdraw( rid string) (bool, error) {
|
||||
wd.log.Info("审核指定的报表", zap.String("rid", rid))
|
||||
ctx, cancel := global.TimeoutContext()
|
||||
|
@ -218,7 +219,7 @@ func (wd _WithdrawRepository) ReviewFalseReportWithdraw( rid string) (bool, erro
|
|||
updateQuerySql, updateArgs, _ := wd.ds.
|
||||
Update(goqu.T("report")).
|
||||
Set(goqu.Record{
|
||||
"withdraw": 2,
|
||||
"withdraw": model.REPORT_WITHDRAW_DENIED,
|
||||
"last_withdraw_audit_at": types.Now(),
|
||||
"published": false,
|
||||
"published_at": nil,
|
||||
|
|
Loading…
Reference in New Issue
Block a user