From 8ec217534e7788d0b4b9d8506478068621e2a8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Tue, 20 Sep 2022 15:44:25 +0800 Subject: [PATCH] =?UTF-8?q?enhance(calculate):=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E6=91=8A=E8=96=84=E6=80=BB=E8=AE=A1=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=9A=84=E8=AE=A1=E7=AE=97=E6=94=B9=E5=8A=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/publicity.go | 44 +++------ model/report_summary.go | 16 ++++ service/calculate.go | 196 ++++++++++++++++++++++++---------------- service/report.go | 100 ++++++++++++-------- 4 files changed, 209 insertions(+), 147 deletions(-) diff --git a/model/publicity.go b/model/publicity.go index 4454154..4f911b1 100644 --- a/model/publicity.go +++ b/model/publicity.go @@ -41,27 +41,7 @@ type EndUserOverallPart struct { ValleyFee decimal.NullDecimal `json:"valleyFee"` } -type DilutedConsumptionOverallPart struct { - Overall decimal.Decimal `json:"overall"` - OverallPrice decimal.Decimal `json:"overallPrice"` - ConsumptionFee decimal.Decimal `json:"consumptionFee"` - OverallFee decimal.Decimal `json:"overallFee"` - Critical decimal.NullDecimal `json:"critical"` - CriticalPrice decimal.NullDecimal `json:"criticalPrice"` - CriticalFee decimal.NullDecimal `json:"criticalFee"` - Peak decimal.NullDecimal `json:"peak"` - PeakPrice decimal.NullDecimal `json:"peakPrice"` - PeakFee decimal.NullDecimal `json:"peakFee"` - Flat decimal.NullDecimal `json:"flat"` - FlatPrice decimal.NullDecimal `json:"flatPrice"` - FlatFee decimal.NullDecimal `json:"flatFee"` - Valley decimal.NullDecimal `json:"valley"` - ValleyPrice decimal.NullDecimal `json:"valleyPrice"` - ValleyFee decimal.NullDecimal `json:"valleyFee"` - Proportion decimal.Decimal `json:"proportion"` -} - -type PublicConsumptionOverallPart struct { +type ConsumptionOverallPart struct { Overall decimal.Decimal `json:"overall"` OverallPrice decimal.Decimal `json:"overallPrice"` ConsumptionFee decimal.Decimal `json:"consumptionFee"` @@ -122,15 +102,15 @@ type EndUserSummary struct { } type Publicity struct { - Report Report `json:"index"` - User UserDetail `json:"enterprise"` - Park Park `json:"park"` - Paid PaidPart `json:"paid"` - EndUser EndUserOverallPart `json:"endUserSum"` - Loss LossPart `json:"loss"` - DilutedConsumptionOverall DilutedConsumptionOverallPart `json:"diluted"` - PublicConsumptionOverall PublicConsumptionOverallPart `json:"public"` - OtherCollections OtherShouldCollectionPart `json:"others"` - Maintenance MaintenancePart `json:"maintenance"` - EndUserDetails []EndUserSummary `json:"endUser"` + Report Report `json:"index"` + User UserDetail `json:"enterprise"` + Park Park `json:"park"` + Paid PaidPart `json:"paid"` + EndUser ConsumptionOverallPart `json:"endUserSum"` + Loss LossPart `json:"loss"` + DilutedConsumptionOverall ConsumptionOverallPart `json:"diluted"` + PublicConsumptionOverall ConsumptionOverallPart `json:"public"` + OtherCollections OtherShouldCollectionPart `json:"others"` + Maintenance MaintenancePart `json:"maintenance"` + EndUserDetails []EndUserSummary `json:"endUser"` } diff --git a/model/report_summary.go b/model/report_summary.go index 1a996af..2302429 100644 --- a/model/report_summary.go +++ b/model/report_summary.go @@ -57,6 +57,22 @@ type Consumptions struct { Proportion decimal.NullDecimal `json:"proportion"` } +func NewConsumptions() Consumptions { + return Consumptions{ + Consumption: decimal.NewNullDecimal(decimal.Zero), + ConsumptionFee: decimal.NewNullDecimal(decimal.Zero), + Critical: decimal.NewNullDecimal(decimal.Zero), + Peak: decimal.NewNullDecimal(decimal.Zero), + PeakFee: decimal.NewNullDecimal(decimal.Zero), + Flat: decimal.NewNullDecimal(decimal.Zero), + CriticalFee: decimal.NewNullDecimal(decimal.Zero), + FlatFee: decimal.NewNullDecimal(decimal.Zero), + Valley: decimal.NewNullDecimal(decimal.Zero), + ValleyFee: decimal.NewNullDecimal(decimal.Zero), + Proportion: decimal.NewNullDecimal(decimal.Zero), + } +} + func (s ReportSummary) Validate() (bool, error) { amountSum := decimal.Sum(s.Critical, s.Peak, s.Valley) if amountSum.GreaterThan(s.Overall) { diff --git a/service/calculate.go b/service/calculate.go index 7a05335..070cb54 100644 --- a/service/calculate.go +++ b/service/calculate.go @@ -41,16 +41,9 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er } // 计算终端用户信息与概览中的合计 - report.Summary.PublicConsumption = decimal.NewNullDecimal(decimal.Zero) - report.Summary.PublicConsumptionCritical = decimal.NewNullDecimal(decimal.Zero) - report.Summary.PublicConsumptionPeak = decimal.NewNullDecimal(decimal.Zero) - report.Summary.PublicConsumptionFlat = decimal.NewNullDecimal(decimal.Zero) - report.Summary.PublicConsumptionValley = decimal.NewNullDecimal(decimal.Zero) - report.Summary.CustomerConsumption = decimal.NewNullDecimal(decimal.Zero) - report.Summary.CustomerConsumptionCritical = decimal.NewNullDecimal(decimal.Zero) - report.Summary.CustomerConsumptionPeak = decimal.NewNullDecimal(decimal.Zero) - report.Summary.CustomerConsumptionFlat = decimal.NewNullDecimal(decimal.Zero) - report.Summary.CustomerConsumptionValley = decimal.NewNullDecimal(decimal.Zero) + report.Summary.Customers = model.NewConsumptions() + report.Summary.Publics = model.NewConsumptions() + report.Summary.Diluteds = model.NewConsumptions() for _, eu := range report.EndUsers { eu.OverallFee = decimal.NewNullDecimal( eu.Overall.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), @@ -67,95 +60,144 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er eu.ValleyFee = decimal.NewNullDecimal( eu.Valley.Decimal.Mul(report.Summary.ValleyPrice.Decimal).RoundBank(2), ) - if eu.IsPublicMeter && eu.WillDilute { - report.Summary.PublicConsumption.Decimal = report.Summary.PublicConsumption.Decimal.Add(eu.Overall.Decimal) - report.Summary.PublicConsumptionCritical.Decimal = report.Summary.PublicConsumptionCritical.Decimal.Add(eu.Critical.Decimal) - report.Summary.PublicConsumptionPeak.Decimal = report.Summary.PublicConsumptionPeak.Decimal.Add(eu.Peak.Decimal) - report.Summary.PublicConsumptionFlat.Decimal = report.Summary.PublicConsumptionFlat.Decimal.Add(eu.Flat.Decimal) - report.Summary.PublicConsumptionValley.Decimal = report.Summary.PublicConsumptionValley.Decimal.Add(eu.Valley.Decimal) + if eu.IsPublicMeter { + report.Summary.Publics.Consumption.Decimal = report.Summary.Publics.Consumption.Decimal.Add(eu.Overall.Decimal) + report.Summary.Publics.Critical.Decimal = report.Summary.Publics.Critical.Decimal.Add(eu.Critical.Decimal) + report.Summary.Publics.Peak.Decimal = report.Summary.Publics.Peak.Decimal.Add(eu.Peak.Decimal) + report.Summary.Publics.Flat.Decimal = report.Summary.Publics.Flat.Decimal.Add(eu.Flat.Decimal) + report.Summary.Publics.Valley.Decimal = report.Summary.Publics.Valley.Decimal.Add(eu.Valley.Decimal) + if eu.WillDilute { + report.Summary.Diluteds.Consumption.Decimal = report.Summary.Diluteds.Consumption.Decimal.Add(eu.Overall.Decimal) + report.Summary.Diluteds.Critical.Decimal = report.Summary.Diluteds.Critical.Decimal.Add(eu.Critical.Decimal) + report.Summary.Diluteds.Peak.Decimal = report.Summary.Diluteds.Peak.Decimal.Add(eu.Peak.Decimal) + report.Summary.Diluteds.Flat.Decimal = report.Summary.Diluteds.Flat.Decimal.Add(eu.Flat.Decimal) + report.Summary.Diluteds.Valley.Decimal = report.Summary.Diluteds.Valley.Decimal.Add(eu.Valley.Decimal) + } } else { - report.Summary.CustomerConsumption.Decimal = report.Summary.CustomerConsumption.Decimal.Add(eu.Overall.Decimal) - report.Summary.CustomerConsumptionCritical.Decimal = report.Summary.CustomerConsumptionCritical.Decimal.Add(eu.Critical.Decimal) - report.Summary.CustomerConsumptionPeak.Decimal = report.Summary.CustomerConsumptionPeak.Decimal.Add(eu.Peak.Decimal) - report.Summary.CustomerConsumptionFlat.Decimal = report.Summary.CustomerConsumptionFlat.Decimal.Add(eu.Flat.Decimal) - report.Summary.CustomerConsumptionValley.Decimal = report.Summary.CustomerConsumptionValley.Decimal.Add(eu.Valley.Decimal) + report.Summary.Customers.Consumption.Decimal = report.Summary.Customers.Consumption.Decimal.Add(eu.Overall.Decimal) + report.Summary.Customers.Critical.Decimal = report.Summary.Customers.Critical.Decimal.Add(eu.Critical.Decimal) + report.Summary.Customers.Peak.Decimal = report.Summary.Customers.Peak.Decimal.Add(eu.Peak.Decimal) + report.Summary.Customers.Flat.Decimal = report.Summary.Customers.Flat.Decimal.Add(eu.Flat.Decimal) + report.Summary.Customers.Valley.Decimal = report.Summary.Customers.Valley.Decimal.Add(eu.Valley.Decimal) } } // 计算户表总电费和公共总电费以及相应的摊薄 if report.SubmeterType == model.CUSTOMER_METER_NON_PV { - report.Summary.CustomerConsumptionFee = decimal.NewNullDecimal( - report.Summary.CustomerConsumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + // 计算终端用户部分 + report.Summary.Customers.ConsumptionFee = decimal.NewNullDecimal( + report.Summary.Customers.Consumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.CustomerConsumptionCriticalFee = decimal.NewNullDecimal( - report.Summary.CustomerConsumptionCritical.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + report.Summary.Customers.CriticalFee = decimal.NewNullDecimal( + report.Summary.Customers.Critical.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.CustomerConsumptionPeakFee = decimal.NewNullDecimal( - report.Summary.CustomerConsumptionPeak.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + report.Summary.Customers.PeakFee = decimal.NewNullDecimal( + report.Summary.Customers.Peak.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.CustomerConsumptionFlatFee = decimal.NewNullDecimal( - report.Summary.CustomerConsumptionFlat.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + report.Summary.Customers.FlatFee = decimal.NewNullDecimal( + report.Summary.Customers.Flat.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.CustomerConsumptionValleyFee = decimal.NewNullDecimal( - report.Summary.CustomerConsumptionValley.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + report.Summary.Customers.ValleyFee = decimal.NewNullDecimal( + report.Summary.Customers.Valley.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.PublicConsumptionFee = decimal.NewNullDecimal( - report.Summary.PublicConsumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + // 计算公共区域部分 + report.Summary.Publics.ConsumptionFee = decimal.NewNullDecimal( + report.Summary.Publics.Consumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.PublicConsumptionCriticalFee = decimal.NewNullDecimal( - report.Summary.PublicConsumptionCritical.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + report.Summary.Publics.CriticalFee = decimal.NewNullDecimal( + report.Summary.Publics.Critical.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.PublicConsumptionPeakFee = decimal.NewNullDecimal( - report.Summary.PublicConsumptionPeak.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + report.Summary.Publics.PeakFee = decimal.NewNullDecimal( + report.Summary.Publics.Peak.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.PublicConsumptionFlatFee = decimal.NewNullDecimal( - report.Summary.PublicConsumptionFlat.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + report.Summary.Publics.FlatFee = decimal.NewNullDecimal( + report.Summary.Publics.Flat.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.PublicConsumptionValleyFee = decimal.NewNullDecimal( - report.Summary.PublicConsumptionValley.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + report.Summary.Publics.ValleyFee = decimal.NewNullDecimal( + report.Summary.Publics.Valley.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + ) + // 计算摊薄总计部分 + report.Summary.Diluteds.ConsumptionFee = decimal.NewNullDecimal( + report.Summary.Diluteds.Consumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + ) + report.Summary.Diluteds.CriticalFee = decimal.NewNullDecimal( + report.Summary.Diluteds.Critical.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + ) + report.Summary.Diluteds.PeakFee = decimal.NewNullDecimal( + report.Summary.Diluteds.Peak.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + ) + report.Summary.Diluteds.FlatFee = decimal.NewNullDecimal( + report.Summary.Diluteds.Flat.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + ) + report.Summary.Diluteds.ValleyFee = decimal.NewNullDecimal( + report.Summary.Diluteds.Valley.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) } if report.SubmeterType == model.CUSTOMER_METER_PV { - report.Summary.CustomerConsumptionFee = decimal.NewNullDecimal( - report.Summary.CustomerConsumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + // 计算终端用户部分 + report.Summary.Customers.ConsumptionFee = decimal.NewNullDecimal( + report.Summary.Customers.Consumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.CustomerConsumptionCriticalFee = decimal.NewNullDecimal( - report.Summary.CustomerConsumptionCritical.Decimal.Mul(report.Summary.CriticalPrice.Decimal).RoundBank(2), + report.Summary.Customers.CriticalFee = decimal.NewNullDecimal( + report.Summary.Customers.Critical.Decimal.Mul(report.Summary.CriticalPrice.Decimal).RoundBank(2), ) - report.Summary.CustomerConsumptionPeakFee = decimal.NewNullDecimal( - report.Summary.CustomerConsumptionPeak.Decimal.Mul(report.Summary.PeakPrice.Decimal).RoundBank(2), + report.Summary.Customers.PeakFee = decimal.NewNullDecimal( + report.Summary.Customers.Peak.Decimal.Mul(report.Summary.PeakPrice.Decimal).RoundBank(2), ) - report.Summary.CustomerConsumptionFlatFee = decimal.NewNullDecimal( - report.Summary.CustomerConsumptionFlat.Decimal.Mul(report.Summary.FlatPrice.Decimal).RoundBank(2), + report.Summary.Customers.FlatFee = decimal.NewNullDecimal( + report.Summary.Customers.Flat.Decimal.Mul(report.Summary.FlatPrice.Decimal).RoundBank(2), ) - report.Summary.CustomerConsumptionValleyFee = decimal.NewNullDecimal( - report.Summary.CustomerConsumptionValley.Decimal.Mul(report.Summary.ValleyPrice.Decimal).RoundBank(2), + report.Summary.Customers.ValleyFee = decimal.NewNullDecimal( + report.Summary.Customers.Valley.Decimal.Mul(report.Summary.ValleyPrice.Decimal).RoundBank(2), ) - report.Summary.PublicConsumptionFee = decimal.NewNullDecimal( - report.Summary.PublicConsumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + // 计算公共区域部分 + report.Summary.Publics.ConsumptionFee = decimal.NewNullDecimal( + report.Summary.Publics.Consumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), ) - report.Summary.PublicConsumptionCriticalFee = decimal.NewNullDecimal( - report.Summary.PublicConsumptionCritical.Decimal.Mul(report.Summary.CriticalPrice.Decimal).RoundBank(2), + report.Summary.Publics.CriticalFee = decimal.NewNullDecimal( + report.Summary.Publics.Critical.Decimal.Mul(report.Summary.CriticalPrice.Decimal).RoundBank(2), ) - report.Summary.PublicConsumptionPeakFee = decimal.NewNullDecimal( - report.Summary.PublicConsumptionPeak.Decimal.Mul(report.Summary.PeakPrice.Decimal).RoundBank(2), + report.Summary.Publics.PeakFee = decimal.NewNullDecimal( + report.Summary.Publics.Peak.Decimal.Mul(report.Summary.PeakPrice.Decimal).RoundBank(2), ) - report.Summary.PublicConsumptionFlatFee = decimal.NewNullDecimal( - report.Summary.PublicConsumptionFlat.Decimal.Mul(report.Summary.FlatPrice.Decimal).RoundBank(2), + report.Summary.Publics.FlatFee = decimal.NewNullDecimal( + report.Summary.Publics.Flat.Decimal.Mul(report.Summary.FlatPrice.Decimal).RoundBank(2), ) - report.Summary.PublicConsumptionValleyFee = decimal.NewNullDecimal( - report.Summary.PublicConsumptionValley.Decimal.Mul(report.Summary.ValleyPrice.Decimal).RoundBank(2), + report.Summary.Publics.ValleyFee = decimal.NewNullDecimal( + report.Summary.Publics.Valley.Decimal.Mul(report.Summary.ValleyPrice.Decimal).RoundBank(2), + ) + // 计算摊薄部分 + report.Summary.Diluteds.ConsumptionFee = decimal.NewNullDecimal( + report.Summary.Diluteds.Consumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2), + ) + report.Summary.Diluteds.CriticalFee = decimal.NewNullDecimal( + report.Summary.Diluteds.Critical.Decimal.Mul(report.Summary.CriticalPrice.Decimal).RoundBank(2), + ) + report.Summary.Diluteds.PeakFee = decimal.NewNullDecimal( + report.Summary.Diluteds.Peak.Decimal.Mul(report.Summary.PeakPrice.Decimal).RoundBank(2), + ) + report.Summary.Diluteds.FlatFee = decimal.NewNullDecimal( + report.Summary.Diluteds.Flat.Decimal.Mul(report.Summary.FlatPrice.Decimal).RoundBank(2), + ) + report.Summary.Diluteds.ValleyFee = decimal.NewNullDecimal( + report.Summary.Diluteds.Valley.Decimal.Mul(report.Summary.ValleyPrice.Decimal).RoundBank(2), ) } if report.Summary.Overall.Abs().GreaterThan(decimal.Zero) { - report.Summary.PublicConsumptionProportion = decimal.NewNullDecimal( - report.Summary.PublicConsumption.Decimal.Div(report.Summary.Overall).RoundBank(15), + report.Summary.Customers.Proportion = decimal.NewNullDecimal( + report.Summary.Customers.Consumption.Decimal.Div(report.Summary.Overall).RoundBank(15), + ) + report.Summary.Publics.Proportion = decimal.NewNullDecimal( + report.Summary.Publics.Consumption.Decimal.Div(report.Summary.Overall).RoundBank(15), + ) + report.Summary.Diluteds.Proportion = decimal.NewNullDecimal( + report.Summary.Diluteds.Consumption.Decimal.Div(report.Summary.Overall).RoundBank(15), ) } // 计算线损 report.Summary.Loss = decimal.NewNullDecimal( - report.Summary.Overall.Sub(report.Summary.PublicConsumption.Decimal).Sub(report.Summary.CustomerConsumption.Decimal), + report.Summary.Overall.Sub(report.Summary.Publics.Consumption.Decimal).Sub(report.Summary.Customers.Consumption.Decimal), ) report.Summary.LossFee = decimal.NewNullDecimal( report.Summary.Loss.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(8), @@ -165,25 +207,27 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er report.Summary.Loss.Decimal.Div(report.Summary.Overall).RoundBank(15), ) } - if report.Summary.CustomerConsumption.Decimal.Abs().GreaterThan(decimal.Zero) { + if report.Summary.Customers.Consumption.Decimal.Abs().GreaterThan(decimal.Zero) { report.Summary.LossDilutedPrice = decimal.NewNullDecimal( - report.Summary.LossFee.Decimal.Div(report.Summary.CustomerConsumption.Decimal).RoundBank(8), + report.Summary.LossFee.Decimal.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(8), ) } // 计算基本电费和调整电费等的摊薄 - if report.Summary.CustomerConsumption.Decimal.Abs().GreaterThan(decimal.Zero) { + if report.Summary.Customers.Consumption.Decimal.Abs().GreaterThan(decimal.Zero) { report.Summary.BasicDilutedPrice = decimal.NewNullDecimal( - report.Summary.BasicFee.Div(report.Summary.CustomerConsumption.Decimal).RoundBank(8), + report.Summary.BasicFee.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(8), ) report.Summary.AdjustDilutedPrice = decimal.NewNullDecimal( - report.Summary.AdjustFee.Div(report.Summary.CustomerConsumption.Decimal).RoundBank(8), + report.Summary.AdjustFee.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(8), ) report.Summary.MaintenanceDilutedPrice = decimal.NewNullDecimal( - maintenanceFeeTotal.Div(report.Summary.CustomerConsumption.Decimal).RoundBank(8), + maintenanceFeeTotal.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(8), ) + // ! 这里需要注意的是,在原始设计中PublicConsumptionDilutedPrice就是表示公共摊薄价格, + // ! 而不是所有公共设施合计数据,所以要使用Diluteds部分数据。 report.Summary.PublicConsumptionDilutedPrice = decimal.NewNullDecimal( - report.Summary.PublicConsumptionFee.Decimal.Div(report.Summary.CustomerConsumption.Decimal).RoundBank(8), + report.Summary.Diluteds.ConsumptionFee.Decimal.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(8), ) } @@ -192,7 +236,7 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er report.Summary.FinalDilutedOverall = decimal.NewNullDecimal( report.Summary.BasicFee. Add(report.Summary.AdjustFee). - Add(report.Summary.PublicConsumptionFee.Decimal). + Add(report.Summary.Diluteds.ConsumptionFee.Decimal). Add(maintenanceFeeTotal). Add(report.Summary.LossFee.Decimal), ) @@ -201,15 +245,15 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er for _, eu := range report.EndUsers { if eu.IsPublicMeter && eu.WillDilute { // 计算需要摊薄的公共表计的摊薄内容 - if report.Summary.PublicConsumption.Decimal.Abs().GreaterThan(decimal.Zero) { - eu.OverallProportion = eu.Overall.Decimal.Div(report.Summary.PublicConsumption.Decimal).RoundBank(15) + if report.Summary.Diluteds.Consumption.Decimal.Abs().GreaterThan(decimal.Zero) { + eu.OverallProportion = eu.Overall.Decimal.Div(report.Summary.Diluteds.Consumption.Decimal).RoundBank(15) } else { eu.OverallProportion = decimal.Zero } } else { // 计算户表表计的摊薄内容 - if report.Summary.CustomerConsumption.Decimal.Abs().GreaterThan(decimal.Zero) { - eu.OverallProportion = eu.Overall.Decimal.Div(report.Summary.CustomerConsumption.Decimal).RoundBank(15) + if report.Summary.Customers.Consumption.Decimal.Abs().GreaterThan(decimal.Zero) { + eu.OverallProportion = eu.Overall.Decimal.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(15) } else { eu.OverallProportion = decimal.Zero } diff --git a/service/report.go b/service/report.go index 752930c..e1c48ea 100644 --- a/service/report.go +++ b/service/report.go @@ -632,22 +632,24 @@ func (_ReportService) AssembleReportPublicity(reportId string) (*model.Publicity BasicFee: report.Summary.BasicFee, AdjustFee: report.Summary.AdjustFee, } - endUserSummary := model.EndUserOverallPart{ - Overall: report.Summary.CustomerConsumption.Decimal, - OverallPrice: report.Summary.OverallPrice.Decimal, - OverallFee: report.Summary.CustomerConsumptionFee.Decimal, - Critical: report.Summary.CustomerConsumptionCritical, - CriticalPrice: report.Summary.CriticalPrice, - CriticalFee: report.Summary.CustomerConsumptionCriticalFee, - Peak: report.Summary.CustomerConsumptionPeak, - PeakPrice: report.Summary.PeakPrice, - PeakFee: report.Summary.CustomerConsumptionPeakFee, - Flat: report.Summary.CustomerConsumptionFlat, - FlatPrice: report.Summary.FlatPrice, - FlatFee: report.Summary.CustomerConsumptionFlatFee, - Valley: report.Summary.CustomerConsumptionValley, - ValleyPrice: report.Summary.ValleyPrice, - ValleyFee: report.Summary.CustomerConsumptionValleyFee, + endUserSummary := model.ConsumptionOverallPart{ + Overall: report.Summary.Customers.Consumption.Decimal, + OverallPrice: report.Summary.OverallPrice.Decimal, + ConsumptionFee: report.Summary.Customers.ConsumptionFee.Decimal, + OverallFee: report.Summary.Customers.ConsumptionFee.Decimal, + Critical: report.Summary.Customers.Critical, + CriticalPrice: report.Summary.CriticalPrice, + CriticalFee: report.Summary.Customers.CriticalFee, + Peak: report.Summary.Customers.Peak, + PeakPrice: report.Summary.PeakPrice, + PeakFee: report.Summary.Customers.PeakFee, + Flat: report.Summary.Customers.Flat, + FlatPrice: report.Summary.FlatPrice, + FlatFee: report.Summary.Customers.FlatFee, + Valley: report.Summary.Customers.Valley, + ValleyPrice: report.Summary.ValleyPrice, + ValleyFee: report.Summary.Customers.ValleyFee, + Proportion: report.Summary.Customers.Proportion.Decimal, } lossPart := model.LossPart{ Quantity: report.Summary.Loss.Decimal, @@ -655,24 +657,43 @@ func (_ReportService) AssembleReportPublicity(reportId string) (*model.Publicity ConsumptionFee: report.Summary.LossFee.Decimal, Proportion: report.Summary.LossProportion.Decimal, } - publicSummary := model.PublicConsumptionOverallPart{ - Overall: report.Summary.PublicConsumption.Decimal, + publicSummary := model.ConsumptionOverallPart{ + Overall: report.Summary.Publics.Consumption.Decimal, OverallPrice: report.Summary.OverallPrice.Decimal, - ConsumptionFee: report.Summary.PublicConsumptionFee.Decimal, - OverallFee: report.Summary.PublicConsumptionFee.Decimal, - Critical: report.Summary.PublicConsumptionCritical, + ConsumptionFee: report.Summary.Publics.ConsumptionFee.Decimal, + OverallFee: report.Summary.Publics.ConsumptionFee.Decimal, + Critical: report.Summary.Publics.Critical, CriticalPrice: report.Summary.CriticalPrice, - CriticalFee: report.Summary.PublicConsumptionCriticalFee, - Peak: report.Summary.PublicConsumptionPeak, + CriticalFee: report.Summary.Publics.CriticalFee, + Peak: report.Summary.Publics.Peak, PeakPrice: report.Summary.PeakPrice, - PeakFee: report.Summary.PublicConsumptionPeakFee, - Flat: report.Summary.PublicConsumptionFlat, + PeakFee: report.Summary.Publics.PeakFee, + Flat: report.Summary.Publics.Flat, FlatPrice: report.Summary.FlatPrice, - FlatFee: report.Summary.PublicConsumptionFlatFee, - Valley: report.Summary.PublicConsumptionValley, + FlatFee: report.Summary.Publics.FlatFee, + Valley: report.Summary.Publics.Valley, ValleyPrice: report.Summary.ValleyPrice, - ValleyFee: report.Summary.PublicConsumptionValleyFee, - Proportion: report.Summary.PublicConsumptionProportion.Decimal, + ValleyFee: report.Summary.Publics.ValleyFee, + Proportion: report.Summary.Publics.Proportion.Decimal, + } + dilutedSummary := model.ConsumptionOverallPart{ + Overall: report.Summary.Diluteds.Consumption.Decimal, + OverallPrice: report.Summary.OverallPrice.Decimal, + ConsumptionFee: report.Summary.Diluteds.ConsumptionFee.Decimal, + OverallFee: report.Summary.Diluteds.ConsumptionFee.Decimal, + Critical: report.Summary.Diluteds.Critical, + CriticalPrice: report.Summary.CriticalPrice, + CriticalFee: report.Summary.Diluteds.CriticalFee, + Peak: report.Summary.Diluteds.Peak, + PeakPrice: report.Summary.PeakPrice, + PeakFee: report.Summary.Diluteds.PeakFee, + Flat: report.Summary.Diluteds.Flat, + FlatPrice: report.Summary.FlatPrice, + FlatFee: report.Summary.Diluteds.FlatFee, + Valley: report.Summary.Diluteds.Valley, + ValleyPrice: report.Summary.ValleyPrice, + ValleyFee: report.Summary.Diluteds.ValleyFee, + Proportion: report.Summary.Diluteds.Proportion.Decimal, } otherCollection := model.OtherShouldCollectionPart{ MaintenanceFee: report.Summary.MaintenanceOverall, @@ -724,16 +745,17 @@ func (_ReportService) AssembleReportPublicity(reportId string) (*model.Publicity ) publicity := &model.Publicity{ - Report: *report, - Park: *report.Park, - User: *report.Park.Enterprise, - Paid: paidPart, - EndUser: endUserSummary, - Loss: lossPart, - PublicConsumptionOverall: publicSummary, - OtherCollections: otherCollection, - Maintenance: maintenanceFees, - EndUserDetails: endUsers, + Report: *report, + Park: *report.Park, + User: *report.Park.Enterprise, + Paid: paidPart, + EndUser: endUserSummary, + Loss: lossPart, + PublicConsumptionOverall: publicSummary, + DilutedConsumptionOverall: dilutedSummary, + OtherCollections: otherCollection, + Maintenance: maintenanceFees, + EndUserDetails: endUsers, } cache.CacheEntity(publicity, []string{fmt.Sprintf("publicity:%s", reportId), fmt.Sprintf("report:%s", reportId), "report", "park"}, "publicity", reportId)