[计算相关]计算已经启用的商铺面积和(完成)
This commit is contained in:
parent
c916301f6b
commit
ce4c483bcb
10
service/calculate/meter.go
Normal file
10
service/calculate/meter.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package calculate
|
||||
|
||||
import "electricity_bill_calc/model/calculate"
|
||||
|
||||
// / 合并所有的表计
|
||||
type Key struct {
|
||||
Code string
|
||||
TenementID string
|
||||
}
|
||||
type MeterMap map[Key]calculate.Meter
|
|
@ -90,7 +90,8 @@ func LossCalculate(report *model.ReportIndex, Public *[]calculate.Meter,
|
|||
}
|
||||
|
||||
// 计算已经启用的商铺面积和
|
||||
func EnabledAreaCalculate(tenements *[]calculate.PrimaryTenementStatistics, summary *calculate.Summary) error {
|
||||
func EnabledAreaCalculate(tenements *[]calculate.PrimaryTenementStatistics,
|
||||
summary *calculate.Summary) error {
|
||||
var areaMeters []calculate.Meter
|
||||
for _, t := range *tenements {
|
||||
areaMeters = append(areaMeters, t.Meters...)
|
||||
|
@ -111,3 +112,23 @@ func EnabledAreaCalculate(tenements *[]calculate.PrimaryTenementStatistics, summ
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 计算基本电费分摊、调整电费分摊以及电费摊薄单价。
|
||||
func PricesCalculate(summary *calculate.Summary) error {
|
||||
if summary.TotalConsumption.IsZero() {
|
||||
return nil
|
||||
}
|
||||
summary.BasicPooledPriceConsumption = summary.BasicFee.Div(summary.TotalConsumption)
|
||||
if summary.OverallArea.IsZero() {
|
||||
summary.BasicPooledPriceArea = decimal.Zero
|
||||
} else {
|
||||
summary.BasicPooledPriceArea = summary.BasicFee.Div(summary.OverallArea)
|
||||
}
|
||||
summary.AdjustPooledPriceConsumption = summary.AdjustFee.Div(summary.TotalConsumption)
|
||||
if summary.OverallArea.IsZero() {
|
||||
summary.AdjustPooledPriceArea = decimal.Zero
|
||||
} else {
|
||||
summary.AdjustPooledPriceArea = summary.AdjustFee.Div(summary.OverallArea)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -7,6 +7,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"github.com/shopspring/decimal"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
@ -266,3 +267,30 @@ func ShiftToAsiaShanghai(t time.Time) time.Time {
|
|||
location, _ := time.LoadLocation("Asia/Shanghai")
|
||||
return t.In(location)
|
||||
}
|
||||
|
||||
// 计算各个商户的合计信息,并归总与商户关联的表计记录
|
||||
func TenementChargeCalculate(tenements []calculate.PrimaryTenementStatistics,
|
||||
summary calculate.Summary, meters MeterMap, _relations []model.MeterRelation) {
|
||||
result := make(map[string][]string)
|
||||
for _, t := range tenements {
|
||||
meterCodes := make([]string, 0)
|
||||
for _, m := range t.Meters {
|
||||
meterCodes = append(meterCodes, m.Code)
|
||||
}
|
||||
sort.Strings(meterCodes)
|
||||
result[t.Tenement.Id] = meterCodes
|
||||
}
|
||||
var Key Key
|
||||
for tCode, meterCodes := range result {
|
||||
relatedMeters := make([]calculate.Meter, 0)
|
||||
for _, code := range meterCodes {
|
||||
Key.Code = code + "_" + tCode
|
||||
meter, ok := meters[Key]
|
||||
if ok {
|
||||
relatedMeters = append(relatedMeters, meter)
|
||||
}
|
||||
}
|
||||
// 计算商户的合计电费信息
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,8 +74,13 @@ func MainCalculateProcess(rid string) {
|
|||
|
||||
// 计算所有已经启用的商铺面积总和,仅计算所有未迁出的商户的所有表计对应的商铺面积。
|
||||
err = EnabledAreaCalculate(&tenementReports, &summary)
|
||||
if err != nil{
|
||||
fmt.Println("10",err)
|
||||
if err != nil {
|
||||
fmt.Println("10", err)
|
||||
return
|
||||
}
|
||||
err = PricesCalculate(&summary)
|
||||
if err != nil {
|
||||
fmt.Println("11", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user