35 lines
913 B
Go
35 lines
913 B
Go
package calculate
|
|
|
|
import (
|
|
"electricity_bill_calc/model"
|
|
"fmt"
|
|
"github.com/shopspring/decimal"
|
|
"sync/atomic"
|
|
)
|
|
|
|
func CheckMeterArea(report *model.ReportIndex, meters []*model.MeterDetail) (bool, error) {
|
|
anyAreaOptions := report.BasisPooled == model.POOLING_MODE_AREA ||
|
|
report.AdjustPooled == model.POOLING_MODE_AREA ||
|
|
report.PublicPooled == model.POOLING_MODE_AREA ||
|
|
report.LossPooled == model.POOLING_MODE_AREA
|
|
|
|
if anyAreaOptions {
|
|
var meterWithoutArea int32
|
|
|
|
for _, m := range meters {
|
|
if (m.MeterType == model.METER_INSTALLATION_TENEMENT || m.MeterType == model.METER_INSTALLATION_POOLING) &&
|
|
m.Area.Decimal == decimal.Zero {
|
|
atomic.AddInt32(&meterWithoutArea, 1)
|
|
}
|
|
}
|
|
|
|
if meterWithoutArea != 0 {
|
|
return false, fmt.Errorf("园区中有 %d 个表计没有设置面积,无法进行按面积摊薄。", meterWithoutArea)
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
return false, nil
|
|
}
|