删除已迁移的代码
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
package cn.iocoder.mall.admin.dao;
|
||||
|
||||
import cn.iocoder.common.framework.mybatis.QueryWrapperX;
|
||||
import cn.iocoder.mall.system.api.dto.depetment.DeptmentPageDTO;
|
||||
import cn.iocoder.mall.admin.dataobject.DeptmentDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
*
|
||||
* @author: zhenxianyimeng
|
||||
* @date: 2019-06-14
|
||||
* @time: 19:26
|
||||
*/
|
||||
public interface DeptmentMapper extends BaseMapper<DeptmentDO> {
|
||||
|
||||
default DeptmentDO findDeptByNameAndPid(String name, Integer pid){
|
||||
return selectOne(new QueryWrapper<DeptmentDO>()
|
||||
.eq("name", name)
|
||||
.eq("pid", pid)
|
||||
.eq("deleted", false)
|
||||
);
|
||||
}
|
||||
|
||||
default IPage<DeptmentDO> selectDeptPage(DeptmentPageDTO deptmentPageDTO, Integer pid){
|
||||
return selectPage(new Page<>(deptmentPageDTO.getPageNo(), deptmentPageDTO.getPageSize()),
|
||||
new QueryWrapperX<DeptmentDO>()
|
||||
.likeIfPresent("name", deptmentPageDTO.getName())
|
||||
.eqIfPresent("pid", pid)
|
||||
.eq("deleted", false));
|
||||
|
||||
}
|
||||
|
||||
default List<DeptmentDO> getDeptByPid(Integer pid){
|
||||
return selectList(new QueryWrapperX<DeptmentDO>()
|
||||
.eqIfPresent("pid", pid)
|
||||
.eq("deleted", false));
|
||||
}
|
||||
|
||||
default List<DeptmentDO> getDeptExcudePid(Integer pid){
|
||||
return selectList(new QueryWrapper<DeptmentDO>()
|
||||
.ne("pid",pid)
|
||||
.eq("deleted",false));
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package cn.iocoder.mall.admin.dao;
|
||||
|
||||
import cn.iocoder.mall.admin.dataobject.DeptmentRoleDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
*
|
||||
* @author: zhenxianyimeng
|
||||
* @date: 2019-06-14
|
||||
* @time: 19:27
|
||||
*/
|
||||
public interface DeptmentRoleMapper extends BaseMapper<DeptmentRoleDO> {
|
||||
|
||||
default int deleteByDeptmentId(Integer deptmentId){
|
||||
return delete(new QueryWrapper<DeptmentRoleDO>().eq("deptment_id", deptmentId));
|
||||
}
|
||||
|
||||
default int deleteByRoleId(Integer roleId){
|
||||
return delete(new QueryWrapper<DeptmentRoleDO>().eq("role_id", roleId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package cn.iocoder.mall.admin.service;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.system.api.DeptmentService;
|
||||
import cn.iocoder.mall.system.api.bo.deptment.DeptmentBO;
|
||||
import cn.iocoder.mall.system.api.constant.AdminErrorCodeEnum;
|
||||
import cn.iocoder.mall.system.api.constant.DeptmentConstants;
|
||||
import cn.iocoder.mall.system.api.dto.depetment.DeptmentAddDTO;
|
||||
import cn.iocoder.mall.system.api.dto.depetment.DeptmentPageDTO;
|
||||
import cn.iocoder.mall.system.api.dto.depetment.DeptmentUpdateDTO;
|
||||
import cn.iocoder.mall.admin.convert.DeptmentConvert;
|
||||
import cn.iocoder.mall.admin.dao.AdminMapper;
|
||||
import cn.iocoder.mall.admin.dao.DeptmentMapper;
|
||||
import cn.iocoder.mall.admin.dao.DeptmentRoleMapper;
|
||||
import cn.iocoder.mall.admin.dataobject.DeptmentDO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
*
|
||||
* @author: zhenxianyimeng
|
||||
* @date: 2019-06-14
|
||||
* @time: 19:30
|
||||
*/
|
||||
@Service
|
||||
public class DeptmentServiceImpl implements DeptmentService {
|
||||
|
||||
@Autowired
|
||||
private DeptmentMapper deptmentMapper;
|
||||
|
||||
@Autowired
|
||||
private DeptmentRoleMapper deptmentRoleMapper;
|
||||
|
||||
@Autowired
|
||||
private AdminMapper adminMapper;
|
||||
|
||||
@Override
|
||||
public DeptmentBO addDeptment(Integer adminId, DeptmentAddDTO deptmentAddDTO) {
|
||||
if (deptmentAddDTO.getPid() != 0 &&
|
||||
deptmentMapper.selectById(deptmentAddDTO.getPid()) == null) {
|
||||
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DEPT_PARENT_NOT_EXITS.getCode());
|
||||
}
|
||||
//不同的大部门下好像可以小部门名字一样,验证同级别部门名字
|
||||
if (null != deptmentMapper.findDeptByNameAndPid(deptmentAddDTO.getName(), deptmentAddDTO.getPid())) {
|
||||
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DEPT_SAME_LEVEL_NAME_EXITS.getCode());
|
||||
}
|
||||
DeptmentDO deptmentDO = DeptmentConvert.INSTANCE.convert(deptmentAddDTO);
|
||||
deptmentMapper.insert(deptmentDO);
|
||||
return DeptmentConvert.INSTANCE.convert(deptmentDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deleteDeptment(Integer adminId, Integer deptmentId) {
|
||||
if(deptmentMapper.selectById(deptmentId) == null){
|
||||
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DEPT_NOT_EXITS.getCode());
|
||||
}
|
||||
|
||||
if(!CollectionUtils.isEmpty(deptmentMapper.getDeptByPid(deptmentId))){
|
||||
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DEPT_EXITS_CHILDREN.getCode());
|
||||
}
|
||||
|
||||
deptmentMapper.deleteById(deptmentId);
|
||||
|
||||
deptmentRoleMapper.deleteByDeptmentId(deptmentId);
|
||||
|
||||
//将改部门下所有员工的DeptmentID设置为0
|
||||
adminMapper.updateDeptByDeptId(deptmentId, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean updateDeptment(Integer adminId, DeptmentUpdateDTO deptmentUpdateDTO) {
|
||||
//判断需要更新的部门是否存在
|
||||
if(deptmentMapper.selectById(deptmentUpdateDTO.getId()) == null){
|
||||
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DEPT_NOT_EXITS.getCode());
|
||||
}
|
||||
|
||||
//不能选择当前部门作为自己的父级部门
|
||||
if(deptmentUpdateDTO.getId().equals(deptmentUpdateDTO.getPid())){
|
||||
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DEPT_PARENT_NOT_LEGAL.getCode());
|
||||
}
|
||||
|
||||
if(deptmentUpdateDTO.getPid()!=null &&
|
||||
!DeptmentConstants.PID_ROOT.equals(deptmentUpdateDTO.getPid())
|
||||
&& deptmentMapper.selectById(deptmentUpdateDTO.getPid())==null){
|
||||
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DEPT_PARENT_NOT_EXITS.getCode());
|
||||
}
|
||||
|
||||
DeptmentDO deptmentDO = DeptmentConvert.INSTANCE.convert(deptmentUpdateDTO);
|
||||
deptmentMapper.updateById(deptmentDO);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<DeptmentBO> getPageRootDeptment(DeptmentPageDTO deptmentPageDTO) {
|
||||
IPage<DeptmentDO> page = deptmentMapper.selectDeptPage(deptmentPageDTO, DeptmentConstants.PID_ROOT);
|
||||
return DeptmentConvert.INSTANCE.convert(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptmentBO> getAllDeptments() {
|
||||
List<DeptmentDO> list = deptmentMapper.getDeptByPid(null);
|
||||
return DeptmentConvert.INSTANCE.convert(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptmentBO> getAllNotRootDeptment() {
|
||||
List<DeptmentDO> list = deptmentMapper.getDeptExcudePid(DeptmentConstants.PID_ROOT);
|
||||
return DeptmentConvert.INSTANCE.convert(list);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user