enhance(model):调整物业附加费、公示报表部分的数据结构模型,以及数据库迁移脚本。

This commit is contained in:
徐涛 2022-09-21 15:36:03 +08:00
parent fa61f83c6a
commit c716de21aa
12 changed files with 179 additions and 205 deletions

Binary file not shown.

View File

@ -190,6 +190,7 @@ func batchImport04kVMeterArchive(c *gin.Context) {
mergedMeters := lo.Map(records, func(meter model.Meter04KV, index int) model.Meter04KV {
meter.ParkId = requestParkId
meter.Enabled = true
meter.WillDilute = false
return meter
})
errs = service.Meter04kVService.DuplicateMeterCodeValidate(mergedMeters)

View File

@ -14,7 +14,6 @@ var meter04kVExcelRecognizers = []*ColumnRecognizer{
{Pattern: []string{"倍率"}, Tag: "ratio", MatchIndex: -1, MustFill: true},
{Pattern: []string{"序号"}, Tag: "seq", MatchIndex: -1, MustFill: true},
{Pattern: []string{"公用设备"}, Tag: "public", MatchIndex: -1, MustFill: true},
{Pattern: []string{"摊薄"}, Tag: "dilute", MatchIndex: -1, MustFill: true},
}
func NewMeterArchiveExcelAnalyzer(file io.Reader) (*ExcelAnalyzer[model.Meter04KV], error) {

View File

@ -0,0 +1,15 @@
alter table meter_04kv
add column dilute boolean not null default false;
alter table end_user_detail
add column dilute boolean not null default false,
add column maintenance_fee_diluted numeric(18,8),
add column public_consumption_diluted numeric(18,8);
alter table maintenance_fee
drop column period;
alter table report_summary
drop column authorize_loss,
drop column authorize_loss_fee,
drop column authorize_loss_proportion;

View File

@ -0,0 +1,37 @@
alter table meter_04kv
drop column dilute;
alter table end_user_detail
drop column dilute,
drop column maintenance_fee_diluted,
drop column public_consumption_diluted;
alter table maintenance_fee
add column period varchar(10) not null;
alter table report_summary
drop column customer_consumption,
drop column customer_consumption_fee,
drop column customer_consumption_critical,
drop column customer_consumption_critical_fee,
drop column customer_consumption_peak,
drop column customer_consumption_peak_fee,
drop column customer_consumption_flat,
drop column customer_consumption_flat_fee,
drop column customer_consumption_valley,
drop column customer_consumption_valley_fee,
drop column public_consumption,
drop column public_consumption_fee,
drop column public_consumption_critical,
drop column public_consumption_critical_fee,
drop column public_consumption_peak,
drop column public_consumption_peak_fee,
drop column public_consumption_flat,
drop column public_consumption_flat_fee,
drop column public_consumption_valley,
drop column public_consumption_valley_fee,
drop column public_consumption_proportion,
drop column diluteds,
add column authorize_loss numeric(14,2),
add column authorize_loss_fee numeric(16,2),
add column authorize_loss_proportion numeric(16,15);

View File

@ -10,55 +10,52 @@ import (
)
type EndUserDetail struct {
bun.BaseModel `bun:"table:end_user_detail,alias:eud"`
CreatedAndModified `bun:"extend"`
ReportId string `bun:",pk,notnull" json:"reportId"`
ParkId string `bun:",pk,notnull" json:"parkId"`
MeterId string `bun:"meter_04kv_id,pk,notnull" json:"meterId"`
Seq int64 `bun:"type:bigint,notnull" json:"seq"`
Ratio decimal.Decimal `bun:"type:numeric,notnull" json:"ratio"`
Address *string `json:"address"`
CustomerName *string `json:"customerName"`
ContactName *string `json:"contactName"`
ContactPhone *string `json:"contactPhone"`
IsPublicMeter bool `bun:"public_meter,notnull" json:"isPublicMeter"`
WillDilute bool `bun:"dilute,notnull" json:"willDilute"`
LastPeriodOverall decimal.Decimal `bun:"type:numeric,notnull" json:"lastPeriodOverall"`
LastPeriodCritical decimal.Decimal `bun:"type:numeric,notnull" json:"lastPeriodCritical"`
LastPeriodPeak decimal.Decimal `bun:"type:numeric,notnull" json:"lastPeriodPeak"`
LastPeriodFlat decimal.Decimal `bun:"type:numeric,notnull" json:"lastPeriodFlat"`
LastPeriodValley decimal.Decimal `bun:"type:numeric,notnull" json:"lastPeriodValley"`
CurrentPeriodOverall decimal.Decimal `bun:"type:numeric,notnull" json:"currentPeriodOverall"`
CurrentPeriodCritical decimal.Decimal `bun:"type:numeric,notnull" json:"currentPeriodCritical"`
CurrentPeriodPeak decimal.Decimal `bun:"type:numeric,notnull" json:"currentPeriodPeak"`
CurrentPeriodFlat decimal.Decimal `bun:"type:numeric,notnull" json:"currentPeriodFlat"`
CurrentPeriodValley decimal.Decimal `bun:"type:numeric,notnull" json:"currentPeriodValley"`
AdjustOverall decimal.Decimal `bun:"type:numeric,notnull" json:"adjustOverall"`
AdjustCritical decimal.Decimal `bun:"type:numeric,notnull" json:"adjustCritical"`
AdjustPeak decimal.Decimal `bun:"type:numeric,notnull" json:"adjustPeak"`
AdjustFlat decimal.Decimal `bun:"type:numeric,notnull" json:"adjustFlat"`
AdjustValley decimal.Decimal `bun:"type:numeric,notnull" json:"adjustValley"`
Overall decimal.NullDecimal `bun:"type:numeric" json:"overall"`
OverallFee decimal.NullDecimal `bun:"type:numeric" json:"overallFee"`
OverallProportion decimal.Decimal `bun:"type:numeric,notnull" json:"-"`
Critical decimal.NullDecimal `bun:"type:numeric" json:"critical"`
CriticalFee decimal.NullDecimal `bun:"type:numeric" json:"criticalFee"`
Peak decimal.NullDecimal `bun:"type:numeric" json:"peak"`
PeakFee decimal.NullDecimal `bun:"type:numeric" json:"peakFee"`
Flat decimal.NullDecimal `bun:"type:numeric" json:"flat"`
FlatFee decimal.NullDecimal `bun:"type:numeric" json:"flatFee"`
Valley decimal.NullDecimal `bun:"type:numeric" json:"valley"`
ValleyFee decimal.NullDecimal `bun:"type:numeric" json:"valleyFee"`
BasicFeeDiluted decimal.NullDecimal `bun:"type:numeric" json:"basicFeeDiluted"`
AdjustFeeDiluted decimal.NullDecimal `bun:"type:numeric" json:"adjustFeeDiluted"`
LossDiluted decimal.NullDecimal `bun:"type:numeric" json:"lossDiluted"`
LossFeeDiluted decimal.NullDecimal `bun:"type:numeric" json:"lossFeeDiluted"`
MaintenanceFeeDiluted decimal.NullDecimal `bun:"type:numeric" json:"maintenanceFeeDiluted"`
PublicConsumptionDiluted decimal.NullDecimal `bun:"type:numeric" json:"publicConsumptionDiluted"`
FinalDiluted decimal.NullDecimal `bun:"type:numeric" json:"finalDiluted"`
FinalCharge decimal.NullDecimal `bun:"type:numeric" json:"finalCharge"`
Initialize bool `bun:"-" json:"-"`
Origin *Meter04KV `bun:"rel:belongs-to,join:park_id=park_id,join:meter_04kv_id=code" json:"-"`
bun.BaseModel `bun:"table:end_user_detail,alias:eud"`
CreatedAndModified `bun:"extend"`
ReportId string `bun:",pk,notnull" json:"reportId"`
ParkId string `bun:",pk,notnull" json:"parkId"`
MeterId string `bun:"meter_04kv_id,pk,notnull" json:"meterId"`
Seq int64 `bun:"type:bigint,notnull" json:"seq"`
Ratio decimal.Decimal `bun:"type:numeric,notnull" json:"ratio"`
Address *string `json:"address"`
CustomerName *string `json:"customerName"`
ContactName *string `json:"contactName"`
ContactPhone *string `json:"contactPhone"`
IsPublicMeter bool `bun:"public_meter,notnull" json:"isPublicMeter"`
LastPeriodOverall decimal.Decimal `bun:"type:numeric,notnull" json:"lastPeriodOverall"`
LastPeriodCritical decimal.Decimal `bun:"type:numeric,notnull" json:"lastPeriodCritical"`
LastPeriodPeak decimal.Decimal `bun:"type:numeric,notnull" json:"lastPeriodPeak"`
LastPeriodFlat decimal.Decimal `bun:"type:numeric,notnull" json:"lastPeriodFlat"`
LastPeriodValley decimal.Decimal `bun:"type:numeric,notnull" json:"lastPeriodValley"`
CurrentPeriodOverall decimal.Decimal `bun:"type:numeric,notnull" json:"currentPeriodOverall"`
CurrentPeriodCritical decimal.Decimal `bun:"type:numeric,notnull" json:"currentPeriodCritical"`
CurrentPeriodPeak decimal.Decimal `bun:"type:numeric,notnull" json:"currentPeriodPeak"`
CurrentPeriodFlat decimal.Decimal `bun:"type:numeric,notnull" json:"currentPeriodFlat"`
CurrentPeriodValley decimal.Decimal `bun:"type:numeric,notnull" json:"currentPeriodValley"`
AdjustOverall decimal.Decimal `bun:"type:numeric,notnull" json:"adjustOverall"`
AdjustCritical decimal.Decimal `bun:"type:numeric,notnull" json:"adjustCritical"`
AdjustPeak decimal.Decimal `bun:"type:numeric,notnull" json:"adjustPeak"`
AdjustFlat decimal.Decimal `bun:"type:numeric,notnull" json:"adjustFlat"`
AdjustValley decimal.Decimal `bun:"type:numeric,notnull" json:"adjustValley"`
Overall decimal.NullDecimal `bun:"type:numeric" json:"overall"`
OverallFee decimal.NullDecimal `bun:"type:numeric" json:"overallFee"`
OverallProportion decimal.Decimal `bun:"type:numeric,notnull" json:"-"`
Critical decimal.NullDecimal `bun:"type:numeric" json:"critical"`
CriticalFee decimal.NullDecimal `bun:"type:numeric" json:"criticalFee"`
Peak decimal.NullDecimal `bun:"type:numeric" json:"peak"`
PeakFee decimal.NullDecimal `bun:"type:numeric" json:"peakFee"`
Flat decimal.NullDecimal `bun:"type:numeric" json:"flat"`
FlatFee decimal.NullDecimal `bun:"type:numeric" json:"flatFee"`
Valley decimal.NullDecimal `bun:"type:numeric" json:"valley"`
ValleyFee decimal.NullDecimal `bun:"type:numeric" json:"valleyFee"`
BasicFeeDiluted decimal.NullDecimal `bun:"type:numeric" json:"basicFeeDiluted"`
AdjustFeeDiluted decimal.NullDecimal `bun:"type:numeric" json:"adjustFeeDiluted"`
LossDiluted decimal.NullDecimal `bun:"type:numeric" json:"lossDiluted"`
LossFeeDiluted decimal.NullDecimal `bun:"type:numeric" json:"lossFeeDiluted"`
FinalDiluted decimal.NullDecimal `bun:"type:numeric" json:"finalDiluted"`
FinalCharge decimal.NullDecimal `bun:"type:numeric" json:"finalCharge"`
Initialize bool `bun:"-" json:"-"`
Origin *Meter04KV `bun:"rel:belongs-to,join:park_id=park_id,join:meter_04kv_id=code" json:"-"`
}
var _ bun.BeforeAppendModelHook = (*EndUserDetail)(nil)

View File

@ -15,6 +15,7 @@ type MaintenanceFee struct {
Id string `bun:",pk,notnull" json:"id"`
ParkId string `bun:",notnull" json:"parkId"`
Name string `bun:",notnull" json:"name"`
Period string `bun:",notnull" json:"period"`
Fee decimal.Decimal `bun:"type:numeric,notnull" json:"fee"`
Memo *string `bun:"type:text" json:"memo"`
Enabled bool `bun:",notnull" json:"enabled"`

View File

@ -62,10 +62,12 @@ type ConsumptionOverallPart struct {
}
type LossPart struct {
Quantity decimal.Decimal `json:"quantity"`
Price decimal.Decimal `json:"price"`
ConsumptionFee decimal.Decimal `json:"consumptionFee"`
Proportion decimal.Decimal `json:"proportion"`
Quantity decimal.Decimal `json:"quantity"`
Price decimal.Decimal `json:"price"`
ConsumptionFee decimal.Decimal `json:"consumptionFee"`
Proportion decimal.Decimal `json:"proportion"`
AuthorizeQuantity decimal.Decimal `json:"authorizeQuantity"`
AuthorizeConsumptionFee decimal.Decimal `json:"authorizeConsumptionFee"`
}
type OtherShouldCollectionPart struct {
@ -89,8 +91,8 @@ type EndUserSummary struct {
Address *string `json:"address"`
MeterId string `json:"meterId"`
IsPublicMeter bool `json:"isPublicMeter"`
Diluted bool `json:"willDilute"`
Overall decimal.Decimal `json:"overall"`
OverallPrice decimal.Decimal `json:"overallPrice"`
OverallFee decimal.Decimal `json:"overallFee"`
Critical decimal.NullDecimal `json:"critical"`
CriticalFee decimal.NullDecimal `json:"criticalFee"`
@ -98,19 +100,19 @@ type EndUserSummary struct {
PeakFee decimal.NullDecimal `json:"peakFee"`
Valley decimal.NullDecimal `json:"valley"`
ValleyFee decimal.NullDecimal `json:"valleyFee"`
Maintenance decimal.Decimal `json:"maintenance"`
Loss decimal.Decimal `json:"loss"`
LossFee decimal.Decimal `json:"lossFee"`
}
type Publicity struct {
Report Report `json:"index"`
User UserDetail `json:"enterprise"`
Park Park `json:"park"`
Paid PaidPart `json:"paid"`
EndUser ConsumptionOverallPart `json:"endUserSum"`
Loss LossPart `json:"loss"`
DilutedConsumptionOverall ConsumptionOverallPart `json:"diluted"`
PublicConsumptionOverall ConsumptionOverallPart `json:"public"`
OtherCollections OtherShouldCollectionPart `json:"others"`
Maintenance MaintenancePart `json:"maintenance"`
EndUserDetails []EndUserSummary `json:"endUser"`
Report Report `json:"index"`
User UserDetail `json:"enterprise"`
Park Park `json:"park"`
Paid PaidPart `json:"paid"`
EndUser ConsumptionOverallPart `json:"endUserSum"`
Loss LossPart `json:"loss"`
PublicConsumptionOverall ConsumptionOverallPart `json:"public"`
OtherCollections OtherShouldCollectionPart `json:"others"`
Maintenance MaintenancePart `json:"maintenance"`
EndUserDetails []EndUserSummary `json:"endUser"`
}

View File

@ -29,6 +29,9 @@ type ReportSummary struct {
Loss decimal.NullDecimal `bun:"type:numeric" json:"loss"`
LossFee decimal.NullDecimal `bun:"type:numeric" json:"lossFee"`
LossProportion decimal.NullDecimal `bun:"type:numeric" json:"lossProportion"`
AuthorizeLoss decimal.NullDecimal `bun:"type:numeric" json:"authorizeLoss"`
AuthorizeLossFee decimal.NullDecimal `bun:"type:numeric" json:"authorizeLossFee"`
AuthorizeLossProportion decimal.NullDecimal `bun:"type:numeric" json:"authorizeLossProportion"`
BasicFee decimal.Decimal `bun:"type:numeric,notnull" json:"basicFee"`
BasicDilutedPrice decimal.NullDecimal `bun:"type:numeric" json:"basicDilutedPrice"`
AdjustFee decimal.Decimal `bun:"type:numeric,notnull" json:"adjustFee"`
@ -40,7 +43,6 @@ type ReportSummary struct {
FinalDilutedOverall decimal.NullDecimal `bun:"type:numeric" json:"finalDilutedOverall"`
Customers Consumptions `bun:"type:jsonb" json:"customers"`
Publics Consumptions `bun:"type:jsonb" json:"publics"`
Diluteds Consumptions `bun:"type:jsonb" json:"diluteds"`
}
type Consumptions struct {

View File

@ -43,7 +43,6 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er
// 计算终端用户信息与概览中的合计
report.Summary.Customers = model.NewConsumptions()
report.Summary.Publics = model.NewConsumptions()
report.Summary.Diluteds = model.NewConsumptions()
for _, eu := range report.EndUsers {
eu.OverallFee = decimal.NewNullDecimal(
eu.Overall.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2),
@ -66,13 +65,6 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er
report.Summary.Publics.Peak.Decimal = report.Summary.Publics.Peak.Decimal.Add(eu.Peak.Decimal)
report.Summary.Publics.Flat.Decimal = report.Summary.Publics.Flat.Decimal.Add(eu.Flat.Decimal)
report.Summary.Publics.Valley.Decimal = report.Summary.Publics.Valley.Decimal.Add(eu.Valley.Decimal)
if eu.WillDilute {
report.Summary.Diluteds.Consumption.Decimal = report.Summary.Diluteds.Consumption.Decimal.Add(eu.Overall.Decimal)
report.Summary.Diluteds.Critical.Decimal = report.Summary.Diluteds.Critical.Decimal.Add(eu.Critical.Decimal)
report.Summary.Diluteds.Peak.Decimal = report.Summary.Diluteds.Peak.Decimal.Add(eu.Peak.Decimal)
report.Summary.Diluteds.Flat.Decimal = report.Summary.Diluteds.Flat.Decimal.Add(eu.Flat.Decimal)
report.Summary.Diluteds.Valley.Decimal = report.Summary.Diluteds.Valley.Decimal.Add(eu.Valley.Decimal)
}
} else {
report.Summary.Customers.Consumption.Decimal = report.Summary.Customers.Consumption.Decimal.Add(eu.Overall.Decimal)
report.Summary.Customers.Critical.Decimal = report.Summary.Customers.Critical.Decimal.Add(eu.Critical.Decimal)
@ -116,22 +108,6 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er
report.Summary.Publics.ValleyFee = decimal.NewNullDecimal(
report.Summary.Publics.Valley.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2),
)
// 计算摊薄总计部分
report.Summary.Diluteds.ConsumptionFee = decimal.NewNullDecimal(
report.Summary.Diluteds.Consumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2),
)
report.Summary.Diluteds.CriticalFee = decimal.NewNullDecimal(
report.Summary.Diluteds.Critical.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2),
)
report.Summary.Diluteds.PeakFee = decimal.NewNullDecimal(
report.Summary.Diluteds.Peak.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2),
)
report.Summary.Diluteds.FlatFee = decimal.NewNullDecimal(
report.Summary.Diluteds.Flat.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2),
)
report.Summary.Diluteds.ValleyFee = decimal.NewNullDecimal(
report.Summary.Diluteds.Valley.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2),
)
}
if report.SubmeterType == model.CUSTOMER_METER_PV {
// 计算终端用户部分
@ -166,22 +142,6 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er
report.Summary.Publics.ValleyFee = decimal.NewNullDecimal(
report.Summary.Publics.Valley.Decimal.Mul(report.Summary.ValleyPrice.Decimal).RoundBank(2),
)
// 计算摊薄部分
report.Summary.Diluteds.ConsumptionFee = decimal.NewNullDecimal(
report.Summary.Diluteds.Consumption.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(2),
)
report.Summary.Diluteds.CriticalFee = decimal.NewNullDecimal(
report.Summary.Diluteds.Critical.Decimal.Mul(report.Summary.CriticalPrice.Decimal).RoundBank(2),
)
report.Summary.Diluteds.PeakFee = decimal.NewNullDecimal(
report.Summary.Diluteds.Peak.Decimal.Mul(report.Summary.PeakPrice.Decimal).RoundBank(2),
)
report.Summary.Diluteds.FlatFee = decimal.NewNullDecimal(
report.Summary.Diluteds.Flat.Decimal.Mul(report.Summary.FlatPrice.Decimal).RoundBank(2),
)
report.Summary.Diluteds.ValleyFee = decimal.NewNullDecimal(
report.Summary.Diluteds.Valley.Decimal.Mul(report.Summary.ValleyPrice.Decimal).RoundBank(2),
)
}
if report.Summary.Overall.Abs().GreaterThan(decimal.Zero) {
report.Summary.Customers.Proportion = decimal.NewNullDecimal(
@ -190,9 +150,6 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er
report.Summary.Publics.Proportion = decimal.NewNullDecimal(
report.Summary.Publics.Consumption.Decimal.Div(report.Summary.Overall).RoundBank(15),
)
report.Summary.Diluteds.Proportion = decimal.NewNullDecimal(
report.Summary.Diluteds.Consumption.Decimal.Div(report.Summary.Overall).RoundBank(15),
)
}
// 计算线损
@ -206,10 +163,21 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er
report.Summary.LossProportion = decimal.NewNullDecimal(
report.Summary.Loss.Decimal.Div(report.Summary.Overall).RoundBank(15),
)
if report.Summary.LossProportion.Decimal.GreaterThan(decimal.NewFromFloat(0.1)) {
report.Summary.AuthorizeLoss = decimal.NewNullDecimal(
report.Summary.Overall.Mul(decimal.NewFromFloat(0.1)).RoundBank(8),
)
report.Summary.AuthorizeLossFee = decimal.NewNullDecimal(
report.Summary.AuthorizeLoss.Decimal.Mul(report.Summary.OverallPrice.Decimal).RoundBank(8),
)
} else {
report.Summary.AuthorizeLoss = report.Summary.Loss
report.Summary.AuthorizeLossFee = report.Summary.LossFee
}
}
if report.Summary.Customers.Consumption.Decimal.Abs().GreaterThan(decimal.Zero) {
report.Summary.LossDilutedPrice = decimal.NewNullDecimal(
report.Summary.LossFee.Decimal.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(8),
report.Summary.AuthorizeLossFee.Decimal.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(8),
)
}
@ -224,11 +192,6 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er
report.Summary.MaintenanceDilutedPrice = decimal.NewNullDecimal(
maintenanceFeeTotal.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(8),
)
// ! 这里需要注意的是在原始设计中PublicConsumptionDilutedPrice就是表示公共摊薄价格
// ! 而不是所有公共设施合计数据所以要使用Diluteds部分数据。
report.Summary.PublicConsumptionDilutedPrice = decimal.NewNullDecimal(
report.Summary.Diluteds.ConsumptionFee.Decimal.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(8),
)
}
// 计算摊薄总计
@ -236,57 +199,38 @@ func (_CalculateService) ComprehensivelyCalculateReport(reportId string) (err er
report.Summary.FinalDilutedOverall = decimal.NewNullDecimal(
report.Summary.BasicFee.
Add(report.Summary.AdjustFee).
Add(report.Summary.Diluteds.ConsumptionFee.Decimal).
Add(maintenanceFeeTotal).
Add(report.Summary.LossFee.Decimal),
Add(report.Summary.AuthorizeLossFee.Decimal),
)
// 计算终端用户的全部摊薄内容
for _, eu := range report.EndUsers {
if eu.IsPublicMeter && eu.WillDilute {
// 计算需要摊薄的公共表计的摊薄内容
if report.Summary.Diluteds.Consumption.Decimal.Abs().GreaterThan(decimal.Zero) {
eu.OverallProportion = eu.Overall.Decimal.Div(report.Summary.Diluteds.Consumption.Decimal).RoundBank(15)
} else {
eu.OverallProportion = decimal.Zero
}
// 计算户表表计的摊薄内容
if report.Summary.Customers.Consumption.Decimal.Abs().GreaterThan(decimal.Zero) {
eu.OverallProportion = eu.Overall.Decimal.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(15)
} else {
// 计算户表表计的摊薄内容
if report.Summary.Customers.Consumption.Decimal.Abs().GreaterThan(decimal.Zero) {
eu.OverallProportion = eu.Overall.Decimal.Div(report.Summary.Customers.Consumption.Decimal).RoundBank(15)
} else {
eu.OverallProportion = decimal.Zero
}
eu.BasicFeeDiluted = decimal.NewNullDecimal(
eu.Overall.Decimal.Mul(report.Summary.BasicDilutedPrice.Decimal).RoundBank(2),
)
eu.AdjustFeeDiluted = decimal.NewNullDecimal(
eu.Overall.Decimal.Mul(report.Summary.AdjustDilutedPrice.Decimal).RoundBank(2),
)
eu.LossDiluted = decimal.NewNullDecimal(
report.Summary.Loss.Decimal.Mul(eu.OverallProportion).RoundBank(8),
)
eu.LossFeeDiluted = decimal.NewNullDecimal(
eu.Overall.Decimal.Mul(report.Summary.LossDilutedPrice.Decimal).RoundBank(8),
)
eu.MaintenanceFeeDiluted = decimal.NewNullDecimal(
eu.Overall.Decimal.Mul(report.Summary.MaintenanceDilutedPrice.Decimal).RoundBank(8),
)
eu.PublicConsumptionDiluted = decimal.NewNullDecimal(
eu.Overall.Decimal.Mul(report.Summary.PublicConsumptionDilutedPrice.Decimal).RoundBank(8),
)
eu.FinalDiluted = decimal.NewNullDecimal(
eu.BasicFeeDiluted.Decimal.
Add(eu.AdjustFeeDiluted.Decimal).
Add(eu.LossFeeDiluted.Decimal).
Add(eu.MaintenanceFeeDiluted.Decimal).
Add(eu.PublicConsumptionDiluted.Decimal).
RoundBank(2),
)
eu.FinalCharge = decimal.NewNullDecimal(
eu.OverallFee.Decimal.Add(eu.FinalDiluted.Decimal).RoundBank(2),
)
eu.OverallProportion = decimal.Zero
}
eu.BasicFeeDiluted = decimal.NewNullDecimal(
eu.Overall.Decimal.Mul(report.Summary.BasicDilutedPrice.Decimal).RoundBank(2),
)
eu.AdjustFeeDiluted = decimal.NewNullDecimal(
eu.Overall.Decimal.Mul(report.Summary.AdjustDilutedPrice.Decimal).RoundBank(2),
)
eu.LossDiluted = decimal.NewNullDecimal(
report.Summary.AuthorizeLoss.Decimal.Mul(eu.OverallProportion).RoundBank(8),
)
eu.LossFeeDiluted = decimal.NewNullDecimal(
eu.Overall.Decimal.Mul(report.Summary.LossDilutedPrice.Decimal).RoundBank(8),
)
eu.FinalDiluted = decimal.NewNullDecimal(
eu.BasicFeeDiluted.Decimal.
Add(eu.AdjustFeeDiluted.Decimal).
Add(eu.LossFeeDiluted.Decimal).
RoundBank(2),
)
eu.FinalCharge = decimal.NewNullDecimal(
eu.OverallFee.Decimal.Add(eu.FinalDiluted.Decimal).RoundBank(2),
)
}
// 向数据库保存报表概况以及终端用户摊薄结果

View File

@ -158,12 +158,8 @@ func (g _GodModeService) resetSingleEndUserRecord(tx *bun.Tx, ctx *context.Conte
record.LossDiluted.Valid = false
record.LossFeeDiluted = decimal.NewNullDecimal(decimal.Zero)
record.LossFeeDiluted.Valid = false
record.MaintenanceFeeDiluted = decimal.NewNullDecimal(decimal.Zero)
record.MaintenanceFeeDiluted.Valid = false
record.FinalDiluted = decimal.NewNullDecimal(decimal.Zero)
record.FinalDiluted.Valid = false
record.PublicConsumptionDiluted = decimal.NewNullDecimal(decimal.Zero)
record.PublicConsumptionDiluted.Valid = false
record.FinalCharge = decimal.NewNullDecimal(decimal.Zero)
record.FinalCharge.Valid = false
@ -250,7 +246,6 @@ func (g _GodModeService) resynchronizeEndUserArchives(tx *bun.Tx, ctx *context.C
record.ContactPhone = meter.ContactPhone
record.Seq = meter.Seq
record.IsPublicMeter = meter.IsPublicMeter
record.WillDilute = meter.WillDilute
success, err := g.resetSingleEndUserRecord(
tx, ctx, *record,
"customer_name",
@ -277,7 +272,6 @@ func (g _GodModeService) resynchronizeEndUserArchives(tx *bun.Tx, ctx *context.C
ContactName: meter.ContactName,
ContactPhone: meter.ContactPhone,
IsPublicMeter: meter.IsPublicMeter,
WillDilute: meter.WillDilute,
LastPeriodOverall: decimal.Zero,
LastPeriodCritical: decimal.Zero,
LastPeriodPeak: decimal.Zero,

View File

@ -240,7 +240,6 @@ func (_ReportService) InitializeNewReport(parkId string, period time.Time) (stri
ContactName: customer.ContactName,
ContactPhone: customer.ContactPhone,
IsPublicMeter: customer.IsPublicMeter,
WillDilute: customer.WillDilute,
LastPeriodOverall: decimal.Zero,
LastPeriodCritical: decimal.Zero,
LastPeriodPeak: decimal.Zero,
@ -652,10 +651,12 @@ func (_ReportService) AssembleReportPublicity(reportId string) (*model.Publicity
Proportion: report.Summary.Customers.Proportion.Decimal,
}
lossPart := model.LossPart{
Quantity: report.Summary.Loss.Decimal,
Price: report.Summary.OverallPrice.Decimal,
ConsumptionFee: report.Summary.LossFee.Decimal,
Proportion: report.Summary.LossProportion.Decimal,
Quantity: report.Summary.Loss.Decimal,
Price: report.Summary.OverallPrice.Decimal,
ConsumptionFee: report.Summary.LossFee.Decimal,
Proportion: report.Summary.LossProportion.Decimal,
AuthorizeQuantity: report.Summary.AuthorizeLoss.Decimal,
AuthorizeConsumptionFee: report.Summary.AuthorizeLossFee.Decimal,
}
publicSummary := model.ConsumptionOverallPart{
Overall: report.Summary.Publics.Consumption.Decimal,
@ -676,25 +677,6 @@ func (_ReportService) AssembleReportPublicity(reportId string) (*model.Publicity
ValleyFee: report.Summary.Publics.ValleyFee,
Proportion: report.Summary.Publics.Proportion.Decimal,
}
dilutedSummary := model.ConsumptionOverallPart{
Overall: report.Summary.Diluteds.Consumption.Decimal,
OverallPrice: report.Summary.OverallPrice.Decimal,
ConsumptionFee: report.Summary.Diluteds.ConsumptionFee.Decimal,
OverallFee: report.Summary.Diluteds.ConsumptionFee.Decimal,
Critical: report.Summary.Diluteds.Critical,
CriticalPrice: report.Summary.CriticalPrice,
CriticalFee: report.Summary.Diluteds.CriticalFee,
Peak: report.Summary.Diluteds.Peak,
PeakPrice: report.Summary.PeakPrice,
PeakFee: report.Summary.Diluteds.PeakFee,
Flat: report.Summary.Diluteds.Flat,
FlatPrice: report.Summary.FlatPrice,
FlatFee: report.Summary.Diluteds.FlatFee,
Valley: report.Summary.Diluteds.Valley,
ValleyPrice: report.Summary.ValleyPrice,
ValleyFee: report.Summary.Diluteds.ValleyFee,
Proportion: report.Summary.Diluteds.Proportion.Decimal,
}
otherCollection := model.OtherShouldCollectionPart{
MaintenanceFee: report.Summary.MaintenanceOverall,
BasicFees: report.Summary.BasicFee.Add(report.Summary.AdjustFee),
@ -730,8 +712,8 @@ func (_ReportService) AssembleReportPublicity(reportId string) (*model.Publicity
Address: elem.Address,
MeterId: elem.MeterId,
IsPublicMeter: elem.IsPublicMeter,
Diluted: elem.WillDilute,
Overall: elem.Overall.Decimal,
OverallPrice: report.Summary.OverallPrice.Decimal,
OverallFee: elem.OverallFee.Decimal,
Critical: elem.Critical,
CriticalFee: elem.CriticalFee,
@ -739,23 +721,23 @@ func (_ReportService) AssembleReportPublicity(reportId string) (*model.Publicity
PeakFee: elem.PeakFee,
Valley: elem.Valley,
ValleyFee: elem.ValleyFee,
Maintenance: elem.FinalDiluted.Decimal,
Loss: elem.LossDiluted.Decimal,
LossFee: elem.LossFeeDiluted.Decimal,
}
},
)
publicity := &model.Publicity{
Report: *report,
Park: *report.Park,
User: *report.Park.Enterprise,
Paid: paidPart,
EndUser: endUserSummary,
Loss: lossPart,
PublicConsumptionOverall: publicSummary,
DilutedConsumptionOverall: dilutedSummary,
OtherCollections: otherCollection,
Maintenance: maintenanceFees,
EndUserDetails: endUsers,
Report: *report,
Park: *report.Park,
User: *report.Park.Enterprise,
Paid: paidPart,
EndUser: endUserSummary,
Loss: lossPart,
PublicConsumptionOverall: publicSummary,
OtherCollections: otherCollection,
Maintenance: maintenanceFees,
EndUserDetails: endUsers,
}
cache.CacheEntity(publicity, []string{fmt.Sprintf("publicity:%s", reportId), fmt.Sprintf("report:%s", reportId), "report", "park"}, "publicity", reportId)