由于公司系统使用的是mybatis-plus操作数据库,研究flowable提供API封装不太好用,故分析最终执行的SQL,进行mybatis.xml改写;此处实现了查询流程定义,我的流程,我的待办,我的已办,流程日志等连表sql;
说明:系统中没有用 flowable用户表 act_id_user,用了自定义用户表 p_project_user。
1. 查询流程定义列表
Page selectDefinitionList(Page page, String tenantId);
SELECT RES.ID_ as DEFINITION_ID_, RES.KEY_ as process_key, RES.NAME_ as process_name, RES.CATEGORY_, f.form_id, f.form_name,
RES.SUSPENSION_STATE_, RES.DEPLOYMENT_ID_, d.DEPLOY_TIME_ as deployment_time, RES.VERSION_
from ACT_RE_PROCDEF RES
left join ACT_RE_DEPLOYMENT d on d.ID_=RES.DEPLOYMENT_ID_
left join p_wf_deploy_form f on f.deploy_id=RES.DEPLOYMENT_ID_
WHERE 1=1
and RES.TENANT_ID_ = #{tenantId}
and RES.VERSION_ = (select max(VERSION_) from ACT_RE_PROCDEF where KEY_ = RES.KEY_ and TENANT_ID_ = #{tenantId})
order by RES.KEY_ asc
2.查询已发布的流程版本列表
Page selectPublishList(Page page, String processKey);
SELECT ID_ as definition_id, KEY_ as process_key, NAME_ as process_name, CATEGORY_, VERSION_, DEPLOYMENT_ID_, SUSPENSION_STATE_ from ACT_RE_PROCDEF WHERE KEY_ = #{processKey} order by VERSION_ asc
3. 查询用户发起流程列表
Page selectOwnList(Page page, String userId);
SELECT p.NAME_ as PROC_DEF_NAME_, t.ACT_NAME_, p.PROC_INST_ID_, p.PROC_DEF_ID_, d.KEY_ as PROC_DEF_KEY_, d.DEPLOYMENT_ID_,
u.user_name as start_user_name, p.BUSINESS_KEY_, p.BUSINESS_STATUS_, p.START_TIME_, p.END_TIME_, p.DURATION_
from (
SELECT PROC_INST_ID_, ACT_NAME_, END_TIME_ FROM ACT_HI_ACTINST
WHERE START_TIME_ IN(SELECT MAX(START_TIME_) FROM ACT_HI_ACTINST GROUP BY PROC_INST_ID_)
) as t
left join ACT_HI_PROCINST p on t.PROC_INST_ID_=p.PROC_INST_ID_
left join ACT_RE_PROCDEF d on p.PROC_DEF_ID_ = d.ID_
left join p_project_user u on u.id=p.START_USER_ID_
WHERE p.DELETE_REASON_ IS NULL and p.START_USER_ID_=#{userId}
order by p.START_TIME_ desc
4.查询用户待办任务列表
Page selectTodoList(Page page, String userId);
SELECT RES.ID_, p.NAME_ as proc_def_name, RES.PROC_INST_ID_, RES.PROC_DEF_ID_, pd.KEY_ as PROC_DEF_KEY_,
RES.NAME_ as task_name, p.START_USER_ID_, u.user_name as start_user_name, RES.CREATE_TIME_, p.BUSINESS_KEY_, p.BUSINESS_STATUS_
from ACT_RU_TASK RES
left join ACT_RE_PROCDEF as pd on pd.ID_=RES.PROC_DEF_ID_
left join ACT_HI_PROCINST p on p.PROC_INST_ID_=RES.PROC_INST_ID_
left join act_ru_identitylink lk on lk.TASK_ID_ = RES.ID_
left join p_project_user u on u.id=p.START_USER_ID_
WHERE RES.SUSPENSION_STATE_ = 1
AND RES.ASSIGNEE_=#{userId}
OR lk.USER_ID_ = #{userId}
OR lk.GROUP_ID_ in (select concat('ROLE', id_group_id) from p_wf_id_group2user where user_id=#{userId})
order by RES.CREATE_TIME_ desc
5.查询用户已办任务列表-同一个流程查询用户所有相关记录
Page selectFinishedList(Page page, @Param("ew") FinishedListQueryModel queryModel);
SELECT t.PROC_INST_ID_, t.PROC_DEF_ID_, p.NAME_ as PROC_DEF_NAME_, t.ASSIGNEE_, t.NAME_ as task_name,
u.user_name as start_user_name, p.BUSINESS_KEY_, p.BUSINESS_STATUS_, c.TYPE_, t.START_TIME_, t.END_TIME_, t.DURATION_
from ACT_HI_TASKINST t
left join ACT_HI_COMMENT c on c.TASK_ID_=t.id_
left join ACT_HI_PROCINST p on p.PROC_INST_ID_=t.PROC_INST_ID_
left join p_project_user u on u.id=p.START_USER_ID_
WHERE c.ACTION_='AddComment' and t.ASSIGNEE_=#{ew.userId}
AND p.NAME_ like '%${ew.procDefName}%'
AND u.user_name like '%${ew.startUserName}%'
= #{ew.startDate}]]>
order by t.END_TIME_ desc
6.查询用户已办任务-同一个流程只保留用户最新一条记录
Page selectFinishedListByLatestOne(Page page, @Param("ew") FinishedListQueryModel queryModel);
select t2.*
from (SELECT p.BUSINESS_KEY_, max(t.END_TIME_) as END_TIME_
from ACT_HI_TASKINST t
left join ACT_HI_PROCINST p on p.PROC_INST_ID_=t.PROC_INST_ID_
left join p_project_user u on u.id=p.START_USER_ID_
left join ACT_HI_COMMENT c on c.TASK_ID_=t.id_
WHERE c.ACTION_='AddComment' and t.ASSIGNEE_=#{ew.userId}
group by p.BUSINESS_KEY_ ) as t1
inner join (
SELECT t.PROC_INST_ID_, t.PROC_DEF_ID_, p.NAME_ as PROC_DEF_NAME_, t.ASSIGNEE_, t.NAME_ as task_name,
u.user_name as start_user_name, p.BUSINESS_KEY_, p.BUSINESS_STATUS_, c.TYPE_, t.START_TIME_, t.END_TIME_, t.DURATION_
from ACT_HI_TASKINST t
left join ACT_HI_PROCINST p on p.PROC_INST_ID_=t.PROC_INST_ID_
left join p_project_user u on u.id=p.START_USER_ID_
left join ACT_HI_COMMENT c on c.TASK_ID_=t.id_
WHERE c.ACTION_='AddComment' and t.ASSIGNEE_=#{ew.userId}
) as t2 on t1.BUSINESS_KEY_=t2.BUSINESS_KEY_ and t1.END_TIME_=t2.END_TIME_
AND t2.PROC_DEF_NAME_ like '%${ew.procDefName}%'
AND t2.start_user_name like '%${ew.startUserName}%'
= #{ew.startDate}]]>
order by t2.END_TIME_ desc
7.查询流程日志列表
List selectWfTaskLogVOList(String procInstId);
SELECT RES.ID_ as task_id, RES.TASK_DEF_KEY_, RES.NAME_ as task_name, RES.START_TIME_, RES.END_TIME_,
RES.DURATION_ as duration_time, RES.ASSIGNEE_ as assignee_id, u.user_name as assignee_name, c.TYPE_, c.MESSAGE_
from ACT_HI_TASKINST RES
left join act_hi_comment c on c.TASK_ID_=RES.id_
left join p_project_user u on u.id=RES.ASSIGNEE_
WHERE c.ACTION_='AddComment' and RES.PROC_INST_ID_ = #{procInstId}
order by RES.START_TIME_ desc