1.0.177.sql 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. -- =============================================================================
  2. -- S8 订单交付超期监控向导:真实数据源登记
  3. -- 作用:将 ORDER_DELIVERY 监控对象的源表切换为数据中台真实发货宽表 dwd_ship_trans
  4. -- (经受控只读视图 v_s8_order_delivery_watch 收敛)。
  5. -- 前提(已拍板):单客户私有云,S8(租户 1)经受控只读视图读取数据中台业务租户
  6. -- 797403760988229 的订单交付数据。
  7. -- 安全级别:仅登记字典;不创建 watch_rule、不启用 watch_rule、不触发调度器、不自动建异常单。
  8. -- =============================================================================
  9. -- 1) 受控视图:锚定业务租户 797403760988229;每 order_no 折叠到最新 stat_date(1 行/单)。
  10. -- plan_delivery_date 取 MIN(最早到期行代表订单超期);
  11. -- delivery_status 采用“全部行 COMPLETED 才算 COMPLETED,否则 OPEN”。
  12. CREATE OR REPLACE VIEW v_s8_order_delivery_watch AS
  13. SELECT
  14. t.order_no AS order_no,
  15. MAX(t.customer_name) AS customer_name,
  16. MIN(t.plan_delivery_date) AS plan_delivery_date,
  17. CASE WHEN SUM(t.delivery_status = 'COMPLETED') = COUNT(*)
  18. THEN 'COMPLETED' ELSE 'OPEN' END AS delivery_status
  19. FROM dwd_ship_trans t
  20. JOIN (
  21. SELECT order_no, MAX(stat_date) AS max_stat
  22. FROM dwd_ship_trans
  23. WHERE tenant_id = 797403760988229
  24. GROUP BY order_no
  25. ) latest ON t.order_no = latest.order_no AND t.stat_date = latest.max_stat
  26. WHERE t.tenant_id = 797403760988229
  27. GROUP BY t.order_no;
  28. -- 2) 监控对象 ORDER_DELIVERY:源表切换到受控视图(baseline 口径 tenant_id=0 / factory_id=0)。
  29. UPDATE ado_s8_monitor_object
  30. SET source_table = 'v_s8_order_delivery_watch', updated_at = NOW()
  31. WHERE tenant_id = 0 AND factory_id = 0 AND object_code = 'ORDER_DELIVERY';
  32. -- 3) 监控指标 ORDER_DUE_AT:字段映射切真实列 + 完成态口径 + 稳定业务键(order_no)。
  33. -- enabled = 1 仅表示字典可见、向导可选;监控启用的安全闸门落在 watch_rule 层。
  34. UPDATE ado_s8_monitor_metric
  35. SET due_at_field = 'plan_delivery_date',
  36. status_field = 'delivery_status',
  37. default_completed_states = 'COMPLETED',
  38. object_id_field = 'order_no',
  39. object_code_field = 'order_no',
  40. object_name_field = 'customer_name',
  41. metric_name = '计划交付超期',
  42. enabled = 1,
  43. updated_at = NOW()
  44. WHERE tenant_id = 0 AND factory_id = 0
  45. AND object_code = 'ORDER_DELIVERY' AND metric_code = 'ORDER_DUE_AT';