java代码:
/**
* 我的参与
* @param paramVO
* @param pn
* @param ps
* @return
* @throws IOException
*/
@SieMethodOperation(code = "attendance.myProcess.participateList.search" , name = "考勤服务我的参与查询",type = "search",url= "/process/pt")
@PostMapping(value = "/process/pt/{pn}/{ps}")
@ResponseBody
public PageResultVO processParticipateList(@RequestBody MyProcessParamVO paramVO, @PathVariable Integer pn, @PathVariable Integer ps) throws IOException, ParseException {
//权限
//String url = "/process/pt";
//if(attendanceService.CheckUrlByUserId(url)) return new ResultVO(GlobalReturnCode.AUTHORITY_ILLEGAL_CODE,"AUTHORITY_ILLEGAL");
//通过userId获取中文名
String userId = SecurityUtils.getCurrentUserLogin();
if(null == userId || userId.isEmpty()) return new PageResultVO(GlobalReturnCode.PARAM_NULL_CODE,"PARAM_NULL");
//设置参数
if(null == paramVO.getTitle() || paramVO.getTitle().isEmpty()){
paramVO.setTitle("%");
}else {
paramVO.setTitle("%" + paramVO.getTitle() + "%");
}
//初始化记录list
List<String> record = new ArrayList<String>();
//初始化
List<ProcessMyCommonVO> dataList = new ArrayList<ProcessMyCommonVO>();
//初始化清单
List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery()
.taskAssignee(userId)
.processInstanceId(paramVO.getInstanceId())
.finished()
.listPage(pn * ps,ps);
long count = historyService.createHistoricTaskInstanceQuery()
.taskAssignee(userId)
.finished()
.count();
for(HistoricTaskInstance task : list){
//判断是否存在
if(!record.contains(task.getProcessInstanceId())){
//初始化流程信息
HistoricProcessInstance historic = historyService
.createHistoricProcessInstanceQuery()
.processInstanceId(task.getProcessInstanceId())
.variableValueLike("title",paramVO.getTitle())
.startedAfter(null == paramVO.getStart() ? null : DtmStringFormat.strYmdToDate(paramVO.getStart()))
.startedBefore(null == paramVO.getEnd() ? null : DtmStringFormat.strYmdToDate(paramVO.getEnd()))
.singleResult();
if(null != historic){
//初始化
ProcessMyCommonVO processVO = new ProcessMyCommonVO(task.getProcessInstanceId(),
historyService.createHistoricVariableInstanceQuery().processInstanceId(historic.getId()).variableName("appName").singleResult().getValue().toString(),
AttendanceUtil.resolveTypeByBusinessKey(historic.getBusinessKey()),
historic.getBusinessKey(),
historyService.createHistoricVariableInstanceQuery().processInstanceId(historic.getId()).variableName("instanceFormType").singleResult().getValue().toString(),
historyService.createHistoricVariableInstanceQuery().processInstanceId(task.getProcessInstanceId()).variableName("title").singleResult().getValue().toString(),
historic.getStartUserId(),
sendGet(UrlConstant.GET_ZHNAME_BY_UID+historic.getStartUserId(),null),
DtmStringFormat.dateTimeToStrYmdHms(historic.getStartTime()),
null
);
//设置状态
if("completed".equals(historic.getState().toLowerCase())){
processVO.setWfState("completed");
}else if("active".equals(historic.getState().toLowerCase())){
List<Task> tasks = taskService.createTaskQuery().processInstanceId(historic.getId()).list();
for(Task ts : tasks){
if("Task_reject".equals(ts.getTaskDefinitionKey())){
if("reject".equals(runtimeService.createVariableInstanceQuery().processInstanceIdIn(historic.getId()).variableName("operate").singleResult().getValue().toString())){
processVO.setWfState("rejected");
//获取驳回原因
HistoricVariableInstance hVars = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(historic.getId())
.variableName("opinion")
.singleResult();
processVO.setOpinion(null == hVars.getValue() ? "" : hVars.getValue().toString());
}else {
processVO.setWfState("cancel");
}
}else {
processVO.setWfState("active");
}
}
}
dataList.add(processVO);
}
//添加key值
record.add(task.getProcessInstanceId());
}
}
//按照时间排序
return new PageResultVO(GlobalReturnCode.SUCCESS_CODE, "SUCCESS",ps,pn,(int)count,AttendanceUtil.processSortByStartDateDesc(dataList));
}
/**
* 初始化活动流程信息
* @param historic
* @param task
* @param processVO
*/
private void initActiveProcessInfo(HistoricProcessInstance historic, Task task, ProcessMyCommonVO processVO) {
if("Task_reject".equals(taskService.createTaskQuery()
.taskId(task.getId())
.singleResult()
.getTaskDefinitionKey())){
//获取操作类型
if("reject".equals(runtimeService.createVariableInstanceQuery().processInstanceIdIn(historic.getId()).variableName("operate").singleResult().getValue().toString())){
//获取驳回原因
VariableInstance tVars = runtimeService.createVariableInstanceQuery()
.processInstanceIdIn(historic.getId())
.variableName("opinion")
.singleResult();
processVO.setOpinion(null == tVars.getValue() ? "" : tVars.getValue().toString());
processVO.setWfState("rejected");
}else {
processVO.setWfState("cancel");
}
}else {
processVO.setWfState("active");
}
}复制代码
界面示例: