成立单独的冀北技术监督项目
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<flowable.version>6.8.0</flowable.version>
|
||||
<mapstruct.version>1.5.5.Final</mapstruct.version>
|
||||
<easy-trans.version>2.2.11</easy-trans.version>
|
||||
</properties>
|
||||
@@ -39,17 +38,7 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Flowable 工作流相关 -->
|
||||
<dependency>
|
||||
<groupId>org.flowable</groupId>
|
||||
<artifactId>flowable-spring-boot-starter-process</artifactId>
|
||||
<version>${flowable.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.flowable</groupId>
|
||||
<artifactId>flowable-spring-boot-starter-actuator</artifactId>
|
||||
<version>${flowable.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.njcn.bpm.api;
|
||||
|
||||
import com.njcn.bpm.api.fallback.BpmProcessFeignClientFallbackFactory;
|
||||
import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
|
||||
/**
|
||||
* 流程实例 Api 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.SUPERVISION,path = "/process",fallbackFactory = BpmProcessFeignClientFallbackFactory.class)
|
||||
public interface BpmProcessFeignClient {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param reqDTO 创建信息
|
||||
* @return 实例的编号
|
||||
*/
|
||||
@PostMapping("/createProcessInstance")
|
||||
HttpResult<String> createProcessInstance(@RequestParam("userId") String userId, @RequestBody BpmProcessInstanceCreateReqDTO reqDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.njcn.bpm.api.fallback;
|
||||
|
||||
import com.njcn.bpm.api.BpmProcessFeignClient;
|
||||
import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO;
|
||||
import com.njcn.bpm.utils.BpmEnumUtil;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
|
||||
/**
|
||||
* @author denghuajun
|
||||
* @version 1.0.0
|
||||
* @date 2022/3/16
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class BpmProcessFeignClientFallbackFactory implements FallbackFactory<BpmProcessFeignClient> {
|
||||
@Override
|
||||
public BpmProcessFeignClient create(Throwable throwable) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (throwable.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) throwable.getCause();
|
||||
exceptionEnum = BpmEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new BpmProcessFeignClient() {
|
||||
@Override
|
||||
public HttpResult<String> createProcessInstance(String userId, BpmProcessInstanceCreateReqDTO reqDTO) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "创建流程实例", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.bpm.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 流程实例 ProcessInstance 的状态
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum BpmProcessInstanceStatusEnum implements IntArrayValuable {
|
||||
|
||||
RUNNING(1, "审批中"),
|
||||
APPROVE(2, "审批通过"),
|
||||
REJECT(3, "审批不通过"),
|
||||
CANCEL(4, "已取消");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmProcessInstanceStatusEnum::getStatus).toArray();
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private final Integer status;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private final String desc;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,10 @@ public enum BpmResponseEnum {
|
||||
|
||||
PROCESS_DEFINITION_NOT_EXISTS("A00568","流程定义不存在"),
|
||||
|
||||
|
||||
|
||||
PROCESS_DEFINITION_IS_SUSPENDED("A00568", "流程定义处于挂起状态"),
|
||||
|
||||
FORM_NOT_EXISTS("A00568","动态表单不存在"),
|
||||
|
||||
MODEL_DEPLOY_FAIL_FORM_NOT_CONFIG("A00568","部署流程失败,原因:流程表单未配置,请点击【修改流程】按钮进行配置"),
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.njcn.bpm.pojo.dto;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 流程实例的创建 Request DTO
|
||||
*/
|
||||
@Data
|
||||
public class BpmProcessInstanceCreateReqDTO {
|
||||
|
||||
/**
|
||||
* 流程定义的标识
|
||||
*/
|
||||
@NotEmpty(message = "流程定义的标识不能为空")
|
||||
private String processDefinitionKey;
|
||||
|
||||
/**
|
||||
* 变量实例(动态表单)
|
||||
*/
|
||||
private Map<String, Object> variables;
|
||||
|
||||
/**
|
||||
* 业务的唯一标识
|
||||
*
|
||||
* 例如说,请假申请的编号。通过它,可以查询到对应的实例
|
||||
*/
|
||||
@NotEmpty(message = "业务的唯一标识")
|
||||
private String businessKey;
|
||||
|
||||
/**
|
||||
* 发起人自选审批人 Map
|
||||
*
|
||||
* key:taskKey 任务编码
|
||||
* value:审批人的数组
|
||||
* 例如:{ taskKey1 :[1, 2] },则表示 taskKey1 这个任务,提前设定了,由 userId 为 1,2 的用户进行审批
|
||||
*/
|
||||
private Map<String, List<String>> startUserSelectAssignees;
|
||||
|
||||
}
|
||||
@@ -44,9 +44,10 @@ public class BpmModelParam implements Serializable {
|
||||
|
||||
private Integer formType = 10;
|
||||
|
||||
|
||||
@ApiModelProperty("表单提交路由")
|
||||
private String formCustomCreatePath;
|
||||
|
||||
@ApiModelProperty("表单查看路由")
|
||||
private String formCustomViewPath;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.Objects;
|
||||
* @version 1.0.0
|
||||
* @date 2021年12月20日 10:03
|
||||
*/
|
||||
public class ProcessEnumUtil {
|
||||
public class BpmEnumUtil {
|
||||
|
||||
/**
|
||||
* 获取HarmonicResponseEnum实例
|
||||
@@ -15,6 +15,7 @@
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<flowable.version>6.8.0</flowable.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -37,6 +38,18 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Flowable 工作流相关 -->
|
||||
<dependency>
|
||||
<groupId>org.flowable</groupId>
|
||||
<artifactId>flowable-spring-boot-starter-process</artifactId>
|
||||
<version>${flowable.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.flowable</groupId>
|
||||
<artifactId>flowable-spring-boot-starter-actuator</artifactId>
|
||||
<version>${flowable.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.njcn.bpm.enums;
|
||||
package com.njcn.bpm.constant;
|
||||
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.njcn.bpm.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO;
|
||||
import com.njcn.bpm.pojo.param.BpmProcessDefinitionInfoParam;
|
||||
import com.njcn.bpm.pojo.po.BpmCategory;
|
||||
import com.njcn.bpm.pojo.po.BpmForm;
|
||||
@@ -10,9 +11,11 @@ import com.njcn.bpm.pojo.vo.BpmProcessDefinitionInfoVO;
|
||||
import com.njcn.bpm.service.IBpmCategoryService;
|
||||
import com.njcn.bpm.service.IBpmFormService;
|
||||
import com.njcn.bpm.service.IBpmProcessDefinitionService;
|
||||
import com.njcn.bpm.service.task.IBpmProcessInstanceService;
|
||||
import com.njcn.bpm.strategy.BpmTaskCandidateStartUserSelectStrategy;
|
||||
import com.njcn.bpm.utils.BpmProcessDefinitionConvert;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
@@ -54,6 +57,8 @@ public class BpmProcessDefinitionController extends BaseController {
|
||||
|
||||
private final IBpmCategoryService categoryService;
|
||||
|
||||
private final IBpmProcessInstanceService processInstanceService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/page")
|
||||
@ApiOperation("获得流程定义分页")
|
||||
@@ -120,4 +125,13 @@ public class BpmProcessDefinitionController extends BaseController {
|
||||
processDefinition, null, null, null, null, bpmnModel, userTaskList), methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
|
||||
@ApiOperation("创建流程实例")
|
||||
@PostMapping("/createProcessInstance")
|
||||
HttpResult<String> createProcessInstance(@RequestParam("userId") String userId, @RequestBody BpmProcessInstanceCreateReqDTO reqDTO){
|
||||
String methodDescribe = getMethodDescribe("createProcessInstance");
|
||||
String instanceId = processInstanceService.createProcessInstance(userId, reqDTO);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, instanceId, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,11 +50,11 @@ public interface IBpmCategoryService extends IService<BpmCategory> {
|
||||
/**
|
||||
* 获得流程分类 Map,基于指定编码
|
||||
*
|
||||
* @param codes 编号数组
|
||||
* @param ids 编号数组
|
||||
* @return 流程分类 Map
|
||||
*/
|
||||
default Map<String, BpmCategory> getCategoryMap(Collection<String> codes) {
|
||||
return convertMap(getCategoryListByCode(codes), BpmCategory::getCode);
|
||||
default Map<String, BpmCategory> getCategoryMap(Collection<String> ids) {
|
||||
return convertMap(getCategoryListById(ids), BpmCategory::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ public interface IBpmCategoryService extends IService<BpmCategory> {
|
||||
*
|
||||
* @return 流程分类列表
|
||||
*/
|
||||
List<BpmCategory> getCategoryListByCode(Collection<String> codes);
|
||||
List<BpmCategory> getCategoryListById(Collection<String> codes);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -83,12 +83,12 @@ public class BpmCategoryServiceImpl extends ServiceImpl<BpmCategoryMapper, BpmCa
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BpmCategory> getCategoryListByCode(Collection<String> codes) {
|
||||
if (CollUtil.isEmpty(codes)) {
|
||||
public List<BpmCategory> getCategoryListById(Collection<String> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
LambdaQueryWrapper<BpmCategory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.in(BpmCategory::getCode,codes);
|
||||
lambdaQueryWrapper.in(BpmCategory::getId,ids);
|
||||
return this.baseMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.bpm.service.task;
|
||||
|
||||
import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO;
|
||||
import org.flowable.engine.delegate.event.FlowableCancelledEvent;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
@@ -26,6 +27,18 @@ public interface IBpmProcessInstanceService {
|
||||
* @return 流程实例
|
||||
*/
|
||||
ProcessInstance getProcessInstance(String id);
|
||||
|
||||
|
||||
/**
|
||||
* 创建流程实例(提供给内部)
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param createReqDTO 创建信息
|
||||
* @return 实例的编号
|
||||
*/
|
||||
String createProcessInstance(String userId, BpmProcessInstanceCreateReqDTO createReqDTO);
|
||||
|
||||
|
||||
//
|
||||
// /**
|
||||
// * 获得流程实例列表
|
||||
@@ -89,14 +102,7 @@ public interface IBpmProcessInstanceService {
|
||||
// */
|
||||
// String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqVO createReqVO);
|
||||
//
|
||||
// /**
|
||||
// * 创建流程实例(提供给内部)
|
||||
// *
|
||||
// * @param userId 用户编号
|
||||
// * @param createReqDTO 创建信息
|
||||
// * @return 实例的编号
|
||||
// */
|
||||
// String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO);
|
||||
|
||||
//
|
||||
// /**
|
||||
// * 发起人取消流程实例
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
package com.njcn.bpm.service.task.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.bpm.constant.BpmConstants;
|
||||
import com.njcn.bpm.enums.BpmProcessInstanceStatusEnum;
|
||||
import com.njcn.bpm.enums.BpmResponseEnum;
|
||||
import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO;
|
||||
import com.njcn.bpm.service.IBpmProcessDefinitionService;
|
||||
import com.njcn.bpm.service.task.IBpmProcessInstanceService;
|
||||
import com.njcn.bpm.strategy.BpmTaskCandidateStartUserSelectStrategy;
|
||||
import com.njcn.bpm.utils.CollectionUtils;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.bpmn.model.BpmnModel;
|
||||
import org.flowable.bpmn.model.UserTask;
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.delegate.event.FlowableCancelledEvent;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.history.HistoricProcessInstanceQuery;
|
||||
import org.flowable.engine.repository.ProcessDefinition;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.njcn.bpm.utils.FlowableUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
@@ -25,13 +30,13 @@ import java.util.*;
|
||||
|
||||
/**
|
||||
* 流程实例 Service 实现类
|
||||
*
|
||||
* <p>
|
||||
* ProcessDefinition & ProcessInstance & Execution & Task 的关系:
|
||||
* 1. <a href="https://blog.csdn.net/bobozai86/article/details/105210414" />
|
||||
*
|
||||
* 1. <a href="https://blog.csdn.net/bobozai86/article/details/105210414" />
|
||||
* <p>
|
||||
* HistoricProcessInstance & ProcessInstance 的关系:
|
||||
* 1. <a href=" https://my.oschina.net/843294669/blog/71902" />
|
||||
*
|
||||
* 1. <a href=" https://my.oschina.net/843294669/blog/71902" />
|
||||
* <p>
|
||||
* 简单来说,前者 = 历史 + 运行中的流程实例,后者仅是运行中的流程实例
|
||||
*
|
||||
* @author 芋道源码
|
||||
@@ -43,16 +48,18 @@ public class BpmProcessInstanceServiceImpl implements IBpmProcessInstanceService
|
||||
|
||||
@Resource
|
||||
private RuntimeService runtimeService;
|
||||
|
||||
@Resource
|
||||
private HistoryService historyService;
|
||||
|
||||
// @Resource
|
||||
// private BpmProcessDefinitionService processDefinitionService;
|
||||
@Resource
|
||||
private IBpmProcessDefinitionService processDefinitionService;
|
||||
|
||||
// @Resource
|
||||
// private BpmMessageService messageService;
|
||||
//
|
||||
// @Resource
|
||||
// private AdminUserApi adminUserApi;
|
||||
@Resource
|
||||
private UserFeignClient userFeignClient;
|
||||
//
|
||||
// @Resource
|
||||
// private BpmProcessInstanceEventPublisher processInstanceEventPublisher;
|
||||
@@ -64,6 +71,8 @@ public class BpmProcessInstanceServiceImpl implements IBpmProcessInstanceService
|
||||
.processInstanceId(id)
|
||||
.singleResult();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// @Override
|
||||
// public List<ProcessInstance> getProcessInstances(Set<String> ids) {
|
||||
@@ -128,70 +137,72 @@ public class BpmProcessInstanceServiceImpl implements IBpmProcessInstanceService
|
||||
// return createProcessInstance0(userId, definition, createReqVO.getVariables(), null,
|
||||
// createReqVO.getStartUserSelectAssignees());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO) {
|
||||
// // 获得流程定义
|
||||
// ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey());
|
||||
// // 发起流程
|
||||
// return createProcessInstance0(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey(),
|
||||
// createReqDTO.getStartUserSelectAssignees());
|
||||
// }
|
||||
//
|
||||
// private String createProcessInstance0(Long userId, ProcessDefinition definition,
|
||||
// Map<String, Object> variables, String businessKey,
|
||||
// Map<String, List<Long>> startUserSelectAssignees) {
|
||||
// // 1.1 校验流程定义
|
||||
// if (definition == null) {
|
||||
// throw exception(PROCESS_DEFINITION_NOT_EXISTS);
|
||||
// }
|
||||
// if (definition.isSuspended()) {
|
||||
// throw exception(PROCESS_DEFINITION_IS_SUSPENDED);
|
||||
// }
|
||||
// // 1.2 校验发起人自选审批人
|
||||
// validateStartUserSelectAssignees(definition, startUserSelectAssignees);
|
||||
//
|
||||
// // 2. 创建流程实例
|
||||
// if (variables == null) {
|
||||
// variables = new HashMap<>();
|
||||
// }
|
||||
// FlowableUtils.filterProcessInstanceFormVariable(variables); // 过滤一下,避免 ProcessInstance 系统级的变量被占用
|
||||
// variables.put(BpmConstants.PROCESS_INSTANCE_VARIABLE_STATUS, // 流程实例状态:审批中
|
||||
// BpmProcessInstanceStatusEnum.RUNNING.getStatus());
|
||||
// if (CollUtil.isNotEmpty(startUserSelectAssignees)) {
|
||||
// variables.put(BpmConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees);
|
||||
// }
|
||||
// ProcessInstance instance = runtimeService.createProcessInstanceBuilder()
|
||||
// .processDefinitionId(definition.getId())
|
||||
// .businessKey(businessKey)
|
||||
// .name(definition.getName().trim())
|
||||
// .variables(variables)
|
||||
// .start();
|
||||
// return instance.getId();
|
||||
// }
|
||||
//
|
||||
// private void validateStartUserSelectAssignees(ProcessDefinition definition, Map<String, List<Long>> startUserSelectAssignees) {
|
||||
// // 1. 获得发起人自选审批人的 UserTask 列表
|
||||
// BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(definition.getId());
|
||||
// List<UserTask> userTaskList = BpmTaskCandidateStartUserSelectStrategy.getStartUserSelectUserTaskList(bpmnModel);
|
||||
// if (CollUtil.isEmpty(userTaskList)) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // 2. 校验发起人自选审批人的 UserTask 是否都配置了
|
||||
// userTaskList.forEach(userTask -> {
|
||||
// List<Long> assignees = startUserSelectAssignees != null ? startUserSelectAssignees.get(userTask.getId()) : null;
|
||||
// if (CollUtil.isEmpty(assignees)) {
|
||||
// throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, userTask.getName());
|
||||
// }
|
||||
// Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(assignees);
|
||||
// assignees.forEach(assignee -> {
|
||||
// if (userMap.get(assignee) == null) {
|
||||
// throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_EXISTS, userTask.getName(), assignee);
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String createProcessInstance(String userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO) {
|
||||
// 获得流程定义
|
||||
ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey());
|
||||
// 发起流程
|
||||
return createProcessInstance(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey(),
|
||||
createReqDTO.getStartUserSelectAssignees());
|
||||
}
|
||||
|
||||
private String createProcessInstance(String userId, ProcessDefinition definition,
|
||||
Map<String, Object> variables, String businessKey,
|
||||
Map<String, List<String>> startUserSelectAssignees) {
|
||||
// 1.1 校验流程定义
|
||||
if (definition == null) {
|
||||
throw new BusinessException(BpmResponseEnum.PROCESS_DEFINITION_NOT_EXISTS);
|
||||
}
|
||||
if (definition.isSuspended()) {
|
||||
throw new BusinessException(BpmResponseEnum.PROCESS_DEFINITION_IS_SUSPENDED);
|
||||
}
|
||||
|
||||
// 1.2 校验发起人自选审批人
|
||||
validateStartUserSelectAssignees(definition, startUserSelectAssignees);
|
||||
|
||||
// 2. 创建流程实例
|
||||
if (variables == null) {
|
||||
variables = new HashMap<>();
|
||||
}
|
||||
FlowableUtils.filterProcessInstanceFormVariable(variables); // 过滤一下,避免 ProcessInstance 系统级的变量被占用
|
||||
variables.put(BpmConstants.PROCESS_INSTANCE_VARIABLE_STATUS, // 流程实例状态:审批中
|
||||
BpmProcessInstanceStatusEnum.RUNNING.getStatus());
|
||||
if (CollUtil.isNotEmpty(startUserSelectAssignees)) {
|
||||
variables.put(BpmConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees);
|
||||
}
|
||||
ProcessInstance instance = runtimeService.createProcessInstanceBuilder()
|
||||
.processDefinitionId(definition.getId())
|
||||
.businessKey(businessKey)
|
||||
.name(definition.getName().trim())
|
||||
.variables(variables)
|
||||
.start();
|
||||
return instance.getId();
|
||||
}
|
||||
|
||||
private void validateStartUserSelectAssignees(ProcessDefinition definition, Map<String, List<String>> startUserSelectAssignees) {
|
||||
// 1. 获得发起人自选审批人的 UserTask 列表
|
||||
BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(definition.getId());
|
||||
List<UserTask> userTaskList = BpmTaskCandidateStartUserSelectStrategy.getStartUserSelectUserTaskList(bpmnModel);
|
||||
if (CollUtil.isEmpty(userTaskList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 校验发起人自选审批人的 UserTask 是否都配置了
|
||||
userTaskList.forEach(userTask -> {
|
||||
List<String> assignees = startUserSelectAssignees != null ? startUserSelectAssignees.get(userTask.getId()) : null;
|
||||
if (CollUtil.isEmpty(assignees)) {
|
||||
throw new BusinessException("审批任务(" + userTask.getName() + ")的审批人未配置");
|
||||
}
|
||||
List<User> userList = userFeignClient.getUserByIdList(assignees).getData();
|
||||
Map<String, User> userMap = CollectionUtils.convertMap(userList, User::getId);
|
||||
assignees.forEach(assignee -> {
|
||||
if (userMap.get(assignee) == null) {
|
||||
throw new BusinessException("审批任务(" + userTask.getName() + ")的审批人(" + assignee + ")不存在");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// public void cancelProcessInstanceByStartUser(Long userId, @Valid BpmProcessInstanceCancelReqVO cancelReqVO) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.njcn.bpm.utils;
|
||||
|
||||
import com.njcn.bpm.enums.BpmConstants;
|
||||
import com.njcn.bpm.constant.BpmConstants;
|
||||
import org.flowable.common.engine.api.delegate.Expression;
|
||||
import org.flowable.common.engine.api.variable.VariableContainer;
|
||||
import org.flowable.common.engine.impl.el.ExpressionManager;
|
||||
|
||||
Reference in New Issue
Block a user