forked from free-lancers/electricity_bill_calc_service
		
	fix(report):确定ConsumptionUnit对应的ConsumptionDisplay数据结构的自动复制模式。
This commit is contained in:
		| @@ -70,7 +70,7 @@ type ParkBuildingInformationForm struct { | ||||
|  | ||||
| type SimplifiedParkDetail struct { | ||||
| 	Id          string  `json:"id"` | ||||
| 	UserId      string  `json:"user_id"` | ||||
| 	UserId      string  `json:"userId"` | ||||
| 	Name        string  `json:"name"` | ||||
| 	TenementStr *string `json:"tenement"` | ||||
| 	AreaStr     *string `json:"area"` | ||||
|   | ||||
							
								
								
									
										42
									
								
								vo/report.go
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								vo/report.go
									
									
									
									
									
								
							| @@ -75,9 +75,9 @@ type ComprehensiveReportQueryResponse struct { | ||||
|  | ||||
| type BasicReportIndexResponse struct { | ||||
| 	Id                    string          `json:"id"` | ||||
| 	Park                  string          `json:"park_id"` | ||||
| 	PeriodBegin           types.Date      `json:"period_begin"` | ||||
| 	PeriodEnd             types.Date      `json:"period_end"` | ||||
| 	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"` | ||||
| @@ -86,14 +86,14 @@ type BasicReportIndexResponse struct { | ||||
| 	LossPooled            int16           `json:"lossDiluted"` | ||||
| 	PublicPooled          int16           `json:"publicDiluted"` | ||||
| 	Published             bool            `json:"published"` | ||||
| 	PublishedAt           *types.DateTime `json:"published_at"` | ||||
| 	PublishedAt           *types.DateTime `json:"publishedAt"` | ||||
| 	Withdraw              int16           `json:"withdraw"` | ||||
| 	LastWithdrawAppliedAt *types.DateTime `json:"last_withdraw_applied_at"` | ||||
| 	LastWithdrawAuditAt   *types.DateTime `json:"last_withdraw_audit_at"` | ||||
| 	LastWithdrawAppliedAt *types.DateTime `json:"lastWithdrawAppliedAt"` | ||||
| 	LastWithdrawAuditAt   *types.DateTime `json:"lastWithdrawAuditAt"` | ||||
| 	Status                int16           `json:"status"` | ||||
| 	Message               *string         `json:"message"` | ||||
| 	CreatedAt             types.DateTime  `json:"created_at"` | ||||
| 	LastModifiedAt        types.DateTime  `json:"last_modified_at"` | ||||
| 	CreatedAt             types.DateTime  `json:"createdAt"` | ||||
| 	LastModifiedAt        types.DateTime  `json:"lastModifiedAt"` | ||||
| } | ||||
|  | ||||
| func (bri *BasicReportIndexResponse) Period(p types.DateRange) { | ||||
| @@ -116,8 +116,8 @@ func NewReportDetailQueryResponse(user *model.UserDetail, park *model.Park, repo | ||||
| } | ||||
|  | ||||
| type ParkSummaryResponse struct { | ||||
| 	Id                      string             `json:"id"` | ||||
| 	Overall                 ConsumptionDisplay `json:"overall"` | ||||
| 	ReportId                string             `json:"reportId"` | ||||
| 	OverallDisplay          ConsumptionDisplay `json:"overall"` | ||||
| 	Area                    decimal.Decimal    `json:"area"` | ||||
| 	BasicFee                decimal.Decimal    `json:"basicFee"` | ||||
| 	PooledBasicFeeByAmount  decimal.Decimal    `json:"pooledBasicFeeByAmount"` | ||||
| @@ -130,6 +130,10 @@ type ParkSummaryResponse struct { | ||||
| 	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"` | ||||
| @@ -200,9 +204,9 @@ type ReportPublicQueryResponse struct { | ||||
|  | ||||
| func (rpqr *ReportPublicQueryResponse) FromReportDetailPublicConsumption(value *model.ReportDetailedPublicConsumption) { | ||||
| 	copier.Copy(&rpqr.SimplifiedMeterQueryResponse, &value.MeterDetail) | ||||
| 	rpqr.Overall = FromConsumptionUnit(&value.ReportPublicConsumption.Overall) | ||||
| 	rpqr.Overall.FromConsumptionUnit(&value.ReportPublicConsumption.Overall) | ||||
| 	rpqr.Overall.Amount(value.ReportPublicConsumption.Overall.Amount.Add(value.ReportPublicConsumption.LossAdjust.Amount)) | ||||
| 	rpqr.AdjustLoss = FromConsumptionUnit(&value.ReportPublicConsumption.LossAdjust) | ||||
| 	rpqr.AdjustLoss.FromConsumptionUnit(&value.ReportPublicConsumption.LossAdjust) | ||||
| } | ||||
|  | ||||
| type ReportPooledQueryResponse struct { | ||||
| @@ -213,13 +217,13 @@ type ReportPooledQueryResponse struct { | ||||
|  | ||||
| func (rpqr *ReportPooledQueryResponse) FromReportDetailPooledConsumption(value *model.ReportDetailedPooledConsumption) { | ||||
| 	copier.Copy(&rpqr.SimplifiedMeterQueryResponse, &value.MeterDetail) | ||||
| 	rpqr.Overall = FromConsumptionUnit(&value.ReportPooledConsumption.Overall) | ||||
| 	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.Overall.FromConsumptionUnit(&value.Consumption.Overall) | ||||
| 	rqpr.PoolMethod = -1 | ||||
| } | ||||
|  | ||||
| @@ -273,11 +277,11 @@ type ReportMeterDetailResponse struct { | ||||
|  | ||||
| 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) | ||||
| 	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 { | ||||
|   | ||||
							
								
								
									
										14
									
								
								vo/shares.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								vo/shares.go
									
									
									
									
									
								
							| @@ -3,7 +3,6 @@ package vo | ||||
| import ( | ||||
| 	"electricity_bill_calc/model" | ||||
|  | ||||
| 	"github.com/jinzhu/copier" | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
|  | ||||
| @@ -18,28 +17,27 @@ type ConsumptionDisplay struct { | ||||
| 	ProportionStr string `json:"proportion"` | ||||
| } | ||||
|  | ||||
| func (cd ConsumptionDisplay) Amount(a decimal.Decimal) ConsumptionDisplay { | ||||
| func (cd *ConsumptionDisplay) Amount(a decimal.Decimal) *ConsumptionDisplay { | ||||
| 	cd.AmountStr = a.StringFixedBank(4) | ||||
| 	return cd | ||||
| } | ||||
|  | ||||
| func (cd ConsumptionDisplay) Fee(f decimal.Decimal) ConsumptionDisplay { | ||||
| func (cd *ConsumptionDisplay) Fee(f decimal.Decimal) *ConsumptionDisplay { | ||||
| 	cd.FeeStr = f.StringFixedBank(4) | ||||
| 	return cd | ||||
| } | ||||
|  | ||||
| func (cd ConsumptionDisplay) Price(p decimal.Decimal) ConsumptionDisplay { | ||||
| func (cd *ConsumptionDisplay) Price(p decimal.Decimal) *ConsumptionDisplay { | ||||
| 	cd.PriceStr = p.StringFixedBank(8) | ||||
| 	return cd | ||||
| } | ||||
|  | ||||
| func (cd ConsumptionDisplay) Proportion(p decimal.Decimal) ConsumptionDisplay { | ||||
| 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) | ||||
| func (cd *ConsumptionDisplay) FromConsumptionUnit(cu *model.ConsumptionUnit) ConsumptionDisplay { | ||||
| 	cd.Amount(cu.Amount).Fee(cu.Fee).Price(cu.Price).Proportion(cu.Proportion) | ||||
| 	return *cd | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user