Search in sources :

Example 11 with BusinessException

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

the class UserServiceImpl method updateUserInfoMy.

@Override
public void updateUserInfoMy(SysUser vo) {
    SysUser user = sysUserMapper.selectById(httpSessionService.getCurrentUserId());
    if (null == user) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    if (!StringUtils.isEmpty(vo.getPassword())) {
        String newPassword = PasswordUtils.encode(vo.getPassword(), user.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)

Example 12 with BusinessException

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

the class RoleServiceImpl method updateRole.

@Transactional(rollbackFor = Exception.class)
@Override
public void updateRole(SysRole vo) {
    SysRole sysRole = sysRoleMapper.selectById(vo.getId());
    if (null == sysRole) {
        log.error("传入 的 id:{}不合法", vo.getId());
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    sysRoleMapper.updateById(vo);
    // 删除角色权限关联
    rolePermissionService.remove(Wrappers.<SysRolePermission>lambdaQuery().eq(SysRolePermission::getRoleId, sysRole.getId()));
    if (!CollectionUtils.isEmpty(vo.getPermissions())) {
        RolePermissionOperationReqVO reqVO = new RolePermissionOperationReqVO();
        reqVO.setRoleId(sysRole.getId());
        reqVO.setPermissionIds(vo.getPermissions());
        rolePermissionService.addRolePermission(reqVO);
        // 刷新权限
        httpSessionService.refreshRolePermission(sysRole.getId());
    }
}
Also used : SysRolePermission(com.jun.plugin.system.entity.SysRolePermission) BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysRole(com.jun.plugin.system.entity.SysRole) RolePermissionOperationReqVO(com.jun.plugin.system.vo.req.RolePermissionOperationReqVO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with BusinessException

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

the class RoleServiceImpl method detailInfo.

@Override
public SysRole detailInfo(String id) {
    SysRole sysRole = sysRoleMapper.selectById(id);
    if (sysRole == null) {
        log.error("传入 的 id:{}不合法", id);
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    List<PermissionRespNode> permissionRespNodes = permissionService.selectAllByTree();
    LambdaQueryWrapper<SysRolePermission> queryWrapper = Wrappers.<SysRolePermission>lambdaQuery().select(SysRolePermission::getPermissionId).eq(SysRolePermission::getRoleId, sysRole.getId());
    Set<Object> checkList = new HashSet<>(rolePermissionService.listObjs(queryWrapper));
    setChecked(permissionRespNodes, checkList);
    sysRole.setPermissionRespNodes(permissionRespNodes);
    LambdaQueryWrapper<SysRoleDeptEntity> queryWrapperDept = Wrappers.<SysRoleDeptEntity>lambdaQuery().select(SysRoleDeptEntity::getDeptId).eq(SysRoleDeptEntity::getRoleId, sysRole.getId());
    List<DeptRespNodeVO> deptRespNodes = deptService.deptTreeList(null, true);
    Set<Object> checkDeptList = new HashSet<>(sysRoleDeptService.listObjs(queryWrapperDept));
    setCheckedDept(deptRespNodes, checkDeptList);
    sysRole.setDeptRespNodes(deptRespNodes);
    return sysRole;
}
Also used : SysRolePermission(com.jun.plugin.system.entity.SysRolePermission) PermissionRespNode(com.jun.plugin.system.vo.resp.PermissionRespNode) DeptRespNodeVO(com.jun.plugin.system.vo.resp.DeptRespNodeVO) BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysRole(com.jun.plugin.system.entity.SysRole) SysRoleDeptEntity(com.jun.plugin.system.entity.SysRoleDeptEntity) HashSet(java.util.HashSet)

Example 14 with BusinessException

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

the class SysDictDetailServiceImpl method listByPage.

@Override
public IPage<SysDictDetailEntity> listByPage(Page<SysDictDetailEntity> page, String dictId) {
    SysDictEntity sysDictEntity = sysDictMapper.selectById(dictId);
    if (sysDictEntity == null) {
        throw new BusinessException("获取字典数据失败!");
    }
    LambdaQueryWrapper<SysDictDetailEntity> wrapper = Wrappers.lambdaQuery();
    wrapper.eq(SysDictDetailEntity::getDictId, dictId);
    wrapper.orderByAsc(SysDictDetailEntity::getSort);
    IPage<SysDictDetailEntity> result = sysDictDetailMapper.selectPage(page, wrapper);
    if (!CollectionUtils.isEmpty(result.getRecords())) {
        result.getRecords().parallelStream().forEach(entity -> entity.setDictName(sysDictEntity.getName()));
    }
    return result;
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysDictDetailEntity(com.jun.plugin.system.entity.SysDictDetailEntity) SysDictEntity(com.jun.plugin.system.entity.SysDictEntity)

Example 15 with BusinessException

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

the class SysFilesServiceImpl method saveFile.

@Override
public DataResult saveFile(MultipartFile file) {
    // 存储文件夹
    String createTime = DateUtils.format(new Date(), DateUtils.DATEPATTERN);
    String newPath = fileUploadProperties.getPath() + createTime + File.separator;
    File uploadDirectory = new File(newPath);
    if (uploadDirectory.exists()) {
        if (!uploadDirectory.isDirectory()) {
            uploadDirectory.delete();
        }
    } else {
        uploadDirectory.mkdir();
    }
    try {
        String fileName = file.getOriginalFilename();
        // id与filename保持一直,删除文件
        String fileNameNew = UUID.randomUUID().toString().replace("-", "") + getFileType(fileName);
        String newFilePathName = newPath + fileNameNew;
        String url = fileUploadProperties.getUrl() + "/" + createTime + "/" + fileNameNew;
        // 创建输出文件对象
        File outFile = new File(newFilePathName);
        // 拷贝文件到输出文件对象
        FileUtils.copyInputStreamToFile(file.getInputStream(), outFile);
        // 保存文件记录
        SysFilesEntity sysFilesEntity = new SysFilesEntity();
        sysFilesEntity.setFileName(fileName);
        sysFilesEntity.setFilePath(newFilePathName);
        sysFilesEntity.setUrl(url);
        this.save(sysFilesEntity);
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("src", url);
        return DataResult.success(resultMap);
    } catch (Exception e) {
        throw new BusinessException("上传文件失败");
    }
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) SysFilesEntity(com.jun.plugin.system.entity.SysFilesEntity) BusinessException(com.jun.plugin.system.common.exception.BusinessException)

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