目录
一、实体类
创建接收结果集的实体类。
代码如下:
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "用户查询", description = "查询用户待办、已执行、发起流程相信")
public class BasProcessInfo {
private List<String> businessKey;
@ApiModelProperty(value = "用户相关类型 0、与我相关、1、待处理、2、已处理、3、我的请求")
private String type;
}
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "用户查询", description = "查询用户待办、已执行、发起流程相信")
public class ActStatus implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "执行状态")
private String status;
private List<BasProcessInfo> basProcessInfo;
}
二、服务实现类
根据用户账号和类型查询不同的列表。
代码如下:
/**
* <p>
* 根据用户账号获取正运行流程集合
* </p >
*
* @param userCode 用户账号、
* type 查询类型、
* 1、待办的、2、已处理的、3、我发起的
* @return 流程处理及查询状态
* @author 刘易彦
* @custom.date 2024/6/29 10:35
*/
@Override
public ActStatus getBusinessKeyByUserType(String userCode, String type) {
try {
ActStatus result = new ActStatus();
List<BasProcessInfo> basProcessInfos = new ArrayList<>();
if(StringUtils.equals(type,"0")){
List<String> relatedMyprocess = this.userMapper.relatedMyprocess(userCode);
BasProcessInfo basProcessInfo = new BasProcessInfo();
basProcessInfo.setBusinessKey(relatedMyprocess);
basProcessInfo.setType("0");
basProcessInfos.add(basProcessInfo);
}
if (StringUtils.equals(type, "1")) {
//查询所有我待办的流程
List<String> map = this.userMapper.taskCandidate(userCode);
//赋值给返回结果集
List<String> collect = map.stream()
.distinct()
.collect(Collectors.toList());
BasProcessInfo basProcessInfo = new BasProcessInfo();
basProcessInfo.setBusinessKey(collect);
basProcessInfo.setType("1");
basProcessInfos.add(basProcessInfo);
}
if (StringUtils.equals(type, "2")) {
//查询所有我参与的流程
List<Map<String, Object>> maps = this.userMapper.hisTaskCandidate(userCode);
List<String> collect1 = new ArrayList<>();
//筛选所有我参与未结束的流程
if (ObjectUtils.isNotEmpty(maps)) {
//筛选出所有我参与的进行中的流程
collect1 = maps.stream().filter(a -> a.get("END_TIME_") == null).map(a -> (String) a.get("BUSINESS_KEY_")).distinct().collect(Collectors.toList());
}
BasProcessInfo basProcessInfo = new BasProcessInfo();
basProcessInfo.setBusinessKey(collect1);
basProcessInfo.setType("2");
basProcessInfos.add(basProcessInfo);
}
if (StringUtils.equals(type, "3")) {
//查询所有我发起的流程
List<ProcessInstance> list = processEngine.getRuntimeService().createProcessInstanceQuery().startedBy(userCode).list();
//查询所有我发起的未结束流程
List<String> collect1 = list.stream().map(a -> a.getBusinessKey()).distinct().collect(Collectors.toList());
BasProcessInfo basProcessInfo = new BasProcessInfo();
basProcessInfo.setBusinessKey(collect1);
basProcessInfo.setType("3");
basProcessInfos.add(basProcessInfo);
}else if(StringUtils.isEmpty(type)){
//组装类型为0的数据
List<String> relatedMyprocess = this.userMapper.relatedMyprocess(userCode);
BasProcessInfo basProcessInfo = new BasProcessInfo();
basProcessInfo.setBusinessKey(relatedMyprocess);
basProcessInfo.setType("0");
basProcessInfos.add(basProcessInfo);
//组装类型为1的数据
//查询所有我待办的流程
List<String> map = this.userMapper.taskCandidate(userCode);
//赋值给返回结果集
List<String> collect = map.stream()
.distinct()
.collect(Collectors.toList());
BasProcessInfo basProcessInfo1 = new BasProcessInfo();
basProcessInfo1.setBusinessKey(collect);
basProcessInfo1.setType("1");
basProcessInfos.add(basProcessInfo1);
//组装类型为2的数据
//查询所有我参与的流程
List<Map<String, Object>> maps = this.userMapper.hisTaskCandidate(userCode);
List<String> collect1 = new ArrayList<>();
//筛选所有我参与未结束的流程
if (ObjectUtils.isNotEmpty(maps)) {
//筛选出所有我参与的进行中的流程
collect1 = maps.stream().filter(a -> a.get("END_TIME_") == null).map(a -> (String) a.get("BUSINESS_KEY_")).distinct().collect(Collectors.toList());
}
BasProcessInfo basProcessInfo2 = new BasProcessInfo();
basProcessInfo2.setBusinessKey(collect1);
basProcessInfo2.setType("2");
basProcessInfos.add(basProcessInfo2);
//组装类型为3的数据
//查询所有我发起的流程
List<ProcessInstance> list = processEngine.getRuntimeService().createProcessInstanceQuery().startedBy(userCode).list();
//查询所有我发起的未结束流程
List<String> collect2 = list.stream().map(a -> a.getBusinessKey()).distinct().collect(Collectors.toList());
BasProcessInfo basProcessInfo3 = new BasProcessInfo();
basProcessInfo3.setBusinessKey(collect2);
basProcessInfo3.setType("3");
basProcessInfos.add(basProcessInfo3);
}
result.setBasProcessInfo(basProcessInfos);
result.setStatus(ActivitiConstants.MYQUERY_SUCCESS);
return result;
}catch (Exception e){
ActStatus result = new ActStatus();
result.setStatus(ActivitiConstants.MYQUERY_FAIL);
return result;
}
}
三、数据访问层
查询activiti表的数据。
代码如下:
<select id="relatedMyprocess" resultType="String">
SELECT DISTINCT
a.BUSINESS_KEY_
FROM
ACT_HI_PROCINST a,
(
SELECT DISTINCT
RES.*
FROM
ACT_HI_TASKINST RES
INNER JOIN ACT_HI_IDENTITYLINK HI ON HI.TASK_ID_ = RES.ID_
WHERE
HI.USER_ID_ = #{userId}
OR RES.ASSIGNEE_ = #{userId}
ORDER BY
RES.ID_ ASC
) b
WHERE
a.PROC_INST_ID_ = b.PROC_INST_ID_ or a.START_USER_ID_ = #{userId}
</select>
<select id="taskCandidate" resultType="String">
SELECT
a.BUSINESS_KEY_
FROM
ACT_RU_EXECUTION a,
(
SELECT DISTINCT
RES.*
FROM
ACT_RU_TASK RES
INNER JOIN ACT_RU_IDENTITYLINK I ON I.TASK_ID_ = RES.ID_
WHERE
(I.USER_ID_ = #{userId})
ORDER BY
RES.ID_ ASC
) b
WHERE
a.PROC_INST_ID_ = b.PROC_INST_ID_
AND a.BUSINESS_KEY_ IS NOT NULL
</select>
<select id="hisTaskCandidate" resultType="map">
SELECT
a.*
FROM
ACT_HI_PROCINST a,
(
SELECT DISTINCT
RES.*
FROM
ACT_HI_TASKINST RES
INNER JOIN ACT_HI_IDENTITYLINK HI ON HI.TASK_ID_ = RES.ID_
WHERE
RES.ASSIGNEE_ IS NOT NULL
AND RES.END_TIME_ IS NOT NULL
AND (HI.USER_ID_ = #{userId})
ORDER BY
RES.ID_ ASC
) b
WHERE
a.PROC_INST_ID_ = b.PROC_INST_ID_
</select>
标签:activiti,RES,basProcessInfo,List,列表,待办,BasProcessInfo,new,ID
From: https://blog.csdn.net/milk_yan/article/details/143584880