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);
}
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);
});
}
}
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);
}
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);
}
}
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);
}
Aggregations