forked from free-lancers/electricity_bill_calc_service
feat(withdraw):完成公示撤回及审核相关的功能。
This commit is contained in:
86
controller/withdraw.go
Normal file
86
controller/withdraw.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/exceptions"
|
||||
"electricity_bill_calc/response"
|
||||
"electricity_bill_calc/security"
|
||||
"electricity_bill_calc/service"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitializeWithdrawController(router *gin.Engine) {
|
||||
router.DELETE("/publicity/:pid", security.EnterpriseAuthorize, applyReportWithdraw)
|
||||
router.GET("/withdraws", security.OPSAuthorize, fetchWithdrawsWaitingAutdit)
|
||||
router.PUT("/withdraw/:rid", security.OPSAuthorize, auditWithdraw)
|
||||
}
|
||||
|
||||
func applyReportWithdraw(c *gin.Context) {
|
||||
result := response.NewResult(c)
|
||||
requestReportId := c.Param("pid")
|
||||
if !ensureReportBelongs(c, result, requestReportId) {
|
||||
return
|
||||
}
|
||||
deleted, err := service.WithdrawService.ApplyWithdraw(requestReportId)
|
||||
if err != nil {
|
||||
if nfErr, ok := err.(exceptions.NotFoundError); ok {
|
||||
result.NotFound(nfErr.Error())
|
||||
return
|
||||
} else if ioErr, ok := err.(exceptions.ImproperOperateError); ok {
|
||||
result.NotAccept(ioErr.Error())
|
||||
return
|
||||
} else {
|
||||
result.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
if !deleted {
|
||||
result.Error(http.StatusInternalServerError, "未能完成公示报表的申请撤回操作。")
|
||||
return
|
||||
}
|
||||
result.Success("指定的公示报表已经申请撤回。")
|
||||
}
|
||||
|
||||
func fetchWithdrawsWaitingAutdit(c *gin.Context) {
|
||||
result := response.NewResult(c)
|
||||
keyword := c.DefaultQuery("keyword", "")
|
||||
requestPage, err := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
if err != nil {
|
||||
result.NotAccept("查询参数[page]格式不正确。")
|
||||
return
|
||||
}
|
||||
reports, totalitems, err := service.WithdrawService.FetchPagedWithdrawApplies(requestPage, keyword)
|
||||
if err != nil {
|
||||
result.NotFound(err.Error())
|
||||
return
|
||||
}
|
||||
result.Json(
|
||||
http.StatusOK,
|
||||
"已经取得符合条件的等待审核的撤回申请。",
|
||||
response.NewPagedResponse(requestPage, totalitems).ToMap(),
|
||||
gin.H{"records": reports},
|
||||
)
|
||||
}
|
||||
|
||||
type WithdrawAuditFormData struct {
|
||||
Audit bool `json:"audit" form:"audit"`
|
||||
}
|
||||
|
||||
func auditWithdraw(c *gin.Context) {
|
||||
result := response.NewResult(c)
|
||||
requestReportId := c.Param("rid")
|
||||
formData := new(WithdrawAuditFormData)
|
||||
c.BindJSON(formData)
|
||||
err := service.WithdrawService.AuditWithdraw(requestReportId, formData.Audit)
|
||||
if err != nil {
|
||||
if nfErr, ok := err.(exceptions.NotFoundError); ok {
|
||||
result.NotFound(nfErr.Error())
|
||||
} else {
|
||||
result.NotAccept(err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
result.Success("指定公示报表的撤回申请已经完成审核")
|
||||
}
|
Reference in New Issue
Block a user