activiti实战六(待办流程)

查询我的待办流程:

@Override
public AjaxJson getTodoProcessInfo(String typeCode){//typeCode是请假类型
String loginName = SessionUser.getUser().getLoginname();
String userId = SessionUser.getUser().getUserid();
List roles = processService.getRoleName(loginName);
String roleName = "";
for (Sysrole sysrole : roles) {
if ("云管理员".equals(sysrole.getRolename())) {//判断当前用户的角色
roleName = "云管理员";
break;
} else if ("超级管理员".equals(sysrole.getRolename())) {
roleName = "超级管理员";
break;
}
}
List list = taskService.createTaskQuery().taskCandidateGroup(roleName).list();//根据角色去查看可领取的任务
for (Task task : list) {
taskService.claim(task.getId(), userId);//拾取任务
}
List toDoTasks = taskService.createTaskQuery().taskAssignee(userId).orderByTaskCreateTime().desc().list();//拾取后才能查出该用户的代办流程
List leaveItems = new ArrayList<>();//待办流程显示的是业务的信息,而非真正的任务信息
for (Task task : toDoTasks) {
LeaveItem leaveItem = processService.getLeaveItemByPiId(task.getProcessInstanceId());
leaveItems.add(leaveItem);
}
AjaxJson aj = new AjaxJson();
aj.setTotalCount(leaveItems.size());
if (!StringUtils.isEmpty(typeCode)) {//根据类型筛选
for (int i = 0; i < leaveItems.size(); i++) {
if (!typeCode.equals(leaveItems.get(i).getTypeCode())) {
leaveItems.remove(i);
i--;
}
}
}
aj.setData(leaveItems);
return aj;
}

执行任务:

@Override
public void doProcess(Integer status, String replyContent, String procInstenceId) {

//前台会传status(同意还是不同意),replyContent是回复内容,procInstenceId是当前流程id
Task task = taskService.createTaskQuery().processInstanceId(procInstenceId).singleResult();查出当前任务
Map map = new HashMap<>();
map.put("status", status);//给流程图定义流程流量,让它去判断走哪条路
Authentication.setAuthenticatedUserId(SessionUser.getUser().getUserid());//添加审批人
taskService.addComment(task.getId(), procInstenceId, replyContent);//添加审批意见
taskService.complete(task.getId(), map);执行任务
LeaveItem leaveItem = processService.getLeaveItemByPiId(procInstenceId);
leaveItem.setStatus(status);//修改业务状态(审批结果)
session.saveOrUpdate(leaveItem);
}

你可能感兴趣的:(activiti实战六(待办流程))