s8DeliveryMonitoringApi.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { s8MonitoringApi, type S8MonitoringSummary, type S8ModuleOrderSummary, type S8Period } from './s8MonitoringApi';
  2. import { loadConfiguredAnomalyTypes } from './s8MonitoringCellApi';
  3. export interface DeliveryAnomalyType {
  4. key: string;
  5. label: string;
  6. total: number;
  7. avgProcessHours: number;
  8. closeRate: number;
  9. }
  10. export interface DeliveryMonitoringData {
  11. summary: S8MonitoringSummary;
  12. modules: S8ModuleOrderSummary[];
  13. anomalyTypes: DeliveryAnomalyType[];
  14. }
  15. // S8-DELIVERY-PAGE-TYPE-PRUNE-AND-TREND-ALIGN-1:Delivery 页类型卡收敛为 2 类;
  16. // 显示名「总装发货延期」仅 delivery 大屏展示,不改 ado_s8_exception_type.type_name。
  17. const DELIVERY_ANOMALY_SPECS = [
  18. {
  19. key: 'order-due-date-delay',
  20. label: '订单交期延期',
  21. totalCellCode: 'DELIVERY_ANOMALY_ORDER_DUE_DATE_DELAY',
  22. analysisCellCode: 'DELIVERY_CAT_ORDER_DUE_DATE_DELAY',
  23. },
  24. {
  25. key: 'delivery-delay-warning',
  26. label: '总装发货延期',
  27. totalCellCode: 'DELIVERY_ANOMALY_DELIVERY_DELAY_WARNING',
  28. analysisCellCode: 'DELIVERY_CAT_DELIVERY_DELAY_WARNING',
  29. },
  30. ] as const;
  31. const EMPTY_SUMMARY: S8MonitoringSummary = { total: 0, red: 0, yellow: 0, green: 0, timeout: 0, byModule: [] };
  32. export const s8DeliveryMonitoringApi = {
  33. /** 获取交付域汇总摘要;moduleCodes 由 page-config 派生(fallback 走 STAGE_META_FALLBACK)。空数组时直接返回空态,不退化为后端全量。 */
  34. summary: (moduleCodes: string[], period?: S8Period): Promise<S8MonitoringSummary> =>
  35. moduleCodes.length === 0
  36. ? Promise.resolve({ ...EMPTY_SUMMARY, byModule: [] })
  37. : s8MonitoringApi.summary({ moduleCode: moduleCodes.join(','), period }),
  38. /** 获取交付域各阶段订单统计;按 moduleCodes 过滤 byModule 全集。空数组时不调接口,直接返回空数组。 */
  39. modules: (moduleCodes: string[], period?: S8Period): Promise<S8ModuleOrderSummary[]> => {
  40. if (moduleCodes.length === 0) return Promise.resolve([]);
  41. const set = new Set(moduleCodes);
  42. return s8MonitoringApi.orderGrid({ period }).then((data) =>
  43. data.modules.filter((m) => set.has(m.moduleCode)),
  44. );
  45. },
  46. /** 获取交付异常类型明细;接口失败返回空数组(不再回退到示例数据) */
  47. anomalyTypes: (): Promise<DeliveryAnomalyType[]> =>
  48. loadConfiguredAnomalyTypes('DELIVERY', [...DELIVERY_ANOMALY_SPECS]),
  49. };