fix(#23): 修复获取园区公共电费概况有问题
This commit is contained in:
parent
3f36153968
commit
de176ce61d
|
@ -10,6 +10,7 @@ import (
|
|||
"electricity_bill_calc/tools"
|
||||
"electricity_bill_calc/types"
|
||||
"electricity_bill_calc/vo"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
|
@ -285,15 +286,47 @@ func listPublicMetersInReport(c *fiber.Ctx) error {
|
|||
reportLog.Error("无法获取核算报表中的公共表计信息", zap.Error(err))
|
||||
return result.Error(fiber.StatusInternalServerError, "无法获取核算报表中的公共表计信息。")
|
||||
}
|
||||
meterResponse := lo.Map(meters, func(meter *model.ReportDetailedPublicConsumption, _ int) *vo.ReportPublicQueryResponse {
|
||||
m := &vo.ReportPublicQueryResponse{}
|
||||
m.FromReportDetailPublicConsumption(meter)
|
||||
return m
|
||||
})
|
||||
|
||||
var meterResponses []vo.Public
|
||||
for _, meter := range meters {
|
||||
fmt.Println("000",meter.ParkMeterID)
|
||||
fmt.Println("000",meter)
|
||||
meterResponse := vo.Public{
|
||||
Address: meter.Address,
|
||||
AdjustLoss: model.ConsumptionUnit{
|
||||
Amount: meter.LossAdjust.Amount,
|
||||
Fee: meter.LossAdjust.Fee,
|
||||
Price: meter.LossAdjust.Price,
|
||||
Proportion: meter.LossAdjust.Proportion,
|
||||
},
|
||||
Area: meter.Area.Decimal.String(),
|
||||
AttachedAt: meter.AttachedAt,
|
||||
Building: meter.Building,
|
||||
BuildingName: meter.BuildingName,
|
||||
Code: meter.ParkMeterID,
|
||||
DetachedAt: meter.DetachedAt,
|
||||
DisplayRatio: strconv.FormatFloat(meter.DisplayRatio, 'f', -1, 64),
|
||||
Enabled: meter.Enabled,
|
||||
OnFloor: meter.OnFloor,
|
||||
Overall: model.ConsumptionUnit{
|
||||
Amount: meter.Overall.Amount,
|
||||
Fee: meter.Overall.Fee,
|
||||
Price: meter.Overall.Price,
|
||||
Proportion: meter.Overall.Proportion,
|
||||
},
|
||||
ParkID: meter.ParkID,
|
||||
Ratio: meter.Ratio.String(),
|
||||
Seq: meter.Seq,
|
||||
Type: float64(meter.MeterType),
|
||||
}
|
||||
|
||||
meterResponses = append(meterResponses, meterResponse)
|
||||
}
|
||||
fmt.Println(meterResponses)
|
||||
return result.Success(
|
||||
"已经获取到指定核算报表中的分页公共表计的核算信息。",
|
||||
response.NewPagedResponse(page, total).ToMap(),
|
||||
fiber.Map{"public": meterResponse},
|
||||
fiber.Map{"public": meterResponses},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -344,23 +344,31 @@ func (rr _ReportRepository) GetReportTaskStatus(uid string) ([]*model.ReportTask
|
|||
}
|
||||
|
||||
// 检索指定核算报表中园区公共表计的核算记录
|
||||
func (rr _ReportRepository) ListPublicMetersInReport(rid string, page uint, keyword *string) ([]*model.ReportDetailedPublicConsumption, int64, error) {
|
||||
func (rr _ReportRepository) ListPublicMetersInReport(rid string, page uint, keyword *string) ([]*vo.ReportPublishResponse, int64, error) {
|
||||
rr.log.Info("检索指定核算报表中园区公共表计的核算记录", zap.String("Report", rid))
|
||||
ctx, cancel := global.TimeoutContext()
|
||||
defer cancel()
|
||||
|
||||
reportQuery := rr.ds.
|
||||
From(goqu.T("report_public_consumption").As("r")).
|
||||
Join(goqu.T("meter_04kv").As("m"), goqu.On(goqu.I("m.code").Eq(goqu.I("r.park_meter_id")))).
|
||||
Join(goqu.T("report").As("ri"), goqu.On(goqu.I("ri.id").Eq(goqu.I("r.report_id")))).
|
||||
Join(goqu.T("meter_04kv").As("m"), goqu.On(
|
||||
goqu.I("m.code").Eq(goqu.I("r.park_meter_id")),
|
||||
goqu.I("m.park_id").Eq(goqu.I("ri.park_id")),
|
||||
)).
|
||||
Join(goqu.T("park").As("p"), goqu.On(goqu.I("p.id").Eq(goqu.I("m.park_id")))).
|
||||
LeftJoin(goqu.T("park_building").As("b"), goqu.On(goqu.I("b.id").Eq(goqu.I("m.building")))).
|
||||
Select(
|
||||
goqu.I("r.*"), goqu.I("b.name").As("building_name"), goqu.I("p.public_pooled"),
|
||||
goqu.I("r.*"), goqu.I("m.*"), goqu.I("b.name").As("building_name"),
|
||||
).
|
||||
Where(goqu.I("r.report_id").Eq(rid))
|
||||
countQuery := rr.ds.
|
||||
From(goqu.T("report_public_consumption").As("r")).
|
||||
Join(goqu.T("meter_04kv").As("m"), goqu.On(goqu.I("m.code").Eq(goqu.I("r.park_meter_id")))).
|
||||
Join(goqu.T("report").As("ri"), goqu.On(goqu.I("ri.id").Eq(goqu.I("r.report_id")))).
|
||||
Join(goqu.T("meter_04kv").As("m"), goqu.On(
|
||||
goqu.I("m.code").Eq(goqu.I("r.park_meter_id")),
|
||||
goqu.I("m.park_id").Eq(goqu.I("ri.park_id")),
|
||||
)).
|
||||
Join(goqu.T("park").As("p"), goqu.On(goqu.I("p.id").Eq(goqu.I("m.park_id")))).
|
||||
LeftJoin(goqu.T("park_building").As("b"), goqu.On(goqu.I("b.id").Eq(goqu.I("m.building")))).
|
||||
Select(goqu.COUNT(goqu.I("r.*"))).
|
||||
|
@ -384,7 +392,7 @@ func (rr _ReportRepository) ListPublicMetersInReport(rid string, page uint, keyw
|
|||
Offset(startRow).Limit(config.ServiceSettings.ItemsPageSize)
|
||||
|
||||
var (
|
||||
consumptions []*model.ReportDetailedPublicConsumption = make([]*model.ReportDetailedPublicConsumption, 0)
|
||||
consumptions = make([]*vo.ReportPublishResponse, 0)
|
||||
count int64
|
||||
)
|
||||
querySql, queryArgs, _ := reportQuery.Prepared(true).ToSQL()
|
||||
|
|
55
vo/meter.go
55
vo/meter.go
|
@ -1,7 +1,9 @@
|
|||
package vo
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/model"
|
||||
"electricity_bill_calc/types"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
@ -59,7 +61,7 @@ type SimplifiedMeterDetailResponse struct {
|
|||
Area decimal.Decimal `json:"area"`
|
||||
Enabled bool `json:"enabled"`
|
||||
MeterType int16 `json:"type"`
|
||||
AttachedAt types.DateTime `json:"attachedAt"`
|
||||
AttachedAt *types.DateTime `json:"attachedAt"`
|
||||
DetachedAt *types.DateTime `json:"detachedAt"`
|
||||
}
|
||||
type ReadableMeterQueryResponse struct {
|
||||
|
@ -67,3 +69,54 @@ type ReadableMeterQueryResponse struct {
|
|||
Address *string `json:"address"`
|
||||
Park string `json:"park"`
|
||||
}
|
||||
|
||||
type ReportPublishResponse struct {
|
||||
//ID string
|
||||
ReportID string `json:"report_id" db:"report_id"` // 报告ID
|
||||
ParkMeterID string `json:"park_meter_id" db:"park_meter_id"` // 停车计费ID
|
||||
Overall model.ConsumptionUnit `json:"overall" db:"overall"` // 总体信息
|
||||
Critical model.ConsumptionUnit `json:"critical" db:"critical"` // 关键信息
|
||||
Peak model.ConsumptionUnit `json:"peak" db:"peak"` // 高峰信息
|
||||
Flat model.ConsumptionUnit `json:"flat" db:"flat"` // 平峰信息
|
||||
Valley model.ConsumptionUnit `json:"valley" db:"valley"` // 谷峰信息
|
||||
LossAdjust model.ConsumptionUnit `json:"loss_adjust" db:"loss_adjust"` // 损耗调整信息
|
||||
ConsumptionTotal float64 `json:"consumption_total" db:"consumption_total"` // 总消费量
|
||||
LossAdjustTotal float64 `json:"loss_adjust_total" db:"loss_adjust_total"` // 总损耗调整
|
||||
FinalTotal float64 `json:"final_total" db:"final_total"` // 最终总量
|
||||
CreatedAt time.Time `json:"created_at" db:"created_at"` // 创建时间
|
||||
LastModifiedAt time.Time `json:"last_modified_at" db:"last_modified_at"` // 最后修改时间
|
||||
Code string `json:"code" db:"code"` // 代码
|
||||
ParkID string `json:"park_id" db:"park_id"` // 停车场ID
|
||||
Address *string `json:"address" db:"address"` // 地址
|
||||
Ratio decimal.Decimal `json:"ratio" db:"ratio"` // 比率
|
||||
Seq int64 `json:"seq" db:"seq"` // 序列号
|
||||
Enabled bool `json:"enabled" db:"enabled"` // 是否启用
|
||||
MeterType int16 `json:"meter_type" db:"meter_type"` // 计量类型
|
||||
Building *string `json:"building" db:"building"` // 建筑物
|
||||
OnFloor *string `json:"on_floor" db:"on_floor"` // 楼层
|
||||
Area decimal.NullDecimal `json:"area" db:"area"` // 面积
|
||||
AttachedAt *types.DateTime `json:"attached_at" db:"attached_at"` // 附加时间
|
||||
DetachedAt *types.DateTime `json:"detached_at" db:"detached_at"` // 分离时间
|
||||
DisplayRatio float64 `json:"display_ratio" db:"display_ratio"` // 显示比例
|
||||
BuildingName *string `json:"building_name" db:"building_name"` // 建筑物名称
|
||||
PublicPooled int16 `json:"public_pooled" db:"public_pooled"` // 公共汇总
|
||||
}
|
||||
|
||||
type Public struct {
|
||||
Address *string `json:"address"` // 户址
|
||||
AdjustLoss model.ConsumptionUnit `json:"adjustLoss"` // 调整线损数据,仅运维可见,仅使用其中`amount`内容
|
||||
Area string `json:"area"` // 所辖面积
|
||||
AttachedAt *types.DateTime `json:"attachedAt"` // 接入系统时间,挂表
|
||||
Building *string `json:"building"` // 所在建筑ID
|
||||
BuildingName *string `json:"buildingName"` // 所在建筑名称
|
||||
Code string `json:"code"` // 表计表号
|
||||
DetachedAt *types.DateTime `json:"detachedAt"` // 从系统移除时间,拆表
|
||||
DisplayRatio string `json:"displayRatio"` // 表计表显倍率,仅用于展示。
|
||||
Enabled bool `json:"enabled"` // 是否可用
|
||||
OnFloor *string `json:"onFloor"` // 所在楼层
|
||||
Overall model.ConsumptionUnit `json:"overall"` // 总电量部分
|
||||
ParkID string `json:"parkId"` // 所属园区ID
|
||||
Ratio string `json:"ratio"` // 表计计算倍率,参与表计读数计算。
|
||||
Seq int64 `json:"seq"` // 抄表序号
|
||||
Type float64 `json:"type"` // 表计类型,0:商户电表,1:园区电表,2:公摊电表
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user