Search in sources :

Example 16 with BusinessException

use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.

the class SysJobServiceImpl method updateJobById.

@Override
public void updateJobById(SysJobEntity sysJob) {
    SysJobEntity sysJobEntity = this.getById(sysJob.getId());
    if (sysJobEntity == null) {
        throw new BusinessException("获取定时任务异常");
    }
    sysJob.setStatus(sysJobEntity.getStatus());
    ScheduleUtils.updateScheduleJob(scheduler, sysJob);
    this.updateById(sysJob);
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysJobEntity(com.jun.plugin.system.entity.SysJobEntity)

Example 17 with BusinessException

use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.

the class DeptServiceImpl method updateDept.

@Override
@Transactional(rollbackFor = Exception.class)
public void updateDept(SysDept vo) {
    SysDept sysDept = sysDeptMapper.selectById(vo.getId());
    if (null == sysDept) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    sysDeptMapper.updateById(vo);
    // 说明层级发生了变化
    if (!StringUtils.isEmpty(vo.getPid()) && !vo.getPid().equals(sysDept.getPid())) {
        SysDept parent = sysDeptMapper.selectById(vo.getPid());
        if (!"0".equals(vo.getPid()) && null == parent) {
            throw new BusinessException(BaseResponseCode.DATA_ERROR);
        }
        SysDept oldParent = sysDeptMapper.selectById(sysDept.getPid());
        String oldRelationCode;
        String newRelationCode;
        // 根目录降到其他目录
        if ("0".equals(sysDept.getPid())) {
            oldRelationCode = sysDept.getDeptNo();
            newRelationCode = parent.getRelationCode() + sysDept.getDeptNo();
        } else if ("0".equals(vo.getPid())) {
            // 其他目录升级到跟目录
            oldRelationCode = sysDept.getRelationCode();
            newRelationCode = sysDept.getDeptNo();
        } else {
            oldRelationCode = oldParent.getRelationCode();
            newRelationCode = parent.getRelationCode();
        }
        LambdaQueryWrapper<SysDept> wrapper = Wrappers.lambdaQuery();
        wrapper.likeLeft(SysDept::getDeptNo, sysDept.getDeptNo());
        List<SysDept> list = sysDeptMapper.selectList(wrapper);
        list.parallelStream().forEach(entity -> {
            String relationCode = entity.getRelationCode().replace(oldRelationCode, newRelationCode);
            entity.setRelationCode(relationCode);
            sysDeptMapper.updateById(entity);
        });
    }
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysDept(com.jun.plugin.system.entity.SysDept) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with BusinessException

use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.

the class DeptServiceImpl method deleted.

@Override
public void deleted(String id) {
    SysDept sysDept = sysDeptMapper.selectById(id);
    if (null == sysDept) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    List<Object> deptIds = sysDeptMapper.selectObjs(Wrappers.<SysDept>lambdaQuery().select(SysDept::getId).likeRight(SysDept::getRelationCode, sysDept.getRelationCode()));
    List<SysUser> list = sysUserMapper.selectList(Wrappers.<SysUser>lambdaQuery().in(SysUser::getDeptId, deptIds));
    if (!CollectionUtils.isEmpty(list)) {
        throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT);
    }
    sysDeptMapper.deleteById(id);
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysUser(com.jun.plugin.system.entity.SysUser) SysDept(com.jun.plugin.system.entity.SysDept)

Example 19 with BusinessException

use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.

the class PermissionServiceImpl method deleted.

/**
 * 删除菜单权限
 * 判断是否 有角色关联
 * 判断是否有子集
 */
@Transactional(rollbackFor = Exception.class)
@Override
public void deleted(String permissionId) {
    // 获取关联userId
    List<String> userIds = getUserIdsById(permissionId);
    SysPermission sysPermission = sysPermissionMapper.selectById(permissionId);
    if (null == sysPermission) {
        log.error("传入 的 id:{}不合法", permissionId);
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    // 获取下一级
    List<SysPermission> childs = sysPermissionMapper.selectList(Wrappers.<SysPermission>lambdaQuery().eq(SysPermission::getPid, permissionId));
    if (!CollectionUtils.isEmpty(childs)) {
        throw new BusinessException(BaseResponseCode.ROLE_PERMISSION_RELATION);
    }
    sysPermissionMapper.deleteById(permissionId);
    // 删除和角色关联
    rolePermissionService.remove(Wrappers.<SysRolePermission>lambdaQuery().eq(SysRolePermission::getPermissionId, permissionId));
    if (!CollectionUtils.isEmpty(userIds)) {
        // 刷新权限
        userIds.parallelStream().forEach(httpSessionService::refreshUerId);
    }
}
Also used : SysRolePermission(com.jun.plugin.system.entity.SysRolePermission) BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysPermission(com.jun.plugin.system.entity.SysPermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with BusinessException

use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.

the class UserServiceImpl method updateUserInfo.

@Override
public void updateUserInfo(SysUser vo) {
    SysUser sysUser = sysUserMapper.selectById(vo.getId());
    if (null == sysUser) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    // 如果用户名变更
    if (!sysUser.getUsername().equals(vo.getUsername())) {
        SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
        if (sysUserOne != null) {
            throw new BusinessException("用户名已存在!");
        }
    }
    // 如果用户名、密码、状态 变更,删除redis中用户绑定的角色跟权限
    if (!sysUser.getUsername().equals(vo.getUsername()) || (!StringUtils.isEmpty(vo.getPassword()) && !sysUser.getPassword().equals(PasswordUtils.encode(vo.getPassword(), sysUser.getSalt()))) || !sysUser.getStatus().equals(vo.getStatus())) {
        httpSessionService.abortUserById(vo.getId());
    }
    if (!StringUtils.isEmpty(vo.getPassword())) {
        String newPassword = PasswordUtils.encode(vo.getPassword(), sysUser.getSalt());
        vo.setPassword(newPassword);
    } else {
        vo.setPassword(null);
    }
    vo.setUpdateId(httpSessionService.getCurrentUserId());
    sysUserMapper.updateById(vo);
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysUser(com.jun.plugin.system.entity.SysUser)

Aggregations

BusinessException (com.jun.plugin.system.common.exception.BusinessException)32 SysUser (com.jun.plugin.system.entity.SysUser)7 SysDept (com.jun.plugin.system.entity.SysDept)5 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 SysPermission (com.jun.plugin.system.entity.SysPermission)3 SysRolePermission (com.jun.plugin.system.entity.SysRolePermission)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Algorithm (com.auth0.jwt.algorithms.Algorithm)2 SysRole (com.jun.plugin.system.entity.SysRole)2 DeptRespNodeVO (com.jun.plugin.system.vo.resp.DeptRespNodeVO)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SecureRandom (java.security.SecureRandom)2 BadPaddingException (javax.crypto.BadPaddingException)2 Cipher (javax.crypto.Cipher)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 KeyGenerator (javax.crypto.KeyGenerator)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2 SecretKey (javax.crypto.SecretKey)2