智慧水务管理系统 - 精河县供水工程综合管理平台

V_bpm_orchestration.sql 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. -- =====================================================
  2. -- 跨系统流程编排 DDL
  3. -- Issue #35: 跨系统流程编排 + Webhook 回调通知
  4. -- =====================================================
  5. -- 编排定义表 (已存在则跳过)
  6. CREATE TABLE IF NOT EXISTS bpm_orchestration (
  7. id BIGSERIAL PRIMARY KEY,
  8. orchestration_name VARCHAR(200) NOT NULL,
  9. orchestration_code VARCHAR(100) UNIQUE,
  10. description TEXT,
  11. process_definition_ids JSONB,
  12. orchestration_rules JSONB,
  13. trigger_type VARCHAR(50) DEFAULT 'manual',
  14. cron_expression VARCHAR(100),
  15. event_name VARCHAR(200),
  16. status INTEGER DEFAULT 0,
  17. created_by VARCHAR(100),
  18. execution_count INTEGER DEFAULT 0,
  19. tenant_id VARCHAR(100),
  20. deleted INTEGER DEFAULT 0,
  21. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  22. updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  23. );
  24. -- 编排执行记录表
  25. CREATE TABLE IF NOT EXISTS bpm_orchestration_execution (
  26. id BIGSERIAL PRIMARY KEY,
  27. orchestration_id BIGINT NOT NULL REFERENCES bpm_orchestration(id),
  28. execution_no VARCHAR(100) UNIQUE NOT NULL,
  29. current_step_index INTEGER DEFAULT 0,
  30. current_step_name VARCHAR(200),
  31. status VARCHAR(50) DEFAULT 'pending',
  32. started_at TIMESTAMP,
  33. completed_at TIMESTAMP,
  34. triggered_by VARCHAR(100),
  35. trigger_type VARCHAR(50) DEFAULT 'manual',
  36. input_params JSONB,
  37. output_result JSONB,
  38. failure_reason TEXT,
  39. retry_count INTEGER DEFAULT 0,
  40. tenant_id VARCHAR(100),
  41. deleted INTEGER DEFAULT 0,
  42. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  43. updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  44. );
  45. CREATE INDEX IF NOT EXISTS idx_orch_exec_orch_id ON bpm_orchestration_execution(orchestration_id);
  46. CREATE INDEX IF NOT EXISTS idx_orch_exec_no ON bpm_orchestration_execution(execution_no);
  47. CREATE INDEX IF NOT EXISTS idx_orch_exec_status ON bpm_orchestration_execution(status);
  48. CREATE INDEX IF NOT EXISTS idx_orch_exec_started ON bpm_orchestration_execution(started_at);
  49. -- 编排日志表
  50. CREATE TABLE IF NOT EXISTS bpm_orchestration_log (
  51. id BIGSERIAL PRIMARY KEY,
  52. execution_id BIGINT NOT NULL REFERENCES bpm_orchestration_execution(id),
  53. execution_no VARCHAR(100) NOT NULL,
  54. step_index INTEGER,
  55. step_name VARCHAR(200),
  56. action VARCHAR(50) NOT NULL,
  57. target_system VARCHAR(100),
  58. request_body JSONB,
  59. response_body JSONB,
  60. http_status INTEGER,
  61. duration_ms BIGINT,
  62. success BOOLEAN DEFAULT TRUE,
  63. error_message TEXT,
  64. log_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  65. operator VARCHAR(100),
  66. deleted INTEGER DEFAULT 0,
  67. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  68. updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  69. );
  70. CREATE INDEX IF NOT EXISTS idx_orch_log_exec_id ON bpm_orchestration_log(execution_id);
  71. CREATE INDEX IF NOT EXISTS idx_orch_log_exec_no ON bpm_orchestration_log(execution_no);
  72. CREATE INDEX IF NOT EXISTS idx_orch_log_time ON bpm_orchestration_log(log_time);
  73. CREATE INDEX IF NOT EXISTS idx_orch_log_action ON bpm_orchestration_log(action);
  74. -- 插入示例编排定义
  75. INSERT INTO bpm_orchestration (orchestration_name, orchestration_code, description, trigger_type, orchestration_rules, status, created_by)
  76. VALUES
  77. ('日常巡检数据同步编排', 'DAILY_PATROL_SYNC', '每日自动同步IoT设备数据、巡检任务、营收数据并发送通知', 'scheduled',
  78. '[
  79. {"stepName":"查询IoT设备状态","targetSystem":"iot","apiPath":"/api/iot/devices/status","method":"GET","timeoutMs":5000,"skippable":false,"maxRetries":3},
  80. {"stepName":"同步巡检任务","targetSystem":"patrol","apiPath":"/api/patrol/tasks/sync","method":"POST","timeoutMs":10000,"skippable":false,"maxRetries":3},
  81. {"stepName":"汇总营收数据","targetSystem":"revenue","apiPath":"/api/revenue/daily/summary","method":"GET","timeoutMs":8000,"skippable":true,"maxRetries":2},
  82. {"stepName":"发送汇总通知","targetSystem":"notify","apiPath":"/api/notify/send","method":"POST","timeoutMs":5000,"skippable":true,"maxRetries":1}
  83. ]',
  84. 1, 'system'),
  85. ('应急事件处理编排', 'EMERGENCY_RESPONSE', '突发事件触发时:获取设备数据→派发巡检任务→通知相关人员', 'event',
  86. '[
  87. {"stepName":"获取异常设备数据","targetSystem":"iot","apiPath":"/api/iot/devices/alerts","method":"GET","timeoutMs":3000,"skippable":false,"maxRetries":3},
  88. {"stepName":"派发应急巡检任务","targetSystem":"patrol","apiPath":"/api/patrol/tasks/emergency","method":"POST","timeoutMs":5000,"skippable":false,"maxRetries":3},
  89. {"stepName":"发送紧急通知","targetSystem":"notify","apiPath":"/api/notify/emergency","method":"POST","timeoutMs":3000,"skippable":false,"maxRetries":2}
  90. ]',
  91. 1, 'system')
  92. ON CONFLICT DO NOTHING;
  93. -- 注释
  94. COMMENT ON TABLE bpm_orchestration IS '跨系统流程编排定义表';
  95. COMMENT ON TABLE bpm_orchestration_execution IS '编排执行记录表';
  96. COMMENT ON TABLE bpm_orchestration_log IS '编排执行日志表';
  97. COMMENT ON COLUMN bpm_orchestration.orchestration_rules IS '编排步骤JSON数组';
  98. COMMENT ON COLUMN bpm_orchestration_execution.status IS '执行状态: pending/running/completed/failed/cancelled';
  99. COMMENT ON COLUMN bpm_orchestration_log.action IS '动作类型: start/complete/fail/retry/callback/skip/cancel';