feat(report):完成计算园区概况部分的功能。

This commit is contained in:
徐涛
2022-08-21 16:12:50 +08:00
parent 957eb445b5
commit b198bfc423
2 changed files with 64 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package service
import (
"electricity_bill_calc/exceptions"
"electricity_bill_calc/global"
"electricity_bill_calc/model"
"electricity_bill_calc/tools"
@@ -160,3 +161,45 @@ 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
}
func (_ReportService) CalculateSummaryAndFinishStep(reportId string) error {
var report = new(model.Report)
has, err := global.DBConn.ID(reportId).NoAutoCondition().Get(report)
if err != nil {
return err
}
if !has {
return exceptions.NewNotFoundError("未找到指定报表")
}
var summary = new(model.ReportSummary)
has, err = global.DBConn.ID(reportId).NoAutoCondition().Get(summary)
if err != nil {
return err
}
if !has {
return exceptions.NewNotFoundError("未找到指定报表的园区概况")
}
tx := global.DBConn.NewSession()
if err = tx.Begin(); err != nil {
return err
}
defer tx.Close()
summary.CalculatePrices()
_, err = tx.ID(summary.ReportId).Cols("overall_price", "critical_price", "peak_price", "flat", "flat_fee", "flat_price", "valley_price").Update(summary)
if err != nil {
tx.Rollback()
return err
}
report.StepState.Summary = true
_, err = tx.ID(report.Id).Cols("step_state").Update(report)
if err != nil {
tx.Rollback()
return err
}
err = tx.Commit()
if err != nil {
tx.Rollback()
return err
}
return nil
}