s8DeliveryMonitoringApi.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. const DELIVERY_ANOMALY_SPECS = [
  16. {
  17. key: 'order-change',
  18. label: '订单变更',
  19. totalCellCode: 'DELIVERY_ANOMALY_ORDER_CHANGE',
  20. analysisCellCode: 'DELIVERY_CAT_ORDER_CHANGE',
  21. },
  22. {
  23. key: 'delivery-delay',
  24. label: '交期延迟',
  25. totalCellCode: 'DELIVERY_ANOMALY_DELIVERY_DELAY',
  26. analysisCellCode: 'DELIVERY_CAT_DELIVERY_DELAY',
  27. },
  28. {
  29. key: 'stock-pending',
  30. label: '入库待发',
  31. totalCellCode: 'DELIVERY_ANOMALY_STOCK_PENDING',
  32. analysisCellCode: 'DELIVERY_CAT_STOCK_PENDING',
  33. },
  34. ] as const;
  35. const EMPTY_SUMMARY: S8MonitoringSummary = { total: 0, red: 0, yellow: 0, green: 0, timeout: 0, byModule: [] };
  36. export const s8DeliveryMonitoringApi = {
  37. /** 获取交付域汇总摘要;moduleCodes 由 page-config 派生(fallback 走 STAGE_META_FALLBACK)。空数组时直接返回空态,不退化为后端全量。 */
  38. summary: (moduleCodes: string[], period?: S8Period): Promise<S8MonitoringSummary> =>
  39. moduleCodes.length === 0
  40. ? Promise.resolve({ ...EMPTY_SUMMARY, byModule: [] })
  41. : s8MonitoringApi.summary({ moduleCode: moduleCodes.join(','), period }),
  42. /** 获取交付域各阶段订单统计;按 moduleCodes 过滤 byModule 全集。空数组时不调接口,直接返回空数组。 */
  43. modules: (moduleCodes: string[], period?: S8Period): Promise<S8ModuleOrderSummary[]> => {
  44. if (moduleCodes.length === 0) return Promise.resolve([]);
  45. const set = new Set(moduleCodes);
  46. return s8MonitoringApi.orderGrid({ period }).then((data) =>
  47. data.modules.filter((m) => set.has(m.moduleCode)),
  48. );
  49. },
  50. /** 获取交付异常类型明细;接口失败返回空数组(不再回退到示例数据) */
  51. anomalyTypes: (): Promise<DeliveryAnomalyType[]> =>
  52. loadConfiguredAnomalyTypes('DELIVERY', [...DELIVERY_ANOMALY_SPECS]),
  53. };