Search in sources :

Example 21 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class WriteInterceptor method intercept.

@Override
@SneakyThrows
public Object intercept(Invocation invocation) {
    // 为什么在拦截器里使用 @RefreshScope 无效?
    if (SpringContextHolder.getApplicationContext() == null) {
        return invocation.proceed();
    }
    if (!SpringContextHolder.getApplicationContext().getEnvironment().getProperty("application.database.isNotWrite", Boolean.class, false)) {
        return invocation.proceed();
    }
    StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget());
    MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
    // sqlParser(metaObject);
    // 读操作 放行
    MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
    if (SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) {
        return invocation.proceed();
    }
    // 记录日志相关的 放行
    if (StrUtil.containsAnyIgnoreCase(mappedStatement.getId(), "uid", "resetPassErrorNum", "updateLastLoginTime")) {
        return invocation.proceed();
    }
    // userId=1 的超级管理员 放行
    Long userId = ContextUtil.getUserId();
    String tenant = ContextUtil.getTenant();
    log.info("mapper id={}, userId={}", mappedStatement.getId(), userId);
    // 演示用的超级管理员 能查 和 增
    if (Long.valueOf(2).equals(userId) && (DELETE.equals(mappedStatement.getSqlCommandType()))) {
        throw new BizException(-1, "演示环境,无删除权限,请本地部署后测试");
    }
    // 内置的租户 不能 修改、删除 权限数据
    boolean isAuthority = StrUtil.containsAnyIgnoreCase(mappedStatement.getId(), "Tenant", "GlobalUser", "User", "Menu", "Resource", "Role", "Dictionary", "Parameter", "Application");
    boolean isWrite = CollectionUtil.contains(Arrays.asList(DELETE, UPDATE, INSERT), mappedStatement.getSqlCommandType());
    if ("0000".equals(tenant) && isWrite && isAuthority) {
        throw new BizException(-1, "演示环境禁止修改、删除重要数据!请登录租户【0000】,账号【manage】创建其他租户管理员账号后测试全部功能");
    }
    // 放行
    return invocation.proceed();
}
Also used : SystemMetaObject(org.apache.ibatis.reflection.SystemMetaObject) MetaObject(org.apache.ibatis.reflection.MetaObject) BizException(com.albedo.java.common.core.exception.BizException) StatementHandler(org.apache.ibatis.executor.statement.StatementHandler) MappedStatement(org.apache.ibatis.mapping.MappedStatement) SneakyThrows(lombok.SneakyThrows)

Example 22 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class TreeService method removeByIds.

/**
 * removeByIds
 *
 * @param idList 主键ID或实体列表
 * @return boolean
 */
@Override
default boolean removeByIds(Collection<?> idList) {
    idList.forEach(id -> {
        // 查询父节点为当前节点的节点
        List<T> menuList = this.list(Wrappers.<T>query().eq(TreeDo.F_SQL_PARENT_ID, id));
        ArgumentAssert.notEmpty(menuList, () -> new BizException("含有下级不能删除"));
    });
    return CollectionUtils.isEmpty(idList) ? false : SqlHelper.retBool(this.getBaseMapper().deleteBatchIds(idList));
}
Also used : BizException(com.albedo.java.common.core.exception.BizException)

Aggregations

BizException (com.albedo.java.common.core.exception.BizException)22 UserDo (com.albedo.java.modules.sys.domain.UserDo)3 SneakyThrows (lombok.SneakyThrows)3 RoleDo (com.albedo.java.modules.sys.domain.RoleDo)2 AlipayClient (com.alipay.api.AlipayClient)2 DefaultAlipayClient (com.alipay.api.DefaultAlipayClient)2 IORuntimeException (cn.hutool.core.io.IORuntimeException)1 TableColumnDo (com.albedo.java.modules.gen.domain.TableColumnDo)1 TableDo (com.albedo.java.modules.gen.domain.TableDo)1 SchemeDto (com.albedo.java.modules.gen.domain.dto.SchemeDto)1 TableDto (com.albedo.java.modules.gen.domain.dto.TableDto)1 TemplateVo (com.albedo.java.modules.gen.domain.vo.TemplateVo)1 GenConfig (com.albedo.java.modules.gen.domain.xml.GenConfig)1 Job (com.albedo.java.modules.quartz.domain.Job)1 DictCacheKeyBuilder (com.albedo.java.modules.sys.cache.DictCacheKeyBuilder)1 DeptDo (com.albedo.java.modules.sys.domain.DeptDo)1 DictDo (com.albedo.java.modules.sys.domain.DictDo)1 LogOperateDo (com.albedo.java.modules.sys.domain.LogOperateDo)1 MenuDo (com.albedo.java.modules.sys.domain.MenuDo)1 RoleMenuDo (com.albedo.java.modules.sys.domain.RoleMenuDo)1