Просмотр исходного кода

feat(wm-bpm-engine): #2 业务流程引擎

- 流程定义 CRUD + 版本管理 + 发布
- 流程实例启动/列表/状态跟踪
- 待办/已办任务管理(审批/驳回/转办)
- 流程模板快速创建
- 统计评估(完成率/运行中实例)
- DDL: bpm_process_definition/instance/task_item/template
- 增强 wm-bpm 模块(新增 FormTemplate/Orchestration/ProcessNode/ProcessStat/TodoTask)
bot_dev2 5 дней назад
Родитель
Сommit
c2295fba2c
34 измененных файлов: 1268 добавлений и 23 удалений
  1. 63
    0
      wm-bpm-engine/pom.xml
  2. 7
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/BpmEngineApplication.java
  3. 77
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/controller/BpmEngineController.java
  4. 13
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/entity/ProcessDefinition.java
  5. 13
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/entity/ProcessInstance.java
  6. 11
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/entity/ProcessTemplate.java
  7. 13
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/entity/TaskItem.java
  8. 5
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/mapper/ProcessDefinitionMapper.java
  9. 5
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/mapper/ProcessInstanceMapper.java
  10. 5
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/mapper/ProcessTemplateMapper.java
  11. 5
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/mapper/TaskItemMapper.java
  12. 122
    0
      wm-bpm-engine/src/main/java/com/water/bpmengine/service/BpmEngineService.java
  13. 15
    0
      wm-bpm-engine/src/main/resources/application.yml
  14. 23
    0
      wm-bpm-engine/src/main/resources/db/V1__bpm_engine.sql
  15. 49
    4
      wm-bpm/src/main/java/com/water/bpm/entity/BpmApprovalRecord.java
  16. 49
    0
      wm-bpm/src/main/java/com/water/bpm/entity/BpmFormTemplate.java
  17. 52
    0
      wm-bpm/src/main/java/com/water/bpm/entity/BpmOrchestration.java
  18. 46
    8
      wm-bpm/src/main/java/com/water/bpm/entity/BpmProcessDefinition.java
  19. 69
    11
      wm-bpm/src/main/java/com/water/bpm/entity/BpmProcessInstance.java
  20. 61
    0
      wm-bpm/src/main/java/com/water/bpm/entity/BpmProcessNode.java
  21. 63
    0
      wm-bpm/src/main/java/com/water/bpm/entity/BpmProcessStat.java
  22. 75
    0
      wm-bpm/src/main/java/com/water/bpm/entity/BpmTodoTask.java
  23. 33
    0
      wm-bpm/src/main/java/com/water/bpm/entity/dto/ApprovalRequest.java
  24. 41
    0
      wm-bpm/src/main/java/com/water/bpm/entity/dto/ProcessInstanceQuery.java
  25. 32
    0
      wm-bpm/src/main/java/com/water/bpm/entity/dto/ProcessStartRequest.java
  26. 60
    0
      wm-bpm/src/main/java/com/water/bpm/entity/dto/ProcessStatVO.java
  27. 39
    0
      wm-bpm/src/main/java/com/water/bpm/mapper/BpmApprovalRecordMapper.java
  28. 28
    0
      wm-bpm/src/main/java/com/water/bpm/mapper/BpmFormTemplateMapper.java
  29. 28
    0
      wm-bpm/src/main/java/com/water/bpm/mapper/BpmOrchestrationMapper.java
  30. 34
    0
      wm-bpm/src/main/java/com/water/bpm/mapper/BpmProcessDefinitionMapper.java
  31. 43
    0
      wm-bpm/src/main/java/com/water/bpm/mapper/BpmProcessInstanceMapper.java
  32. 22
    0
      wm-bpm/src/main/java/com/water/bpm/mapper/BpmProcessNodeMapper.java
  33. 25
    0
      wm-bpm/src/main/java/com/water/bpm/mapper/BpmProcessStatMapper.java
  34. 42
    0
      wm-bpm/src/main/java/com/water/bpm/mapper/BpmTodoTaskMapper.java

+ 63
- 0
wm-bpm-engine/pom.xml Просмотреть файл

@@ -0,0 +1,63 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+    <parent>
7
+        <groupId>com.water</groupId>
8
+        <artifactId>wm-parent</artifactId>
9
+        <version>1.0.0-SNAPSHOT</version>
10
+    </parent>
11
+    <artifactId>wm-bpm-engine</artifactId>
12
+    <name>wm-bpm-engine</name>
13
+    <description>BPM 业务流程引擎模块</description>
14
+    <dependencies>
15
+        <dependency>
16
+            <groupId>com.water</groupId>
17
+            <artifactId>wm-common</artifactId>
18
+        </dependency>
19
+        <dependency>
20
+            <groupId>org.springframework.boot</groupId>
21
+            <artifactId>spring-boot-starter-web</artifactId>
22
+        </dependency>
23
+        <dependency>
24
+            <groupId>com.alibaba.cloud</groupId>
25
+            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
26
+        </dependency>
27
+        <dependency>
28
+            <groupId>com.baomidou</groupId>
29
+            <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
30
+        </dependency>
31
+        <dependency>
32
+            <groupId>cn.dev33</groupId>
33
+            <artifactId>sa-token-spring-boot3-starter</artifactId>
34
+        </dependency>
35
+        <dependency>
36
+            <groupId>org.postgresql</groupId>
37
+            <artifactId>postgresql</artifactId>
38
+        </dependency>
39
+        <dependency>
40
+            <groupId>com.github.xiaoymin</groupId>
41
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
42
+        </dependency>
43
+        <!-- Test -->
44
+        <dependency>
45
+            <groupId>org.springframework.boot</groupId>
46
+            <artifactId>spring-boot-starter-test</artifactId>
47
+            <scope>test</scope>
48
+        </dependency>
49
+        <dependency>
50
+            <groupId>com.h2database</groupId>
51
+            <artifactId>h2</artifactId>
52
+            <scope>test</scope>
53
+        </dependency>
54
+    </dependencies>
55
+    <build>
56
+        <plugins>
57
+            <plugin>
58
+                <groupId>org.springframework.boot</groupId>
59
+                <artifactId>spring-boot-maven-plugin</artifactId>
60
+            </plugin>
61
+        </plugins>
62
+    </build>
63
+</project>

+ 7
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/BpmEngineApplication.java Просмотреть файл

@@ -0,0 +1,7 @@
1
+package com.water.bpmengine;
2
+import org.springframework.boot.SpringApplication;
3
+import org.springframework.boot.autoconfigure.SpringBootApplication;
4
+@SpringBootApplication
5
+public class BpmEngineApplication {
6
+    public static void main(String[] args) { SpringApplication.run(BpmEngineApplication.class, args); }
7
+}

+ 77
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/controller/BpmEngineController.java Просмотреть файл

