forked from free-lancers/electricity_bill_calc_service
		
	fix(report):基本完成报表部分的查询调整。
This commit is contained in:
		| @@ -15,32 +15,32 @@ type EndUserDetail struct { | |||||||
| 	ReportId                 string              `bun:",pk,notnull" json:"reportId"` | 	ReportId                 string              `bun:",pk,notnull" json:"reportId"` | ||||||
| 	ParkId                   string              `bun:",pk,notnull" json:"parkId"` | 	ParkId                   string              `bun:",pk,notnull" json:"parkId"` | ||||||
| 	MeterId                  string              `bun:"meter_04kv_id,pk,notnull" json:"meterId"` | 	MeterId                  string              `bun:"meter_04kv_id,pk,notnull" json:"meterId"` | ||||||
| 	Seq                      int64               `bun:"type:bigint,notnull,default:0" json:"seq"` | 	Seq                      int64               `bun:"type:bigint,notnull" json:"seq"` | ||||||
| 	Ratio                    decimal.Decimal     `bun:",notnull,default:1" json:"ratio"` | 	Ratio                    decimal.Decimal     `bun:",notnull" json:"ratio"` | ||||||
| 	Address                  *string             `json:"address"` | 	Address                  *string             `json:"address"` | ||||||
| 	CustomerName             *string             `json:"customerName"` | 	CustomerName             *string             `json:"customerName"` | ||||||
| 	ContactName              *string             `json:"contactName"` | 	ContactName              *string             `json:"contactName"` | ||||||
| 	ContactPhone             *string             `json:"contactPhone"` | 	ContactPhone             *string             `json:"contactPhone"` | ||||||
| 	IsPublicMeter            bool                `bun:"public_meter,notnull,default:false" json:"isPublicMeter"` | 	IsPublicMeter            bool                `bun:"public_meter,notnull" json:"isPublicMeter"` | ||||||
| 	WillDilute               bool                `bun:"dilute,notnull,default:false" json:"willDilute"` | 	WillDilute               bool                `bun:"dilute,notnull" json:"willDilute"` | ||||||
| 	LastPeriodOverall        decimal.Decimal     `bun:",notnull,default:0" json:"lastPeriodOverall"` | 	LastPeriodOverall        decimal.Decimal     `bun:",notnull" json:"lastPeriodOverall"` | ||||||
| 	LastPeriodCritical       decimal.Decimal     `bun:",notnull,default:0" json:"lastPeriodCritical"` | 	LastPeriodCritical       decimal.Decimal     `bun:",notnull" json:"lastPeriodCritical"` | ||||||
| 	LastPeriodPeak           decimal.Decimal     `bun:",notnull,default:0" json:"lastPeriodPeak"` | 	LastPeriodPeak           decimal.Decimal     `bun:",notnull" json:"lastPeriodPeak"` | ||||||
| 	LastPeriodFlat           decimal.Decimal     `bun:",notnull,default:0" json:"lastPeriodFlat"` | 	LastPeriodFlat           decimal.Decimal     `bun:",notnull" json:"lastPeriodFlat"` | ||||||
| 	LastPeriodValley         decimal.Decimal     `bun:",notnull,default:0" json:"lastPeriodValley"` | 	LastPeriodValley         decimal.Decimal     `bun:",notnull" json:"lastPeriodValley"` | ||||||
| 	CurrentPeriodOverall     decimal.Decimal     `bun:",notnull,default:0" json:"currentPeriodOverall"` | 	CurrentPeriodOverall     decimal.Decimal     `bun:",notnull" json:"currentPeriodOverall"` | ||||||
| 	CurrentPeriodCritical    decimal.Decimal     `bun:",notnull,default:0" json:"currentPeriodCritical"` | 	CurrentPeriodCritical    decimal.Decimal     `bun:",notnull" json:"currentPeriodCritical"` | ||||||
| 	CurrentPeriodPeak        decimal.Decimal     `bun:",notnull,default:0" json:"currentPeriodPeak"` | 	CurrentPeriodPeak        decimal.Decimal     `bun:",notnull" json:"currentPeriodPeak"` | ||||||
| 	CurrentPeriodFlat        decimal.Decimal     `bun:",notnull,default:0" json:"currentPeriodFlat"` | 	CurrentPeriodFlat        decimal.Decimal     `bun:",notnull" json:"currentPeriodFlat"` | ||||||
| 	CurrentPeriodValley      decimal.Decimal     `bun:",notnull,default:0" json:"currentPeriodValley"` | 	CurrentPeriodValley      decimal.Decimal     `bun:",notnull" json:"currentPeriodValley"` | ||||||
| 	AdjustOverall            decimal.Decimal     `bun:",notnull,default:0" json:"adjustOverall"` | 	AdjustOverall            decimal.Decimal     `bun:",notnull" json:"adjustOverall"` | ||||||
| 	AdjustCritical           decimal.Decimal     `bun:",notnull,default:0" json:"adjustCritical"` | 	AdjustCritical           decimal.Decimal     `bun:",notnull" json:"adjustCritical"` | ||||||
| 	AdjustPeak               decimal.Decimal     `bun:",notnull,default:0" json:"adjustPeak"` | 	AdjustPeak               decimal.Decimal     `bun:",notnull" json:"adjustPeak"` | ||||||
| 	AdjustFlat               decimal.Decimal     `bun:",notnull,default:0" json:"adjustFlat"` | 	AdjustFlat               decimal.Decimal     `bun:",notnull" json:"adjustFlat"` | ||||||
| 	AdjustValley             decimal.Decimal     `bun:",notnull,default:0" json:"adjustValley"` | 	AdjustValley             decimal.Decimal     `bun:",notnull" json:"adjustValley"` | ||||||
| 	Overall                  decimal.NullDecimal `json:"overall"` | 	Overall                  decimal.NullDecimal `json:"overall"` | ||||||
| 	OverallFee               decimal.NullDecimal `json:"overallFee"` | 	OverallFee               decimal.NullDecimal `json:"overallFee"` | ||||||
| 	OverallProportion        decimal.Decimal     `bun:",notnull,default:0" json:"-"` | 	OverallProportion        decimal.Decimal     `bun:",notnull" json:"-"` | ||||||
| 	Critical                 decimal.NullDecimal `json:"critical"` | 	Critical                 decimal.NullDecimal `json:"critical"` | ||||||
| 	CriticalFee              decimal.NullDecimal `json:"criticalFee"` | 	CriticalFee              decimal.NullDecimal `json:"criticalFee"` | ||||||
| 	Peak                     decimal.NullDecimal `json:"peak"` | 	Peak                     decimal.NullDecimal `json:"peak"` | ||||||
| @@ -58,7 +58,7 @@ type EndUserDetail struct { | |||||||
| 	FinalDiluted             decimal.NullDecimal `json:"finalDiluted"` | 	FinalDiluted             decimal.NullDecimal `json:"finalDiluted"` | ||||||
| 	FinalCharge              decimal.NullDecimal `json:"finalCharge"` | 	FinalCharge              decimal.NullDecimal `json:"finalCharge"` | ||||||
| 	Initialize               bool                `bun:"-" json:"-"` | 	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) | var _ bun.BeforeAppendModelHook = (*EndUserDetail)(nil) | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ type Meter04KV struct { | |||||||
| 	CustomerName       *string         `json:"customerName" excel:"name"` | 	CustomerName       *string         `json:"customerName" excel:"name"` | ||||||
| 	ContactName        *string         `json:"contactName" excel:"contact"` | 	ContactName        *string         `json:"contactName" excel:"contact"` | ||||||
| 	ContactPhone       *string         `json:"contactPhone" excel:"phone"` | 	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"` | 	Seq                int64           `bun:"type:bigint,notnull" json:"seq" excel:"seq"` | ||||||
| 	IsPublicMeter      bool            `bun:"public_meter,notnull" json:"isPublicMeter" excel:"public"` | 	IsPublicMeter      bool            `bun:"public_meter,notnull" json:"isPublicMeter" excel:"public"` | ||||||
| 	WillDilute         bool            `bun:"dilute,notnull" json:"willDilute" excel:"dilute"` | 	WillDilute         bool            `bun:"dilute,notnull" json:"willDilute" excel:"dilute"` | ||||||
|   | |||||||
| @@ -42,6 +42,7 @@ type Park struct { | |||||||
| 	Enterprise         *UserDetail         `bun:"rel:belongs-to,join:user_id=id" json:"-"` | 	Enterprise         *UserDetail         `bun:"rel:belongs-to,join:user_id=id" json:"-"` | ||||||
| 	MaintenanceFees    []*MaintenanceFee   `bun:"rel:has-many,join:id=park_id" json:"-"` | 	MaintenanceFees    []*MaintenanceFee   `bun:"rel:has-many,join:id=park_id" json:"-"` | ||||||
| 	Meters             []*Meter04KV        `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 { | type ParkSimplified struct { | ||||||
|   | |||||||
| @@ -6,6 +6,6 @@ type Region struct { | |||||||
| 	bun.BaseModel `bun:"table:region,alias:r"` | 	bun.BaseModel `bun:"table:region,alias:r"` | ||||||
| 	Code          string `bun:",pk,notnull" json:"code"` | 	Code          string `bun:",pk,notnull" json:"code"` | ||||||
| 	Name          string `bun:",notnull" json:"name"` | 	Name          string `bun:",notnull" json:"name"` | ||||||
| 	Level         int    `bun:",notnull,default:0" json:"level"` | 	Level         int    `bun:",notnull" json:"level"` | ||||||
| 	Parent        string `bun:",notnull,default:'0'" json:"parent"` | 	Parent        string `bun:",notnull" json:"parent"` | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,12 +20,12 @@ type Report struct { | |||||||
| 	Id                    string            `bun:",pk,notnull" json:"id"` | 	Id                    string            `bun:",pk,notnull" json:"id"` | ||||||
| 	ParkId                string            `bun:",notnull" json:"parkId"` | 	ParkId                string            `bun:",notnull" json:"parkId"` | ||||||
| 	Period                time.Time         `bun:"type:date,notnull" json:"period" time_format:"simple_date" time_location:"shanghai"` | 	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"` | 	Category              int8              `bun:"type:smallint,notnull" json:"category"` | ||||||
| 	SubmeterType          int8              `bun:"meter_04kv_type,type:smallint,notnull,default:0" json:"meter04kvType"` | 	SubmeterType          int8              `bun:"meter_04kv_type,type:smallint,notnull" json:"meter04kvType"` | ||||||
| 	StepState             Steps             `bun:"type:jsonb,notnull" json:"stepState"` | 	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"` | 	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"` | 	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"` | 	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:"-"` | 	Park                  *Park             `bun:"rel:belongs-to,join:park_id=id" json:"-"` | ||||||
| @@ -71,9 +71,9 @@ type ReportIndexSimplified struct { | |||||||
| 	ParkId                string     `bun:",notnull" json:"parkId"` | 	ParkId                string     `bun:",notnull" json:"parkId"` | ||||||
| 	Period                Date       `bun:"type:date,notnull" json:"period"` | 	Period                Date       `bun:"type:date,notnull" json:"period"` | ||||||
| 	StepState             Steps      `bun:"type:jsonb,notnull" json:"stepState"` | 	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"` | 	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"` | 	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"` | 	LastWithdrawAuditAt   *time.Time `bun:"type:timestamptz" json:"lastWithdrawAuditAt" time_format:"simple_datetime" time_location:"shanghai"` | ||||||
| } | } | ||||||
|   | |||||||
| @@ -10,21 +10,21 @@ import ( | |||||||
| type ReportSummary struct { | type ReportSummary struct { | ||||||
| 	bun.BaseModel                  `bun:"table:report_summary,alias:rs"` | 	bun.BaseModel                  `bun:"table:report_summary,alias:rs"` | ||||||
| 	ReportId                       string              `bun:",pk,notnull" json:"-"` | 	ReportId                       string              `bun:",pk,notnull" json:"-"` | ||||||
| 	Overall                        decimal.Decimal     `bun:",notnull,default:0" json:"overall"` | 	Overall                        decimal.Decimal     `bun:",notnull" json:"overall"` | ||||||
| 	OverallFee                     decimal.Decimal     `bun:",notnull,default:0" json:"overallFee"` | 	OverallFee                     decimal.Decimal     `bun:",notnull" json:"overallFee"` | ||||||
| 	ConsumptionFee                 decimal.NullDecimal `json:"consumptionFee"` | 	ConsumptionFee                 decimal.NullDecimal `json:"consumptionFee"` | ||||||
| 	OverallPrice                   decimal.NullDecimal `json:"overallPrice"` | 	OverallPrice                   decimal.NullDecimal `json:"overallPrice"` | ||||||
| 	Critical                       decimal.Decimal     `bun:",notnull,default:0" json:"critical"` | 	Critical                       decimal.Decimal     `bun:",notnull" json:"critical"` | ||||||
| 	CriticalFee                    decimal.Decimal     `bun:",notnull,default:0" json:"criticalFee"` | 	CriticalFee                    decimal.Decimal     `bun:",notnull" json:"criticalFee"` | ||||||
| 	CriticalPrice                  decimal.NullDecimal `json:"criticalPrice"` | 	CriticalPrice                  decimal.NullDecimal `json:"criticalPrice"` | ||||||
| 	Peak                           decimal.Decimal     `bun:",notnull,default:0" json:"peak"` | 	Peak                           decimal.Decimal     `bun:",notnull" json:"peak"` | ||||||
| 	PeakFee                        decimal.Decimal     `bun:",notnull,default:0" json:"peakFee"` | 	PeakFee                        decimal.Decimal     `bun:",notnull" json:"peakFee"` | ||||||
| 	PeakPrice                      decimal.NullDecimal `json:"peakPrice"` | 	PeakPrice                      decimal.NullDecimal `json:"peakPrice"` | ||||||
| 	Flat                           decimal.Decimal     `bun:",notnull,default:0" json:"flat"` | 	Flat                           decimal.Decimal     `bun:",notnull" json:"flat"` | ||||||
| 	FlatFee                        decimal.Decimal     `bun:",notnull,default:0" json:"flatFee"` | 	FlatFee                        decimal.Decimal     `bun:",notnull" json:"flatFee"` | ||||||
| 	FlatPrice                      decimal.NullDecimal `json:"flatPrice"` | 	FlatPrice                      decimal.NullDecimal `json:"flatPrice"` | ||||||
| 	Valley                         decimal.Decimal     `bun:",notnull,default:0" json:"valley"` | 	Valley                         decimal.Decimal     `bun:",notnull" json:"valley"` | ||||||
| 	ValleyFee                      decimal.Decimal     `bun:",notnull,default:0" json:"valleyFee"` | 	ValleyFee                      decimal.Decimal     `bun:",notnull" json:"valleyFee"` | ||||||
| 	ValleyPrice                    decimal.NullDecimal `json:"valleyPrice"` | 	ValleyPrice                    decimal.NullDecimal `json:"valleyPrice"` | ||||||
| 	Loss                           decimal.NullDecimal `json:"loss"` | 	Loss                           decimal.NullDecimal `json:"loss"` | ||||||
| 	LossFee                        decimal.NullDecimal `json:"lossFee"` | 	LossFee                        decimal.NullDecimal `json:"lossFee"` | ||||||
| @@ -50,9 +50,9 @@ type ReportSummary struct { | |||||||
| 	PublicConsumptionFlatFee       decimal.NullDecimal `json:"publicConsumptionFlatFee"` | 	PublicConsumptionFlatFee       decimal.NullDecimal `json:"publicConsumptionFlatFee"` | ||||||
| 	PublicConsumptionValley        decimal.NullDecimal `json:"publicConsumptionValley"` | 	PublicConsumptionValley        decimal.NullDecimal `json:"publicConsumptionValley"` | ||||||
| 	PublicConsumptionValleyFee     decimal.NullDecimal `json:"publicConsumptionValleyFee"` | 	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"` | 	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"` | 	AdjustDilutedPrice             decimal.NullDecimal `json:"adjustDilutedPrice"` | ||||||
| 	MaintenanceDilutedPrice        decimal.NullDecimal `json:"maintencanceDilutedPrice"` | 	MaintenanceDilutedPrice        decimal.NullDecimal `json:"maintencanceDilutedPrice"` | ||||||
| 	LossDilutedPrice               decimal.NullDecimal `json:"lossDilutedPrice"` | 	LossDilutedPrice               decimal.NullDecimal `json:"lossDilutedPrice"` | ||||||
|   | |||||||
| @@ -17,11 +17,11 @@ type UserCharge struct { | |||||||
| 	Discount      decimal.NullDecimal `json:"discount"` | 	Discount      decimal.NullDecimal `json:"discount"` | ||||||
| 	Amount        decimal.NullDecimal `json:"amount"` | 	Amount        decimal.NullDecimal `json:"amount"` | ||||||
| 	ChargeTo      Date                `bun:"type:date,notnull" json:"chargeTo"` | 	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"` | 	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"` | 	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"` | 	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:"-"` | 	Detail        *UserDetail         `bun:"rel:belongs-to,join:user_id=id" json:"-"` | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,6 +1,9 @@ | |||||||
| package model | package model | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
|  | 	"context" | ||||||
|  | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/shopspring/decimal" | 	"github.com/shopspring/decimal" | ||||||
| 	"github.com/uptrace/bun" | 	"github.com/uptrace/bun" | ||||||
| ) | ) | ||||||
| @@ -12,7 +15,21 @@ type WillDilutedFee struct { | |||||||
| 	ReportId           string          `bun:",notnull" json:"reportId"` | 	ReportId           string          `bun:",notnull" json:"reportId"` | ||||||
| 	SourceId           *string         `json:"sourceId"` | 	SourceId           *string         `json:"sourceId"` | ||||||
| 	Name               string          `bun:",notnull" json:"name"` | 	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"` | 	Memo               *string         `bun:"type:text" json:"memo"` | ||||||
| 	Origin             *MaintenanceFee `bun:"rel:belongs-to,join:source_id=id"` | 	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 | ||||||
|  | } | ||||||
|   | |||||||
| @@ -120,7 +120,7 @@ func (_EndUserService) UpdateEndUserRegisterRecord(tx *bun.Tx, ctx *context.Cont | |||||||
| 		"current_period_critical", | 		"current_period_critical", | ||||||
| 		"current_period_peak", | 		"current_period_peak", | ||||||
| 		"current_period_flat", | 		"current_period_flat", | ||||||
| 		"current_perios_valley", | 		"current_period_valley", | ||||||
| 		"adjust_critical", | 		"adjust_critical", | ||||||
| 		"adjust_peak", | 		"adjust_peak", | ||||||
| 		"adjust_flat", | 		"adjust_flat", | ||||||
|   | |||||||
| @@ -36,37 +36,34 @@ func (_ReportService) FetchParksWithNewestReport(uid string) ([]model.ParkNewest | |||||||
|  |  | ||||||
| 	ctx, cancel := global.TimeoutContext() | 	ctx, cancel := global.TimeoutContext() | ||||||
| 	defer cancel() | 	defer cancel() | ||||||
| 	reports := make([]model.Report, 0) | 	parks := make([]model.Park, 0) | ||||||
| 	err := global.DB.NewSelect().Model(&reports).Relation("Park"). | 	err := global.DB.NewSelect().Model(&parks).Relation("Reports"). | ||||||
| 		Where("p.user_id = ?", uid). | 		Where("user_id = ?", uid). | ||||||
| 		Where("p.enabled = ?", true). | 		Where("enabled = ?", true). | ||||||
|  | 		Order("created_at asc"). | ||||||
| 		Scan(ctx) | 		Scan(ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return make([]model.ParkNewestReport, 0), err | 		return make([]model.ParkNewestReport, 0), err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	reducedParks := lo.Reduce( | 	reducedParks := lo.Reduce( | ||||||
| 		reports, | 		parks, | ||||||
| 		func(acc map[string]model.ParkNewestReport, elem model.Report, index int) map[string]model.ParkNewestReport { | 		func(acc map[string]model.ParkNewestReport, elem model.Park, index int) map[string]model.ParkNewestReport { | ||||||
| 			if v, ok := acc[elem.Park.Id]; ok { | 			if _, ok := acc[elem.Id]; !ok { | ||||||
| 				if v.Report == nil || (elem.Period.After(v.Report.Period)) { | 				newestReport := lo.MaxBy(elem.Reports, func(a, b *model.Report) bool { | ||||||
| 					acc[elem.Park.Id] = model.ParkNewestReport{ | 					return a.Period.After(b.Period) | ||||||
| 						Report: &elem, | 				}) | ||||||
| 						Park:   *elem.Park, | 				acc[elem.Id] = model.ParkNewestReport{ | ||||||
| 					} | 					Report: newestReport, | ||||||
| 				} | 					Park:   elem, | ||||||
| 			} else { |  | ||||||
| 				acc[elem.Park.Id] = model.ParkNewestReport{ |  | ||||||
| 					Report: &elem, |  | ||||||
| 					Park:   *elem.Park, |  | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			return acc | 			return acc | ||||||
| 		}, | 		}, | ||||||
| 		make(map[string]model.ParkNewestReport, 0), | 		make(map[string]model.ParkNewestReport, 0), | ||||||
| 	) | 	) | ||||||
| 	relations := lo.Map(reports, func(r model.Report, _ int) string { | 	relations := lo.Map(parks, func(r model.Park, _ int) string { | ||||||
| 		return fmt.Sprintf("report:%s", r.Id) | 		return fmt.Sprintf("park:%s", r.Id) | ||||||
| 	}) | 	}) | ||||||
| 	relations = append(relations, "park", "report") | 	relations = append(relations, "park", "report") | ||||||
| 	cache.CacheSearch(reducedParks, relations, "park_newest_report", uid) | 	cache.CacheSearch(reducedParks, relations, "park_newest_report", uid) | ||||||
| @@ -81,11 +78,11 @@ func (_ReportService) IsNewPeriodValid(uid, pid string, period time.Time) (bool, | |||||||
| 		reports = *cachedReport | 		reports = *cachedReport | ||||||
| 	} else { | 	} else { | ||||||
| 		err := global.DB.NewSelect().Model(&reports).Relation("Park"). | 		err := global.DB.NewSelect().Model(&reports).Relation("Park"). | ||||||
| 			Where("p.user_id = ?", uid). | 			Where("park.user_id = ?", uid). | ||||||
| 			Where("r.park_id = ?", pid). | 			Where("r.park_id = ?", pid). | ||||||
| 			Scan(ctx) | 			Scan(ctx) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return false, nil | 			return false, err | ||||||
| 		} | 		} | ||||||
| 		cache.CacheSearch(reports, []string{"report", "park"}, "park", "user", uid, "park", pid) | 		cache.CacheSearch(reports, []string{"report", "park"}, "park", "user", uid, "park", pid) | ||||||
| 	} | 	} | ||||||
| @@ -430,7 +427,8 @@ func (_ReportService) UpdateMaintenanceFee(feeId string, updates map[string]inte | |||||||
| 	ctx, cancel := global.TimeoutContext() | 	ctx, cancel := global.TimeoutContext() | ||||||
| 	defer cancel() | 	defer cancel() | ||||||
|  |  | ||||||
| 	_, err = global.DB.NewUpdate().Model(updates).TableExpr("will_diluted_fee"). | 	updates["last_modified_at"] = lo.ToPtr(time.Now()) | ||||||
|  | 	_, err = global.DB.NewUpdate().Model(&updates).TableExpr("will_diluted_fee"). | ||||||
| 		Where("id = ?", feeId). | 		Where("id = ?", feeId). | ||||||
| 		Exec(ctx) | 		Exec(ctx) | ||||||
| 	cache.AbolishRelation(fmt.Sprintf("will_diluted_fee:%s", feeId)) | 	cache.AbolishRelation(fmt.Sprintf("will_diluted_fee:%s", feeId)) | ||||||
| @@ -454,6 +452,7 @@ func (_ReportService) ProgressReportWillDilutedFee(report model.Report) (err err | |||||||
|  |  | ||||||
| 	report.StepState.WillDiluted = true | 	report.StepState.WillDiluted = true | ||||||
| 	_, err = global.DB.NewUpdate().Model(&report). | 	_, err = global.DB.NewUpdate().Model(&report). | ||||||
|  | 		WherePK(). | ||||||
| 		Column("step_state"). | 		Column("step_state"). | ||||||
| 		Exec(ctx) | 		Exec(ctx) | ||||||
| 	cache.AbolishRelation(fmt.Sprintf("report:%s", report.Id)) | 	cache.AbolishRelation(fmt.Sprintf("report:%s", report.Id)) | ||||||
| @@ -466,6 +465,7 @@ func (_ReportService) ProgressReportRegisterEndUser(report model.Report) (err er | |||||||
|  |  | ||||||
| 	report.StepState.Submeter = true | 	report.StepState.Submeter = true | ||||||
| 	_, err = global.DB.NewUpdate().Model(&report). | 	_, err = global.DB.NewUpdate().Model(&report). | ||||||
|  | 		WherePK(). | ||||||
| 		Column("step_state"). | 		Column("step_state"). | ||||||
| 		Exec(ctx) | 		Exec(ctx) | ||||||
| 	cache.AbolishRelation(fmt.Sprintf("report:%s", report.Id)) | 	cache.AbolishRelation(fmt.Sprintf("report:%s", report.Id)) | ||||||
| @@ -478,6 +478,7 @@ func (_ReportService) ProgressReportCalculate(report model.Report) (err error) { | |||||||
|  |  | ||||||
| 	report.StepState.Calculate = true | 	report.StepState.Calculate = true | ||||||
| 	_, err = global.DB.NewUpdate().Model(&report). | 	_, err = global.DB.NewUpdate().Model(&report). | ||||||
|  | 		WherePK(). | ||||||
| 		Column("step_state"). | 		Column("step_state"). | ||||||
| 		Exec(ctx) | 		Exec(ctx) | ||||||
| 	cache.AbolishRelation(fmt.Sprintf("report:%s", report.Id)) | 	cache.AbolishRelation(fmt.Sprintf("report:%s", report.Id)) | ||||||
| @@ -492,7 +493,11 @@ func (_ReportService) RetreiveParkEndUserMeterType(reportId string) (int, error) | |||||||
| 	defer cancel() | 	defer cancel() | ||||||
|  |  | ||||||
| 	var mType int | 	var mType int | ||||||
| 	err := global.DB.NewSelect().Model((*model.Report)(nil)).Relation("Park"). | 	err := global.DB.NewSelect().Model((*model.Report)(nil)). | ||||||
|  | 		Relation("Park", func(q *bun.SelectQuery) *bun.SelectQuery { | ||||||
|  | 			return q.Column("meter_04kv_type") | ||||||
|  | 		}). | ||||||
|  | 		ExcludeColumn("*"). | ||||||
| 		Where("r.id = ?", reportId). | 		Where("r.id = ?", reportId). | ||||||
| 		Scan(ctx, &mType) | 		Scan(ctx, &mType) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -597,14 +602,19 @@ func (_ReportService) AssembleReportPublicity(reportId string) (*model.Publicity | |||||||
| 	var report = new(model.Report) | 	var report = new(model.Report) | ||||||
| 	err := global.DB.NewSelect().Model(report). | 	err := global.DB.NewSelect().Model(report). | ||||||
| 		Relation("Summary").Relation("WillDilutedFees").Relation("EndUsers"). | 		Relation("Summary").Relation("WillDilutedFees").Relation("EndUsers"). | ||||||
| 		Relation("Park", func(q *bun.SelectQuery) *bun.SelectQuery { | 		Relation("Park"). | ||||||
| 			return q.Relation("Enterprise") | 		Where("r.id = ?", reportId). | ||||||
| 		}). |  | ||||||
| 		Where("id = ?", reportId). |  | ||||||
| 		Scan(ctx) | 		Scan(ctx) | ||||||
| 	if err != nil || report == nil { | 	if err != nil { | ||||||
| 		return nil, exceptions.NewNotFoundErrorFromError("未找到指定的公示报表", err) | 		return nil, exceptions.NewNotFoundErrorFromError("未找到指定的公示报表", err) | ||||||
| 	} | 	} | ||||||
|  | 	var enterprise = new(model.UserDetail) | ||||||
|  | 	err = global.DB.NewSelect().Model(enterprise). | ||||||
|  | 		Where("id = ?", report.Park.UserId). | ||||||
|  | 		Scan(ctx) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, exceptions.NewNotFoundErrorFromError("未找到指定公示报表对应的用户信息", err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	// 组合数据 | 	// 组合数据 | ||||||
| 	paidPart := model.PaidPart{ | 	paidPart := model.PaidPart{ | ||||||
| @@ -719,7 +729,7 @@ func (_ReportService) AssembleReportPublicity(reportId string) (*model.Publicity | |||||||
| 	publicity := &model.Publicity{ | 	publicity := &model.Publicity{ | ||||||
| 		Report:                   *report, | 		Report:                   *report, | ||||||
| 		Park:                     *report.Park, | 		Park:                     *report.Park, | ||||||
| 		User:                     *report.Park.Enterprise, | 		User:                     *enterprise, | ||||||
| 		Paid:                     paidPart, | 		Paid:                     paidPart, | ||||||
| 		EndUser:                  endUserSummary, | 		EndUser:                  endUserSummary, | ||||||
| 		Loss:                     lossPart, | 		Loss:                     lossPart, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user