Browse Source

优化工作流与脚本

test
smallchill 6 years ago
parent
commit
517bc5f992
  1. 8
      blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/utils/TaskUtil.java
  2. 25
      blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/service/impl/FlowBusinessServiceImpl.java
  3. 65
      blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowFollowController.java
  4. 50
      blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/entity/FlowExecution.java
  5. 20
      blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/service/FlowService.java
  6. 52
      blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java
  7. 14
      blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/cache/UserCache.java
  8. 17
      doc/sql/bladex-sword-mysql.sql
  9. 6
      doc/sql/bladex-update-RC9.sql

8
blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/utils/TaskUtil.java

@ -20,6 +20,8 @@ import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import static org.springblade.core.launch.constant.FlowConstant.TASK_USR_PREFIX;
/**
* 工作流任务工具类
*
@ -33,7 +35,7 @@ public class TaskUtil {
* @return taskUser
*/
public static String getTaskUser() {
return StringUtil.format("taskUser_{}", SecureUtil.getUserId());
return StringUtil.format("{}{}", TASK_USR_PREFIX, SecureUtil.getUserId());
}
/**
@ -43,7 +45,7 @@ public class TaskUtil {
* @return taskUser
*/
public static String getTaskUser(String userId) {
return StringUtil.format("taskUser_{}", userId);
return StringUtil.format("{}{}", TASK_USR_PREFIX, userId);
}
@ -54,7 +56,7 @@ public class TaskUtil {
* @return userId
*/
public static Integer getUserId(String taskUser) {
return Func.toInt(StringUtil.removePrefix(taskUser, "taskUser_"));
return Func.toInt(StringUtil.removePrefix(taskUser, TASK_USR_PREFIX));
}
/**

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

@ -57,14 +57,14 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
@Override
public IPage<BladeFlow> selectClaimPage(IPage<BladeFlow> page, BladeFlow bladeFlow) {
String taskUser = TaskUtil.getTaskUser();
String taskRole = TaskUtil.getCandidateGroup();
String taskGroup = TaskUtil.getCandidateGroup();
List<BladeFlow> flowList = new LinkedList<>();
// 等待签收的任务
TaskQuery claimUserQuery = taskService.createTaskQuery().taskCandidateUser(taskUser)
.includeProcessVariables().active().orderByTaskCreateTime().desc();
// 等待签收的任务
TaskQuery claimRoleQuery = taskService.createTaskQuery().taskCandidateGroup(taskRole)
TaskQuery claimRoleQuery = taskService.createTaskQuery().taskCandidateGroup(taskGroup)
.includeProcessVariables().active().orderByTaskCreateTime().desc();
// 构建列表数据
@ -111,8 +111,19 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
List<BladeFlow> flowList = new LinkedList<>();
HistoricProcessInstanceQuery historyQuery = historyService.createHistoricProcessInstanceQuery().startedBy(taskUser).orderByProcessInstanceStartTime().desc();
if (bladeFlow.getCategory() != null) {
historyQuery.processDefinitionCategory(bladeFlow.getCategory());
}
if (bladeFlow.getBeginDate() != null) {
historyQuery.startedAfter(bladeFlow.getBeginDate());
}
if (bladeFlow.getEndDate() != null) {
historyQuery.startedBefore(bladeFlow.getEndDate());
}
// 查询列表
List<HistoricProcessInstance> historyList = historyQuery.listPage(Func.toInt(page.getCurrent() - 1), Func.toInt(page.getSize()));
List<HistoricProcessInstance> historyList = historyQuery.listPage(Func.toInt(page.getCurrent() - 1), Func.toInt(page.getSize() * page.getCurrent()));
historyList.forEach(historicProcessInstance -> {
BladeFlow flow = new BladeFlow();
@ -168,6 +179,9 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
HistoricTaskInstanceQuery doneQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(taskUser).finished()
.includeProcessVariables().orderByHistoricTaskInstanceEndTime().desc();
if (bladeFlow.getCategory() != null) {
doneQuery.processCategoryIn(Func.toStrList(bladeFlow.getCategory()));
}
if (bladeFlow.getBeginDate() != null) {
doneQuery.taskCompletedAfter(bladeFlow.getBeginDate());
}
@ -176,7 +190,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
}
// 查询列表
List<HistoricTaskInstance> doneList = doneQuery.listPage(Func.toInt(page.getCurrent() - 1), Func.toInt(page.getSize()));
List<HistoricTaskInstance> doneList = doneQuery.listPage(Func.toInt(page.getCurrent() - 1), Func.toInt(page.getSize() * page.getCurrent()));
doneList.forEach(historicTaskInstance -> {
BladeFlow flow = new BladeFlow();
flow.setTaskId(historicTaskInstance.getId());
@ -249,6 +263,9 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
* @param status 状态
*/
private void buildFlowTaskList(BladeFlow bladeFlow, List<BladeFlow> flowList, TaskQuery taskQuery, String status) {
if (bladeFlow.getCategory() != null) {
taskQuery.processCategoryIn(Func.toStrList(bladeFlow.getCategory()));
}
if (bladeFlow.getBeginDate() != null) {
taskQuery.taskCreatedAfter(bladeFlow.getBeginDate());
}

65
blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowFollowController.java

@ -0,0 +1,65 @@
/*
* 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.engine.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.flowable.engine.entity.FlowExecution;
import org.springblade.flowable.engine.service.FlowService;
import org.springframework.web.bind.annotation.*;
/**
* 流程状态控制器
*
* @author Chill
*/
@RestController
@RequestMapping("follow")
@AllArgsConstructor
@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR)
public class FlowFollowController {
private FlowService flowService;
/**
* 流程状态列表
*/
@GetMapping("list")
@ApiOperation(value = "分页", notes = "传入notice", position = 1)
public R<IPage<FlowExecution>> list(Query query, @ApiParam(value = "流程实例id") String processInstanceId, @ApiParam(value = "流程key") String processDefinitionKey) {
IPage<FlowExecution> pages = flowService.selectFollowPage(Condition.getPage(query), processInstanceId, processDefinitionKey);
return R.data(pages);
}
/**
* 删除流程实例
*/
@PostMapping("delete-process-instance")
@ApiOperation(value = "删除", notes = "传入主键集合", position = 2)
public R deleteProcessInstance(@ApiParam(value = "流程实例id") @RequestParam String processInstanceId, @ApiParam(value = "删除原因") @RequestParam String deleteReason) {
boolean temp = flowService.deleteProcessInstance(processInstanceId, deleteReason);
return R.status(temp);
}
}

50
blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/entity/FlowExecution.java

@ -0,0 +1,50 @@
/*
* 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.engine.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 运行实体类
*
* @author Chill
*/
@Data
public class FlowExecution implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String name;
private String startUserId;
private String startUser;
private Date startTime;
private String taskDefinitionId;
private String taskDefinitionKey;
private String category;
private String categoryName;
private String processInstanceId;
private String processDefinitionId;
private String processDefinitionKey;
private String activityId;
private int suspensionState;
private String executionId;
}

