enhance(report):创建新的报表时可以返回新创建的报表ID。
This commit is contained in:
parent
b6b69896cb
commit
96c8699d7f
|
@ -95,12 +95,12 @@ func initializeNewReport(c *gin.Context) {
|
||||||
result.NotAccept("只能初始化已发布报表下一个月份的新报表。")
|
result.NotAccept("只能初始化已发布报表下一个月份的新报表。")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = service.ReportService.InitializeNewReport(requestParkId, reportPeriod)
|
newId, err := service.ReportService.InitializeNewReport(requestParkId, reportPeriod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Error(http.StatusInternalServerError, err.Error())
|
result.Error(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
result.Created("新一期报表初始化成功。")
|
result.Created("新一期报表初始化成功。", gin.H{"reportId": newId})
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchReportStepStates(c *gin.Context) {
|
func fetchReportStepStates(c *gin.Context) {
|
||||||
|
|
|
@ -108,15 +108,15 @@ func (_ReportService) IsNewPeriodValid(uid string, period time.Time) (bool, erro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ReportService) InitializeNewReport(parkId string, period time.Time) (err error) {
|
func (_ReportService) InitializeNewReport(parkId string, period time.Time) (string, error) {
|
||||||
periods := make([]model.Report, 0)
|
periods := make([]model.Report, 0)
|
||||||
err = global.DBConn.
|
err := global.DBConn.
|
||||||
Table("report").
|
Table("report").
|
||||||
Where(builder.Eq{"park_id": parkId, "published": true}).
|
Where(builder.Eq{"park_id": parkId, "published": true}).
|
||||||
Asc("period").
|
Asc("period").
|
||||||
Find(&periods)
|
Find(&periods)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
// 获取上一期的报表索引信息
|
// 获取上一期的报表索引信息
|
||||||
maxPublishedReport := lo.Reduce(
|
maxPublishedReport := lo.Reduce(
|
||||||
|
@ -135,7 +135,7 @@ func (_ReportService) InitializeNewReport(parkId string, period time.Time) (err
|
||||||
lastPeriodCustomers := make([]model.EndUserDetail, 0)
|
lastPeriodCustomers := make([]model.EndUserDetail, 0)
|
||||||
err = global.DBConn.Where(builder.Eq{"report_id": maxPublishedReport.Id}).Find(&lastPeriodCustomers)
|
err = global.DBConn.Where(builder.Eq{"report_id": maxPublishedReport.Id}).Find(&lastPeriodCustomers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
indexedLastPeriodCustomers = lo.Reduce(
|
indexedLastPeriodCustomers = lo.Reduce(
|
||||||
lastPeriodCustomers,
|
lastPeriodCustomers,
|
||||||
|
@ -151,12 +151,12 @@ func (_ReportService) InitializeNewReport(parkId string, period time.Time) (err
|
||||||
currentActivatedCustomers := make([]model.Meter04KV, 0)
|
currentActivatedCustomers := make([]model.Meter04KV, 0)
|
||||||
err = global.DBConn.Where(builder.Eq{"park_id": parkId, "enabled": true}).Find(¤tActivatedCustomers)
|
err = global.DBConn.Where(builder.Eq{"park_id": parkId, "enabled": true}).Find(¤tActivatedCustomers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
// 生成新一期的报表
|
// 生成新一期的报表
|
||||||
tx := global.DBConn.NewSession()
|
tx := global.DBConn.NewSession()
|
||||||
if err = tx.Begin(); err != nil {
|
if err = tx.Begin(); err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
defer tx.Close()
|
||||||
// 插入已经生成的报表索引信息和园区概况信息
|
// 插入已经生成的报表索引信息和园区概况信息
|
||||||
|
@ -174,7 +174,7 @@ func (_ReportService) InitializeNewReport(parkId string, period time.Time) (err
|
||||||
_, err = tx.Insert(newReport, newReportSummary)
|
_, err = tx.Insert(newReport, newReportSummary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
// 生成并插入户表信息
|
// 生成并插入户表信息
|
||||||
for _, customer := range currentActivatedCustomers {
|
for _, customer := range currentActivatedCustomers {
|
||||||
|
@ -206,15 +206,15 @@ func (_ReportService) InitializeNewReport(parkId string, period time.Time) (err
|
||||||
_, err = tx.Insert(newEndUser)
|
_, err = tx.Insert(newEndUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
return nil
|
return newReport.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ReportService) RetreiveReportIndex(rid string) (*model.Report, error) {
|
func (_ReportService) RetreiveReportIndex(rid string) (*model.Report, error) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user