fix(energy): 待核对上线期初改为 2026-01-01,并统一前后端口径
待核对订单的起算日原先硬编码为 2026-05-01,散落在后端 SQL、看板诊断卡 和下钻提示三处,改一处就会与另两处口径不一致。 - 新增 shared/hydrogen-verify.ts 的 HYDROGEN_VERIFY_START_DATE 作为唯一来源 - repository 的 unverified 过滤条件改为引用该常量,起算日提前到 2026-01-01 - 看板桌面/移动诊断卡与待核对下钻提示同步显示新日期 - 契约测试锁定字面量,防止日期被无意改动 仅影响 verifyScope=unverified;all / verified 口径不变。
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
|||||||
Zap,
|
Zap,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { exportAoaSheet } from '../../../../shared/xlsx';
|
import { exportAoaSheet } from '../../../../shared/xlsx';
|
||||||
|
import { HYDROGEN_VERIFY_START_DATE } from '../../../../shared/hydrogen-verify';
|
||||||
import { MobileListFullscreenButton } from '../common/MobileListFullscreenButton';
|
import { MobileListFullscreenButton } from '../common/MobileListFullscreenButton';
|
||||||
import {
|
import {
|
||||||
SOURCE_LABEL,
|
SOURCE_LABEL,
|
||||||
@@ -2136,7 +2137,7 @@ export const EnergyBiBoardApp: React.FC = () => {
|
|||||||
<button type="button" className="ehb-diagnosis__item is-action" onClick={() => setKpiDrillType('待核对订单')} title="查看待核对订单">
|
<button type="button" className="ehb-diagnosis__item is-action" onClick={() => setKpiDrillType('待核对订单')} title="查看待核对订单">
|
||||||
<span>待核对订单</span>
|
<span>待核对订单</span>
|
||||||
<strong className={risk.count > 0 ? 'is-warning' : ''}>{risk.count}笔 · ¥{unverifiedWan}万</strong>
|
<strong className={risk.count > 0 ? 'is-warning' : ''}>{risk.count}笔 · ¥{unverifiedWan}万</strong>
|
||||||
<small>核对上线期初:2026-05-01(含)· 查看待核对订单</small>
|
<small>核对上线期初:{HYDROGEN_VERIFY_START_DATE}(含)· 查看待核对订单</small>
|
||||||
</button>
|
</button>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
@@ -2155,7 +2156,7 @@ export const EnergyBiBoardApp: React.FC = () => {
|
|||||||
<div><span>月度环比</span><strong className={liveMonthComparison && liveMonthComparison.value < 0 ? 'is-warning' : 'is-positive'}>{liveMonthComparison ? `${liveMonthComparison.value >= 0 ? '+' : ''}${liveMonthComparison.value.toFixed(1)}%` : '—'}</strong><small>{liveMonthComparison?.label ?? '暂无可比月份'}</small></div>
|
<div><span>月度环比</span><strong className={liveMonthComparison && liveMonthComparison.value < 0 ? 'is-warning' : 'is-positive'}>{liveMonthComparison ? `${liveMonthComparison.value >= 0 ? '+' : ''}${liveMonthComparison.value.toFixed(1)}%` : '—'}</strong><small>{liveMonthComparison?.label ?? '暂无可比月份'}</small></div>
|
||||||
<div><span>单公斤毛利</span><strong>¥{unitProfitYuan}<small>/kg</small></strong><small>按累计加氢量计算</small></div>
|
<div><span>单公斤毛利</span><strong>¥{unitProfitYuan}<small>/kg</small></strong><small>按累计加氢量计算</small></div>
|
||||||
<button type="button" className="ehb-mobile-diagnosis-action" onClick={() => setKpiDrillType('加氢站加氢量排名')}><span>头部站点占比</span><strong>{top5SharePct}%</strong><small>前5站占总量</small></button>
|
<button type="button" className="ehb-mobile-diagnosis-action" onClick={() => setKpiDrillType('加氢站加氢量排名')}><span>头部站点占比</span><strong>{top5SharePct}%</strong><small>前5站占总量</small></button>
|
||||||
<button type="button" className="ehb-mobile-diagnosis-action" onClick={() => setKpiDrillType('待核对订单')}><span>待核对订单</span><strong className={risk.count > 0 ? 'is-warning' : ''}>{risk.count}笔</strong><small>¥{unverifiedWan}万 · 上线期初 2026-05-01(含)</small></button>
|
<button type="button" className="ehb-mobile-diagnosis-action" onClick={() => setKpiDrillType('待核对订单')}><span>待核对订单</span><strong className={risk.count > 0 ? 'is-warning' : ''}>{risk.count}笔</strong><small>¥{unverifiedWan}万 · 上线期初 {HYDROGEN_VERIFY_START_DATE}(含)</small></button>
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { ChevronDown, ChevronLeft, Download, Search, SlidersHorizontal, Truck, X
|
|||||||
import { MobileListFullscreenButton } from "../common/MobileListFullscreenButton";
|
import { MobileListFullscreenButton } from "../common/MobileListFullscreenButton";
|
||||||
import { fetchAllH2BiDrill, fetchH2BiDrill, fetchH2BiMeta } from "../api";
|
import { fetchAllH2BiDrill, fetchH2BiDrill, fetchH2BiMeta } from "../api";
|
||||||
import { exportAoaSheet } from "../../../../shared/xlsx";
|
import { exportAoaSheet } from "../../../../shared/xlsx";
|
||||||
|
import { HYDROGEN_VERIFY_START_DATE } from "../../../../shared/hydrogen-verify";
|
||||||
import { bearingLabels } from "../model/bearing-labels";
|
import { bearingLabels } from "../model/bearing-labels";
|
||||||
import { formatFixed } from "../model/display-format";
|
import { formatFixed } from "../model/display-format";
|
||||||
import type {
|
import type {
|
||||||
@@ -1236,7 +1237,7 @@ export function PrototypeDrillModal({
|
|||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
<DrillSummaryCards kind={kind} label={cleanLabel} data={live.data} />
|
<DrillSummaryCards kind={kind} label={cleanLabel} data={live.data} />
|
||||||
{cleanLabel === "待核对订单" ? <div className="ehb-modal-hint-text">核对功能上线期初:2026-05-01(含)。仅统计当前查询范围与上线期初之后的交集;此前订单不计入待核对。</div> : null}
|
{cleanLabel === "待核对订单" ? <div className="ehb-modal-hint-text">核对功能上线期初:{HYDROGEN_VERIFY_START_DATE}(含)。仅统计当前查询范围与上线期初之后的交集;此前订单不计入待核对。</div> : null}
|
||||||
{cleanLabel === "加氢利润" && customerBearingScope ? (
|
{cleanLabel === "加氢利润" && customerBearingScope ? (
|
||||||
<div className="ehb-modal-hint-text" style={{ marginBottom: 10 }}>
|
<div className="ehb-modal-hint-text" style={{ marginBottom: 10 }}>
|
||||||
利润口径:客户承担订单的对客总价 ¥
|
利润口径:客户承担订单的对客总价 ¥
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
export const HYDROGEN_MIN_DATE = '2024-01-01';
|
export const HYDROGEN_MIN_DATE = '2024-01-01';
|
||||||
|
|
||||||
|
// 核对功能上线期初(含当日):待核对口径的唯一起算日,前端文案同样引用该常量。
|
||||||
|
export { HYDROGEN_VERIFY_START_DATE } from '../../../shared/hydrogen-verify.js';
|
||||||
|
|
||||||
// hydrogen_fuel_ledger.refuel_time 已是业务本地时间字面值,直接使用即可(不再 +8 小时)
|
// hydrogen_fuel_ledger.refuel_time 已是业务本地时间字面值,直接使用即可(不再 +8 小时)
|
||||||
export const HYDROGEN_TABLE = 'hydrogen_fuel_ledger';
|
export const HYDROGEN_TABLE = 'hydrogen_fuel_ledger';
|
||||||
export const HYDROGEN_LOCAL = `refuel_time`;
|
export const HYDROGEN_LOCAL = `refuel_time`;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
HYDROGEN_MIN_DATE,
|
HYDROGEN_MIN_DATE,
|
||||||
HYDROGEN_TABLE,
|
HYDROGEN_TABLE,
|
||||||
HYDROGEN_TENANT_ID,
|
HYDROGEN_TENANT_ID,
|
||||||
|
HYDROGEN_VERIFY_START_DATE,
|
||||||
MANUAL_RECHARGE_SOURCE,
|
MANUAL_RECHARGE_SOURCE,
|
||||||
NORMALIZED_PLATE,
|
NORMALIZED_PLATE,
|
||||||
NORMALIZED_PLATE_UNICODE,
|
NORMALIZED_PLATE_UNICODE,
|
||||||
@@ -765,7 +766,8 @@ export function buildFilterClauses(input: {
|
|||||||
if (verifyScope === "unverified")
|
if (verifyScope === "unverified")
|
||||||
clauses.push(
|
clauses.push(
|
||||||
"LOWER(COALESCE(NULLIF(TRIM(b.verify_status), ''), 'unverified')) <> 'verified'",
|
"LOWER(COALESCE(NULLIF(TRIM(b.verify_status), ''), 'unverified')) <> 'verified'",
|
||||||
"b.refuel_time >= '2026-05-01'",
|
// 待核对只统计核对上线期初(含当日)之后的订单,期初之前的历史订单不算待核对。
|
||||||
|
`b.refuel_time >= '${HYDROGEN_VERIFY_START_DATE}'`,
|
||||||
);
|
);
|
||||||
return { clauses, params };
|
return { clauses, params };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
registerHydrogenBiV2Routes,
|
registerHydrogenBiV2Routes,
|
||||||
type HydrogenBiV2Dependencies,
|
type HydrogenBiV2Dependencies,
|
||||||
} from "./hydrogen-bi-v2.js";
|
} from "./hydrogen-bi-v2.js";
|
||||||
|
import { HYDROGEN_VERIFY_START_DATE } from "./constants.js";
|
||||||
|
|
||||||
interface QueryCall {
|
interface QueryCall {
|
||||||
sql: string;
|
sql: string;
|
||||||
@@ -32,6 +33,9 @@ interface CacheCall {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("待核对的汇总和下钻统一从核对上线期初起统计,不影响其他核对范围", async () => {
|
test("待核对的汇总和下钻统一从核对上线期初起统计,不影响其他核对范围", async () => {
|
||||||
|
// 期初日期以字面量锁定:它同时被前端文案引用,改动必须是有意的。
|
||||||
|
assert.equal(HYDROGEN_VERIFY_START_DATE, "2026-01-01");
|
||||||
|
const cutoverClause = `b.refuel_time >= '${HYDROGEN_VERIFY_START_DATE}'`;
|
||||||
for (const scope of ["unverified", "all", "verified"]) {
|
for (const scope of ["unverified", "all", "verified"]) {
|
||||||
for (const endpoint of ["overview", "drill"]) {
|
for (const endpoint of ["overview", "drill"]) {
|
||||||
const calls: QueryCall[] = [];
|
const calls: QueryCall[] = [];
|
||||||
@@ -44,7 +48,7 @@ test("待核对的汇总和下钻统一从核对上线期初起统计,不影
|
|||||||
const ledgerQueries = calls.filter(({ sql }) => sql.includes("FROM hydrogen_fuel_ledger b"));
|
const ledgerQueries = calls.filter(({ sql }) => sql.includes("FROM hydrogen_fuel_ledger b"));
|
||||||
assert.ok(ledgerQueries.length > 0);
|
assert.ok(ledgerQueries.length > 0);
|
||||||
for (const { sql } of ledgerQueries) {
|
for (const { sql } of ledgerQueries) {
|
||||||
assert.equal(sql.includes("b.refuel_time >= '2026-05-01'"), scope === "unverified");
|
assert.equal(sql.includes(cutoverClause), scope === "unverified");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* 核对功能上线期初(含当日)。
|
||||||
|
*
|
||||||
|
* 「待核对订单」只统计这一天及之后的加氢订单:起算日之前的历史订单视为核对范围之外,
|
||||||
|
* 不计入待核对笔数与金额。该口径同时决定后端 SQL 过滤(energy/repository.ts)与前端
|
||||||
|
* 展示文案(看板诊断卡、下钻弹窗提示),因此收敛到 shared 这一层,避免只改了一处导致
|
||||||
|
* 口径与文案不一致。
|
||||||
|
*/
|
||||||
|
export const HYDROGEN_VERIFY_START_DATE = '2026-01-01';
|
||||||
Reference in New Issue
Block a user