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);
}
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());
}
}
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;
}
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;
}
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("上传文件失败");
}
}
Aggregations