use of com.jun.plugin.system.entity.SysDept 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.entity.SysDept 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.entity.SysDept in project jun_springboot_api_service by wujun728.
the class DeptServiceImpl method getTree.
private List<DeptRespNodeVO> getTree(List<SysDept> all) {
List<DeptRespNodeVO> list = new ArrayList<>();
for (SysDept sysDept : all) {
if ("0".equals(sysDept.getPid())) {
DeptRespNodeVO deptTree = new DeptRespNodeVO();
BeanUtils.copyProperties(sysDept, deptTree);
deptTree.setTitle(sysDept.getName());
deptTree.setSpread(true);
deptTree.setChildren(getChild(sysDept.getId(), all));
list.add(deptTree);
}
}
return list;
}
use of com.jun.plugin.system.entity.SysDept in project jun_springboot_api_service by wujun728.
the class UserServiceImpl method pageInfo.
@Override
public IPage<SysUser> pageInfo(SysUser vo) {
Page page = new Page(vo.getPage(), vo.getLimit());
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery();
if (!StringUtils.isEmpty(vo.getUsername())) {
queryWrapper.like(SysUser::getUsername, vo.getUsername());
}
if (!StringUtils.isEmpty(vo.getStartTime())) {
queryWrapper.gt(SysUser::getCreateTime, vo.getStartTime());
}
if (!StringUtils.isEmpty(vo.getEndTime())) {
queryWrapper.lt(SysUser::getCreateTime, vo.getEndTime());
}
if (!StringUtils.isEmpty(vo.getNickName())) {
queryWrapper.like(SysUser::getNickName, vo.getNickName());
}
if (null != vo.getStatus()) {
queryWrapper.eq(SysUser::getStatus, vo.getStatus());
}
if (!StringUtils.isEmpty(vo.getDeptNo())) {
LambdaQueryWrapper<SysDept> queryWrapperDept = Wrappers.lambdaQuery();
queryWrapperDept.select(SysDept::getId).like(SysDept::getRelationCode, vo.getDeptNo());
List<Object> list = sysDeptMapper.selectObjs(queryWrapperDept);
queryWrapper.in(SysUser::getDeptId, list);
}
queryWrapper.orderByDesc(SysUser::getCreateTime);
IPage<SysUser> iPage = sysUserMapper.selectPage(page, queryWrapper);
if (!CollectionUtils.isEmpty(iPage.getRecords())) {
for (SysUser sysUser : iPage.getRecords()) {
SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId());
if (sysDept != null) {
sysUser.setDeptName(sysDept.getName());
}
}
}
return iPage;
}
use of com.jun.plugin.system.entity.SysDept in project jun_springboot_api_service by wujun728.
the class UserServiceImpl method login.
@Override
public LoginRespVO login(SysUser vo) {
SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
if (null == sysUser) {
throw new BusinessException(BaseResponseCode.NOT_ACCOUNT);
}
if (sysUser.getStatus() == 2) {
throw new BusinessException(BaseResponseCode.USER_LOCK);
}
if (!PasswordUtils.matches(sysUser.getSalt(), vo.getPassword(), sysUser.getPassword())) {
throw new BusinessException(BaseResponseCode.PASSWORD_ERROR);
}
LoginRespVO respVO = new LoginRespVO();
BeanUtils.copyProperties(sysUser, respVO);
// true:允许多处登陆; false:只能单处登陆,顶掉之前登陆
if (!allowMultipleLogin) {
httpSessionService.abortUserById(sysUser.getId());
}
if (StringUtils.isNotBlank(sysUser.getDeptId())) {
SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId());
if (sysDept != null) {
sysUser.setDeptNo(sysDept.getDeptNo());
}
}
String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId()));
respVO.setAccessToken(token);
respVO.setJwtToken(JwtUtil.sign(vo.getUsername()));
return respVO;
}
Aggregations