enhance(report):合并精简用户抄表记录的更新操作。
This commit is contained in:
parent
1d60706108
commit
aec0cd379f
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
|
"xorm.io/xorm"
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,6 +56,29 @@ func (_EndUserService) AllEndUserRecord(reportId string) ([]model.EndUserDetail,
|
||||||
return users, err
|
return users, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_EndUserService) UpdateEndUserRegisterRecord(tx *xorm.Session, record model.EndUserDetail) (err error) {
|
||||||
|
record.CalculatePeriod()
|
||||||
|
_, err = tx.ID(schemas.NewPK(record.ReportId, record.ParkId, record.MeterId)).
|
||||||
|
Cols(
|
||||||
|
"current_period_overall",
|
||||||
|
"adjust_overall",
|
||||||
|
"current_period_critical",
|
||||||
|
"current_period_peak",
|
||||||
|
"current_period_flat",
|
||||||
|
"current_perios_valley",
|
||||||
|
"adjust_critical",
|
||||||
|
"adjust_peak",
|
||||||
|
"adjust_flat",
|
||||||
|
"adjust_valley",
|
||||||
|
).
|
||||||
|
Update(record)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_EndUserService) newVirtualExcelAnalysisError(err error) *excel.ExcelAnalysisError {
|
||||||
|
return &excel.ExcelAnalysisError{Col: -1, Row: -1, Err: excel.AnalysisError{Err: err}}
|
||||||
|
}
|
||||||
|
|
||||||
func (es _EndUserService) BatchImportNonPVRegister(reportId string, file io.Reader) *exceptions.BatchError {
|
func (es _EndUserService) BatchImportNonPVRegister(reportId string, file io.Reader) *exceptions.BatchError {
|
||||||
errs := exceptions.NewBatchError()
|
errs := exceptions.NewBatchError()
|
||||||
users, err := es.AllEndUserRecord(reportId)
|
users, err := es.AllEndUserRecord(reportId)
|
||||||
|
@ -99,21 +123,7 @@ func (es _EndUserService) BatchImportNonPVRegister(reportId string, file io.Read
|
||||||
elem.AdjustCritical = decimal.Zero
|
elem.AdjustCritical = decimal.Zero
|
||||||
elem.AdjustPeak = decimal.Zero
|
elem.AdjustPeak = decimal.Zero
|
||||||
elem.AdjustValley = decimal.Zero
|
elem.AdjustValley = decimal.Zero
|
||||||
elem.CalculatePeriod()
|
err := es.UpdateEndUserRegisterRecord(tx, elem)
|
||||||
_, err = tx.ID(schemas.NewPK(elem.ReportId, elem.ParkId, elem.MeterId)).
|
|
||||||
Cols(
|
|
||||||
"current_period_overall",
|
|
||||||
"adjust_overall",
|
|
||||||
"current_period_critical",
|
|
||||||
"current_period_peak",
|
|
||||||
"current_period_flat",
|
|
||||||
"current_perios_valley",
|
|
||||||
"adjust_critical",
|
|
||||||
"adjust_peak",
|
|
||||||
"adjust_flat",
|
|
||||||
"adjust_valley",
|
|
||||||
).
|
|
||||||
Update(elem)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs.AddError(es.newVirtualExcelAnalysisError(err))
|
errs.AddError(es.newVirtualExcelAnalysisError(err))
|
||||||
}
|
}
|
||||||
|
@ -134,10 +144,6 @@ func (es _EndUserService) BatchImportNonPVRegister(reportId string, file io.Read
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_EndUserService) newVirtualExcelAnalysisError(err error) *excel.ExcelAnalysisError {
|
|
||||||
return &excel.ExcelAnalysisError{Col: -1, Row: -1, Err: excel.AnalysisError{Err: err}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (es _EndUserService) BatchImportPVRegister(reportId string, file io.Reader) *exceptions.BatchError {
|
func (es _EndUserService) BatchImportPVRegister(reportId string, file io.Reader) *exceptions.BatchError {
|
||||||
errs := exceptions.NewBatchError()
|
errs := exceptions.NewBatchError()
|
||||||
users, err := es.AllEndUserRecord(reportId)
|
users, err := es.AllEndUserRecord(reportId)
|
||||||
|
@ -182,21 +188,7 @@ func (es _EndUserService) BatchImportPVRegister(reportId string, file io.Reader)
|
||||||
elem.AdjustCritical = im.AdjustCritical.Decimal
|
elem.AdjustCritical = im.AdjustCritical.Decimal
|
||||||
elem.AdjustPeak = im.AdjustPeak.Decimal
|
elem.AdjustPeak = im.AdjustPeak.Decimal
|
||||||
elem.AdjustValley = im.AdjustValley.Decimal
|
elem.AdjustValley = im.AdjustValley.Decimal
|
||||||
elem.CalculatePeriod()
|
err := es.UpdateEndUserRegisterRecord(tx, elem)
|
||||||
_, err = tx.ID(schemas.NewPK(elem.ReportId, elem.ParkId, elem.MeterId)).
|
|
||||||
Cols(
|
|
||||||
"current_period_overall",
|
|
||||||
"adjust_overall",
|
|
||||||
"current_period_critical",
|
|
||||||
"current_period_peak",
|
|
||||||
"current_period_flat",
|
|
||||||
"current_perios_valley",
|
|
||||||
"adjust_critical",
|
|
||||||
"adjust_peak",
|
|
||||||
"adjust_flat",
|
|
||||||
"adjust_valley",
|
|
||||||
).
|
|
||||||
Update(elem)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs.AddError(es.newVirtualExcelAnalysisError(err))
|
errs.AddError(es.newVirtualExcelAnalysisError(err))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user