合并分支

This commit is contained in:
2023-08-04 17:11:10 +08:00
parent 12ec8d26bf
commit 020e76b901
100 changed files with 12692 additions and 2574 deletions

39
vo/invoice.go Normal file
View File

@@ -0,0 +1,39 @@
package vo
import (
"electricity_bill_calc/model"
"electricity_bill_calc/types"
"github.com/shopspring/decimal"
)
type InvoiceResponse struct {
No string `json:"no" copier:"InvoiceNo"`
Tenement string `json:"tenement"`
Title model.InvoiceTitle `json:"title" copier:"Info"`
IssuedAt types.DateTime `json:"issuedAt"`
Amount decimal.Decimal `json:"amount" copier:"Total"`
TaxMethod int16 `json:"taxMethod"`
TaxRate decimal.Decimal `json:"taxRate"`
InvoiceType string `json:"invoiceType" copier:"Type"`
}
type InvoiceCreationForm struct {
Park string `json:"park"`
Tenement string `json:"tenement"`
TaxMethod int16 `json:"taxMethod"`
TaxRate decimal.NullDecimal `json:"taxRate"`
Covers []string `json:"covers"`
}
type ExtendedInvoiceResponse struct {
InvoiceResponse
Cargos []*model.InvoiceCargo `json:"cargos"`
Covers []*model.SimplifiedTenementCharge `json:"covers"`
}
type ExtendedInvoiceCreationForm struct {
InvoiceCreationForm
InvoiceType *string `json:"invoiceType"`
InvoiceNo string `json:"invoiceNo"`
}

64
vo/meter.go Normal file
View File

@@ -0,0 +1,64 @@
package vo
import (
"electricity_bill_calc/types"
"github.com/shopspring/decimal"
)
type MeterCreationForm struct {
Code string `json:"code"`
Address *string `json:"address"`
Ratio decimal.Decimal `json:"ratio"`
Seq int64 `json:"seq"`
MeterType int16 `json:"type"`
Building *string `json:"building"`
OnFloor *string `json:"onFloor"`
Area decimal.NullDecimal `json:"area"`
Enabled bool `json:"enabled"`
MeterReadingForm `json:"-"`
}
type MeterModificationForm struct {
Address *string `json:"address"`
Seq int64 `json:"seq"`
Ratio decimal.Decimal `json:"ratio"`
Enabled bool `json:"enabled"`
MeterType int16 `json:"type"`
Building *string `json:"building"`
OnFloor *string `json:"onFloor"`
Area decimal.NullDecimal `json:"area"`
}
type NewMeterForReplacingForm struct {
Code string `json:"code"`
Ratio decimal.Decimal `json:"ratio"`
Reading MeterReadingForm `json:"reading"`
}
type MeterReplacingForm struct {
OldReading MeterReadingForm `json:"oldReading"`
NewMeter NewMeterForReplacingForm `json:"newMeter"`
}
type SimplifiedMeterQueryResponse struct {
Code string `json:"code"`
Address *string `json:"address"`
Park string `json:"parkId"`
}
type SimplifiedMeterDetailResponse struct {
Code string `json:"code"`
Park string `json:"parkId"`
Address *string `json:"address"`
Seq int64 `json:"seq"`
Ratio decimal.Decimal `json:"ratio"`
Building *string `json:"building"`
BuildingName *string `json:"buildingName"`
OnFloor *string `json:"onFloor"`
Area decimal.Decimal `json:"area"`
Enabled bool `json:"enabled"`
MeterType int16 `json:"type"`
AttachedAt types.DateTime `json:"attachedAt"`
DetachedAt *types.DateTime `json:"detachedAt"`
}

96
vo/park.go Normal file
View File

