fix(enduser):修正抄表记录的初始化与上传。现在可以正常上传了。

This commit is contained in:
徐涛 2022-09-20 14:50:14 +08:00
parent d7f3e0f096
commit aa3a4dc44e
2 changed files with 7 additions and 3 deletions

View File

@ -175,7 +175,7 @@ func (es _EndUserService) BatchImportNonPVRegister(reportId string, file io.Read
err = global.DB.NewSelect().Model((*model.EndUserDetail)(nil)).
ColumnExpr("meter_04kv_id as meter").
ColumnExpr("count(*) as appears").
Where("park_id = ?", reportDetail.Id).
Where("park_id = ?", reportDetail.ParkId).
Group("meter_04kv_id").
Scan(ctx, &meterAppers)
if err != nil {

View File

@ -138,7 +138,7 @@ func (_ReportService) IsNewPeriodValid(uid, pid string, period time.Time) (bool,
}
func (_ReportService) InitializeNewReport(parkId string, period time.Time) (string, error) {
ctx, cancel := global.TimeoutContext()
ctx, cancel := global.TimeoutContext(120)
defer cancel()
periods := make([]model.Report, 0)
@ -227,6 +227,7 @@ func (_ReportService) InitializeNewReport(parkId string, period time.Time) (stri
return "", err
}
// 生成并插入户表信息
var inserts = make([]model.EndUserDetail, 0)
for _, customer := range currentActivatedCustomers {
newEndUser := model.EndUserDetail{
ReportId: newReport.Id,
@ -253,7 +254,10 @@ func (_ReportService) InitializeNewReport(parkId string, period time.Time) (stri
newEndUser.LastPeriodFlat = lastPeriod.CurrentPeriodFlat
newEndUser.LastPeriodValley = lastPeriod.CurrentPeriodValley
}
_, err = tx.NewInsert().Model(&newEndUser).Exec(ctx)
inserts = append(inserts, newEndUser)
}
if len(inserts) > 0 {
_, err = tx.NewInsert().Model(&inserts).Exec(ctx)
if err != nil {
tx.Rollback()
return "", err