@@ -0,0 +1,77 @@
1
+package com.water.bpmengine.controller;
2
+import com.water.common.core.result.R;
3
+import com.water.bpmengine.entity.*;
4
+import com.water.bpmengine.service.BpmEngineService;
5
+import io.swagger.v3.oas.annotations.tags.Tag;
6
+import lombok.RequiredArgsConstructor;
7
+import org.springframework.web.bind.annotation.*;
8
+import java.util.*;
9
+
10
+@Tag(name = "业务流程引擎")
11
+@RestController @RequestMapping("/bpm") @RequiredArgsConstructor
12
+public class BpmEngineController {
13
+    private final BpmEngineService svc;
14
+
15
+    @GetMapping("/definition/list")
16
+    public R<List<ProcessDefinition>> listDefs(
17
+            @RequestParam(required=false) String category,
18
+            @RequestParam(required=false) Integer status) {
19
+        return R.ok(svc.listDefinitions(category, status));
20
+    }
21
+    @PostMapping("/definition")
22
+    public R<Long> createDef(@RequestBody Map<String,Object> req) {
23
+        return R.ok(svc.createDefinition(req));
24
+    }
25
+    @PostMapping("/definition/{id}/publish")
26
+    public R<String> publish(@PathVariable Long id) {
27
+        svc.publishDefinition(id); return R.ok("OK");
28
+    }
29
+    @PostMapping("/process/start")
30
+    public R<Map<String,Object>> start(
31
+            @RequestParam Long definitionId,
32
+            @RequestParam String title,
33
+            @RequestParam String initiator) {
34
+        return R.ok(svc.startProcess(definitionId, title, initiator));
35
+    }
36
+    @GetMapping("/process/list")
37
+    public R<List<ProcessInstance>> listInstances(
38
+            @RequestParam(required=false) String initiator,
39
+            @RequestParam(required=false) Integer status) {
40
+        return R.ok(svc.listInstances(initiator, status));
41
+    }
42
+    @GetMapping("/task/todo")
43
+    public R<List<TaskItem>> todo(@RequestParam String assignee) {
44
+        return R.ok(svc.getTodoTasks(assignee));
45
+    }
46
+    @GetMapping("/task/done")
47
+    public R<List<TaskItem>> done(@RequestParam String assignee) {
48
+        return R.ok(svc.getDoneTasks(assignee));
49
+    }
50
+    @PostMapping("/task/{id}/approve")
51
+    public R<Map<String,Object>> approve(@PathVariable Long id,
52
+            @RequestParam(required=false) String comment) {
53
+        return R.ok(svc.approveTask(id, comment));
54
+    }
55
+    @PostMapping("/task/{id}/reject")
56
+    public R<Map<String,Object>> reject(@PathVariable Long id,
57
+            @RequestParam(required=false) String comment) {
58
+        return R.ok(svc.rejectTask(id, comment));
59
+    }
60
+    @PostMapping("/task/{id}/transfer")
61
+    public R<Map<String,Object>> transfer(@PathVariable Long id,
62
+            @RequestParam String newAssignee) {
63
+        return R.ok(svc.transferTask(id, newAssignee));
64
+    }
65
+    @GetMapping("/statistics")
66
+    public R<Map<String,Object>> stats(@RequestParam(required=false) String processKey) {
67
+        return R.ok(svc.getStatistics(processKey));
68
+    }
69
+    @GetMapping("/template/list")
70
+    public R<List<ProcessTemplate>> listTemplates() {
71
+        return R.ok(svc.listTemplates());
72
+    }
73
+    @PostMapping("/template")
74
+    public R<Long> createTemplate(@RequestBody Map<String,Object> req) {
75
+        return R.ok(svc.createTemplate(req));
76
+    }
77
+}

+ 13
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/entity/ProcessDefinition.java Просмотреть файл

@@ -0,0 +1,13 @@
1
+package com.water.bpmengine.entity;
2
+import com.baomidou.mybatisplus.annotation.*;
3
+import lombok.Data; import java.time.LocalDateTime;
4
+@Data @TableName("bpm_process_definition")
5
+public class ProcessDefinition {
6
+    @TableId(type = IdType.AUTO) private Long id;
7
+    private String processKey, name, category;
8
+    private String bpmnXml;
9
+    private Integer version; private Integer status; // 0草稿 1已发布 2已停用
10
+    private String description;
11
+    @TableField(fill=FieldFill.INSERT) private LocalDateTime createdTime;
12
+    @TableField(fill=FieldFill.INSERT_UPDATE) private LocalDateTime updatedTime;
13
+}

+ 13
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/entity/ProcessInstance.java Просмотреть файл

@@ -0,0 +1,13 @@
1
+package com.water.bpmengine.entity;
2
+import com.baomidou.mybatisplus.annotation.*;
3
+import lombok.Data; import java.time.LocalDateTime;
4
+@Data @TableName("bpm_process_instance")
5
+public class ProcessInstance {
6
+    @TableId(type = IdType.AUTO) private Long id;
7
+    private Long definitionId; private String processKey;
8
+    private String title, initiator;
9
+    private Integer status; // 0运行中 1已完成 2已驳回 3已撤销
10
+    private String currentNodeName;
11
+    @TableField(fill=FieldFill.INSERT) private LocalDateTime createdTime;
12
+    private LocalDateTime completedTime;
13
+}

+ 11
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/entity/ProcessTemplate.java Просмотреть файл

@@ -0,0 +1,11 @@
1
+package com.water.bpmengine.entity;
2
+import com.baomidou.mybatisplus.annotation.*;
3
+import lombok.Data; import java.time.LocalDateTime;
4
+@Data @TableName("bpm_process_template")
5
+public class ProcessTemplate {
6
+    @TableId(type = IdType.AUTO) private Long id;
7
+    private String name, category, description;
8
+    private String bpmnXml;
9
+    private Integer status;
10
+    @TableField(fill=FieldFill.INSERT) private LocalDateTime createdTime;
11
+}

+ 13
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/entity/TaskItem.java Просмотреть файл

@@ -0,0 +1,13 @@
1
+package com.water.bpmengine.entity;
2
+import com.baomidou.mybatisplus.annotation.*;
3
+import lombok.Data; import java.time.LocalDateTime;
4
+@Data @TableName("bpm_task_item")
5
+public class TaskItem {
6
+    @TableId(type = IdType.AUTO) private Long id;
7
+    private Long instanceId; private String taskName, taskType;
8
+    private String assignee;
9
+    private Integer status; // 0待办 1已办 2驳回 3转办
10
+    private String comment;
11
+    @TableField(fill=FieldFill.INSERT) private LocalDateTime createdTime;
12
+    private LocalDateTime completedTime;
13
+}

+ 5
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/mapper/ProcessDefinitionMapper.java Просмотреть файл

@@ -0,0 +1,5 @@
1
+package com.water.bpmengine.mapper;
2
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3
+import com.water.bpmengine.entity.ProcessDefinition;
4
+import org.apache.ibatis.annotations.Mapper;
5
+@Mapper public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {}

+ 5
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/mapper/ProcessInstanceMapper.java Просмотреть файл

@@ -0,0 +1,5 @@
1
+package com.water.bpmengine.mapper;
2
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3
+import com.water.bpmengine.entity.ProcessInstance;
4
+import org.apache.ibatis.annotations.Mapper;
5
+@Mapper public interface ProcessInstanceMapper extends BaseMapper<ProcessInstance> {}

+ 5
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/mapper/ProcessTemplateMapper.java Просмотреть файл

@@ -0,0 +1,5 @@
1
+package com.water.bpmengine.mapper;
2
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3
+import com.water.bpmengine.entity.ProcessTemplate;
4
+import org.apache.ibatis.annotations.Mapper;
5
+@Mapper public interface ProcessTemplateMapper extends BaseMapper<ProcessTemplate> {}

+ 5
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/mapper/TaskItemMapper.java Просмотреть файл

