forked from free-lancers/electricity_bill_calc_service
[计算相关]获取所有的物业表计,然后对所有的物业表计电量进行计算。(完成)
This commit is contained in:
@@ -3,6 +3,7 @@ package calculate
|
||||
import (
|
||||
"electricity_bill_calc/model"
|
||||
"electricity_bill_calc/types"
|
||||
"fmt"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
@@ -42,6 +43,11 @@ type Meter struct {
|
||||
Poolings []*Pooling
|
||||
}
|
||||
|
||||
type PrimaryTenementStatistics struct {
|
||||
Tenement model.Tenement
|
||||
Meters []Meter
|
||||
}
|
||||
|
||||
type TenementCharge struct {
|
||||
Tenement string
|
||||
Overall model.ConsumptionUnit
|
||||
@@ -90,3 +96,118 @@ type PoolingSummary struct {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
@@ -21,3 +21,13 @@ type Tenement struct {
|
||||
LastModifiedAt types.DateTime `json:"lastModifiedAt" db:"last_modified_at"`
|
||||
DeletedAt *types.DateTime `json:"deletedAt" db:"deleted_at"`
|
||||
}
|
||||
|
||||
type TenementMeter struct {
|
||||
ParkId string `db:"park_id"`
|
||||
TenementId string `db:"tenement_id"`
|
||||
MeterId string `db:"meter_id"`
|
||||
ForeignRelation bool `db:"foreign_relation"`
|
||||
AssociatedAt types.DateTime `db:"associated_at"`
|
||||
DisassociatedAt types.DateTime `db:"disassociated_at"`
|
||||
SynchronizedAt types.DateTime `db:"synchronized_at"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user