feat(god):增加重新同步终端用户档案的功能。
This commit is contained in:
parent
ac70adf92a
commit
e3f6af886b
|
@ -16,6 +16,7 @@ func InitializeGodModeController(router *gin.Engine) {
|
||||||
gmR.DELETE("/report/:rid/summary", security.SingularityAuthorize, gmResetReportSummary)
|
gmR.DELETE("/report/:rid/summary", security.SingularityAuthorize, gmResetReportSummary)
|
||||||
gmR.DELETE("/report/:rid/maintenance", security.SingularityAuthorize, gmResetReportMaintenance)
|
gmR.DELETE("/report/:rid/maintenance", security.SingularityAuthorize, gmResetReportMaintenance)
|
||||||
gmR.DELETE("/report/:rid/meters", security.SingularityAuthorize, gmResetReportEndUserRecord)
|
gmR.DELETE("/report/:rid/meters", security.SingularityAuthorize, gmResetReportEndUserRecord)
|
||||||
|
gmR.POST("/report/:rid/meters", security.SingularityAuthorize, gmResynchronizeReportEndUserRecord)
|
||||||
gmR.DELETE("/report/:rid", security.SingularityAuthorize, gmResetReport)
|
gmR.DELETE("/report/:rid", security.SingularityAuthorize, gmResetReport)
|
||||||
gmR.DELETE("/report/:rid/force", security.SingularityAuthorize, gmDeleteReport)
|
gmR.DELETE("/report/:rid/force", security.SingularityAuthorize, gmDeleteReport)
|
||||||
gmR.DELETE("/park/:pid/maintenance/:mid", security.SingularityAuthorize, gmDeleteSpecificMaintenance)
|
gmR.DELETE("/park/:pid/maintenance/:mid", security.SingularityAuthorize, gmDeleteSpecificMaintenance)
|
||||||
|
@ -56,6 +57,21 @@ func gmResetReportMaintenance(c *gin.Context) {
|
||||||
result.Success("指定报表的配电维护费已经重置。")
|
result.Success("指定报表的配电维护费已经重置。")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func gmResynchronizeReportEndUserRecord(c *gin.Context) {
|
||||||
|
result := response.NewResult(c)
|
||||||
|
requestReportId := c.Param("rid")
|
||||||
|
done, err := service.GodModeService.ResynchronizeEndUser(requestReportId)
|
||||||
|
if err != nil {
|
||||||
|
result.Error(http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !done {
|
||||||
|
result.Error(http.StatusInternalServerError, "未能成功重置指定报表的抄表记录基本档案。")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result.Success("指定报表的抄表记录基本档案已经重新同步。")
|
||||||
|
}
|
||||||
|
|
||||||
func gmResetReportEndUserRecord(c *gin.Context) {
|
func gmResetReportEndUserRecord(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
requestReportId := c.Param("rid")
|
requestReportId := c.Param("rid")
|
||||||
|
|
|
@ -108,47 +108,38 @@ func (_GodModeService) flushReportMaintenances(tx *xorm.Session, reportId string
|
||||||
return rows >= 0, err
|
return rows >= 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_GodModeService) resetEndUserRecords(tx *xorm.Session, reportId string) (bool, error) {
|
func (_GodModeService) resetSingleEndUserRecord(tx *xorm.Session, record *model.EndUserDetail, additionalColumns ...string) (bool, error) {
|
||||||
var records = make([]*model.EndUserDetail, 0)
|
record.CurrentPeriodOverall = decimal.Zero
|
||||||
err := tx.Where(builder.Eq{"report_id": reportId}).Find(&records)
|
record.CurrentPeriodCritical = decimal.Zero
|
||||||
if err != nil {
|
record.CurrentPeriodPeak = decimal.Zero
|
||||||
tx.Rollback()
|
record.CurrentPeriodFlat = decimal.Zero
|
||||||
return false, err
|
record.CurrentPeriodValley = decimal.Zero
|
||||||
}
|
record.AdjustOverall = decimal.Zero
|
||||||
for _, u := range records {
|
record.AdjustCritical = decimal.Zero
|
||||||
u.CurrentPeriodOverall = decimal.Zero
|
record.AdjustPeak = decimal.Zero
|
||||||
u.CurrentPeriodCritical = decimal.Zero
|
record.AdjustFlat = decimal.Zero
|
||||||
u.CurrentPeriodPeak = decimal.Zero
|
record.AdjustValley = decimal.Zero
|
||||||
u.CurrentPeriodFlat = decimal.Zero
|
record.Overall.Valid = false
|
||||||
u.CurrentPeriodValley = decimal.Zero
|
record.OverallFee.Valid = false
|
||||||
u.AdjustOverall = decimal.Zero
|
record.OverallProportion = decimal.Zero
|
||||||
u.AdjustCritical = decimal.Zero
|
record.Critical.Valid = false
|
||||||
u.AdjustPeak = decimal.Zero
|
record.CriticalFee.Valid = false
|
||||||
u.AdjustFlat = decimal.Zero
|
record.Peak.Valid = false
|
||||||
u.AdjustValley = decimal.Zero
|
record.PeakFee.Valid = false
|
||||||
u.Overall.Valid = false
|
record.Flat.Valid = false
|
||||||
u.OverallFee.Valid = false
|
record.FlatFee.Valid = false
|
||||||
u.OverallProportion = decimal.Zero
|
record.Valley.Valid = false
|
||||||
u.Critical.Valid = false
|
record.ValleyFee.Valid = false
|
||||||
u.CriticalFee.Valid = false
|
record.BasicFeeDiluted.Valid = false
|
||||||
u.Peak.Valid = false
|
record.AdjustFeeDiluted.Valid = false
|
||||||
u.PeakFee.Valid = false
|
record.LossDiluted.Valid = false
|
||||||
u.Flat.Valid = false
|
record.LossFeeDiluted.Valid = false
|
||||||
u.FlatFee.Valid = false
|
record.MaintenanceFeeDiluted.Valid = false
|
||||||
u.Valley.Valid = false
|
record.FinalDiluted.Valid = false
|
||||||
u.ValleyFee.Valid = false
|
record.PublicConsumptionDiluted.Valid = false
|
||||||
u.BasicFeeDiluted.Valid = false
|
record.FinalCharge.Valid = false
|
||||||
u.AdjustFeeDiluted.Valid = false
|
|
||||||
u.LossDiluted.Valid = false
|
|
||||||
u.LossFeeDiluted.Valid = false
|
|
||||||
u.MaintenanceFeeDiluted.Valid = false
|
|
||||||
u.FinalDiluted.Valid = false
|
|
||||||
u.PublicConsumptionDiluted.Valid = false
|
|
||||||
u.FinalCharge.Valid = false
|
|
||||||
|
|
||||||
affected, err := tx.
|
columns := []string{
|
||||||
ID(schemas.PK{u.ReportId, u.ParkId, u.MeterId}).
|
|
||||||
MustCols(
|
|
||||||
"current_period_overall",
|
"current_period_overall",
|
||||||
"current_period_critical",
|
"current_period_critical",
|
||||||
"current_period_peak",
|
"current_period_peak",
|
||||||
|
@ -178,16 +169,114 @@ func (_GodModeService) resetEndUserRecords(tx *xorm.Session, reportId string) (b
|
||||||
"public_consumption_diluted",
|
"public_consumption_diluted",
|
||||||
"final_diluted",
|
"final_diluted",
|
||||||
"final_charge",
|
"final_charge",
|
||||||
).
|
}
|
||||||
Update(u)
|
columns = append(columns, additionalColumns...)
|
||||||
|
|
||||||
|
affected, err := tx.
|
||||||
|
ID(schemas.PK{record.ReportId, record.ParkId, record.MeterId}).
|
||||||
|
MustCols(columns...).
|
||||||
|
Update(record)
|
||||||
|
if err != nil || affected == 0 {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g _GodModeService) resynchronizeEndUserArchives(tx *xorm.Session, reportId string) (bool, error) {
|
||||||
|
var currentRecords = make([]*model.EndUserDetail, 0)
|
||||||
|
err := tx.Where(builder.Eq{"report_id": reportId}).Find(¤tRecords)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if affected == 0 {
|
var report = new(model.Report)
|
||||||
|
has, err := tx.ID(reportId).NoAutoCondition().Unscoped().Get(report)
|
||||||
|
if err != nil || !has {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
var latestArchives = make([]model.Meter04KV, 0)
|
||||||
|
err = tx.Table(new(model.Meter04KV)).Where(builder.Eq{"park_id": report.ParkId}).Find(&latestArchives)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, meter := range latestArchives {
|
||||||
|
record, has := lo.Find(currentRecords, func(rec *model.EndUserDetail) bool {
|
||||||
|
return rec.ParkId == meter.ParkId && rec.MeterId == meter.Code
|
||||||
|
})
|
||||||
|
if has {
|
||||||
|
record.CustomerName = meter.CustomerName
|
||||||
|
record.Address = meter.Address
|
||||||
|
record.Ratio = meter.Ratio
|
||||||
|
record.ContactName = meter.ContactName
|
||||||
|
record.ContactPhone = meter.ContactPhone
|
||||||
|
record.Seq = meter.Seq
|
||||||
|
record.IsPublicMeter = meter.IsPublicMeter
|
||||||
|
record.WillDilute = meter.WillDilute
|
||||||
|
success, err := g.resetSingleEndUserRecord(
|
||||||
|
tx, record,
|
||||||
|
"customer_name",
|
||||||
|
"address",
|
||||||
|
"ratio",
|
||||||
|
"contact_name",
|
||||||
|
"contact_phone",
|
||||||
|
"seq",
|
||||||
|
"public_meter",
|
||||||
|
"dilute",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return success, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newEndUser := model.EndUserDetail{
|
||||||
|
ReportId: report.Id,
|
||||||
|
ParkId: report.ParkId,
|
||||||
|
MeterId: meter.Code,
|
||||||
|
Seq: meter.Seq,
|
||||||
|
Ratio: meter.Ratio,
|
||||||
|
Address: meter.Address,
|
||||||
|
CustomerName: meter.CustomerName,
|
||||||
|
ContactName: meter.ContactName,
|
||||||
|
ContactPhone: meter.ContactPhone,
|
||||||
|
IsPublicMeter: meter.IsPublicMeter,
|
||||||
|
WillDilute: meter.WillDilute,
|
||||||
|
LastPeriodOverall: decimal.Zero,
|
||||||
|
LastPeriodCritical: decimal.Zero,
|
||||||
|
LastPeriodPeak: decimal.Zero,
|
||||||
|
LastPeriodFlat: decimal.Zero,
|
||||||
|
LastPeriodValley: decimal.Zero,
|
||||||
|
}
|
||||||
|
_, err = tx.Insert(newEndUser)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
report.StepState.Submeter = false
|
||||||
|
rows, err := tx.ID(reportId).Cols("step_state").NoAutoCondition().Update(report)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
return rows >= 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g _GodModeService) resetEndUserRecords(tx *xorm.Session, reportId string) (bool, error) {
|
||||||
|
var records = make([]*model.EndUserDetail, 0)
|
||||||
|
err := tx.Where(builder.Eq{"report_id": reportId}).Find(&records)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
for _, u := range records {
|
||||||
|
success, err := g.resetSingleEndUserRecord(tx, u)
|
||||||
|
if err != nil {
|
||||||
|
return success, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var report = new(model.Report)
|
var report = new(model.Report)
|
||||||
_, err = tx.ID(reportId).NoAutoCondition().Unscoped().Get(report)
|
_, err = tx.ID(reportId).NoAutoCondition().Unscoped().Get(report)
|
||||||
|
@ -256,6 +345,13 @@ func (_GodModeService) forceDeleteReport(tx *xorm.Session, reportId string) (boo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) ClearReportSummary(reportId string) (bool, error) {
|
func (g _GodModeService) ClearReportSummary(reportId string) (bool, error) {
|
||||||
|
isLatest, err := g.isTheLatestReport(reportId)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if !isLatest {
|
||||||
|
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
||||||
|
}
|
||||||
tx := global.DBConn.NewSession()
|
tx := global.DBConn.NewSession()
|
||||||
if err := tx.Begin(); err != nil {
|
if err := tx.Begin(); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -277,6 +373,13 @@ func (g _GodModeService) ClearReportSummary(reportId string) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) ClearReportMaintenances(reportId string) (bool, error) {
|
func (g _GodModeService) ClearReportMaintenances(reportId string) (bool, error) {
|
||||||
|
isLatest, err := g.isTheLatestReport(reportId)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if !isLatest {
|
||||||
|
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
||||||
|
}
|
||||||
tx := global.DBConn.NewSession()
|
tx := global.DBConn.NewSession()
|
||||||
if err := tx.Begin(); err != nil {
|
if err := tx.Begin(); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -297,7 +400,43 @@ func (g _GodModeService) ClearReportMaintenances(reportId string) (bool, error)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g _GodModeService) ResynchronizeEndUser(reportId string) (bool, error) {
|
||||||
|
isLatest, err := g.isTheLatestReport(reportId)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if !isLatest {
|
||||||
|
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
||||||
|
}
|
||||||
|
tx := global.DBConn.NewSession()
|
||||||
|
if err := tx.Begin(); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
defer tx.Close()
|
||||||
|
|
||||||
|
result, err := g.resynchronizeEndUserArchives(tx, reportId)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tx.Commit()
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
cache.AbolishRelation("end_user_detail")
|
||||||
|
cache.AbolishRelation(fmt.Sprintf("report_%s", reportId))
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (g _GodModeService) ResetEndUserRegisterRecords(reportId string) (bool, error) {
|
func (g _GodModeService) ResetEndUserRegisterRecords(reportId string) (bool, error) {
|
||||||
|
isLatest, err := g.isTheLatestReport(reportId)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if !isLatest {
|
||||||
|
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
||||||
|
}
|
||||||
tx := global.DBConn.NewSession()
|
tx := global.DBConn.NewSession()
|
||||||
if err := tx.Begin(); err != nil {
|
if err := tx.Begin(); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -320,6 +459,13 @@ func (g _GodModeService) ResetEndUserRegisterRecords(reportId string) (bool, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g _GodModeService) ResetReport(reportId string) (bool, error) {
|
func (g _GodModeService) ResetReport(reportId string) (bool, error) {
|
||||||
|
isLatest, err := g.isTheLatestReport(reportId)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if !isLatest {
|
||||||
|
return false, exceptions.NewImproperOperateError("不能操作非最新期数的报表。")
|
||||||
|
}
|
||||||
tx := global.DBConn.NewSession()
|
tx := global.DBConn.NewSession()
|
||||||
if err := tx.Begin(); err != nil {
|
if err := tx.Begin(); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user