enhance(meter):恢复对于表计类型的解析错误提示,并在表计类型解析出现错误的时候停下来。
This commit is contained in:
parent
6f0edc54bf
commit
23e9e2ec4d
|
@ -1,6 +1,7 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,19 +20,18 @@ const (
|
||||||
METER_INSTALLATION_TENEMENT int16 = iota
|
METER_INSTALLATION_TENEMENT int16 = iota
|
||||||
METER_INSTALLATION_PARK
|
METER_INSTALLATION_PARK
|
||||||
METER_INSTALLATION_POOLING
|
METER_INSTALLATION_POOLING
|
||||||
METER_INSTALLATION_UNDEFINED = 99
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseMeterInstallationType(s string) int16 {
|
func ParseMeterInstallationType(s string) (int16, error) {
|
||||||
switch {
|
switch {
|
||||||
case strings.Contains(s, "商户"):
|
case strings.Contains(s, "商户"):
|
||||||
return METER_INSTALLATION_TENEMENT
|
return METER_INSTALLATION_TENEMENT, nil
|
||||||
case strings.Contains(s, "公共"):
|
case strings.Contains(s, "公共"):
|
||||||
return METER_INSTALLATION_PARK
|
return METER_INSTALLATION_PARK, nil
|
||||||
case strings.Contains(s, "楼道"):
|
case strings.Contains(s, "楼道"):
|
||||||
return METER_INSTALLATION_POOLING
|
return METER_INSTALLATION_POOLING, nil
|
||||||
default:
|
default:
|
||||||
return METER_INSTALLATION_UNDEFINED
|
return -1, fmt.Errorf("提供了一个无法识别的表计类型: %s", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,27 +204,55 @@ func (ms _MeterService) BatchImportMeters(pid string, file *multipart.FileHeader
|
||||||
ms.log.Error("无法启动数据插入阶段的数据库事务。", zap.Error(err))
|
ms.log.Error("无法启动数据插入阶段的数据库事务。", zap.Error(err))
|
||||||
return make([]excel.ExcelAnalysisError, 0), fmt.Errorf("无法启动数据插入阶段的数据库事务,%w", err)
|
return make([]excel.ExcelAnalysisError, 0), fmt.Errorf("无法启动数据插入阶段的数据库事务,%w", err)
|
||||||
}
|
}
|
||||||
meterCreationForms := lo.Map(records, func(element model.MeterImportRow, _ int) vo.MeterCreationForm {
|
var meterCreationForms = make([]vo.MeterCreationForm, 0)
|
||||||
return vo.MeterCreationForm{
|
for row, element := range records {
|
||||||
Code: element.Code,
|
if element.MeterType != nil {
|
||||||
Address: element.Address,
|
meterType, err := model.ParseMeterInstallationType(*element.MeterType)
|
||||||
MeterType: model.ParseMeterInstallationType(*element.MeterType),
|
if err != nil {
|
||||||
Ratio: element.Ratio,
|
ms.log.Error("无法识别表计类型。", zap.Int("record_index", row), zap.Error(err))
|
||||||
Seq: element.Seq,
|
errs = append(errs, excel.ExcelAnalysisError{
|
||||||
Enabled: true,
|
Row: row + 1,
|
||||||
Building: element.Building,
|
Col: 3,
|
||||||
OnFloor: element.OnFloor,
|
Err: excel.AnalysisError{
|
||||||
Area: element.Area,
|
Err: fmt.Errorf("表计类型无法识别"),
|
||||||
MeterReadingForm: vo.MeterReadingForm{
|
},
|
||||||
ReadAt: &element.ReadAt,
|
})
|
||||||
Overall: element.Overall,
|
}
|
||||||
Critical: element.Critical.Decimal,
|
meterCreationForms = append(meterCreationForms, vo.MeterCreationForm{
|
||||||
Peak: element.Peak.Decimal,
|
Code: element.Code,
|
||||||
Flat: element.Flat.Decimal,
|
Address: element.Address,
|
||||||
Valley: element.Valley.Decimal,
|
MeterType: meterType,
|
||||||
},
|
Ratio: element.Ratio,
|
||||||
|
Seq: element.Seq,
|
||||||
|
Enabled: true,
|
||||||
|
Building: element.Building,
|
||||||
|
OnFloor: element.OnFloor,
|
||||||
|
Area: element.Area,
|
||||||
|
MeterReadingForm: vo.MeterReadingForm{
|
||||||
|
ReadAt: &element.ReadAt,
|
||||||
|
Overall: element.Overall,
|
||||||
|
Critical: element.Critical.Decimal,
|
||||||
|
Peak: element.Peak.Decimal,
|
||||||
|
Flat: element.Flat.Decimal,
|
||||||
|
Valley: element.Valley.Decimal,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
ms.log.Error("表计类型不能为空。", zap.Int("record_index", row))
|
||||||
|
errs = append(errs, excel.ExcelAnalysisError{
|
||||||
|
Row: row + 1,
|
||||||
|
Col: 3,
|
||||||
|
Err: excel.AnalysisError{
|
||||||
|
Err: fmt.Errorf("表计类型不能为空"),
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
if len(errs) > 0 {
|
||||||
|
ms.log.Error("表计档案分析器在解析上传的 Excel 文件时发生错误。", zap.Int("error count", len(errs)))
|
||||||
|
tx.Rollback(ctx)
|
||||||
|
return errs, fmt.Errorf("表计档案分析器在解析上传的 Excel 文件时发生错误。")
|
||||||
|
}
|
||||||
for _, record := range meterCreationForms {
|
for _, record := range meterCreationForms {
|
||||||
_, err := repository.MeterRepository.CreateOrUpdateMeter(tx, ctx, pid, record)
|
_, err := repository.MeterRepository.CreateOrUpdateMeter(tx, ctx, pid, record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user