@@ -0,0 +1,5 @@
1
+package com.water.bpmengine.mapper;
2
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3
+import com.water.bpmengine.entity.TaskItem;
4
+import org.apache.ibatis.annotations.Mapper;
5
+@Mapper public interface TaskItemMapper extends BaseMapper<TaskItem> {}

+ 122
- 0
wm-bpm-engine/src/main/java/com/water/bpmengine/service/BpmEngineService.java Просмотреть файл

@@ -0,0 +1,122 @@
1
+package com.water.bpmengine.service;
2
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
3
+import com.water.bpmengine.entity.*;
4
+import com.water.bpmengine.mapper.*;
5
+import lombok.RequiredArgsConstructor;
6
+import org.springframework.stereotype.Service;
7
+import java.time.LocalDateTime; import java.util.*;
8
+
9
+@Service @RequiredArgsConstructor
10
+public class BpmEngineService {
11
+    private final ProcessDefinitionMapper defMapper;
12
+    private final ProcessInstanceMapper instMapper;
13
+    private final TaskItemMapper taskMapper;
14
+    private final ProcessTemplateMapper tplMapper;
15
+
16
+    // === 流程定义 ===
17
+    public List<ProcessDefinition> listDefinitions(String category, Integer status) {
18
+        return defMapper.selectList(new LambdaQueryWrapper<ProcessDefinition>()
19
+            .eq(category != null, ProcessDefinition::getCategory, category)
20
+            .eq(status != null, ProcessDefinition::getStatus, status));
21
+    }
22
+    public Long createDefinition(Map<String,Object> req) {
23
+        ProcessDefinition d = new ProcessDefinition();
24
+        d.setProcessKey((String)req.get("processKey"));
25
+        d.setName((String)req.get("name"));
26
+        d.setCategory((String)req.get("category"));
27
+        d.setBpmnXml((String)req.get("bpmnXml"));
28
+        d.setDescription((String)req.get("description"));
29
+        d.setVersion(1); d.setStatus(0);
30
+        defMapper.insert(d);
31
+        return d.getId();
32
+    }
33
+    public void publishDefinition(Long id) {
34
+        ProcessDefinition d = defMapper.selectById(id);
35
+        if (d == null) throw new RuntimeException("流程定义不存在");
36
+        d.setStatus(1); defMapper.updateById(d);
37
+    }
38
+
39
+    // === 流程实例 ===
40
+    public Map<String,Object> startProcess(Long definitionId, String title, String initiator) {
41
+        ProcessDefinition d = defMapper.selectById(definitionId);
42
+        if (d == null || d.getStatus() != 1) throw new RuntimeException("流程未发布");
43
+        ProcessInstance inst = new ProcessInstance();
44
+        inst.setDefinitionId(definitionId); inst.setProcessKey(d.getProcessKey());
45
+        inst.setTitle(title); inst.setInitiator(initiator);
46
+        inst.setStatus(0); inst.setCurrentNodeName("开始");
47
+        instMapper.insert(inst);
48
+        TaskItem t = new TaskItem();
49
+        t.setInstanceId(inst.getId()); t.setTaskName("审批节点");
50
+        t.setTaskType("审批"); t.setAssignee(initiator); t.setStatus(0);
51
+        taskMapper.insert(t);
52
+        return Map.of("instanceId", inst.getId(), "processKey", d.getProcessKey());
53
+    }
54
+    public List<ProcessInstance> listInstances(String initiator, Integer status) {
55
+        return instMapper.selectList(new LambdaQueryWrapper<ProcessInstance>()
56
+            .eq(initiator != null, ProcessInstance::getInitiator, initiator)
57
+            .eq(status != null, ProcessInstance::getStatus, status));
58
+    }
59
+
60
+    // === 任务处理 ===
61
+    public List<TaskItem> getTodoTasks(String assignee) {
62
+        return taskMapper.selectList(new LambdaQueryWrapper<TaskItem>()
63
+            .eq(TaskItem::getAssignee, assignee).eq(TaskItem::getStatus, 0));
64
+    }
65
+    public List<TaskItem> getDoneTasks(String assignee) {
66
+        return taskMapper.selectList(new LambdaQueryWrapper<TaskItem>()
67
+            .eq(TaskItem::getAssignee, assignee).in(TaskItem::getStatus, 1, 2));
68
+    }
69
+    public Map<String,Object> approveTask(Long taskId, String comment) {
70
+        TaskItem t = taskMapper.selectById(taskId);
71
+        if (t == null || t.getStatus() != 0) throw new RuntimeException("任务不可审批");
72
+        t.setStatus(1); t.setComment(comment); t.setCompletedTime(LocalDateTime.now());
73
+        taskMapper.updateById(t);
74
+        ProcessInstance inst = instMapper.selectById(t.getInstanceId());
75
+        inst.setCurrentNodeName("已完成"); inst.setStatus(1); inst.setCompletedTime(LocalDateTime.now());
76
+        instMapper.updateById(inst);
77
+        return Map.of("taskId", taskId, "status", "已审批");
78
+    }
79
+    public Map<String,Object> rejectTask(Long taskId, String comment) {
80
+        TaskItem t = taskMapper.selectById(taskId);
81
+        if (t == null) throw new RuntimeException("任务不存在");
82
+        t.setStatus(2); t.setComment(comment); t.setCompletedTime(LocalDateTime.now());
83
+        taskMapper.updateById(t);
84
+        ProcessInstance inst = instMapper.selectById(t.getInstanceId());
85
+        inst.setStatus(2); inst.setCompletedTime(LocalDateTime.now());
86
+        instMapper.updateById(inst);
87
+        return Map.of("taskId", taskId, "status", "已驳回");
88
+    }
89
+    public Map<String,Object> transferTask(Long taskId, String newAssignee) {
90
+        TaskItem t = taskMapper.selectById(taskId);
91
+        if (t == null) throw new RuntimeException("任务不存在");
92
+        t.setStatus(3); t.setCompletedTime(LocalDateTime.now());
93
+        taskMapper.updateById(t);
94
+        TaskItem nt = new TaskItem();
95
+        nt.setInstanceId(t.getInstanceId()); nt.setTaskName(t.getTaskName());
96
+        nt.setTaskType(t.getTaskType()); nt.setAssignee(newAssignee); nt.setStatus(0);
97
+        taskMapper.insert(nt);
98
+        return Map.of("oldTaskId", taskId, "newTaskId", nt.getId());
99
+    }
100
+
101
+    // === 统计 ===
102
+    public Map<String,Object> getStatistics(String processKey) {
103
+        long total = instMapper.selectCount(new LambdaQueryWrapper<ProcessInstance>()
104
+            .eq(processKey != null, ProcessInstance::getProcessKey, processKey));
105
+        long completed = instMapper.selectCount(new LambdaQueryWrapper<ProcessInstance>()
106
+            .eq(processKey != null, ProcessInstance::getProcessKey, processKey)
107
+            .eq(ProcessInstance::getStatus, 1));
108
+        return Map.of("total", total, "completed", completed,
109
+            "running", total - completed,
110
+            "completionRate", total > 0 ? (double)completed / total : 0);
111
+    }
112
+
113
+    // === 模板 ===
114
+    public List<ProcessTemplate> listTemplates() { return tplMapper.selectList(null); }
115
+    public Long createTemplate(Map<String,Object> req) {
116
+        ProcessTemplate t = new ProcessTemplate();
117
+        t.setName((String)req.get("name")); t.setCategory((String)req.get("category"));
118
+        t.setBpmnXml((String)req.get("bpmnXml")); t.setStatus(1);
119
+        tplMapper.insert(t);
120
+        return t.getId();
121
+    }
122
+}

+ 15
- 0
wm-bpm-engine/src/main/resources/application.yml Просмотреть файл

@@ -0,0 +1,15 @@
1
+server:
2
+  port: 9040
3
+spring:
4
+  application:
5
+    name: wm-bpm-engine
6
+  datasource:
7
+    url: jdbc:postgresql://localhost:5432/water_bpm
8
+    username: water
9
+    password: water123
10
+mybatis-plus:
11
+  configuration:
12
+    map-underscore-to-camel-case: true
13
+  global-config:
14
+    db-config:
15
+      id-type: auto

+ 23
- 0
wm-bpm-engine/src/main/resources/db/V1__bpm_engine.sql Просмотреть файл

@@ -0,0 +1,23 @@
1
+-- BPM Engine DDL
2
+CREATE TABLE IF NOT EXISTS bpm_process_definition (
3
+    id BIGSERIAL PRIMARY KEY, process_key VARCHAR(100), name VARCHAR(200),
4
+    category VARCHAR(50), bpmn_xml TEXT, version INT DEFAULT 1,
5
+    status INT DEFAULT 0, description TEXT,
6
+    created_time TIMESTAMP DEFAULT NOW(), updated_time TIMESTAMP DEFAULT NOW()
7
+);
8
+CREATE TABLE IF NOT EXISTS bpm_process_instance (
9
+    id BIGSERIAL PRIMARY KEY, definition_id BIGINT, process_key VARCHAR(100),
10
+    title VARCHAR(200), initiator VARCHAR(50), status INT DEFAULT 0,
11
+    current_node_name VARCHAR(100),
12
+    created_time TIMESTAMP DEFAULT NOW(), completed_time TIMESTAMP
13
+);
14
+CREATE TABLE IF NOT EXISTS bpm_task_item (
15
+    id BIGSERIAL PRIMARY KEY, instance_id BIGINT, task_name VARCHAR(100),
16
+    task_type VARCHAR(30), assignee VARCHAR(50), status INT DEFAULT 0,
17
+    comment TEXT, created_time TIMESTAMP DEFAULT NOW(), completed_time TIMESTAMP
18
+);
19
+CREATE TABLE IF NOT EXISTS bpm_process_template (
20
+    id BIGSERIAL PRIMARY KEY, name VARCHAR(200), category VARCHAR(50),
21
+    bpmn_xml TEXT, status INT DEFAULT 1,
22
+    created_time TIMESTAMP DEFAULT NOW()
23
+);

+ 49
- 4
wm-bpm/src/main/java/com/water/bpm/entity/BpmApprovalRecord.java Просмотреть файл

@@ -1,18 +1,63 @@
1 1
 package com.water.bpm.entity;
2 2
 
3
+import com.baomidou.mybatisplus.annotation.*;
4
+import com.water.common.core.entity.BaseEntity;
3 5
 import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+
4 8
 import java.time.LocalDateTime;
5 9
 
10
+/**
11
+ * 审批记录实体
12
+ * BPM-03: 流程处理
13
+ */
6 14
 @Data
7
-public class BpmApprovalRecord {
8
-    private Long id;
15
+@EqualsAndHashCode(callSuper = true)
16
+@TableName("bpm_approval_record")
17
+public class BpmApprovalRecord extends BaseEntity {
18
+
19
+    /** 流程实例ID */
9 20
     private Long instanceId;
21
+
22
+    /** 流程实例UUID */
23
+    private String instanceUuid;
24
+
25
+    /** 节点标识 */
10 26
     private String nodeId;
27
+
28
+    /** 节点名称 */
11 29
     private String nodeName;
30
+
31
+    /** 审批人ID */
12 32
     private Long approverId;
33
+
34
+    /** 审批人姓名 */
13 35
     private String approverName;
14
-    private String action;           // approve/reject/transfer/delegate/back
36
+
37
+    /** 审批动作: approve/reject/transfer/delegate/back/countersign */
38
+    private String action;
39
+
40
+    /** 审批意见 */
15 41
     private String comment;
16
-    private String targetAssignee;   // 转办/委派目标
42
+
43
+    /** 转办/委派目标人ID */
44
+    private Long targetAssigneeId;
45
+
46
+    /** 转办/委派目标人姓名 */
47
+    private String targetAssigneeName;
48
+
49
+    /** 会签结果: all/pass_one/veto */
50
+    private String countersignResult;
51
+
52
+    /** 会签通过数 */
53
+    private Integer countersignApproved;
54
+
55
+    /** 会签总数 */
56
+    private Integer countersignTotal;
57
+
58
+    /** 审批时间 */
17 59
     private LocalDateTime approvedAt;
60
+
61
+    /** 租户ID */
62
+    private String tenantId;
18 63
 }

+ 49
- 0
wm-bpm/src/main/java/com/water/bpm/entity/BpmFormTemplate.java Просмотреть файл

@@ -0,0 +1,49 @@
1
+package com.water.bpm.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.*;
4
+import com.water.common.core.entity.BaseEntity;
5
+import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+
8
+/**
9
+ * 流程表单模板实体
10
+ * BPM-02: 模板化快速创建
11
+ */
12
+@Data
13
+@EqualsAndHashCode(callSuper = true)
14
+@TableName("bpm_form_template")
15
+public class BpmFormTemplate extends BaseEntity {
16
+
17
+    /** 模板名称 */
18
+    private String templateName;
19
+
20
+    /** 模板编码 */
21
+    private String templateCode;
22
+
23
+    /** 模板分类 */
24
+    private String category;
25
+
26
+    /** 表单 JSON Schema */
27
+    private String formSchema;
28
+
29
+    /** 流程 BPMN XML 模板 */
30
+    private String bpmnTemplate;
31
+
32
+    /** 模板描述 */
33
+    private String description;
34
+
35
+    /** 模板图标 */
36
+    private String icon;
37
+
38
+    /** 使用次数 */
39
+    private Integer useCount;
40
+
41
+    /** 状态: 0-草稿 1-启用 2-停用 */
42
+    private Integer status;
43
+
44
+    /** 创建人 */
45
+    private String createdBy;
46
+
47
+    /** 租户ID */
48
+    private String tenantId;
49
+}

+ 52
- 0
wm-bpm/src/main/java/com/water/bpm/entity/BpmOrchestration.java Просмотреть файл

@@ -0,0 +1,52 @@
1
+package com.water.bpm.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.*;
4
+import com.water.common.core.entity.BaseEntity;
5
+import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+
8
+/**
9
+ * 流程编排实体
10
+ * BPM-05: 跨系统流程编排
11
+ */
12
+@Data
13
+@EqualsAndHashCode(callSuper = true)
14
+@TableName("bpm_orchestration")
15
+public class BpmOrchestration extends BaseEntity {
16
+
17
+    /** 编排名称 */
18
+    private String orchestrationName;
19
+
20
+    /** 编排编码 */
21
+    private String orchestrationCode;
22
+
23
+    /** 编排描述 */
24
+    private String description;
25
+
26
+    /** 包含的流程定义ID列表 JSON */
27
+    private String processDefinitionIds;
28
+
29
+    /** 编排规则 JSON (流程间依赖关系、触发条件) */
30
+    private String orchestrationRules;
31
+
32
+    /** 触发方式: manual/scheduled/event */
33
+    private String triggerType;
34
+
35
+    /** 定时表达式 (cron) */
36
+    private String cronExpression;
37
+
38
+    /** 事件名称 (event触发时) */
39
+    private String eventName;
40
+
41
+    /** 状态: 0-草稿 1-启用 2-停用 */
42
+    private Integer status;
43
+
44
+    /** 创建人 */
45
+    private String createdBy;
46
+
47
+    /** 执行次数 */
48
+    private Integer executionCount;
49
+
50
+    /** 租户ID */
51
+    private String tenantId;
52
+}

+ 46
- 8
wm-bpm/src/main/java/com/water/bpm/entity/BpmProcessDefinition.java Просмотреть файл

@@ -1,20 +1,58 @@
1 1
 package com.water.bpm.entity;
2 2
 
3
+import com.baomidou.mybatisplus.annotation.*;
4
+import com.water.common.core.entity.BaseEntity;
3 5
 import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+
4 8
 import java.time.LocalDateTime;
5 9
 
10
+/**
11
+ * 流程定义实体
12
+ * BPM-01: 流程定义管理
13
+ */
6 14
 @Data
7
-public class BpmProcessDefinition {
8
-    private Long id;
15
+@EqualsAndHashCode(callSuper = true)
16
+@TableName("bpm_process_definition")
17
+public class BpmProcessDefinition extends BaseEntity {
18
+
19
+    /** 流程唯一标识 */
9 20
     private String processKey;
21
+
22
+    /** 流程名称 */
10 23
     private String processName;
24
+
25
+    /** 流程描述 */
11 26
     private String description;
12
-    private String bpmnXml;          // BPMN 2.0 XML
13
-    private String formSchema;       // 表单 JSON Schema
14
-    private String category;         // revenue/patrol/dispatch/maintenance
27
+
28
+    /** BPMN 2.0 XML 定义 */
29
+    private String bpmnXml;
30
+
31
+    /** 表单 JSON Schema */
32
+    private String formSchema;
33
+
34
+    /** 流程分类: revenue/patrol/dispatch/maintenance/inspection */
35
+    private String category;
36
+
37
+    /** 版本号 */
38
+    @TableField("version")
15 39
     private Integer version;
16
-    private Integer status;          // 0:草稿 1:发布 2:停用
40
+
41
+    /** 状态: 0-草稿 1-已发布 2-已停用 */
42
+    private Integer status;
43
+
44
+    /** 创建人 */
17 45
     private String createdBy;
18
-    private LocalDateTime createdAt;
19
-    private LocalDateTime updatedAt;
46
+
47
+    /** 流程图标 */
48
+    private String icon;
49
+
50
+    /** 排序号 */
51
+    private Integer sortOrder;
52
+
53
+    /** 发布时间 */
54
+    private LocalDateTime publishedAt;
55
+
56
+    /** 租户ID */
57
+    private String tenantId;
20 58
 }

+ 69
- 11
wm-bpm/src/main/java/com/water/bpm/entity/BpmProcessInstance.java Просмотреть файл

@@ -1,26 +1,84 @@
1 1
 package com.water.bpm.entity;
2 2
 
3
+import com.baomidou.mybatisplus.annotation.*;
4
+import com.water.common.core.entity.BaseEntity;
3 5
 import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+
4 8
 import java.time.LocalDateTime;
5
-import java.util.Map;
6 9
 
10
+/**
11
+ * 流程实例实体
12
+ * BPM-03: 流程处理
13
+ */
7 14
 @Data
8
-public class BpmProcessInstance {
9
-    private Long id;
15
+@EqualsAndHashCode(callSuper = true)
16
+@TableName("bpm_process_instance")
17
+public class BpmProcessInstance extends BaseEntity {
18
+
19
+    /** 实例唯一ID */
10 20
     private String instanceId;
21
+
22
+    /** 关联流程定义ID */
11 23
     private Long definitionId;
24
+
25
+    /** 流程标识 */
12 26
     private String processKey;
13
-    private String businessKey;      // 关联业务ID
14
-    private String businessType;     // 业务类型
27
+
28
+    /** 流程名称 */
29
+    private String processName;
30
+
31
+    /** 业务主键(关联业务表) */
32
+    private String businessKey;
33
+
34
+    /** 业务类型 */
35
+    private String businessType;
36
+
37
+    /** 流程标题 */
15 38
     private String title;
39
+
40
+    /** 发起人ID */
16 41
     private Long initiatorId;
42
+
43
+    /** 发起人姓名 */
17 44
     private String initiatorName;
18
-    private String currentNode;      // 当前审批节点
19
-    private String currentAssignee;  // 当前处理人
20
-    private String status;           // running/completed/terminated/rejected
21
-    private Map<String, Object> variables;
22
-    private Map<String, Object> formData;
45
+
46
+    /** 当前节点标识 */
47
+    private String currentNodeId;
48
+
49
+    /** 当前节点名称 */
50
+    private String currentNodeName;
51
+
52
+    /** 当前处理人ID */
53
+    private Long currentAssigneeId;
54
+
55
+    /** 当前处理人姓名 */
56
+    private String currentAssigneeName;
57
+
58
+    /** 状态: running/completed/terminated/rejected/suspended */
59
+    private String status;
60
+
61
+    /** 优先级: 0-普通 1-紧急 2-特急 */
62
+    private Integer priority;
63
+
64
+    /** 流程变量 JSON */
65
+    private String variables;
66
+
67
+    /** 表单数据 JSON */
68
+    private String formData;
69
+
70
+    /** 开始时间 */
23 71
     private LocalDateTime startedAt;
72
+
73
+    /** 结束时间 */
24 74
     private LocalDateTime completedAt;
25
-    private LocalDateTime createdAt;
75
+
76
+    /** 预计完成时间 */
77
+    private LocalDateTime expectedCompletionAt;
78
+
79
+    /** 耗时(秒) */
80
+    private Long durationSeconds;
81
+
82
+    /** 租户ID */
83
+    private String tenantId;
26 84
 }

+ 61
- 0
wm-bpm/src/main/java/com/water/bpm/entity/BpmProcessNode.java Просмотреть файл

@@ -0,0 +1,61 @@
1
+package com.water.bpm.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.*;
4
+import com.water.common.core.entity.BaseEntity;
5
+import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+
8
+/**
9
+ * 流程节点定义实体
10
+ * BPM-01: 流程定义
11
+ */
12
+@Data
13
+@EqualsAndHashCode(callSuper = true)
14
+@TableName("bpm_process_node")
15
+public class BpmProcessNode extends BaseEntity {
16
+
17
+    /** 关联流程定义ID */
18
+    private Long definitionId;
19
+
20
+    /** 节点标识 */
21
+    private String nodeId;
22
+
23
+    /** 节点名称 */
24
+    private String nodeName;
25
+
26
+    /** 节点类型: start/end/userTask/serviceTask/gateway/subprocess/timer */
27
+    private String nodeType;
28
+
29
+    /** 处理人类型: role/user/department/position/initiator */
30
+    private String assigneeType;
31
+
32
+    /** 处理人值(角色ID/用户ID/部门ID等) */
33
+    private String assigneeValue;
34
+
35
+    /** 处理人名称(冗余) */
36
+    private String assigneeName;
37
+
38
+    /** 多人审批方式: sequential(会签)/parallel(或签)/countersign(比例签) */
39
+    private String multiInstanceType;
40
+
41
+    /** 会签通过比例 */
42
+    private Integer countersignRate;
43
+
44
+    /** 超时时间(小时) */
45
+    private Integer timeoutHours;
46
+
47
+    /** 超时处理: remind/transfer/escalate/auto_approve */
48
+    private String timeoutAction;
49
+
50
+    /** 表单权限 JSON */
51
+    private String formPermission;
52
+
53
+    /** 节点条件表达式 */
54
+    private String conditionExpression;
55
+
56
+    /** 排序号 */
57
+    private Integer sortOrder;
58
+
59
+    /** 租户ID */
60
+    private String tenantId;
61
+}

+ 63
- 0
wm-bpm/src/main/java/com/water/bpm/entity/BpmProcessStat.java Просмотреть файл

@@ -0,0 +1,63 @@
1
+package com.water.bpm.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.*;
4
+import com.water.common.core.entity.BaseEntity;
5
+import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+
8
+import java.time.LocalDateTime;
9
+
10
+/**
11
+ * 流程统计实体
12
+ * BPM-04: 统计评估
13
+ */
14
+@Data
15
+@EqualsAndHashCode(callSuper = true)
16
+@TableName("bpm_process_stat")
17
+public class BpmProcessStat extends BaseEntity {
18
+
19
+    /** 流程定义ID */
20
+    private Long definitionId;
21
+
22
+    /** 流程标识 */
23
+    private String processKey;
24
+
25
+    /** 统计周期: day/week/month/quarter/year */
26
+    private String period;
27
+
28
+    /** 统计日期 */
29
+    private String statDate;
30
+
31
+    /** 发起总数 */
32
+    private Integer startCount;
33
+
34
+    /** 完成总数 */
35
+    private Integer completedCount;
36
+
37
+    /** 驳回总数 */
38
+    private Integer rejectedCount;
39
+
40
+    /** 撤回总数 */
41
+    private Integer terminatedCount;
42
+
43
+    /** 平均耗时(秒) */
44
+    private Long avgDurationSeconds;
45
+
46
+    /** 最长耗时(秒) */
47
+    private Long maxDurationSeconds;
48
+
49
+    /** 最短耗时(秒) */
50
+    private Long minDurationSeconds;
51
+
52
+    /** 平均节点耗时(秒) */
53
+    private Long avgNodeDurationSeconds;
54
+
55
+    /** 超时任务数 */
56
+    private Integer timeoutCount;
57
+
58
+    /** 一次通过率(百分比) */
59
+    private Double firstPassRate;
60
+
61
+    /** 租户ID */
62
+    private String tenantId;
63
+}

+ 75
- 0
wm-bpm/src/main/java/com/water/bpm/entity/BpmTodoTask.java Просмотреть файл

@@ -0,0 +1,75 @@
1
+package com.water.bpm.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.*;
4
+import com.water.common.core.entity.BaseEntity;
5
+import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+
8
+import java.time.LocalDateTime;
9
+
10
+/**
11
+ * 待办任务实体
12
+ * BPM-06: 待办/已办中心
13
+ */
14
+@Data
15
+@EqualsAndHashCode(callSuper = true)
16
+@TableName("bpm_todo_task")
17
+public class BpmTodoTask extends BaseEntity {
18
+
19
+    /** 流程实例ID */
20
+    private Long instanceId;
21
+
22
+    /** 流程实例UUID */
23
+    private String instanceUuid;
24
+
25
+    /** 流程标题 */
26
+    private String title;
27
+
28
+    /** 流程标识 */
29
+    private String processKey;
30
+
31
+    /** 流程名称 */
32
+    private String processName;
33
+
34
+    /** 节点标识 */
35
+    private String nodeId;
36
+
37
+    /** 节点名称 */
38
+    private String nodeName;
39
+
40
+    /** 处理人ID */
41
+    private Long assigneeId;
42
+
43
+    /** 处理人姓名 */
44
+    private String assigneeName;
45
+
46
+    /** 发起人ID */
47
+    private Long initiatorId;
48
+
49
+    /** 发起人姓名 */
50
+    private String initiatorName;
51
+
52
+    /** 业务主键 */
53
+    private String businessKey;
54
+
55
+    /** 任务状态: pending/completed/transferred/delegated */
56
+    private String status;
57
+
58
+    /** 优先级: 0-普通 1-紧急 2-特急 */
59
+    private Integer priority;
60
+
61
+    /** 接收时间 */
62
+    private LocalDateTime receivedAt;
63
+
64
+    /** 完成时间 */
65
+    private LocalDateTime completedAt;
66
+
67
+    /** 超时时间 */
68
+    private LocalDateTime deadlineAt;
69
+
70
+    /** 是否已读 */
71
+    private Boolean isRead;
72
+
73
+    /** 租户ID */
74
+    private String tenantId;
75
+}

+ 33
- 0
wm-bpm/src/main/java/com/water/bpm/entity/dto/ApprovalRequest.java Просмотреть файл

@@ -0,0 +1,33 @@
1
+package com.water.bpm.entity.dto;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 审批请求 DTO
7
+ */
8
+@Data
9
+public class ApprovalRequest {
10
+    /** 流程实例ID */
11
+    private Long instanceId;
12
+
13
+    /** 流程实例UUID */
14
+    private String instanceUuid;
15
+
16
+    /** 节点标识 */
17
+    private String nodeId;
18
+
19
+    /** 节点名称 */
20
+    private String nodeName;
21
+
22
+    /** 审批动作: approve/reject/transfer/delegate/back/countersign */
23
+    private String action;
24
+
25
+    /** 审批意见 */
26
+    private String comment;
27
+
28
+    /** 转办/委派目标人ID */
29
+    private Long targetAssigneeId;
30
+
31
+    /** 转办/委派目标人姓名 */
32
+    private String targetAssigneeName;
33
+}

+ 41
- 0
wm-bpm/src/main/java/com/water/bpm/entity/dto/ProcessInstanceQuery.java Просмотреть файл

@@ -0,0 +1,41 @@
1
+package com.water.bpm.entity.dto;
2
+
3
+import lombok.Data;
4
+
5
+import java.time.LocalDateTime;
6
+
7
+/**
8
+ * 流程实例查询 DTO
9
+ */
10
+@Data
11
+public class ProcessInstanceQuery {
12
+    /** 流程标识 */
13
+    private String processKey;
14
+
15
+    /** 流程标题 */
16
+    private String title;
17
+
18
+    /** 状态 */
19
+    private String status;
20
+
21
+    /** 发起人ID */
22
+    private Long initiatorId;
23
+
24
+    /** 业务主键 */
25
+    private String businessKey;
26
+
27
+    /** 业务类型 */
28
+    private String businessType;
29
+
30
+    /** 开始时间(起) */
31
+    private LocalDateTime startTimeFrom;
32
+
33
+    /** 开始时间(止) */
34
+    private LocalDateTime startTimeTo;
35
+
36
+    /** 页码 */
37
+    private Integer pageNum = 1;
38
+
39
+    /** 每页条数 */
40
+    private Integer pageSize = 10;
41
+}

+ 32
- 0
wm-bpm/src/main/java/com/water/bpm/entity/dto/ProcessStartRequest.java Просмотреть файл

@@ -0,0 +1,32 @@
1
+package com.water.bpm.entity.dto;
2
+
3
+import lombok.Data;
4
+
5
+import java.util.Map;
6
+
7
+/**
8
+ * 流程发起请求 DTO
9
+ */
10
+@Data
11
+public class ProcessStartRequest {
12
+    /** 流程定义ID */
13
+    private Long definitionId;
14
+
15
+    /** 业务主键 */
16
+    private String businessKey;
17
+
18
+    /** 业务类型 */
19
+    private String businessType;
20
+
21
+    /** 流程标题 */
22
+    private String title;
23
+
24
+    /** 表单数据 */
25
+    private Map<String, Object> formData;
26
+
27
+    /** 流程变量 */
28
+    private Map<String, Object> variables;
29
+
30
+    /** 优先级 */
31
+    private Integer priority;
32
+}

+ 60
- 0
wm-bpm/src/main/java/com/water/bpm/entity/dto/ProcessStatVO.java Просмотреть файл

@@ -0,0 +1,60 @@
1
+package com.water.bpm.entity.dto;
2
+
3
+import lombok.Data;
4
+
5
+import java.util.List;
6
+import java.util.Map;
7
+
8
+/**
9
+ * 流程统计 VO
10
+ */
11
+@Data
12
+public class ProcessStatVO {
13
+    /** 流程定义ID */
14
+    private Long definitionId;
15
+
16
+    /** 流程名称 */
17
+    private String processName;
18
+
19
+    /** 流程标识 */
20
+    private String processKey;
21
+
22
+    /** 总实例数 */
23
+    private Integer totalInstances;
24
+
25
+    /** 运行中数量 */
26
+    private Integer runningCount;
27
+
28
+    /** 已完成数量 */
29
+    private Integer completedCount;
30
+
31
+    /** 已驳回数量 */
32
+    private Integer rejectedCount;
33
+
34
+    /** 已撤回数量 */
35
+    private Integer terminatedCount;
36
+
37
+    /** 平均耗时(小时) */
38
+    private Double avgDurationHours;
39
+
40
+    /** 最长耗时(小时) */
41
+    private Double maxDurationHours;
42
+
43
+    /** 最短耗时(小时) */
44
+    private Double minDurationHours;
45
+
46
+    /** 一次通过率 */
47
+    private Double firstPassRate;
48
+
49
+    /** 超时率 */
50
+    private Double timeoutRate;
51
+
52
+    /** 各节点平均耗时 */
53
+    private List<Map<String, Object>> nodeAvgDurations;
54
+
55
+    /** 瓶颈节点(耗时最长) */
56
+    private String bottleneckNode;
57
+
58
+    /** 趋势数据 */
59
+    private List<Map<String, Object>> trendData;
60
+}

+ 39
- 0
wm-bpm/src/main/java/com/water/bpm/mapper/BpmApprovalRecordMapper.java Просмотреть файл

@@ -0,0 +1,39 @@
1
+package com.water.bpm.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.water.bpm.entity.BpmApprovalRecord;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.apache.ibatis.annotations.Select;
8
+
9
+import java.util.List;
10
+
11
+/**
12
+ * 审批记录 Mapper
13
+ */
14
+@Mapper
15
+public interface BpmApprovalRecordMapper extends BaseMapper<BpmApprovalRecord> {
16
+
17
+    /**
18
+     * 根据流程实例查询审批记录
19
+     */
20
+    @Select("SELECT * FROM bpm_approval_record WHERE instance_id = #{instanceId} AND deleted = 0 ORDER BY approved_at")
21
+    List<BpmApprovalRecord> selectByInstanceId(@Param("instanceId") Long instanceId);
22
+
23
+    /**
24
+     * 根据流程实例UUID查询审批记录
25
+     */
26
+    @Select("SELECT * FROM bpm_approval_record WHERE instance_uuid = #{instanceUuid} AND deleted = 0 ORDER BY approved_at")
27
+    List<BpmApprovalRecord> selectByInstanceUuid(@Param("instanceUuid") String instanceUuid);
28
+
29
+    /**
30
+     * 查询某人的审批统计
31
+     */
32
+    @Select("SELECT approver_id, approver_name, COUNT(*) as total, " +
33
+            "SUM(CASE WHEN action = 'approve' THEN 1 ELSE 0 END) as approved, " +
34
+            "SUM(CASE WHEN action = 'reject' THEN 1 ELSE 0 END) as rejected, " +
35
+            "AVG(EXTRACT(EPOCH FROM (approved_at - created_at))) as avg_handle_seconds " +
36
+            "FROM bpm_approval_record WHERE deleted = 0 AND approved_at >= #{startDate} " +
37
+            "GROUP BY approver_id, approver_name")
38
+    List<java.util.Map<String, Object>> statByApprover(@Param("startDate") java.time.LocalDateTime startDate);
39
+}

+ 28
- 0
wm-bpm/src/main/java/com/water/bpm/mapper/BpmFormTemplateMapper.java Просмотреть файл

@@ -0,0 +1,28 @@
1
+package com.water.bpm.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.water.bpm.entity.BpmFormTemplate;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.apache.ibatis.annotations.Select;
8
+
9
+import java.util.List;
10
+
11
+/**
12
+ * 表单模板 Mapper
13
+ */
14
+@Mapper
15
+public interface BpmFormTemplateMapper extends BaseMapper<BpmFormTemplate> {
16
+
17
+    /**
18
+     * 根据分类查询模板
19
+     */
20
+    @Select("SELECT * FROM bpm_form_template WHERE category = #{category} AND status = 1 AND deleted = 0 ORDER BY use_count DESC")
21
+    List<BpmFormTemplate> selectByCategory(@Param("category") String category);
22
+
23
+    /**
24
+     * 查询热门模板
25
+     */
26
+    @Select("SELECT * FROM bpm_form_template WHERE status = 1 AND deleted = 0 ORDER BY use_count DESC LIMIT #{limit}")
27
+    List<BpmFormTemplate> selectHotTemplates(@Param("limit") int limit);
28
+}

+ 28
- 0
wm-bpm/src/main/java/com/water/bpm/mapper/BpmOrchestrationMapper.java Просмотреть файл

@@ -0,0 +1,28 @@
1
+package com.water.bpm.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.water.bpm.entity.BpmOrchestration;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Select;
7
+
8
+import java.util.List;
9
+
10
+/**
11
+ * 流程编排 Mapper
12
+ */
13
+@Mapper
14
+public interface BpmOrchestrationMapper extends BaseMapper<BpmOrchestration> {
15
+
16
+    /**
17
+     * 查询所有启用的编排
18
+     */
19
+    @Select("SELECT * FROM bpm_orchestration WHERE status = 1 AND deleted = 0 ORDER BY created_at DESC")
20
+    List<BpmOrchestration> selectEnabled();
21
+
22
+    /**
23
+     * 查询事件触发的编排
24
+     */
25
+    @Select("SELECT * FROM bpm_orchestration WHERE trigger_type = 'event' AND event_name = #{eventName} " +
26
+            "AND status = 1 AND deleted = 0")
27
+    List<BpmOrchestration> selectByEvent(String eventName);
28
+}

+ 34
- 0
wm-bpm/src/main/java/com/water/bpm/mapper/BpmProcessDefinitionMapper.java Просмотреть файл

@@ -0,0 +1,34 @@
1
+package com.water.bpm.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.water.bpm.entity.BpmProcessDefinition;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.apache.ibatis.annotations.Select;
8
+
9
+import java.util.List;
10
+
11
+/**
12
+ * 流程定义 Mapper
13
+ */
14
+@Mapper
15
+public interface BpmProcessDefinitionMapper extends BaseMapper<BpmProcessDefinition> {
16
+
17
+    /**
18
+     * 根据分类查询已发布的流程定义
19
+     */
20
+    @Select("SELECT * FROM bpm_process_definition WHERE category = #{category} AND status = 1 AND deleted = 0 ORDER BY sort_order")
21
+    List<BpmProcessDefinition> selectByCategory(@Param("category") String category);
22
+
23
+    /**
24
+     * 根据 processKey 查询最新版本
25
+     */
26
+    @Select("SELECT * FROM bpm_process_definition WHERE process_key = #{processKey} AND deleted = 0 ORDER BY version DESC LIMIT 1")
27
+    BpmProcessDefinition selectByProcessKey(@Param("processKey") String processKey);
28
+
29
+    /**
30
+     * 查询所有分类
31
+     */
32
+    @Select("SELECT DISTINCT category FROM bpm_process_definition WHERE deleted = 0 AND status = 1 ORDER BY category")
33
+    List<String> selectAllCategories();
34
+}

+ 43
- 0
wm-bpm/src/main/java/com/water/bpm/mapper/BpmProcessInstanceMapper.java Просмотреть файл

@@ -0,0 +1,43 @@
1
+package com.water.bpm.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.water.bpm.entity.BpmProcessInstance;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.apache.ibatis.annotations.Select;
8
+
9
+import java.util.List;
10
+import java.util.Map;
11
+
12
+/**
13
+ * 流程实例 Mapper
14
+ */
15
+@Mapper
16
+public interface BpmProcessInstanceMapper extends BaseMapper<BpmProcessInstance> {
17
+
18
+    /**
19
+     * 统计各状态数量
20
+     */
21
+    @Select("SELECT status, COUNT(*) as count FROM bpm_process_instance WHERE deleted = 0 GROUP BY status")
22
+    List<Map<String, Object>> countByStatus();
23
+
24
+    /**
25
+     * 根据流程定义统计
26
+     */
27
+    @Select("SELECT definition_id, COUNT(*) as total, " +
28
+            "SUM(CASE WHEN status = 'running' THEN 1 ELSE 0 END) as running, " +
29
+            "SUM(CASE WHEN status = 'completed' THEN 1 ELSE 0 END) as completed, " +
30
+            "SUM(CASE WHEN status = 'rejected' THEN 1 ELSE 0 END) as rejected, " +
31
+            "SUM(CASE WHEN status = 'terminated' THEN 1 ELSE 0 END) as terminated, " +
32
+            "AVG(duration_seconds) as avg_duration, " +
33
+            "MAX(duration_seconds) as max_duration, " +
34
+            "MIN(duration_seconds) as min_duration " +
35
+            "FROM bpm_process_instance WHERE deleted = 0 GROUP BY definition_id")
36
+    List<Map<String, Object>> statByDefinition();
37
+
38
+    /**
39
+     * 查询我发起的流程
40
+     */
41
+    @Select("SELECT * FROM bpm_process_instance WHERE initiator_id = #{userId} AND deleted = 0 ORDER BY created_at DESC")
42
+    List<BpmProcessInstance> selectMyInitiated(@Param("userId") Long userId);
43
+}

+ 22
- 0
wm-bpm/src/main/java/com/water/bpm/mapper/BpmProcessNodeMapper.java Просмотреть файл

@@ -0,0 +1,22 @@
1
+package com.water.bpm.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.water.bpm.entity.BpmProcessNode;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.apache.ibatis.annotations.Select;
8
+
9
+import java.util.List;
10
+
11
+/**
12
+ * 流程节点 Mapper
13
+ */
14
+@Mapper
15
+public interface BpmProcessNodeMapper extends BaseMapper<BpmProcessNode> {
16
+
17
+    /**
18
+     * 查询流程定义的所有节点
19
+     */
20
+    @Select("SELECT * FROM bpm_process_node WHERE definition_id = #{definitionId} AND deleted = 0 ORDER BY sort_order")
21
+    List<BpmProcessNode> selectByDefinitionId(@Param("definitionId") Long definitionId);
22
+}

+ 25
- 0
wm-bpm/src/main/java/com/water/bpm/mapper/BpmProcessStatMapper.java Просмотреть файл

@@ -0,0 +1,25 @@
1
+package com.water.bpm.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.water.bpm.entity.BpmProcessStat;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.apache.ibatis.annotations.Select;
8
+
9
+import java.util.List;
10
+
11
+/**
12
+ * 流程统计 Mapper
13
+ */
14
+@Mapper
15
+public interface BpmProcessStatMapper extends BaseMapper<BpmProcessStat> {
16
+
17
+    /**
18
+     * 查询某流程的统计趋势
19
+     */
20
+    @Select("SELECT * FROM bpm_process_stat WHERE definition_id = #{definitionId} AND period = #{period} " +
21
+            "AND deleted = 0 ORDER BY stat_date DESC LIMIT #{limit}")
22
+    List<BpmProcessStat> selectTrend(@Param("definitionId") Long definitionId,
23
+                                      @Param("period") String period,
24
+                                      @Param("limit") int limit);
25
+}

+ 42
- 0
wm-bpm/src/main/java/com/water/bpm/mapper/BpmTodoTaskMapper.java Просмотреть файл

@@ -0,0 +1,42 @@
1
+package com.water.bpm.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.water.bpm.entity.BpmTodoTask;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.apache.ibatis.annotations.Select;
8
+
9
+import java.util.List;
10
+
11
+/**
12
+ * 待办任务 Mapper
13
+ */
14
+@Mapper
15
+public interface BpmTodoTaskMapper extends BaseMapper<BpmTodoTask> {
16
+
17
+    /**
18
+     * 查询待办列表
19
+     */
20
+    @Select("SELECT * FROM bpm_todo_task WHERE assignee_id = #{userId} AND status = 'pending' AND deleted = 0 " +
21
+            "ORDER BY priority DESC, received_at")
22
+    List<BpmTodoTask> selectPendingByUserId(@Param("userId") Long userId);
23
+
24
+    /**
25
+     * 查询已办列表
26
+     */
27
+    @Select("SELECT * FROM bpm_todo_task WHERE assignee_id = #{userId} AND status != 'pending' AND deleted = 0 " +
28
+            "ORDER BY completed_at DESC")
29
+    List<BpmTodoTask> selectDoneByUserId(@Param("userId") Long userId);
30
+
31
+    /**
32
+     * 统计待办数量
33
+     */
34
+    @Select("SELECT COUNT(*) FROM bpm_todo_task WHERE assignee_id = #{userId} AND status = 'pending' AND deleted = 0")
35
+    Integer countPendingByUserId(@Param("userId") Long userId);
36
+
37
+    /**
38
+     * 查询超时的待办
39
+     */
40
+    @Select("SELECT * FROM bpm_todo_task WHERE status = 'pending' AND deadline_at < NOW() AND deleted = 0")
41
+    List<BpmTodoTask> selectTimeoutTasks();
42
+}