enhance(report):合并精简用户抄表记录的更新操作。
This commit is contained in:
parent
1d60706108
commit
aec0cd379f
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/samber/lo"
|
||||
"github.com/shopspring/decimal"
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
|
@ -55,6 +56,29 @@ func (_EndUserService) AllEndUserRecord(reportId string) ([]model.EndUserDetail,
|
|||
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 {
|
||||
errs := exceptions.NewBatchError()
|
||||
users, err := es.AllEndUserRecord(reportId)
|
||||
|
@ -99,21 +123,7 @@ func (es _EndUserService) BatchImportNonPVRegister(reportId string, file io.Read
|
|||
elem.AdjustCritical = decimal.Zero
|
||||
elem.AdjustPeak = decimal.Zero
|
||||
elem.AdjustValley = decimal.Zero
|
||||
elem.CalculatePeriod()
|
||||
_, 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)
|
||||
err := es.UpdateEndUserRegisterRecord(tx, elem)
|
||||
if err != nil {
|
||||
errs.AddError(es.newVirtualExcelAnalysisError(err))
|
||||
}
|
||||
|
@ -134,10 +144,6 @@ func (es _EndUserService) BatchImportNonPVRegister(reportId string, file io.Read
|
|||
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 {
|
||||
errs := exceptions.NewBatchError()
|
||||
users, err := es.AllEndUserRecord(reportId)
|
||||
|
@ -182,21 +188,7 @@ func (es _EndUserService) BatchImportPVRegister(reportId string, file io.Reader)
|
|||
elem.AdjustCritical = im.AdjustCritical.Decimal
|
||||
elem.AdjustPeak = im.AdjustPeak.Decimal
|
||||
elem.AdjustValley = im.AdjustValley.Decimal
|
||||
elem.CalculatePeriod()
|
||||
_, 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)
|
||||
err := es.UpdateEndUserRegisterRecord(tx, elem)
|
||||
if err != nil {
|
||||
errs.AddError(es.newVirtualExcelAnalysisError(err))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user