enhance(calculate): 增加方法:计算商户的合计电费信息,并归总与商户相关关联的表计记录
This commit is contained in:
parent
ce4c483bcb
commit
af359f4429
|
@ -270,7 +270,7 @@ func ShiftToAsiaShanghai(t time.Time) time.Time {
|
||||||
|
|
||||||
// 计算各个商户的合计信息,并归总与商户关联的表计记录
|
// 计算各个商户的合计信息,并归总与商户关联的表计记录
|
||||||
func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics,
|
func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics,
|
||||||
summary calculate.Summary, meters MeterMap, _relations []model.MeterRelation) {
|
summary calculate.Summary, meters MeterMap) []calculate.TenementCharge {
|
||||||
result := make(map[string][]string)
|
result := make(map[string][]string)
|
||||||
for _, t := range tenements {
|
for _, t := range tenements {
|
||||||
meterCodes := make([]string, 0)
|
meterCodes := make([]string, 0)
|
||||||
|
@ -281,6 +281,7 @@ func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics,
|
||||||
result[t.Tenement.Id] = meterCodes
|
result[t.Tenement.Id] = meterCodes
|
||||||
}
|
}
|
||||||
var Key Key
|
var Key Key
|
||||||
|
var tc []calculate.TenementCharge
|
||||||
for tCode, meterCodes := range result {
|
for tCode, meterCodes := range result {
|
||||||
relatedMeters := make([]calculate.Meter, 0)
|
relatedMeters := make([]calculate.Meter, 0)
|
||||||
for _, code := range meterCodes {
|
for _, code := range meterCodes {
|
||||||
|
@ -291,6 +292,167 @@ func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 计算商户的合计电费信息
|
// 计算商户的合计电费信息
|
||||||
|
var overall model.ConsumptionUnit
|
||||||
|
var critical model.ConsumptionUnit
|
||||||
|
var peak model.ConsumptionUnit
|
||||||
|
var flat model.ConsumptionUnit
|
||||||
|
var valley model.ConsumptionUnit
|
||||||
|
|
||||||
|
var basicPooled decimal.Decimal
|
||||||
|
var adjustPooled decimal.Decimal
|
||||||
|
var lossAmount decimal.Decimal
|
||||||
|
var lossPooled decimal.Decimal
|
||||||
|
var publicPooled decimal.Decimal
|
||||||
|
|
||||||
|
for _, meter := range relatedMeters {
|
||||||
|
overall.Amount.Add(meter.Overall.Amount)
|
||||||
|
overall.Fee.Add(meter.Overall.Fee)
|
||||||
|
|
||||||
|
critical.Amount.Add(meter.Critical.Amount)
|
||||||
|
critical.Fee.Add(meter.Critical.Fee)
|
||||||
|
|
||||||
|
peak.Amount.Add(meter.Peak.Amount)
|
||||||
|
peak.Fee.Add(meter.Peak.Fee)
|
||||||
|
|
||||||
|
flat.Amount.Add(meter.Flat.Amount)
|
||||||
|
flat.Fee.Add(meter.Flat.Fee)
|
||||||
|
|
||||||
|
valley.Amount.Add(meter.Valley.Amount)
|
||||||
|
valley.Fee.Add(meter.Valley.Fee)
|
||||||
|
|
||||||
|
basicPooled.Add(meter.PooledBasic.Fee)
|
||||||
|
adjustPooled.Add(meter.PooledAdjust.Fee)
|
||||||
|
lossAmount.Add(meter.PooledLoss.Amount)
|
||||||
|
lossPooled.Add(meter.PooledLoss.Fee)
|
||||||
|
publicPooled.Add(meter.PooledPublic.Fee)
|
||||||
|
|
||||||
|
// 反写商户表计的统计数据
|
||||||
|
meter.Overall.Proportion = func() decimal.Decimal {
|
||||||
|
if overall.Amount.Equal(decimal.Zero) {
|
||||||
|
return decimal.Zero
|
||||||
|
}
|
||||||
|
return meter.Overall.Amount.Div(overall.Amount)
|
||||||
|
}()
|
||||||
|
meter.Critical.Proportion = func() decimal.Decimal {
|
||||||
|
if critical.Amount.Equal(decimal.Zero) {
|
||||||
|
return decimal.Zero
|
||||||
|
}
|
||||||
|
return meter.Critical.Amount.Div(critical.Amount)
|
||||||
|
}()
|
||||||
|
meter.Peak.Proportion = func() decimal.Decimal {
|
||||||
|
if peak.Amount.Equal(decimal.Zero) {
|
||||||
|
return decimal.Zero
|
||||||
|
}
|
||||||
|
return meter.Peak.Amount.Div(peak.Amount)
|
||||||
|
}()
|
||||||
|
meter.Flat.Proportion = func() decimal.Decimal {
|
||||||
|
if flat.Amount.Equal(decimal.Zero) {
|
||||||
|
return decimal.Zero
|
||||||
|
}
|
||||||
|
return meter.Flat.Amount.Div(flat.Amount)
|
||||||
|
}()
|
||||||
|
meter.Valley.Proportion = func() decimal.Decimal {
|
||||||
|
if valley.Amount.Equal(decimal.Zero) {
|
||||||
|
return decimal.Zero
|
||||||
|
}
|
||||||
|
return meter.Valley.Amount.Div(valley.Amount)
|
||||||
|
}()
|
||||||
|
meter.PooledBasic.Proportion = func() decimal.Decimal {
|
||||||
|
if basicPooled.Equal(decimal.Zero) {
|
||||||
|
return decimal.Zero
|
||||||
|
}
|
||||||
|
return meter.PooledBasic.Fee.Div(basicPooled)
|
||||||
|
}()
|
||||||
|
meter.PooledAdjust.Proportion = func() decimal.Decimal {
|
||||||
|
if adjustPooled.Equal(decimal.Zero) {
|
||||||
|
return decimal.Zero
|
||||||
|
}
|
||||||
|
return meter.PooledAdjust.Fee.Div(adjustPooled)
|
||||||
|
}()
|
||||||
|
meter.PooledLoss.Proportion = func() decimal.Decimal {
|
||||||
|
if lossPooled.Equal(decimal.Zero) {
|
||||||
|
return decimal.Zero
|
||||||
|
}
|
||||||
|
return meter.PooledLoss.Fee.Div(lossPooled)
|
||||||
|
}()
|
||||||
|
meter.PooledPublic.Proportion = func() decimal.Decimal {
|
||||||
|
if publicPooled.Equal(decimal.Zero) {
|
||||||
|
return decimal.Zero
|
||||||
|
}
|
||||||
|
return meter.PooledPublic.Fee.Div(publicPooled)
|
||||||
|
}()
|
||||||
|
|
||||||
|
var OverallProportion decimal.Decimal
|
||||||
|
if summary.Overall.Amount == decimal.Zero {
|
||||||
|
OverallProportion = decimal.Zero
|
||||||
|
} else {
|
||||||
|
OverallProportion = decimal.NewFromFloat(overall.Amount.InexactFloat64() / summary.Overall.Amount.InexactFloat64())
|
||||||
|
}
|
||||||
|
|
||||||
|
var CriticalProportion decimal.Decimal
|
||||||
|
if summary.Critical.Amount == decimal.Zero {
|
||||||
|
CriticalProportion = decimal.Zero
|
||||||
|
} else {
|
||||||
|
CriticalProportion = decimal.NewFromFloat(critical.Amount.InexactFloat64() / summary.Critical.Amount.InexactFloat64())
|
||||||
|
}
|
||||||
|
|
||||||
|
var PeakProportion decimal.Decimal
|
||||||
|
if summary.Peak.Amount == decimal.Zero {
|
||||||
|
PeakProportion = decimal.Zero
|
||||||
|
} else {
|
||||||
|
PeakProportion = decimal.NewFromFloat(peak.Amount.InexactFloat64() / summary.Peak.Amount.InexactFloat64())
|
||||||
|
}
|
||||||
|
|
||||||
|
var FlatProportion decimal.Decimal
|
||||||
|
if summary.Flat.Amount == decimal.Zero {
|
||||||
|
FlatProportion = decimal.Zero
|
||||||
|
} else {
|
||||||
|
FlatProportion = decimal.NewFromFloat(flat.Amount.InexactFloat64() / summary.Flat.Amount.InexactFloat64())
|
||||||
|
}
|
||||||
|
|
||||||
|
var ValleyProportion decimal.Decimal
|
||||||
|
if summary.Valley.Amount == decimal.Zero {
|
||||||
|
ValleyProportion = decimal.Zero
|
||||||
|
} else {
|
||||||
|
ValleyProportion = decimal.NewFromFloat(valley.Amount.InexactFloat64() / summary.Valley.Amount.InexactFloat64())
|
||||||
|
}
|
||||||
|
|
||||||
|
tenementCharge := calculate.TenementCharge{
|
||||||
|
Tenement: tCode,
|
||||||
|
Overall: model.ConsumptionUnit{
|
||||||
|
Price: summary.Overall.Price,
|
||||||
|
Proportion: OverallProportion,
|
||||||
|
},
|
||||||
|
Critical: model.ConsumptionUnit{
|
||||||
|
Price: summary.Critical.Price,
|
||||||
|
Proportion: CriticalProportion,
|
||||||
|
},
|
||||||
|
Peak: model.ConsumptionUnit{
|
||||||
|
Price: summary.Overall.Price,
|
||||||
|
Proportion: PeakProportion,
|
||||||
|
},
|
||||||
|
Flat: model.ConsumptionUnit{
|
||||||
|
Price: summary.Overall.Price,
|
||||||
|
Proportion: FlatProportion,
|
||||||
|
},
|
||||||
|
Valley: model.ConsumptionUnit{
|
||||||
|
Price: summary.Overall.Price,
|
||||||
|
Proportion: ValleyProportion,
|
||||||
|
},
|
||||||
|
BasicFee: basicPooled,
|
||||||
|
AdjustFee: adjustPooled,
|
||||||
|
LossPooled: lossPooled,
|
||||||
|
PublicPooled: publicPooled,
|
||||||
|
FinalCharges: decimal.NewFromFloat(
|
||||||
|
overall.Fee.InexactFloat64() + basicPooled.InexactFloat64() +
|
||||||
|
adjustPooled.InexactFloat64() + lossPooled.InexactFloat64() +
|
||||||
|
publicPooled.InexactFloat64()),
|
||||||
|
Submeters: nil,
|
||||||
|
Poolings: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
tc = append(tc, tenementCharge)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return tc
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,12 @@ func MainCalculateProcess(rid string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(meterRelations, poolingMetersReports, parkMetersReports, parkTotal)
|
//为获取值初始化一个空的,合并分支时可忽略
|
||||||
|
var meters MeterMap
|
||||||
|
|
||||||
|
// 计算商户的合计电费信息,并归总与商户相关联的表计记录
|
||||||
|
tenementCharges := TenementChargeCalculate(tenementReports, summary, meters)
|
||||||
|
|
||||||
|
fmt.Println(meterRelations, poolingMetersReports, tenementCharges)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user