Flowable 快速入门教程:通过 Comment 保存审核信息

前言

先说下本人为什么使用 Comment 来保存审核信息

  1. 自然因为简单,不需要自己额外建表保存(本人懒汉)
  2. 由于本人项目这使用的是微服务架构,流程引擎单独一个数据库,其他数据其他库。但不管在哪建表,查询后也需要自己对数据整合,比较麻烦(本人懒汉)
  3. 就目前而言,个人觉得 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 类别

  1. taskStatus:审核状态
  2. taskMessage:审核结果
  3. 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:主要保存转办历史,因为转办后还能转给别人
在这里插入图片描述
在这里插入图片描述

效果图

在这里插入图片描述

发布了107 篇原创文章 · 获赞 414 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/qq_37143673/article/details/104357336
今日推荐