Browse Source

流程收尾

test
smallchill 6 years ago
parent
commit
e0271ead13
  1. 12
      blade-service-api/blade-dict-api/src/main/java/org/springblade/system/cache/DictCache.java
  2. 15
      blade-service-api/blade-flow-api/src/main/java/org/springblade/flowable/core/entity/BladeFlow.java
  3. 3
      blade-service-api/blade-flow-api/src/main/java/org/springblade/flowable/core/feign/IFlowClient.java
  4. 9
      blade-service-api/blade-flow-api/src/main/java/org/springblade/flowable/core/feign/IFlowClientFallback.java
  5. 7
      blade-service/blade-desk/src/main/java/org/springblade/desk/controller/LeaveController.java
  6. 3
      blade-service/blade-desk/src/main/java/org/springblade/desk/service/ILeaveService.java
  7. 8
      blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/LeaveServiceImpl.java
  8. 106
      blade-service/blade-flow/src/main/java/org/springblade/flowable/business/controller/LeaveController.java
  9. 8
      blade-service/blade-flow/src/main/java/org/springblade/flowable/business/feign/FlowClient.java
  10. 19
      blade-service/blade-flow/src/main/java/org/springblade/flowable/business/handler/BossTaskHandler.java
  11. 18
      blade-service/blade-flow/src/main/java/org/springblade/flowable/business/handler/ManagerTaskHandler.java
  12. 32
      blade-service/blade-flow/src/main/java/org/springblade/flowable/business/service/impl/FlowBusinessServiceImpl.java
  13. 4
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java
  14. 4
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/utils/FlowCache.java
  15. 10
      blade-service/blade-flow/src/main/resources/processes/LeaveProcess.bpmn20.xml

12
blade-service-api/blade-dict-api/src/main/java/org/springblade/system/utils/DictUtil.java → blade-service-api/blade-dict-api/src/main/java/org/springblade/system/cache/DictCache.java vendored

