From 2aa3729e03043a89dd2fbe980a0face882d7e609 Mon Sep 17 00:00:00 2001 From: DEKA_123 <1904876928@qq.com> Date: Wed, 9 Aug 2023 15:42:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(#12):=E4=BF=AE=E5=A4=8D=E6=8A=84=E8=A1=A8?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E4=B8=8E=E8=A1=A8=E8=AE=B0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=A4=84=E6=97=A0=E8=AE=BA=E9=80=89=E6=8B=A9=E4=BB=BB=E4=BD=95?= =?UTF-8?q?=E8=A1=A8=E8=AE=B0=E7=B1=BB=E5=9E=8B=E5=8F=AA=E4=BC=9A=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=85=A8=E9=83=A8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/meter.go | 6 ++++-- repository/calculate.go | 1 + repository/meter.go | 20 +++++++++++--------- service/calculate/wattCost.go | 17 ++++++++--------- service/meter.go | 4 ++-- settings.yaml | 4 ++-- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/controller/meter.go b/controller/meter.go index eb3424d..1c8c8a3 100644 --- a/controller/meter.go +++ b/controller/meter.go @@ -54,7 +54,8 @@ func searchMetersWithinPark(c *fiber.Ctx) error { } keyword := c.Query("keyword") page := c.QueryInt("page", 1) - meters, total, err := repository.MeterRepository.MetersIn(parkId, uint(page), &keyword) + mtype := c.QueryInt("type", 0) + meters, total, err := repository.MeterRepository.MetersIn(parkId, uint(page), &keyword, uint(mtype)) if err != nil { meterLog.Error("无法查询指定园区下的表计信息,无法获取表计列表", zap.Error(err)) return result.Error(http.StatusInternalServerError, err.Error()) @@ -349,6 +350,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") if pass, err := checkParkBelongs(parkId, meterLog, c, &result); !pass { return err } @@ -373,7 +375,7 @@ func queryMeterReadings(c *fiber.Ctx) error { endDate = &parsedDate } } - readings, total, err := service.MeterService.SearchMeterReadings(parkId, building, startDate, endDate, uint(page), keyword) + readings, total, err := service.MeterService.SearchMeterReadings(parkId, building, startDate, endDate, uint(page), keyword, uint(mtype)) if err != nil { meterLog.Error("查询指定园区中的表计读数,无法获取表计读数列表", zap.Error(err)) return result.Error(http.StatusInternalServerError, err.Error()) diff --git a/repository/calculate.go b/repository/calculate.go index 7318511..ecd148f 100644 --- a/repository/calculate.go +++ b/repository/calculate.go @@ -249,6 +249,7 @@ func (cr _CalculateRepository) GetLastPeriodReadings(rid string, meterType int16 cr.log.Error("获取指定报表中所有涉及到的表计在核算起始日期前的最后一次读数出错", zap.Error(err)) return nil, err } + fmt.Println(">>>>>>>>>>>>", readingsSql) fmt.Println(";;;;;;;;;;;;;;;;;;", readings) return readings, nil } diff --git a/repository/meter.go b/repository/meter.go index 9aba81d..962c675 100644 --- a/repository/meter.go +++ b/repository/meter.go @@ -12,7 +12,6 @@ import ( "electricity_bill_calc/types" "electricity_bill_calc/vo" "fmt" - "github.com/doug-martin/goqu/v9" _ "github.com/doug-martin/goqu/v9/dialect/postgres" "github.com/georgysavva/scany/v2/pgxscan" @@ -121,11 +120,10 @@ func (mr _MeterRepository) AllUsedMetersInReport(rid string) ([]*model.MeterDeta } // 分页列出指定园区下的表计信息 -func (mr _MeterRepository) MetersIn(pid string, page uint, keyword *string) ([]*model.MeterDetail, int64, error) { +func (mr _MeterRepository) MetersIn(pid string, page uint, keyword *string, mtype uint) ([]*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() - meterQuery := mr.ds. From(goqu.T("meter_04kv").As("m")). LeftJoin(goqu.T("park_building").As("b"), goqu.On(goqu.I("m.building").Eq(goqu.I("b.id")))). @@ -135,6 +133,7 @@ func (mr _MeterRepository) MetersIn(pid string, page uint, keyword *string) ([]* 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")). @@ -142,6 +141,7 @@ func (mr _MeterRepository) MetersIn(pid string, page uint, keyword *string) ([]* Where( goqu.I("m.park_id").Eq(pid), goqu.I("m.detached_at").IsNull(), + goqu.I("m.meter_type").Eq(mtype), ) if keyword != nil && len(*keyword) > 0 { @@ -174,11 +174,11 @@ func (mr _MeterRepository) MetersIn(pid string, page uint, keyword *string) ([]* mr.log.Error("查询表计信息失败", zap.Error(err)) return make([]*model.MeterDetail, 0), 0, err } + if err := pgxscan.Get(ctx, global.DB, &total, countSql, countArgs...); err != nil { mr.log.Error("查询表计数量失败", zap.Error(err)) return make([]*model.MeterDetail, 0), 0, err } - return meters, total, nil } @@ -209,7 +209,6 @@ func (mr _MeterRepository) ListMetersByIDs(pid string, ids []string) ([]*model.M mr.log.Error("查询表计信息失败", zap.Error(err)) return make([]*model.MeterDetail, 0), err } - return meters, nil } @@ -777,24 +776,28 @@ func (mr _MeterRepository) ListUnboundTenementMeters(uid string, pid *string, ke } // 查询指定园区中的符合条件的抄表记录 -func (mr _MeterRepository) ListMeterReadings(pid string, keyword *string, page uint, start, end *types.Date, buidling *string) ([]*model.MeterReading, int64, error) { +func (mr _MeterRepository) ListMeterReadings(pid string, keyword *string, page uint, start, end *types.Date, buidling *string, mtype uint) ([]*model.MeterReading, int64, error) { mr.log.Info("查询指定园区中的符合条件的抄表记录", zap.String("park id", pid), zap.String("keyword", tools.DefaultTo(keyword, "")), zap.Uint("page", page), logger.DateFieldp("start", start), logger.DateFieldp("end", end), zap.String("building", tools.DefaultTo(buidling, ""))) ctx, cancel := global.TimeoutContext() defer cancel() readingQuery := mr.ds. From(goqu.T("meter_reading").As("r")). - LeftJoin(goqu.T("meter_04kv").As("m"), goqu.On(goqu.I("r.meter_id").Eq(goqu.I("m.code")), goqu.I("m.park_id").Eq(goqu.I("r.park_id")))). + LeftJoin(goqu.T("meter_04kv").As("m"), goqu.On(goqu.I("r.meter_id").Eq(goqu.I("m.code")), + goqu.I("m.park_id").Eq(goqu.I("r.park_id")))). 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")). - LeftJoin(goqu.T("meter_04kv").As("m"), goqu.On(goqu.I("r.meter_id").Eq(goqu.I("m.code")), goqu.I("m.park_id").Eq(goqu.I("r.park_id")))). + LeftJoin(goqu.T("meter_04kv").As("m"), goqu.On(goqu.I("r.meter_id").Eq(goqu.I("m.code")), + goqu.I("m.park_id").Eq(goqu.I("r.park_id")))). Select(goqu.COUNT("*")). Where( goqu.I("r.park_id").Eq(pid), + goqu.I("m.meter_type").Eq(mtype), ) if keyword != nil && len(*keyword) > 0 { @@ -859,7 +862,6 @@ func (mr _MeterRepository) ListMeterReadings(pid string, keyword *string, page u mr.log.Error("查询抄表记录数量失败", zap.Error(err)) return make([]*model.MeterReading, 0), 0, err } - return readings, total, nil } diff --git a/service/calculate/wattCost.go b/service/calculate/wattCost.go index 724334f..d6cf3d6 100644 --- a/service/calculate/wattCost.go +++ b/service/calculate/wattCost.go @@ -64,14 +64,14 @@ func MainCalculateProcess(rid string) error { } // 计算所有表计的总电量 - _ = TotalConsumptionCalculate(tenementReports, summary) + parkTotal := TotalConsumptionCalculate(tenementReports, summary) - // 计算线损以及调整线损 - //err = LossCalculate(report, parkMetersReports, &parkTotal, &summary) - //if err != nil { - // fmt.Println("9", err) - // return err - //} + //计算线损以及调整线损 + err = LossCalculate(report, parkMetersReports, &parkTotal, &summary) + if err != nil { + fmt.Println("9", err) + return err + } // 计算所有已经启用的商铺面积总和,仅计算所有未迁出的商户的所有表计对应的商铺面积。 _, err = EnabledAreaCalculate(&tenementReports, &summary) @@ -79,14 +79,13 @@ func MainCalculateProcess(rid string) error { fmt.Println("10", err) return err } + // 计算基本电费分摊、调整电费分摊、电费摊薄单价。 err = CalculatePrices(&summary) if err != nil { fmt.Println("11", err) return err } fmt.Println("计算数据读取完成") - // 计算基本电费分摊、调整电费分摊、电费摊薄单价。 - err = CalculatePrices(&summary) // 收集目前所有已经处理的表计,统一对其进行摊薄计算。 meters, err := CollectMeters(tenementReports, poolingMetersReports, parkMetersReports) if err != nil { diff --git a/service/meter.go b/service/meter.go index ff3be35..0fbd15c 100644 --- a/service/meter.go +++ b/service/meter.go @@ -587,7 +587,7 @@ func (ms _MeterService) UnbindMeter(pid, masterMeter string, slaveMeters []strin } // 查询符合条件的表计读数记录 -func (ms _MeterService) SearchMeterReadings(pid string, building *string, start, end *types.Date, page uint, keyword *string) ([]*model.DetailedMeterReading, int64, error) { +func (ms _MeterService) SearchMeterReadings(pid string, building *string, start, end *types.Date, page uint, keyword *string, mtype uint) ([]*model.DetailedMeterReading, int64, error) { ms.log.Info( "查询符合条件的表计读数记录", zap.String("park id", pid), @@ -597,7 +597,7 @@ func (ms _MeterService) SearchMeterReadings(pid string, building *string, start, zap.Uint("page", page), zap.Stringp("keyword", keyword), ) - readings, total, err := repository.MeterRepository.ListMeterReadings(pid, keyword, page, start, end, building) + readings, total, err := repository.MeterRepository.ListMeterReadings(pid, keyword, page, start, end, building, mtype) if err != nil { ms.log.Error("无法查询符合条件的表计读数记录。", zap.Error(err)) return make([]*model.DetailedMeterReading, 0), 0, err diff --git a/settings.yaml b/settings.yaml index 7620533..84db9ed 100644 --- a/settings.yaml +++ b/settings.yaml @@ -12,9 +12,9 @@ Server: ReadTimeout: 60 WriteTimeout: 60 Redis: - Host: 127.0.0.1 + Host: 192.168.88.129 Port: 6379 - Password: + Password: 123456 DB: 1 Service: MaxSessionLife: 2h