fix(query):修正查询时所使用的变量类型。

This commit is contained in:
徐涛 2022-09-18 07:07:26 +08:00
parent ffaccc4c88
commit cea90c5b29
7 changed files with 17 additions and 34 deletions

View File

@ -20,7 +20,7 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er
defer cancel()
// 资料准备
var report *model.Report
var report = new(model.Report)
err = global.DB.NewSelect().Model(report).
Relation("Summary").
Relation("WillDilutedFees").

View File

@ -61,7 +61,7 @@ func (c _ChargeService) SettleCharge(seq int64, uid string) error {
if err != nil {
return err
}
var record *model.UserCharge
var record = new(model.UserCharge)
err = tx.NewSelect().Model(&record).
Where("seq = ?", seq).
Where("user_id = ?", uid).

View File

@ -10,7 +10,6 @@ import (
"electricity_bill_calc/global"
"electricity_bill_calc/logger"
"electricity_bill_calc/model"
"errors"
"fmt"
"io"
"strconv"
@ -164,16 +163,12 @@ func (es _EndUserService) BatchImportNonPVRegister(reportId string, file io.Read
errs.AddError(es.newVirtualExcelAnalysisError(err))
return errs
}
var reportDetail *model.Report
var reportDetail = new(model.Report)
err = global.DB.NewSelect().Model(reportDetail).
Where("id = ?", reportId).
Scan(ctx)
if err != nil {
errs.AddError(es.newVirtualExcelAnalysisError(err))
return errs
}
if reportDetail == nil {
errs.AddError(es.newVirtualExcelAnalysisError(errors.New("未能找到相应的报表。")))
errs.AddError(es.newVirtualExcelAnalysisError(fmt.Errorf("未能找到相应的报表。%w", err)))
return errs
}
meterAppers := make([]MeterAppears, 0)
@ -269,14 +264,10 @@ func (es _EndUserService) BatchImportPVRegister(reportId string, file io.Reader)
errs.AddError(es.newVirtualExcelAnalysisError(err))
return errs
}
var reportDetail *model.Report
var reportDetail = new(model.Report)
err = global.DB.NewSelect().Model(reportDetail).Where("id = ?", reportId).Scan(ctx)
if err != nil {
errs.AddError(es.newVirtualExcelAnalysisError(err))
return errs
}
if reportDetail != nil {
errs.AddError(es.newVirtualExcelAnalysisError(errors.New("未能找到相应的报表。")))
errs.AddError(es.newVirtualExcelAnalysisError(fmt.Errorf("未能找到相应的报表。%w", err)))
return errs
}
meterAppers := make([]MeterAppears, 0)

View File

@ -28,13 +28,9 @@ var GodModeService = _GodModeService{
// 从此处开始为删除报表相关的部分
func (_GodModeService) resetReportIndex(tx *bun.Tx, ctx *context.Context, reportId string) (bool, error) {
var report *model.Report
var report = new(model.Report)
err := tx.NewSelect().Model(report).Where("id = ?", reportId).Scan(*ctx)
if err != nil {
tx.Rollback()
return false, err
}
if report == nil {
tx.Rollback()
return false, exceptions.NewNotFoundError("指定报表索引未找到。")
}
@ -338,11 +334,11 @@ func (_GodModeService) isTheLatestReport(ctx *context.Context, reportId string)
if err != nil || report == nil {
return false, exceptions.NewNotFoundErrorFromError("指定报表索引未找到。", err)
}
var maxPeriod *time.Time
var maxPeriod time.Time
err = global.DB.NewSelect().Model((*model.Report)(nil)).
ColumnExpr("max(?)", bun.Ident("period")).
Where("park_id = ?", report.ParkId).
Scan(*ctx, maxPeriod)
Scan(*ctx, &maxPeriod)
if err != nil {
return false, err
}

View File

@ -125,7 +125,7 @@ func (_ParkService) FetchParkDetail(pid string) (*model.Park, error) {
}
ctx, cancel := global.TimeoutContext()
defer cancel()
var park *model.Park
var park = new(model.Park)
err := global.DB.NewSelect().Model(&park).
Where("id = ?", pid).
Scan(ctx)

View File

@ -277,19 +277,15 @@ func (_ReportService) RetreiveReportIndex(rid string) (*model.Report, error) {
}
ctx, cancel := global.TimeoutContext()
defer cancel()
var report *model.Report
var report = new(model.Report)
err := global.DB.NewSelect().Model(report).
Where("id = ?", rid).
Scan(ctx)
if err != nil {
return nil, err
}
if report != nil {
cache.CacheEntity(report, []string{fmt.Sprintf("report:%s", rid), "park"}, "report", rid)
return report, nil
} else {
return nil, nil
}
}
func (_ReportService) RetreiveReportSummary(rid string) (*model.ReportSummary, error) {

View File

@ -28,7 +28,7 @@ func (_WithdrawService) ApplyWithdraw(reportId string) (bool, error) {
ctx, cancel := global.TimeoutContext()
defer cancel()
var report *model.Report
var report = new(model.Report)
err := global.DB.NewSelect().Model(report).
Where("id = ?", reportId).
Scan(ctx)
@ -38,16 +38,16 @@ func (_WithdrawService) ApplyWithdraw(reportId string) (bool, error) {
if !report.Published {
return false, exceptions.NewImproperOperateError("指定报表尚未发布。")
}
var maxPublished *time.Time
var maxPublished time.Time
err = global.DB.NewSelect().Model((*model.Report)(nil)).
ColumnExpr("max(period)").
Where("park_id = ?", report.ParkId).
Where("published = ?", true).
Scan(ctx, maxPublished)
Scan(ctx, &maxPublished)
if err != nil {
return false, exceptions.NewNotFoundError("未能找到匹配的系列报表。")
}
if maxPublished != nil && !report.Period.Equal(*maxPublished) {
if !report.Period.Equal(maxPublished) {
return false, exceptions.NewImproperOperateError("申请撤回的报表必须是最新已发布的报表。")
}