diff --git a/model/end_user_detail.go b/model/end_user_detail.go index 02522d6..4c93e52 100644 --- a/model/end_user_detail.go +++ b/model/end_user_detail.go @@ -116,6 +116,7 @@ type EndUserImport struct { type EndUserPeriodStat struct { CustomerName string `json:"customerName"` Address string `json:"address"` + ParkId string `json:"parkId"` MeterId string `bun:"meter_04kv_id" json:"meterId"` IsPublicMeter bool `bun:"public_meter" json:"isPublicMeter"` Kind int8 `bun:"-" json:"pvKind"` diff --git a/service/end_user.go b/service/end_user.go index 873a377..72fa950 100644 --- a/service/end_user.go +++ b/service/end_user.go @@ -410,7 +410,7 @@ func (es _EndUserService) StatEndUserRecordInPeriod(requestUser, requestPark, st ctx, cancel := global.TimeoutContext(120) defer cancel() var endUserSums []model.EndUserPeriodStat - err := cond.Column("eud.meter_04kv_id"). + err := cond.Column("eud.meter_04kv_id", "eud.park_id"). ColumnExpr("sum(?) as overall", bun.Ident("eud.overall")). ColumnExpr("sum(?) as overall_fee", bun.Ident("eud.overall_fee")). ColumnExpr("sum(?) as critical", bun.Ident("eud.critical")). @@ -421,23 +421,24 @@ func (es _EndUserService) StatEndUserRecordInPeriod(requestUser, requestPark, st ColumnExpr("sum(?) as valley_fee", bun.Ident("eud.valley_fee")). ColumnExpr("sum(?) as final_diluted", bun.Ident("eud.final_diluted")). Where("report.published = ?", true). - Group("eud.meter_04kv_id"). + Group("eud.meter_04kv_id", "eud.park_id"). Scan(ctx, &endUserSums) if err != nil { return make([]model.EndUserPeriodStat, 0), fmt.Errorf("未能完成终端用户在指定期限内的统计,%w", err) } - meterIds := lo.Reduce( + parkIds := lo.Reduce( endUserSums, func(acc mapset.Set[string], elem model.EndUserPeriodStat, _ int) mapset.Set[string] { - acc.Add(elem.MeterId) + acc.Add(elem.ParkId) return acc }, mapset.NewSet[string](), ) meterArchives := make([]model.Meter04KV, 0) - if len(meterIds.ToSlice()) > 0 { - err = global.DB.NewSelect().Model(&meterArchives).Relation("ParkDetail"). - Where("code in (?)", bun.In(meterIds.ToSlice())). + if len(parkIds.ToSlice()) > 0 { + err = global.DB.NewSelect(). + Model(&meterArchives).Relation("ParkDetail"). + Where("park_id in (?)", bun.In(parkIds.ToSlice())). Scan(ctx) if err != nil { return make([]model.EndUserPeriodStat, 0), fmt.Errorf("未能获取到终端表计的最新基础档案,%w", err)