feat(report):完成报表中园区概况的试计算功能。
This commit is contained in:
parent
9e6914c787
commit
957eb445b5
|
@ -4,11 +4,13 @@ import (
|
|||
"electricity_bill_calc/response"
|
||||
"electricity_bill_calc/security"
|
||||
"electricity_bill_calc/service"
|
||||
"electricity_bill_calc/tools"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/samber/lo"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
|
@ -18,6 +20,7 @@ func InitializeReportController(router *gin.Engine) {
|
|||
router.GET("/report/:rid/step/state", security.EnterpriseAuthorize, fetchReportStepStates)
|
||||
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)
|
||||
}
|
||||
|
||||
func ensureReportBelongs(c *gin.Context, result *response.Result, requestReportId string) bool {
|
||||
|
@ -142,7 +145,7 @@ func fillReportSummary(c *gin.Context) {
|
|||
c.BindJSON(formData)
|
||||
originSummary, err := service.ReportService.RetreiveReportSummary(requestReportId)
|
||||
if err != nil {
|
||||
result.Error(http.StatusInternalServerError, err.Error())
|
||||
result.NotFound(err.Error())
|
||||
return
|
||||
}
|
||||
copier.Copy(originSummary, formData)
|
||||
|
@ -153,3 +156,19 @@ func fillReportSummary(c *gin.Context) {
|
|||
}
|
||||
result.Updated("指定电费公示报表中的园区概况基本数据已经完成更新。")
|
||||
}
|
||||
|
||||
func testCalculateReportSummary(c *gin.Context) {
|
||||
result := response.NewResult(c)
|
||||
requestReportId := c.Param("rid")
|
||||
if !ensureReportBelongs(c, result, requestReportId) {
|
||||
return
|
||||
}
|
||||
summary, err := service.ReportService.RetreiveReportSummary(requestReportId)
|
||||
if err != nil {
|
||||
result.NotFound(err.Error())
|
||||
return
|
||||
}
|
||||
summary.CalculatePrices()
|
||||
calcResults := tools.ConvertStructToMap(summary)
|
||||
result.Json(http.StatusOK, "已完成园区概览的试计算。", gin.H{"result": lo.PickByKeys(calcResults, []string{"overallPrice", "criticalPrice", "peakPrice", "flat", "flatFee", "flatPrice", "valleyPrice"})})
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ func (_ReportService) RetreiveReportIndex(rid string) (*model.Report, error) {
|
|||
|
||||
func (_ReportService) RetreiveReportSummary(rid string) (*model.ReportSummary, error) {
|
||||
var summary = new(model.ReportSummary)
|
||||
_, err := global.DBConn.ID(rid).Get(summary)
|
||||
_, err := global.DBConn.ID(rid).NoAutoCondition().Get(summary)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package tools
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/mozillazg/go-pinyin"
|
||||
|
@ -21,3 +22,11 @@ func PinyinAbbr(source string) string {
|
|||
finalAbbr := strings.Join(abbrCollect, "")
|
||||
return finalAbbr
|
||||
}
|
||||
|
||||
// 将给定结构体的内容通过JSON转换为`map[string]interface{}`类型的值
|
||||
func ConvertStructToMap[T any](origin T) map[string]interface{} {
|
||||
incr, _ := json.Marshal(origin)
|
||||
var dest map[string]interface{}
|
||||
json.Unmarshal(incr, &dest)
|
||||
return dest
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user