forked from free-lancers/electricity_bill_calc_service
		
	合并分支
This commit is contained in:
		
							
								
								
									
										92
									
								
								model/calculate/calculate.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								model/calculate/calculate.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | ||||
| package calculate | ||||
|  | ||||
| import ( | ||||
| 	"electricity_bill_calc/model" | ||||
| 	"electricity_bill_calc/types" | ||||
|  | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| type Reading struct { | ||||
| 	ReadAt   types.DateTime | ||||
| 	Ratio    decimal.Decimal | ||||
| 	Overall  decimal.Decimal | ||||
| 	Critical decimal.Decimal | ||||
| 	Peak     decimal.Decimal | ||||
| 	Flat     decimal.Decimal | ||||
| 	Valley   decimal.Decimal | ||||
| } | ||||
|  | ||||
| type Pooling struct { | ||||
| 	Code   string | ||||
| 	Detail model.ConsumptionUnit | ||||
| } | ||||
|  | ||||
| type Meter struct { | ||||
| 	Code                    string | ||||
| 	Detail                  model.MeterDetail | ||||
| 	CoveredArea             decimal.Decimal | ||||
| 	LastTermReading         *Reading | ||||
| 	CurrentTermReading      *Reading | ||||
| 	Overall                 model.ConsumptionUnit | ||||
| 	Critical                model.ConsumptionUnit | ||||
| 	Peak                    model.ConsumptionUnit | ||||
| 	Flat                    model.ConsumptionUnit | ||||
| 	Valley                  model.ConsumptionUnit | ||||
| 	AdjustLoss              model.ConsumptionUnit | ||||
| 	PooledBasic             model.ConsumptionUnit | ||||
| 	PooledAdjust            model.ConsumptionUnit | ||||
| 	PooledLoss              model.ConsumptionUnit | ||||
| 	PooledPublic            model.ConsumptionUnit | ||||
| 	SharedPoolingProportion decimal.Decimal | ||||
| 	Poolings                []*Pooling | ||||
| } | ||||
|  | ||||
| type TenementCharge struct { | ||||
| 	Tenement     string | ||||
| 	Overall      model.ConsumptionUnit | ||||
| 	Critical     model.ConsumptionUnit | ||||
| 	Peak         model.ConsumptionUnit | ||||
| 	Flat         model.ConsumptionUnit | ||||
| 	Valley       model.ConsumptionUnit | ||||
| 	BasicFee     decimal.Decimal | ||||
| 	AdjustFee    decimal.Decimal | ||||
| 	LossPooled   decimal.Decimal | ||||
| 	PublicPooled decimal.Decimal | ||||
| 	FinalCharges decimal.Decimal | ||||
| 	Submeters    []*Meter | ||||
| 	Poolings     []*Meter | ||||
| } | ||||
|  | ||||
| type Summary struct { | ||||
| 	ReportId                     string | ||||
| 	OverallArea                  decimal.Decimal | ||||
| 	Overall                      model.ConsumptionUnit | ||||
| 	ConsumptionFee               decimal.Decimal | ||||
| 	Critical                     model.ConsumptionUnit | ||||
| 	Peak                         model.ConsumptionUnit | ||||
| 	Flat                         model.ConsumptionUnit | ||||
| 	Valley                       model.ConsumptionUnit | ||||
| 	Loss                         decimal.Decimal | ||||
| 	LossFee                      decimal.Decimal | ||||
| 	LossProportion               decimal.Decimal | ||||
| 	AuthoizeLoss                 model.ConsumptionUnit | ||||
| 	BasicFee                     decimal.Decimal | ||||
| 	BasicPooledPriceConsumption  decimal.Decimal | ||||
| 	BasicPooledPriceArea         decimal.Decimal | ||||
| 	AdjustFee                    decimal.Decimal | ||||
| 	AdjustPooledPriceConsumption decimal.Decimal | ||||
| 	AdjustPooledPriceArea        decimal.Decimal | ||||
| 	LossDilutedPrice             decimal.Decimal | ||||
| 	TotalConsumption             decimal.Decimal | ||||
| 	FinalDilutedOverall          decimal.Decimal | ||||
| } | ||||
|  | ||||
| type PoolingSummary struct { | ||||
| 	Tenement          string | ||||
| 	Meter             string | ||||
| 	TargetMeter       string | ||||
| 	Area              decimal.NullDecimal | ||||
| 	OverallAmount     decimal.Decimal | ||||
| 	PoolingProportion decimal.Decimal | ||||
| } | ||||
							
								
								
									
										32
									
								
								model/charge.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								model/charge.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"electricity_bill_calc/types" | ||||
|  | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| type UserChargeDetail struct { | ||||
| 	Seq         int64           `json:"seq"` | ||||
| 	UserId      string          `json:"userId" db:"user_id"` | ||||
| 	Name        string          `json:"name"` | ||||
| 	Fee         *float64        `json:"fee"` | ||||
| 	Discount    *float64        `json:"discount"` | ||||
| 	Amount      *float64        `json:"amount"` | ||||
| 	ChargeTo    types.Date      `json:"chargeTo"` | ||||
| 	Settled     bool            `json:"settled"` | ||||
| 	SettledAt   *types.DateTime `json:"settledAt"` | ||||
| 	Cancelled   bool            `json:"cancelled"` | ||||
| 	CancelledAt *types.DateTime `json:"cancelledAt"` | ||||
| 	Refunded    bool            `json:"refunded"` | ||||
| 	RefundedAt  *types.DateTime `json:"refundedAt"` | ||||
| 	CreatedAt   types.DateTime  `json:"createdAt"` | ||||
| } | ||||
|  | ||||
| type ChargeRecordCreationForm struct { | ||||
| 	UserId   string              `json:"userId"` | ||||
| 	Fee      decimal.NullDecimal `json:"fee"` | ||||
| 	Discount decimal.NullDecimal `json:"discount"` | ||||
| 	Amount   decimal.NullDecimal `json:"amount"` | ||||
| 	ChargeTo types.Date          `json:"chargeTo"` | ||||
| } | ||||
							
								
								
									
										10
									
								
								model/cunsumption.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								model/cunsumption.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| package model | ||||
|  | ||||
| import "github.com/shopspring/decimal" | ||||
|  | ||||
| type ConsumptionUnit struct { | ||||
| 	Amount     decimal.Decimal `json:"amount"` | ||||
| 	Fee        decimal.Decimal `json:"fee"` | ||||
| 	Price      decimal.Decimal `json:"price"` | ||||
| 	Proportion decimal.Decimal `json:"proportion"` | ||||
| } | ||||
							
								
								
									
										90
									
								
								model/enums.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								model/enums.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	ELECTRICITY_CATE_TWO_PART int16 = iota | ||||
| 	ELECTRICITY_CATE_UNITARY_PV | ||||
| 	ELECTRICITY_CATE_FULL_PV | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	METER_TYPE_UNITARY int16 = iota | ||||
| 	METER_TYPE_PV | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	METER_INSTALLATION_TENEMENT int16 = iota | ||||
| 	METER_INSTALLATION_PARK | ||||
| 	METER_INSTALLATION_POOLING | ||||
| ) | ||||
|  | ||||
| func ParseMeterInstallationType(s string) (int16, error) { | ||||
| 	switch { | ||||
| 	case strings.Contains(s, "商户"): | ||||
| 		return METER_INSTALLATION_TENEMENT, nil | ||||
| 	case strings.Contains(s, "公共"): | ||||
| 		return METER_INSTALLATION_PARK, nil | ||||
| 	case strings.Contains(s, "楼道"): | ||||
| 		return METER_INSTALLATION_POOLING, nil | ||||
| 	default: | ||||
| 		return -1, fmt.Errorf("提供了一个无法识别的表计类型: %s", s) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| const ( | ||||
| 	PRICING_POLICY_CONSUMPTION int16 = iota | ||||
| 	PRICING_POLICY_ALL | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	POOLING_MODE_NONE int16 = iota | ||||
| 	POOLING_MODE_CONSUMPTION | ||||
| 	POOLING_MODE_AREA | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	PAYMENT_CASH int16 = iota | ||||
| 	PAYMENT_BANK_CARD | ||||
| 	PAYMENT_ALIPAY | ||||
| 	PAYMENT_WECHAT | ||||
| 	PAYMENT_UNION_PAY | ||||
| 	PAYMENT_OTHER int16 = 99 | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	METER_TELEMETER_HYBRID int16 = iota | ||||
| 	METER_TELEMETER_AUTOMATIC | ||||
| 	METER_TELEMETER_MANUAL | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	RETRY_INTERVAL_ALGORITHM_EXPONENTIAL_BACKOFF int16 = iota | ||||
| 	RETRY_INTERVAL_ALGORITHM_DOUBLE_LINEAR_BACKOFF | ||||
| 	RETRY_INTERVAL_ALGORITHM_TRIPLE_LINEAR_BACKOFF | ||||
| 	RETRY_INTERVAL_ALGORITHM_FIXED | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	TAX_METHOD_INCLUSIVE int16 = iota | ||||
| 	TAX_METHOD_EXCLUSIVE | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	REPORT_CALCULATE_TASK_STATUS_PENDING int16 = iota | ||||
| 	REPORT_CALCULATE_TASK_STATUS_SUCCESS | ||||
| 	REPORT_CALCULATE_TASK_STATUS_INSUFICIENT_DATA | ||||
| 	REPORT_CALCULATE_TASK_STATUS_SUSPENDED | ||||
| 	REPORT_CALCULATE_TASK_STATUS_UNKNOWN_ERROR | ||||
| 	REPORT_CALCULATE_TASK_STATUS_UNEXISTS = 99 | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	REPORT_WITHDRAW_NON int16 = iota | ||||
| 	REPORT_WITHDRAW_APPLYING | ||||
| 	REPORT_WITHDRAW_DENIED | ||||
| 	REPORT_WITHDRAW_GRANTED | ||||
| ) | ||||
							
								
								
									
										45
									
								
								model/invoice.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								model/invoice.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"electricity_bill_calc/tools" | ||||
| 	"electricity_bill_calc/types" | ||||
|  | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| type InvoiceTitle struct { | ||||
| 	Name    string `json:"name"` | ||||
| 	USCI    string `json:"usci"` | ||||
| 	Address string `json:"address"` | ||||
| 	Phone   string `json:"phone"` | ||||
| 	Bank    string `json:"bank"` | ||||
| 	Account string `json:"account"` | ||||
| } | ||||
|  | ||||
| type InvoiceCargo struct { | ||||
| 	Name     string          `json:"name"` | ||||
| 	Price    decimal.Decimal `json:"price"` | ||||
| 	Unit     string          `json:"unit"` | ||||
| 	Quantity decimal.Decimal `json:"quantity"` | ||||
| 	TaxRate  decimal.Decimal `json:"taxRate"` | ||||
| 	Tax      decimal.Decimal `json:"tax"` | ||||
| 	Total    decimal.Decimal `json:"total"` | ||||
| } | ||||
|  | ||||
| type Invoice struct { | ||||
| 	InvoiceNo   string          `json:"invoiceNo"` | ||||
| 	Park        string          `json:"parkId" db:"park_id"` | ||||
| 	Tenement    string          `json:"tenementId" db:"tenement_id"` | ||||
| 	InvoiceType *string         `json:"type" db:"type"` | ||||
| 	Info        InvoiceTitle    `json:"invoiceInfo" db:"invoice_info"` | ||||
| 	Cargos      []InvoiceCargo  `json:"cargos"` | ||||
| 	TaxRate     decimal.Decimal `json:"taxRate" db:"tax_rate"` | ||||
| 	TaxMethod   int16           `json:"taxMethod" db:"tax_method"` | ||||
| 	Total       decimal.Decimal `json:"total" db:"total"` | ||||
| 	IssuedAt    types.DateTime  `json:"issuedAt" db:"issued_at"` | ||||
| 	Covers      []string        `json:"covers"` | ||||
| } | ||||
|  | ||||
| func (i Invoice) Type() string { | ||||
| 	return tools.DefaultOrEmptyStr(i.InvoiceType, "") | ||||
| } | ||||
							
								
								
									
										106
									
								
								model/meter.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								model/meter.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,106 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"electricity_bill_calc/types" | ||||
|  | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| type MeterDetail struct { | ||||
| 	Code           string              `json:"code" db:"code"` | ||||
| 	Park           string              `json:"parkId" db:"park_id"` | ||||
| 	Address        *string             `json:"address" db:"address"` | ||||
| 	MeterType      int16               `json:"type" db:"meter_type"` | ||||
| 	Building       *string             `json:"building" db:"building"` | ||||
| 	BuildingName   *string             `json:"buildingName" db:"building_name"` | ||||
| 	OnFloor        *string             `json:"onFloor" db:"on_floor" ` | ||||
| 	Area           decimal.NullDecimal `json:"area" db:"area"` | ||||
| 	Ratio          decimal.Decimal     `json:"ratio" db:"ratio"` | ||||
| 	Seq            int64               `json:"seq" db:"seq"` | ||||
| 	Enabled        bool                `json:"enabled" db:"enabled"` | ||||
| 	AttachedAt     *types.DateTime     `json:"attachedAt" db:"attached_at"` | ||||
| 	DetachedAt     *types.DateTime     `json:"detachedAt" db:"detached_at"` | ||||
| 	CreatedAt      types.DateTime      `json:"createdAt" db:"created_at"` | ||||
| 	LastModifiedAt types.DateTime      `json:"lastModifiedAt" db:"last_modified_at"` | ||||
| } | ||||
|  | ||||
| type MeterRelation struct { | ||||
| 	Id            string          `json:"id"` | ||||
| 	Park          string          `json:"parkId" db:"park_id"` | ||||
| 	MasterMeter   string          `json:"masterMeterId" db:"master_meter_id"` | ||||
| 	SlaveMeter    string          `json:"slaveMeterId" db:"slave_meter_id"` | ||||
| 	EstablishedAt types.DateTime  `json:"establishedAt"` | ||||
| 	SuspendedAt   *types.DateTime `json:"suspendedAt"` | ||||
| 	RevokedAt     *types.DateTime `json:"revokedAt"` | ||||
| } | ||||
|  | ||||
| type MeterSynchronization struct { | ||||
| 	Park               string          `json:"parkId" db:"park_id"` | ||||
| 	Meter              string          `json:"meterId" db:"meter_id"` | ||||
| 	ForeignMeter       string          `json:"foreignMeter"` | ||||
| 	SystemType         string          `json:"systemType"` | ||||
| 	SystemIdentity     string          `json:"systemIdentity"` | ||||
| 	Enabled            bool            `json:"enabled"` | ||||
| 	LastSynchronizedAt types.DateTime  `json:"lastSynchronizedAt" db:"last_synchronized_at"` | ||||
| 	RevokeAt           *types.DateTime `json:"revokeAt" db:"revoke_at"` | ||||
| } | ||||
|  | ||||
| type SimpleMeterDocument struct { | ||||
| 	Code         string          `json:"code"` | ||||
| 	Seq          int64           `json:"seq"` | ||||
| 	Address      *string         `json:"address"` | ||||
| 	Ratio        decimal.Decimal `json:"ratio"` | ||||
| 	TenementName *string         `json:"tenementName"` | ||||
| } | ||||
|  | ||||
| type NestedMeter struct { | ||||
| 	MeterId             string          `json:"meterId"` | ||||
| 	MeterDetail         MeterDetail     `json:"meterDetail"` | ||||
| 	LastTermReadings    Reading         `json:"lastTermReadings"` | ||||
| 	CurrentTermReadings Reading         `json:"currentTermReadings"` | ||||
| 	Overall             ConsumptionUnit `json:"overall"` | ||||
| 	Critical            ConsumptionUnit `json:"critical"` | ||||
| 	Peak                ConsumptionUnit `json:"peak"` | ||||
| 	Flat                ConsumptionUnit `json:"flat"` | ||||
| 	Valley              ConsumptionUnit `json:"valley"` | ||||
| 	BasicPooled         decimal.Decimal `json:"basicPooled"` | ||||
| 	AdjustPooled        decimal.Decimal `json:"adjustPooled"` | ||||
| 	LossPooled          decimal.Decimal `json:"lossPooled"` | ||||
| 	PublicPooled        decimal.Decimal `json:"publicPooled"` | ||||
| 	FinalTotal          decimal.Decimal `json:"finalTotal"` | ||||
| 	Area                decimal.Decimal `json:"area"` | ||||
| 	Proportion          decimal.Decimal `json:"proportion"` | ||||
| } | ||||
|  | ||||
| type PooledMeterDetailCompound struct { | ||||
| 	MeterDetail | ||||
| 	BindMeters []MeterDetail `json:"bindedMeters"` | ||||
| } | ||||
|  | ||||
| // 以下结构体用于导入表计档案数据 | ||||
| type MeterImportRow struct { | ||||
| 	Code      string              `json:"code" excel:"code"` | ||||
| 	Address   *string             `json:"address" excel:"address"` | ||||
| 	MeterType *string             `json:"meterType" excel:"meterType"` | ||||
| 	Building  *string             `json:"building" excel:"building"` | ||||
| 	OnFloor   *string             `json:"onFloor" excel:"onFloor"` | ||||
| 	Area      decimal.NullDecimal `json:"area" excel:"area"` | ||||
| 	Ratio     decimal.Decimal     `json:"ratio" excel:"ratio"` | ||||
| 	Seq       int64               `json:"seq" excel:"seq"` | ||||
| 	ReadAt    types.DateTime      `json:"readAt" excel:"readAt"` | ||||
| 	Overall   decimal.Decimal     `json:"overall" excel:"overall"` | ||||
| 	Critical  decimal.NullDecimal `json:"critical" excel:"critical"` | ||||
| 	Peak      decimal.NullDecimal `json:"peak" excel:"peak"` | ||||
| 	Flat      decimal.NullDecimal `json:"flat" excel:"flat"` | ||||
| 	Valley    decimal.NullDecimal `json:"valley" excel:"valley"` | ||||
| } | ||||
|  | ||||
| // 以下结构体用于导入表计抄表数据 | ||||
| type ReadingImportRow struct { | ||||
| 	Code     string              `json:"code" excel:"code"` | ||||
| 	ReadAt   types.DateTime      `json:"readAt" excel:"readAt"` | ||||
| 	Overall  decimal.Decimal     `json:"overall" excel:"overall"` | ||||
| 	Critical decimal.NullDecimal `json:"critical" excel:"critical"` | ||||
| 	Peak     decimal.NullDecimal `json:"peak" excel:"peak"` | ||||
| 	Valley   decimal.NullDecimal `json:"valley" excel:"valley"` | ||||
| } | ||||
| @@ -1,89 +1,33 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/jinzhu/copier" | ||||
| 	"github.com/shopspring/decimal" | ||||
| 	"github.com/uptrace/bun" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	CATEGORY_TWO_PART int8 = iota | ||||
| 	CATEGORY_SINGLE_PV | ||||
| 	CATEGORY_SINGLE_NON_PV | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	CUSTOMER_METER_NON_PV int8 = iota | ||||
| 	CUSTOMER_METER_PV | ||||
| ) | ||||
|  | ||||
| type Park struct { | ||||
| 	bun.BaseModel      `bun:"table:park,alias:p"` | ||||
| 	CreatedAndModified `bun:"extend"` | ||||
| 	Deleted            `bun:"extend"` | ||||
| 	Id                 string              `bun:",pk,notnull" json:"id"` | ||||
| 	UserId             string              `bun:",notnull" json:"userId"` | ||||
| 	Name               string              `bun:",notnull" json:"name"` | ||||
| 	Abbr               *string             `json:"abbr"` | ||||
| 	Area               decimal.NullDecimal `bun:"type:numeric" json:"area"` | ||||
| 	TenementQuantity   decimal.NullDecimal `bun:"type:numeric" json:"tenement"` | ||||
| 	Capacity           decimal.NullDecimal `bun:"type:numeric" json:"capacity"` | ||||
| 	Category           int8                `bun:"type:smallint,notnull" json:"category"` | ||||
| 	SubmeterType       int8                `bun:"meter_04kv_type,type:smallint,notnull" json:"meter04kvType"` | ||||
| 	Region             *string             `json:"region"` | ||||
| 	Address            *string             `json:"address"` | ||||
| 	Contact            *string             `json:"contact"` | ||||
| 	Phone              *string             `json:"phone"` | ||||
| 	Enabled            bool                `bun:",notnull" json:"enabled"` | ||||
| 	EnterpriseIndex    *User               `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:"-"` | ||||
| 	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 { | ||||
| 	bun.BaseModel    `bun:"table:park,alias:p"` | ||||
| 	Id               string              `bun:",pk,notnull" json:"id"` | ||||
| 	UserId           string              `bun:",notnull" json:"userId"` | ||||
| 	Name             string              `bun:",notnull" json:"name"` | ||||
| 	Abbr             *string             `json:"abbr"` | ||||
| 	Id               string              `json:"id"` | ||||
| 	UserId           string              `json:"userId"` | ||||
| 	Name             string              `json:"name"` | ||||
| 	Abbr             string              `json:"-"` | ||||
| 	Area             decimal.NullDecimal `json:"area"` | ||||
| 	TenementQuantity decimal.NullDecimal `json:"tenement"` | ||||
| 	Capacity         decimal.NullDecimal `json:"capacity"` | ||||
| 	Category         int8                `bun:"type:smallint,notnull" json:"category"` | ||||
| 	SubmeterType     int8                `bun:"meter_04kv_type,type:smallint,notnull" json:"meter04kvType"` | ||||
| 	Category         int16               `json:"category"` | ||||
| 	MeterType        int16               `json:"meter04kvType" db:"meter_04kv_type"` | ||||
| 	PricePolicy      int16               `json:"pricePolicy"` | ||||
| 	BasicPooled      int16               `json:"basicDiluted"` | ||||
| 	AdjustPooled     int16               `json:"adjustDiluted"` | ||||
| 	LossPooled       int16               `json:"lossDiluted"` | ||||
| 	PublicPooled     int16               `json:"publicDiluted"` | ||||
| 	TaxRate          decimal.NullDecimal `json:"taxRate"` | ||||
| 	Region           *string             `json:"region"` | ||||
| 	Address          *string             `json:"address"` | ||||
| 	Contact          *string             `json:"contact"` | ||||
| 	Phone            *string             `json:"phone"` | ||||
| } | ||||
|  | ||||
| type ParkPeriodStatistics struct { | ||||
| 	Id     string `bun:"park__id,notnull" json:"id"` | ||||
| 	Name   string `bun:"park__name,notnull" json:"name"` | ||||
| 	Period *Date  `bun:"type:date" json:"period"` | ||||
| } | ||||
|  | ||||
| func FromPark(park Park) ParkSimplified { | ||||
| 	dest := ParkSimplified{} | ||||
| 	copier.Copy(&dest, park) | ||||
| 	return dest | ||||
| } | ||||
|  | ||||
| var _ bun.BeforeAppendModelHook = (*Park)(nil) | ||||
|  | ||||
| func (p *Park) BeforeAppendModel(ctx context.Context, query bun.Query) error { | ||||
| 	oprTime := time.Now() | ||||
| 	switch query.(type) { | ||||
| 	case *bun.InsertQuery: | ||||
| 		p.CreatedAt = oprTime | ||||
| 		p.LastModifiedAt = &oprTime | ||||
| 	case *bun.UpdateQuery: | ||||
| 		p.LastModifiedAt = &oprTime | ||||
| 	} | ||||
| 	return nil | ||||
| 	Enabled          bool                `json:"enabled"` | ||||
| 	CreatedAt        time.Time           `json:"createdAt"` | ||||
| 	LastModifiedAt   time.Time           `json:"lastModifiedAt"` | ||||
| 	DeletedAt        *time.Time          `json:"deletedAt"` | ||||
| } | ||||
|   | ||||
							
								
								
									
										14
									
								
								model/park_building.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								model/park_building.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| package model | ||||
|  | ||||
| import "time" | ||||
|  | ||||
| type ParkBuilding struct { | ||||
| 	Id             string     `json:"id"` | ||||
| 	Park           string     `json:"parkId" db:"park_id"` | ||||
| 	Name           string     `json:"name"` | ||||
| 	Floors         *string    `json:"floors"` | ||||
| 	Enabled        bool       `json:"enabled"` | ||||
| 	CreatedAt      time.Time  `json:"createdAt"` | ||||
| 	LastModifiedAt time.Time  `json:"lastModifiedAt"` | ||||
| 	DeletedAt      *time.Time `json:"deletedAt"` | ||||
| } | ||||
							
								
								
									
										56
									
								
								model/reading.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								model/reading.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"electricity_bill_calc/types" | ||||
|  | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| type Reading struct { | ||||
| 	Ratio    decimal.Decimal `json:"ratio"` | ||||
| 	Overall  decimal.Decimal `json:"overall"` | ||||
| 	Critical decimal.Decimal `json:"critical"` | ||||
| 	Peak     decimal.Decimal `json:"peak"` | ||||
| 	Flat     decimal.Decimal `json:"flat"` | ||||
| 	Valley   decimal.Decimal `json:"valley"` | ||||
| } | ||||
|  | ||||
| func NewPVReading(ratio, overall, critical, peak, flat, valley decimal.Decimal) *Reading { | ||||
| 	return &Reading{ | ||||
| 		Ratio:    ratio, | ||||
| 		Overall:  overall, | ||||
| 		Critical: critical, | ||||
| 		Peak:     peak, | ||||
| 		Flat:     flat, | ||||
| 		Valley:   valley, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func NewUnitaryReading(ratio, overall decimal.Decimal) *Reading { | ||||
| 	return &Reading{ | ||||
| 		Ratio:    ratio, | ||||
| 		Overall:  overall, | ||||
| 		Critical: decimal.Zero, | ||||
| 		Peak:     decimal.Zero, | ||||
| 		Flat:     overall, | ||||
| 		Valley:   decimal.Zero, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type MeterReading struct { | ||||
| 	ReadAt    types.DateTime  `json:"readAt"` | ||||
| 	Park      string          `json:"parkId" db:"park_id"` | ||||
| 	Meter     string          `json:"meterId" db:"meter_id"` | ||||
| 	MeterType int16           `json:"meterType"` | ||||
| 	Ratio     decimal.Decimal `json:"ratio"` | ||||
| 	Overall   decimal.Decimal `json:"overall"` | ||||
| 	Critical  decimal.Decimal `json:"critical"` | ||||
| 	Peak      decimal.Decimal `json:"peak"` | ||||
| 	Flat      decimal.Decimal `json:"flat"` | ||||
| 	Valley    decimal.Decimal `json:"valley"` | ||||
| } | ||||
|  | ||||
| type DetailedMeterReading struct { | ||||
| 	Detail  MeterDetail  `json:"detail"` | ||||
| 	Reading MeterReading `json:"reading"` | ||||
| } | ||||
| @@ -1,11 +1,8 @@ | ||||
| package model | ||||
|  | ||||
| import "github.com/uptrace/bun" | ||||
|  | ||||
| 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" json:"level"` | ||||
| 	Parent        string `bun:",notnull" json:"parent"` | ||||
| 	Code   string `json:"code"` | ||||
| 	Name   string `json:"name"` | ||||
| 	Level  int32  `json:"level"` | ||||
| 	Parent string `json:"parent"` | ||||
| } | ||||
|   | ||||
							
								
								
									
										192
									
								
								model/report.go
									
									
									
									
									
								
							
							
						
						
									
										192
									
								
								model/report.go
									
									
									
									
									
								
							| @@ -1,99 +1,137 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"time" | ||||
| 	"electricity_bill_calc/types" | ||||
|  | ||||
| 	"github.com/uptrace/bun" | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	REPORT_NOT_WITHDRAW int8 = iota | ||||
| 	REPORT_WITHDRAW_APPLIED | ||||
| 	REPORT_WITHDRAW_DENIED | ||||
| 	REPORT_WITHDRAW_GRANTED | ||||
| ) | ||||
|  | ||||
| type Report struct { | ||||
| 	bun.BaseModel         `bun:"table:report,alias:r"` | ||||
| 	CreatedAndModified    `bun:"extend"` | ||||
| 	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" 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" json:"published"` | ||||
| 	PublishedAt           *time.Time        `bun:"type:timestamptz,nullzero" json:"publishedAt" time_format:"simple_datetime" time_location:"shanghai"` | ||||
| 	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:"-"` | ||||
| 	Summary               *ReportSummary    `bun:"rel:has-one,join:id=report_id" json:"-"` | ||||
| 	WillDilutedFees       []*WillDilutedFee `bun:"rel:has-many,join:id=report_id" json:"-"` | ||||
| 	EndUsers              []*EndUserDetail  `bun:"rel:has-many,join:id=report_id,join:park_id=park_id" json:"-"` | ||||
| type ReportIndex struct { | ||||
| 	Id                    string          `json:"id"` | ||||
| 	Park                  string          `json:"parkId" db:"park_id"` | ||||
| 	Period                types.DateRange `json:"period"` | ||||
| 	Category              int16           `json:"category"` | ||||
| 	MeterType             int16           `json:"meter04kvType" db:"meter_04kv_type"` | ||||
| 	PricePolicy           int16           `json:"pricePolicy"` | ||||
| 	BasisPooled           int16           `json:"basisPooled"` | ||||
| 	AdjustPooled          int16           `json:"adjustPooled"` | ||||
| 	LossPooled            int16           `json:"lossPooled"` | ||||
| 	PublicPooled          int16           `json:"publicPooled"` | ||||
| 	Published             bool            `json:"published"` | ||||
| 	PublishedAt           *types.DateTime `json:"publishedAt" db:"published_at"` | ||||
| 	Withdraw              int16           `json:"withdraw"` | ||||
| 	LastWithdrawAppliedAt *types.DateTime `json:"lastWithdrawAppliedAt" db:"last_withdraw_applied_at"` | ||||
| 	LastWithdrawAuditAt   *types.DateTime `json:"lastWithdrawAuditAt" db:"last_withdraw_audit_at"` | ||||
| 	Status                *int16          `json:"status"` | ||||
| 	Message               *string         `json:"message"` | ||||
| 	CreatedAt             types.DateTime  `json:"createdAt" db:"created_at"` | ||||
| 	LastModifiedAt        types.DateTime  `json:"lastModifiedAt" db:"last_modified_at"` | ||||
| } | ||||
|  | ||||
| type Steps struct { | ||||
| 	Summary     bool `json:"summary"` | ||||
| 	WillDiluted bool `json:"willDiluted"` | ||||
| 	Submeter    bool `json:"submeter"` | ||||
| 	Calculate   bool `json:"calculate"` | ||||
| 	Preview     bool `json:"preview"` | ||||
| 	Publish     bool `json:"publish"` | ||||
| type ReportSummary struct { | ||||
| 	ReportId                     string              `json:"reportId" db:"report_id"` | ||||
| 	OverallArea                  decimal.Decimal     `json:"overallArea" db:"overall_area"` | ||||
| 	Overall                      ConsumptionUnit     `json:"overall"` | ||||
| 	ConsumptionFee               decimal.NullDecimal `json:"consumptionFee" db:"consumption_fee"` | ||||
| 	Critical                     ConsumptionUnit     `json:"critical"` | ||||
| 	Peak                         ConsumptionUnit     `json:"peak"` | ||||
| 	Flat                         ConsumptionUnit     `json:"flat"` | ||||
| 	Valley                       ConsumptionUnit     `json:"valley"` | ||||
| 	Loss                         decimal.NullDecimal `json:"loss"` | ||||
| 	LossFee                      decimal.NullDecimal `json:"lossFee" db:"loss_fee"` | ||||
| 	LossProportion               decimal.NullDecimal `json:"lossProportion" db:"loss_proportion"` | ||||
| 	AuthorizeLoss                *ConsumptionUnit    `json:"authorizeLoss" db:"authorize_loss"` | ||||
| 	BasicFee                     decimal.Decimal     `json:"basicFee" db:"basic_fee"` | ||||
| 	BasicPooledPriceConsumption  decimal.NullDecimal `json:"basicPooledPriceConsumption" db:"basic_pooled_price_consumption"` | ||||
| 	BasicPooledPriceArea         decimal.NullDecimal `json:"basicPooledPriceArea" db:"basic_pooled_price_area"` | ||||
| 	AdjustFee                    decimal.Decimal     `json:"adjustFee" db:"adjust_fee"` | ||||
| 	AdjustPooledPriceConsumption decimal.NullDecimal `json:"adjustPooledPriceConsumption" db:"adjust_pooled_price_consumption"` | ||||
| 	AdjustPooledPriceArea        decimal.NullDecimal `json:"adjustPooledPriceArea" db:"adjust_pooled_price_area"` | ||||
| 	LossDilutedPrice             decimal.NullDecimal `json:"lossDilutedPrice" db:"loss_diluted_price"` | ||||
| 	TotalConsumption             decimal.Decimal     `json:"totalConsumption" db:"total_consumption"` | ||||
| 	FinalDilutedOverall          decimal.NullDecimal `json:"finalDilutedOverall" db:"final_diluted_overall"` | ||||
| } | ||||
|  | ||||
| func NewSteps() Steps { | ||||
| 	return Steps{ | ||||
| 		Summary:     false, | ||||
| 		WillDiluted: false, | ||||
| 		Submeter:    false, | ||||
| 		Calculate:   false, | ||||
| 		Preview:     false, | ||||
| 		Publish:     false, | ||||
| func (rs ReportSummary) GetConsumptionFee() decimal.Decimal { | ||||
| 	if !rs.ConsumptionFee.Valid { | ||||
| 		return rs.Overall.Fee.Sub(rs.BasicFee).Sub(rs.AdjustFee) | ||||
| 	} | ||||
| 	return rs.ConsumptionFee.Decimal | ||||
| } | ||||
|  | ||||
| type ParkNewestReport struct { | ||||
| 	Park   Park    `bun:"extends" json:"park"` | ||||
| 	Report *Report `bun:"extends" json:"report"` | ||||
| type ReportPublicConsumption struct { | ||||
| 	ReportId         string          `json:"reportId" db:"report_id"` | ||||
| 	MeterId          string          `json:"parkMeterId" db:"park_meter_id"` | ||||
| 	Overall          ConsumptionUnit `json:"overall"` | ||||
| 	Critical         ConsumptionUnit `json:"critical"` | ||||
| 	Peak             ConsumptionUnit `json:"peak"` | ||||
| 	Flat             ConsumptionUnit `json:"flat"` | ||||
| 	Valley           ConsumptionUnit `json:"valley"` | ||||
| 	LossAdjust       ConsumptionUnit `json:"lossAdjust"` | ||||
| 	ConsumptionTotal decimal.Decimal `json:"consumptionTotal" db:"consumption_total"` | ||||
| 	LossAdjustTotal  decimal.Decimal `json:"lossAdjustTotal" db:"loss_adjust_total"` | ||||
| 	FinalTotal       decimal.Decimal `json:"finalTotal" db:"final_total"` | ||||
| 	PublicPooled     int16           `json:"publicPooled" db:"public_pooled"` | ||||
| } | ||||
|  | ||||
| func (p *ParkNewestReport) AfterLoad() { | ||||
| 	if p.Report != nil && len(p.Report.Id) == 0 { | ||||
| 		p.Report = nil | ||||
| 	} | ||||
| type ReportDetailedPublicConsumption struct { | ||||
| 	MeterDetail | ||||
| 	ReportPublicConsumption | ||||
| } | ||||
|  | ||||
| type ReportIndexSimplified struct { | ||||
| 	bun.BaseModel         `bun:"table:report,alias:r"` | ||||
| 	Id                    string     `bun:",pk,notnull" json:"id"` | ||||
| 	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" json:"published"` | ||||
| 	PublishedAt           *time.Time `bun:"type:timestampz" json:"publishedAt" time_format:"simple_datetime" time_location:"shanghai"` | ||||
| 	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"` | ||||
| type ReportPooledConsumption struct { | ||||
| 	ReportId   string          `json:"reportId" db:"report_id"` | ||||
| 	MeterId    string          `json:"pooledMeterId" db:"pooled_meter_id"` | ||||
| 	Overall    ConsumptionUnit `json:"overall"` | ||||
| 	Critical   ConsumptionUnit `json:"critical"` | ||||
| 	Peak       ConsumptionUnit `json:"peak"` | ||||
| 	Flat       ConsumptionUnit `json:"flat"` | ||||
| 	Valley     ConsumptionUnit `json:"valley"` | ||||
| 	PooledArea decimal.Decimal `json:"pooledArea" db:"pooled_area"` | ||||
| 	Diluted    []NestedMeter   `json:"diluted"` | ||||
| } | ||||
|  | ||||
| type JoinedReportForWithdraw struct { | ||||
| 	Report Report               `bun:"extends" json:"report"` | ||||
| 	Park   ParkSimplified       `bun:"extends" json:"park"` | ||||
| 	User   UserDetailSimplified `bun:"extends" json:"user"` | ||||
| type ReportDetailedPooledConsumption struct { | ||||
| 	MeterDetail | ||||
| 	ReportPooledConsumption | ||||
| 	PublicPooled int16 `json:"publicPooled"` | ||||
| } | ||||
|  | ||||
| var _ bun.BeforeAppendModelHook = (*Report)(nil) | ||||
|  | ||||
| func (p *Report) BeforeAppendModel(ctx context.Context, query bun.Query) error { | ||||
| 	oprTime := time.Now() | ||||
| 	switch query.(type) { | ||||
| 	case *bun.InsertQuery: | ||||
| 		p.CreatedAt = oprTime | ||||
| 		p.LastModifiedAt = &oprTime | ||||
| 	case *bun.UpdateQuery: | ||||
| 		p.LastModifiedAt = &oprTime | ||||
| 	} | ||||
| 	return nil | ||||
| type ReportDetailNestedMeterConsumption struct { | ||||
| 	Meter       MeterDetail `json:"meter"` | ||||
| 	Consumption NestedMeter `json:"consumption"` | ||||
| } | ||||
|  | ||||
| type ReportTenement struct { | ||||
| 	ReportId        string          `json:"reportId" db:"report_id"` | ||||
| 	Tenement        string          `json:"tenementId" db:"tenement_id"` | ||||
| 	Detail          Tenement        `json:"tenementDetail" db:"tenement_detail"` | ||||
| 	Period          types.DateRange `json:"calcPeriod" db:"calc_period"` | ||||
| 	Overall         ConsumptionUnit `json:"overall"` | ||||
| 	Critical        ConsumptionUnit `json:"critical"` | ||||
| 	Peak            ConsumptionUnit `json:"peak"` | ||||
| 	Flat            ConsumptionUnit `json:"flat"` | ||||
| 	Valley          ConsumptionUnit `json:"valley"` | ||||
| 	BasicFeePooled  decimal.Decimal `json:"basicFeePooled" db:"basic_fee_pooled"` | ||||
| 	AdjustFeePooled decimal.Decimal `json:"adjustFeePooled" db:"adjust_fee_pooled"` | ||||
| 	LossFeePooled   decimal.Decimal `json:"lossFeePooled" db:"loss_fee_pooled"` | ||||
| 	FinalPooled     decimal.Decimal `json:"finalPooled" db:"final_pooled"` | ||||
| 	FinalCharge     decimal.Decimal `json:"finalCharge" db:"final_charge"` | ||||
| 	Invoice         []string        `json:"invoice" db:"invoice"` | ||||
| 	Meters          []NestedMeter   `json:"meters" db:"meters"` | ||||
| 	Pooled          []NestedMeter   `json:"pooled" db:"pooled"` | ||||
| } | ||||
|  | ||||
| type ReportTask struct { | ||||
| 	Id             string         `json:"id"` | ||||
| 	LastModifiedAt types.DateTime `json:"lastModifiedAt" db:"last_modified_at"` | ||||
| 	Status         int16          `json:"status"` | ||||
| 	Message        *string        `json:"message"` | ||||
| } | ||||
|  | ||||
| type SimplifiedTenementCharge struct { | ||||
| 	ReportId         string          `json:"reportId" db:"report_id"` | ||||
| 	Period           types.DateRange `json:"period"` | ||||
| 	TotalConsumption decimal.Decimal `json:"totalConsumption" db:"total_consumption"` | ||||
| 	FinalCharge      decimal.Decimal `json:"finalCharge" db:"final_charge"` | ||||
| } | ||||
|   | ||||
| @@ -5,7 +5,7 @@ import "time" | ||||
| type Session struct { | ||||
| 	Uid       string    `json:"uid"` | ||||
| 	Name      string    `json:"name"` | ||||
| 	Type      int8      `json:"type"` | ||||
| 	Type      int16     `json:"type"` | ||||
| 	Token     string    `json:"token"` | ||||
| 	ExpiresAt time.Time `json:"expiresAt" time_format:"simple_datetime" time_location:"shanghai"` | ||||
| } | ||||
|   | ||||
							
								
								
									
										38
									
								
								model/synchronize.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								model/synchronize.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"electricity_bill_calc/types" | ||||
| 	_ "github.com/shopspring/decimal" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| type SynchronizeConfiguration struct { | ||||
| 	User                   string    `json:"user" db:"user_id"` | ||||
| 	Park                   string    `json:"park" db:"park_id"` | ||||
| 	MeterReadingType       int16     `json:"meter_reading_type"` | ||||
| 	ImrsType               string    `json:"imrs_type"` | ||||
| 	AuthorizationAccount   string    `json:"authorization_account" db:"imrs_authorization_account"` | ||||
| 	AuthorizationSecret    string    `json:"authorization_secret" db:"imrs_authorization_secret"` | ||||
| 	AuthorizationKey       []byte    `json:"authorization_key,omitempty" db:"imrs_authorization_key"` | ||||
| 	Interval               int16     `json:"interval"` | ||||
| 	CollectAt              time.Time `json:"collect_at" db:"-"` | ||||
| 	MaxRetries             int16     `json:"max_retries"` | ||||
| 	RetryInterval          int16     `json:"retry_interval"` | ||||
| 	RetryIntervalAlgorithm int16     `json:"retry_interval_algorithm"` | ||||
| } | ||||
|  | ||||
| type SynchronizeSchedule struct { | ||||
| 	User               string         `json:"userId" db:"user_id"` | ||||
| 	UserName           string         `json:"userName" db:"user_name"` | ||||
| 	Park               string         `json:"parkId" db:"park_id"` | ||||
| 	ParkName           string         `json:"parkName" db:"park_name"` | ||||
| 	TaskIdentity       string         `json:"taskIdentity" db:"task_identity"` | ||||
| 	TaskName           string         `json:"taskName" db:"task_name"` | ||||
| 	TaskDescription    string         `json:"taskDescription" db:"task_description"` | ||||
| 	CreatedAt          types.DateTime `json:"createdAt" db:"created_at"` | ||||
| 	LastModifiedAt     types.DateTime `json:"lastModifiedAt" db:"last_modified_at"` | ||||
| 	LastDispatchedAt   types.DateTime `json:"lastDispatchedAt" db:"last_dispatched_at"` | ||||
| 	LastDispatchStatus int16          `json:"lastDispatchStatus" db:"last_dispatch_status"` | ||||
| 	NextDispatchAt     types.DateTime `json:"nextDispatchAt" db:"next_dispatch_at"` | ||||
| 	CurrentRetries     int16          `json:"currentRetries" db:"current_retries"` | ||||
| } | ||||
							
								
								
									
										23
									
								
								model/tenement.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								model/tenement.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| package model | ||||
|  | ||||
| import "electricity_bill_calc/types" | ||||
|  | ||||
| type Tenement struct { | ||||
| 	Id             string          `json:"id"` | ||||
| 	Park           string          `json:"parkId" db:"park_id"` | ||||
| 	FullName       string          `json:"fullName" db:"full_name"` | ||||
| 	ShortName      *string         `json:"shortName" db:"short_name"` | ||||
| 	Abbr           string          `json:"-"` | ||||
| 	Address        string          `json:"address"` | ||||
| 	ContactName    string          `json:"contactName" db:"contact_name"` | ||||
| 	ContactPhone   string          `json:"contactPhone" db:"contact_phone"` | ||||
| 	Building       *string         `json:"building"` | ||||
| 	BuildingName   *string         `json:"buildingName" db:"building_name"` | ||||
| 	OnFloor        *string         `json:"onFloor" db:"on_floor"` | ||||
| 	InvoiceInfo    *InvoiceTitle   `json:"invoiceInfo" db:"invoice_info"` | ||||
| 	MovedInAt      *types.DateTime `json:"movedInAt" db:"moved_in_at"` | ||||
| 	MovedOutAt     *types.DateTime `json:"movedOutAt" db:"moved_out_at"` | ||||
| 	CreatedAt      types.DateTime  `json:"createdAt" db:"created_at"` | ||||
| 	LastModifiedAt types.DateTime  `json:"lastModifiedAt" db:"last_modified_at"` | ||||
| 	DeletedAt      *types.DateTime `json:"deletedAt" db:"deleted_at"` | ||||
| } | ||||
							
								
								
									
										33
									
								
								model/top_up.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								model/top_up.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"electricity_bill_calc/types" | ||||
|  | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| type TopUp struct { | ||||
| 	TopUpCode              string          `json:"topUpCode" db:"top_up_code"` | ||||
| 	Park                   string          `json:"parkId" db:"park_id"` | ||||
| 	Tenement               string          `json:"tenementId" db:"tenement_id"` | ||||
| 	TenementName           string          `json:"tenementName" db:"tenement_name"` | ||||
| 	Meter                  string          `json:"meterId" db:"meter_id"` | ||||
| 	MeterAddress           *string         `json:"meterAddress" db:"meter_address"` | ||||
| 	ToppedUpAt             types.DateTime  `json:"toppedUpAt" db:"topped_up_at"` | ||||
| 	Amount                 decimal.Decimal `json:"amount" db:"amount"` | ||||
| 	PaymentType            int16           `json:"paymentType" db:"payment_type"` | ||||
| 	SuccessfulSynchronized bool            `json:"successfulSynchronized" db:"successful_synchronized"` | ||||
| 	SynchronizedAt         *types.DateTime `json:"synchronizedAt" db:"synchronized_at"` | ||||
| 	CancelledAt            *types.DateTime `json:"cancelledAt" db:"cancelled_at"` | ||||
| } | ||||
|  | ||||
| func (t TopUp) SyncStatus() int16 { | ||||
| 	switch { | ||||
| 	case t.SuccessfulSynchronized && t.SynchronizedAt != nil: | ||||
| 		return 1 | ||||
| 	case !t.SuccessfulSynchronized && t.SynchronizedAt != nil: | ||||
| 		return 2 | ||||
| 	default: | ||||
| 		return 0 | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										130
									
								
								model/user.go
									
									
									
									
									
								
							
							
						
						
									
										130
									
								
								model/user.go
									
									
									
									
									
								
							| @@ -1,48 +1,114 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"electricity_bill_calc/types" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/uptrace/bun" | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	USER_TYPE_ENT int8 = iota | ||||
| 	USER_TYPE_ENT int16 = iota | ||||
| 	USER_TYPE_SUP | ||||
| 	USER_TYPE_OPS | ||||
| ) | ||||
|  | ||||
| type User struct { | ||||
| 	bun.BaseModel `bun:"table:user,alias:u"` | ||||
| 	Created       `bun:"extend"` | ||||
| 	Id            string        `bun:",pk,notnull" json:"id"` | ||||
| 	Username      string        `bun:",notnull" json:"username"` | ||||
| 	Password      string        `bun:",notnull" json:"-"` | ||||
| 	ResetNeeded   bool          `bun:",notnull" json:"resetNeeded"` | ||||
| 	Type          int8          `bun:"type:smallint,notnull" json:"type"` | ||||
| 	Enabled       bool          `bun:",notnull" json:"enabled"` | ||||
| 	Detail        *UserDetail   `bun:"rel:has-one,join:id=id" json:"-"` | ||||
| 	Charges       []*UserCharge `bun:"rel:has-many,join:id=user_id" json:"-"` | ||||
| type ManagementAccountCreationForm struct { | ||||
| 	Id       *string    `json:"id"` | ||||
| 	Username string     `json:"username"` | ||||
| 	Name     string     `json:"name"` | ||||
| 	Contact  *string    `json:"contact"` | ||||
| 	Phone    *string    `json:"phone"` | ||||
| 	Type     int16      `json:"type"` | ||||
| 	Enabled  bool       `json:"enabled"` | ||||
| 	Expires  types.Date `json:"expires"` | ||||
| } | ||||
|  | ||||
| type UserWithCredentials struct { | ||||
| 	bun.BaseModel `bun:"table:user,alias:u"` | ||||
| 	Created       `bun:"extend"` | ||||
| 	Id            string `bun:",pk,notnull" json:"id"` | ||||
| 	Username      string `bun:",notnull" json:"username"` | ||||
| 	Password      string `bun:",notnull" json:"credential"` | ||||
| 	ResetNeeded   bool   `bun:",notnull" json:"resetNeeded"` | ||||
| 	Type          int8   `bun:"type:smallint,notnull" json:"type"` | ||||
| 	Enabled       bool   `bun:",notnull" json:"enabled"` | ||||
| } | ||||
|  | ||||
| var _ bun.BeforeAppendModelHook = (*User)(nil) | ||||
|  | ||||
| func (u *User) BeforeAppendModel(ctx context.Context, query bun.Query) error { | ||||
| 	switch query.(type) { | ||||
| 	case *bun.InsertQuery: | ||||
| 		u.CreatedAt = time.Now() | ||||
| func (m ManagementAccountCreationForm) IntoUser() *User { | ||||
| 	return &User{ | ||||
| 		Id:          *m.Id, | ||||
| 		Username:    m.Username, | ||||
| 		Password:    "", | ||||
| 		ResetNeeded: false, | ||||
| 		UserType:    m.Type, | ||||
| 		Enabled:     m.Enabled, | ||||
| 		CreatedAt:   nil, | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (m ManagementAccountCreationForm) IntoUserDetail() *UserDetail { | ||||
| 	return &UserDetail{ | ||||
| 		Id:                *m.Id, | ||||
| 		Name:              &m.Name, | ||||
| 		Abbr:              nil, | ||||
| 		Region:            nil, | ||||
| 		Address:           nil, | ||||
| 		Contact:           m.Contact, | ||||
| 		Phone:             m.Phone, | ||||
| 		UnitServiceFee:    decimal.Zero, | ||||
| 		ServiceExpiration: m.Expires, | ||||
| 		CreatedAt:         types.Now(), | ||||
| 		CreatedBy:         nil, | ||||
| 		LastModifiedAt:    types.Now(), | ||||
| 		LastModifiedBy:    nil, | ||||
| 		DeletedAt:         nil, | ||||
| 		DeletedBy:         nil, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type UserModificationForm struct { | ||||
| 	Name           string           `json:"name"` | ||||
| 	Region         *string          `json:"region"` | ||||
| 	Address        *string          `json:"address"` | ||||
| 	Contact        *string          `json:"contact"` | ||||
| 	Phone          *string          `json:"phone"` | ||||
| 	UnitServiceFee *decimal.Decimal `json:"unitServiceFee"` | ||||
| } | ||||
|  | ||||
| type User struct { | ||||
| 	Id          string     `json:"id"` | ||||
| 	Username    string     `json:"username"` | ||||
| 	Password    string     `json:"password"` | ||||
| 	ResetNeeded bool       `json:"resetNeeded"` | ||||
| 	UserType    int16      `db:"type"` | ||||
| 	Enabled     bool       `json:"enabled"` | ||||
| 	CreatedAt   *time.Time `json:"createdAt"` | ||||
| } | ||||
|  | ||||
| type UserDetail struct { | ||||
| 	Id                string          `json:"id"` | ||||
| 	Name              *string         `json:"name"` | ||||
| 	Abbr              *string         `json:"abbr"` | ||||
| 	Region            *string         `json:"region"` | ||||
| 	Address           *string         `json:"address"` | ||||
| 	Contact           *string         `json:"contact"` | ||||
| 	Phone             *string         `json:"phone"` | ||||
| 	UnitServiceFee    decimal.Decimal `db:"unit_service_fee" json:"unitServiceFee"` | ||||
| 	ServiceExpiration types.Date      `json:"serviceExpiration"` | ||||
| 	CreatedAt         types.DateTime  `json:"createdAt"` | ||||
| 	CreatedBy         *string         `json:"createdBy"` | ||||
| 	LastModifiedAt    types.DateTime  `json:"lastModifiedAt"` | ||||
| 	LastModifiedBy    *string         `json:"lastModifiedBy"` | ||||
| 	DeletedAt         *types.DateTime `json:"deletedAt"` | ||||
| 	DeletedBy         *string         `json:"deletedBy"` | ||||
| } | ||||
|  | ||||
| type UserWithDetail struct { | ||||
| 	Id                string          `json:"id"` | ||||
| 	Username          string          `json:"username"` | ||||
| 	ResetNeeded       bool            `json:"resetNeeded"` | ||||
| 	UserType          int16           `db:"type" json:"type"` | ||||
| 	Enabled           bool            `json:"enabled"` | ||||
| 	Name              *string         `json:"name"` | ||||
| 	Abbr              *string         `json:"abbr"` | ||||
| 	Region            *string         `json:"region"` | ||||
| 	Address           *string         `json:"address"` | ||||
| 	Contact           *string         `json:"contact"` | ||||
| 	Phone             *string         `json:"phone"` | ||||
| 	UnitServiceFee    decimal.Decimal `db:"unit_service_fee" json:"unitServiceFee"` | ||||
| 	ServiceExpiration types.Date      `json:"serviceExpiration"` | ||||
| 	CreatedAt         types.DateTime  `json:"createdAt"` | ||||
| 	CreatedBy         *string         `json:"createdBy"` | ||||
| 	LastModifiedAt    types.DateTime  `json:"lastModifiedAt"` | ||||
| 	LastModifiedBy    *string         `json:"lastModifiedBy"` | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user