Search in sources :

Example 46 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysUserServiceImpl method checkUserDataScope.

/**
 * 校验用户是否有数据权限
 *
 * @param userId 用户id
 */
@Override
public void checkUserDataScope(Long userId) {
    if (!LoginHelper.isAdmin()) {
        SysUser user = new SysUser();
        user.setUserId(userId);
        List<SysUser> users = this.selectUserList(user);
        if (CollUtil.isEmpty(users)) {
            throw new ServiceException("没有权限访问用户数据!");
        }
    }
}
Also used : SysUser(com.ruoyi.system.api.domain.SysUser) ServiceException(com.ruoyi.common.core.exception.ServiceException)

Example 47 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysRoleServiceImpl method deleteRoleByIds.

/**
 * 批量删除角色信息
 *
 * @param roleIds 需要删除的角色ID
 * @return 结果
 */
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteRoleByIds(Long[] roleIds) {
    for (Long roleId : roleIds) {
        checkRoleAllowed(new SysRole(roleId));
        checkRoleDataScope(roleId);
        SysRole role = selectRoleById(roleId);
        if (countUserRoleByRoleId(roleId) > 0) {
            throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName()));
        }
    }
    List<Long> ids = Arrays.asList(roleIds);
    // 删除角色与菜单关联
    roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, ids));
    // 删除角色与部门关联
    roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().in(SysRoleDept::getRoleId, ids));
    return baseMapper.deleteBatchIds(ids);
}
Also used : ServiceException(com.ruoyi.common.core.exception.ServiceException) SysRole(com.ruoyi.system.api.domain.SysRole) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Plus by JavaLionLi.

the class CreateAndUpdateMetaObjectHandler method insertFill.

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

Example 49 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Plus by JavaLionLi.

the class RepeatSubmitAspect method doBefore.

@Before("@annotation(repeatSubmit)")
public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) throws Throwable {
    // 如果注解不为0 则使用注解数值
    long interval = repeatSubmit.timeUnit().toMillis(repeatSubmit.interval());
    if (interval < 1000) {
        throw new ServiceException("重复提交间隔时间不能小于'1'秒");
    }
    HttpServletRequest request = ServletUtils.getRequest();
    String nowParams = argsArrayToString(point.getArgs());
    // 请求地址(作为存放cache的key值)
    String url = request.getRequestURI();
    // 唯一值(没有消息头则使用请求地址)
    String submitKey = StringUtils.trimToEmpty(request.getHeader(SaManager.getConfig().getTokenName()));
    submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
    // 唯一标识(指定key + url + 消息头)
    String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + url + submitKey;
    String key = RedisUtils.getCacheObject(cacheRepeatKey);
    if (key == null) {
        RedisUtils.setCacheObject(cacheRepeatKey, "", Duration.ofMillis(interval));
        KEY_CACHE.set(cacheRepeatKey);
    } else {
        String message = repeatSubmit.message();
        if (StringUtils.startsWith(message, "{") && StringUtils.endsWith(message, "}")) {
            message = MessageUtils.message(StringUtils.substring(message, 1, message.length() - 1));
        }
        throw new ServiceException(message);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServiceException(com.ruoyi.common.core.exception.ServiceException) Before(org.aspectj.lang.annotation.Before)

Aggregations

ServiceException (com.ruoyi.common.core.exception.ServiceException)49 IOException (java.io.IOException)10 GenTable (com.ruoyi.gen.domain.GenTable)9 SysUser (com.ruoyi.system.api.domain.SysUser)9 Transactional (org.springframework.transaction.annotation.Transactional)7 GenTableColumn (com.ruoyi.gen.domain.GenTableColumn)6 SysDept (com.ruoyi.system.api.domain.SysDept)6 SysRole (com.ruoyi.system.api.domain.SysRole)6 StringWriter (java.io.StringWriter)6 Template (org.apache.velocity.Template)6 VelocityContext (org.apache.velocity.VelocityContext)6 File (java.io.File)5 JSONObject (com.alibaba.fastjson.JSONObject)4 SysOss (com.ruoyi.resource.domain.SysOss)4 LoginUser (com.ruoyi.system.api.model.LoginUser)4 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)3 Constants (com.ruoyi.common.core.constant.Constants)3 GenConstants (com.ruoyi.common.core.constant.GenConstants)3 StringUtils (com.ruoyi.common.core.utils.StringUtils)3 GenTableColumnMapper (com.ruoyi.gen.mapper.GenTableColumnMapper)3