Commit 5c3fbbda authored by neo's avatar neo

[dev] add bpmn for leave and add some controller

parent 97b1d200
package pwc.taxtech.atms.controller;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "leave")
public class LeaveController {
private static Logger logger = LoggerFactory.getLogger(LeaveController.class);
@Autowired
RuntimeService runtimeService;
@Autowired
TaskService taskService;
@Autowired
RepositoryService repositoryService;
@ResponseBody
@RequestMapping(value = "/deploy", method = RequestMethod.POST)
public ResponseEntity deploy(@RequestBody Leave user) {
repositoryService.createDeployment().addClasspathResource("bpmn/leave.bpmn").deploy();
return ResponseEntity.ok().build();
}
@ResponseBody
@RequestMapping(value = "/save", method = RequestMethod.POST)
public Leave save(@RequestBody Leave user) {
ProcessInstance pi = runtimeService.startProcessInstanceById("leaveProcess");
user.setInstaceId(pi.getId());
insert(user);//todo use service insert
return user;
}
@ResponseBody
@RequestMapping(value = "/data/{assignee}")
public List<MyTask> data(@PathVariable String assignee) {
List<Task> tasks = taskService.createTaskQuery().taskAssignee(assignee).list();
List<MyTask> list = new ArrayList<>();
for (Task task : tasks) {
MyTask t = new MyTask();
t.setTaskId(task.getId());
t.setName(task.getName());
t.setAssignee(task.getAssignee());
t.setExecutionId(task.getExecutionId());
t.setProcessInstanceId(task.getProcessInstanceId());
t.setProcessDefinitionId(task.getProcessDefinitionId());
list.add(t);
}
return list;
}
@RequestMapping(value = "/shwoImg/{procDefId}")//获取流程图
public void shwoImg(@PathVariable String procDefId, HttpServletResponse response) {
try {
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
String diagramResourceName = pd.getDiagramResourceName();
InputStream pic = repositoryService.getResourceAsStream(pd.getDeploymentId(), diagramResourceName);
byte[] b = new byte[1024];
int len = -1;
while ((len = pic.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@ResponseBody
@RequestMapping(value = "/showImg/{procDefId}/{executionId}")//获取流程坐标
public Rect showImg(@PathVariable String procDefId,@PathVariable String executionId ) {
Rect rect = new Rect();
try {
repositoryService.getProcessDefinition(procDefId);
// ActivityImpl img = Workflow.getProcessMap(procDefId,executionId );
// rect.setX(img.getX());
// rect.setY(img.getY());
// rect.setWidth(img.getWidth());
// rect.setHeight(img.getHeight());
} catch (Exception e) {
e.printStackTrace();
}
return rect;
}
@ResponseBody
@RequestMapping(value = "/check/{taskId}")
public String check(@PathVariable String taskId) {
Map<String, Object> map = new HashMap<>();
map.put("day", 3);
taskService.complete(taskId,map);
logger.debug("success ...........");
return taskId;
}
class Rect{
String X;
String Y;
String width;
String height;
public String getX() {
return X;
}
public void setX(String x) {
X = x;
}
public String getY() {
return Y;
}
public void setY(String y) {
Y = y;
}
public String getWidth() {
return width;
}
public void setWidth(String width) {
this.width = width;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
}
class MyTask {
String taskId;
String name;
String assignee;
String executionId;
String processInstanceId;
String processDefinitionId;
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAssignee() {
return assignee;
}
public void setAssignee(String assignee) {
this.assignee = assignee;
}
public String getExecutionId() {
return executionId;
}
public void setExecutionId(String executionId) {
this.executionId = executionId;
}
public String getProcessInstanceId() {
return processInstanceId;
}
public void setProcessInstanceId(String processInstanceId) {
this.processInstanceId = processInstanceId;
}
public String getProcessDefinitionId() {
return processDefinitionId;
}
public void setProcessDefinitionId(String processDefinitionId) {
this.processDefinitionId = processDefinitionId;
}
}
class Leave {
String name;
Integer day;
String leaveReason;
String instaceId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getDay() {
return day;
}
public void setDay(Integer day) {
this.day = day;
}
public String getLeaveReason() {
return leaveReason;
}
public void setLeaveReason(String leaveReason) {
this.leaveReason = leaveReason;
}
public String getInstaceId() {
return instaceId;
}
public void setInstaceId(String instaceId) {
this.instaceId = instaceId;
}
@Override
public String toString() {
return "Leave{" +
"name='" + name + '\'' +
", day=" + day +
", leaveReason='" + leaveReason + '\'' +
", instaceId='" + instaceId + '\'' +
'}';
}
}
private void insert(Leave leave) {
logger.debug("save leave info {}", leave.toString());
}
}
<?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:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/testm1539743341882" 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="m1539743341882" name="" targetNamespace="http://www.activiti.org/testm1539743341882" typeLanguage="http://www.w3.org/2001/XMLSchema">
<process id="leaveProcess" isClosed="false" isExecutable="true" name="LeaveProcess" processType="None">
<startEvent id="_2" name="StartEvent"/>
<userTask activiti:assignee="apply" activiti:exclusive="true" id="usertask1" name="请假申请"/>
<exclusiveGateway gatewayDirection="Unspecified" id="_4" name="ExclusiveGateway"/>
<userTask activiti:assignee="apply" activiti:exclusive="true" id="userTask2" name="审批(项目经理)"/>
<userTask activiti:assignee="boss" activiti:exclusive="true" id="usertask3" name="审批(?板?"/>
<endEvent id="_7" name="EndEvent"/>
<sequenceFlow id="_8" sourceRef="_2" targetRef="usertask1"/>
<sequenceFlow id="_9" name="天数判断" sourceRef="usertask1" targetRef="_4">
<documentation id="_9_D_1"/>
</sequenceFlow>
<sequenceFlow id="_10" name="小于3?" sourceRef="_4" targetRef="userTask2">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${day<=3}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="_11" name="大于3?" sourceRef="_4" targetRef="usertask3">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${day>3}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="_12" sourceRef="userTask2" targetRef="_7"/>
<sequenceFlow id="_13" sourceRef="usertask3" targetRef="_7"/>
</process>
<bpmndi:BPMNDiagram documentation="background=#FFFFFF;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="leaveProcess">
<bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
<dc:Bounds height="32.0" width="32.0" x="105.0" y="200.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="Shape-usertask1">
<dc:Bounds height="55.0" width="85.0" x="205.0" y="190.0"/>
<bpmndi:BPMNLabel>
<dc: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">
<dc:Bounds height="32.0" width="32.0" x="405.0" y="190.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="userTask2" id="Shape-userTask2">
<dc:Bounds height="55.0" width="85.0" x="605.0" y="110.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="Shape-usertask3">
<dc:Bounds height="55.0" width="85.0" x="610.0" y="295.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
<dc:Bounds height="32.0" width="32.0" x="795.0" y="240.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13" sourceElement="_6" targetElement="_7">
<di:waypoint x="695.0" y="322.5"/>
<di:waypoint x="795.0" y="256.0"/>
<bpmndi:BPMNLabel>
<dc: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="_7">
<di:waypoint x="690.0" y="137.5"/>
<di:waypoint x="795.0" y="256.0"/>
<bpmndi:BPMNLabel>
<dc: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">
<di:waypoint x="137.0" y="216.0"/>
<di:waypoint x="205.0" y="217.5"/>
<bpmndi:BPMNLabel>
<dc: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">
<di:waypoint x="290.0" y="217.5"/>
<di:waypoint x="405.0" y="206.0"/>
<bpmndi:BPMNLabel>
<dc: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">
<di:waypoint x="437.0" y="206.0"/>
<di:waypoint x="610.0" y="322.5"/>
<bpmndi:BPMNLabel>
<dc: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">
<di:waypoint x="437.0" y="206.0"/>
<di:waypoint x="605.0" y="137.5"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment