From eaf45331f13017628c0f01b55bf2ffab4058a89c Mon Sep 17 00:00:00 2001 From: ZiHangQin <1420014281@qq.com> Date: Tue, 15 Aug 2023 14:46:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(calculate=5Ftenement)=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=AE=A1=E7=AE=97=E7=9B=B8=E5=85=B3=E8=B5=8B=E5=80=BC?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/calculate/tenement.go | 40 +++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/service/calculate/tenement.go b/service/calculate/tenement.go index 03e1997..83d4ffa 100644 --- a/service/calculate/tenement.go +++ b/service/calculate/tenement.go @@ -283,6 +283,7 @@ func ShiftToAsiaShanghai(t time.Time) time.Time { func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics, summary calculate.Summary, meters MeterMap) []calculate.TenementCharge { result := make(map[string][]string) + var tc []calculate.TenementCharge for _, t := range tenements { meterCodes := make([]string, 0) for _, m := range t.Meters { @@ -292,7 +293,6 @@ func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics, result[t.Tenement.Id] = meterCodes } var Key Key - var tc []calculate.TenementCharge for tCode, meterCodes := range result { relatedMeters := make([]calculate.Meter, 0) for _, code := range meterCodes { @@ -302,6 +302,11 @@ func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics, relatedMeters = append(relatedMeters, meter) } } + fmt.Println("---", relatedMeters[0].Valley) + fmt.Println("---", relatedMeters[0].Flat) + fmt.Println("---", relatedMeters[0].Peak) + fmt.Println("---", relatedMeters[0].Overall) + fmt.Println("---", relatedMeters[0].Critical) // 计算商户的合计电费信息 var overall model.ConsumptionUnit var critical model.ConsumptionUnit @@ -401,7 +406,6 @@ func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics, } var CriticalProportion decimal.Decimal - fmt.Println(summary.Critical.Amount == decimal.Zero) if summary.Critical.Amount.InexactFloat64() == decimal.Zero.InexactFloat64() { CriticalProportion = decimal.Zero } else { @@ -429,28 +433,50 @@ func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics, ValleyProportion = decimal.NewFromFloat(valley.Amount.InexactFloat64() / summary.Valley.Amount.InexactFloat64()) } + var lossProportion decimal.Decimal + if summary.AuthoizeLoss.Amount == decimal.Zero { + lossProportion = decimal.Zero + } else { + lossProportion = decimal.NewFromFloat(lossAmount.InexactFloat64() / summary.AuthoizeLoss.Amount.InexactFloat64()) + } tenementCharge := calculate.TenementCharge{ Tenement: tCode, Overall: model.ConsumptionUnit{ + Amount: overall.Amount, + Fee: overall.Fee, Price: summary.Overall.Price, Proportion: OverallProportion, }, Critical: model.ConsumptionUnit{ + Amount: critical.Amount, + Fee: critical.Fee, Price: summary.Critical.Price, Proportion: CriticalProportion, }, Peak: model.ConsumptionUnit{ - Price: summary.Overall.Price, + Amount: peak.Amount, + Fee: peak.Fee, + Price: summary.Peak.Price, Proportion: PeakProportion, }, Flat: model.ConsumptionUnit{ - Price: summary.Overall.Price, + Amount: flat.Amount, + Fee: flat.Fee, + Price: summary.Flat.Price, Proportion: FlatProportion, }, Valley: model.ConsumptionUnit{ - Price: summary.Overall.Price, + Amount: valley.Amount, + Fee: valley.Fee, + Price: summary.Valley.Price, Proportion: ValleyProportion, }, + Loss: model.ConsumptionUnit{ + Amount: lossAmount, + Fee: lossPooled, + Price: summary.AuthoizeLoss.Price, + Proportion: lossProportion, + }, BasicFee: basicPooled, AdjustFee: adjustPooled, LossPooled: lossPooled, @@ -462,10 +488,10 @@ func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics, Submeters: nil, Poolings: nil, } - + fmt.Println("=====", tenementCharge) tc = append(tc, tenementCharge) } } - fmt.Println(tc) + //fmt.Println(len(tc)) return tc }