enhance(report):在初始化报表的时候,一并初始化园区电量概要。
This commit is contained in:
parent
b2126a534b
commit
738472a5fb
@ -1,7 +1,6 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"electricity_bill_calc/model"
|
|
||||||
"electricity_bill_calc/response"
|
"electricity_bill_calc/response"
|
||||||
"electricity_bill_calc/security"
|
"electricity_bill_calc/security"
|
||||||
"electricity_bill_calc/service"
|
"electricity_bill_calc/service"
|
||||||
@ -64,8 +63,7 @@ func initializeNewReport(c *gin.Context) {
|
|||||||
result.NotAccept("只能初始化已发布报表下一个月份的新报表。")
|
result.NotAccept("只能初始化已发布报表下一个月份的新报表。")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newReport := model.Report{ParkId: requestParkId, Period: reportPeriod}
|
err = service.ReportService.InitializeNewReport(requestParkId, reportPeriod)
|
||||||
err = service.ReportService.InitializeNewReport(newReport)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Error(http.StatusInternalServerError, err.Error())
|
result.Error(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
|
@ -104,13 +104,30 @@ func (_ReportService) IsNewPeriodValid(uid string, period time.Time) (bool, erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ReportService) InitializeNewReport(report model.Report) (err error) {
|
func (_ReportService) InitializeNewReport(parkId string, period time.Time) (err error) {
|
||||||
report.Id = uuid.New().String()
|
newReport := model.Report{
|
||||||
report.StepState = model.NewSteps()
|
Id: uuid.New().String(),
|
||||||
report.Published = false
|
ParkId: parkId,
|
||||||
report.Withdraw = model.REPORT_NOT_WITHDRAW
|
StepState: model.NewSteps(),
|
||||||
_, err = global.DBConn.Insert(report)
|
Published: false,
|
||||||
|
Withdraw: model.REPORT_NOT_WITHDRAW,
|
||||||
|
}
|
||||||
|
newReportSummary := model.ReportSummary{
|
||||||
|
ReportId: newReport.Id,
|
||||||
|
}
|
||||||
|
tx := global.DBConn.NewSession()
|
||||||
|
if err = tx.Begin(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer tx.Close()
|
||||||
|
_, err = tx.Insert(newReport, newReportSummary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = tx.Commit()
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user