214 lines
6.9 KiB
Go
214 lines
6.9 KiB
Go
package calculate
|
|
|
|
import (
|
|
"electricity_bill_calc/model"
|
|
"electricity_bill_calc/types"
|
|
"fmt"
|
|
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
type Reading struct {
|
|
ReadAt types.DateTime
|
|
Ratio decimal.Decimal
|
|
Overall decimal.Decimal
|
|
Critical decimal.Decimal
|
|
Peak decimal.Decimal
|
|
Flat decimal.Decimal
|
|
Valley decimal.Decimal
|
|
}
|
|
|
|
type Pooling struct {
|
|
Code string
|
|
Detail model.ConsumptionUnit
|
|
}
|
|
|
|
type Meter struct {
|
|
Code string
|
|
Detail model.MeterDetail
|
|
CoveredArea decimal.Decimal
|
|
LastTermReading *Reading
|
|
CurrentTermReading *Reading
|
|
Overall model.ConsumptionUnit
|
|
Critical model.ConsumptionUnit
|
|
Peak model.ConsumptionUnit
|
|
Flat model.ConsumptionUnit
|
|
Valley model.ConsumptionUnit
|
|
AdjustLoss model.ConsumptionUnit
|
|
PooledBasic model.ConsumptionUnit
|
|
PooledAdjust model.ConsumptionUnit
|
|
PooledLoss model.ConsumptionUnit
|
|
PooledPublic model.ConsumptionUnit
|
|
SharedPoolingProportion decimal.Decimal
|
|
Poolings []*Pooling
|
|
}
|
|
|
|
type PrimaryTenementStatistics struct {
|
|
Tenement model.Tenement
|
|
Meters []Meter
|
|
}
|
|
|
|
type TenementCharge struct {
|
|
Tenement string
|
|
Overall model.ConsumptionUnit
|
|
Critical model.ConsumptionUnit
|
|
Peak model.ConsumptionUnit
|
|
Flat model.ConsumptionUnit
|
|
Valley model.ConsumptionUnit
|
|
BasicFee decimal.Decimal
|
|
AdjustFee decimal.Decimal
|
|
LossPooled decimal.Decimal
|
|
PublicPooled decimal.Decimal
|
|
FinalCharges decimal.Decimal
|
|
Submeters []*Meter
|
|
Poolings []*Meter
|
|
}
|
|
|
|
type Summary struct {
|
|
ReportId string
|
|
OverallArea decimal.Decimal
|
|
Overall model.ConsumptionUnit
|
|
ConsumptionFee decimal.Decimal
|
|
Critical model.ConsumptionUnit
|
|
Peak model.ConsumptionUnit
|
|
Flat model.ConsumptionUnit
|
|
Valley model.ConsumptionUnit
|
|
Loss decimal.Decimal
|
|
LossFee decimal.Decimal
|
|
LossProportion decimal.Decimal
|
|
AuthoizeLoss model.ConsumptionUnit
|
|
BasicFee decimal.Decimal
|
|
BasicPooledPriceConsumption decimal.Decimal
|
|
BasicPooledPriceArea decimal.Decimal
|
|
AdjustFee decimal.Decimal
|
|
AdjustPooledPriceConsumption decimal.Decimal
|
|
AdjustPooledPriceArea decimal.Decimal
|
|
LossDilutedPrice decimal.Decimal
|
|
TotalConsumption decimal.Decimal
|
|
FinalDilutedOverall decimal.Decimal
|
|
}
|
|
|
|
type PoolingSummary struct {
|
|
Tenement string
|
|
Meter string
|
|
TargetMeter string
|
|
Area decimal.NullDecimal
|
|
OverallAmount decimal.Decimal
|
|
PoolingProportion decimal.Decimal
|
|
}
|
|
|
|
func FromReportSummary(summary *model.ReportSummary, pricingMode *model.ReportIndex) Summary {
|
|
var parkPrice float64
|
|
switch pricingMode.PricePolicy {
|
|
case model.PRICING_POLICY_CONSUMPTION:
|
|
parkPrice = summary.ConsumptionFee.Decimal.InexactFloat64() / summary.Overall.Amount.InexactFloat64()
|
|
case model.PRICING_POLICY_ALL:
|
|
parkPrice = summary.Overall.Fee.InexactFloat64() / summary.Overall.Amount.InexactFloat64()
|
|
default:
|
|
fmt.Println("无法识别类型")
|
|
}
|
|
|
|
flatAmount := summary.Overall.Amount.InexactFloat64() -
|
|
summary.Critical.Amount.InexactFloat64() -
|
|
summary.Peak.Amount.InexactFloat64() -
|
|
summary.Valley.Amount.InexactFloat64()
|
|
|
|
flatFee := summary.Overall.Amount.InexactFloat64() -
|
|
summary.Critical.Fee.InexactFloat64() -
|
|
summary.Peak.Fee.InexactFloat64() -
|
|
summary.Valley.Fee.InexactFloat64()
|
|
|
|
var OverallPrice float64
|
|
if summary.Overall.Amount.GreaterThan(decimal.Zero) {
|
|
OverallPrice = parkPrice
|
|
} else {
|
|
OverallPrice = decimal.Zero.InexactFloat64()
|
|
}
|
|
|
|
var CriticalPrice float64
|
|
if summary.Critical.Amount.GreaterThan(decimal.Zero) {
|
|
CriticalPrice = summary.Critical.Fee.InexactFloat64() / summary.Critical.Amount.InexactFloat64()
|
|
} else {
|
|
CriticalPrice = decimal.Zero.InexactFloat64()
|
|
}
|
|
|
|
var PeakPrice float64
|
|
if summary.Peak.Amount.GreaterThan(decimal.Zero) {
|
|
PeakPrice = summary.Peak.Fee.InexactFloat64() / summary.Peak.Amount.InexactFloat64()
|
|
} else {
|
|
PeakPrice = decimal.Zero.InexactFloat64()
|
|
}
|
|
|
|
var FlatPrice float64
|
|
if decimal.NewFromFloat(flatAmount).GreaterThan(decimal.Zero) {
|
|
FlatPrice = flatFee / flatAmount
|
|
} else {
|
|
FlatPrice = decimal.Zero.InexactFloat64()
|
|
}
|
|
|
|
var ValleyPrice float64
|
|
if summary.Valley.Amount.GreaterThan(decimal.Zero) {
|
|
ValleyPrice = summary.Valley.Fee.InexactFloat64() / summary.Valley.Amount.InexactFloat64()
|
|
} else {
|
|
ValleyPrice = decimal.Zero.InexactFloat64()
|
|
}
|
|
|
|
var LossDilutedPrice float64
|
|
if summary.Overall.Amount.GreaterThan(decimal.Zero) {
|
|
LossDilutedPrice = parkPrice
|
|
} else {
|
|
LossDilutedPrice = decimal.Zero.InexactFloat64()
|
|
}
|
|
|
|
_ = parkPrice
|
|
|
|
return Summary{
|
|
ReportId: summary.ReportId,
|
|
OverallArea: decimal.Zero,
|
|
Overall: model.ConsumptionUnit{
|
|
Amount: summary.Overall.Amount,
|
|
Fee: summary.Overall.Fee,
|
|
Price: decimal.NewFromFloat(OverallPrice),
|
|
Proportion: decimal.NewFromFloat(1.0),
|
|
},
|
|
ConsumptionFee: summary.ConsumptionFee.Decimal,
|
|
Critical: model.ConsumptionUnit{
|
|
Amount: summary.Critical.Amount,
|
|
Fee: summary.Critical.Fee,
|
|
Price: decimal.NewFromFloat(CriticalPrice),
|
|
Proportion: decimal.NewFromFloat(summary.Critical.Amount.InexactFloat64() / summary.Overall.Amount.InexactFloat64()),
|
|
},
|
|
Peak: model.ConsumptionUnit{
|
|
Amount: summary.Peak.Amount,
|
|
Fee: summary.Peak.Fee,
|
|
Price: decimal.NewFromFloat(PeakPrice),
|
|
Proportion: decimal.NewFromFloat(summary.Peak.Amount.InexactFloat64() / summary.Overall.Amount.InexactFloat64()),
|
|
},
|
|
Flat: model.ConsumptionUnit{
|
|
Amount: decimal.NewFromFloat(flatAmount),
|
|
Fee: decimal.NewFromFloat(flatFee),
|
|
Price: decimal.NewFromFloat(FlatPrice),
|
|
Proportion: decimal.NewFromFloat(flatAmount / summary.Overall.Amount.InexactFloat64()),
|
|
},
|
|
Valley: model.ConsumptionUnit{
|
|
Amount: summary.Valley.Amount,
|
|
Fee: summary.Valley.Fee,
|
|
Price: decimal.NewFromFloat(ValleyPrice),
|
|
Proportion: decimal.NewFromFloat(summary.Valley.Amount.InexactFloat64() / summary.Overall.Amount.InexactFloat64()),
|
|
},
|
|
Loss: decimal.Zero,
|
|
LossFee: decimal.Zero,
|
|
LossProportion: decimal.Zero,
|
|
AuthoizeLoss: model.ConsumptionUnit{},
|
|
BasicFee: summary.BasicFee,
|
|
BasicPooledPriceConsumption: decimal.Zero,
|
|
BasicPooledPriceArea: decimal.Zero,
|
|
AdjustFee: summary.AdjustFee,
|
|
AdjustPooledPriceConsumption: decimal.Zero,
|
|
AdjustPooledPriceArea: decimal.Zero,
|
|
LossDilutedPrice: decimal.NewFromFloat(LossDilutedPrice),
|
|
TotalConsumption: decimal.Zero,
|
|
FinalDilutedOverall: decimal.Zero,
|
|
}
|
|
}
|