fix(#10):修复空指针

This commit is contained in:
DEKA_123 2023-08-11 15:31:24 +08:00
parent 683907b363
commit d6829fce27
3 changed files with 11 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"github.com/shopspring/decimal"
"log"
)
func CollectMeters(tenements []calculate.PrimaryTenementStatistics, poolings []calculate.Meter, publics []calculate.Meter) (MeterMap, error) {
@ -14,20 +15,27 @@ func CollectMeters(tenements []calculate.PrimaryTenementStatistics, poolings []c
// Collect tenement meters
for _, t := range tenements {
for _, m := range t.Meters {
log.Println("m000000000000000000000000000", m.Code)
key := Key{TenementID: t.Tenement.Id, Code: m.Code}
meters[key] = m
}
}
// Collect poolings
for _, m := range poolings {
log.Println("m111111111111111111111111", m.Code)
key := Key{TenementID: "", Code: m.Code}
meters[key] = m
}
// Collect publics
for _, m := range publics {
log.Println("m222222222222222222222222222", m.Code)
key := Key{TenementID: "", Code: m.Code}
meters[key] = m
}
log.Println("m33333333333333333333333333333333333333", meters[Key{Code: "yq00001"}])
return meters, nil
}
@ -178,11 +186,10 @@ func CalculateTenementConsumptions(meters MeterMap) (map[string]decimal.Decimal,
// 计算商户表计的公摊分摊
func CalculateTenementPoolings(report model.ReportIndex, summary calculate.Summary, meters MeterMap, meterRelations []model.MeterRelation) error {
switch report.PublicPooled {
case model.POOLING_MODE_AREA:
for _, meter := range meters {
if meter.Detail.MeterType == model.METER_INSTALLATION_TENEMENT {
if meter.Detail.MeterType != model.METER_INSTALLATION_TENEMENT {
var pooleds []struct {
PooledAmount decimal.Decimal
ParentAmount decimal.Decimal
@ -199,7 +206,6 @@ func CalculateTenementPoolings(report model.ReportIndex, summary calculate.Summa
continue
}
// 计算分摊电量和父级表电量
pooledAmount := meter.Detail.Area.Decimal.Div(parentMeter.CoveredArea).Mul(parentMeter.Overall.Amount).Mul(meter.SharedPoolingProportion)
pooleds = append(pooleds, struct {
PooledAmount decimal.Decimal
@ -219,7 +225,6 @@ func CalculateTenementPoolings(report model.ReportIndex, summary calculate.Summa
consumptions = consumptions.Add(p.PooledAmount)
total = total.Add(p.ParentAmount)
}
// 计算并更新公摊分摊信息
for _, p := range pooleds {
poolingAmount := p.PooledAmount

View File

@ -27,9 +27,7 @@ func SaveSummary(tx pgx.Tx, summary calculate.Summary) error {
func SavePublics(tx pgx.Tx, report model.ReportIndex, meters MeterMap) error {
ctx, cancel := global.TimeoutContext()
defer cancel()
var filteredMeters []calculate.Meter
for _, m := range meters {
if m.Detail.MeterType == model.METER_INSTALLATION_PARK {
filteredMeters = append(filteredMeters, m)

View File

@ -12,9 +12,9 @@ Server:
ReadTimeout: 60
WriteTimeout: 60
Redis:
Host: 127.0.0.1
Host: 192.168.88.129
Port: 6379
Password:
Password: 123456
DB: 1
Service:
MaxSessionLife: 2h