@ -1,4 +1,4 @@
package org.springblade.system.utils;
package org.springblade.system.cache;
import org.springblade.core.cache.constant.CacheConstant;
import org.springblade.core.cache.utils.CacheUtil;
@ -12,13 +12,17 @@ import org.springblade.system.feign.IDictClient;
import java.util.List;
/**
* DictUtil
* DictCache
*
* @author Chill
*/
public class DictUtil {
public class DictCache {
private static IDictClient dictClient = SpringUtil.getBean(IDictClient.class);
private static IDictClient dictClient;
static {
dictClient = SpringUtil.getBean(IDictClient.class);
}
/**
* 获取字典值

15
blade-service-api/blade-flow-api/src/main/java/org/springblade/flowable/core/entity/BladeFlow.java

@ -145,9 +145,13 @@ public class BladeFlow implements Serializable {
*/
private String comment;
/**
* 是否继续
* 是否通过
*/
private boolean isPass;
/**
* 是否通过代号
*/
private String flag;
/**
* 批复名
*/
@ -169,7 +173,14 @@ public class BladeFlow implements Serializable {
* 获取批复名
*/
public String getPassComment() {
return this.isPass ? ProcessConstant.PASS_COMMENT : ProcessConstant.NOT_PASS_COMMENT;
return isPass() ? ProcessConstant.PASS_COMMENT : ProcessConstant.NOT_PASS_COMMENT;
}
/**
* 获取是否通过
*/
public boolean isPass() {
return "ok".equals(flag);
}
}

3
blade-service-api/blade-flow-api/src/main/java/org/springblade/flowable/core/feign/IFlowClient.java

@ -69,12 +69,11 @@ public interface IFlowClient {
*
* @param taskId 任务id
* @param processInstanceId 流程实例id
* @param title 任务标题
* @param comment 评论
* @param variables 参数
* @return R
*/
@PostMapping(COMPLETE_TASK)
R completeTask(@RequestParam("taskId") String taskId, @RequestParam("processInstanceId") String processInstanceId, @RequestParam("title") String title, @RequestParam("comment") String comment, @RequestBody Map<String, Object> variables);
R completeTask(@RequestParam("taskId") String taskId, @RequestParam("processInstanceId") String processInstanceId, @RequestParam("comment") String comment, @RequestBody Map<String, Object> variables);
}

9
blade-service-api/blade-flow-api/src/main/java/org/springblade/flowable/core/feign/IFlowClientFallback.java

@ -32,16 +32,17 @@ public class IFlowClientFallback implements IFlowClient {
@Override
public R<BladeFlow> startProcessInstanceById(String processDefinitionId, String businessKey, Map<String, Object> variables) {
return null;
return R.fail("远程调用失败");
}
@Override
public R<BladeFlow> startProcessInstanceByKey(String processDefinitionKey, String businessKey, Map<String, Object> variables) {
return null;
return R.fail("远程调用失败");
}
@Override
public R completeTask(String taskId, String processInstanceId, String title, String comment, Map<String, Object> variables) {
return null;
public R completeTask(String taskId, String processInstanceId, String comment, Map<String, Object> variables) {
return R.fail("远程调用失败");
}
}

7
blade-service/blade-desk/src/main/java/org/springblade/desk/controller/LeaveController.java

@ -22,6 +22,7 @@ import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.desk.entity.ProcessLeave;
import org.springblade.desk.service.ILeaveService;
import org.springblade.flowable.core.entity.BladeFlow;
import org.springblade.system.user.cache.UserCache;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
@ -65,11 +66,11 @@ public class LeaveController extends BladeController implements CacheNames {
/**
* 完成任务
*
* @param leave 请假信息
* @param flow 请假信息
*/
@PostMapping("complete-task")
public R completeTask(@RequestBody ProcessLeave leave) {
return R.status(leaveService.completeTask(leave));
public R completeTask(@RequestBody BladeFlow flow) {
return R.status(leaveService.completeTask(flow));
}
}

3
blade-service/blade-desk/src/main/java/org/springblade/desk/service/ILeaveService.java

@ -18,6 +18,7 @@ package org.springblade.desk.service;
import org.springblade.core.mp.base.BaseService;
import org.springblade.desk.entity.ProcessLeave;
import org.springblade.flowable.core.entity.BladeFlow;
/**
* 服务类
@ -40,6 +41,6 @@ public interface ILeaveService extends BaseService<ProcessLeave> {
* @param leave 请假信息
* @return boolean
*/
boolean completeTask(ProcessLeave leave);
boolean completeTask(BladeFlow leave);
}

8
blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/LeaveServiceImpl.java

@ -77,10 +77,8 @@ public class LeaveServiceImpl extends BaseServiceImpl<LeaveMapper, ProcessLeave>
}
@Override
public boolean completeTask(ProcessLeave leave) {
BladeFlow flow = leave.getFlow();
flow.setComment(flow.getPassComment());
return false;
public boolean completeTask(BladeFlow flow) {
R result = flowClient.completeTask(flow.getTaskId(), flow.getProcessInstanceId(), flow.getPassComment(), Kv.create().set("pass", flow.isPass()));
return result.isSuccess();
}
}

106
blade-service/blade-flow/src/main/java/org/springblade/flowable/business/controller/LeaveController.java

@ -1,106 +0,0 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.flowable.business.controller;
import lombok.AllArgsConstructor;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.List;
/**
* 报销控制器
*
* @author Chill
*/
@Controller
@AllArgsConstructor
@RequestMapping(value = "leave")
public class LeaveController {
private RuntimeService runtimeService;
private TaskService taskService;
/**
* 添加报销
*
* @param userId 用户Id
* @param money 报销金额
* @param descption 描述
*/
@RequestMapping(value = "add")
@ResponseBody
public String addExpense(String userId, Integer money, String descption) {
//启动流程
HashMap<String, Object> map = new HashMap<>();
map.put("taskUser", userId);
map.put("money", money);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Expense", map);
return "提交成功.流程Id为:" + processInstance.getId();
}
/**
* 获取审批管理列表
*/
@RequestMapping(value = "/list")
@ResponseBody
public Object list(String userId) {
List<Task> tasks = taskService.createTaskQuery().taskAssignee(userId).orderByTaskCreateTime().desc().list();
for (Task task : tasks) {
System.out.println(task.toString());
}
return tasks.toArray().toString();
}
/**
* 批准
*
* @param taskId 任务ID
*/
@RequestMapping(value = "apply")
@ResponseBody
public String apply(String taskId) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task == null) {
throw new RuntimeException("流程不存在");
}
//通过审核
HashMap<String, Object> map = new HashMap<>();
map.put("outcome", "通过");
taskService.complete(taskId, map);
return "processed ok!";
}
/**
* 拒绝
*/
@ResponseBody
@RequestMapping(value = "reject")
public String reject(String taskId) {
HashMap<String, Object> map = new HashMap<>();
map.put("outcome", "驳回");
taskService.complete(taskId, map);
return "reject";
}
}

8
blade-service/blade-flow/src/main/java/org/springblade/flowable/business/feign/FlowClient.java

