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