From 6f0edc54bf03d42d78a2adda87cf7cfe006a01af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Tue, 13 Jun 2023 10:59:49 +0800 Subject: [PATCH] =?UTF-8?q?enhance(meter):=E8=B0=83=E6=95=B4=E5=AF=B9?= =?UTF-8?q?=E4=BA=8E=E8=A1=A8=E8=AE=A1=E7=B1=BB=E5=9E=8B=E7=9A=84=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/enums.go | 18 ++++++++++++++++++ model/meter.go | 2 +- service/meter.go | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/model/enums.go b/model/enums.go index bdbb9c1..fd8b0db 100644 --- a/model/enums.go +++ b/model/enums.go @@ -1,5 +1,9 @@ package model +import ( + "strings" +) + const ( ELECTRICITY_CATE_TWO_PART int16 = iota ELECTRICITY_CATE_UNITARY_PV @@ -15,8 +19,22 @@ const ( METER_INSTALLATION_TENEMENT int16 = iota METER_INSTALLATION_PARK METER_INSTALLATION_POOLING + METER_INSTALLATION_UNDEFINED = 99 ) +func ParseMeterInstallationType(s string) int16 { + switch { + case strings.Contains(s, "商户"): + return METER_INSTALLATION_TENEMENT + case strings.Contains(s, "公共"): + return METER_INSTALLATION_PARK + case strings.Contains(s, "楼道"): + return METER_INSTALLATION_POOLING + default: + return METER_INSTALLATION_UNDEFINED + } +} + const ( PRICING_POLICY_CONSUMPTION int16 = iota PRICING_POLICY_ALL diff --git a/model/meter.go b/model/meter.go index e68b603..d592fdc 100644 --- a/model/meter.go +++ b/model/meter.go @@ -81,7 +81,7 @@ type PooledMeterDetailCompound struct { type MeterImportRow struct { Code string `json:"code" excel:"code"` Address *string `json:"address" excel:"address"` - MeterType int16 `json:"meterType" excel:"meterType"` + MeterType *string `json:"meterType" excel:"meterType"` Building *string `json:"building" excel:"building"` OnFloor *string `json:"onFloor" excel:"onFloor"` Area decimal.NullDecimal `json:"area" excel:"area"` diff --git a/service/meter.go b/service/meter.go index c3c85bc..182c987 100644 --- a/service/meter.go +++ b/service/meter.go @@ -208,7 +208,7 @@ func (ms _MeterService) BatchImportMeters(pid string, file *multipart.FileHeader return vo.MeterCreationForm{ Code: element.Code, Address: element.Address, - MeterType: element.MeterType, + MeterType: model.ParseMeterInstallationType(*element.MeterType), Ratio: element.Ratio, Seq: element.Seq, Enabled: true,