@@ -0,0 +1,96 @@
package vo
import (
"electricity_bill_calc/model"
"electricity_bill_calc/tools"
"github.com/shopspring/decimal"
)
type ParkInformationForm struct {
Name string `json:"name"`
Region *string `json:"region"`
Address *string `json:"address"`
Contact *string `json:"contact"`
Phone *string `json:"phone"`
Area *string `json:"area"`
Capacity *string `json:"capacity"`
TenementQuantity *string `json:"tenement"`
TaxRate *string `json:"taxRate"`
Category int16 `json:"category"`
MeterType int16 `json:"submeter"`
PricePolicy int16 `json:"pricePolicy"`
BasicPooled int16 `json:"basicDiluted"`
AdjustPooled int16 `json:"adjustDiluted"`
LossPooled int16 `json:"lossDiluted"`
PublicPooled int16 `json:"publicDiluted"`
}
func (pcf ParkInformationForm) TryIntoPark() (*model.Park, error) {
area, err := tools.NewNullDecimalFromString(pcf.Area)
if err != nil {
return nil, err
}
tenementQuantity, err := tools.NewNullDecimalFromString(pcf.TenementQuantity)
if err != nil {
return nil, err
}
capacity, err := tools.NewNullDecimalFromString(pcf.Capacity)
if err != nil {
return nil, err
}
taxRate, err := tools.NewNullDecimalFromString(pcf.TaxRate)
if err != nil {
return nil, err
}
return &model.Park{
Name: pcf.Name,
Region: pcf.Region,
Address: pcf.Address,
Contact: pcf.Contact,
Phone: pcf.Phone,
Area: area,
TenementQuantity: tenementQuantity,
Capacity: capacity,
Category: pcf.Category,
MeterType: pcf.MeterType,
PricePolicy: pcf.PricePolicy,
BasicPooled: pcf.BasicPooled,
AdjustPooled: pcf.AdjustPooled,
LossPooled: pcf.LossPooled,
PublicPooled: pcf.PublicPooled,
TaxRate: taxRate,
}, nil
}
type ParkBuildingInformationForm struct {
Name string `json:"name"`
Floors string `json:"floors"`
}
type SimplifiedParkDetail struct {
Id string `json:"id"`
UserId string `json:"userId"`
Name string `json:"name"`
TenementStr *string `json:"tenement"`
AreaStr *string `json:"area"`
CapacityStr *string `json:"capacity"`
Category int16 `json:"category"`
MeterType int16 `json:"meter04kvType"`
Region *string `json:"region"`
Address *string `json:"address"`
Contact *string `json:"contact"`
Phone *string `json:"phone"`
}
func (spd *SimplifiedParkDetail) TenementQuantity(tq decimal.NullDecimal) {
spd.TenementStr = tools.NullDecimalToString(tq)
}
func (spd *SimplifiedParkDetail) Area(area decimal.NullDecimal) {
spd.AreaStr = tools.NullDecimalToString(area)
}
func (spd *SimplifiedParkDetail) Capacity(capacity decimal.NullDecimal) {
spd.CapacityStr = tools.NullDecimalToString(capacity)
}

80
vo/reading.go Normal file
View File

