enhance(excel):增加对于表计档案和抄表记录两个 Excel 文件的解析器。

This commit is contained in:
徐涛 2023-06-10 06:37:34 +08:00
parent 48753eb3f0
commit 0020776218
3 changed files with 76 additions and 1 deletions

27
excel/meter_archive.go Normal file
View File

@ -0,0 +1,27 @@
package excel
import (
"electricity_bill_calc/model"
"io"
)
var meterArchiveRecognizers = []*ColumnRecognizer{
{Pattern: [][]string{{"表号"}}, Tag: "code", MatchIndex: -1, MustFill: true},
{Pattern: [][]string{{"表址", "地址", "户址"}}, Tag: "address", MatchIndex: -1},
{Pattern: [][]string{{"类型"}}, Tag: "meterType", MatchIndex: -1, MustFill: true},
{Pattern: [][]string{{"建筑"}}, Tag: "building", MatchIndex: -1},
{Pattern: [][]string{{"楼层"}}, Tag: "onFloor", MatchIndex: -1},
{Pattern: [][]string{{"面积"}}, Tag: "area", MatchIndex: -1},
{Pattern: [][]string{{"倍率"}}, Tag: "ratio", MatchIndex: -1, MustFill: true},
{Pattern: [][]string{{"序号"}}, Tag: "seq", MatchIndex: -1, MustFill: true},
{Pattern: [][]string{{"抄表"}, {"时间", "日期"}}, Tag: "readAt", MatchIndex: -1, MustFill: true},
{Pattern: [][]string{{"有功", "表底", "底数"}, {"总"}}, Tag: "overall", MatchIndex: -1, MustFill: true},
{Pattern: [][]string{{"有功", "表底", "底数"}, {"尖"}}, Tag: "critical", MatchIndex: -1},
{Pattern: [][]string{{"有功", "表底", "底数"}, {"峰"}}, Tag: "peak", MatchIndex: -1},
{Pattern: [][]string{{"有功", "表底", "底数"}, {"平"}}, Tag: "flat", MatchIndex: -1},
{Pattern: [][]string{{"有功", "表底", "底数"}, {"谷"}}, Tag: "valley", MatchIndex: -1},
}
func NewMeterArchiveExcelAnalyzer(file io.Reader) (*ExcelAnalyzer[model.MeterImportRow], error) {
return NewExcelAnalyzer[model.MeterImportRow](file, meterArchiveRecognizers)
}

19
excel/meter_reading.go Normal file
View File

@ -0,0 +1,19 @@
package excel
import (
"electricity_bill_calc/model"
"io"
)
var meterReadingsRecognizers = []*ColumnRecognizer{
{Pattern: [][]string{{"表", "表计"}, {"编号"}}, Tag: "code", MatchIndex: -1, MustFill: true},
{Pattern: [][]string{{"抄表", "结束"}, {"时间", "日期"}}, Tag: "readAt", MatchIndex: -1, MustFill: true},
{Pattern: [][]string{{"用电", "有功", "表底", "底数"}, {"总", "量"}}, Tag: "overall", MatchIndex: -1, MustFill: true},
{Pattern: [][]string{{"有功", "表底", "底数"}, {"尖", "尖锋"}}, Tag: "critical", MatchIndex: -1},
{Pattern: [][]string{{"有功", "表底", "底数"}, {"峰"}}, Tag: "peak", MatchIndex: -1},
{Pattern: [][]string{{"有功", "表底", "底数"}, {"谷"}}, Tag: "valley", MatchIndex: -1},
}
func NewMeterReadingsExcelAnalyzer(file io.Reader) (*ExcelAnalyzer[model.ReadingImportRow], error) {
return NewExcelAnalyzer[model.ReadingImportRow](file, meterReadingsRecognizers)
}

View File

@ -1,6 +1,7 @@
package model
import (
"electricity_bill_calc/types"
"time"
"github.com/shopspring/decimal"
@ -13,7 +14,7 @@ type MeterDetail struct {
MeterType int16 `json:"meterType" db:"meter_type"`
Building *string `json:"building" db:"building"`
BuildingName *string `json:"buildingName" db:"building_name"`
OnFloor *string `json:"onFloor" db:"on_floor"`
OnFloor *string `json:"onFloor" db:"on_floor" `
Area decimal.NullDecimal `json:"area" db:"area"`
Ratio decimal.Decimal `json:"ratio" db:"ratio"`
Seq int64 `json:"seq" db:"seq"`
@ -76,3 +77,31 @@ type PooledMeterDetailCompound struct {
MeterDetail
BindMeters []MeterDetail `json:"bindMeters"`
}
// 以下结构体用于导入表计档案数据
type MeterImportRow struct {
Code string `json:"code" excel:"code"`
Address *string `json:"address" excel:"address"`
MeterType int16 `json:"meterType" excel:"meterType"`
Building *string `json:"building" excel:"building"`
OnFloor *string `json:"onFloor" excel:"onFloor"`
Area decimal.NullDecimal `json:"area" excel:"area"`
Ratio decimal.Decimal `json:"ratio" excel:"ratio"`
Seq int64 `json:"seq" excel:"seq"`
ReadAt types.DateTime `json:"readAt" excel:"readAt"`
Overall decimal.Decimal `json:"overall" excel:"overall"`
Critical decimal.NullDecimal `json:"critical" excel:"critical"`
Peak decimal.NullDecimal `json:"peak" excel:"peak"`
Flat decimal.NullDecimal `json:"flat" excel:"flat"`
Valley decimal.NullDecimal `json:"valley" excel:"valley"`
}
// 以下结构体用于导入表计抄表数据
type ReadingImportRow struct {
Code string `json:"code" excel:"code"`
ReadAt types.DateTime `json:"readAt" excel:"readAt"`
Overall decimal.Decimal `json:"overall" excel:"overall"`
Critical decimal.NullDecimal `json:"critical" excel:"critical"`
Peak decimal.NullDecimal `json:"peak" excel:"peak"`
Valley decimal.NullDecimal `json:"valley" excel:"valley"`
}