forked from free-lancers/electricity_bill_calc_service
		
	feat(report):基本完成报表查看部分内容的迁移。
This commit is contained in:
		
							
								
								
									
										22
									
								
								vo/meter.go
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								vo/meter.go
									
									
									
									
									
								
							| @@ -1,6 +1,10 @@ | ||||
| package vo | ||||
|  | ||||
| import "github.com/shopspring/decimal" | ||||
| import ( | ||||
| 	"electricity_bill_calc/types" | ||||
|  | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| type MeterCreationForm struct { | ||||
| 	Code             string              `json:"code"` | ||||
| @@ -42,3 +46,19 @@ type SimplifiedMeterQueryResponse struct { | ||||
| 	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:"meterType"` | ||||
| 	AttachedAt   types.DateTime  `json:"attachedAt"` | ||||
| 	DetachedAt   *types.DateTime `json:"detachedAt"` | ||||
| } | ||||
|   | ||||
							
								
								
									
										247
									
								
								vo/report.go
									
									
									
									
									
								
							
							
						
						
									
										247
									
								
								vo/report.go
									
									
									
									
									
								
							| @@ -1,8 +1,10 @@ | ||||
| package vo | ||||
|  | ||||
| import ( | ||||
| 	"electricity_bill_calc/model" | ||||
| 	"electricity_bill_calc/types" | ||||
|  | ||||
| 	"github.com/jinzhu/copier" | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| @@ -70,3 +72,248 @@ type ComprehensiveReportQueryResponse struct { | ||||
| 	Park   SimplifiedParkDetail  `json:"park"` | ||||
| 	User   SimplifiedUserDetail  `json:"user"` | ||||
| } | ||||
|  | ||||
| type BasicReportIndexResponse struct { | ||||
| 	Id                    string          `json:"id"` | ||||
| 	Park                  string          `json:"park_id"` | ||||
| 	PeriodBegin           types.Date      `json:"period_begin"` | ||||
| 	PeriodEnd             types.Date      `json:"period_end"` | ||||
| 	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:"published_at"` | ||||
| 	Withdraw              int16           `json:"withdraw"` | ||||
| 	LastWithdrawAppliedAt *types.DateTime `json:"last_withdraw_applied_at"` | ||||
| 	LastWithdrawAuditAt   *types.DateTime `json:"last_withdraw_audit_at"` | ||||
| 	Status                int16           `json:"status"` | ||||
| 	Message               *string         `json:"message"` | ||||
| 	CreatedAt             types.DateTime  `json:"created_at"` | ||||
| 	LastModifiedAt        types.DateTime  `json:"last_modified_at"` | ||||
| } | ||||
|  | ||||
| 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 { | ||||
| 	Id                      string             `json:"id"` | ||||
| 	Overall                 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"` | ||||
| } | ||||
|  | ||||
| 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 { | ||||
| 	SimplifiedMeterQueryResponse | ||||
| 	Overall    ConsumptionDisplay `json:"overall"` | ||||
| 	AdjustLoss ConsumptionDisplay `json:"adjustLoss"` | ||||
| } | ||||
|  | ||||
| func (rpqr *ReportPublicQueryResponse) FromReportDetailPublicConsumption(value *model.ReportDetailedPublicConsumption) { | ||||
| 	copier.Copy(&rpqr.SimplifiedMeterQueryResponse, &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 { | ||||
| 	SimplifiedMeterQueryResponse | ||||
| 	Overall    ConsumptionDisplay `json:"overall"` | ||||
| 	PoolMethod int16              `json:"poolMethod"` | ||||
| } | ||||
|  | ||||
| func (rpqr *ReportPooledQueryResponse) FromReportDetailPooledConsumption(value *model.ReportDetailedPooledConsumption) { | ||||
| 	copier.Copy(&rpqr.SimplifiedMeterQueryResponse, &value.MeterDetail) | ||||
| 	rpqr.Overall = FromConsumptionUnit(&value.ReportPooledConsumption.Overall) | ||||
| 	rpqr.PoolMethod = value.PublicPooled | ||||
| } | ||||
|  | ||||
| func (rqpr *ReportPooledQueryResponse) FromReportDetailNestedMeterConsumption(value *model.ReportDetailNestedMeterConsumption) { | ||||
| 	copier.Copy(&rqpr.SimplifiedMeterQueryResponse, &value.Meter) | ||||
| 	rqpr.Overall = FromConsumptionUnit(&value.Consumption.Overall) | ||||
| 	rqpr.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) | ||||
| 	} | ||||
| } | ||||
|   | ||||
							
								
								
									
										40
									
								
								vo/shares.go
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								vo/shares.go
									
									
									
									
									
								
							| @@ -1,5 +1,45 @@ | ||||
| package vo | ||||
|  | ||||
| import ( | ||||
| 	"electricity_bill_calc/model" | ||||
|  | ||||
| 	"github.com/jinzhu/copier" | ||||
| 	"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 FromConsumptionUnit(cu *model.ConsumptionUnit) ConsumptionDisplay { | ||||
| 	cd := &ConsumptionDisplay{} | ||||
| 	copier.Copy(cd, cu) | ||||
| 	return *cd | ||||
| } | ||||
|   | ||||
| @@ -59,3 +59,17 @@ type TenementDetailResponse struct { | ||||
| 	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"` | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user