fix(report):基本完成报表部分的查询调整。

This commit is contained in:
徐涛
2022-09-19 14:27:25 +08:00
parent 3742a445b7
commit 0355300908
10 changed files with 104 additions and 76 deletions

View File

@@ -15,32 +15,32 @@ type EndUserDetail struct {
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,default:0" json:"seq"`
Ratio decimal.Decimal `bun:",notnull,default:1" json:"ratio"`
Seq int64 `bun:"type:bigint,notnull" json:"seq"`
Ratio decimal.Decimal `bun:",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,default:false" json:"isPublicMeter"`
WillDilute bool `bun:"dilute,notnull,default:false" json:"willDilute"`
LastPeriodOverall decimal.Decimal `bun:",notnull,default:0" json:"lastPeriodOverall"`
LastPeriodCritical decimal.Decimal `bun:",notnull,default:0" json:"lastPeriodCritical"`
LastPeriodPeak decimal.Decimal `bun:",notnull,default:0" json:"lastPeriodPeak"`
LastPeriodFlat decimal.Decimal `bun:",notnull,default:0" json:"lastPeriodFlat"`
LastPeriodValley decimal.Decimal `bun:",notnull,default:0" json:"lastPeriodValley"`
CurrentPeriodOverall decimal.Decimal `bun:",notnull,default:0" json:"currentPeriodOverall"`
CurrentPeriodCritical decimal.Decimal `bun:",notnull,default:0" json:"currentPeriodCritical"`
CurrentPeriodPeak decimal.Decimal `bun:",notnull,default:0" json:"currentPeriodPeak"`
CurrentPeriodFlat decimal.Decimal `bun:",notnull,default:0" json:"currentPeriodFlat"`
CurrentPeriodValley decimal.Decimal `bun:",notnull,default:0" json:"currentPeriodValley"`
AdjustOverall decimal.Decimal `bun:",notnull,default:0" json:"adjustOverall"`
AdjustCritical decimal.Decimal `bun:",notnull,default:0" json:"adjustCritical"`
AdjustPeak decimal.Decimal `bun:",notnull,default:0" json:"adjustPeak"`
AdjustFlat decimal.Decimal `bun:",notnull,default:0" json:"adjustFlat"`
AdjustValley decimal.Decimal `bun:",notnull,default:0" json:"adjustValley"`
IsPublicMeter bool `bun:"public_meter,notnull" json:"isPublicMeter"`
WillDilute bool `bun:"dilute,notnull" json:"willDilute"`
LastPeriodOverall decimal.Decimal `bun:",notnull" json:"lastPeriodOverall"`
LastPeriodCritical decimal.Decimal `bun:",notnull" json:"lastPeriodCritical"`
LastPeriodPeak decimal.Decimal `bun:",notnull" json:"lastPeriodPeak"`
LastPeriodFlat decimal.Decimal `bun:",notnull" json:"lastPeriodFlat"`
LastPeriodValley decimal.Decimal `bun:",notnull" json:"lastPeriodValley"`
CurrentPeriodOverall decimal.Decimal `bun:",notnull" json:"currentPeriodOverall"`
CurrentPeriodCritical decimal.Decimal `bun:",notnull" json:"currentPeriodCritical"`
CurrentPeriodPeak decimal.Decimal `bun:",notnull" json:"currentPeriodPeak"`
CurrentPeriodFlat decimal.Decimal `bun:",notnull" json:"currentPeriodFlat"`
CurrentPeriodValley decimal.Decimal `bun:",notnull" json:"currentPeriodValley"`
AdjustOverall decimal.Decimal `bun:",notnull" json:"adjustOverall"`
AdjustCritical decimal.Decimal `bun:",notnull" json:"adjustCritical"`
AdjustPeak decimal.Decimal `bun:",notnull" json:"adjustPeak"`
AdjustFlat decimal.Decimal `bun:",notnull" json:"adjustFlat"`
AdjustValley decimal.Decimal `bun:",notnull" json:"adjustValley"`
Overall decimal.NullDecimal `json:"overall"`
OverallFee decimal.NullDecimal `json:"overallFee"`
OverallProportion decimal.Decimal `bun:",notnull,default:0" json:"-"`
OverallProportion decimal.Decimal `bun:",notnull" json:"-"`
Critical decimal.NullDecimal `json:"critical"`
CriticalFee decimal.NullDecimal `json:"criticalFee"`
Peak decimal.NullDecimal `json:"peak"`
@@ -58,7 +58,7 @@ type EndUserDetail struct {
FinalDiluted decimal.NullDecimal `json:"finalDiluted"`
FinalCharge decimal.NullDecimal `json:"finalCharge"`
Initialize bool `bun:"-" json:"-"`
Origin *Meter04KV `bun:"rel:belongs-to,join:park_id=park_id,join:meter_04kv_id=code"`
Origin *Meter04KV `bun:"rel:belongs-to,join:park_id=park_id,join:meter_04kv_id=code" json:"-"`
}
var _ bun.BeforeAppendModelHook = (*EndUserDetail)(nil)

View File

@@ -17,7 +17,7 @@ type Meter04KV struct {
CustomerName *string `json:"customerName" excel:"name"`
ContactName *string `json:"contactName" excel:"contact"`
ContactPhone *string `json:"contactPhone" excel:"phone"`
Ratio decimal.Decimal `bun:",notnull,default:1" json:"ratio" excel:"ratio"`
Ratio decimal.Decimal `bun:",notnull" json:"ratio" excel:"ratio"`
Seq int64 `bun:"type:bigint,notnull" json:"seq" excel:"seq"`
IsPublicMeter bool `bun:"public_meter,notnull" json:"isPublicMeter" excel:"public"`
WillDilute bool `bun:"dilute,notnull" json:"willDilute" excel:"dilute"`

View File

@@ -42,6 +42,7 @@ type Park struct {
Enterprise *UserDetail `bun:"rel:belongs-to,join:user_id=id" json:"-"`
MaintenanceFees []*MaintenanceFee `bun:"rel:has-many,join:id=park_id" json:"-"`
Meters []*Meter04KV `bun:"rel:has-many,join:id=park_id" json:"-"`
Reports []*Report `bun:"rel:has-many,join:id=park_id" json:"-"`
}
type ParkSimplified struct {

View File

@@ -6,6 +6,6 @@ type Region struct {
bun.BaseModel `bun:"table:region,alias:r"`
Code string `bun:",pk,notnull" json:"code"`
Name string `bun:",notnull" json:"name"`
Level int `bun:",notnull,default:0" json:"level"`
Parent string `bun:",notnull,default:'0'" json:"parent"`
Level int `bun:",notnull" json:"level"`
Parent string `bun:",notnull" json:"parent"`
}

View File

@@ -20,12 +20,12 @@ type Report struct {
Id string `bun:",pk,notnull" json:"id"`
ParkId string `bun:",notnull" json:"parkId"`
Period time.Time `bun:"type:date,notnull" json:"period" time_format:"simple_date" time_location:"shanghai"`
Category int8 `bun:"type:smallint,notnull,default:0" json:"category"`
SubmeterType int8 `bun:"meter_04kv_type,type:smallint,notnull,default:0" json:"meter04kvType"`
Category int8 `bun:"type:smallint,notnull" json:"category"`
SubmeterType int8 `bun:"meter_04kv_type,type:smallint,notnull" json:"meter04kvType"`
StepState Steps `bun:"type:jsonb,notnull" json:"stepState"`
Published bool `bun:",notnull,default:false" json:"published"`
Published bool `bun:",notnull" json:"published"`
PublishedAt *time.Time `bun:"type:timestamptz,nullzero" json:"publishedAt" time_format:"simple_datetime" time_location:"shanghai"`
Withdraw int8 `bun:"type:smallint,notnull,default:0" json:"withdraw"`
Withdraw int8 `bun:"type:smallint,notnull" json:"withdraw"`
LastWithdrawAppliedAt *time.Time `bun:"type:timestamptz,nullzero" json:"lastWithdrawAppliedAt" time_format:"simple_datetime" time_location:"shanghai"`
LastWithdrawAuditAt *time.Time `bun:"type:timestamptz,nullzero" json:"lastWithdrawAuditAt" time_format:"simple_datetime" time_location:"shanghai"`
Park *Park `bun:"rel:belongs-to,join:park_id=id" json:"-"`
@@ -71,9 +71,9 @@ type ReportIndexSimplified struct {
ParkId string `bun:",notnull" json:"parkId"`
Period Date `bun:"type:date,notnull" json:"period"`
StepState Steps `bun:"type:jsonb,notnull" json:"stepState"`
Published bool `bun:",notnull,default:false" json:"published"`
Published bool `bun:",notnull" json:"published"`
PublishedAt *time.Time `bun:"type:timestampz" json:"publishedAt" time_format:"simple_datetime" time_location:"shanghai"`
Withdraw int8 `bun:"type:smallint,notnull,default:0" json:"withdraw"`
Withdraw int8 `bun:"type:smallint,notnull" json:"withdraw"`
LastWithdrawAppliedAt *time.Time `bun:"type:timestamptz" json:"lastWithdrawAppliedAt" time_format:"simple_datetime" time_location:"shanghai"`
LastWithdrawAuditAt *time.Time `bun:"type:timestamptz" json:"lastWithdrawAuditAt" time_format:"simple_datetime" time_location:"shanghai"`
}

View File

@@ -10,21 +10,21 @@ import (
type ReportSummary struct {
bun.BaseModel `bun:"table:report_summary,alias:rs"`
ReportId string `bun:",pk,notnull" json:"-"`
Overall decimal.Decimal `bun:",notnull,default:0" json:"overall"`
OverallFee decimal.Decimal `bun:",notnull,default:0" json:"overallFee"`
Overall decimal.Decimal `bun:",notnull" json:"overall"`
OverallFee decimal.Decimal `bun:",notnull" json:"overallFee"`
ConsumptionFee decimal.NullDecimal `json:"consumptionFee"`
OverallPrice decimal.NullDecimal `json:"overallPrice"`
Critical decimal.Decimal `bun:",notnull,default:0" json:"critical"`
CriticalFee decimal.Decimal `bun:",notnull,default:0" json:"criticalFee"`
Critical decimal.Decimal `bun:",notnull" json:"critical"`
CriticalFee decimal.Decimal `bun:",notnull" json:"criticalFee"`
CriticalPrice decimal.NullDecimal `json:"criticalPrice"`
Peak decimal.Decimal `bun:",notnull,default:0" json:"peak"`
PeakFee decimal.Decimal `bun:",notnull,default:0" json:"peakFee"`
Peak decimal.Decimal `bun:",notnull" json:"peak"`
PeakFee decimal.Decimal `bun:",notnull" json:"peakFee"`
PeakPrice decimal.NullDecimal `json:"peakPrice"`
Flat decimal.Decimal `bun:",notnull,default:0" json:"flat"`
FlatFee decimal.Decimal `bun:",notnull,default:0" json:"flatFee"`
Flat decimal.Decimal `bun:",notnull" json:"flat"`
FlatFee decimal.Decimal `bun:",notnull" json:"flatFee"`
FlatPrice decimal.NullDecimal `json:"flatPrice"`
Valley decimal.Decimal `bun:",notnull,default:0" json:"valley"`
ValleyFee decimal.Decimal `bun:",notnull,default:0" json:"valleyFee"`
Valley decimal.Decimal `bun:",notnull" json:"valley"`
ValleyFee decimal.Decimal `bun:",notnull" json:"valleyFee"`
ValleyPrice decimal.NullDecimal `json:"valleyPrice"`
Loss decimal.NullDecimal `json:"loss"`
LossFee decimal.NullDecimal `json:"lossFee"`
@@ -50,9 +50,9 @@ type ReportSummary struct {
PublicConsumptionFlatFee decimal.NullDecimal `json:"publicConsumptionFlatFee"`
PublicConsumptionValley decimal.NullDecimal `json:"publicConsumptionValley"`
PublicConsumptionValleyFee decimal.NullDecimal `json:"publicConsumptionValleyFee"`
BasicFee decimal.Decimal `bun:",notnull,default:0" json:"basicFee"`
BasicFee decimal.Decimal `bun:",notnull" json:"basicFee"`
BasicDilutedPrice decimal.NullDecimal `json:"basicDilutedPrice"`
AdjustFee decimal.Decimal `bun:",notnull,default:0" json:"adjustFee"`
AdjustFee decimal.Decimal `bun:",notnull" json:"adjustFee"`
AdjustDilutedPrice decimal.NullDecimal `json:"adjustDilutedPrice"`
MaintenanceDilutedPrice decimal.NullDecimal `json:"maintencanceDilutedPrice"`
LossDilutedPrice decimal.NullDecimal `json:"lossDilutedPrice"`

View File

@@ -17,11 +17,11 @@ type UserCharge struct {
Discount decimal.NullDecimal `json:"discount"`
Amount decimal.NullDecimal `json:"amount"`
ChargeTo Date `bun:"type:date,notnull" json:"chargeTo"`
Settled bool `bun:",notnull,default:false" json:"settled"`
Settled bool `bun:",notnull" json:"settled"`
SettledAt *time.Time `bun:"type:timestamptz" json:"settledAt" time_format:"simple_datetime" time_location:"shanghai"`
Cancelled bool `bun:",notnull,default:false" json:"cancelled"`
Cancelled bool `bun:",notnull" json:"cancelled"`
CancelledAt *time.Time `bun:"type:timestamptz" json:"cancelledAt" time_format:"simple_datetime" time_location:"shanghai"`
Refunded bool `bun:",notnull,default:false" json:"refunded"`
Refunded bool `bun:",notnull" json:"refunded"`
RefundedAt *time.Time `bun:"type:timestamptz" json:"refundedAt" time_format:"simple_datetime" time_location:"shanghai"`
Detail *UserDetail `bun:"rel:belongs-to,join:user_id=id" json:"-"`
}

View File

@@ -1,6 +1,9 @@
package model
import (
"context"
"time"
"github.com/shopspring/decimal"
"github.com/uptrace/bun"
)
@@ -12,7 +15,21 @@ type WillDilutedFee struct {
ReportId string `bun:",notnull" json:"reportId"`
SourceId *string `json:"sourceId"`
Name string `bun:",notnull" json:"name"`
Fee decimal.Decimal `bun:",notnull,default:0" json:"fee"`
Fee decimal.Decimal `bun:",notnull" json:"fee"`
Memo *string `bun:"type:text" json:"memo"`
Origin *MaintenanceFee `bun:"rel:belongs-to,join:source_id=id"`
}
var _ bun.BeforeAppendModelHook = (*WillDilutedFee)(nil)
func (d *WillDilutedFee) BeforeAppendModel(ctx context.Context, query bun.Query) error {
oprTime := time.Now()
switch query.(type) {
case *bun.InsertQuery:
d.CreatedAt = oprTime
d.LastModifiedAt = &oprTime
case *bun.UpdateQuery:
d.LastModifiedAt = &oprTime
}
return nil
}