20
blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/service/FlowService.java

@ -19,6 +19,7 @@ package org.springblade.flowable.engine.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.flowable.core.entity.BladeFlow;
import org.springblade.flowable.engine.entity.FlowExecution;
import org.springblade.flowable.engine.entity.FlowModel;
import org.springblade.flowable.engine.entity.FlowProcess;
import org.springframework.web.multipart.MultipartFile;
@ -51,6 +52,16 @@ public interface FlowService extends IService<FlowModel> {
*/
IPage<FlowProcess> selectProcessPage(IPage<FlowProcess> page, String category);
/**
* 流程管理列表
*
* @param page 分页工具
* @param processInstanceId 流程实例id
* @param processDefinitionKey 流程key
* @return
*/
IPage<FlowExecution> selectFollowPage(IPage<FlowExecution> page, String processInstanceId, String processDefinitionKey);
/**
* 获取流转历史列表
*
@ -105,4 +116,13 @@ public interface FlowService extends IService<FlowModel> {
* @return
*/
boolean deployModel(String modelId, String category);
/**
* 删除流程实例
*
* @param processInstanceId 流程实例id
* @param deleteReason 删除原因
* @return
*/
boolean deleteProcessInstance(String processInstanceId, String deleteReason);
}

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

@ -33,11 +33,13 @@ import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.repository.ProcessDefinitionQuery;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.runtime.ProcessInstanceQuery;
import org.flowable.engine.task.Comment;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.DateUtil;
@ -47,10 +49,12 @@ import org.springblade.core.tool.utils.StringUtil;
import org.springblade.flowable.core.entity.BladeFlow;
import org.springblade.flowable.core.utils.TaskUtil;
import org.springblade.flowable.engine.constant.FlowConstant;
import org.springblade.flowable.engine.entity.FlowExecution;
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;
@ -90,20 +94,54 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
if (StringUtils.isNotEmpty(category)) {
processDefinitionQuery.processDefinitionCategory(category);
}
List<ProcessDefinition> processDefinitionList = processDefinitionQuery.listPage(Func.toInt(page.getCurrent() - 1), Func.toInt(page.getSize()));
List<ProcessDefinition> processDefinitionList = processDefinitionQuery.listPage(Func.toInt(page.getCurrent() - 1), Func.toInt(page.getSize() * page.getCurrent()));
List<FlowProcess> flowProcessList = new ArrayList<>();
for (ProcessDefinition processDefinition : processDefinitionList) {
processDefinitionList.forEach(processDefinition -> {
String deploymentId = processDefinition.getDeploymentId();
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
FlowProcess flowProcess = new FlowProcess((ProcessDefinitionEntityImpl) processDefinition);
flowProcess.setDeploymentTime(deployment.getDeploymentTime());
flowProcessList.add(flowProcess);
}
});
page.setTotal(processDefinitionQuery.count());
page.setRecords(flowProcessList);
return page;
}
@Override
public IPage<FlowExecution> selectFollowPage(IPage<FlowExecution> page, String processInstanceId, String processDefinitionKey) {
ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery();
if (StringUtil.isNotBlank(processInstanceId)) {
processInstanceQuery.processInstanceId(processInstanceId);
}
if (StringUtil.isNotBlank(processDefinitionKey)) {
processInstanceQuery.processDefinitionKey(processDefinitionKey);
}
List<FlowExecution> flowList = new ArrayList<>();
List<ProcessInstance> procInsList = processInstanceQuery.listPage(Func.toInt(page.getCurrent() - 1), Func.toInt(page.getSize() * page.getCurrent()));
procInsList.forEach(processInstance -> {
ExecutionEntityImpl execution = (ExecutionEntityImpl) processInstance;
FlowExecution flowExecution = new FlowExecution();
flowExecution.setId(execution.getId());
flowExecution.setName(execution.getName());
flowExecution.setStartUserId(execution.getStartUserId());
flowExecution.setStartUser(UserCache.getUserByTaskUser(execution.getStartUserId()).getName());
flowExecution.setStartTime(execution.getStartTime());
flowExecution.setExecutionId(execution.getId());
flowExecution.setProcessInstanceId(execution.getProcessInstanceId());
flowExecution.setProcessDefinitionId(execution.getProcessDefinitionId());
flowExecution.setProcessDefinitionKey(execution.getProcessDefinitionKey());
flowExecution.setSuspensionState(execution.getSuspensionState());
ProcessDefinition processDefinition = FlowCache.getProcessDefinition(execution.getProcessDefinitionId());
flowExecution.setCategory(processDefinition.getCategory());
flowExecution.setCategoryName(FlowCache.getCategoryName(processDefinition.getCategory()));
flowList.add(flowExecution);
});
page.setTotal(processInstanceQuery.count());
page.setRecords(flowList);
return page;
}
@Override
public List<BladeFlow> historyFlowList(String processInstanceId, String startActivityId, String endActivityId) {
List<BladeFlow> flowList = new LinkedList<>();
@ -132,7 +170,7 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
flow.setHistoryActivityName(historicActivityInstance.getActivityName());
flow.setCreateTime(historicActivityInstance.getStartTime());
flow.setEndTime(historicActivityInstance.getEndTime());
String durationTime = DateUtil.secondToTime(Func.toLong(historicActivityInstance.getDurationInMillis(),0L) / 1000);
String durationTime = DateUtil.secondToTime(Func.toLong(historicActivityInstance.getDurationInMillis(), 0L) / 1000);
flow.setHistoryActivityDurationTime(durationTime);
// 获取流程发起人名称
if (FlowConstant.START_EVENT.equals(historicActivityInstance.getActivityType())) {
@ -252,6 +290,12 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
return deploy(deployment, category);
}
@Override
public boolean deleteProcessInstance(String processInstanceId, String deleteReason) {
runtimeService.deleteProcessInstance(processInstanceId, deleteReason);
return true;
}
private boolean deploy(Deployment deployment, String category) {
log.debug("流程部署--------deploy: " + deployment + " 分类---------->" + category);
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();

14
blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/cache/UserCache.java vendored

@ -20,9 +20,12 @@ import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
import static org.springblade.core.launch.constant.FlowConstant.TASK_USR_PREFIX;
/**
* 系统缓存
*
@ -39,6 +42,17 @@ public class UserCache {
userClient = SpringUtil.getBean(IUserClient.class);
}
/**
* 根据任务用户id获取用户信息
*
* @param taskUserId 任务用户id
* @return
*/
public static User getUserByTaskUser(String taskUserId) {
int userId = Func.toInt(StringUtil.removePrefix(taskUserId, TASK_USR_PREFIX));
return getUser(userId);
}
/**
* 获取用户名
*

17
doc/sql/bladex-sword-mysql.sql

File diff suppressed because one or more lines are too long

6
doc/sql/bladex-update-RC9.sql

@ -33,10 +33,10 @@ INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`,
VALUES (@managerid, 'flow_manager_remove', '删除', 'remove', '', 'delete', 3, 2, 3, 1, NULL, 0);
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@flowid, 'flow_status', '流程状态', 'menu', '/flow/status', NULL, 4, 1, 0, 1, NULL, 0);
VALUES (@flowid, 'flow_follow', '流程跟踪', 'menu', '/flow/follow', NULL, 4, 1, 0, 1, NULL, 0);
set @statueid = (SELECT LAST_INSERT_ID());
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@statueid, 'flow_status_delete', '删除', 'delete', '', 'delete', 1, 2, 3, 1, NULL, 0);
VALUES (@statueid, 'flow_follow_delete', '删除', 'remove', '', 'remove', 1, 2, 2, 1, NULL, 0);
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (0, 'work', '我的事务', 'work', '/work', 'bell', 2, 1, 0, 1, NULL, 0);
@ -85,7 +85,7 @@ set @doneid = (SELECT LAST_INSERT_ID());
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@doneid, 'work_done_detail', '详情', 'detail', '', 'detail', 1, 2, 2, 1, NULL, 0);
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@sendid, 'work_done_follow', '跟踪', 'follow', '', 'follow', 2, 2, 2, 1, NULL, 0);
VALUES (@doneid, 'work_done_follow', '跟踪', 'follow', '', 'follow', 2, 2, 2, 1, NULL, 0);
-- ----------------------------
-- 更新系统管理排序

Loading…
Cancel
Save