From d7a3aed80a9581f51766e02b0d268a3248b09f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zhero=20=26=20=E5=8A=A9=E7=90=86?= Date: Thu, 3 Dec 2026 22:45:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(qa-dashboard):=20=E5=B7=B2=E7=BB=93?= =?UTF-8?q?=E6=9D=9F=E6=9C=88=E4=BB=BD=E4=B8=8D=E5=86=8D=E6=8B=89=E4=BC=B8?= =?UTF-8?q?=E5=88=B0=E5=BD=93=E5=89=8D=EF=BC=8C=E5=8C=BA=E5=9F=9F=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E8=B7=9F=E9=9A=8F=E6=89=80=E9=80=89=E5=8C=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/qaopsmirror/dashboard_store.go | 9 ++++++++- web/src/QADashboardDrawing.tsx | 26 ++++++++++++++++++++----- web/src/qaDashboardData.ts | 10 ++++++++++ web/src/qaDashboardLive.test.ts | 13 +++++++++++++ web/src/qaDashboardMonth.test.tsx | 9 +++++++++ 5 files changed, 61 insertions(+), 6 deletions(-) diff --git a/internal/qaopsmirror/dashboard_store.go b/internal/qaopsmirror/dashboard_store.go index 263b335..223e27f 100644 --- a/internal/qaopsmirror/dashboard_store.go +++ b/internal/qaopsmirror/dashboard_store.go @@ -249,6 +249,13 @@ func (s *Store) readDashboard(ctx context.Context, q dobotaiops.RecordQuery, mas out.Regions = append(out.Regions, r) } inPeriod := 0 + regionFrom := out.MonthStart + if q.Granularity != "" { + // 区域统计跟随所选区间:按天/周/月/自定义看板里,"这个区间用了多少"才是 + // 用户要的数字。老周看板(granularity 为空)保持原来的自然月累计不变, + // 周报生成链路逐字段不变。分母仍是月度通讯录人数,由前端注明快照月份。 + regionFrom = q.Window.Start + } for _, r := range records { if q.Granularity == "" { if !r.at.Before(out.WeekStart) { @@ -269,7 +276,7 @@ func (s *Store) readDashboard(ctx context.Context, q dobotaiops.RecordQuery, mas products[dashboardCategory(v.Effective.ProductCategory)]++ types[dashboardCategory(v.Effective.ProblemType)]++ } - if !r.at.Before(out.MonthStart) { + if !r.at.Before(regionFrom) { person := attribution.Resolve(r.identity.StaffID, r.identity.UnionID, r.fields["asker"], r.fields["trigger_person"]) if index, ok := regionIndex[person.Region]; ok && person.PersonID != "" { out.Regions[index].Questions++ diff --git a/web/src/QADashboardDrawing.tsx b/web/src/QADashboardDrawing.tsx index 5ad03bf..5007dd4 100644 --- a/web/src/QADashboardDrawing.tsx +++ b/web/src/QADashboardDrawing.tsx @@ -467,11 +467,13 @@ function RegionTable({ regions, frequency, month, + caption, }: { box: Box regions: DashboardRegion[] frequency: boolean month: string + caption: string }) { const rows = [...regions].sort((a, b) => { const av = frequency ? a.frequency : a.usage_coverage.percent, @@ -504,7 +506,7 @@ function RegionTable({ y += h return ( - {`${r.name};${month}月内提问 ${r.questions} 次;去重使用 ${r.users ?? '未知'} 人 / 通讯录归属 ${r.roster_people ?? '未知'} 人`} + {`${r.name};${caption};提问 ${r.questions} 次;去重使用 ${r.users ?? '未知'} 人 / ${month} 月通讯录归属 ${r.roster_people ?? '未知'} 人`} {i % 2 === 0 ? : null} {value !== null && i < 3 ? ( @@ -520,7 +522,7 @@ function RegionTable({ ) })} - {month}月累计 + {caption} ) @@ -545,7 +547,7 @@ export function QADashboardDrawing({ week = currentQAWeek(new Date(data.week_start)), filterLines = wrap(data.keyword ? `关键词:${data.keyword}` : '', inner - 16, 11), heading = data.period - ? `${data.period.label} · 全部指标按所选范围统计 · 区域统计 ${new Date(Date.parse(data.month_start) + 8 * 3600000).toISOString().slice(0, 7)} 月累计` + ? `${data.period.label} · 全部指标按所选范围统计 · 区域统计按所选区间(分母为 ${new Date(Date.parse(data.month_start) + 8 * 3600000).toISOString().slice(0, 7)} 月通讯录)` : `${data.week_start.slice(0, 10)} 起的自然周${data.quality_period ? ` · 质量 ${data.quality_period.month} 月内累计` : ''} · 区域统计 ${new Date(Date.parse(data.month_start) + 8 * 3600000).toISOString().slice(0, 7)} 月累计`, headingLines = (mobile ? [heading.split(' · ')[0], heading.split(' · ').slice(1).join(' · ')] : [heading]).flatMap( (row) => wrap(row, inner - 16, 10.5) @@ -606,6 +608,8 @@ export function QADashboardDrawing({ height = mobile ? cursor + 540 + gap + pad : cursor + 270 + pad const frozen = (correctness: boolean): PlotPoint[] => historicalTrend(data, correctness) const month = new Date(Date.parse(data.month_start) + 8 * 3600000).toISOString().slice(0, 7) + // 有 granularity 时区域面板跟所选区间走,分母仍是月度通讯录;老周看板保持"月累计"。 + const regionCaption = data.period ? `所选区间提问 / 去重使用 ÷ ${month} 月通讯录` : `${month}月累计` const tipWidth = Math.min(334, inner), tipLines = wrap(tip ? definitions[tip.id] : '', tipWidth - 26, 11.5), tipHeight = tipLines.length * 15.525 + 26, @@ -700,8 +704,20 @@ export function QADashboardDrawing({ id="issue-trend" points={data.daily.map((p) => ({ label: p.date.slice(5), value: p.count, hint: `${p.date}:${p.count} 条` }))} /> - - + + new Date(at + 8 * 3_600_000).toISOString().slice(0, 7) + // A chosen month is a closed accounting period: only the month that contains + // "now" may advance with the clock. Stretching a finished month to now pulled + // the region panels (natural-month cumulative) into the NEXT month, so an + // 11 月 selection showed 12 月 usage. + if (granularity === 'month') { + if (beijingMonth(Date.parse(query.end) - 1) !== beijingMonth(now.getTime())) return query + if (Date.parse(query.end) >= now.getTime()) return query + return { ...query, end: now.toISOString() } + } const last = currentQAWeek(new Date(Date.parse(query.end) - 1)), current = currentQAWeek(now) if ( diff --git a/web/src/qaDashboardLive.test.ts b/web/src/qaDashboardLive.test.ts index cedc0ed..1f54ee6 100644 --- a/web/src/qaDashboardLive.test.ts +++ b/web/src/qaDashboardLive.test.ts @@ -23,3 +23,16 @@ it('never stretches an explicit custom range to now', () => { const custom = { ...query, start: '2026-10-01T00:00:00+08:00', end: '2026-10-03T00:00:00+08:00' } expect(liveDashboardQuery(custom, new Date('2026-10-20T09:00:00+08:00'), 'custom')).toEqual(custom) }) + +it('never stretches a finished month into the next month', () => { + const closedMonth = { ...query, start: '2026-11-01T00:00:00+08:00', end: '2026-12-01T00:00:00+08:00' } + const now = new Date('2026-12-03T22:45:00+08:00') + expect(liveDashboardQuery(closedMonth, now, 'month')).toEqual(closedMonth) +}) + +it('keeps the current month live up to now', () => { + const openMonth = { ...query, start: '2026-12-01T00:00:00+08:00', end: '2026-12-03T22:00:00+08:00' } + const next = liveDashboardQuery(openMonth, new Date('2026-12-03T22:45:00+08:00'), 'month') + expect(next.end).toBe('2026-12-03T14:45:00.000Z') + expect(next.start).toBe(openMonth.start) +}) diff --git a/web/src/qaDashboardMonth.test.tsx b/web/src/qaDashboardMonth.test.tsx index d9612a7..2d7d33e 100644 --- a/web/src/qaDashboardMonth.test.tsx +++ b/web/src/qaDashboardMonth.test.tsx @@ -57,6 +57,15 @@ describe('monthly dashboard range', () => { expect(html).toContain('66.7%') }) + it('cuts the region panels from the selected range and names the roster month', () => { + const data = parseQADashboard(monthFixture) + const html = renderToStaticMarkup() + expect(html).toContain('区域统计按所选区间') + expect(html).toContain('分母为 2026-11 月通讯录') + expect(html).toContain('所选区间提问 / 去重使用 ÷ 2026-11 月通讯录') + expect(html).not.toContain('2026-11月累计') + }) + it('rejects a payload that claims a month granularity without a matching period', () => { const { period: _period, ...rest } = monthFixture expect(() => parseQADashboard(rest)).toThrow()