forked from free-lancers/electricity_bill_calc_service
fix(meter):修复表计查询中的错误映射关系。
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"electricity_bill_calc/types"
|
||||
"electricity_bill_calc/vo"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/doug-martin/goqu/v9"
|
||||
_ "github.com/doug-martin/goqu/v9/dialect/postgres"
|
||||
@@ -477,7 +476,7 @@ func (mr _MeterRepository) UnbindMeter(tx pgx.Tx, ctx context.Context, pid, mast
|
||||
goqu.I("park_id").Eq(pid),
|
||||
goqu.I("master_meter_id").Eq(masterMeter),
|
||||
goqu.I("slave_meter_id").Eq(slaveMeter),
|
||||
goqu.I("revoke_at").IsNull(),
|
||||
goqu.I("revoked_at").IsNull(),
|
||||
).
|
||||
Prepared(true).ToSQL()
|
||||
|
||||
@@ -518,25 +517,17 @@ func (mr _MeterRepository) ListPooledMeterRelations(pid, code string) ([]*model.
|
||||
// 列出指定公摊表计列表所包含的全部关联表计关系
|
||||
func (mr _MeterRepository) ListPooledMeterRelationsByCodes(pid string, codes []string) ([]*model.MeterRelation, error) {
|
||||
mr.log.Info("列出指定公摊表计列表所包含的全部关联表计关系", zap.String("park id", pid), zap.Strings("meter codes", codes))
|
||||
cacheConditions := []string{
|
||||
pid,
|
||||
strings.Join(codes, ","),
|
||||
}
|
||||
if relations, err := cache.RetrieveSearch[[]*model.MeterRelation]("meter_relations", cacheConditions...); err == nil {
|
||||
mr.log.Info("从缓存中获取到了所需的关联表计信息", zap.Int("count", len(*relations)))
|
||||
return *relations, nil
|
||||
}
|
||||
ctx, cancel := global.TimeoutContext()
|
||||
defer cancel()
|
||||
|
||||
var relations []*model.MeterRelation
|
||||
relationsSql, relationsArgs, _ := mr.ds.
|
||||
From(goqu.T("meter_relations")).
|
||||
Select("*").
|
||||
From(goqu.T("meter_relations").As("r")).
|
||||
Select("r.*").
|
||||
Where(
|
||||
goqu.I("r.park_id").Eq(pid),
|
||||
goqu.I("r.master_meter_id").Eq(goqu.Func("any", codes)),
|
||||
goqu.I("r.revoke_at").IsNull(),
|
||||
goqu.I("r.master_meter_id").In(codes),
|
||||
goqu.I("r.revoked_at").IsNull(),
|
||||
).
|
||||
Prepared(true).ToSQL()
|
||||
|
||||
@@ -561,7 +552,7 @@ func (mr _MeterRepository) ListMeterRelations(pid, code string) ([]*model.MeterR
|
||||
Where(
|
||||
goqu.I("r.park_id").Eq(pid),
|
||||
goqu.I("r.slave_meter_id").Eq(code),
|
||||
goqu.I("r.revoke_at").IsNull(),
|
||||
goqu.I("r.revoked_at").IsNull(),
|
||||
).
|
||||
Prepared(true).ToSQL()
|
||||
|
||||
@@ -687,7 +678,7 @@ func (mr _MeterRepository) ListUnboundMeters(uid string, pid *string, keyword *s
|
||||
))
|
||||
}
|
||||
slaveMeterQuery = slaveMeterQuery.Where(
|
||||
goqu.I("revoke_at").IsNull(),
|
||||
goqu.I("revoked_at").IsNull(),
|
||||
)
|
||||
meterQuery = meterQuery.Where(
|
||||
goqu.I("m.code").NotIn(slaveMeterQuery),
|
||||
|
Reference in New Issue
Block a user