320 lines
13 KiB
Go
320 lines
13 KiB
Go
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:"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)
|
|
}
|
|
}
|