forked from free-lancers/electricity_bill_calc_service
		
	fix(#22):修复无法获取报表的总览信息错误
This commit is contained in:
		| @@ -11,6 +11,7 @@ import ( | ||||
| 	"electricity_bill_calc/types" | ||||
| 	"electricity_bill_calc/vo" | ||||
| 	"log" | ||||
| 	"strconv" | ||||
|  | ||||
| 	"github.com/gofiber/fiber/v2" | ||||
| 	"github.com/jinzhu/copier" | ||||
| @@ -246,8 +247,26 @@ func getReportSummary(c *fiber.Ctx) error { | ||||
| 		reportLog.Error("未找到核算报表的总览信息") | ||||
| 		return result.NotFound("未找到核算报表的总览信息。") | ||||
| 	} | ||||
| 	var summaryResponse vo.ParkSummaryResponse | ||||
| 	copier.Copy(&summaryResponse, report) | ||||
| 	summaryResponse := vo.ParkSummaryResponse{ | ||||
| 		ReportId: report.ReportId, | ||||
| 		OverallDisplay: vo.ConsumptionDisplay{ | ||||
| 			AmountStr:     strconv.FormatFloat(report.Overall.Amount.InexactFloat64(), 'f', -1, 64), | ||||
| 			FeeStr:        strconv.FormatFloat(report.Overall.Fee.InexactFloat64(), 'f', -1, 64), | ||||
| 			PriceStr:      strconv.FormatFloat(report.Overall.Price.InexactFloat64(), 'f', -1, 64), | ||||
| 			ProportionStr: strconv.FormatFloat(report.Overall.Proportion.InexactFloat64(), 'f', -1, 64), | ||||
| 		}, | ||||
| 		Area:                    report.OverallArea, | ||||
| 		BasicFee:                report.BasicFee, | ||||
| 		PooledBasicFeeByAmount:  report.AuthorizeLoss.Amount, | ||||
| 		PooledBasicFeeByArea:    report.BasicPooledPriceArea.Decimal, | ||||
| 		AdjustFee:               report.AdjustFee, | ||||
| 		PooledAdjustFeeByAmount: report.AdjustPooledPriceConsumption.Decimal, | ||||
| 		PooledAdjustFeeByArea:   report.AdjustPooledPriceArea.Decimal, | ||||
| 		Consumption:             report.ConsumptionFee.Decimal, | ||||
| 		Loss:                    report.Loss.Decimal, | ||||
| 		LossRate:                report.LossFee.Decimal, | ||||
| 	} | ||||
| 	//copier.Copy(&summaryResponse, report) | ||||
| 	return result.Success( | ||||
| 		"已经获取到核算报表的总览信息。", | ||||
| 		fiber.Map{"summary": summaryResponse}, | ||||
|   | ||||
| @@ -368,11 +368,15 @@ func (cr _CalculateRepository) SaveReportPublics(tx pgx.Tx, ctx context.Context, | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
| func (cr _CalculateRepository) SaveReportSummary(tx pgx.Tx, summary calculate.Summary) error { | ||||
| 	ctx, cancel := global.TimeoutContext() | ||||
| 	defer cancel() | ||||
| func (cr _CalculateRepository) SaveReportSummary(tx pgx.Tx, ctx context.Context, summary calculate.Summary) error { | ||||
| 	// 构建插入表达式 | ||||
| 	insertsql, insertArgs, _ := cr.ds.Insert("report_summary"). | ||||
| 	Overall,_  := json.Marshal(summary.Overall) | ||||
| 	Critical,_  := json.Marshal(summary.Critical) | ||||
| 	Peak,_  := json.Marshal(summary.Peak) | ||||
| 	Flat,_  := json.Marshal(summary.Flat) | ||||
| 	Valley,_  := json.Marshal(summary.Valley) | ||||
| 	AuthoizeLoss,_  := json.Marshal(summary.AuthoizeLoss) | ||||
| 	insertsql, insertArgs, err := cr.ds.Insert(goqu.T("report_summary")). | ||||
| 		Cols( | ||||
| 			"report_id", "overall", "critical", "peak", "flat", "valley", | ||||
| 			"loss", "loss_fee", "basic_fee", "basic_pooled_price_consumption", "basic_pooled_price_area", | ||||
| @@ -381,16 +385,18 @@ func (cr _CalculateRepository) SaveReportSummary(tx pgx.Tx, summary calculate.Su | ||||
| 			"consumption_fee", "authorize_loss", "overall_area", "total_consumption", | ||||
| 		). | ||||
| 		Vals(goqu.Vals{ | ||||
| 			summary.ReportId, summary.Overall, summary.Critical, summary.Peak, summary.Flat, | ||||
| 			summary.Valley, summary.Loss, summary.LossFee, summary.BasicFee, | ||||
| 			summary.ReportId, Overall, Critical, Peak, Flat, | ||||
| 			Valley, summary.Loss, summary.LossFee, summary.BasicFee, | ||||
| 			summary.BasicPooledPriceConsumption, summary.BasicPooledPriceArea, | ||||
| 			summary.AdjustFee, summary.AdjustPooledPriceConsumption, summary.AdjustPooledPriceArea, | ||||
| 			summary.LossDilutedPrice, summary.LossProportion, summary.FinalDilutedOverall, | ||||
| 			summary.ConsumptionFee, summary.AuthoizeLoss, summary.OverallArea, summary.TotalConsumption, | ||||
| 		}).Prepared(true).ToSQL() | ||||
|  | ||||
| 			summary.ConsumptionFee, AuthoizeLoss, summary.OverallArea, summary.TotalConsumption, | ||||
| 		}).ToSQL() | ||||
| 	if err != nil { | ||||
| 		fmt.Println(err) | ||||
| 		return err | ||||
| 	} | ||||
| 	// 执行插入语句 | ||||
|  | ||||
| 	if _, err := tx.Exec(ctx, insertsql, insertArgs...); err != nil { | ||||
| 		cr.log.Error("保存报表核算概要失败。") | ||||
| 		return err | ||||
|   | ||||
| @@ -11,10 +11,10 @@ import ( | ||||
| ) | ||||
|  | ||||
| // 向数据库保存核算概况结果 | ||||
| func SaveSummary(tx pgx.Tx, summary calculate.Summary) error { | ||||
| func SaveSummary(tx pgx.Tx, ctx context.Context, summary calculate.Summary) error { | ||||
|  | ||||
| 	// 保存核算概况结果到数据库 | ||||
| 	err := repository.CalculateRepository.SaveReportSummary(tx, summary) | ||||
| 	err := repository.CalculateRepository.SaveReportSummary(tx,ctx, summary) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|   | ||||
| @@ -62,7 +62,7 @@ func MainCalculateProcess(rid string) error { | ||||
| 		fmt.Println("8", err) | ||||
| 		return err | ||||
| 	} | ||||
| 	fmt.Println(parkMetersReports, "看看物业所有表计电量是否为空", tenementReports, summary) | ||||
|  | ||||
| 	// 计算所有表计的总电量 | ||||
| 	parkTotal := TotalConsumptionCalculate(tenementReports, summary) | ||||
|  | ||||
| @@ -73,7 +73,6 @@ func MainCalculateProcess(rid string) error { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	// 计算所有已经启用的商铺面积总和,仅计算所有未迁出的商户的所有表计对应的商铺面积。 | ||||
| 	_, err = EnabledAreaCalculate(&tenementReports, &summary) | ||||
| 	if err != nil { | ||||
| @@ -135,7 +134,7 @@ func MainCalculateProcess(rid string) error { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	err = SaveSummary(tx, summary) | ||||
| 	err = SaveSummary(tx, ctx, summary) | ||||
| 	if err != nil { | ||||
| 		_ = tx.Rollback(ctx) | ||||
| 		fmt.Println("19", err) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user