feat(report):基本完成园区报表概况的录入,待测。

This commit is contained in:
徐涛 2022-08-21 12:30:57 +08:00
parent 0eb3be025c
commit 6edee68df6
2 changed files with 45 additions and 2 deletions

View File

@ -8,6 +8,8 @@ import (
"time"
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
"github.com/shopspring/decimal"
)
func InitializeReportController(router *gin.Engine) {
@ -15,6 +17,7 @@ func InitializeReportController(router *gin.Engine) {
router.POST("/park/:pid/report", security.EnterpriseAuthorize, initializeNewReport)
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)
}
func ensureReportBelongs(c *gin.Context, result *response.Result, requestReportId string) bool {
@ -104,7 +107,7 @@ func fetchReportParkSummary(c *gin.Context) {
if !ensureReportBelongs(c, result, requestReportId) {
return
}
summary, err := service.ReportService.RetreiveParkSummary(requestReportId)
summary, err := service.ReportService.RetreiveReportSummary(requestReportId)
if err != nil {
result.NotFound(err.Error())
return
@ -115,3 +118,38 @@ func fetchReportParkSummary(c *gin.Context) {
}
result.Json(http.StatusOK, "已经获取到指定报表中的园区概况。", gin.H{"summary": summary})
}
type ReportSummaryFormData struct {
Overall decimal.Decimal `json:"overall" form:"overall"`
OverallFee decimal.Decimal `json:"overallFee" form:"overallFee"`
Critical decimal.Decimal `json:"critical" form:"critical"`
CriticalFee decimal.Decimal `json:"criticalFee" form:"criticalFee"`
Peak decimal.Decimal `json:"peak" form:"peak"`
PeakFee decimal.Decimal `json:"peakFee" form:"peakFee"`
Valley decimal.Decimal `json:"valley" form:"valley"`
ValleyFee decimal.Decimal `json:"valleyFee" form:"valleyFee"`
BasicFee decimal.Decimal `json:"basicFee" form:"basicFee"`
AdjustFee decimal.Decimal `json:"adjustFee" from:"adjustFee"`
}
func fillReportSummary(c *gin.Context) {
result := response.NewResult(c)
requestReportId := c.Param("rid")
if !ensureReportBelongs(c, result, requestReportId) {
return
}
formData := new(ReportSummaryFormData)
c.BindJSON(formData)
originSummary, err := service.ReportService.RetreiveReportSummary(requestReportId)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
copier.Copy(originSummary, formData)
err = service.ReportService.UpdateReportSummary(originSummary)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Updated("指定电费公示报表中的园区概况基本数据已经完成更新。")
}

View File

@ -146,7 +146,7 @@ func (_ReportService) RetreiveReportIndex(rid string) (*model.Report, error) {
}
}
func (_ReportService) RetreiveParkSummary(rid string) (*model.ReportSummary, error) {
func (_ReportService) RetreiveReportSummary(rid string) (*model.ReportSummary, error) {
var summary = new(model.ReportSummary)
_, err := global.DBConn.ID(rid).Get(summary)
if err != nil {
@ -154,3 +154,8 @@ func (_ReportService) RetreiveParkSummary(rid string) (*model.ReportSummary, err
}
return summary, nil
}
func (_ReportService) UpdateReportSummary(summary *model.ReportSummary) error {
_, err := global.DBConn.ID(summary.ReportId).Cols("overall", "overall_fee", "critical", "critical_fee", "peak", "peak_fee", "valley", "valley_fee", "basic_fee", "adjust_fee").Update(summary)
return err
}