fix(#10):修复创建报表错误,但查出列出园区bug
This commit is contained in:
parent
ed5a3f6c0a
commit
00cf35ec2a
|
@ -9,7 +9,9 @@ import (
|
||||||
"electricity_bill_calc/tools/serial"
|
"electricity_bill_calc/tools/serial"
|
||||||
"electricity_bill_calc/types"
|
"electricity_bill_calc/types"
|
||||||
"electricity_bill_calc/vo"
|
"electricity_bill_calc/vo"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/doug-martin/goqu/v9"
|
"github.com/doug-martin/goqu/v9"
|
||||||
_ "github.com/doug-martin/goqu/v9/dialect/postgres"
|
_ "github.com/doug-martin/goqu/v9/dialect/postgres"
|
||||||
|
@ -124,8 +126,8 @@ func (rr _ReportRepository) CreateReport(form *vo.ReportCreationForm) (bool, str
|
||||||
createSql, createArgs, _ := rr.ds.
|
createSql, createArgs, _ := rr.ds.
|
||||||
Insert(goqu.T("report")).
|
Insert(goqu.T("report")).
|
||||||
Cols(
|
Cols(
|
||||||
"id", "park_id", "period", "category", "meter_o4kv_type", "price_policy",
|
"id", "park_id", "period", "category", "meter_04kv_type", "price_policy",
|
||||||
"basic_pooled", "adjust_pooled", "loss_pooled", "public_pooled", "created_at",
|
"basis_pooled", "adjust_pooled", "loss_pooled", "public_pooled", "created_at",
|
||||||
"last_modified_at",
|
"last_modified_at",
|
||||||
).
|
).
|
||||||
Vals(goqu.Vals{
|
Vals(goqu.Vals{
|
||||||
|
@ -134,38 +136,45 @@ func (rr _ReportRepository) CreateReport(form *vo.ReportCreationForm) (bool, str
|
||||||
createTime,
|
createTime,
|
||||||
}).
|
}).
|
||||||
Prepared(true).ToSQL()
|
Prepared(true).ToSQL()
|
||||||
summarySql, summaryArgs, _ := rr.ds.
|
critical := model.ConsumptionUnit{
|
||||||
|
Amount: form.Critical,
|
||||||
|
Fee: form.CriticalFee,
|
||||||
|
}
|
||||||
|
criticalData, _ := json.Marshal(critical)
|
||||||
|
overall := model.ConsumptionUnit{
|
||||||
|
Amount: form.Overall,
|
||||||
|
Fee: form.OverallFee,
|
||||||
|
}
|
||||||
|
overallData, _ := json.Marshal(overall)
|
||||||
|
peak := model.ConsumptionUnit{
|
||||||
|
Amount: form.Peak,
|
||||||
|
Fee: form.PeakFee,
|
||||||
|
}
|
||||||
|
peakData, _ := json.Marshal(peak)
|
||||||
|
flat := model.ConsumptionUnit{
|
||||||
|
Amount: form.Flat,
|
||||||
|
Fee: form.FlatFee,
|
||||||
|
}
|
||||||
|
flatData, _ := json.Marshal(flat)
|
||||||
|
valley := model.ConsumptionUnit{
|
||||||
|
Amount: form.Valley,
|
||||||
|
Fee: form.ValleyFee,
|
||||||
|
}
|
||||||
|
valleyData, _ := json.Marshal(valley)
|
||||||
|
summarySql, summaryArgs, err5 := rr.ds.
|
||||||
Insert(goqu.T("report_summary")).
|
Insert(goqu.T("report_summary")).
|
||||||
Cols(
|
//Cols("report_id", "overall", "critical", "peak", "flat", "valley", "basic_fee", "adjust_fee").
|
||||||
"report_id", "overall", "critical", "peak", "flat", "valley", "basic_fee",
|
Rows(goqu.Record{
|
||||||
"adjust_fee",
|
"report_id": reportId,
|
||||||
).
|
"overall": string(overallData),
|
||||||
Vals(goqu.Vals{
|
"critical": string(criticalData),
|
||||||
reportId,
|
"peak": string(peakData),
|
||||||
model.ConsumptionUnit{
|
"flat": string(flatData),
|
||||||
Amount: form.Overall,
|
"valley": string(valleyData),
|
||||||
Fee: form.OverallFee,
|
"basic_fee": form.BasicFee,
|
||||||
},
|
"adjust_fee": form.AdjustFee,
|
||||||
model.ConsumptionUnit{
|
}).Prepared(true).ToSQL()
|
||||||
Amount: form.Critical,
|
log.Println("errrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr:", err5)
|
||||||
Fee: form.CriticalFee,
|
|
||||||
},
|
|
||||||
model.ConsumptionUnit{
|
|
||||||
Amount: form.Peak,
|
|
||||||
Fee: form.PeakFee,
|
|
||||||
},
|
|
||||||
model.ConsumptionUnit{
|
|
||||||
Amount: form.Flat,
|
|
||||||
Fee: form.FlatFee,
|
|
||||||
},
|
|
||||||
model.ConsumptionUnit{
|
|
||||||
Amount: form.Valley,
|
|
||||||
Fee: form.ValleyFee,
|
|
||||||
},
|
|
||||||
form.BasicFee,
|
|
||||||
form.AdjustFee,
|
|
||||||
}).
|
|
||||||
Prepared(true).ToSQL()
|
|
||||||
taskSql, taskArgs, _ := rr.ds.
|
taskSql, taskArgs, _ := rr.ds.
|
||||||
Insert(goqu.T("report_task")).
|
Insert(goqu.T("report_task")).
|
||||||
Cols("id", "status", "last_modified_at").
|
Cols("id", "status", "last_modified_at").
|
||||||
|
@ -189,11 +198,14 @@ func (rr _ReportRepository) CreateReport(form *vo.ReportCreationForm) (bool, str
|
||||||
tx.Rollback(ctx)
|
tx.Rollback(ctx)
|
||||||
return false, "", err
|
return false, "", err
|
||||||
}
|
}
|
||||||
|
log.Println("?????????", summarySql, summaryArgs)
|
||||||
|
log.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", resSummary.RowsAffected())
|
||||||
if resSummary.RowsAffected() == 0 {
|
if resSummary.RowsAffected() == 0 {
|
||||||
rr.log.Error("保存核算报表汇总时出现错误", zap.Error(err))
|
rr.log.Error("保存核算报表汇总时出现错误", zap.Error(err))
|
||||||
tx.Rollback(ctx)
|
tx.Rollback(ctx)
|
||||||
return false, "", exceptions.NewUnsuccessCreateError("创建核算报表汇总时出现错误")
|
return false, "", exceptions.NewUnsuccessCreateError("创建核算报表汇总时出现错误")
|
||||||
}
|
}
|
||||||
|
|
||||||
resTask, err := tx.Exec(ctx, taskSql, taskArgs...)
|
resTask, err := tx.Exec(ctx, taskSql, taskArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rr.log.Error("创建核算报表任务时出现错误", zap.Error(err))
|
rr.log.Error("创建核算报表任务时出现错误", zap.Error(err))
|
||||||
|
|
|
@ -209,7 +209,7 @@ func (rs _ReportService) ReportCalcuateDispatch(rid string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建一个新的核算报表,并同时完成核算报表的计算
|
// 创建一个新的核算报表,并同时完成核算报表的计算
|
||||||
func (rs _ReportService) CreateNewReport(createFrom *vo.ReportCreationForm) (bool, error) {
|
func (rs _ReportService) CreateNewReport(createFrom *vo.ReportCreationForm) (bool, error) {
|
||||||
state, report, err := repository.ReportRepository.CreateReport(createFrom)
|
state, report, err := repository.ReportRepository.CreateReport(createFrom)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -217,7 +217,8 @@ func (rs _ReportService) CreateNewReport(createFrom *vo.ReportCreationForm) (boo
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !state {
|
if !state {
|
||||||
status, err := repository.CalculateRepository.UpdateReportCalculateStatus(report, "InsufficientData", "创建报表时发生错误,需手动再次计算")
|
status, err := repository.CalculateRepository.UpdateReportCalculateStatus(report, "InsufficientData",
|
||||||
|
"创建报表时发生错误,需手动再次计算")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rs.log.Error("创建报表时发生错误,需手动再次计算", zap.Error(err))
|
rs.log.Error("创建报表时发生错误,需手动再次计算", zap.Error(err))
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -232,7 +233,7 @@ func (rs _ReportService) CreateNewReport(createFrom *vo.ReportCreationForm) (boo
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//更新一个核算报表中的数据,并同时完成计算
|
// 更新一个核算报表中的数据,并同时完成计算
|
||||||
func (rs _ReportService) UpdateRepoet(rid string, updateForm *vo.ReportModifyForm) (bool, error) {
|
func (rs _ReportService) UpdateRepoet(rid string, updateForm *vo.ReportModifyForm) (bool, error) {
|
||||||
state, err := repository.ReportRepository.UpdateReportSummary(rid, updateForm)
|
state, err := repository.ReportRepository.UpdateReportSummary(rid, updateForm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user