Files
2026-05-18 09:28:15 +08:00

96 lines
2.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 触发器流程示例(type=2)
> 来源:平台示例 webhook、Timedtrigger、customeradd、messagetrigger
## 特点
- 无审批环节
- 由 Webhook 或定时器触发
- 用于自动化任务
## 平台示例
| 模板 | ID | 说明 |
|------|-----|------|
| webhook触发 | 623157924671258821 | 纯Webhook触发,无表单 |
| 定时获取官网案例信息 | 623157956061429957 | 定时触发 |
| 客户新增事件触发 | 623157979998322885 | 数据事件触发 |
| 人员入职通知触发 | 624245824599098245 | 消息触发器 |
## 与常规流程的区别
| 特性 | type=0/1 | type=2 触发器 |
|------|----------|---------------|
| 审批环节 | 有 | 无 |
| 表单 | 必需 | 可选 |
| flowId | 有 | 无 |
| 触发方式 | 人工发起 | Webhook/定时/事件 |
## flowXml(触发器流程)
```xml
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions ...>
<bpmn2:process id="Process_1" isExecutable="true">
<bpmn2:startEvent id="Event_1" />
</bpmn2:process>
</bpmn2:definitions>
```
## Webhook 配置
```python
# 获取 Webhook URL
resp = client.workflow.get_webhook_url({"flowId": template_id})
webhook_url = resp.data
# 开启 Webhook
client.workflow.webhook_start(template_id, random_str)
# 外部系统调用
import requests
requests.post(webhook_url, json={
"f_data": "trigger data",
})
```
## 触发器类型
### 1. Webhook 触发
- 外部系统通过 HTTP POST 调用
- 需要开启 webhook_start
### 2. 定时触发
- 配置 Cron 表达式
- 系统自动定时执行
### 3. 数据事件触发
- 绑定数据表变化事件
- 如:客户新增时触发
## 后端实现
```java
// TriggerApi.java
public class TriggerApi {
// Webhook 触发入口
public void webHookTrigger(String flowId, Map<String, Object> data) {
// 处理 Webhook 数据
// 执行业务逻辑
}
// 定时触发入口
public void timedTrigger(String flowId) {
// 获取配置的执行时间
// 执行业务逻辑
}
}
```
## 适用场景
1. **数据同步** - 当外部系统数据变化时同步到 JNPF
2. **定时任务** - 定期清理数据、发送报告
3. **事件驱动** - 用户注册后自动发送欢迎邮件
4. **消息通知** - 满足条件时发送通知