部门列表接口
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package cn.iocoder.mall.admin.convert;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO;
|
||||
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO;
|
||||
import cn.iocoder.mall.admin.dataobject.DeptmentDO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
*
|
||||
@@ -25,4 +30,9 @@ public interface DeptmentConvert {
|
||||
@Mappings({})
|
||||
DeptmentBO convert(DeptmentDO deptmentDO);
|
||||
|
||||
@Mappings({@Mapping(source = "records", target = "list")})
|
||||
PageResult<DeptmentBO> convert(IPage<DeptmentDO> list);
|
||||
|
||||
@Mappings({})
|
||||
List<DeptmentBO> convert(List<DeptmentDO> list);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package cn.iocoder.mall.admin.dao;
|
||||
|
||||
import cn.iocoder.common.framework.mybatis.QueryWrapperX;
|
||||
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentPageDTO;
|
||||
import cn.iocoder.mall.admin.dataobject.AdminDO;
|
||||
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 org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
*
|
||||
@@ -23,5 +29,24 @@ public interface DeptmentMapper extends BaseMapper<DeptmentDO> {
|
||||
);
|
||||
}
|
||||
|
||||
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,16 +1,22 @@
|
||||
package cn.iocoder.mall.admin.service;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.admin.api.DeptmentService;
|
||||
import cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO;
|
||||
import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum;
|
||||
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.DeptmentPageDTO;
|
||||
import cn.iocoder.mall.admin.convert.DeptmentConvert;
|
||||
import cn.iocoder.mall.admin.dao.DeptmentMapper;
|
||||
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 java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
*
|
||||
@@ -25,17 +31,36 @@ public class DeptmentServiceImpl implements DeptmentService {
|
||||
private DeptmentMapper deptmentMapper;
|
||||
|
||||
@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);
|
||||
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
|
||||
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