enhance(model):调整数据模型设计。

This commit is contained in:
徐涛 2022-08-11 15:16:21 +08:00
parent 57ea1bd69a
commit 279fb32f4d
11 changed files with 81 additions and 63 deletions

View File

@ -4,26 +4,28 @@ import "github.com/shopspring/decimal"
type EndUserDetail struct { type EndUserDetail struct {
CreatedAndModified `xorm:"extends"` CreatedAndModified `xorm:"extends"`
ReportId string `xorm:"varchar(120) pk notnull" json:"-"` ReportId string `xorm:"varchar(120) pk not null" json:"-"`
MeterId string `xorm:"meter_04kv_id varchar(120) pk notnull" json:"meterId"` MeterId string `xorm:"meter_04kv_id varchar(120) pk not null" json:"meterId"`
Seq int64 `xorm:"bigint not null" json:"seq"`
Ratio decimal.Decimal `xorm:"numeric(8,4) not null" json:"ratio"`
LastPeriodCritical decimal.NullDecimal `xorm:"numeric(14,2)" json:"lastPeriodCritical"` LastPeriodCritical decimal.NullDecimal `xorm:"numeric(14,2)" json:"lastPeriodCritical"`
LastPeriodPeek decimal.NullDecimal `xorm:"numeric(14,2)" json:"lastPeriodPeek"` LastPeriodPeek decimal.NullDecimal `xorm:"numeric(14,2)" json:"lastPeriodPeek"`
LastPeriodFlat decimal.Decimal `xorm:"numeric(14,2) notnull" json:"lastPeriodFlat"` LastPeriodFlat decimal.Decimal `xorm:"numeric(14,2) not null" json:"lastPeriodFlat"`
LastPeriodValley decimal.NullDecimal `xorm:"numeric(14,2)" json:"lastPeriodValley"` LastPeriodValley decimal.NullDecimal `xorm:"numeric(14,2)" json:"lastPeriodValley"`
CurrentPeriodCritical decimal.NullDecimal `xorm:"numeric(14,2)" json:"currentPeriodCritical"` CurrentPeriodCritical decimal.NullDecimal `xorm:"numeric(14,2)" json:"currentPeriodCritical"`
CurrentPeriodPeek decimal.NullDecimal `xorm:"numeric(14,2)" json:"currentPeriodPeek"` CurrentPeriodPeek decimal.NullDecimal `xorm:"numeric(14,2)" json:"currentPeriodPeek"`
CurrentPeriodFlat decimal.Decimal `xorm:"numeric(14,2) notnull" json:"currentPeriodFlat"` CurrentPeriodFlat decimal.Decimal `xorm:"numeric(14,2) not null" json:"currentPeriodFlat"`
CurrentPeriodValley decimal.NullDecimal `xorm:"numeric(14,2)" json:"currentPeriodValley"` CurrentPeriodValley decimal.NullDecimal `xorm:"numeric(14,2)" json:"currentPeriodValley"`
AdjustCritical decimal.NullDecimal `xorm:"numeric(14,2)" json:"adjustCritical"` AdjustCritical decimal.NullDecimal `xorm:"numeric(14,2)" json:"adjustCritical"`
AdjustPeek decimal.NullDecimal `xorm:"numeric(14,2)" json:"adjustPeek"` AdjustPeek decimal.NullDecimal `xorm:"numeric(14,2)" json:"adjustPeek"`
AdjustFlat decimal.Decimal `xorm:"numeric(14,2) notnull" json:"adjustFlat"` AdjustFlat decimal.Decimal `xorm:"numeric(14,2) not null" json:"adjustFlat"`
AdjustValley decimal.NullDecimal `xorm:"numeric(14,2)" json:"adjustValley"` AdjustValley decimal.NullDecimal `xorm:"numeric(14,2)" json:"adjustValley"`
Critical decimal.NullDecimal `xorm:"numeric(14,2)" json:"critical"` Critical decimal.NullDecimal `xorm:"numeric(14,2)" json:"critical"`
CriticalFee decimal.NullDecimal `xorm:"numeric(18,8)" json:"criticalFee"` CriticalFee decimal.NullDecimal `xorm:"numeric(18,8)" json:"criticalFee"`
Peek decimal.NullDecimal `xorm:"numeric(14,2)" json:"peek"` Peek decimal.NullDecimal `xorm:"numeric(14,2)" json:"peek"`
PeekFee decimal.NullDecimal `xorm:"numeric(18,8)" json:"peekFee"` PeekFee decimal.NullDecimal `xorm:"numeric(18,8)" json:"peekFee"`
Flat decimal.Decimal `xorm:"numeric(14,2) notnull" json:"flat"` Flat decimal.Decimal `xorm:"numeric(14,2) not null" json:"flat"`
FlatFee decimal.Decimal `xorm:"numeric(18,8) notnull" json:"flatFee"` FlatFee decimal.Decimal `xorm:"numeric(18,8) not null" json:"flatFee"`
Valley decimal.NullDecimal `xorm:"numeric(14,2)" json:"valley"` Valley decimal.NullDecimal `xorm:"numeric(14,2)" json:"valley"`
ValleyFee decimal.NullDecimal `xorm:"numeric(18,8)" json:"valleyFee"` ValleyFee decimal.NullDecimal `xorm:"numeric(18,8)" json:"valleyFee"`
BasicFeeDiluted decimal.NullDecimal `xorm:"numeric(18,8)" json:"basicFeeDiluted"` BasicFeeDiluted decimal.NullDecimal `xorm:"numeric(18,8)" json:"basicFeeDiluted"`

View File

@ -6,12 +6,13 @@ import (
type MaintenanceFee struct { type MaintenanceFee struct {
CreatedAndModified `xorm:"extends"` CreatedAndModified `xorm:"extends"`
Id string `xorm:"varchar(120) pk notnull" json:"id"` Deleted `xorm:"extends"`
ParkId string `xorm:"varchar(120) notnull" json:"parkId"` Id string `xorm:"varchar(120) pk not null" json:"id"`
Name string `xorm:"varchar(50) notnull" json:"name"` ParkId string `xorm:"varchar(120) not null" json:"parkId"`
Fee decimal.Decimal `xorm:"numeric(8,2) notnull" json:"fee"` Name string `xorm:"varchar(50) not null" json:"name"`
Fee decimal.Decimal `xorm:"numeric(8,2) not null" json:"fee"`
Memo *string `xorm:"text" json:"memo"` Memo *string `xorm:"text" json:"memo"`
Enabled bool `xorm:"bool notnull" json:"enabled"` Enabled bool `xorm:"bool not null" json:"enabled"`
} }
func (MaintenanceFee) TableName() string { func (MaintenanceFee) TableName() string {

View File

@ -6,16 +6,17 @@ import (
type Meter04KV struct { type Meter04KV struct {
CreatedAndModified `xorm:"extends"` CreatedAndModified `xorm:"extends"`
Code string `xorm:"varchar(120) pk notnull" json:"code"` Code string `xorm:"varchar(120) pk not null" json:"code"`
ParkId string `xorm:"varchar(120) notnull" json:"parkId"` ParkId string `xorm:"varchar(120) not null" json:"parkId"`
Address *string `xorm:"varchar(100)" json:"address"` Address *string `xorm:"varchar(100)" json:"address"`
CustomerName *string `xorm:"varchar(100)" json:"customerName"` CustomerName *string `xorm:"varchar(100)" json:"customerName"`
ContactName *string `xorm:"varchar(70)" json:"contactName"` ContactName *string `xorm:"varchar(70)" json:"contactName"`
ContactPhone *string `xorm:"varchar(50)" json:"contactPhone"` ContactPhone *string `xorm:"varchar(50)" json:"contactPhone"`
Ratio decimal.Decimal `xorm:"numeric(8,4) notnull default(1)" json:"ratio"` Ratio decimal.Decimal `xorm:"numeric(8,4) not null default 1" json:"ratio"`
IsPublicMeter bool `xorm:"'public_meter' bool notnull default(false)" json:"isPublicMeter"` Seq int64 `xorm:"bigint not null" json:"seq"`
WillDilute bool `xorm:"'dilute' bool notnull default(false)" json:"willDilute"` IsPublicMeter bool `xorm:"'public_meter' bool not null default false" json:"isPublicMeter"`
Enabled bool `xorm:"bool notnull default(true)" json:"enabled"` WillDilute bool `xorm:"'dilute' bool not null default false" json:"willDilute"`
Enabled bool `xorm:"bool not null default true" json:"enabled"`
} }
func (Meter04KV) TableName() string { func (Meter04KV) TableName() string {

View File

@ -6,19 +6,20 @@ import (
type Park struct { type Park struct {
CreatedAndModified `xorm:"extends"` CreatedAndModified `xorm:"extends"`
Id string `xorm:"varchar(120) pk notnull" json:"id"` Deleted `xorm:"extends"`
UserId string `xorm:"varchar(120) notnull" json:"userId"` Id string `xorm:"varchar(120) pk not null" json:"id"`
Name string `xorm:"vachar(70) notnull" json:"name"` UserId string `xorm:"varchar(120) not null" json:"userId"`
Name string `xorm:"vachar(70) not null" json:"name"`
Abbr *string `xorm:"varchar(50)" json:"abbr"` Abbr *string `xorm:"varchar(50)" json:"abbr"`
Area decimal.NullDecimal `xorm:"numeric(14,2)" json:"area"` Area decimal.NullDecimal `xorm:"numeric(14,2)" json:"area"`
TenementQuantity decimal.NullDecimal `xorm:"numeric(8,0)" json:"tenementQuantity"` TenementQuantity decimal.NullDecimal `xorm:"numeric(8,0)" json:"tenementQuantity"`
Capacity decimal.NullDecimal `xorm:"numeric(16,2)" json:"capacity"` Capacity decimal.NullDecimal `xorm:"numeric(16,2)" json:"capacity"`
Category int8 `xorm:"smallint notnull" json:"category"` Category int8 `xorm:"smallint not null" json:"category"`
Region *string `xorm:"varchar(10)" json:"region"` Region *string `xorm:"varchar(10)" json:"region"`
Address *string `xorm:"varchar(120)" json:"address"` Address *string `xorm:"varchar(120)" json:"address"`
Contact *string `xorm:"varchar(100)" json:"contact"` Contact *string `xorm:"varchar(100)" json:"contact"`
Phone *string `xorm:"varchar(50)" json:"phone"` Phone *string `xorm:"varchar(50)" json:"phone"`
Enabled bool `xorm:"bool notnull" json:"enabled"` Enabled bool `xorm:"bool not null" json:"enabled"`
} }
func (Park) TableName() string { func (Park) TableName() string {

View File

@ -4,12 +4,13 @@ import "time"
type Report struct { type Report struct {
CreatedAndModified `xorm:"extends"` CreatedAndModified `xorm:"extends"`
Id string `xorm:"varchar(120) pk notnull" json:"id"` Deleted `xorm:"extends"`
ParkId string `xorm:"varchar(120) notnull" json:"parkId"` Id string `xorm:"varchar(120) pk not null" json:"id"`
Period time.Time `xorm:"date notnull" json:"period"` ParkId string `xorm:"varchar(120) not null" json:"parkId"`
Published bool `xorm:"bool notnull default(false)" json:"published"` Period time.Time `xorm:"date not null" json:"period"`
Published bool `xorm:"bool not null default false" json:"published"`
PublishedAt *time.Time `xorm:"timestampz" json:"publishedAt"` PublishedAt *time.Time `xorm:"timestampz" json:"publishedAt"`
Withdraw byte `xorm:"smallint notnull default(0)" json:"withdraw"` Withdraw byte `xorm:"smallint not null default 0" json:"withdraw"`
LastWithdrawAppliedAt *time.Time `xorm:"timestampz" json:"lastWithdrawAppliedAt"` LastWithdrawAppliedAt *time.Time `xorm:"timestampz" json:"lastWithdrawAppliedAt"`
LastWithdrawAuditAt *time.Time `xorm:"timestampz" json:"lastWithdrawAuditAt"` LastWithdrawAuditAt *time.Time `xorm:"timestampz" json:"lastWithdrawAuditAt"`
} }

View File

@ -3,29 +3,29 @@ package model
import "github.com/shopspring/decimal" import "github.com/shopspring/decimal"
type ReportSummary struct { type ReportSummary struct {
ReportId string `xorm:"varchar(120) pk notnull" json:"-"` ReportId string `xorm:"varchar(120) pk not null" json:"-"`
Overall decimal.Decimal `xorm:"numeric(14,2) notnull" json:"overall"` Overall decimal.Decimal `xorm:"numeric(14,2) not null" json:"overall"`
OverallFee decimal.Decimal `xorm:"numeric(14,2) notnull" json:"overallFee"` OverallFee decimal.Decimal `xorm:"numeric(14,2) not null" json:"overallFee"`
OverallPrice decimal.Decimal `xorm:"numeric(16,8)" json:"overallPrice"` OverallPrice decimal.Decimal `xorm:"numeric(16,8)" json:"overallPrice"`
Critical decimal.Decimal `xorm:"numeric(14,2) notnull" json:"critial"` Critical decimal.Decimal `xorm:"numeric(14,2) not null" json:"critial"`
CriticalFee decimal.Decimal `xorm:"numeric(14,2) notnull" json:"criticalFee"` CriticalFee decimal.Decimal `xorm:"numeric(14,2) not null" json:"criticalFee"`
CriticalPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"criticalPrice"` CriticalPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"criticalPrice"`
Peek decimal.Decimal `xorm:"numeric(14,2) notnull" json:"peek"` Peek decimal.Decimal `xorm:"numeric(14,2) not null" json:"peek"`
PeekFee decimal.Decimal `xorm:"numeric(14,2) notnull" json:"peekFee"` PeekFee decimal.Decimal `xorm:"numeric(14,2) not null" json:"peekFee"`
PeekPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"peekPrice"` PeekPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"peekPrice"`
Flat decimal.NullDecimal `xorm:"numeric(14,2)" json:"flat"` Flat decimal.NullDecimal `xorm:"numeric(14,2)" json:"flat"`
FlatFee decimal.Decimal `xorm:"numeric(14,2) notnull" json:"flatFee"` FlatFee decimal.Decimal `xorm:"numeric(14,2) not null" json:"flatFee"`
FlatPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"flatPrice"` FlatPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"flatPrice"`
Valley decimal.Decimal `xorm:"numeric(14,2) notnull" json:"valley"` Valley decimal.Decimal `xorm:"numeric(14,2) not null" json:"valley"`
ValleyFee decimal.Decimal `xorm:"numeric(14,2) notnull" json:"valleyFee"` ValleyFee decimal.Decimal `xorm:"numeric(14,2) not null" json:"valleyFee"`
ValleyPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"valleyPrice"` ValleyPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"valleyPrice"`
Loss decimal.NullDecimal `xorm:"numeric(14,2)" json:"loss"` Loss decimal.NullDecimal `xorm:"numeric(14,2)" json:"loss"`
LossFee decimal.NullDecimal `xorm:"numeric(16,2)" json:"lossFee"` LossFee decimal.NullDecimal `xorm:"numeric(16,2)" json:"lossFee"`
PublicConsumption decimal.NullDecimal `xorm:"numeric(14,2)" json:"publicConsumption"` PublicConsumption decimal.NullDecimal `xorm:"numeric(14,2)" json:"publicConsumption"`
PublicConsumptionFee decimal.NullDecimal `xorm:"numeric(14,2)" json:"publicConsumptionFee"` PublicConsumptionFee decimal.NullDecimal `xorm:"numeric(14,2)" json:"publicConsumptionFee"`
BasicFee decimal.Decimal `xorm:"numeric(14,2) notnull" json:"basicFee"` BasicFee decimal.Decimal `xorm:"numeric(14,2) not null" json:"basicFee"`
BasicDilutedPrice decimal.NullDecimal `xorm:"numeric(18,8)" json:"basicDilutedPrice"` BasicDilutedPrice decimal.NullDecimal `xorm:"numeric(18,8)" json:"basicDilutedPrice"`
AdjustFee decimal.Decimal `xorm:"numeric(14,2) notnull" json:"adjustFee"` AdjustFee decimal.Decimal `xorm:"numeric(14,2) not null" json:"adjustFee"`
AdjustDilutedPrice decimal.NullDecimal `xorm:"numeric(18,8)" json:"adjustDilutedPrice"` AdjustDilutedPrice decimal.NullDecimal `xorm:"numeric(18,8)" json:"adjustDilutedPrice"`
MaintenanceDilutedPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"maintencanceDilutedPrice"` MaintenanceDilutedPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"maintencanceDilutedPrice"`
LossDilutedPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"lossDilutedPrice"` LossDilutedPrice decimal.NullDecimal `xorm:"numeric(16,8)" json:"lossDilutedPrice"`

View File

@ -3,7 +3,7 @@ package model
import "time" import "time"
type Created struct { type Created struct {
CreatedAt time.Time `xorm:"timestampz notnull created" json:"createdAt"` CreatedAt time.Time `xorm:"timestampz not null created" json:"createdAt"`
} }
type CreatedWithUser struct { type CreatedWithUser struct {
@ -11,6 +11,15 @@ type CreatedWithUser struct {
CreatedBy *string `xorm:"varchar(100)" json:"createdBy"` CreatedBy *string `xorm:"varchar(100)" json:"createdBy"`
} }
type Deleted struct {
DeletedAt *time.Time `xorm:"timestampz deleted" json:"deletedAt"`
}
type DeletedWithUser struct {
Deleted `xorm:"extends"`
DeletedBy *string `xorm:"varchar(120)" json:"deletedBy"`
}
type CreatedAndModified struct { type CreatedAndModified struct {
Created `xorm:"extends"` Created `xorm:"extends"`
LastModifiedAt *time.Time `xorm:"timestampz updated" json:"lastModifiedAt"` LastModifiedAt *time.Time `xorm:"timestampz updated" json:"lastModifiedAt"`

View File

@ -2,12 +2,12 @@ package model
type User struct { type User struct {
Created `xorm:"extends"` Created `xorm:"extends"`
Id string `xorm:"varchar(120) pk notnull" json:"id"` Id string `xorm:"varchar(120) pk not null" json:"id"`
Username string `xorm:"varchar(30) notnull" json:"username"` Username string `xorm:"varchar(30) not null" json:"username"`
Password string `xorm:"varchar(120) notnull" json:"-"` Password string `xorm:"varchar(120) not null" json:"-"`
ResetNeeded bool `xorm:"bool notnull" json:"resetNeeded"` ResetNeeded bool `xorm:"bool not null" json:"resetNeeded"`
Type byte `xorm:"smallint notnull" json:"type"` Type byte `xorm:"smallint not null" json:"type"`
Enabled bool `xorm:"bool notnull" json:"enabled"` Enabled bool `xorm:"bool not null" json:"enabled"`
} }
func (User) TableName() string { func (User) TableName() string {

View File

@ -7,15 +7,17 @@ import (
) )
type UserCharge struct { type UserCharge struct {
Created `xorm:"extends"` Created `xorm:"extends"`
Seq int64 `xorm:"bigint pk notnull " json:"seq"` Seq int64 `xorm:"bigint pk not null " json:"seq"`
CreatedAt time.Time `xorm:"timestampz notnull" json:"createdAt"` CreatedAt time.Time `xorm:"timestampz not null" json:"createdAt"`
UserId string `xorm:"varchar(120) notnull" json:"userId"` UserId string `xorm:"varchar(120) not null" json:"userId"`
Fee decimal.Decimal `xorm:"numeric(12,2) notnull" json:"fee"` Fee decimal.Decimal `xorm:"numeric(12,2) not null" json:"fee"`
Discount decimal.Decimal `xorm:"numeric(5,4) notnull" json:"discount"` Discount decimal.Decimal `xorm:"numeric(5,4) not null" json:"discount"`
Amount decimal.Decimal `xorm:"numeric(12,2) notnull" json:"amount"` Amount decimal.Decimal `xorm:"numeric(12,2) not null" json:"amount"`
Settled bool `xorm:"bool notnull" json:"settled"` Settled bool `xorm:"bool not null default false" json:"settled"`
SettledAt *time.Time `xorm:"timestampz" json:"settledAt"` SettledAt *time.Time `xorm:"timestampz" json:"settledAt"`
Refunded bool `xorm:"bool not null default false" json:"refunded"`
RefundedAt *time.Time `xorm:"timestampz" json:"refundedAt"`
} }
func (UserCharge) TableName() string { func (UserCharge) TableName() string {

View File

@ -8,15 +8,16 @@ import (
type UserDetail struct { type UserDetail struct {
CreatedAndModifiedWithUser `xorm:"extends"` CreatedAndModifiedWithUser `xorm:"extends"`
Id string `xorm:"varchar(120) pk notnull" json:"id"` DeletedWithUser `xorm:"extends"`
Id string `xorm:"varchar(120) pk not null" json:"id"`
Name *string `xorm:"varchar(100)" json:"name"` Name *string `xorm:"varchar(100)" json:"name"`
Abbr *string `xorm:"varchar(50)" json:"abbr"` Abbr *string `xorm:"varchar(50)" json:"abbr"`
Region *string `xorm:"varchar(10)" json:"region"` Region *string `xorm:"varchar(10)" json:"region"`
Address *string `xorm:"varchar(120)" json:"address"` Address *string `xorm:"varchar(120)" json:"address"`
Contact *string `xorm:"varchar(100)" json:"contact"` Contact *string `xorm:"varchar(100)" json:"contact"`
Phone *string `xorm:"varchar(50)" json:"phone"` Phone *string `xorm:"varchar(50)" json:"phone"`
UnitServiceFee decimal.Decimal `xorm:"numeric(8,2) notnull" json:"unitServiceFee"` UnitServiceFee decimal.Decimal `xorm:"numeric(8,2) not null" json:"unitServiceFee"`
ServiceExpiration time.Time `xorm:"date notnull" json:"serviceExpiration"` ServiceExpiration time.Time `xorm:"date not null" json:"serviceExpiration"`
} }
func (UserDetail) TableName() string { func (UserDetail) TableName() string {

View File

@ -4,10 +4,10 @@ import "github.com/shopspring/decimal"
type WillDilutedFee struct { type WillDilutedFee struct {
CreatedAndModified `xorm:"extends"` CreatedAndModified `xorm:"extends"`
Id string `xorm:"varchar(120) pk notnull" json:"id"` Id string `xorm:"varchar(120) pk not null" json:"id"`
ReportId string `xorm:"varchar(120) notnull" json:"reportId"` ReportId string `xorm:"varchar(120) not null" json:"reportId"`
Name string `xorm:"varchar(50) notnull" json:"name"` Name string `xorm:"varchar(50) not null" json:"name"`
Fee decimal.Decimal `xorm:"numeric(8,2) notnull" json:"fee"` Fee decimal.Decimal `xorm:"numeric(8,2) not null" json:"fee"`
Memo *string `xorm:"text" json:"memo"` Memo *string `xorm:"text" json:"memo"`
} }