mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	完成岗位的迁移
This commit is contained in:
		| @@ -2,15 +2,16 @@ package cn.iocoder.dashboard.modules.system.controller.dept; | ||||
|  | ||||
| import cn.iocoder.dashboard.common.enums.CommonStatusEnum; | ||||
| import cn.iocoder.dashboard.common.pojo.CommonResult; | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostSimpleRespVO; | ||||
| import cn.iocoder.dashboard.common.pojo.PageResult; | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.*; | ||||
| import cn.iocoder.dashboard.modules.system.convert.dept.SysPostConvert; | ||||
| import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; | ||||
| import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.Collections; | ||||
| @@ -37,4 +38,54 @@ public class SysPostController { | ||||
|         return success(SysPostConvert.INSTANCE.convertList02(list)); | ||||
|     } | ||||
|  | ||||
|     @ApiOperation("获得岗位分页列表") | ||||
|     @GetMapping("/page") | ||||
| //    @PreAuthorize("@ss.hasPermi('system:post:list')") | ||||
|     public CommonResult<PageResult<SysPostRespVO>> pagePosts(@Validated SysPostPageReqVO reqVO) { | ||||
|         return success(SysPostConvert.INSTANCE.convertPage(postService.pagePosts(reqVO))); | ||||
|     } | ||||
|  | ||||
|     @ApiOperation("新增岗位") | ||||
|     @PostMapping("/create") | ||||
| //    @PreAuthorize("@ss.hasPermi('system:post:add')") | ||||
| //    @Log(title = "岗位管理", businessType = BusinessType.INSERT) | ||||
|     public CommonResult<Long> createPost(@Validated @RequestBody SysPostCreateReqVO reqVO) { | ||||
|         Long postId = postService.createPost(reqVO); | ||||
|         return success(postId); | ||||
|     } | ||||
|  | ||||
|     @ApiOperation("修改岗位") | ||||
|     @PostMapping("/update") | ||||
| //    @PreAuthorize("@ss.hasPermi('system:post:edit')") | ||||
| //    @Log(title = "岗位管理", businessType = BusinessType.UPDATE) | ||||
|     public CommonResult<Boolean> updatePost(@Validated @RequestBody SysPostUpdateReqVO reqVO) { | ||||
|         postService.updatePost(reqVO); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
|     @ApiOperation("删除岗位") | ||||
|     @PostMapping("/delete") | ||||
| //    @PreAuthorize("@ss.hasPermi('system:post:remove')") | ||||
| //    @Log(title = "岗位管理", businessType = BusinessType.DELETE) | ||||
|     public CommonResult<Boolean> deletePost(@RequestParam("id") Long id) { | ||||
|         postService.deletePost(id); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
|     @ApiOperation("获得岗位信息") | ||||
|     @ApiImplicitParam(name = "id", value = "岗位编号", readOnly = true, example = "1024") | ||||
| //    @PreAuthorize("@ss.hasPermi('system:post:query')") | ||||
|     @GetMapping(value = "/get") | ||||
|     public CommonResult<SysPostRespVO> getPost(@RequestParam("id") Long id) { | ||||
|         return success(SysPostConvert.INSTANCE.convert(postService.getPost(id))); | ||||
|     } | ||||
|  | ||||
| //    @Log(title = "岗位管理", businessType = BusinessType.EXPORT) | ||||
| //    @PreAuthorize("@ss.hasPermi('system:post:export')") | ||||
| //    @GetMapping("/export") | ||||
| //    public AjaxResult export(SysPost post) { | ||||
| //        List<SysPost> list = postService.selectPostList(post); | ||||
| //        ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class); | ||||
| //        return util.exportExcel(list, "岗位数据"); | ||||
| //    } | ||||
| } | ||||
|   | ||||
| @@ -27,6 +27,9 @@ public class SysPostBaseVO { | ||||
|     @NotBlank(message = "显示顺序不能为空") | ||||
|     private String sort; | ||||
|  | ||||
|     @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类") | ||||
|     private Integer status; | ||||
|  | ||||
|     @ApiModelProperty(value = "备注", example = "快乐的备注") | ||||
|     private String remark; | ||||
|  | ||||
|   | ||||
| @@ -0,0 +1,20 @@ | ||||
| package cn.iocoder.dashboard.modules.system.controller.dept.vo.post; | ||||
|  | ||||
| import cn.iocoder.dashboard.common.pojo.PageParam; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
|  | ||||
| @ApiModel("岗位分页 Request VO") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| public class SysPostPageReqVO extends PageParam { | ||||
|  | ||||
|     @ApiModelProperty(value = "岗位名称", example = "芋道", notes = "模糊匹配") | ||||
|     private String name; | ||||
|  | ||||
|     @ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类") | ||||
|     private Integer status; | ||||
|  | ||||
| } | ||||
| @@ -15,9 +15,6 @@ public class SysPostRespVO extends SysPostBaseVO { | ||||
|     @ApiModelProperty(value = "岗位序号", required = true, example = "1024") | ||||
|     private Integer id; | ||||
|  | ||||
|     @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类") | ||||
|     private Integer status; | ||||
|  | ||||
|     @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") | ||||
|     private Date createTime; | ||||
|  | ||||
|   | ||||
| @@ -14,6 +14,6 @@ public class SysPostUpdateReqVO extends SysPostBaseVO { | ||||
|  | ||||
|     @ApiModelProperty(value = "岗位编号", required = true, example = "1024") | ||||
|     @NotNull(message = "岗位编号不能为空") | ||||
|     private Integer id; | ||||
|     private Long id; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,14 @@ | ||||
| package cn.iocoder.dashboard.modules.system.convert.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.SysPostRespVO; | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostSimpleRespVO; | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostUpdateReqVO; | ||||
| import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; | ||||
| import com.baomidou.mybatisplus.core.metadata.IPage; | ||||
| import org.mapstruct.Mapper; | ||||
| import org.mapstruct.Mapping; | ||||
| import org.mapstruct.factory.Mappers; | ||||
|  | ||||
| import java.util.List; | ||||
| @@ -14,4 +20,15 @@ public interface SysPostConvert { | ||||
|  | ||||
|     List<SysPostSimpleRespVO> convertList02(List<SysPostDO> list); | ||||
|  | ||||
|     PageResult<SysPostRespVO> convertPage(PageResult<SysPostDO> page); | ||||
|  | ||||
|     SysPostRespVO convert(SysPostDO id); | ||||
|  | ||||
|     @Mapping(source = "records", target = "list") | ||||
|     PageResult<SysPostDO> convertPage02(IPage<SysPostDO> page); | ||||
|  | ||||
|     SysPostDO convert(SysPostCreateReqVO bean); | ||||
|  | ||||
|     SysPostDO convert(SysPostUpdateReqVO reqVO); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,12 @@ | ||||
| package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept; | ||||
|  | ||||
| import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; | ||||
| import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils; | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostPageReqVO; | ||||
| import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||
| import com.baomidou.mybatisplus.core.metadata.IPage; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| import java.util.Collection; | ||||
| @@ -16,4 +20,18 @@ public interface SysPostMapper extends BaseMapper<SysPostDO> { | ||||
|                 .inIfPresent("status", statuses)); | ||||
|     } | ||||
|  | ||||
|     default IPage<SysPostDO> selectList(SysPostPageReqVO reqVO) { | ||||
|         return selectPage(MyBatisUtils.buildPage(reqVO), | ||||
|                 new QueryWrapperX<SysPostDO>().likeIfPresent("name", reqVO.getName()) | ||||
|                         .eqIfPresent("status", reqVO.getStatus())); | ||||
|     } | ||||
|  | ||||
|     default SysPostDO selectByName(String name) { | ||||
|         return selectOne(new QueryWrapper<SysPostDO>().eq("name", name)); | ||||
|     } | ||||
|  | ||||
|     default SysPostDO selectByCode(String code) { | ||||
|         return selectOne(new QueryWrapper<SysPostDO>().eq("code", code)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -51,5 +51,7 @@ public interface SysErrorCodeConstants { | ||||
|     // ========== 岗位模块 1002005000 ========== | ||||
|     ErrorCode POST_NOT_FOUND = new ErrorCode(1002005001, "当前岗位不存在"); | ||||
|     ErrorCode POST_NOT_ENABLE = new ErrorCode(1002005002, "岗位({}) 不处于开启状态,不允许选择"); | ||||
|     ErrorCode POST_NAME_DUPLICATE = new ErrorCode(1002004001, "已经存在该名字的岗位"); | ||||
|     ErrorCode POST_CODE_DUPLICATE = new ErrorCode(1002004001, "已经存在该标识的岗位"); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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
	 YunaiV
					YunaiV