@ -62,7 +62,7 @@ public class FlowClient implements IFlowClient {
@Override
@PostMapping(START_PROCESS_INSTANCE_BY_KEY)
public R<BladeFlow> startProcessInstanceByKey(String processDefinitionKey, String businessKey, Map<String, Object> variables) {
public R<BladeFlow> startProcessInstanceByKey(String processDefinitionKey, String businessKey, @RequestBody Map<String, Object> variables) {
// 设置流程启动用户
identityService.setAuthenticatedUserId(String.valueOf(SecureUtil.getUserId()));
// 开启流程
@ -75,7 +75,7 @@ public class FlowClient implements IFlowClient {
@Override
@PostMapping(COMPLETE_TASK)
public R completeTask(String taskId, String processInstanceId, String title, String comment, Map<String, Object> variables) {
public R completeTask(String taskId, String processInstanceId, String comment, @RequestBody Map<String, Object> variables) {
// 增加评论
if (StringUtil.isNoneBlank(processInstanceId, comment)) {
taskService.addComment(taskId, processInstanceId, comment);
@ -84,10 +84,6 @@ public class FlowClient implements IFlowClient {
if (Func.isEmpty(variables)) {
variables = Kv.create();
}
// 增加标题
if (StringUtil.isNotBlank(title)) {
variables.put("title", title);
}
// 完成任务
taskService.complete(taskId, variables);
return R.success("流程提交成功");

19
blade-service/blade-flow/src/main/java/org/springblade/flowable/business/handler/BossTaskHandler.java

@ -1,19 +0,0 @@
package org.springblade.flowable.business.handler;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
/**
* 老板处理器
*
* @author Chill
*/
public class BossTaskHandler implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
delegateTask.setAssignee("老板");
}
}

18
blade-service/blade-flow/src/main/java/org/springblade/flowable/business/handler/ManagerTaskHandler.java

@ -1,18 +0,0 @@
package org.springblade.flowable.business.handler;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
/**
* 经理处理器
*
* @author Chill
*/
public class ManagerTaskHandler implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
delegateTask.setAssignee("经理");
}
}

32
blade-service/blade-flow/src/main/java/org/springblade/flowable/business/service/impl/FlowBusinessServiceImpl.java

@ -52,7 +52,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
@Override
public IPage<BladeFlow> selectClaimPage(IPage<BladeFlow> page, BladeFlow bladeFlow) {
String taskUser = String.valueOf(SecureUtil.getUserId());
String taskUser = String.valueOf(SecureUtil.getUserAccount());
List<BladeFlow> flowList = new LinkedList<>();
// 等待签收的任务
@ -75,7 +75,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
@Override
public IPage<BladeFlow> selectTodoPage(IPage<BladeFlow> page, BladeFlow bladeFlow) {
String taskUser = String.valueOf(SecureUtil.getUserId());
String taskUser = String.valueOf(SecureUtil.getUserAccount());
List<BladeFlow> flowList = new LinkedList<>();
// 已签收的任务
@ -98,7 +98,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
@Override
public IPage<BladeFlow> selectSendPage(IPage<BladeFlow> page, BladeFlow bladeFlow) {
String taskUser = String.valueOf(SecureUtil.getUserId());
String taskUser = String.valueOf(SecureUtil.getUserAccount());
List<BladeFlow> flowList = new LinkedList<>();
HistoricProcessInstanceQuery historyQuery = historyService.createHistoricProcessInstanceQuery().startedBy(taskUser).orderByProcessInstanceStartTime().desc();
@ -120,11 +120,13 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
flow.setProcessInstanceId(historicProcessInstance.getId());
flow.setHistoryProcessInstanceId(historicProcessInstance.getId());
// ProcessDefinition
ProcessDefinition pd = FlowCache.getProcessDefinition(historicProcessInstance.getProcessDefinitionId());
flow.setProcessDefinitionId(pd.getId());
flow.setProcessDefinitionName(pd.getName());
flow.setProcessDefinitionKey(pd.getKey());
flow.setProcessDefinitionVersion(pd.getVersion());
ProcessDefinition processDefinition = FlowCache.getProcessDefinition(historicProcessInstance.getProcessDefinitionId());
flow.setProcessDefinitionId(processDefinition.getId());
flow.setProcessDefinitionName(processDefinition.getName());
flow.setProcessDefinitionVersion(processDefinition.getVersion());
flow.setProcessDefinitionKey(processDefinition.getKey());
flow.setCategory(processDefinition.getCategory());
flow.setCategoryName(FlowCache.getCategoryName(processDefinition.getCategory()));
flow.setProcessInstanceId(historicProcessInstance.getId());
// HistoricTaskInstance
HistoricTaskInstance historyTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(historicProcessInstance.getId()).orderByHistoricTaskInstanceEndTime().desc().list().get(0);
@ -151,7 +153,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
@Override
public IPage<BladeFlow> selectDonePage(IPage<BladeFlow> page, BladeFlow bladeFlow) {
String taskUser = String.valueOf(SecureUtil.getUserId());
String taskUser = String.valueOf(SecureUtil.getUserAccount());
List<BladeFlow> flowList = new LinkedList<>();
HistoricTaskInstanceQuery doneQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(taskUser).finished()
@ -177,11 +179,13 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
flow.setHistoryTaskEndTime(historicTaskInstance.getEndTime());
flow.setVariables(historicTaskInstance.getProcessVariables());
ProcessDefinition pd = FlowCache.getProcessDefinition(historicTaskInstance.getProcessDefinitionId());
flow.setProcessDefinitionId(pd.getId());
flow.setProcessDefinitionName(pd.getName());
flow.setProcessDefinitionKey(pd.getKey());
flow.setProcessDefinitionVersion(pd.getVersion());
ProcessDefinition processDefinition = FlowCache.getProcessDefinition(historicTaskInstance.getProcessDefinitionId());
flow.setProcessDefinitionId(processDefinition.getId());
flow.setProcessDefinitionName(processDefinition.getName());
flow.setProcessDefinitionKey(processDefinition.getKey());
flow.setProcessDefinitionVersion(processDefinition.getVersion());
flow.setCategory(processDefinition.getCategory());
flow.setCategoryName(FlowCache.getCategoryName(processDefinition.getCategory()));
flow.setProcessInstanceId(historicTaskInstance.getProcessInstanceId());
flow.setHistoryProcessInstanceId(historicTaskInstance.getProcessInstanceId());

4
blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java

@ -50,7 +50,6 @@ import org.springblade.flowable.engine.entity.FlowModel;
import org.springblade.flowable.engine.entity.FlowProcess;
import org.springblade.flowable.engine.mapper.FlowMapper;
import org.springblade.flowable.engine.service.FlowService;
import org.springblade.flowable.engine.utils.FlowCache;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
import org.springframework.stereotype.Service;
@ -132,7 +131,8 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
flow.setHistoryActivityName(historicActivityInstance.getActivityName());
flow.setCreateTime(historicActivityInstance.getStartTime());
flow.setEndTime(historicActivityInstance.getEndTime());
flow.setHistoryActivityDurationTime(DateUtil.secondToTime(historicActivityInstance.getDurationInMillis()));
String durationTime = DateUtil.secondToTime(Func.toLong(historicActivityInstance.getDurationInMillis(),0L) / 1000);
flow.setHistoryActivityDurationTime(durationTime);
// 获取流程发起人名称
if (FlowConstant.START_EVENT.equals(historicActivityInstance.getActivityType())) {
List<HistoricProcessInstance> processInstanceList = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).orderByProcessInstanceStartTime().asc().list();

4
blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/utils/FlowCache.java

@ -22,7 +22,7 @@ import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.system.utils.DictUtil;
import org.springblade.system.cache.DictCache;
/**
* 流程缓存
@ -66,7 +66,7 @@ public class FlowCache {
if (Func.isEmpty(category)) {
return StringPool.EMPTY;
}
return DictUtil.getValue(category.split(StringPool.UNDERSCORE)[0], Func.toInt(category.split(StringPool.UNDERSCORE)[1]));
return DictCache.getValue(category.split(StringPool.UNDERSCORE)[0], Func.toInt(category.split(StringPool.UNDERSCORE)[1]));
}
}

10
blade-service/blade-flow/src/main/resources/processes/LeaveProcess.bpmn20.xml

@ -3,20 +3,20 @@
<process id="Leave" name="请假流程" isExecutable="true">
<documentation>请假流程</documentation>
<startEvent id="start" name="开始"></startEvent>
<userTask id="fillTask" name="事假申请" flowable:assignee="${taskUser}">
<userTask id="fillTask" name="人事审批" flowable:assignee="${taskUser}">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<exclusiveGateway id="judgeTask"></exclusiveGateway>
<userTask id="managerTak" name="经理审批">
<userTask id="managerTak" name="经理审批" flowable:assignee="manager">
<extensionElements>
<flowable:taskListener event="create" class="org.springblade.flowable.business.handler.ManagerTaskHandler"></flowable:taskListener>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<userTask id="bossTask" name="老板审批">
<userTask id="bossTask" name="老板审批" flowable:assignee="boss">
<extensionElements>
<flowable:taskListener event="create" class="org.springblade.flowable.business.handler.BossTaskHandler"></flowable:taskListener>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<endEvent id="end" name="结束"></endEvent>

Loading…
Cancel
Save