forked from free-lancers/electricity_bill_calc_service
feat(report):完成计算园区概况部分的功能。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/exceptions"
|
||||
"electricity_bill_calc/response"
|
||||
"electricity_bill_calc/security"
|
||||
"electricity_bill_calc/service"
|
||||
@@ -21,6 +22,7 @@ func InitializeReportController(router *gin.Engine) {
|
||||
router.GET("/report/:rid/summary", security.EnterpriseAuthorize, fetchReportParkSummary)
|
||||
router.PUT("/report/:rid/summary", security.EnterpriseAuthorize, fillReportSummary)
|
||||
router.GET("/report/:rid/summary/calculate", security.EnterpriseAuthorize, testCalculateReportSummary)
|
||||
router.POST("/report/:rid/summary/calculate", security.EnterpriseAuthorize, progressReportSummary)
|
||||
}
|
||||
|
||||
func ensureReportBelongs(c *gin.Context, result *response.Result, requestReportId string) bool {
|
||||
@@ -170,5 +172,23 @@ func testCalculateReportSummary(c *gin.Context) {
|
||||
}
|
||||
summary.CalculatePrices()
|
||||
calcResults := tools.ConvertStructToMap(summary)
|
||||
result.Json(http.StatusOK, "已完成园区概览的试计算。", gin.H{"result": lo.PickByKeys(calcResults, []string{"overallPrice", "criticalPrice", "peakPrice", "flat", "flatFee", "flatPrice", "valleyPrice"})})
|
||||
result.Json(http.StatusOK, "已完成园区概况的试计算。", gin.H{"result": lo.PickByKeys(calcResults, []string{"overallPrice", "criticalPrice", "peakPrice", "flat", "flatFee", "flatPrice", "valleyPrice"})})
|
||||
}
|
||||
|
||||
func progressReportSummary(c *gin.Context) {
|
||||
result := response.NewResult(c)
|
||||
requestReportId := c.Param("rid")
|
||||
if !ensureReportBelongs(c, result, requestReportId) {
|
||||
return
|
||||
}
|
||||
err := service.ReportService.CalculateSummaryAndFinishStep(requestReportId)
|
||||
if err != nil {
|
||||
if nfErr, ok := err.(exceptions.NotFoundError); ok {
|
||||
result.NotFound(nfErr.Error())
|
||||
} else {
|
||||
result.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
result.Success("已经完成园区概况的计算,并可以进行到下一步骤。")
|
||||
}
|
||||
|
Reference in New Issue
Block a user