@@ -0,0 +1,80 @@
package vo
import (
"electricity_bill_calc/model"
"electricity_bill_calc/types"
"fmt"
"github.com/shopspring/decimal"
)
type MeterReadingForm struct {
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"`
ReadAt *types.DateTime `json:"readAt"`
}
func (r MeterReadingForm) Validate() bool {
flat := r.Overall.Sub(r.Critical).Sub(r.Peak).Sub(r.Valley)
return flat.GreaterThanOrEqual(decimal.Zero)
}
type MeterReadingFormWithCode struct {
Code string `json:"code"`
MeterReadingForm
}
type MeterReadingDetailResponse struct {
Code string `json:"code"`
Park string `json:"parkId"`
Address *string `json:"address"`
Seq int64 `json:"seq"`
Ratio decimal.Decimal `json:"ratio"`
MeterType int16 `json:"type"`
Enabled bool `json:"enabled"`
Building *string `json:"building"`
BuildingName *string `json:"buildingName"`
OnFloor *string `json:"onFloor"`
Area decimal.Decimal `json:"area"`
AttachedAt *types.DateTime `json:"attachedAt"`
DetachedAt *types.DateTime `json:"detachedAt"`
CreatedAt types.DateTime `json:"createdAt"`
LastModifiedAt *types.DateTime `json:"lastModifiedAt"`
ReadAt types.DateTime `json:"readAt"`
ReadAtTimestamp string `json:"readAtTimestamp"`
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 FromDetailedMeterReading(reading model.DetailedMeterReading) MeterReadingDetailResponse {
return MeterReadingDetailResponse{
Code: reading.Detail.Code,
Park: reading.Detail.Park,
Address: reading.Detail.Address,
Seq: reading.Detail.Seq,
Ratio: reading.Detail.Ratio,
MeterType: reading.Detail.MeterType,
Enabled: reading.Detail.Enabled,
Building: reading.Detail.Building,
BuildingName: reading.Detail.BuildingName,
OnFloor: reading.Detail.OnFloor,
Area: reading.Detail.Area.Decimal,
AttachedAt: reading.Detail.AttachedAt,
DetachedAt: (*types.DateTime)(reading.Detail.DetachedAt),
CreatedAt: types.DateTime(reading.Detail.CreatedAt),
LastModifiedAt: (*types.DateTime)(&reading.Detail.LastModifiedAt),
ReadAt: reading.Reading.ReadAt,
ReadAtTimestamp: fmt.Sprintf("%d", reading.Reading.ReadAt.UnixMicro()),
Overall: reading.Reading.Overall,
Critical: reading.Reading.Critical,
Peak: reading.Reading.Peak,
Flat: reading.Reading.Flat,
Valley: reading.Reading.Valley,
}
}

323
vo/report.go Normal file
View File

@@ -0,0 +1,323 @@
package vo
import (
"electricity_bill_calc/model"
"electricity_bill_calc/types"
"github.com/jinzhu/copier"
"github.com/shopspring/decimal"
)
type ReportCreationForm struct {
Park string `json:"parkId"`
PeriodBegin types.Date `json:"periodBegin"`
PeriodEnd types.Date `json:"periodEnd"`
Overall decimal.Decimal `json:"overall"`
OverallFee decimal.Decimal `json:"overallFee"`
Critical decimal.Decimal `json:"critical"`
CriticalFee decimal.Decimal `json:"criticalFee"`
Peak decimal.Decimal `json:"peak"`
PeakFee decimal.Decimal `json:"peakFee"`
Flat decimal.Decimal `json:"flat,omitempty"`
FlatFee decimal.Decimal `json:"flatFee,omitempty"`
Valley decimal.Decimal `json:"valley"`
ValleyFee decimal.Decimal `json:"valleyFee"`
BasicFee decimal.Decimal `json:"basicFee"`
AdjustFee decimal.Decimal `json:"adjustFee"`
}
type ReportModifyForm struct {
PeriodBegin types.Date `json:"periodBegin"`
PeriodEnd types.Date `json:"periodEnd"`
Overall decimal.Decimal `json:"overall"`
OverallFee decimal.Decimal `json:"overallFee"`
Critical decimal.Decimal `json:"critical"`
CriticalFee decimal.Decimal `json:"criticalFee"`
Peak decimal.Decimal `json:"peak"`
PeakFee decimal.Decimal `json:"peakFee"`
Flat decimal.Decimal `json:"flat,omitempty"`
FlatFee decimal.Decimal `json:"flatFee,omitempty"`
Valley decimal.Decimal `json:"valley"`
ValleyFee decimal.Decimal `json:"valleyFee"`
BasicFee decimal.Decimal `json:"basicFee"`
AdjustFee decimal.Decimal `json:"adjustFee"`
}
type SimplifiedReportIndex struct {
Id string `json:"id"`
Park string `json:"parkId"`
PeriodBegin types.Date `json:"periodBegin"`
PeriodEnd types.Date `json:"periodEnd"`
Published bool `json:"published"`
PublishedAt *types.DateTime `json:"publishedAt"`
Withdraw int16 `json:"withdraw"`
LastWithdrawAppliedAt *types.DateTime `json:"lastWithdrawAppliedAt"`
LastWithdrawAuditAt *types.DateTime `json:"lastWithdrawAuditAt"`
Status int16 `json:"status"`
Message *string `json:"message"`
}
func (sri *SimplifiedReportIndex) Period(p types.DateRange) {
sri.PeriodBegin = p.SafeLower()
sri.PeriodEnd = p.SafeUpper()
}
type ReportIndexQueryResponse struct {
Park SimplifiedParkDetail `json:"park"`
Report *SimplifiedReportIndex `json:"report"`
}
type ComprehensiveReportQueryResponse struct {
Report SimplifiedReportIndex `json:"report"`
Park SimplifiedParkDetail `json:"park"`
User SimplifiedUserDetail `json:"user"`
}
type BasicReportIndexResponse struct {
Id string `json:"id"`
Park string `json:"parkId"`
PeriodBegin types.Date `json:"periodBegin"`
PeriodEnd types.Date `json:"periodEnd"`
Category int16 `json:"category"`
MeterType int16 `json:"meter04kvType"`
PricePolicy int16 `json:"pricePolicy"`
BasisPooled int16 `json:"basisDiluted"`
AdjustPooled int16 `json:"adjustDiluted"`
LossPooled int16 `json:"lossDiluted"`
PublicPooled int16 `json:"publicDiluted"`
Published bool `json:"published"`
PublishedAt *types.DateTime `json:"publishedAt"`
Withdraw int16 `json:"withdraw"`
LastWithdrawAppliedAt *types.DateTime `json:"lastWithdrawAppliedAt"`
LastWithdrawAuditAt *types.DateTime `json:"lastWithdrawAuditAt"`
Status int16 `json:"status"`
Message *string `json:"message"`
CreatedAt types.DateTime `json:"createdAt"`
LastModifiedAt types.DateTime `json:"lastModifiedAt"`
}
func (bri *BasicReportIndexResponse) Period(p types.DateRange) {
bri.PeriodBegin = p.SafeLower()
bri.PeriodEnd = p.SafeUpper()
}
type ReportDetailQueryResponse struct {
Enterprise SimplifiedUserDetail `json:"enterprise"`
Park SimplifiedParkDetail `json:"park"`
Report BasicReportIndexResponse `json:"report"`
}
func NewReportDetailQueryResponse(user *model.UserDetail, park *model.Park, report *model.ReportIndex) ReportDetailQueryResponse {
var response ReportDetailQueryResponse
copier.Copy(&response.Enterprise, user)
copier.Copy(&response.Park, park)
copier.Copy(&response.Report, report)
return response
}
type ParkSummaryResponse struct {
ReportId string `json:"reportId"`
OverallDisplay ConsumptionDisplay `json:"overall"`
Area decimal.Decimal `json:"area"`
BasicFee decimal.Decimal `json:"basicFee"`
PooledBasicFeeByAmount decimal.Decimal `json:"pooledBasicFeeByAmount"`
PooledBasicFeeByArea decimal.Decimal `json:"pooledBasicFeeByArea"`
AdjustFee decimal.Decimal `json:"adjustFee"`
PooledAdjustFeeByAmount decimal.Decimal `json:"pooledAdjustFeeByAmount"`
PooledAdjustFeeByArea decimal.Decimal `json:"pooledAdjustFeeByArea"`
Consumption decimal.Decimal `json:"consumption"`
Loss decimal.Decimal `json:"loss"`
LossRate decimal.Decimal `json:"lossRate"`
}
func (psr *ParkSummaryResponse) Overall(value model.ConsumptionUnit) {
psr.OverallDisplay.FromConsumptionUnit(&value)
}
type SimplifiedReportSummary struct {
Overall model.ConsumptionUnit `json:"overall"`
Critical model.ConsumptionUnit `json:"critical"`
Peak model.ConsumptionUnit `json:"peak"`
Flat model.ConsumptionUnit `json:"flat"`
Valley model.ConsumptionUnit `json:"valley"`
BasicFee decimal.Decimal `json:"basicFee"`
AdjustFee decimal.Decimal `json:"adjustFee"`
ConsumptionFee decimal.Decimal `json:"consumptionFee" copier:"GetConsumptionFee"`
}
type TestCalculateForm struct {
Overall decimal.Decimal `json:"overall"`
OverallFee decimal.Decimal `json:"overallFee"`
Critical decimal.Decimal `json:"critical"`
CriticalFee decimal.Decimal `json:"criticalFee"`
Peak decimal.Decimal `json:"peak"`
PeakFee decimal.Decimal `json:"peakFee"`
Valley decimal.Decimal `json:"valley"`
ValleyFee decimal.Decimal `json:"valleyFee"`
BasicFee decimal.Decimal `json:"basicFee"`
AdjustFee decimal.Decimal `json:"adjustFee"`
}
type TestCalculateResult struct {
OverallPrice decimal.Decimal `json:"overallPrice"`
CriticalPrice decimal.Decimal `json:"criticalPrice"`
PeakPrice decimal.Decimal `json:"peakPrice"`
Flat decimal.Decimal `json:"flat"`
FlatFee decimal.Decimal `json:"flatFee"`
FlatPrice decimal.Decimal `json:"flatPrice"`
ValleyPrice decimal.Decimal `json:"valleyPrice"`
ConsumptionFee decimal.Decimal `json:"consumptionFee"`
}
func (t TestCalculateForm) Calculate() TestCalculateResult {
var r TestCalculateResult = TestCalculateResult{}
r.ConsumptionFee = t.OverallFee.Sub(t.BasicFee).Sub(t.AdjustFee)
if t.Overall.GreaterThan(decimal.Zero) {
r.OverallPrice = r.ConsumptionFee.Div(t.Overall).RoundBank(8)
}
if t.Critical.GreaterThan(decimal.Zero) {
r.CriticalPrice = t.CriticalFee.Div(t.Critical).RoundBank(8)
}
if t.Peak.GreaterThan(decimal.Zero) {
r.PeakPrice = t.PeakFee.Div(t.Peak).RoundBank(8)
}
r.Flat = t.Overall.Sub(t.Critical).Sub(t.Peak).Sub(t.Valley)
r.FlatFee = r.ConsumptionFee.Sub(t.CriticalFee).Sub(t.PeakFee).Sub(t.ValleyFee).RoundBank(8)
if r.Flat.GreaterThan(decimal.Zero) {
r.FlatPrice = r.FlatFee.Div(r.Flat).RoundBank(8)
}
r.ConsumptionFee = r.ConsumptionFee.RoundBank(8)
return r
}
type ReportCalculateTaskStatusResponse struct {
Id string `json:"id"`
Status int16 `json:"status"`
Message *string `json:"message"`
}
type ReportPublicQueryResponse struct {
SimplifiedMeterDetailResponse
Overall ConsumptionDisplay `json:"overall"`
AdjustLoss ConsumptionDisplay `json:"adjustLoss"`
}
func (rpqr *ReportPublicQueryResponse) FromReportDetailPublicConsumption(value *model.ReportDetailedPublicConsumption) {
copier.Copy(&rpqr.SimplifiedMeterDetailResponse, &value.MeterDetail)
rpqr.Overall.FromConsumptionUnit(&value.ReportPublicConsumption.Overall)
rpqr.Overall.Amount(value.ReportPublicConsumption.Overall.Amount.Add(value.ReportPublicConsumption.LossAdjust.Amount))
rpqr.AdjustLoss.FromConsumptionUnit(&value.ReportPublicConsumption.LossAdjust)
}
type ReportPooledQueryResponse struct {
SimplifiedMeterDetailResponse
Overall ConsumptionDisplay `json:"overall"`
PoolMethod int16 `json:"poolMethod"`
}
func (rpqr *ReportPooledQueryResponse) FromReportDetailPooledConsumption(value *model.ReportDetailedPooledConsumption) {
copier.Copy(&rpqr.SimplifiedMeterDetailResponse, &value.MeterDetail)
rpqr.Overall.FromConsumptionUnit(&value.ReportPooledConsumption.Overall)
rpqr.PoolMethod = value.PublicPooled
}
func (rpqr *ReportPooledQueryResponse) FromReportDetailNestedMeterConsumption(value *model.ReportDetailNestedMeterConsumption) {
copier.Copy(&rpqr.SimplifiedMeterDetailResponse, &value.Meter)
rpqr.Overall.FromConsumptionUnit(&value.Consumption.Overall)
rpqr.PoolMethod = -1
}
type ReportTenementSummaryResponse struct {
SimplifiedTenementDetailResponse
Consumption decimal.Decimal `json:"consumption"`
Fee decimal.Decimal `json:"fee"`
Pooled decimal.Decimal `json:"pooled"`
Total decimal.Decimal `json:"final"`
}
func (rtsr *ReportTenementSummaryResponse) FromReportTenement(value *model.ReportTenement) {
copier.Copy(&rtsr.SimplifiedTenementDetailResponse, &value.Detail)
fee := value.BasicFeePooled.Add(value.AdjustFeePooled).Add(value.LossFeePooled)
rtsr.Consumption = value.Overall.Amount
rtsr.Fee = fee
rtsr.Pooled = value.FinalPooled
rtsr.Total = value.FinalCharge
}
type ReportTenementComprehensiveDetailResponse struct {
Consumption decimal.Decimal `json:"consumption"`
Fee decimal.Decimal `json:"fee"`
Price decimal.Decimal `json:"price"`
BasicPooled decimal.Decimal `json:"basicPooled"`
AdjustPooled decimal.Decimal `json:"adjustPooled"`
LossPooled decimal.Decimal `json:"lossPooled"`
PublicPooled decimal.Decimal `json:"publicPooled"`
Total decimal.Decimal `json:"total"`
}
func (rtcdr *ReportTenementComprehensiveDetailResponse) FromReportTenement(value *model.ReportTenement) {
rtcdr.Consumption = value.Overall.Amount
rtcdr.Fee = value.Overall.Fee
rtcdr.Price = value.Overall.Price
rtcdr.BasicPooled = value.BasicFeePooled
rtcdr.AdjustPooled = value.AdjustFeePooled
rtcdr.LossPooled = value.LossFeePooled
rtcdr.PublicPooled = value.FinalPooled
rtcdr.Total = value.FinalCharge
}
type ReportMeterDetailResponse struct {
SimplifiedMeterDetailResponse
Overall ConsumptionDisplay `json:"overall"`
Critical ConsumptionDisplay `json:"critical"`
Peak ConsumptionDisplay `json:"peak"`
Flat ConsumptionDisplay `json:"flat"`
Valley ConsumptionDisplay `json:"valley"`
}
func (rmdr *ReportMeterDetailResponse) FromNestedMeter(value *model.NestedMeter) {
copier.Copy(&rmdr.SimplifiedMeterDetailResponse, &value.MeterDetail)
rmdr.Overall.FromConsumptionUnit(&value.Overall)
rmdr.Critical.FromConsumptionUnit(&value.Critical)
rmdr.Peak.FromConsumptionUnit(&value.Peak)
rmdr.Flat.FromConsumptionUnit(&value.Flat)
rmdr.Valley.FromConsumptionUnit(&value.Valley)
}
type ReportMeterExtendedDetailResponse struct {
ReportMeterDetailResponse
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"`
}
func (rmedr *ReportMeterExtendedDetailResponse) FromNestedMeter(value *model.NestedMeter) {
rmedr.ReportMeterDetailResponse.FromNestedMeter(value)
rmedr.BasicPooled = value.BasicPooled
rmedr.AdjustPooled = value.AdjustPooled
rmedr.LossPooled = value.LossPooled
rmedr.PublicPooled = value.PublicPooled
rmedr.FinalTotal = value.FinalTotal
}
type ReportTenementDetailResponse struct {
Tenement SimplifiedTenementDetailResponse `json:"tenement"`
Comprehensive ReportTenementComprehensiveDetailResponse `json:"comprehensive"`
Meters []ReportMeterExtendedDetailResponse `json:"meters"`
Pooled []ReportMeterDetailResponse `json:"pooled"`
}
func (rtdr *ReportTenementDetailResponse) FromReportTenement(value *model.ReportTenement) {
copier.Copy(&rtdr.Tenement, &value.Detail)
rtdr.Comprehensive.FromReportTenement(value)
rtdr.Meters = make([]ReportMeterExtendedDetailResponse, len(value.Meters))
for i, v := range value.Meters {
rtdr.Meters[i].FromNestedMeter(&v)
}
rtdr.Pooled = make([]ReportMeterDetailResponse, len(value.Pooled))
for i, v := range value.Pooled {
rtdr.Pooled[i].FromNestedMeter(&v)
}
}

43
vo/shares.go Normal file
View File

@@ -0,0 +1,43 @@
package vo
import (
"electricity_bill_calc/model"
"github.com/shopspring/decimal"
)
type StateForm struct {
Enabled bool `json:"enabled"`
}
type ConsumptionDisplay struct {
AmountStr string `json:"amount"`
FeeStr string `json:"fee"`
PriceStr string `json:"price"`
ProportionStr string `json:"proportion"`
}
func (cd *ConsumptionDisplay) Amount(a decimal.Decimal) *ConsumptionDisplay {
cd.AmountStr = a.StringFixedBank(4)
return cd
}
func (cd *ConsumptionDisplay) Fee(f decimal.Decimal) *ConsumptionDisplay {
cd.FeeStr = f.StringFixedBank(4)
return cd
}
func (cd *ConsumptionDisplay) Price(p decimal.Decimal) *ConsumptionDisplay {
cd.PriceStr = p.StringFixedBank(8)
return cd
}
func (cd *ConsumptionDisplay) Proportion(p decimal.Decimal) *ConsumptionDisplay {
cd.ProportionStr = p.StringFixedBank(8)
return cd
}
func (cd *ConsumptionDisplay) FromConsumptionUnit(cu *model.ConsumptionUnit) ConsumptionDisplay {
cd.Amount(cu.Amount).Fee(cu.Fee).Price(cu.Price).Proportion(cu.Proportion)
return *cd
}

29
vo/synchronize.go Normal file
View File

@@ -0,0 +1,29 @@
package vo
type SynchronizeConfiguration struct {
CollectAt string `json:"collectAt"` // 采集时间格式HH:mm
EntID string `json:"entId"` // 企业ID
Imrs string `json:"imrs"` // 采集系统型号
ImrsAccount string `json:"imrsAccount"` // 同步登录账号
ImrsKey string `json:"imrsKey"` // 同步登录私钥Base64或者私钥文件内容
ImrsSecret string `json:"imrsSecret"` // 同步登录密钥,加盐双向加密
Interval float64 `json:"interval"` // 采集周期0每小时1每日2每周3每月
MaxRetries string `json:"maxRetries"` // 最大重试次数
ParkID string `json:"parkId"` // 园区ID
ReadingType float64 `json:"readingType"` // 采集方式0自动+人工1自动2人工
RetryAlgorithm float64 `json:"retryAlgorithm"` // 重试间隔算法0指数退避12倍线性间隔23倍线性间隔3固定间隔
RetryInterval string `json:"retryInterval"` // 重试间隔,基础间隔时间,根据间隔算法不同会产生不同的间隔
}
type SynchronizeConfigurationCreateForm struct {
CollectAt string `json:"collectAt"` // 采集时间格式HH:mm
Imrs string `json:"imrs"` // 采集系统型号,为空的时候表示不同步
ImrsAccount string `json:"imrsAccount"` // 同步登录账号
ImrsKey string `json:"imrsKey"` // 同步登录私钥Base64或者私钥文件内容
ImrsSecret string `json:"imrsSecret"` // 同步登录密钥,加盐双向加密
Interval float64 `json:"interval"` // 采集周期0每小时1每日2每周3每月
MaxRetries string `json:"maxRetries"` // 最大重试次数
ParkID string `json:"parkId"` // 园区ID
ReadingType float64 `json:"readingType"` // 采集方式0自动+人工1自动2人工
RetryAlgorithm float64 `json:"retryAlgorithm"` // 重试间隔算法0指数退避12倍线性间隔23倍线性间隔3固定间隔
RetryInterval string `json:"retryInterval"` // 重试间隔,基础间隔时间,根据间隔算法不同会产生不同的间隔
}

75
vo/tenement.go Normal file
View File

@@ -0,0 +1,75 @@
package vo
import (
"electricity_bill_calc/model"
"electricity_bill_calc/types"
)
type TenementCreationForm struct {
Name string `json:"name"`
ShortName *string `json:"shortName"`
Address string `json:"address"`
Contact string `json:"contact"`
Phone string `json:"phone"`
Building *string `json:"building"`
OnFloor *string `json:"onFloor"`
USCI string `json:"usci"`
InvoiceAddress *string `json:"invoiceAddress"`
InvoicePhone *string `json:"invoicePhone"`
Bank *string `json:"bank"`
Account *string `json:"bankAccount"`
}
type TenementQueryResponse struct {
Id string `json:"id"`
FullName string `json:"fullName"`
ShortName *string `json:"shortName"`
Address *string `json:"address"`
Contact *string `json:"contact" copier:"ContactName"`
Phone *string `json:"phone" copier:"ContactPhone"`
Building *string `json:"building"`
BuildingName *string `json:"buildingName"`
OnFloor *string `json:"onFloor"`
MovedInAt *types.Date `json:"movedInAt"`
MovedOutAt *types.Date `json:"movedOutAt"`
CreatedAt types.DateTime `json:"createdAt"`
LastModifiedAt *types.DateTime `json:"lastModifiedAt"`
}
type SimplifiedTenementResponse struct {
Id string `json:"id"`
FullName string `json:"fullName"`
ShortName *string `json:"shortName"`
Park string `json:"park"`
}
type TenementDetailResponse struct {
Id string `json:"id"`
FullName string `json:"fullName"`
ShortName *string `json:"shortName"`
Address string `json:"address"`
Contact string `json:"contact" copier:"ContactName"`
Phone string `json:"phone" copier:"ContactPhone"`
Building string `json:"building"`
BuildingName *string `json:"buildingName"`
OnFloor *string `json:"onFloor"`
InvoiceInfo *model.InvoiceTitle `json:"invoiceInfo"`
MovedInAt *types.Date `json:"movedInAt"`
MovedOutAt *types.Date `json:"movedOutAt"`
CreatedAt types.DateTime `json:"createdAt"`
LastModifiedAt *types.DateTime `json:"lastModifiedAt"`
}
type SimplifiedTenementDetailResponse struct {
Id string `json:"id"`
FullName string `json:"fullName"`
ShortName *string `json:"shortName"`
Address string `json:"address"`
Contact string `json:"contact" copier:"ContactName"`
Phone string `json:"phone" copier:"ContactPhone"`
Building string `json:"building"`
BuildingName *string `json:"buildingName"`
OnFloor *string `json:"onFloor"`
MovedInAt *types.Date `json:"movedInAt"`
MovedOutAt *types.Date `json:"movedOutAt"`
}

25
vo/top_up.go Normal file
View File

@@ -0,0 +1,25 @@
package vo
import (
"electricity_bill_calc/types"
"github.com/shopspring/decimal"
)
type TopUpCreationForm struct {
Tenement string `json:"tenement"`
Meter string `json:"meter"`
Amount decimal.Decimal `json:"amount"`
}
type TopUpDetailQueryResponse struct {
Id string `json:"id" copier:"TopUpCode"`
Tenement string `json:"tenement"`
TenementName string `json:"tenementName"`
Meter string `json:"meter"`
MeterAddress string `json:"meterAddress"`
ToppedUpAt types.DateTime `json:"toppedUpAt"`
Amount decimal.Decimal `json:"amount"`
PaymentType int16 `json:"paymentType"`
SyncStatus int16 `json:"syncStatus" copier:"SyncStatus"`
}

141
vo/user.go Normal file
View File

@@ -0,0 +1,141 @@
package vo
import (
"electricity_bill_calc/model"
"electricity_bill_calc/tools"
"electricity_bill_calc/types"
"time"
"github.com/shopspring/decimal"
)
type MGTAndOPSAccountCreationForm struct {
Username string `json:"username"`
Name string `json:"name"`
Contact *string `json:"contact"`
Phone *string `json:"phone"`
UserType int16 `json:"type"`
}
func (u MGTAndOPSAccountCreationForm) IntoUser() *model.User {
return &model.User{
Username: u.Username,
Password: "",
ResetNeeded: false,
UserType: u.UserType,
Enabled: true,
CreatedAt: nil,
}
}
func (u MGTAndOPSAccountCreationForm) IntoUserDetail() *model.UserDetail {
return &model.UserDetail{
Id: "",
Name: &u.Name,
Abbr: nil,
Region: nil,
Address: nil,
Contact: u.Contact,
Phone: u.Phone,
UnitServiceFee: decimal.Zero,
ServiceExpiration: types.NewDate(2099, time.December, 31),
CreatedAt: types.Now(),
CreatedBy: nil,
LastModifiedAt: types.Now(),
LastModifiedBy: nil,
DeletedAt: nil,
DeletedBy: nil,
}
}
type EnterpriseAccountCreationForm struct {
Username string `json:"username"`
Name string `json:"name"`
Region *string `json:"region"`
Address *string `json:"address"`
Contact *string `json:"contact"`
Phone *string `json:"phone"`
UnitServiceFee string `json:"unitServiceFee"`
}
func (u EnterpriseAccountCreationForm) IntoUser() *model.User {
return &model.User{
Username: u.Username,
Password: "",
ResetNeeded: false,
UserType: model.USER_TYPE_ENT,
Enabled: true,
CreatedAt: nil,
}
}
func (u EnterpriseAccountCreationForm) IntoUserDetail() (*model.UserDetail, error) {
unitServiceFee, err := decimal.NewFromString(u.UnitServiceFee)
if err != nil {
return nil, err
}
return &model.UserDetail{
Name: &u.Name,
Abbr: nil,
Region: u.Region,
Address: u.Address,
Contact: u.Contact,
Phone: u.Phone,
UnitServiceFee: unitServiceFee,
ServiceExpiration: types.NewDate(2000, time.January, 1),
CreatedAt: types.Now(),
CreatedBy: nil,
LastModifiedAt: types.Now(),
LastModifiedBy: nil,
DeletedAt: nil,
DeletedBy: nil,
}, nil
}
type UserDetailModificationForm struct {
Name string `json:"name"`
Region *string `json:"region"`
Address *string `json:"address"`
Contact *string `json:"contact"`
Phone *string `json:"phone"`
UnitServiceFee *string `json:"unitServiceFee"`
}
func (u UserDetailModificationForm) IntoModificationModel() (*model.UserModificationForm, error) {
unitServiceFee, err := decimal.NewFromString(*u.UnitServiceFee)
if err != nil {
return nil, err
}
return &model.UserModificationForm{
Name: u.Name,
Region: u.Region,
Address: u.Address,
Contact: u.Contact,
Phone: u.Phone,
UnitServiceFee: &unitServiceFee,
}, nil
}
type UserStateChangeForm struct {
Uid string `json:"uid"`
Enabled bool `json:"enabled"`
}
type RepasswordForm struct {
VerifyCode string `json:"verifyCode"`
Username string `json:"uname"`
NewPassword string `json:"newPass"`
}
type SimplifiedUserDetail struct {
Id string `json:"id"`
NameStr string `json:"name"`
Contact *string `json:"contact"`
Phone *string `json:"phone"`
Region *string `json:"region"`
Address *string `json:"address"`
}
func (sud *SimplifiedUserDetail) Name(n *string) {
sud.NameStr = tools.DefaultTo(n, "")
}