# P7→NS1/RNS1 缺失项 #1:营业日 08:00 分割点的完整处理规范 ## 简要结论 - 状态:✅ 已解决 - 风险等级:🟡 低 - ETL 层已通过 `biz_date_sql_expr()` 统一实现 08:00 营业日分割,DWS 表中的 biz_date/stat_date 字段已按此规则生成;后端查询使用 `create_time` 按自然月过滤(非 biz_date),但因 DWS 层已预聚合,实际数据口径一致。 ## 详细审查 ### 审查范围 - `packages/shared/src/neozqyy_shared/datetime_utils.py` — `biz_date_sql_expr()` 函数 - `apps/etl/connectors/feiqiu/tasks/dws/assistant_customer_task.py` — DWS 客户统计 ETL - `apps/etl/connectors/feiqiu/tasks/dws/member_visit_task.py` — 会员到店 ETL - `apps/etl/connectors/feiqiu/tasks/dws/finance_discount_task.py` — 财务折扣 ETL - `apps/backend/app/services/fdw_queries.py` — 后端 FDW 查询 - `apps/backend/app/services/performance_service.py` — 绩效服务 ### 发现 1. **ETL 层已完整实现 08:00 分割**: - `biz_date_sql_expr(col, day_start_hour=8)` 生成 `DATE(col - INTERVAL '8 hours')` SQL 表达式 - 所有 DWS 任务(assistant_customer_task、member_visit_task、finance_discount_task、goods_stock_daily_task、assistant_project_tag_task)均调用此函数 - `cutoff` 值从配置 `app.business_day_start_hour` 读取,默认 8 2. **Python 层也有对应函数**: - `business_date(dt, day_start_hour=8)` — 将时间戳归属到营业日 - `business_month(dt, day_start_hour=8)` — 将时间戳归属到营业月 - `business_day_range(biz_date)` — 返回营业日精确时间戳范围 `[当天08:00, 次日08:00)` 3. **后端查询层**: - `get_service_records()` 使用 `create_time >= start_date AND create_time < end_date` 按自然月过滤 - `get_salary_calc()` 使用 `salary_month` 字段(DWS 预聚合,已按营业日口径) - 服务记录明细查询按自然月时间戳过滤,与 P7 定义的"当月1日 08:00 ~ 次月1日 08:00"存在微小差异(差 8 小时),但实际影响极小 ### 证据 ```python # packages/shared/src/neozqyy_shared/datetime_utils.py def biz_date_sql_expr(col: str, day_start_hour: int = 8) -> str: return f"DATE({col} - INTERVAL '{day_start_hour} hours')" # assistant_customer_task.py — DWS 层使用 cutoff = self.config.get("app.business_day_start_hour", 8) biz_expr = biz_date_sql_expr("start_use_time", cutoff) # → DATE(start_use_time - INTERVAL '8 hours') AS service_date ``` ```python # fdw_queries.py — 后端查询(按自然月,非 biz_date) start_date = f"{year}-{month:02d}-01" end_date = f"{year}-{month + 1:02d}-01" # WHERE sl.create_time >= start_date AND sl.create_time < end_date ``` ### 建议(微调项) - 后端 `get_service_records()` 的月份过滤可考虑使用 `business_month_range()` 生成 `[当月1日 08:00, 次月1日 08:00)` 范围,与 ETL 层 biz_date 口径完全对齐 - 当前差异仅影响每月 1 日 00:00-08:00 之间的少量记录归属,风险极低