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 { | type SimplifiedParkDetail struct { | ||||||
| 	Id          string  `json:"id"` | 	Id          string  `json:"id"` | ||||||
| 	UserId      string  `json:"user_id"` | 	UserId      string  `json:"userId"` | ||||||
| 	Name        string  `json:"name"` | 	Name        string  `json:"name"` | ||||||
| 	TenementStr *string `json:"tenement"` | 	TenementStr *string `json:"tenement"` | ||||||
| 	AreaStr     *string `json:"area"` | 	AreaStr     *string `json:"area"` | ||||||
|   | |||||||
							
								
								
									
										42
									
								
								vo/report.go
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								vo/report.go
									
									
									
									
									
								
							| @@ -75,9 +75,9 @@ type ComprehensiveReportQueryResponse struct { | |||||||
|  |  | ||||||
| type BasicReportIndexResponse struct { | type BasicReportIndexResponse struct { | ||||||
| 	Id                    string          `json:"id"` | 	Id                    string          `json:"id"` | ||||||
| 	Park                  string          `json:"park_id"` | 	Park                  string          `json:"parkId"` | ||||||
| 	PeriodBegin           types.Date      `json:"period_begin"` | 	PeriodBegin           types.Date      `json:"periodBegin"` | ||||||
| 	PeriodEnd             types.Date      `json:"period_end"` | 	PeriodEnd             types.Date      `json:"periodEnd"` | ||||||
| 	Category              int16           `json:"category"` | 	Category              int16           `json:"category"` | ||||||
| 	MeterType             int16           `json:"meter04kvType"` | 	MeterType             int16           `json:"meter04kvType"` | ||||||
| 	PricePolicy           int16           `json:"pricePolicy"` | 	PricePolicy           int16           `json:"pricePolicy"` | ||||||
| @@ -86,14 +86,14 @@ type BasicReportIndexResponse struct { | |||||||
| 	LossPooled            int16           `json:"lossDiluted"` | 	LossPooled            int16           `json:"lossDiluted"` | ||||||
| 	PublicPooled          int16           `json:"publicDiluted"` | 	PublicPooled          int16           `json:"publicDiluted"` | ||||||
| 	Published             bool            `json:"published"` | 	Published             bool            `json:"published"` | ||||||
| 	PublishedAt           *types.DateTime `json:"published_at"` | 	PublishedAt           *types.DateTime `json:"publishedAt"` | ||||||
| 	Withdraw              int16           `json:"withdraw"` | 	Withdraw              int16           `json:"withdraw"` | ||||||
| 	LastWithdrawAppliedAt *types.DateTime `json:"last_withdraw_applied_at"` | 	LastWithdrawAppliedAt *types.DateTime `json:"lastWithdrawAppliedAt"` | ||||||
| 	LastWithdrawAuditAt   *types.DateTime `json:"last_withdraw_audit_at"` | 	LastWithdrawAuditAt   *types.DateTime `json:"lastWithdrawAuditAt"` | ||||||
| 	Status                int16           `json:"status"` | 	Status                int16           `json:"status"` | ||||||
| 	Message               *string         `json:"message"` | 	Message               *string         `json:"message"` | ||||||
| 	CreatedAt             types.DateTime  `json:"created_at"` | 	CreatedAt             types.DateTime  `json:"createdAt"` | ||||||
| 	LastModifiedAt        types.DateTime  `json:"last_modified_at"` | 	LastModifiedAt        types.DateTime  `json:"lastModifiedAt"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func (bri *BasicReportIndexResponse) Period(p types.DateRange) { | func (bri *BasicReportIndexResponse) Period(p types.DateRange) { | ||||||
| @@ -116,8 +116,8 @@ func NewReportDetailQueryResponse(user *model.UserDetail, park *model.Park, repo | |||||||
| } | } | ||||||
|  |  | ||||||
| type ParkSummaryResponse struct { | type ParkSummaryResponse struct { | ||||||
| 	Id                      string             `json:"id"` | 	ReportId                string             `json:"reportId"` | ||||||
| 	Overall                 ConsumptionDisplay `json:"overall"` | 	OverallDisplay          ConsumptionDisplay `json:"overall"` | ||||||
| 	Area                    decimal.Decimal    `json:"area"` | 	Area                    decimal.Decimal    `json:"area"` | ||||||
| 	BasicFee                decimal.Decimal    `json:"basicFee"` | 	BasicFee                decimal.Decimal    `json:"basicFee"` | ||||||
| 	PooledBasicFeeByAmount  decimal.Decimal    `json:"pooledBasicFeeByAmount"` | 	PooledBasicFeeByAmount  decimal.Decimal    `json:"pooledBasicFeeByAmount"` | ||||||
| @@ -130,6 +130,10 @@ type ParkSummaryResponse struct { | |||||||
| 	LossRate                decimal.Decimal    `json:"lossRate"` | 	LossRate                decimal.Decimal    `json:"lossRate"` | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (psr *ParkSummaryResponse) Overall(value model.ConsumptionUnit) { | ||||||
|  | 	psr.OverallDisplay.FromConsumptionUnit(&value) | ||||||
|  | } | ||||||
|  |  | ||||||
| type SimplifiedReportSummary struct { | type SimplifiedReportSummary struct { | ||||||
| 	Overall        model.ConsumptionUnit `json:"overall"` | 	Overall        model.ConsumptionUnit `json:"overall"` | ||||||
| 	Critical       model.ConsumptionUnit `json:"critical"` | 	Critical       model.ConsumptionUnit `json:"critical"` | ||||||
| @@ -200,9 +204,9 @@ type ReportPublicQueryResponse struct { | |||||||
|  |  | ||||||
| func (rpqr *ReportPublicQueryResponse) FromReportDetailPublicConsumption(value *model.ReportDetailedPublicConsumption) { | func (rpqr *ReportPublicQueryResponse) FromReportDetailPublicConsumption(value *model.ReportDetailedPublicConsumption) { | ||||||
| 	copier.Copy(&rpqr.SimplifiedMeterQueryResponse, &value.MeterDetail) | 	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.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 { | type ReportPooledQueryResponse struct { | ||||||
| @@ -213,13 +217,13 @@ type ReportPooledQueryResponse struct { | |||||||
|  |  | ||||||
| func (rpqr *ReportPooledQueryResponse) FromReportDetailPooledConsumption(value *model.ReportDetailedPooledConsumption) { | func (rpqr *ReportPooledQueryResponse) FromReportDetailPooledConsumption(value *model.ReportDetailedPooledConsumption) { | ||||||
| 	copier.Copy(&rpqr.SimplifiedMeterQueryResponse, &value.MeterDetail) | 	copier.Copy(&rpqr.SimplifiedMeterQueryResponse, &value.MeterDetail) | ||||||
| 	rpqr.Overall = FromConsumptionUnit(&value.ReportPooledConsumption.Overall) | 	rpqr.Overall.FromConsumptionUnit(&value.ReportPooledConsumption.Overall) | ||||||
| 	rpqr.PoolMethod = value.PublicPooled | 	rpqr.PoolMethod = value.PublicPooled | ||||||
| } | } | ||||||
|  |  | ||||||
| func (rqpr *ReportPooledQueryResponse) FromReportDetailNestedMeterConsumption(value *model.ReportDetailNestedMeterConsumption) { | func (rqpr *ReportPooledQueryResponse) FromReportDetailNestedMeterConsumption(value *model.ReportDetailNestedMeterConsumption) { | ||||||
| 	copier.Copy(&rqpr.SimplifiedMeterQueryResponse, &value.Meter) | 	copier.Copy(&rqpr.SimplifiedMeterQueryResponse, &value.Meter) | ||||||
| 	rqpr.Overall = FromConsumptionUnit(&value.Consumption.Overall) | 	rqpr.Overall.FromConsumptionUnit(&value.Consumption.Overall) | ||||||
| 	rqpr.PoolMethod = -1 | 	rqpr.PoolMethod = -1 | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -273,11 +277,11 @@ type ReportMeterDetailResponse struct { | |||||||
|  |  | ||||||
| func (rmdr *ReportMeterDetailResponse) FromNestedMeter(value *model.NestedMeter) { | func (rmdr *ReportMeterDetailResponse) FromNestedMeter(value *model.NestedMeter) { | ||||||
| 	copier.Copy(&rmdr.SimplifiedMeterDetailResponse, &value.MeterDetail) | 	copier.Copy(&rmdr.SimplifiedMeterDetailResponse, &value.MeterDetail) | ||||||
| 	rmdr.Overall = FromConsumptionUnit(&value.Overall) | 	rmdr.Overall.FromConsumptionUnit(&value.Overall) | ||||||
| 	rmdr.Critical = FromConsumptionUnit(&value.Critical) | 	rmdr.Critical.FromConsumptionUnit(&value.Critical) | ||||||
| 	rmdr.Peak = FromConsumptionUnit(&value.Peak) | 	rmdr.Peak.FromConsumptionUnit(&value.Peak) | ||||||
| 	rmdr.Flat = FromConsumptionUnit(&value.Flat) | 	rmdr.Flat.FromConsumptionUnit(&value.Flat) | ||||||
| 	rmdr.Valley = FromConsumptionUnit(&value.Valley) | 	rmdr.Valley.FromConsumptionUnit(&value.Valley) | ||||||
| } | } | ||||||
|  |  | ||||||
| type ReportMeterExtendedDetailResponse struct { | type ReportMeterExtendedDetailResponse struct { | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								vo/shares.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								vo/shares.go
									
									
									
									
									
								
							| @@ -3,7 +3,6 @@ package vo | |||||||
| import ( | import ( | ||||||
| 	"electricity_bill_calc/model" | 	"electricity_bill_calc/model" | ||||||
|  |  | ||||||
| 	"github.com/jinzhu/copier" |  | ||||||
| 	"github.com/shopspring/decimal" | 	"github.com/shopspring/decimal" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -18,28 +17,27 @@ type ConsumptionDisplay struct { | |||||||
| 	ProportionStr string `json:"proportion"` | 	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) | 	cd.AmountStr = a.StringFixedBank(4) | ||||||
| 	return cd | 	return cd | ||||||
| } | } | ||||||
|  |  | ||||||
| func (cd ConsumptionDisplay) Fee(f decimal.Decimal) ConsumptionDisplay { | func (cd *ConsumptionDisplay) Fee(f decimal.Decimal) *ConsumptionDisplay { | ||||||
| 	cd.FeeStr = f.StringFixedBank(4) | 	cd.FeeStr = f.StringFixedBank(4) | ||||||
| 	return cd | 	return cd | ||||||
| } | } | ||||||
|  |  | ||||||
| func (cd ConsumptionDisplay) Price(p decimal.Decimal) ConsumptionDisplay { | func (cd *ConsumptionDisplay) Price(p decimal.Decimal) *ConsumptionDisplay { | ||||||
| 	cd.PriceStr = p.StringFixedBank(8) | 	cd.PriceStr = p.StringFixedBank(8) | ||||||
| 	return cd | 	return cd | ||||||
| } | } | ||||||
|  |  | ||||||
| func (cd ConsumptionDisplay) Proportion(p decimal.Decimal) ConsumptionDisplay { | func (cd *ConsumptionDisplay) Proportion(p decimal.Decimal) *ConsumptionDisplay { | ||||||
| 	cd.ProportionStr = p.StringFixedBank(8) | 	cd.ProportionStr = p.StringFixedBank(8) | ||||||
| 	return cd | 	return cd | ||||||
| } | } | ||||||
|  |  | ||||||
| func FromConsumptionUnit(cu *model.ConsumptionUnit) ConsumptionDisplay { | func (cd *ConsumptionDisplay) FromConsumptionUnit(cu *model.ConsumptionUnit) ConsumptionDisplay { | ||||||
| 	cd := &ConsumptionDisplay{} | 	cd.Amount(cu.Amount).Fee(cu.Fee).Price(cu.Price).Proportion(cu.Proportion) | ||||||
| 	copier.Copy(cd, cu) |  | ||||||
| 	return *cd | 	return *cd | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user