fix(#12):修复抄表记录与表记管理处无论选择任何表记类型只会显示全部错误

This commit is contained in:
DEKA_123 2023-08-10 09:54:57 +08:00
parent 3d918eea85
commit a34aa6ad07
4 changed files with 18 additions and 12 deletions

View File

@ -12,12 +12,11 @@ import (
"electricity_bill_calc/types"
"electricity_bill_calc/vo"
"fmt"
"net/http"
"github.com/gofiber/fiber/v2"
"github.com/jinzhu/copier"
"github.com/samber/lo"
"go.uber.org/zap"
"net/http"
)
var meterLog = logger.Named("Handler", "Meter")
@ -54,8 +53,8 @@ func searchMetersWithinPark(c *fiber.Ctx) error {
}
keyword := c.Query("keyword")
page := c.QueryInt("page", 1)
mtype := c.QueryInt("type", 0)
meters, total, err := repository.MeterRepository.MetersIn(parkId, uint(page), &keyword, uint(mtype))
mtype := c.QueryInt("type", 3)
meters, total, err := repository.MeterRepository.MetersIn(parkId, uint(page), &keyword, mtype)
if err != nil {
meterLog.Error("无法查询指定园区下的表计信息,无法获取表计列表", zap.Error(err))
return result.Error(http.StatusInternalServerError, err.Error())
@ -350,7 +349,7 @@ func listUnboundTenementMeters(c *fiber.Ctx) error {
func queryMeterReadings(c *fiber.Ctx) error {
result := response.NewResult(c)
parkId := c.Params("pid")
mtype := c.QueryInt("type")
mtype := c.QueryInt("type", 3)
if pass, err := checkParkBelongs(parkId, meterLog, c, &result); !pass {
return err
}

View File

@ -420,6 +420,7 @@ func reportComprehensiveSearch(c *fiber.Ctx) error {
reportLog.Error("无法解析核算报表查询的结束日期", zap.Error(err))
return result.BadRequest("无法解析核算报表查询的结束日期。")
}
reports, total, err := service.ReportService.QueryReports(requestUser, park, uint(page), keyword, startDate, endDate)
if err != nil {
reportLog.Error("无法查询核算报表", zap.Error(err))

View File

@ -120,7 +120,7 @@ func (mr _MeterRepository) AllUsedMetersInReport(rid string) ([]*model.MeterDeta
}
// 分页列出指定园区下的表计信息
func (mr _MeterRepository) MetersIn(pid string, page uint, keyword *string, mtype uint) ([]*model.MeterDetail, int64, error) {
func (mr _MeterRepository) MetersIn(pid string, page uint, keyword *string, mtype int) ([]*model.MeterDetail, int64, error) {
mr.log.Info("分页列出指定园区下的表计信息", zap.String("park id", pid), zap.Uint("page", page), zap.String("keyword", tools.DefaultTo(keyword, "")))
ctx, cancel := global.TimeoutContext()
defer cancel()
@ -133,7 +133,6 @@ func (mr _MeterRepository) MetersIn(pid string, page uint, keyword *string, mtyp
Where(
goqu.I("m.park_id").Eq(pid),
goqu.I("m.detached_at").IsNull(),
goqu.I("m.meter_type").Eq(mtype),
)
countQuery := mr.ds.
From(goqu.T("meter_04kv").As("m")).
@ -141,9 +140,11 @@ func (mr _MeterRepository) MetersIn(pid string, page uint, keyword *string, mtyp
Where(
goqu.I("m.park_id").Eq(pid),
goqu.I("m.detached_at").IsNull(),
goqu.I("m.meter_type").Eq(mtype),
)
if mtype != 3 {
meterQuery = meterQuery.Where(goqu.I("m.meter_type").Eq(uint(mtype)))
countQuery = countQuery.Where(goqu.I("m.meter_type").Eq(uint(mtype)))
}
if keyword != nil && len(*keyword) > 0 {
pattern := fmt.Sprintf("%%%s%%", *keyword)
meterQuery = meterQuery.Where(
@ -788,7 +789,6 @@ func (mr _MeterRepository) ListMeterReadings(pid string, keyword *string, page u
Select("r.*").
Where(
goqu.I("r.park_id").Eq(pid),
goqu.I("m.meter_type").Eq(mtype),
)
countQuery := mr.ds.
From(goqu.T("meter_reading").As("r")).
@ -797,8 +797,11 @@ func (mr _MeterRepository) ListMeterReadings(pid string, keyword *string, page u
Select(goqu.COUNT("*")).
Where(
goqu.I("r.park_id").Eq(pid),
goqu.I("m.meter_type").Eq(mtype),
)
if mtype != 3 {
readingQuery = readingQuery.Where(goqu.I("m.meter_type").Eq(mtype))
countQuery = countQuery.Where(goqu.I("m.meter_type").Eq(mtype))
}
if keyword != nil && len(*keyword) > 0 {
pattern := fmt.Sprintf("%%%s%%", *keyword)

View File

@ -638,7 +638,8 @@ func (rr _ReportRepository) ComprehensiveReportSearch(uid, pid *string, page uin
queryDateRange := types.NewDateRange(start, end)
reportQuery = reportQuery.Where(goqu.L("r.period <@ ?", queryDateRange))
countQuery = countQuery.Where(goqu.L("r.period <@ ?", queryDateRange))
reportQuery = reportQuery.Where(goqu.I("r.published").Eq(true))
countQuery = countQuery.Where(goqu.I("r.published").Eq(true))
if keyword != nil && len(*keyword) > 0 {
pattern := fmt.Sprintf("%%%s%%", *keyword)
reportQuery = reportQuery.Where(goqu.Or(
@ -680,6 +681,8 @@ func (rr _ReportRepository) ComprehensiveReportSearch(uid, pid *string, page uin
rr.log.Error("对指定核算报表进行综合检索总数量时出现错误", zap.Error(err))
return reports, 0, err
}
log.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>", querySql, "1111111111111111111111", countSql, "????????????", count)
return reports, count, nil
}