Search in sources :

Example 76 with ServiceException

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

the class PlusDataPermissionHandler method buildDataFilter.

/**
 * 构造数据过滤sql
 */
private String buildDataFilter(DataColumn[] dataColumns, boolean isSelect) {
    StringBuilder sqlString = new StringBuilder();
    // 更新或删除需满足所有条件
    String joinStr = isSelect ? " OR " : " AND ";
    LoginUser user = DataPermissionHelper.getVariable("user");
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setBeanResolver(beanResolver);
    DataPermissionHelper.getContext().forEach(context::setVariable);
    for (RoleDTO role : user.getRoles()) {
        user.setRoleId(role.getRoleId());
        // 获取角色权限泛型
        DataScopeType type = DataScopeType.findCode(role.getDataScope());
        if (ObjectUtil.isNull(type)) {
            throw new ServiceException("角色数据范围异常 => " + role.getDataScope());
        }
        // 全部数据权限直接返回
        if (type == DataScopeType.ALL) {
            return "";
        }
        boolean isSuccess = false;
        for (DataColumn dataColumn : dataColumns) {
            // 不包含 key 变量 则不处理
            if (!StringUtils.contains(type.getSqlTemplate(), "#" + dataColumn.key())) {
                continue;
            }
            // 设置注解变量 key 为表达式变量 value 为变量值
            context.setVariable(dataColumn.key(), dataColumn.value());
            // 解析sql模板并填充
            String sql = parser.parseExpression(type.getSqlTemplate(), parserContext).getValue(context, String.class);
            sqlString.append(joinStr).append(sql);
            isSuccess = true;
        }
        // 未处理成功则填充兜底方案
        if (!isSuccess) {
            sqlString.append(joinStr).append(type.getElseSql());
        }
    }
    if (StringUtils.isNotBlank(sqlString.toString())) {
        return sqlString.substring(joinStr.length());
    }
    return "";
}
Also used : RoleDTO(com.ruoyi.common.core.domain.dto.RoleDTO) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) DataScopeType(com.ruoyi.common.enums.DataScopeType) ServiceException(com.ruoyi.common.exception.ServiceException) DataColumn(com.ruoyi.common.annotation.DataColumn) LoginUser(com.ruoyi.common.core.domain.model.LoginUser)

Example 77 with ServiceException

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

the class PlusDataPermissionHandler method getSqlSegment.

public Expression getSqlSegment(Expression where, String mappedStatementId, boolean isSelect) {
    DataColumn[] dataColumns = findAnnotation(mappedStatementId);
    if (ArrayUtil.isEmpty(dataColumns)) {
        inavlidCacheSet.add(mappedStatementId);
        return where;
    }
    LoginUser currentUser = DataPermissionHelper.getVariable("user");
    if (ObjectUtil.isNull(currentUser)) {
        currentUser = LoginHelper.getLoginUser();
        DataPermissionHelper.setVariable("user", currentUser);
    }
    // 如果是超级管理员,则不过滤数据
    if (LoginHelper.isAdmin()) {
        return where;
    }
    String dataFilterSql = buildDataFilter(dataColumns, isSelect);
    if (StringUtils.isBlank(dataFilterSql)) {
        return where;
    }
    try {
        Expression expression = CCJSqlParserUtil.parseExpression(dataFilterSql);
        // 数据权限使用单独的括号 防止与其他条件冲突
        Parenthesis parenthesis = new Parenthesis(expression);
        if (ObjectUtil.isNotNull(where)) {
            return new AndExpression(where, parenthesis);
        } else {
            return parenthesis;
        }
    } catch (JSQLParserException e) {
        throw new ServiceException("数据权限解析异常 => " + e.getMessage());
    }
}
Also used : Parenthesis(net.sf.jsqlparser.expression.Parenthesis) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) ServiceException(com.ruoyi.common.exception.ServiceException) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) Expression(net.sf.jsqlparser.expression.Expression) JSQLParserException(net.sf.jsqlparser.JSQLParserException) DataColumn(com.ruoyi.common.annotation.DataColumn) LoginUser(com.ruoyi.common.core.domain.model.LoginUser)

Example 78 with ServiceException

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

the class SysOssController method upload.

/**
 * 上传OSS对象存储
 */
@ApiOperation("上传OSS对象存储")
@ApiImplicitParams({ @ApiImplicitParam(name = "file", value = "文件", paramType = "query", dataTypeClass = File.class, required = true) })
@SaCheckPermission("system:oss:upload")
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
@PostMapping("/upload")
public R<Map<String, String>> upload(@RequestPart("file") MultipartFile file) {
    if (ObjectUtil.isNull(file)) {
        throw new ServiceException("上传文件不能为空");
    }
    SysOss oss = iSysOssService.upload(file);
    Map<String, String> map = new HashMap<>(2);
    map.put("url", oss.getUrl());
    map.put("fileName", oss.getFileName());
    return R.ok(map);
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) ServiceException(com.ruoyi.common.exception.ServiceException) HashMap(java.util.HashMap) Log(com.ruoyi.common.annotation.Log) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 79 with ServiceException

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

the class SysOssController method download.

@ApiOperation("下载OSS对象存储")
@SaCheckPermission("system:oss:download")
@GetMapping("/download/{ossId}")
public void download(@ApiParam("OSS对象ID") @PathVariable Long ossId, HttpServletResponse response) throws IOException {
    SysOss sysOss = iSysOssService.getById(ossId);
    if (ObjectUtil.isNull(sysOss)) {
        throw new ServiceException("文件数据不存在!");
    }
    response.reset();
    FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
    response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
    long data;
    try {
        data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false);
    } catch (HttpException e) {
        if (e.getMessage().contains("403")) {
            throw new ServiceException("无读取权限, 请在对应的OSS开启'公有读'权限!");
        } else {
            throw new ServiceException(e.getMessage());
        }
    }
    response.setContentLength(Convert.toInt(data));
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) ServiceException(com.ruoyi.common.exception.ServiceException) HttpException(cn.hutool.http.HttpException) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 80 with ServiceException

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

the class WfInstanceServiceImpl method startProcessInstanceById.

/**
 * 根据流程定义ID启动流程实例
 *
 * @param procDefId 流程定义Id
 * @param variables 流程变量
 * @return
 */
@Override
public void startProcessInstanceById(String procDefId, Map<String, Object> variables) {
    try {
        // 设置流程发起人Id到流程中
        String userIdStr = LoginHelper.getUserId().toString();
        // identityService.setAuthenticatedUserId(userId.toString());
        variables.put(ProcessConstants.PROCESS_INITIATOR, userIdStr);
        variables.put("_FLOWABLE_SKIP_EXPRESSION_ENABLED", true);
        runtimeService.startProcessInstanceById(procDefId, variables);
    } catch (Exception e) {
        e.printStackTrace();
        throw new ServiceException("流程启动错误");
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) ServiceException(com.ruoyi.common.exception.ServiceException) FlowableObjectNotFoundException(org.flowable.common.engine.api.FlowableObjectNotFoundException)

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