From 877b8304c3bb1314da08a059b5fae28b129d89d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Mon, 26 Jun 2023 16:54:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(report):=E7=A1=AE=E5=AE=9AConsumptionUnit?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84ConsumptionDisplay=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E7=9A=84=E8=87=AA=E5=8A=A8=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vo/park.go | 2 +- vo/report.go | 42 +++++++++++++++++++++++------------------- vo/shares.go | 14 ++++++-------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/vo/park.go b/vo/park.go index cbcc8a6..209f066 100644 --- a/vo/park.go +++ b/vo/park.go @@ -70,7 +70,7 @@ type ParkBuildingInformationForm struct { type SimplifiedParkDetail struct { Id string `json:"id"` - UserId string `json:"user_id"` + UserId string `json:"userId"` Name string `json:"name"` TenementStr *string `json:"tenement"` AreaStr *string `json:"area"` diff --git a/vo/report.go b/vo/report.go index 6ad2f5f..941bd15 100644 --- a/vo/report.go +++ b/vo/report.go @@ -75,9 +75,9 @@ type ComprehensiveReportQueryResponse struct { type BasicReportIndexResponse struct { Id string `json:"id"` - Park string `json:"park_id"` - PeriodBegin types.Date `json:"period_begin"` - PeriodEnd types.Date `json:"period_end"` + Park string `json:"parkId"` + PeriodBegin types.Date `json:"periodBegin"` + PeriodEnd types.Date `json:"periodEnd"` Category int16 `json:"category"` MeterType int16 `json:"meter04kvType"` PricePolicy int16 `json:"pricePolicy"` @@ -86,14 +86,14 @@ type BasicReportIndexResponse struct { LossPooled int16 `json:"lossDiluted"` PublicPooled int16 `json:"publicDiluted"` Published bool `json:"published"` - PublishedAt *types.DateTime `json:"published_at"` + PublishedAt *types.DateTime `json:"publishedAt"` Withdraw int16 `json:"withdraw"` - LastWithdrawAppliedAt *types.DateTime `json:"last_withdraw_applied_at"` - LastWithdrawAuditAt *types.DateTime `json:"last_withdraw_audit_at"` + LastWithdrawAppliedAt *types.DateTime `json:"lastWithdrawAppliedAt"` + LastWithdrawAuditAt *types.DateTime `json:"lastWithdrawAuditAt"` Status int16 `json:"status"` Message *string `json:"message"` - CreatedAt types.DateTime `json:"created_at"` - LastModifiedAt types.DateTime `json:"last_modified_at"` + CreatedAt types.DateTime `json:"createdAt"` + LastModifiedAt types.DateTime `json:"lastModifiedAt"` } func (bri *BasicReportIndexResponse) Period(p types.DateRange) { @@ -116,8 +116,8 @@ func NewReportDetailQueryResponse(user *model.UserDetail, park *model.Park, repo } type ParkSummaryResponse struct { - Id string `json:"id"` - Overall ConsumptionDisplay `json:"overall"` + ReportId string `json:"reportId"` + OverallDisplay ConsumptionDisplay `json:"overall"` Area decimal.Decimal `json:"area"` BasicFee decimal.Decimal `json:"basicFee"` PooledBasicFeeByAmount decimal.Decimal `json:"pooledBasicFeeByAmount"` @@ -130,6 +130,10 @@ type ParkSummaryResponse struct { LossRate decimal.Decimal `json:"lossRate"` } +func (psr *ParkSummaryResponse) Overall(value model.ConsumptionUnit) { + psr.OverallDisplay.FromConsumptionUnit(&value) +} + type SimplifiedReportSummary struct { Overall model.ConsumptionUnit `json:"overall"` Critical model.ConsumptionUnit `json:"critical"` @@ -200,9 +204,9 @@ type ReportPublicQueryResponse struct { func (rpqr *ReportPublicQueryResponse) FromReportDetailPublicConsumption(value *model.ReportDetailedPublicConsumption) { copier.Copy(&rpqr.SimplifiedMeterQueryResponse, &value.MeterDetail) - rpqr.Overall = FromConsumptionUnit(&value.ReportPublicConsumption.Overall) + rpqr.Overall.FromConsumptionUnit(&value.ReportPublicConsumption.Overall) rpqr.Overall.Amount(value.ReportPublicConsumption.Overall.Amount.Add(value.ReportPublicConsumption.LossAdjust.Amount)) - rpqr.AdjustLoss = FromConsumptionUnit(&value.ReportPublicConsumption.LossAdjust) + rpqr.AdjustLoss.FromConsumptionUnit(&value.ReportPublicConsumption.LossAdjust) } type ReportPooledQueryResponse struct { @@ -213,13 +217,13 @@ type ReportPooledQueryResponse struct { func (rpqr *ReportPooledQueryResponse) FromReportDetailPooledConsumption(value *model.ReportDetailedPooledConsumption) { copier.Copy(&rpqr.SimplifiedMeterQueryResponse, &value.MeterDetail) - rpqr.Overall = FromConsumptionUnit(&value.ReportPooledConsumption.Overall) + rpqr.Overall.FromConsumptionUnit(&value.ReportPooledConsumption.Overall) rpqr.PoolMethod = value.PublicPooled } func (rqpr *ReportPooledQueryResponse) FromReportDetailNestedMeterConsumption(value *model.ReportDetailNestedMeterConsumption) { copier.Copy(&rqpr.SimplifiedMeterQueryResponse, &value.Meter) - rqpr.Overall = FromConsumptionUnit(&value.Consumption.Overall) + rqpr.Overall.FromConsumptionUnit(&value.Consumption.Overall) rqpr.PoolMethod = -1 } @@ -273,11 +277,11 @@ type ReportMeterDetailResponse struct { func (rmdr *ReportMeterDetailResponse) FromNestedMeter(value *model.NestedMeter) { copier.Copy(&rmdr.SimplifiedMeterDetailResponse, &value.MeterDetail) - rmdr.Overall = FromConsumptionUnit(&value.Overall) - rmdr.Critical = FromConsumptionUnit(&value.Critical) - rmdr.Peak = FromConsumptionUnit(&value.Peak) - rmdr.Flat = FromConsumptionUnit(&value.Flat) - rmdr.Valley = FromConsumptionUnit(&value.Valley) + rmdr.Overall.FromConsumptionUnit(&value.Overall) + rmdr.Critical.FromConsumptionUnit(&value.Critical) + rmdr.Peak.FromConsumptionUnit(&value.Peak) + rmdr.Flat.FromConsumptionUnit(&value.Flat) + rmdr.Valley.FromConsumptionUnit(&value.Valley) } type ReportMeterExtendedDetailResponse struct { diff --git a/vo/shares.go b/vo/shares.go index 5612904..19c7e16 100644 --- a/vo/shares.go +++ b/vo/shares.go @@ -3,7 +3,6 @@ package vo import ( "electricity_bill_calc/model" - "github.com/jinzhu/copier" "github.com/shopspring/decimal" ) @@ -18,28 +17,27 @@ type ConsumptionDisplay struct { ProportionStr string `json:"proportion"` } -func (cd ConsumptionDisplay) Amount(a decimal.Decimal) ConsumptionDisplay { +func (cd *ConsumptionDisplay) Amount(a decimal.Decimal) *ConsumptionDisplay { cd.AmountStr = a.StringFixedBank(4) return cd } -func (cd ConsumptionDisplay) Fee(f decimal.Decimal) ConsumptionDisplay { +func (cd *ConsumptionDisplay) Fee(f decimal.Decimal) *ConsumptionDisplay { cd.FeeStr = f.StringFixedBank(4) return cd } -func (cd ConsumptionDisplay) Price(p decimal.Decimal) ConsumptionDisplay { +func (cd *ConsumptionDisplay) Price(p decimal.Decimal) *ConsumptionDisplay { cd.PriceStr = p.StringFixedBank(8) return cd } -func (cd ConsumptionDisplay) Proportion(p decimal.Decimal) ConsumptionDisplay { +func (cd *ConsumptionDisplay) Proportion(p decimal.Decimal) *ConsumptionDisplay { cd.ProportionStr = p.StringFixedBank(8) return cd } -func FromConsumptionUnit(cu *model.ConsumptionUnit) ConsumptionDisplay { - cd := &ConsumptionDisplay{} - copier.Copy(cd, cu) +func (cd *ConsumptionDisplay) FromConsumptionUnit(cu *model.ConsumptionUnit) ConsumptionDisplay { + cd.Amount(cu.Amount).Fee(cu.Fee).Price(cu.Price).Proportion(cu.Proportion) return *cd }