fix(#10):修复创建报表错误,但查出列出园区bug

This commit is contained in:
2023-08-09 10:48:33 +08:00
parent 00cf35ec2a
commit dd6becc994
7 changed files with 61 additions and 30 deletions

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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{

View File

@@ -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)
// 收集目前所有已经处理的表计,统一对其进行摊薄计算。

View File

@@ -9,6 +9,7 @@ import (
"electricity_bill_calc/types"
"electricity_bill_calc/vo"
"github.com/pkg/errors"
"log"
"sync"
"github.com/doug-martin/goqu/v9"
@@ -216,6 +217,8 @@ func (rs _ReportService) CreateNewReport(createFrom *vo.ReportCreationForm) (boo
rs.log.Error("创建核算报表错误", zap.Error(err))
return false, err
}
log.Println("创建成功successsssssssssssssssssssssssssssssssssssssssssssssssssssss")
if !state {
status, err := repository.CalculateRepository.UpdateReportCalculateStatus(report, "InsufficientData",
"创建报表时发生错误,需手动再次计算")
@@ -225,11 +228,13 @@ func (rs _ReportService) CreateNewReport(createFrom *vo.ReportCreationForm) (boo
}
return status, nil
}
log.Println("更新成功succssssssssssssssss")
err = rs.CalculateReport(report)
if err != nil {
rs.log.Error("计算时出错", zap.Error(err))
return false, err
}
log.Println("返回truettttttttttttttttttt")
return true, nil
}
@@ -259,13 +264,13 @@ var CALCULATE_TASK_PARALLEL_CONTROL = func() *sync.Mutex {
// 执行一个核算报表的计算任务
func (rs _ReportService) CalculateReport(rid string) error {
semaphore := CALCULATE_TASK_PARALLEL_CONTROL
semaphore.Lock()
defer semaphore.Unlock()
//semaphore := CALCULATE_TASK_PARALLEL_CONTROL
//
//semaphore.Lock()
//defer semaphore.Unlock()
errs := calculate.MainCalculateProcess(rid)
log.Println("开始计算555555555555555555555555555")
if errs == nil {
_, err := repository.CalculateRepository.UpdateReportCalculateStatus(rid, "success", "")
if err != nil {