diff --git a/src/main/java/com/cm/inspection/controller/deploy/DeployController.java b/src/main/java/com/cm/inspection/controller/deploy/DeployController.java new file mode 100644 index 0000000..4a453b5 --- /dev/null +++ b/src/main/java/com/cm/inspection/controller/deploy/DeployController.java @@ -0,0 +1,118 @@ +package com.cm.inspection.controller.deploy; + +import com.alibaba.fastjson.JSONArray; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultData; +import com.cm.inspection.service.deploy.IDeployProcessService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: DemoController + * @Description: + * @Author: WangGeng + * @Date: 2020/3/24 9:41 上午 + * @Version: 1.0 + **/ +@RestController +@RequestMapping(ISystemConstant.API_PREFIX + "/deploy") +public class DeployController { + + @Autowired + private IDeployProcessService deployProcessService; + + /** + * 部署流程 + * + * @param processName + * @return + */ + @GetMapping("getdeployprocess/{processName}") + public SuccessResult getDeployProcess(@PathVariable("processName") String processName) { + return deployProcessService.deployProcess(processName); + } + + /** + * 执行流程 + * + * @param processId + * @return + */ + @GetMapping("getstartprocess/{processId}") + public SuccessResult getStartProcess(@PathVariable("processId") String processId) { + return deployProcessService.startProcess(processId); + } + + /** + * 通过代理人查看任务 + * + * @param assignee + * @return + */ + @GetMapping("listtaskbyassignee") + public JSONArray listTaskByAssignee(String assignee) { + return deployProcessService.listTaskByAssignee(assignee); + } + + /** + * 完成任务 + * + * @param taskId + * @return + */ + @GetMapping("gettaskcompletebytaskid/{taskId}") + public SuccessResult getTaskCompleteByTaskId(@PathVariable("taskId") String taskId) { + return deployProcessService.saveTaskCompleteByTaskId(taskId); + } + + @PostMapping("saveleavefulltaskcompletebytaskidanddays/{taskId}") + public SuccessResult saveLeaveFullTaskCompleteByTaskIdAndDays(@PathVariable("taskId") String taskId, @RequestParam("days") Integer days) { + return deployProcessService.saveLeaveFullTaskCompleteByTaskIdAndDays(taskId, days); + } + + /** + * 正在运行的任务 + * + * @return + */ + @GetMapping("listtask") + public JSONArray listTask() { + return deployProcessService.listTask(); + } + + /** + * 实例状态 + * + * @param processId + * @return + */ + @GetMapping("getinstancestatus/{processId}") + public SuccessResultData getInstanceStatus(@PathVariable("processId") String processId) { + return deployProcessService.getInstanceStatus(processId); + } + + /** + * 历史流程 + * + * @return + */ + @GetMapping("listhistoryprocess") + public JSONArray listHistoryProcess() { + return deployProcessService.listHistoryProcess(); + } + + /** + * 历史任务 + * + * @return + */ + @GetMapping("listhistorytask") + public JSONArray listHistoryTask() { + return deployProcessService.listHistoryTask(); + } + +} diff --git a/src/main/java/com/cm/inspection/service/deploy/IDeployProcessService.java b/src/main/java/com/cm/inspection/service/deploy/IDeployProcessService.java index c9b8ab7..3896f8d 100644 --- a/src/main/java/com/cm/inspection/service/deploy/IDeployProcessService.java +++ b/src/main/java/com/cm/inspection/service/deploy/IDeployProcessService.java @@ -1,5 +1,12 @@ package com.cm.inspection.service.deploy; +import com.alibaba.fastjson.JSONArray; +import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultData; +import org.activiti.engine.task.Task; + +import java.util.List; + /** * When you feel like quitting. Think about why you started * 当你想要放弃的时候,想想当初你为何开始 @@ -14,4 +21,23 @@ public interface IDeployProcessService { void deployProcess(); + SuccessResult deployProcess(String processName); + + SuccessResult startProcess(String processId); + + JSONArray listTaskByAssignee(String assignee); + + SuccessResult saveTaskCompleteByTaskId(String taskId); + + SuccessResult saveLeaveFullTaskCompleteByTaskIdAndDays(String taskId, Integer days); + + JSONArray listTask(); + + SuccessResultData getInstanceStatus(String processId); + + JSONArray listHistoryProcess(); + + JSONArray listHistoryTask(); + + } diff --git a/src/main/java/com/cm/inspection/service/deploy/impl/DeployProcessServiceImpl.java b/src/main/java/com/cm/inspection/service/deploy/impl/DeployProcessServiceImpl.java index 1c2352e..08f089d 100644 --- a/src/main/java/com/cm/inspection/service/deploy/impl/DeployProcessServiceImpl.java +++ b/src/main/java/com/cm/inspection/service/deploy/impl/DeployProcessServiceImpl.java @@ -1,10 +1,24 @@ package com.cm.inspection.service.deploy.impl; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultData; import com.cm.inspection.service.deploy.IDeployProcessService; import org.activiti.engine.*; +import org.activiti.engine.history.HistoricProcessInstance; +import org.activiti.engine.history.HistoricTaskInstance; +import org.activiti.engine.repository.Deployment; +import org.activiti.engine.runtime.ProcessInstance; +import org.activiti.engine.task.Task; +import org.activiti.engine.task.TaskQuery; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * When you feel like quitting. Think about why you started * 当你想要放弃的时候,想想当初你为何开始 @@ -31,6 +45,108 @@ public class DeployProcessServiceImpl implements IDeployProcessService { @Override public void deployProcess() { - repositoryService.createDeployment().addClasspathResource("bpmn/leave.bpmn").addClasspathResource("bpmn/leave.png").name("test").deploy(); + repositoryService.createDeployment().addClasspathResource("bpmn/leave.bpmn").name("test").deploy(); + } + + @Override + public SuccessResult deployProcess(String processName) { + Deployment deployment = repositoryService.createDeployment() + .disableSchemaValidation() + .addClasspathResource("bpmn/" + processName + ".bpmn").name("请假").deploy(); + System.out.println("部署ID:" + deployment.getId()); + System.out.println("部署Name:" + deployment.getName()); + return new SuccessResult(); + } + + @Override + public SuccessResult startProcess(String processId) { + ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processId); + System.out.println("流程实例id:" + processInstance.getId()); + System.out.println("流程定义id:" + processInstance.getProcessDefinitionId()); + return new SuccessResult(); + } + + @Override + public JSONArray listTaskByAssignee(String assignee) { + TaskQuery taskQuery = taskService.createTaskQuery(); + List taskList = taskQuery.taskAssignee(assignee).list(); + JSONArray jsonArray = new JSONArray(); + for (Task task : taskList) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("assignee", task.getAssignee()); + jsonObject.put("id", task.getId()); + jsonObject.put("name", task.getName()); + jsonArray.add(jsonObject); + } + return jsonArray; + } + + @Override + public SuccessResult saveTaskCompleteByTaskId(String taskId) { + taskService.complete(taskId); + return new SuccessResult(); + } + + @Override + public SuccessResult saveLeaveFullTaskCompleteByTaskIdAndDays(String taskId, Integer days) { + Map params = new HashMap<>(1); + params.put("days", days); + taskService.complete(taskId, params); + return new SuccessResult(); + } + + @Override + public JSONArray listTask() { + TaskQuery taskQuery = taskService.createTaskQuery(); + List taskList = taskQuery.list(); + JSONArray jsonArray = new JSONArray(); + for (Task task : taskList) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("assignee", task.getAssignee()); + jsonObject.put("id", task.getId()); + jsonObject.put("name", task.getName()); + jsonArray.add(jsonObject); + } + return jsonArray; + } + + @Override + public SuccessResultData getInstanceStatus(String processId) { + ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processDefinitionKey(processId).singleResult(); + return new SuccessResultData<>(processInstance == null ? 1 : 0); + } + + @Override + public JSONArray listHistoryProcess() { + List list = historyService.createHistoricProcessInstanceQuery().list(); + JSONArray jsonArray = new JSONArray(); + for (HistoricProcessInstance historicProcessInstance : list) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", historicProcessInstance.getId()); + jsonObject.put("name", historicProcessInstance.getName()); + jsonObject.put("startTime", historicProcessInstance.getStartTime()); + jsonObject.put("endTime", historicProcessInstance.getEndTime()); + jsonArray.add(jsonObject); + } + return jsonArray; + } + + @Override + public JSONArray listHistoryTask() { + List taskInstanceList = historyService.createHistoricTaskInstanceQuery().list(); + JSONArray jsonArray = new JSONArray(); + for (HistoricTaskInstance historicTaskInstance : taskInstanceList) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", historicTaskInstance.getId()); + jsonObject.put("name", historicTaskInstance.getName()); + jsonObject.put("startTime", historicTaskInstance.getStartTime()); + jsonObject.put("endTime", historicTaskInstance.getEndTime()); + jsonObject.put("processId", historicTaskInstance.getProcessDefinitionId()); + jsonObject.put("assignee", historicTaskInstance.getAssignee()); + jsonObject.put("executionId", historicTaskInstance.getExecutionId()); + jsonObject.put("parentTaskId", historicTaskInstance.getParentTaskId()); + jsonArray.add(jsonObject); + } + return jsonArray; } } diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index da2d3a4..59459a2 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -1,7 +1,7 @@ server: port: 7006 - url: http://192.168.0.113:7006/inspection - title: inspection + url: http://192.168.0.106:7006/inspection + title: 隐患上报系统 servlet: context-path: /inspection @@ -78,11 +78,11 @@ file: # 安全 security: oauth2: - oauth-server: http://192.168.0.113:7001/usercenter + oauth-server: http://192.168.0.106:7001/usercenter oauth-logout: ${security.oauth2.oauth-server}/logout?redirect_uri=${server.url} client: - client-id: 89e9c099c0a24e7f90d3cdc0447a86b3 - client-secret: VlQ1WE53RDZ6QVJLaHd2b1dGMUdEdGFjYTRhVHUyOHNpQzZoVzE3V1NDOG1ac2wwZTJHWk5NbXh3L3h3U2c4Rg== + client-id: 32ec344a5fd04fd9911586df5d1dc36b + client-secret: a2NORTAyZmthdTNtVHNwLytGVVo0ckFhNktHQU9JWVFmUks0TGw5L2hQRW1ac2wwZTJHWk5NbXh3L3h3U2c4Rg== user-authorization-uri: ${security.oauth2.oauth-server}/oauth/authorize access-token-uri: ${security.oauth2.oauth-server}/oauth/token grant-type: authorization_code diff --git a/src/main/resources/bpmn/leave.bpmn b/src/main/resources/bpmn/leave.bpmn index 330b420..7ba400f 100644 --- a/src/main/resources/bpmn/leave.bpmn +++ b/src/main/resources/bpmn/leave.bpmn @@ -12,77 +12,76 @@ name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema"> - - - - - - - - - - + + + + + + + + + + - - - + + + - - + + + + + + + + - - - - - - - - - - - - - + - - - + + + + + + + + + - - - + + + - - - + + + - - - + + + diff --git a/src/main/resources/bpmn/leave.png b/src/main/resources/bpmn/leave.png deleted file mode 100644 index 6d27a67..0000000 Binary files a/src/main/resources/bpmn/leave.png and /dev/null differ diff --git a/src/main/resources/bpmn/leavefull.bpmn b/src/main/resources/bpmn/leavefull.bpmn new file mode 100644 index 0000000..4bfdce7 --- /dev/null +++ b/src/main/resources/bpmn/leavefull.bpmn @@ -0,0 +1,118 @@ + + + + + + + + + + + + ${days <= 3} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file