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();
}
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));
}
Aggregations