use of com.ruoyi.common.exception.ServiceException in project RuoYi-Flowable-Plus by KonBAI-Q.
the class WfProcessServiceImpl method startProcess.
/**
* 根据流程定义ID启动流程实例
*
* @param procDefId 流程定义Id
* @param variables 流程变量
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void startProcess(String procDefId, Map<String, Object> variables) {
try {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
if (Objects.nonNull(processDefinition) && processDefinition.isSuspended()) {
throw new ServiceException("流程已被挂起,请先激活流程");
}
// variables.put("skip", true);
// variables.put(ProcessConstants.FLOWABLE_SKIP_EXPRESSION_ENABLED, true);
// 设置流程发起人Id到流程中
String userIdStr = LoginHelper.getUserId().toString();
identityService.setAuthenticatedUserId(userIdStr);
variables.put(ProcessConstants.PROCESS_INITIATOR, userIdStr);
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, variables);
// 给第一步申请人节点设置任务执行人和意见 todo:第一个节点不设置为申请人节点有点问题?
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
if (Objects.nonNull(task)) {
if (!StrUtil.equalsAny(task.getAssignee(), userIdStr)) {
throw new ServiceException("数据验证失败,该工作流第一个用户任务的指派人并非当前用户,不能执行该操作!");
}
taskService.addComment(task.getId(), processInstance.getProcessInstanceId(), FlowComment.NORMAL.getType(), LoginHelper.getNickName() + "发起流程申请");
// taskService.setAssignee(task.getId(), userIdStr);
taskService.complete(task.getId(), variables);
}
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException("流程启动错误");
}
}
use of com.ruoyi.common.exception.ServiceException in project RuoYi-Flowable-Plus by KonBAI-Q.
the class WfTaskServiceImpl method complete.
/**
* 完成任务
*
* @param taskVo 请求实体参数
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void complete(WfTaskBo taskVo) {
Task task = taskService.createTaskQuery().taskId(taskVo.getTaskId()).singleResult();
if (Objects.isNull(task)) {
throw new ServiceException("任务不存在");
}
if (DelegationState.PENDING.equals(task.getDelegationState())) {
taskService.addComment(taskVo.getTaskId(), taskVo.getInstanceId(), FlowComment.DELEGATE.getType(), taskVo.getComment());
taskService.resolveTask(taskVo.getTaskId(), taskVo.getValues());
} else {
taskService.addComment(taskVo.getTaskId(), taskVo.getInstanceId(), FlowComment.NORMAL.getType(), taskVo.getComment());
Long userId = LoginHelper.getUserId();
taskService.setAssignee(taskVo.getTaskId(), userId.toString());
if (ObjectUtil.isNotEmpty(taskVo.getValues())) {
taskService.complete(taskVo.getTaskId(), taskVo.getValues());
} else {
taskService.complete(taskVo.getTaskId());
}
}
}
use of com.ruoyi.common.exception.ServiceException in project RuoYi-Flowable-Plus by KonBAI-Q.
the class WfTaskServiceImpl method getFlowViewer.
/**
* 获取流程执行过程
*
* @param procInsId
* @return
*/
@Override
public WfViewerVo getFlowViewer(String procInsId) {
// 构建查询条件
HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery().processInstanceId(procInsId);
List<HistoricActivityInstance> allActivityInstanceList = query.list();
if (CollUtil.isEmpty(allActivityInstanceList)) {
return new WfViewerVo();
}
// 获取流程发布Id信息
String processDefinitionId = allActivityInstanceList.get(0).getProcessDefinitionId();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
if (ObjectUtil.isNull(bpmnModel)) {
throw new ServiceException("流程模型不存在");
}
Map<String, List<String>> sequenceElementMap = new HashMap<>();
Map<String, String> sequenceFlowMap = new HashMap<>();
Collection<FlowElement> flowElements = bpmnModel.getMainProcess().getFlowElements();
for (FlowElement flowElement : flowElements) {
if (flowElement instanceof SequenceFlow) {
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
String sourceRef = sequenceFlow.getSourceRef();
String targetRef = sequenceFlow.getTargetRef();
List<String> targetRefList = sequenceElementMap.get(sourceRef);
if (CollUtil.isEmpty(targetRefList)) {
sequenceElementMap.put(sourceRef, ListUtil.toList(targetRef));
} else {
targetRefList.add(targetRef);
}
sequenceFlowMap.put(sourceRef + targetRef, sequenceFlow.getId());
}
}
// 查询所有已完成的元素
List<HistoricActivityInstance> finishedElementList = allActivityInstanceList.stream().filter(item -> ObjectUtil.isNotNull(item.getEndTime())).collect(Collectors.toList());
// 所有已完成的连线
Set<String> finishedSequenceFlowSet = new HashSet<>();
// 所有已完成的任务节点
Set<String> finishedTaskSet = new HashSet<>();
finishedElementList.forEach(item -> {
if ("sequenceFlow".equals(item.getActivityType())) {
finishedSequenceFlowSet.add(item.getActivityId());
} else {
finishedTaskSet.add(item.getActivityId());
}
});
// 查询所有未结束的节点
Set<String> unfinishedTaskSet = allActivityInstanceList.stream().filter(item -> ObjectUtil.isNull(item.getEndTime())).map(HistoricActivityInstance::getActivityId).collect(Collectors.toSet());
Set<String> rejectedTaskSet = new LinkedHashSet<>();
Set<String> sourceTaskSet = unfinishedTaskSet;
while (CollUtil.isNotEmpty(sourceTaskSet)) {
Set<String> nextIdSet = new HashSet<>();
for (String previousId : sourceTaskSet) {
List<String> nextIdList = sequenceElementMap.get(previousId);
if (CollUtil.isEmpty(nextIdList)) {
continue;
}
nextIdList.forEach(nextId -> {
if (finishedTaskSet.contains(nextId)) {
nextIdSet.add(nextId);
String rejectedSequenceFlow = sequenceFlowMap.get(previousId + nextId);
if (finishedSequenceFlowSet.contains(rejectedSequenceFlow)) {
nextIdSet.add(rejectedSequenceFlow);
}
}
});
}
rejectedTaskSet.addAll(nextIdSet);
sourceTaskSet = nextIdSet;
}
return new WfViewerVo(finishedTaskSet, finishedSequenceFlowSet, unfinishedTaskSet, rejectedTaskSet);
}
use of com.ruoyi.common.exception.ServiceException in project RuoYi-Flowable-Plus by KonBAI-Q.
the class SysConfigServiceImpl method deleteConfigByIds.
/**
* 批量删除参数信息
*
* @param configIds 需要删除的参数ID
*/
@Override
public void deleteConfigByIds(Long[] configIds) {
for (Long configId : configIds) {
SysConfig config = selectConfigById(configId);
if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {
throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
}
RedisUtils.deleteObject(getCacheKey(config.getConfigKey()));
}
baseMapper.deleteBatchIds(Arrays.asList(configIds));
}
use of com.ruoyi.common.exception.ServiceException in project RuoYi-Flowable-Plus by KonBAI-Q.
the class SysDeptServiceImpl method insertDept.
/**
* 新增保存部门信息
*
* @param dept 部门信息
* @return 结果
*/
@Override
public int insertDept(SysDept dept) {
SysDept info = baseMapper.selectById(dept.getParentId());
// 如果父节点不为正常状态,则不允许新增子节点
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
throw new ServiceException("部门停用,不允许新增");
}
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
return baseMapper.insert(dept);
}
Aggregations