Search in sources :

Example 81 with ServiceException

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("流程启动错误");
    }
}
Also used : Task(org.flowable.task.api.Task) ServiceException(com.ruoyi.common.exception.ServiceException) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ServiceException(com.ruoyi.common.exception.ServiceException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 82 with 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());
        }
    }
}
Also used : Task(org.flowable.task.api.Task) ServiceException(com.ruoyi.common.exception.ServiceException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 83 with ServiceException

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);
}
Also used : JsonUtils(com.ruoyi.common.utils.JsonUtils) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) ServiceException(com.ruoyi.common.exception.ServiceException) WfFormVo(com.ruoyi.workflow.domain.vo.WfFormVo) ListUtil(cn.hutool.core.collection.ListUtil) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ProcessEngineConfiguration(org.flowable.engine.ProcessEngineConfiguration) StringUtils(org.apache.commons.lang3.StringUtils) WfNextDto(com.ruoyi.workflow.domain.dto.WfNextDto) HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) IWfTaskService(com.ruoyi.workflow.service.IWfTaskService) Authentication(org.flowable.common.engine.impl.identity.Authentication) WfTaskVo(com.ruoyi.workflow.domain.vo.WfTaskVo) org.flowable.bpmn.model(org.flowable.bpmn.model) Comment(org.flowable.engine.task.Comment) Predicate(java.util.function.Predicate) FlowComment(com.ruoyi.flowable.common.enums.FlowComment) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Deployment(org.flowable.engine.repository.Deployment) Task(org.flowable.task.api.Task) LoginHelper(com.ruoyi.common.helper.LoginHelper) CustomProcessDiagramGenerator(com.ruoyi.flowable.flow.CustomProcessDiagramGenerator) WfViewerVo(com.ruoyi.workflow.domain.vo.WfViewerVo) Process(org.flowable.bpmn.model.Process) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) FlowableUtils(com.ruoyi.flowable.flow.FlowableUtils) FlowableObjectNotFoundException(org.flowable.common.engine.api.FlowableObjectNotFoundException) HistoricTaskInstanceQuery(org.flowable.task.api.history.HistoricTaskInstanceQuery) HistoricIdentityLink(org.flowable.identitylink.api.history.HistoricIdentityLink) R(com.ruoyi.common.core.domain.R) java.util(java.util) SysUser(com.ruoyi.common.core.domain.entity.SysUser) TableDataInfo(com.ruoyi.common.core.page.TableDataInfo) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) ObjectUtil(cn.hutool.core.util.ObjectUtil) TaskQuery(org.flowable.task.api.TaskQuery) WfTaskBo(com.ruoyi.workflow.domain.bo.WfTaskBo) IWfDeployFormService(com.ruoyi.workflow.service.IWfDeployFormService) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) PageQuery(com.ruoyi.common.core.domain.PageQuery) FlowableException(org.flowable.common.engine.api.FlowableException) DelegationState(org.flowable.task.api.DelegationState) Execution(org.flowable.engine.runtime.Execution) HistoricActivityInstanceQuery(org.flowable.engine.history.HistoricActivityInstanceQuery) Lists(com.google.common.collect.Lists) ProcessConstants(com.ruoyi.flowable.common.constant.ProcessConstants) Service(org.springframework.stereotype.Service) ISysRoleService(com.ruoyi.system.service.ISysRoleService) FindNextNodeUtil(com.ruoyi.flowable.flow.FindNextNodeUtil) FlowServiceFactory(com.ruoyi.flowable.factory.FlowServiceFactory) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance) WfCommentDto(com.ruoyi.workflow.domain.dto.WfCommentDto) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) CollUtil(cn.hutool.core.collection.CollUtil) ISysUserService(com.ruoyi.system.service.ISysUserService) SysRole(com.ruoyi.common.core.domain.entity.SysRole) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) Transactional(org.springframework.transaction.annotation.Transactional) InputStream(java.io.InputStream) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HistoricActivityInstanceQuery(org.flowable.engine.history.HistoricActivityInstanceQuery) ServiceException(com.ruoyi.common.exception.ServiceException) WfViewerVo(com.ruoyi.workflow.domain.vo.WfViewerVo) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance)

Example 84 with ServiceException

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));
}
Also used : SysConfig(com.ruoyi.system.domain.SysConfig) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 85 with ServiceException

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);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDept(com.ruoyi.common.core.domain.entity.SysDept)

Aggregations

ServiceException (com.ruoyi.common.exception.ServiceException)109 IOException (java.io.IOException)21 Transactional (org.springframework.transaction.annotation.Transactional)21 GenTable (com.ruoyi.generator.domain.GenTable)12 StringWriter (java.io.StringWriter)12 Template (org.apache.velocity.Template)12 VelocityContext (org.apache.velocity.VelocityContext)12 SysRole (com.ruoyi.common.core.domain.entity.SysRole)10 File (java.io.File)10 SysUser (com.ruoyi.common.core.domain.entity.SysUser)9 GenTableColumn (com.ruoyi.generator.domain.GenTableColumn)8 Before (org.aspectj.lang.annotation.Before)8 JSONObject (com.alibaba.fastjson.JSONObject)6 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)6 SysDept (com.ruoyi.common.core.domain.entity.SysDept)6 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)6 Constants (com.ruoyi.common.constant.Constants)5 GenConstants (com.ruoyi.common.constant.GenConstants)5 StringUtils (com.ruoyi.common.utils.StringUtils)5 SysOss (com.ruoyi.system.domain.SysOss)5