fix(meter):修复表计查询中的错误映射关系。
This commit is contained in:
parent
aec1655f1c
commit
037e6258d1
|
@ -23,19 +23,19 @@ import (
|
|||
var meterLog = logger.Named("Handler", "Meter")
|
||||
|
||||
func InitializeMeterHandlers(router *fiber.App) {
|
||||
router.Get("/meter/choice", security.EnterpriseAuthorize, listUnboundMeters)
|
||||
router.Get("/meter/choice/tenement", security.EnterpriseAuthorize, listUnboundTenementMeters)
|
||||
router.Get("/meter/:pid", security.EnterpriseAuthorize, searchMetersWithinPark)
|
||||
router.Post("/meter/:pid", security.EnterpriseAuthorize, createNewMeterManually)
|
||||
router.Get("/meter/:pid/template", security.EnterpriseAuthorize, downloadMeterArchiveTemplate)
|
||||
router.Post("/meter/:pid/batch", security.EnterpriseAuthorize, uploadMeterArchive)
|
||||
router.Get("/meter/:pid/pooled", security.EnterpriseAuthorize, listPooledMeters)
|
||||
router.Get("/meter/:pid/:code", security.EnterpriseAuthorize, retrieveSpecificMeterDetail)
|
||||
router.Put("/meter/:pid/:code", security.EnterpriseAuthorize, updateMeterManually)
|
||||
router.Patch("/meter/:pid/:code", security.EnterpriseAuthorize, replaceMeter)
|
||||
router.Get("/meter/:pid/:code/binding", security.EnterpriseAuthorize, listAssociatedMeters)
|
||||
router.Post("/meter/:pid/:code/binding", security.EnterpriseAuthorize, bindAssociatedMeters)
|
||||
router.Delete("/meter/:pid/:code/binding/:slave", security.EnterpriseAuthorize, unbindAssociatedMeters)
|
||||
router.Get("/meter/:pid/pooled", security.EnterpriseAuthorize, listPooledMeters)
|
||||
router.Get("/meter/choice", security.EnterpriseAuthorize, listUnboundMeters)
|
||||
router.Get("/meter/choice/tenement", security.EnterpriseAuthorize, listUnboundTenementMeters)
|
||||
router.Get("/reading/:pid", security.EnterpriseAuthorize, queryMeterReadings)
|
||||
router.Put("/reading/:pid/:code/:reading", security.EnterpriseAuthorize, updateMeterReading)
|
||||
router.Get("/reading/:pid/template", security.EnterpriseAuthorize, downloadMeterReadingsTemplate)
|
||||
|
|
|
@ -74,7 +74,7 @@ type NestedMeter struct {
|
|||
|
||||
type PooledMeterDetailCompound struct {
|
||||
MeterDetail
|
||||
BindMeters []MeterDetail `json:"bindMeters"`
|
||||
BindMeters []MeterDetail `json:"bindedMeters"`
|
||||
}
|
||||
|
||||
// 以下结构体用于导入表计档案数据
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue
Block a user