1. 说明
在案例5的基础上进行完善,案例5,点击打开
2. 案例6
2.1 对比案例5,增加的内容(后台IDEA)
把自定义用户信息同步到activiti数据库用户,用户组中,具体参考。
对比案例5,流程图增加了一个人事部归档节点,这个节点设置为组任务,属于该组的都可以看到,并且办理任务,一个人办理完成任务结束。
Bpmn文件
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1596608849637" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
<process id="leave" isClosed="false" isExecutable="true" processType="None">
<startEvent id="_2" name="开始"/>
<userTask activiti:assignee="${inputUser}" activiti:exclusive="true" id="_3" name="填写请假单">
<extensionElements>
<activiti:taskListener class="com.yb.listener.MyCompeteistener" event="create"/>
</extensionElements>
</userTask>
<exclusiveGateway gatewayDirection="Unspecified" id="_4" name="排他网关"/>
<userTask activiti:assignee="王大" activiti:exclusive="true" id="_5" name="总经理审批"/>
<userTask activiti:assignee="${assignee}" activiti:exclusive="true" id="_6" name="项目经理审批">
<extensionElements>
<activiti:taskListener class="com.yb.listener.MutiGroupsListener" event="create"/>
</extensionElements>
<multiInstanceLoopCharacteristics activiti:collection="${assignees}" activiti:elementVariable="assignee" isSequential="false">
<completionCondition><![CDATA[${
passCount/totalCount==1}]]></completionCondition>
</multiInstanceLoopCharacteristics>
</userTask>
<endEvent id="_7" name="结束"/>
<sequenceFlow id="_8" sourceRef="_2" targetRef="_3"/>
<sequenceFlow id="_9" sourceRef="_3" targetRef="_4"/>
<sequenceFlow id="_10" name="大于三天" sourceRef="_4" targetRef="_5">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${
day>3}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="_11" name="小于三天" sourceRef="_4" targetRef="_6">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${
day<=3}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="_12" sourceRef="_5" targetRef="_14"/>
<sequenceFlow id="_13" name="都同意" sourceRef="_6" targetRef="_14">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${
passCount/totalCount==1}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="_15" name="都不同意" sourceRef="_6" targetRef="_3">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${
passCount/totalCount==0}]]></conditionExpression>
</sequenceFlow>
<userTask activiti:candidateGroups="group5" activiti:exclusive="true" id="_14" name="人事部归档"/>
<sequenceFlow id="_18" sourceRef="_14" targetRef="_7"/>
</process>
<bpmndi:BPMNDiagram documentation="background=#000000;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
<bpmndi:BPMNPlane bpmnElement="leave">
<bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="345.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
<omgdc:Bounds height="55.0" width="85.0" x="90.0" y="335.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4" isMarkerVisible="false">
<omgdc:Bounds height="32.0" width="32.0" x="250.0" y="345.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5">
<omgdc:Bounds height="55.0" width="85.0" x="375.0" y="280.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_6" id="Shape-_6">
<omgdc:Bounds height="55.0" width="85.0" x="370.0" y="415.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
<omgdc:Bounds height="32.0" width="32.0" x="780.0" y="360.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_14" id="Shape-_14">
<omgdc:Bounds height="55.0" width="85.0" x="600.0" y="350.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13" sourceElement="_6" targetElement="_14">
<omgdi:waypoint x="470.0" y="442.5"/>
<omgdi:waypoint x="600.0" y="377.5"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="_5" targetElement="_14">
<omgdi:waypoint x="460.0" y="307.5"/>
<omgdi:waypoint x="600.0" y="377.5"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_15" id="BPMNEdge__15" sourceElement="_6" targetElement="_3">
<omgdi:waypoint x="412.5" y="470.0"/>
<omgdi:waypoint x="225.0" y="495.0"/>
<omgdi:waypoint x="132.5" y="390.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_18" id="BPMNEdge__18" sourceElement="_14" targetElement="_7">
<omgdi:waypoint x="685.0" y="377.5"/>
<omgdi:waypoint x="780.0" y="376.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_2" targetElement="_3">
<omgdi:waypoint x="32.0" y="361.0"/>
<omgdi:waypoint x="90.0" y="362.5"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9" sourceElement="_3" targetElement="_4">
<omgdi:waypoint x="175.0" y="362.5"/>
<omgdi:waypoint x="250.0" y="361.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="_4" targetElement="_6">
<omgdi:waypoint x="282.0" y="361.0"/>
<omgdi:waypoint x="370.0" y="442.5"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10" sourceElement="_4" targetElement="_5">
<omgdi:waypoint x="282.0" y="361.0"/>
<omgdi:waypoint x="375.0" y="307.5"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
增加人事部归档功能
该功能是组任务,属于该组的人员都可以查看和办理。
ServiceImpl
package com.yb.service.impl;
import com.yb.common.BaseResult;
import com.yb.dao.ActRuTaskDao;
import com.yb.dao.LeaveRepository;
import com.yb.domain.ActRuTask;
import com.yb.domain.Leave;
import com.yb.domain.User;
import com.yb.service.FileService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.task.Task;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* @author [email protected]
* @version 1.0
* @date 2020/8/19
*/
@Service
public class FileServiceImpl implements FileService {
@Resource
private RepositoryService repositoryService;
@Resource
private RuntimeService runtimeService;
@Resource
private TaskService taskService;
@Resource
private IdentityService identityService;
@Resource
private HttpServletRequest request;
@Resource
private ActRuTaskDao actRuTaskDao;
/**
* 归档
* @param leave
* @return
*/
@Override
public BaseResult File(Leave leave) {
try {
User user = (User) request.getServletContext().getAttribute("user");
System.out.println("归档:"+leave);
Task task = taskService.createTaskQuery()
.taskName("人事部归档")
.singleResult();
taskService.claim(task.getId(),user.getUsername());
//归档后更改申请人的状态为已归档
Leave leave1 = searchLeave(task.getProcessInstanceId());
leaveRepository.updateStateByNameS(5,leave1.getName());
//提交任务
String id = taskService.createTaskQuery().taskAssignee(user.getUsername()).singleResult().getId();
taskService.complete(id);
return BaseResult.ok("归档成功");
} catch (Exception e) {
e.printStackTrace();
return BaseResult.error("服务器繁忙");
}
}
/**
* 查询归档待办
* @return
*/
@Override
public BaseResult queryTask() {
User user2 = (User) request.getServletContext().getAttribute("user");
List<Task> list = taskService.createTaskQuery()
.taskName("人事部归档")
.list();
for (Task task : list) {
System.out.println("--------------------------------------------");
System.out.println("任务ID:" + task.getId());
System.out.println("任务名称:" + task.getName());
System.out.println("任务创建时间:" + task.getCreateTime());
System.out.println("任务委派人:" + task.getAssignee());
System.out.println("流程实例ID:" + task.getProcessInstanceId());
System.out.println("--------------------------------------------");
// taskService.complete(task.getId());
List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(task.getId());
for (IdentityLink identityLink : identityLinksForTask) {
System.out.println(identityLink.getGroupId());
//查询属于组group5的用户
List<org.activiti.engine.identity.User> usersInGroup = identityService.createUserQuery()
.memberOfGroup(identityLink.getGroupId())
.list();
for (org.activiti.engine.identity.User user : usersInGroup) {
System.out.println(user.getFirstName());
// 这一步可根据当前登录的用户判断是否属于人事
if(user.getFirstName().equals(user2.getUsername())){
List<ActRuTask> listTask = actRuTaskDao.findActRuTasksByAndName("人事部归档");
//查询需要归档的请假单信息
Leave leave = searchLeave(task.getProcessInstanceId());
return BaseResult.ok("查询成功",listTask).append("leave",leave);
}
}
}
}
return BaseResult.error("服务器繁忙");
}
@Resource
private LeaveRepository leaveRepository;
/**
* 获取请假单信息
* @param procInstId
* @return
*/
public Leave searchLeave(String procInstId){
Map<String, Object> variables = runtimeService.getVariables(procInstId);
//inputUser是办理请假单任务的人,获取到的信息存进请假单业务类中返回
for (Map.Entry<String, Object> entry : variables.entrySet()) {
if(entry.getKey().equals("inputUser")){
List<Leave> byName = leaveRepository.findByName((String) entry.getValue());
for (Leave l : byName) {
if(l.getState()==1){
return l;
}
}
}
}
return null;
}
}
2.2 对比案例5,增加的内容(前台VUE)
对比案例5增加了人事归档功能,该功能由人事部人员办理,人事部人员都可以查看办理,一人办理完成,该任务就归档结束
数据库:
未办理前:
前台未点击归档进行办理时,是没有分配人员的,这时候属于人事组的所有人员都可以看到该任务。
办理后:
点击归档办理,就为设置当前登录用户为当前归档任务办理人,并且办理任务进行归档,任务完成,数据库运行时任务表中信息消失,流程结束。
流程结束: