diff --git a/service/end_user.go b/service/end_user.go index d0e46e4..e0928ee 100644 --- a/service/end_user.go +++ b/service/end_user.go @@ -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 { diff --git a/service/report.go b/service/report.go index 2ec9526..752930c 100644 --- a/service/report.go +++ b/service/report.go @@ -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