Search in sources :

Example 71 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-fast by yangzongzhuan.

the class SysConfigServiceImpl method deleteConfigByIds.

/**
 * 批量删除参数信息
 *
 * @param configIds 需要删除的参数ID
 */
@Override
public void deleteConfigByIds(Long[] configIds) {
    for (Long configId : configIds) {
        SysConfig config = selectConfigById(configId);
        if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {
            throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
        }
        configMapper.deleteConfigById(configId);
        redisCache.deleteObject(getCacheKey(config.getConfigKey()));
    }
}
Also used : SysConfig(com.ruoyi.project.system.domain.SysConfig) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 72 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-fast by yangzongzhuan.

the class SysDeptServiceImpl method checkDeptDataScope.

/**
 * 校验部门是否有数据权限
 *
 * @param deptId 部门id
 */
@Override
public void checkDeptDataScope(Long deptId) {
    if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
        SysDept dept = new SysDept();
        dept.setDeptId(deptId);
        List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
        if (StringUtils.isEmpty(depts)) {
            throw new ServiceException("没有权限访问部门数据!");
        }
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDept(com.ruoyi.project.system.domain.SysDept)

Example 73 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-fast by yangzongzhuan.

the class SysDeptServiceImpl method insertDept.

/**
 * 新增保存部门信息
 *
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int insertDept(SysDept dept) {
    SysDept info = deptMapper.selectDeptById(dept.getParentId());
    // 如果父节点不为正常状态,则不允许新增子节点
    if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
        throw new ServiceException("部门停用,不允许新增");
    }
    dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
    return deptMapper.insertDept(dept);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDept(com.ruoyi.project.system.domain.SysDept)

Example 74 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-fast by yangzongzhuan.

the class SysDictTypeServiceImpl method deleteDictTypeByIds.

/**
 * 批量删除字典类型信息
 *
 * @param dictIds 需要删除的字典ID
 */
@Override
public void deleteDictTypeByIds(Long[] dictIds) {
    for (Long dictId : dictIds) {
        SysDictType dictType = selectDictTypeById(dictId);
        if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) {
            throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
        }
        dictTypeMapper.deleteDictTypeById(dictId);
        DictUtils.removeDictCache(dictType.getDictType());
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDictType(com.ruoyi.project.system.domain.SysDictType)

Example 75 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-fast by yangzongzhuan.

the class SysLoginService method login.

/**
 * 登录验证
 *
 * @param username 用户名
 * @param password 密码
 * @param code 验证码
 * @param uuid 唯一标识
 * @return 结果
 */
public String login(String username, String password, String code, String uuid) {
    boolean captchaOnOff = configService.selectCaptchaOnOff();
    // 验证码开关
    if (captchaOnOff) {
        validateCaptcha(username, code, uuid);
    }
    // 用户验证
    Authentication authentication = null;
    try {
        // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
        authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
    } catch (Exception e) {
        if (e instanceof BadCredentialsException) {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
            throw new UserPasswordNotMatchException();
        } else {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
            throw new ServiceException(e.getMessage());
        }
    }
    AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
    LoginUser loginUser = (LoginUser) authentication.getPrincipal();
    recordLoginInfo(loginUser.getUserId());
    // 生成token
    return tokenService.createToken(loginUser);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException) LoginUser(com.ruoyi.framework.security.LoginUser) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) ServiceException(com.ruoyi.common.exception.ServiceException) CaptchaExpireException(com.ruoyi.common.exception.user.CaptchaExpireException) CaptchaException(com.ruoyi.common.exception.user.CaptchaException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException)

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