forked from free-lancers/electricity_bill_calc_service
fix(#10):修复创建报表错误,但查出列出园区bug
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"electricity_bill_calc/model"
|
||||
"electricity_bill_calc/model/calculate"
|
||||
"electricity_bill_calc/repository"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -22,6 +23,11 @@ func MetersParkCalculate(report model.ReportIndex, periodStart time.Time,
|
||||
|
||||
parkMeterReadings = append(parkMeterReadings, lastTermParkMeterReadings...)
|
||||
|
||||
if len(parkMeterReadings) <= 0 {
|
||||
fmt.Println(parkMeterReadings)
|
||||
return []calculate.Meter{}, nil
|
||||
}
|
||||
|
||||
var parkMetersReports []calculate.Meter
|
||||
for _, meter := range meterDetail {
|
||||
if meter.MeterType == model.METER_INSTALLATION_PARK {
|
||||
|
@@ -4,12 +4,13 @@ import (
|
||||
"electricity_bill_calc/model"
|
||||
"electricity_bill_calc/model/calculate"
|
||||
"electricity_bill_calc/repository"
|
||||
"fmt"
|
||||
"github.com/shopspring/decimal"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
//核算园区中的全部公摊表计的电量用量
|
||||
// 核算园区中的全部公摊表计的电量用量
|
||||
func PooledMetersCalculate(report *model.ReportIndex, periodStart time.Time,
|
||||
periodEnd time.Time, meterDetails []*model.MeterDetail,
|
||||
summary calculate.Summary) ([]calculate.Meter, error) {
|
||||
@@ -24,6 +25,10 @@ func PooledMetersCalculate(report *model.ReportIndex, periodStart time.Time,
|
||||
}
|
||||
|
||||
poolingMeterReadings = append(poolingMeterReadings, lastTermPoolingMeterReadings...)
|
||||
fmt.Println(poolingMeterReadings, "==============================================")
|
||||
if len(poolingMeterReadings) <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var poolingMetersReports []calculate.Meter
|
||||
for _, meter := range meterDetails {
|
||||
@@ -36,7 +41,7 @@ func PooledMetersCalculate(report *model.ReportIndex, periodStart time.Time,
|
||||
return poolingMetersReports, nil
|
||||
}
|
||||
|
||||
// 确定指定非商户表计在指定时间段内的全部电量
|
||||
// 确定指定非商户表计在指定时间段内的全部电量
|
||||
func determinePublicMeterConsumptions(meterId string, periodStart time.Time,
|
||||
periodEnd time.Time, readings []model.MeterReading,
|
||||
meterDetail model.MeterDetail, summary calculate.Summary) (calculate.Meter, error) {
|
||||
|
@@ -42,7 +42,7 @@ func removeDuplicates(meters []calculate.Meter) []calculate.Meter {
|
||||
}
|
||||
|
||||
// 计算线损以及调整线损
|
||||
func LossCalculate(report *model.ReportIndex, Public *[]calculate.Meter,
|
||||
func LossCalculate(report *model.ReportIndex, Public []calculate.Meter,
|
||||
publicTotal *decimal.Decimal, summary *calculate.Summary) error {
|
||||
summary.Loss = summary.Overall.Amount.Sub(summary.TotalConsumption)
|
||||
|
||||
@@ -56,7 +56,7 @@ func LossCalculate(report *model.ReportIndex, Public *[]calculate.Meter,
|
||||
summary.LossProportion = summary.Loss.Div(summaryAmount)
|
||||
|
||||
var authorizedLossRate decimal.Decimal
|
||||
//TODO: 2023.08.04 在此发现reportIndex结构体与数据库中的report表字段不对应缺少两个相应字段,在此添加的,如在其他地方有错误优先查找这里
|
||||
// TODO: 2023.08.04 在此发现reportIndex结构体与数据库中的report表字段不对应缺少两个相应字段,在此添加的,如在其他地方有错误优先查找这里
|
||||
if summary.LossProportion.InexactFloat64() > report.AuthorizedLossRate {
|
||||
authorizedLossRate = summary.LossProportion
|
||||
} else {
|
||||
@@ -72,11 +72,15 @@ func LossCalculate(report *model.ReportIndex, Public *[]calculate.Meter,
|
||||
|
||||
differentialLoss := summary.LossDilutedPrice.Sub(summary.AuthoizeLoss.Amount)
|
||||
|
||||
fmt.Println(publicTotal.InexactFloat64())
|
||||
if publicTotal.InexactFloat64() <= decimal.Zero.InexactFloat64() {
|
||||
return errors.New("园区公共表计的电量总和为非正值,或者园区未设置公共表计,无法计算核定线损")
|
||||
}
|
||||
|
||||
for _, meter := range *Public {
|
||||
if Public == nil {
|
||||
return nil
|
||||
}
|
||||
for _, meter := range Public {
|
||||
amountProportion := meter.Overall.Amount.InexactFloat64() / publicTotal.InexactFloat64()
|
||||
adjustAmount := differentialLoss.InexactFloat64() * decimal.NewFromFloat(-1.0).InexactFloat64()
|
||||
meter.AdjustLoss = model.ConsumptionUnit{
|
||||
|
@@ -64,14 +64,14 @@ func MainCalculateProcess(rid string) error {
|
||||
}
|
||||
|
||||
// 计算所有表计的总电量
|
||||
parkTotal := TotalConsumptionCalculate(tenementReports, summary)
|
||||
_ = TotalConsumptionCalculate(tenementReports, summary)
|
||||
|
||||
// 计算线损以及调整线损
|
||||
err = LossCalculate(report, &parkMetersReports, &parkTotal, &summary)
|
||||
if err != nil {
|
||||
fmt.Println("9", err)
|
||||
return err
|
||||
}
|
||||
//err = LossCalculate(report, parkMetersReports, &parkTotal, &summary)
|
||||
//if err != nil {
|
||||
// fmt.Println("9", err)
|
||||
// return err
|
||||
//}
|
||||
|
||||
// 计算所有已经启用的商铺面积总和,仅计算所有未迁出的商户的所有表计对应的商铺面积。
|
||||
_, err = EnabledAreaCalculate(&tenementReports, &summary)
|
||||
@@ -84,8 +84,7 @@ func MainCalculateProcess(rid string) error {
|
||||
fmt.Println("11", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
fmt.Println("计算数据读取完成")
|
||||
// 计算基本电费分摊、调整电费分摊、电费摊薄单价。
|
||||
err = CalculatePrices(&summary)
|
||||
// 收集目前所有已经处理的表计,统一对其进行摊薄计算。
|
||||
|
Reference in New Issue
Block a user