Search in sources :

Example 6 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Flowable-Plus by KonBAI-Q.

the class CreateAndUpdateMetaObjectHandler method updateFill.

@Override
public void updateFill(MetaObject metaObject) {
    try {
        if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) {
            BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject();
            Date current = new Date();
            // 更新时间填充(不管为不为空)
            baseEntity.setUpdateTime(current);
            String username = getLoginUsername();
            // 当前已登录 更新人填充(不管为不为空)
            if (StringUtils.isNotBlank(username)) {
                baseEntity.setUpdateBy(username);
            }
        }
    } catch (Exception e) {
        throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) BaseEntity(com.ruoyi.common.core.domain.BaseEntity) Date(java.util.Date) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 7 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfDefinitionServiceImpl method startProcessInstanceById.

/**
 * 根据流程定义ID启动流程实例
 *
 * @param procDefId 流程定义Id
 * @param variables 流程变量
 * @return
 */
@Deprecated
@Override
@Transactional(rollbackFor = Exception.class)
public void startProcessInstanceById(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) IOException(java.io.IOException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfTaskServiceImpl method flowRecord.

/**
 * 流程历史流转记录
 *
 * @param procInsId 流程实例Id
 * @return
 */
@Override
public Map<String, Object> flowRecord(String procInsId, String deployId) {
    Map<String, Object> map = new HashMap<>();
    if (StringUtils.isNotBlank(procInsId)) {
        List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().processInstanceId(procInsId).orderByHistoricActivityInstanceStartTime().desc().list();
        List<WfTaskVo> hisFlowList = new ArrayList<>();
        for (HistoricActivityInstance histIns : list) {
            if (StringUtils.isNotBlank(histIns.getTaskId())) {
                WfTaskVo flowTask = new WfTaskVo();
                flowTask.setProcDefId(histIns.getProcessDefinitionId());
                flowTask.setTaskId(histIns.getTaskId());
                flowTask.setTaskName(histIns.getActivityName());
                flowTask.setCreateTime(histIns.getStartTime());
                flowTask.setFinishTime(histIns.getEndTime());
                if (StringUtils.isNotBlank(histIns.getAssignee())) {
                    SysUser sysUser = sysUserService.selectUserById(Long.parseLong(histIns.getAssignee()));
                    flowTask.setAssigneeId(sysUser.getUserId());
                    flowTask.setAssigneeName(sysUser.getNickName());
                    flowTask.setDeptName(sysUser.getDept().getDeptName());
                }
                // 展示审批人员
                List<HistoricIdentityLink> linksForTask = historyService.getHistoricIdentityLinksForTask(histIns.getTaskId());
                StringBuilder stringBuilder = new StringBuilder();
                for (HistoricIdentityLink identityLink : linksForTask) {
                    if ("candidate".equals(identityLink.getType())) {
                        if (StringUtils.isNotBlank(identityLink.getUserId())) {
                            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(identityLink.getUserId()));
                            stringBuilder.append(sysUser.getNickName()).append(",");
                        }
                        if (StringUtils.isNotBlank(identityLink.getGroupId())) {
                            SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId()));
                            stringBuilder.append(sysRole.getRoleName()).append(",");
                        }
                    }
                }
                if (StringUtils.isNotBlank(stringBuilder)) {
                    flowTask.setCandidate(stringBuilder.substring(0, stringBuilder.length() - 1));
                }
                flowTask.setDuration(histIns.getDurationInMillis() == null || histIns.getDurationInMillis() == 0 ? null : getDate(histIns.getDurationInMillis()));
                // 获取意见评论内容
                List<Comment> commentList = taskService.getProcessInstanceComments(histIns.getProcessInstanceId());
                commentList.forEach(comment -> {
                    if (histIns.getTaskId().equals(comment.getTaskId())) {
                        flowTask.setComment(WfCommentDto.builder().type(comment.getType()).comment(comment.getFullMessage()).build());
                    }
                });
                hisFlowList.add(flowTask);
            }
        }
        map.put("flowList", hisFlowList);
    // // 查询当前任务是否完成
    // List<Task> taskList = taskService.createTaskQuery().processInstanceId(procInsId).list();
    // if (CollectionUtils.isNotEmpty(taskList)) {
    // map.put("finished", true);
    // } else {
    // map.put("finished", false);
    // }
    }
    // 第一次申请获取初始化表单
    if (StringUtils.isNotBlank(deployId)) {
        WfFormVo formVo = deployFormService.selectDeployFormByDeployId(deployId);
        if (Objects.isNull(formVo)) {
            throw new ServiceException("请先配置流程表单");
        }
        map.put("formData", JsonUtils.parseObject(formVo.getContent(), Map.class));
    }
    return map;
}
Also used : Comment(org.flowable.engine.task.Comment) FlowComment(com.ruoyi.flowable.common.enums.FlowComment) HistoricIdentityLink(org.flowable.identitylink.api.history.HistoricIdentityLink) SysUser(com.ruoyi.common.core.domain.entity.SysUser) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WfTaskVo(com.ruoyi.workflow.domain.vo.WfTaskVo) WfFormVo(com.ruoyi.workflow.domain.vo.WfFormVo) ServiceException(com.ruoyi.common.exception.ServiceException) SysRole(com.ruoyi.common.core.domain.entity.SysRole) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance)

Example 9 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysDictTypeServiceImpl method deleteDictTypeByIds.

/**
 * 批量删除字典类型信息
 *
 * @param dictIds 需要删除的字典ID
 */
@Override
public void deleteDictTypeByIds(Long[] dictIds) {
    for (Long dictId : dictIds) {
        SysDictType dictType = selectDictTypeById(dictId);
        if (dictDataMapper.exists(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, dictType.getDictType()))) {
            throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
        }
        RedisUtils.deleteObject(getCacheKey(dictType.getDictType()));
    }
    baseMapper.deleteBatchIds(Arrays.asList(dictIds));
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDictType(com.ruoyi.common.core.domain.entity.SysDictType) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 10 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysOssConfigServiceImpl method deleteWithValidByIds.

@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
    if (isValid) {
        if (CollUtil.containsAny(ids, OssConstant.SYSTEM_DATA_IDS)) {
            throw new ServiceException("系统内置, 不可删除!");
        }
    }
    List<SysOssConfig> list = Lists.newArrayList();
    for (Long configId : ids) {
        SysOssConfig config = baseMapper.selectById(configId);
        list.add(config);
    }
    boolean flag = baseMapper.deleteBatchIds(ids) > 0;
    if (flag) {
        list.stream().forEach(sysOssConfig -> {
            RedisUtils.deleteObject(getCacheKey(sysOssConfig.getConfigKey()));
        });
    }
    return flag;
}
Also used : SysOssConfig(com.ruoyi.system.domain.SysOssConfig) ServiceException(com.ruoyi.common.exception.ServiceException)

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