Commit 55f8de0c by luoqi

fix(tz): 本地 CH 设 Asia/Shanghai 对齐远程 DW + 移除 arrived_at +8h band-aid

- 本地 pac-clickhouse 原跑 TZ=UTC,裸 DateTime(in_time)读出比北京裸字段早 8h。
  加 clickhouse/config.d/timezone.xml(<timezone>Asia/Shanghai</timezone>)+ compose TZ env,
  重建后本地行为与远程 DW(本就 Shanghai)一致;源 instant 一直正确,无需改数据。
- special-attention 的 ARRIVED_TZ_FIX_MS(+8h)是为补偿上述本地 UTC 偏差加的;源 CH 统一 Shanghai 后
  会反向多加 8h → 移除(服务器连远程 DW,该 band-aid 本就一直让"迟到"晚 8h,一并修)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
parent d8ea5d52
...@@ -25,9 +25,9 @@ export class SpecialAttentionFeatureExtractor implements FeatureExtractor { ...@@ -25,9 +25,9 @@ export class SpecialAttentionFeatureExtractor implements FeatureExtractor {
readonly key = PersonaFeatureKey.SPECIAL_ATTENTION; readonly key = PersonaFeatureKey.SPECIAL_ATTENTION;
private static readonly DAY = 86400_000; private static readonly DAY = 86400_000;
private static readonly LATE_MS = 15 * 60_000; private static readonly LATE_MS = 15 * 60_000;
// ⚠️ arrived_at(in_time)摄入时区 bug:比 planned_for 一致早 8h(实测 -480min±实际早晚) // 注:曾因源 CH 跑 UTC 导致 arrived_at(in_time)摄入早 8h,这里加过 +8h band-aid
// +8h 补偿对齐 planned_for(UTC)。根治应修摄入 in_time 时区(follow-up,同 occurred_at bug)。 // 已根治 —— 源 CH(本地镜像 + 远程 DW)统一 Asia/Shanghai 时区,in_time 摄入即为正确北京时刻,
private static readonly ARRIVED_TZ_FIX_MS = 8 * 3600_000; // band-aid 移除(留着反而会让到店时间晚 8h)。详见 docs/dw-data-source-issues.md。
private static readonly ATTENDED = new Set(['completed', 'arrived', 'in_treatment']); private static readonly ATTENDED = new Set(['completed', 'arrived', 'in_treatment']);
private static readonly WAIT_KW = ['不可等候', '时间敏感', '赶时间', '不能等']; private static readonly WAIT_KW = ['不可等候', '时间敏感', '赶时间', '不能等'];
...@@ -54,10 +54,10 @@ export class SpecialAttentionFeatureExtractor implements FeatureExtractor { ...@@ -54,10 +54,10 @@ export class SpecialAttentionFeatureExtractor implements FeatureExtractor {
noShow++; noShow++;
noShowIds.push(f.id); noShowIds.push(f.id);
} }
// 迟到:到店时间(+8h 修正摄入 TZ bug)vs 预约时间 // 迟到:到店时间 vs 预约时间(arrived_at 已按正确时区摄入,不再补偿)
const arrRaw = c.arrived_at; const arrRaw = c.arrived_at;
if (arrRaw) { if (arrRaw) {
const arr = new Date(String(arrRaw)).getTime() + SpecialAttentionFeatureExtractor.ARRIVED_TZ_FIX_MS; const arr = new Date(String(arrRaw)).getTime();
if (Number.isFinite(arr)) { if (Number.isFinite(arr)) {
arrivalRecs++; arrivalRecs++;
if (arr - planned.getTime() > SpecialAttentionFeatureExtractor.LATE_MS) { if (arr - planned.getTime() > SpecialAttentionFeatureExtractor.LATE_MS) {
......
<clickhouse>
<!-- 跟远程瑞尔 DW 一致(Asia/Shanghai)。CH 裸 DateTime 列(如 fact_appointment_out.in_time)
的渲染/读取依赖服务器时区:默认 UTC 会让 in_time 比北京裸字段(created_date 等)早 8h,
摄入端 FieldMapper 把它当北京 +08:00 解析 → 偏差。设成 Shanghai 后本地行为与远程 DW 一致。 -->
<timezone>Asia/Shanghai</timezone>
</clickhouse>
...@@ -27,6 +27,7 @@ services: ...@@ -27,6 +27,7 @@ services:
CLICKHOUSE_USER: default CLICKHOUSE_USER: default
CLICKHOUSE_PASSWORD: pac CLICKHOUSE_PASSWORD: pac
CLICKHOUSE_DB: dw_group CLICKHOUSE_DB: dw_group
TZ: Asia/Shanghai # 跟远程 DW 一致;裸 DateTime(in_time)按北京渲染/读取(另见 config.d/timezone.xml)
ports: ports:
- "8123:8123" # HTTP(PAC @clickhouse/client 连这个) - "8123:8123" # HTTP(PAC @clickhouse/client 连这个)
- "9100:9000" # native(避开常见 9000 占用;remote() 复制用) - "9100:9000" # native(避开常见 9000 占用;remote() 复制用)
...@@ -36,6 +37,8 @@ services: ...@@ -36,6 +37,8 @@ services:
hard: 262144 hard: 262144
volumes: volumes:
- clickhouse_data:/var/lib/clickhouse - clickhouse_data:/var/lib/clickhouse
# 服务器时区 = Asia/Shanghai(权威配置,不依赖 TZ env 是否被 CH 识别)
- ./clickhouse/config.d/timezone.xml:/etc/clickhouse-server/config.d/timezone.xml:ro
# 本地开发关闭 healthcheck —— alpine wget 走 localhost IPv6 失败 # 本地开发关闭 healthcheck —— alpine wget 走 localhost IPv6 失败
# ("Connection refused" 循环) → 每 5s spawn 失败 wget 持续占 1 核 CPU(实测 110%)。 # ("Connection refused" 循环) → 每 5s spawn 失败 wget 持续占 1 核 CPU(实测 110%)。
# 生产用时改回:test: ["CMD-SHELL", "wget --spider -q http://127.0.0.1:8123/ping || exit 1"] # 生产用时改回:test: ["CMD-SHELL", "wget --spider -q http://127.0.0.1:8123/ping || exit 1"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment