前言
先說下本人爲什麼使用 Comment 來保存審覈信息
- 自然因爲簡單,不需要自己額外建表保存(本人懶漢)
- 由於本人項目這使用的是微服務架構,流程引擎單獨一個數據庫,其他數據其他庫。但不管在哪建表,查詢後也需要自己對數據整合,比較麻煩(本人懶漢)
- 就目前而言,個人覺得 flowable 提供的 Comment 足夠支持這方面的需求
表結構
ACT_HI_COMMENT
PS:只有 TYPE_
,TIME_
,ACTION_
這三個參數會自動生成,也就是說 TASK_ID_
,PROC_INST_ID_
這兩個參數,如果調用接口時候不設置,就不會有
接口整理
PS:都在 TaskService
接口中
查詢
Comment getComment(String commentId)
List<Comment> getTaskComments(String taskId)
PS:默認只會獲取類型爲 comment 的建議
List<Comment> getTaskComments(String taskId, String type)
List<Comment> getCommentsByType(String type)
List<Comment> getProcessInstanceComments(String processInstanceId)
List<Comment> getProcessInstanceComments(String processInstanceId, String type)
新增
Comment addComment(String taskId, String processInstance, String message)
PS:默認 TYPE_
爲 comment
Comment addComment(String taskId, String processInstance, String type, String message)
更新
void saveComment(Comment comment)
PS:ID 存在則更新,不存在報錯
刪除
void deleteComment(String commentId)
void deleteComments(String taskId, String processInstanceId)
審覈示例
新增信息
審覈完成後,添加審覈信息
我依據自己的想法,自定義 Comment 類別
- taskStatus:審覈狀態
- taskMessage:審覈結果
- taskComment:審覈意見,也就是頁面用戶輸入的意
審覈信息查詢
PS:查詢則是根據流程定義查詢,之後在緩存中再根據任務ID進行匹配。不能用任務ID查詢,因爲限制了類別爲 comment。限制 type 查詢也不行,隨着類別的增加,查詢數據庫的次數就是幾何倍增長,不推薦。
// 審覈狀態
CommentVo taskStatus = null;
// 審覈信息
CommentVo taskMessage = null;
// 審覈說明
CommentVo taskComment = null;
// 轉辦說明
List<CommentVo> transferComment = new ArrayList<>();
// 獲取並設置批註,即審覈原因,駁回原因之類的
List<Comment> commentList = taskService.getProcessInstanceComments(item.getProcessInstanceId());
// 注意,批註的順序爲時間倒序,因此按倒序取出
for (int i = commentList.size() - 1; i >= 0; i --) {
// 先判斷任務ID 相等
if (item.getTaskId().equals(commentList.get(i).getTaskId())) {
if ("taskStatus".equals(commentList.get(i).getType())) {
taskStatus = new CommentVo(commentList.get(i));
}
if ("taskMessage".equals(commentList.get(i).getType())) {
taskMessage = new CommentVo(commentList.get(i));
}
if ("taskComment".equals(commentList.get(i).getType())) {
taskComment = new CommentVo(commentList.get(i));
}
if ("transferComment".equals(commentList.get(i).getType())) {
transferComment.add(new CommentVo(commentList.get(i)));
}
}
}
附贈 CommentVo
PS:由於 fullMessage
字段保存是用 BLOB,獲取的時候出現了中文亂碼,我就改成直接獲取 message
字段了
/**
* CommentVo
* @author: linjinp
* @create: 2020-01-15 16:22
**/
@Data
public class CommentVo {
private String id;
private String processInstanceId;
private String taskId;
private Date time;
private String type;
private String userId;
private String message;
public CommentVo(){}
public CommentVo(Comment comment){
id = comment.getId();
processInstanceId = comment.getProcessInstanceId();
taskId = comment.getTaskId();
time = comment.getTime();
type = comment.getType();
userId = comment.getUserId();
message = ((CommentEntityImpl) comment).getMessage();
}
}
目前我在 Comment 上的使用
流程審覈
流程駁回
流程回退
流程轉辦
PS:主要保存轉辦歷史,因爲轉辦後還能轉給別人