Search in sources :

Example 6 with SysDept

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);
        });
    }
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysDept(com.jun.plugin.system.entity.SysDept) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with SysDept

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);
}
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 8 with SysDept

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;
}
Also used : DeptRespNodeVO(com.jun.plugin.system.vo.resp.DeptRespNodeVO) SysDept(com.jun.plugin.system.entity.SysDept) ArrayList(java.util.ArrayList)

Example 9 with SysDept

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;
}
Also used : SysUser(com.jun.plugin.system.entity.SysUser) SysDept(com.jun.plugin.system.entity.SysDept) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage)

Example 10 with SysDept

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;
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) LoginRespVO(com.jun.plugin.system.vo.resp.LoginRespVO) SysUser(com.jun.plugin.system.entity.SysUser) SysDept(com.jun.plugin.system.entity.SysDept)

Aggregations

SysDept (com.jun.plugin.system.entity.SysDept)10 BusinessException (com.jun.plugin.system.common.exception.BusinessException)5 SysUser (com.jun.plugin.system.entity.SysUser)4 DeptRespNodeVO (com.jun.plugin.system.vo.resp.DeptRespNodeVO)3 ArrayList (java.util.ArrayList)3 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 LogAnnotation (com.jun.plugin.system.common.aop.annotation.LogAnnotation)1 HomeRespVO (com.jun.plugin.system.vo.resp.HomeRespVO)1 LoginRespVO (com.jun.plugin.system.vo.resp.LoginRespVO)1 PermissionRespNode (com.jun.plugin.system.vo.resp.PermissionRespNode)1 UserInfoRespVO (com.jun.plugin.system.vo.resp.UserInfoRespVO)1 ApiOperation (io.swagger.annotations.ApiOperation)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 Transactional (org.springframework.transaction.annotation.Transactional)1