From ad19169ac5081485b3a7a4d7951f90baeb17158d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Wed, 24 Aug 2022 08:53:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(model):=E8=A1=A5=E5=85=85=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=97=B6=E4=B8=A2=E5=A4=B1=E7=9A=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=AD=97=E6=AE=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/park.go | 15 +++++++++++++-- model/report.go | 2 ++ service/report.go | 20 ++++++++++++++------ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/model/park.go b/model/park.go index 9002df3..2c7eb52 100644 --- a/model/park.go +++ b/model/park.go @@ -6,6 +6,17 @@ import ( "github.com/shopspring/decimal" ) +const ( + CATEGORY_TWO_PART int8 = iota + CATEGORY_SINGLE_PV + CATEGORY_SINGLE_NON_PV +) + +const ( + CUSTOMER_METER_NON_PV int8 = iota + CUSTOMER_METER_PV +) + type Park struct { CreatedAndModified `xorm:"extends"` Deleted `xorm:"extends"` @@ -16,8 +27,8 @@ type Park struct { Area decimal.NullDecimal `xorm:"numeric(14,2)" json:"area"` TenementQuantity decimal.NullDecimal `xorm:"numeric(8,0)" json:"tenement"` Capacity decimal.NullDecimal `xorm:"numeric(16,2)" json:"capacity"` - Category int8 `xorm:"smallint not null" json:"category"` - SubmeterType int8 `xorm:"'meter_04kv_type' smallint not null" json:"meter04kvType"` + Category int8 `xorm:"smallint not null default 0" json:"category"` + SubmeterType int8 `xorm:"'meter_04kv_type' smallint not null default 0" json:"meter04kvType"` Region *string `xorm:"varchar(10)" json:"region"` Address *string `xorm:"varchar(120)" json:"address"` Contact *string `xorm:"varchar(100)" json:"contact"` diff --git a/model/report.go b/model/report.go index d4961be..9786218 100644 --- a/model/report.go +++ b/model/report.go @@ -14,6 +14,8 @@ type Report struct { Id string `xorm:"varchar(120) pk not null" json:"id"` ParkId string `xorm:"varchar(120) not null" json:"parkId"` Period time.Time `xorm:"date not null" json:"period" time_format:"simple_date" time_location:"shanghai"` + Category int8 `xorm:"smallint not null default 0" json:"category"` + SubmeterType int8 `xorm:"'meter_04kv_type' smallint not null default 0" json:"meter04kvType"` StepState Steps `xorm:"text not null json" json:"stepState"` Published bool `xorm:"bool not null default false" json:"published"` PublishedAt *time.Time `xorm:"timestampz" json:"publishedAt" time_format:"simple_datetime" time_location:"shanghai"` diff --git a/service/report.go b/service/report.go index de74e8a..14d637c 100644 --- a/service/report.go +++ b/service/report.go @@ -6,6 +6,7 @@ import ( "electricity_bill_calc/global" "electricity_bill_calc/model" "electricity_bill_calc/tools" + "fmt" "time" "github.com/fufuok/utils" @@ -154,6 +155,11 @@ func (_ReportService) InitializeNewReport(parkId string, period time.Time) (stri if err != nil { return "", err } + var parkInfo = new(model.Park) + has, err := global.DBConn.ID(parkId).NoAutoCondition().Get(parkInfo) + if err != nil || !has { + return "", exceptions.NewNotFoundError(fmt.Sprintf("指定园区未找到, %v", err)) + } // 生成新一期的报表 tx := global.DBConn.NewSession() if err = tx.Begin(); err != nil { @@ -162,12 +168,14 @@ func (_ReportService) InitializeNewReport(parkId string, period time.Time) (stri defer tx.Close() // 插入已经生成的报表索引信息和园区概况信息 newReport := model.Report{ - Id: uuid.New().String(), - ParkId: parkId, - Period: period, - StepState: model.NewSteps(), - Published: false, - Withdraw: model.REPORT_NOT_WITHDRAW, + Id: uuid.New().String(), + ParkId: parkId, + Period: period, + Category: parkInfo.Category, + SubmeterType: parkInfo.SubmeterType, + StepState: model.NewSteps(), + Published: false, + Withdraw: model.REPORT_NOT_WITHDRAW, } newReportSummary := model.ReportSummary{ ReportId: newReport.Id,