完成岗位的迁移
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.dept;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -22,4 +26,42 @@ public interface SysPostService {
|
||||
*/
|
||||
List<SysPostDO> listPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses);
|
||||
|
||||
/**
|
||||
* 获得岗位分页列表
|
||||
*
|
||||
* @param reqVO 分页条件
|
||||
* @return 部门分页列表
|
||||
*/
|
||||
PageResult<SysPostDO> pagePosts(SysPostPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得岗位信息
|
||||
*
|
||||
* @param id 岗位编号
|
||||
* @return 岗位信息
|
||||
*/
|
||||
SysPostDO getPost(Long id);
|
||||
|
||||
/**
|
||||
* 创建岗位
|
||||
*
|
||||
* @param reqVO 岗位信息
|
||||
* @return 岗位编号
|
||||
*/
|
||||
Long createPost(SysPostCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新岗位
|
||||
*
|
||||
* @param reqVO 岗位信息
|
||||
*/
|
||||
void updatePost(SysPostUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 删除岗位信息
|
||||
*
|
||||
* @param id 岗位编号
|
||||
*/
|
||||
void deletePost(Long id);
|
||||
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class SysDeptServiceImpl implements SysDeptService {
|
||||
if (parentId.equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_PARENT_ERROR);
|
||||
}
|
||||
// 父菜单不存在
|
||||
// 父岗位不存在
|
||||
SysDeptDO dept = deptMapper.selectById(parentId);
|
||||
if (dept == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_PARENT_NOT_EXITS);
|
||||
@@ -206,7 +206,7 @@ public class SysDeptServiceImpl implements SysDeptService {
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的菜单
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的岗位
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.dept.impl;
|
||||
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.convert.dept.SysPostConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept.SysPostMapper;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.dept.SysPostService;
|
||||
@@ -9,6 +15,8 @@ import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 岗位 Service 实现类
|
||||
*
|
||||
@@ -25,4 +33,88 @@ public class SysPostServiceImpl implements SysPostService {
|
||||
return postMapper.selectList(ids, statuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysPostDO> pagePosts(SysPostPageReqVO reqVO) {
|
||||
return SysPostConvert.INSTANCE.convertPage02(postMapper.selectList(reqVO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysPostDO getPost(Long id) {
|
||||
return postMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createPost(SysPostCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkCreateOrUpdate(null, reqVO.getName(), reqVO.getCode());
|
||||
// 插入岗位
|
||||
SysPostDO post = SysPostConvert.INSTANCE.convert(reqVO);
|
||||
postMapper.insert(post);
|
||||
return post.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePost(SysPostUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), reqVO.getCode());
|
||||
// 更新岗位
|
||||
SysPostDO updateObj = SysPostConvert.INSTANCE.convert(reqVO);
|
||||
postMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String name, String code) {
|
||||
// 校验自己存在
|
||||
checkPostExists(id);
|
||||
// 校验岗位名的唯一性
|
||||
checkPostNameUnique(id, name);
|
||||
// 校验岗位编码的唯一性
|
||||
checkPostCodeUnique(id, code);
|
||||
}
|
||||
|
||||
private void checkPostNameUnique(Long id, String name) {
|
||||
SysPostDO post = postMapper.selectByName(name);
|
||||
if (post == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的岗位
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(POST_NAME_DUPLICATE);
|
||||
}
|
||||
if (!post.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(POST_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPostCodeUnique(Long id, String code) {
|
||||
SysPostDO post = postMapper.selectByCode(code);
|
||||
if (post == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的岗位
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(POST_CODE_DUPLICATE);
|
||||
}
|
||||
if (!post.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(POST_CODE_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePost(Long id) {
|
||||
// 校验是否存在
|
||||
this.checkPostExists(id);
|
||||
// 删除部门
|
||||
postMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void checkPostExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
SysPostDO post = postMapper.selectById(id);
|
||||
if (post == null) {
|
||||
throw ServiceExceptionUtil.exception(POST_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user