|
|
|
@ -1,5 +1,6 @@
|
|
|
|
package cn.iocoder.mall.admin.service;
|
|
|
|
package cn.iocoder.mall.admin.service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.common.framework.util.ExceptionUtil;
|
|
|
|
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
|
|
|
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
|
|
|
import cn.iocoder.common.framework.vo.PageResult;
|
|
|
|
import cn.iocoder.common.framework.vo.PageResult;
|
|
|
|
import cn.iocoder.mall.admin.api.DeptmentService;
|
|
|
|
import cn.iocoder.mall.admin.api.DeptmentService;
|
|
|
|
@ -8,12 +9,17 @@ import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum;
|
|
|
|
import cn.iocoder.mall.admin.api.constant.DeptmentConstants;
|
|
|
|
import cn.iocoder.mall.admin.api.constant.DeptmentConstants;
|
|
|
|
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO;
|
|
|
|
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO;
|
|
|
|
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentPageDTO;
|
|
|
|
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentPageDTO;
|
|
|
|
|
|
|
|
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentUpdateDTO;
|
|
|
|
import cn.iocoder.mall.admin.convert.DeptmentConvert;
|
|
|
|
import cn.iocoder.mall.admin.convert.DeptmentConvert;
|
|
|
|
import cn.iocoder.mall.admin.dao.DeptmentMapper;
|
|
|
|
import cn.iocoder.mall.admin.dao.DeptmentMapper;
|
|
|
|
|
|
|
|
import cn.iocoder.mall.admin.dao.DeptmentRoleMapper;
|
|
|
|
import cn.iocoder.mall.admin.dataobject.DeptmentDO;
|
|
|
|
import cn.iocoder.mall.admin.dataobject.DeptmentDO;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@ -30,6 +36,9 @@ public class DeptmentServiceImpl implements DeptmentService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private DeptmentMapper deptmentMapper;
|
|
|
|
private DeptmentMapper deptmentMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private DeptmentRoleMapper deptmentRoleMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public DeptmentBO addDeptment(Integer adminId, DeptmentAddDTO deptmentAddDTO) {
|
|
|
|
public DeptmentBO addDeptment(Integer adminId, DeptmentAddDTO deptmentAddDTO) {
|
|
|
|
if (deptmentAddDTO.getPid() != 0 &&
|
|
|
|
if (deptmentAddDTO.getPid() != 0 &&
|
|
|
|
@ -45,6 +54,49 @@ public class DeptmentServiceImpl implements DeptmentService {
|
|
|
|
return DeptmentConvert.INSTANCE.convert(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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
@Override
|
|
|
|
public PageResult<DeptmentBO> getPageRootDeptment(DeptmentPageDTO deptmentPageDTO) {
|
|
|
|
public PageResult<DeptmentBO> getPageRootDeptment(DeptmentPageDTO deptmentPageDTO) {
|
|
|
|
IPage<DeptmentDO> page = deptmentMapper.selectDeptPage(deptmentPageDTO, DeptmentConstants.PID_ROOT);
|
|
|
|
IPage<DeptmentDO> page = deptmentMapper.selectDeptPage(deptmentPageDTO, DeptmentConstants.PID_ROOT);
|
|
|
|
|