diff --git a/repository/report.go b/repository/report.go index 74ba8fc..7d531c1 100644 --- a/repository/report.go +++ b/repository/report.go @@ -9,7 +9,9 @@ import ( "electricity_bill_calc/tools/serial" "electricity_bill_calc/types" "electricity_bill_calc/vo" + "encoding/json" "fmt" + "log" "github.com/doug-martin/goqu/v9" _ "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. Insert(goqu.T("report")). Cols( - "id", "park_id", "period", "category", "meter_o4kv_type", "price_policy", - "basic_pooled", "adjust_pooled", "loss_pooled", "public_pooled", "created_at", + "id", "park_id", "period", "category", "meter_04kv_type", "price_policy", + "basis_pooled", "adjust_pooled", "loss_pooled", "public_pooled", "created_at", "last_modified_at", ). Vals(goqu.Vals{ @@ -134,38 +136,45 @@ func (rr _ReportRepository) CreateReport(form *vo.ReportCreationForm) (bool, str createTime, }). 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")). - Cols( - "report_id", "overall", "critical", "peak", "flat", "valley", "basic_fee", - "adjust_fee", - ). - Vals(goqu.Vals{ - reportId, - model.ConsumptionUnit{ - Amount: form.Overall, - Fee: form.OverallFee, - }, - model.ConsumptionUnit{ - Amount: form.Critical, - 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() + //Cols("report_id", "overall", "critical", "peak", "flat", "valley", "basic_fee", "adjust_fee"). + Rows(goqu.Record{ + "report_id": reportId, + "overall": string(overallData), + "critical": string(criticalData), + "peak": string(peakData), + "flat": string(flatData), + "valley": string(valleyData), + "basic_fee": form.BasicFee, + "adjust_fee": form.AdjustFee, + }).Prepared(true).ToSQL() + log.Println("errrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr:", err5) taskSql, taskArgs, _ := rr.ds. Insert(goqu.T("report_task")). Cols("id", "status", "last_modified_at"). @@ -189,11 +198,14 @@ func (rr _ReportRepository) CreateReport(form *vo.ReportCreationForm) (bool, str tx.Rollback(ctx) return false, "", err } + log.Println("?????????", summarySql, summaryArgs) + log.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", resSummary.RowsAffected()) if resSummary.RowsAffected() == 0 { rr.log.Error("保存核算报表汇总时出现错误", zap.Error(err)) tx.Rollback(ctx) return false, "", exceptions.NewUnsuccessCreateError("创建核算报表汇总时出现错误") } + resTask, err := tx.Exec(ctx, taskSql, taskArgs...) if err != nil { rr.log.Error("创建核算报表任务时出现错误", zap.Error(err)) diff --git a/service/report.go b/service/report.go index e881815..bcb222e 100644 --- a/service/report.go +++ b/service/report.go @@ -209,7 +209,7 @@ func (rs _ReportService) ReportCalcuateDispatch(rid string) error { return nil } -//创建一个新的核算报表,并同时完成核算报表的计算 +// 创建一个新的核算报表,并同时完成核算报表的计算 func (rs _ReportService) CreateNewReport(createFrom *vo.ReportCreationForm) (bool, error) { state, report, err := repository.ReportRepository.CreateReport(createFrom) if err != nil { @@ -217,7 +217,8 @@ func (rs _ReportService) CreateNewReport(createFrom *vo.ReportCreationForm) (boo return false, err } if !state { - status, err := repository.CalculateRepository.UpdateReportCalculateStatus(report, "InsufficientData", "创建报表时发生错误,需手动再次计算") + status, err := repository.CalculateRepository.UpdateReportCalculateStatus(report, "InsufficientData", + "创建报表时发生错误,需手动再次计算") if err != nil { rs.log.Error("创建报表时发生错误,需手动再次计算", zap.Error(err)) return false, err @@ -232,7 +233,7 @@ func (rs _ReportService) CreateNewReport(createFrom *vo.ReportCreationForm) (boo return true, nil } -//更新一个核算报表中的数据,并同时完成计算 +// 更新一个核算报表中的数据,并同时完成计算 func (rs _ReportService) UpdateRepoet(rid string, updateForm *vo.ReportModifyForm) (bool, error) { state, err := repository.ReportRepository.UpdateReportSummary(rid, updateForm) if err != nil {