fix(#27): 未完全修复成功
This commit is contained in:
parent
032d38181a
commit
7d3fafeb04
|
@ -49,20 +49,20 @@ type PrimaryTenementStatistics struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TenementCharge struct {
|
type TenementCharge struct {
|
||||||
Tenement string
|
Tenement string `json:"tenement"`
|
||||||
Overall model.ConsumptionUnit
|
Overall model.ConsumptionUnit `json:"overall"`
|
||||||
Critical model.ConsumptionUnit
|
Critical model.ConsumptionUnit `json:"critical"`
|
||||||
Peak model.ConsumptionUnit
|
Peak model.ConsumptionUnit `json:"peak"`
|
||||||
Flat model.ConsumptionUnit
|
Flat model.ConsumptionUnit `json:"flat"`
|
||||||
Valley model.ConsumptionUnit
|
Valley model.ConsumptionUnit `json:"valley"`
|
||||||
BasicFee decimal.Decimal
|
BasicFee decimal.Decimal `json:"basic_fee"`
|
||||||
AdjustFee decimal.Decimal
|
AdjustFee decimal.Decimal `json:"adjust_fee"`
|
||||||
LossPooled decimal.Decimal
|
LossPooled decimal.Decimal `json:"loss_pooled"`
|
||||||
PublicPooled decimal.Decimal
|
PublicPooled decimal.Decimal `json:"public_pooled"`
|
||||||
FinalCharges decimal.Decimal
|
FinalCharges decimal.Decimal `json:"final_charges"`
|
||||||
Loss decimal.Decimal
|
Loss decimal.Decimal `json:"loss"`
|
||||||
Submeters []*Meter
|
Submeters []*Meter `json:"submeters"`
|
||||||
Poolings []*Meter
|
Poolings []*Meter `json:"poolings"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Summary struct {
|
type Summary struct {
|
||||||
|
|
|
@ -7,7 +7,7 @@ type Tenement struct {
|
||||||
Park string `json:"parkId" db:"park_id"`
|
Park string `json:"parkId" db:"park_id"`
|
||||||
FullName string `json:"fullName" db:"full_name"`
|
FullName string `json:"fullName" db:"full_name"`
|
||||||
ShortName *string `json:"shortName" db:"short_name"`
|
ShortName *string `json:"shortName" db:"short_name"`
|
||||||
Abbr string `json:"-"`
|
Abbr string `json:"abbr"`
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
ContactName string `json:"contactName" db:"contact_name"`
|
ContactName string `json:"contactName" db:"contact_name"`
|
||||||
ContactPhone string `json:"contactPhone" db:"contact_phone"`
|
ContactPhone string `json:"contactPhone" db:"contact_phone"`
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/doug-martin/goqu/v9"
|
"github.com/doug-martin/goqu/v9"
|
||||||
|
@ -337,12 +336,12 @@ func (cr _CalculateRepository) SaveReportPublics(tx pgx.Tx, ctx context.Context,
|
||||||
"loss_adjust", "consumption_total", "loss_adjust_total", "final_total",
|
"loss_adjust", "consumption_total", "loss_adjust_total", "final_total",
|
||||||
)
|
)
|
||||||
// 添加值到插入表达式中
|
// 添加值到插入表达式中
|
||||||
overall,_ := json.Marshal(meter.Overall)
|
overall, _ := json.Marshal(meter.Overall)
|
||||||
criyical,_ := json.Marshal(meter.Critical)
|
criyical, _ := json.Marshal(meter.Critical)
|
||||||
peak,_ := json.Marshal(meter.Peak)
|
peak, _ := json.Marshal(meter.Peak)
|
||||||
flat,_ := json.Marshal(meter.Flat)
|
flat, _ := json.Marshal(meter.Flat)
|
||||||
valley,_ := json.Marshal(meter.Valley)
|
valley, _ := json.Marshal(meter.Valley)
|
||||||
adjustLoss,_ := json.Marshal(meter.AdjustLoss)
|
adjustLoss, _ := json.Marshal(meter.AdjustLoss)
|
||||||
insertExpr = insertExpr.Vals(goqu.Vals{
|
insertExpr = insertExpr.Vals(goqu.Vals{
|
||||||
rid,
|
rid,
|
||||||
meter.Code,
|
meter.Code,
|
||||||
|
@ -370,12 +369,12 @@ func (cr _CalculateRepository) SaveReportPublics(tx pgx.Tx, ctx context.Context,
|
||||||
}
|
}
|
||||||
func (cr _CalculateRepository) SaveReportSummary(tx pgx.Tx, ctx context.Context, summary calculate.Summary) error {
|
func (cr _CalculateRepository) SaveReportSummary(tx pgx.Tx, ctx context.Context, summary calculate.Summary) error {
|
||||||
// 构建插入表达式
|
// 构建插入表达式
|
||||||
Overall,_ := json.Marshal(summary.Overall)
|
Overall, _ := json.Marshal(summary.Overall)
|
||||||
Critical,_ := json.Marshal(summary.Critical)
|
Critical, _ := json.Marshal(summary.Critical)
|
||||||
Peak,_ := json.Marshal(summary.Peak)
|
Peak, _ := json.Marshal(summary.Peak)
|
||||||
Flat,_ := json.Marshal(summary.Flat)
|
Flat, _ := json.Marshal(summary.Flat)
|
||||||
Valley,_ := json.Marshal(summary.Valley)
|
Valley, _ := json.Marshal(summary.Valley)
|
||||||
AuthoizeLoss,_ := json.Marshal(summary.AuthoizeLoss)
|
AuthoizeLoss, _ := json.Marshal(summary.AuthoizeLoss)
|
||||||
insertsql, insertArgs, err := cr.ds.Insert(goqu.T("report_summary")).
|
insertsql, insertArgs, err := cr.ds.Insert(goqu.T("report_summary")).
|
||||||
Cols(
|
Cols(
|
||||||
"report_id", "overall", "critical", "peak", "flat", "valley",
|
"report_id", "overall", "critical", "peak", "flat", "valley",
|
||||||
|
@ -465,11 +464,11 @@ func (cr _CalculateRepository) SaveReportPoolings(tx pgx.Tx,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
overall,_ := json.Marshal(meter.Overall)
|
overall, _ := json.Marshal(meter.Overall)
|
||||||
criyical,_ := json.Marshal(meter.Critical)
|
criyical, _ := json.Marshal(meter.Critical)
|
||||||
peak,_ := json.Marshal(meter.Peak)
|
peak, _ := json.Marshal(meter.Peak)
|
||||||
flat,_ := json.Marshal(meter.Flat)
|
flat, _ := json.Marshal(meter.Flat)
|
||||||
valley,_ := json.Marshal(meter.Valley)
|
valley, _ := json.Marshal(meter.Valley)
|
||||||
|
|
||||||
insertQuery := goqu.Insert("report_pooled_consumption").
|
insertQuery := goqu.Insert("report_pooled_consumption").
|
||||||
Cols("report_id", "pooled_meter_id", "overall", "critical", "peak", "flat", "valley", "pooled_area", "diluted").
|
Cols("report_id", "pooled_meter_id", "overall", "critical", "peak", "flat", "valley", "pooled_area", "diluted").
|
||||||
|
@ -500,40 +499,59 @@ func (cr _CalculateRepository) SaveReportTenement(tx pgx.Tx, report model.Report
|
||||||
cr.log.Info("保存商户报表。")
|
cr.log.Info("保存商户报表。")
|
||||||
ctx, cancel := global.TimeoutContext()
|
ctx, cancel := global.TimeoutContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
insertQuery := cr.ds.Insert("report_tenement").Prepared(true)
|
insertQuery := cr.ds.
|
||||||
values := []goqu.Record{}
|
Insert("report_tenement")
|
||||||
|
//var values []goqu.Record
|
||||||
for _, tenement := range tenements {
|
for _, tenement := range tenements {
|
||||||
charge := findTenementCharge(tenementCharges, tenement.Id)
|
//charge := findTenementCharge(tenementCharges, tenement.Id)
|
||||||
values = append(values, goqu.Record{
|
for _, charge := range tenementCharges {
|
||||||
"report_id": report.Id,
|
tenementStr, _ := json.Marshal(tenement)
|
||||||
"tenement_id": tenement.Id,
|
overallStr, _ := json.Marshal(charge.Overall)
|
||||||
"tenement_detail": toJSONString(tenement),
|
criticalStr, _ := json.Marshal(charge.Critical)
|
||||||
"calc_period": report.Period,
|
peakStr, _ := json.Marshal(charge.Peak)
|
||||||
"overall": toJSONString(charge.Overall),
|
flatStr, _ := json.Marshal(charge.Flat)
|
||||||
"critical": toJSONString(charge.Critical),
|
valleyStr, _ := json.Marshal(charge.Valley)
|
||||||
"peak": toJSONString(charge.Peak),
|
lossStr, _ := json.Marshal(charge.Loss)
|
||||||
"flat": toJSONString(charge.Flat),
|
meters, _ := json.Marshal(convertToNestedMeters(charge.Submeters))
|
||||||
"valley": toJSONString(charge.Valley),
|
pooled, _ := json.Marshal(convertToNestedMeters(charge.Poolings))
|
||||||
"loss": toJSONString(charge.Loss),
|
fmt.Println(report.Id, tenement.Id, "123")
|
||||||
"basic_fee_pooled": charge.BasicFee,
|
insertQuery = insertQuery.
|
||||||
"adjust_fee_pooled": charge.AdjustFee,
|
Cols(
|
||||||
"loss_fee_pooled": charge.LossPooled,
|
"report_id", "tenement_id", "tenement_detail", "calc_period", "overall", "critical", "peak", "flat", "valley", "loss", "basic_fee_pooled",
|
||||||
"final_pooled": charge.PublicPooled,
|
"adjust_fee_pooled", "loss_fee_pooled", "final_charge", "invoice", "meters", "pooled",
|
||||||
"final_charge": charge.FinalCharges,
|
).
|
||||||
"meters": toJSONString(convertToNestedMeters(charge.Submeters)),
|
Vals(goqu.Vals{report.Id,
|
||||||
"pooled": toJSONString(convertToNestedMeters(charge.Poolings)),
|
tenement.Id,
|
||||||
})
|
tenementStr,
|
||||||
|
report.Period,
|
||||||
|
overallStr,
|
||||||
|
criticalStr,
|
||||||
|
peakStr,
|
||||||
|
flatStr,
|
||||||
|
valleyStr,
|
||||||
|
lossStr,
|
||||||
|
charge.BasicFee,
|
||||||
|
charge.AdjustFee,
|
||||||
|
charge.LossPooled,
|
||||||
|
charge.PublicPooled,
|
||||||
|
charge.FinalCharges,
|
||||||
|
meters,
|
||||||
|
pooled})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sql, params, err := insertQuery.Rows(values).Prepared(true).ToSQL()
|
sql, params, err := insertQuery.Prepared(true).ToSQL()
|
||||||
if err != nil {
|
|
||||||
log.Println("sql出现问题................................")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
tx.Exec(ctx, sql, params...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
fmt.Println("====================================================================", sql)
|
||||||
|
_, err = tx.Exec(ctx, sql, params...)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
fmt.Println("保存成功")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,8 +580,3 @@ func convertToNestedMeters(meters []*calculate.Meter) []NestedMeter {
|
||||||
}
|
}
|
||||||
return nestedMeters
|
return nestedMeters
|
||||||
}
|
}
|
||||||
|
|
||||||
// toJSONString 将对象转换为 JSON 字符串
|
|
||||||
func toJSONString(obj interface{}) string {
|
|
||||||
return `"` + strings.ReplaceAll(fmt.Sprintf("%#v", obj), `"`, `\"`) + `"`
|
|
||||||
}
|
|
||||||
|
|
|
@ -563,15 +563,17 @@ func (rr _ReportRepository) ListTenementInReport(rid string, page uint, keyword
|
||||||
Offset(startRow).Limit(config.ServiceSettings.ItemsPageSize)
|
Offset(startRow).Limit(config.ServiceSettings.ItemsPageSize)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tenements []*model.ReportTenement = make([]*model.ReportTenement, 0)
|
tenements = make([]*model.ReportTenement, 0)
|
||||||
count int64
|
count int64
|
||||||
)
|
)
|
||||||
querySql, queryArgs, _ := reportQuery.Prepared(true).ToSQL()
|
querySql, queryArgs, _ := reportQuery.Prepared(true).ToSQL()
|
||||||
countSql, countArgs, _ := countQuery.Prepared(true).ToSQL()
|
countSql, countArgs, _ := countQuery.Prepared(true).ToSQL()
|
||||||
|
fmt.Println(querySql, rid)
|
||||||
if err := pgxscan.Select(ctx, global.DB, &tenements, querySql, queryArgs...); err != nil {
|
if err := pgxscan.Select(ctx, global.DB, &tenements, querySql, queryArgs...); err != nil {
|
||||||
rr.log.Error("查询指定核算报表下的商户简要计费信息时出现错误", zap.Error(err))
|
rr.log.Error("查询指定核算报表下的商户简要计费信息时出现错误", zap.Error(err))
|
||||||
return tenements, 0, err
|
return tenements, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pgxscan.Get(ctx, global.DB, &count, countSql, countArgs...); err != nil {
|
if err := pgxscan.Get(ctx, global.DB, &count, countSql, countArgs...); err != nil {
|
||||||
rr.log.Error("查询指定核算报表下的商户简要计费信息总数量时出现错误", zap.Error(err))
|
rr.log.Error("查询指定核算报表下的商户简要计费信息总数量时出现错误", zap.Error(err))
|
||||||
return tenements, 0, err
|
return tenements, 0, err
|
||||||
|
|
|
@ -2,7 +2,6 @@ package calculate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"electricity_bill_calc/global"
|
|
||||||
"electricity_bill_calc/model"
|
"electricity_bill_calc/model"
|
||||||
"electricity_bill_calc/model/calculate"
|
"electricity_bill_calc/model/calculate"
|
||||||
"electricity_bill_calc/repository"
|
"electricity_bill_calc/repository"
|
||||||
|
@ -40,8 +39,6 @@ func SavePublics(tx pgx.Tx, ctx context.Context, report model.ReportIndex, meter
|
||||||
}
|
}
|
||||||
|
|
||||||
func SavePoolings(tx pgx.Tx, report model.ReportIndex, meters MeterMap, relations []model.MeterRelation) error {
|
func SavePoolings(tx pgx.Tx, report model.ReportIndex, meters MeterMap, relations []model.MeterRelation) error {
|
||||||
ctx, cancel := global.TimeoutContext()
|
|
||||||
defer cancel()
|
|
||||||
var poolingMeters []calculate.Meter
|
var poolingMeters []calculate.Meter
|
||||||
var tenementMeters []calculate.Meter
|
var tenementMeters []calculate.Meter
|
||||||
// 根据条件筛选 Meter 并保存到对应的数组中
|
// 根据条件筛选 Meter 并保存到对应的数组中
|
||||||
|
@ -56,13 +53,9 @@ func SavePoolings(tx pgx.Tx, report model.ReportIndex, meters MeterMap, relation
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tx.Commit(ctx)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func SaveTenements(tx pgx.Tx, report model.ReportIndex, tenement []calculate.PrimaryTenementStatistics, tc []calculate.TenementCharge) error {
|
func SaveTenements(tx pgx.Tx, report model.ReportIndex, tenement []calculate.PrimaryTenementStatistics, tc []calculate.TenementCharge) error {
|
||||||
ctx, cancel := global.TimeoutContext()
|
|
||||||
defer cancel()
|
|
||||||
var ts []model.Tenement
|
var ts []model.Tenement
|
||||||
for _, r := range tenement {
|
for _, r := range tenement {
|
||||||
ts = append(ts, r.Tenement)
|
ts = append(ts, r.Tenement)
|
||||||
|
@ -71,7 +64,5 @@ func SaveTenements(tx pgx.Tx, report model.ReportIndex, tenement []calculate.Pri
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tx.Commit(ctx)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,7 @@ func MainCalculateProcess(rid string) error {
|
||||||
fmt.Println("22", err)
|
fmt.Println("22", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
fmt.Println("商户分摊关系保存成功")
|
||||||
_ = tx.Commit(ctx)
|
_ = tx.Commit(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user