fix(service):修正一些使用错误。

This commit is contained in:
徐涛 2022-09-17 21:35:50 +08:00
parent 60d2db6cdd
commit ffaccc4c88
4 changed files with 6 additions and 18 deletions

View File

@ -1,12 +0,0 @@
package service
func _postProcessSingle[T interface{}](instance *T, has bool, err error) (*T, error) {
if err != nil {
return nil, err
}
if has {
return instance, nil
} else {
return nil, nil
}
}

View File

@ -69,7 +69,7 @@ func (_EndUserService) SearchEndUserRecord(reportId, keyword string, page int) (
relations := []string{"end_user", "report", "park"} relations := []string{"end_user", "report", "park"}
for _, eu := range endUsers { for _, eu := range endUsers {
relations = append(relations, fmt.Sprintf("end_user:%s:%d", eu.ReportId, eu.MeterId)) relations = append(relations, fmt.Sprintf("end_user:%s:%s", eu.ReportId, eu.MeterId))
} }
cache.CacheCount(relations, "end_user_detail", int64(total), conditions...) cache.CacheCount(relations, "end_user_detail", int64(total), conditions...)
cache.CacheSearch(endUsers, relations, "end_user_detail", conditions...) cache.CacheSearch(endUsers, relations, "end_user_detail", conditions...)
@ -164,7 +164,7 @@ func (es _EndUserService) BatchImportNonPVRegister(reportId string, file io.Read
errs.AddError(es.newVirtualExcelAnalysisError(err)) errs.AddError(es.newVirtualExcelAnalysisError(err))
return errs return errs
} }
reportDetail := new(model.Report) var reportDetail *model.Report
err = global.DB.NewSelect().Model(reportDetail). err = global.DB.NewSelect().Model(reportDetail).
Where("id = ?", reportId). Where("id = ?", reportId).
Scan(ctx) Scan(ctx)
@ -269,7 +269,7 @@ func (es _EndUserService) BatchImportPVRegister(reportId string, file io.Reader)
errs.AddError(es.newVirtualExcelAnalysisError(err)) errs.AddError(es.newVirtualExcelAnalysisError(err))
return errs return errs
} }
reportDetail := new(model.Report) var reportDetail *model.Report
err = global.DB.NewSelect().Model(reportDetail).Where("id = ?", reportId).Scan(ctx) err = global.DB.NewSelect().Model(reportDetail).Where("id = ?", reportId).Scan(ctx)
if err != nil { if err != nil {
errs.AddError(es.newVirtualExcelAnalysisError(err)) errs.AddError(es.newVirtualExcelAnalysisError(err))

View File

@ -28,7 +28,7 @@ var GodModeService = _GodModeService{
// 从此处开始为删除报表相关的部分 // 从此处开始为删除报表相关的部分
func (_GodModeService) resetReportIndex(tx *bun.Tx, ctx *context.Context, reportId string) (bool, error) { func (_GodModeService) resetReportIndex(tx *bun.Tx, ctx *context.Context, reportId string) (bool, error) {
var report = new(model.Report) var report *model.Report
err := tx.NewSelect().Model(report).Where("id = ?", reportId).Scan(*ctx) err := tx.NewSelect().Model(report).Where("id = ?", reportId).Scan(*ctx)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()

View File

@ -66,7 +66,7 @@ func (_ReportService) FetchParksWithNewestReport(uid string) ([]model.ParkNewest
make(map[string]model.ParkNewestReport, 0), make(map[string]model.ParkNewestReport, 0),
) )
relations := lo.Map(reports, func(r model.Report, _ int) string { relations := lo.Map(reports, func(r model.Report, _ int) string {
return fmt.Sprint("report:%s", r.Id) return fmt.Sprintf("report:%s", r.Id)
}) })
relations = append(relations, "park", "report") relations = append(relations, "park", "report")
cache.CacheSearch(reducedParks, relations, "park_newest_report", uid) cache.CacheSearch(reducedParks, relations, "park_newest_report", uid)
@ -277,7 +277,7 @@ func (_ReportService) RetreiveReportIndex(rid string) (*model.Report, error) {
} }
ctx, cancel := global.TimeoutContext() ctx, cancel := global.TimeoutContext()
defer cancel() defer cancel()
report := new(model.Report) var report *model.Report
err := global.DB.NewSelect().Model(report). err := global.DB.NewSelect().Model(report).
Where("id = ?", rid). Where("id = ?", rid).
Scan(ctx) Scan(ctx)