forked from free-lancers/electricity_bill_calc_service
		
	enhance(meter):完成大部分表计相关的接口。
This commit is contained in:
		| @@ -36,3 +36,9 @@ 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"` | ||||
| } | ||||
|   | ||||
| @@ -1,7 +1,9 @@ | ||||
| package vo | ||||
|  | ||||
| import ( | ||||
| 	"electricity_bill_calc/model" | ||||
| 	"electricity_bill_calc/types" | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/shopspring/decimal" | ||||
| ) | ||||
| @@ -14,3 +16,60 @@ type MeterReadingForm struct { | ||||
| 	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.LessThan(decimal.Zero) | ||||
| } | ||||
|  | ||||
| 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, | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user