Commit ba6c879ee1c9a7f4b37c959bed1d63c0b1c68ca1

Authored by YunaiV
1 parent e4fd022c

完成岗位的迁移

ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysPostController.java deleted
1 -package com.ruoyi.web.controller.system;  
2 -  
3 -import java.util.List;  
4 -import org.springframework.beans.factory.annotation.Autowired;  
5 -import org.springframework.security.access.prepost.PreAuthorize;  
6 -import org.springframework.validation.annotation.Validated;  
7 -import org.springframework.web.bind.annotation.DeleteMapping;  
8 -import org.springframework.web.bind.annotation.GetMapping;  
9 -import org.springframework.web.bind.annotation.PathVariable;  
10 -import org.springframework.web.bind.annotation.PostMapping;  
11 -import org.springframework.web.bind.annotation.PutMapping;  
12 -import org.springframework.web.bind.annotation.RequestBody;  
13 -import org.springframework.web.bind.annotation.RequestMapping;  
14 -import org.springframework.web.bind.annotation.RestController;  
15 -import com.ruoyi.common.annotation.Log;  
16 -import com.ruoyi.common.constant.UserConstants;  
17 -import com.ruoyi.common.core.controller.BaseController;  
18 -import com.ruoyi.common.core.domain.AjaxResult;  
19 -import com.ruoyi.common.core.page.TableDataInfo;  
20 -import com.ruoyi.common.enums.BusinessType;  
21 -import com.ruoyi.common.utils.SecurityUtils;  
22 -import com.ruoyi.common.utils.poi.ExcelUtil;  
23 -import com.ruoyi.system.domain.SysPost;  
24 -import com.ruoyi.system.service.ISysPostService;  
25 -  
26 -/**  
27 - * 岗位信息操作处理  
28 - *  
29 - * @author ruoyi  
30 - */  
31 -@RestController  
32 -@RequestMapping("/system/post")  
33 -public class SysPostController extends BaseController  
34 -{  
35 - @Autowired  
36 - private ISysPostService postService;  
37 -  
38 - /**  
39 - * 获取岗位列表  
40 - */  
41 - @PreAuthorize("@ss.hasPermi('system:post:list')")  
42 - @GetMapping("/list")  
43 - public TableDataInfo list(SysPost post)  
44 - {  
45 - startPage();  
46 - List<SysPost> list = postService.selectPostList(post);  
47 - return getDataTable(list);  
48 - }  
49 -  
50 - @Log(title = "岗位管理", businessType = BusinessType.EXPORT)  
51 - @PreAuthorize("@ss.hasPermi('system:post:export')")  
52 - @GetMapping("/export")  
53 - public AjaxResult export(SysPost post)  
54 - {  
55 - List<SysPost> list = postService.selectPostList(post);  
56 - ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);  
57 - return util.exportExcel(list, "岗位数据");  
58 - }  
59 -  
60 - /**  
61 - * 根据岗位编号获取详细信息  
62 - */  
63 - @PreAuthorize("@ss.hasPermi('system:post:query')")  
64 - @GetMapping(value = "/{postId}")  
65 - public AjaxResult getInfo(@PathVariable Long postId)  
66 - {  
67 - return AjaxResult.success(postService.selectPostById(postId));  
68 - }  
69 -  
70 - /**  
71 - * 新增岗位  
72 - */  
73 - @PreAuthorize("@ss.hasPermi('system:post:add')")  
74 - @Log(title = "岗位管理", businessType = BusinessType.INSERT)  
75 - @PostMapping  
76 - public AjaxResult add(@Validated @RequestBody SysPost post)  
77 - {  
78 - if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))  
79 - {  
80 - return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");  
81 - }  
82 - else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))  
83 - {  
84 - return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");  
85 - }  
86 - post.setCreateBy(SecurityUtils.getUsername());  
87 - return toAjax(postService.insertPost(post));  
88 - }  
89 -  
90 - /**  
91 - * 修改岗位  
92 - */  
93 - @PreAuthorize("@ss.hasPermi('system:post:edit')")  
94 - @Log(title = "岗位管理", businessType = BusinessType.UPDATE)  
95 - @PutMapping  
96 - public AjaxResult edit(@Validated @RequestBody SysPost post)  
97 - {  
98 - if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))  
99 - {  
100 - return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");  
101 - }  
102 - else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))  
103 - {  
104 - return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");  
105 - }  
106 - post.setUpdateBy(SecurityUtils.getUsername());  
107 - return toAjax(postService.updatePost(post));  
108 - }  
109 -  
110 - /**  
111 - * 删除岗位  
112 - */  
113 - @PreAuthorize("@ss.hasPermi('system:post:remove')")  
114 - @Log(title = "岗位管理", businessType = BusinessType.DELETE)  
115 - @DeleteMapping("/{postIds}")  
116 - public AjaxResult remove(@PathVariable Long[] postIds)  
117 - {  
118 - return toAjax(postService.deletePostByIds(postIds));  
119 - }  
120 -  
121 - /**  
122 - * 获取岗位选择框列表  
123 - */  
124 - @GetMapping("/optionselect")  
125 - public AjaxResult optionselect()  
126 - {  
127 - List<SysPost> posts = postService.selectPostAll();  
128 - return AjaxResult.success(posts);  
129 - }  
130 -}  
ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java deleted
1 -package com.ruoyi.common.constant;  
2 -  
3 -/**  
4 - * 用户常量信息  
5 - *  
6 - * @author ruoyi  
7 - */  
8 -public class UserConstants  
9 -{  
10 - /**  
11 - * 平台内系统用户的唯一标志  
12 - */  
13 - public static final String SYS_USER = "SYS_USER";  
14 -  
15 - /** 正常状态 */  
16 - public static final String NORMAL = "0";  
17 -  
18 - /** 异常状态 */  
19 - public static final String EXCEPTION = "1";  
20 -  
21 - /** 用户封禁状态 */  
22 - public static final String USER_DISABLE = "1";  
23 -  
24 - /** 角色封禁状态 */  
25 - public static final String ROLE_DISABLE = "1";  
26 -  
27 - /** 部门正常状态 */  
28 - public static final String DEPT_NORMAL = "0";  
29 -  
30 - /** 部门停用状态 */  
31 - public static final String DEPT_DISABLE = "1";  
32 -  
33 - /** 字典正常状态 */  
34 - public static final String DICT_NORMAL = "0";  
35 -  
36 - /** 是否为系统默认(是) */  
37 - public static final String YES = "Y";  
38 -  
39 - /** 是否菜单外链(是) */  
40 - public static final String YES_FRAME = "0";  
41 -  
42 - /** 是否菜单外链(否) */  
43 - public static final String NO_FRAME = "1";  
44 -  
45 - /** Layout组件标识 */  
46 - public final static String LAYOUT = "Layout";  
47 -  
48 - /** ParentView组件标识 */  
49 - public final static String PARENT_VIEW = "ParentView";  
50 -  
51 - /** 校验返回结果码 */  
52 - public final static String UNIQUE = "0";  
53 - public final static String NOT_UNIQUE = "1";  
54 -}  
ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java deleted
1 -package com.ruoyi.common.core.controller;  
2 -  
3 -import java.beans.PropertyEditorSupport;  
4 -import java.util.Date;  
5 -import java.util.List;  
6 -  
7 -import org.slf4j.Logger;  
8 -import org.slf4j.LoggerFactory;  
9 -import org.springframework.web.bind.WebDataBinder;  
10 -import org.springframework.web.bind.annotation.InitBinder;  
11 -import com.github.pagehelper.PageHelper;  
12 -import com.github.pagehelper.PageInfo;  
13 -import com.ruoyi.common.constant.HttpStatus;  
14 -import com.ruoyi.common.core.domain.AjaxResult;  
15 -import com.ruoyi.common.core.page.PageDomain;  
16 -import com.ruoyi.common.core.page.TableDataInfo;  
17 -import com.ruoyi.common.core.page.TableSupport;  
18 -import com.ruoyi.common.utils.DateUtils;  
19 -import com.ruoyi.common.utils.StringUtils;  
20 -import com.ruoyi.common.utils.sql.SqlUtil;  
21 -  
22 -/**  
23 - * web层通用数据处理  
24 - *  
25 - * @author ruoyi  
26 - */  
27 -public class BaseController {  
28 - protected final Logger logger = LoggerFactory.getLogger(BaseController.class);  
29 -  
30 - /**  
31 - * 将前台传递过来的日期格式的字符串,自动转化为Date类型  
32 - */  
33 - @InitBinder  
34 - public void initBinder(WebDataBinder binder) {  
35 - // Date 类型转换  
36 - binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {  
37 - @Override  
38 - public void setAsText(String text) {  
39 - setValue(DateUtils.parseDate(text));  
40 - }  
41 - });  
42 - }  
43 -  
44 -}  
ruoyi-common/src/main/java/com/ruoyi/common/enums/HttpMethod.java deleted
1 -package com.ruoyi.common.enums;  
2 -  
3 -import java.util.HashMap;  
4 -import java.util.Map;  
5 -import org.springframework.lang.Nullable;  
6 -  
7 -/**  
8 - * 请求方式  
9 - *  
10 - * @author ruoyi  
11 - */  
12 -public enum HttpMethod  
13 -{  
14 - GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE;  
15 -  
16 - private static final Map<String, HttpMethod> mappings = new HashMap<>(16);  
17 -  
18 - static  
19 - {  
20 - for (HttpMethod httpMethod : values())  
21 - {  
22 - mappings.put(httpMethod.name(), httpMethod);  
23 - }  
24 - }  
25 -  
26 - @Nullable  
27 - public static HttpMethod resolve(@Nullable String method)  
28 - {  
29 - return (method != null ? mappings.get(method) : null);  
30 - }  
31 -  
32 - public boolean matches(String method)  
33 - {  
34 - return (this == resolve(method));  
35 - }  
36 -}  
ruoyi-ui/src/api/system/post.js
@@ -3,7 +3,7 @@ import request from &#39;@/utils/request&#39; @@ -3,7 +3,7 @@ import request from &#39;@/utils/request&#39;
3 // 查询岗位列表 3 // 查询岗位列表
4 export function listPost(query) { 4 export function listPost(query) {
5 return request({ 5 return request({
6 - url: '/system/post/list', 6 + url: '/system/post/page',
7 method: 'get', 7 method: 'get',
8 params: query 8 params: query
9 }) 9 })
@@ -20,7 +20,7 @@ export function listSimplePosts() { @@ -20,7 +20,7 @@ export function listSimplePosts() {
20 // 查询岗位详细 20 // 查询岗位详细
21 export function getPost(postId) { 21 export function getPost(postId) {
22 return request({ 22 return request({
23 - url: '/system/post/' + postId, 23 + url: '/system/post/get?id=' + postId,
24 method: 'get' 24 method: 'get'
25 }) 25 })
26 } 26 }
@@ -28,7 +28,7 @@ export function getPost(postId) { @@ -28,7 +28,7 @@ export function getPost(postId) {
28 // 新增岗位 28 // 新增岗位
29 export function addPost(data) { 29 export function addPost(data) {
30 return request({ 30 return request({
31 - url: '/system/post', 31 + url: '/system/post/create',
32 method: 'post', 32 method: 'post',
33 data: data 33 data: data
34 }) 34 })
@@ -37,8 +37,8 @@ export function addPost(data) { @@ -37,8 +37,8 @@ export function addPost(data) {
37 // 修改岗位 37 // 修改岗位
38 export function updatePost(data) { 38 export function updatePost(data) {
39 return request({ 39 return request({
40 - url: '/system/post',  
41 - method: 'put', 40 + url: '/system/post/update',
  41 + method: 'post',
42 data: data 42 data: data
43 }) 43 })
44 } 44 }
@@ -46,8 +46,8 @@ export function updatePost(data) { @@ -46,8 +46,8 @@ export function updatePost(data) {
46 // 删除岗位 46 // 删除岗位
47 export function delPost(postId) { 47 export function delPost(postId) {
48 return request({ 48 return request({
49 - url: '/system/post/' + postId,  
50 - method: 'delete' 49 + url: '/system/post/delete?id=' + postId,
  50 + method: 'post'
51 }) 51 })
52 } 52 }
53 53
ruoyi-ui/src/views/system/dept/index.vue
@@ -142,7 +142,7 @@ import { listDept, getDept, delDept, addDept, updateDept } from &quot;@/api/system/de @@ -142,7 +142,7 @@ import { listDept, getDept, delDept, addDept, updateDept } from &quot;@/api/system/de
142 import Treeselect from "@riophae/vue-treeselect"; 142 import Treeselect from "@riophae/vue-treeselect";
143 import "@riophae/vue-treeselect/dist/vue-treeselect.css"; 143 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
144 144
145 -import {SysCommonStatusEnum, SysMenuTypeEnum} from '@/utils/constants' 145 +import {SysCommonStatusEnum} from '@/utils/constants'
146 import { getDictDataLabel, getDictDatas, DICT_TYPE } from '@/utils/dict' 146 import { getDictDataLabel, getDictDatas, DICT_TYPE } from '@/utils/dict'
147 147
148 export default { 148 export default {
@@ -249,7 +249,7 @@ export default { @@ -249,7 +249,7 @@ export default {
249 leader: undefined, 249 leader: undefined,
250 phone: undefined, 250 phone: undefined,
251 email: undefined, 251 email: undefined,
252 - status: "0" 252 + status: SysCommonStatusEnum.ENABLE,
253 }; 253 };
254 this.resetForm("form"); 254 this.resetForm("form");
255 }, 255 },
ruoyi-ui/src/views/system/post/index.vue
1 <template> 1 <template>
2 <div class="app-container"> 2 <div class="app-container">
3 <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> 3 <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
4 - <el-form-item label="岗位编码" prop="postCode"> 4 + <el-form-item label="岗位编码" prop="code">
5 <el-input 5 <el-input
6 - v-model="queryParams.postCode" 6 + v-model="queryParams.code"
7 placeholder="请输入岗位编码" 7 placeholder="请输入岗位编码"
8 clearable 8 clearable
9 size="small" 9 size="small"
10 @keyup.enter.native="handleQuery" 10 @keyup.enter.native="handleQuery"
11 /> 11 />
12 </el-form-item> 12 </el-form-item>
13 - <el-form-item label="岗位名称" prop="postName"> 13 + <el-form-item label="岗位名称" prop="name">
14 <el-input 14 <el-input
15 - v-model="queryParams.postName" 15 + v-model="queryParams.name"
16 placeholder="请输入岗位名称" 16 placeholder="请输入岗位名称"
17 clearable 17 clearable
18 size="small" 18 size="small"
@@ -22,10 +22,10 @@ @@ -22,10 +22,10 @@
22 <el-form-item label="状态" prop="status"> 22 <el-form-item label="状态" prop="status">
23 <el-select v-model="queryParams.status" placeholder="岗位状态" clearable size="small"> 23 <el-select v-model="queryParams.status" placeholder="岗位状态" clearable size="small">
24 <el-option 24 <el-option
25 - v-for="dict in statusOptions"  
26 - :key="dict.dictValue"  
27 - :label="dict.dictLabel"  
28 - :value="dict.dictValue" 25 + v-for="dict in statusDictDatas"
  26 + :key="parseInt(dict.value)"
  27 + :label="dict.label"
  28 + :value="parseInt(dict.value)"
29 /> 29 />
30 </el-select> 30 </el-select>
31 </el-form-item> 31 </el-form-item>
@@ -47,26 +47,6 @@ @@ -47,26 +47,6 @@
47 </el-col> 47 </el-col>
48 <el-col :span="1.5"> 48 <el-col :span="1.5">
49 <el-button 49 <el-button
50 - type="success"  
51 - icon="el-icon-edit"  
52 - size="mini"  
53 - :disabled="single"  
54 - @click="handleUpdate"  
55 - v-hasPermi="['system:post:edit']"  
56 - >修改</el-button>  
57 - </el-col>  
58 - <el-col :span="1.5">  
59 - <el-button  
60 - type="danger"  
61 - icon="el-icon-delete"  
62 - size="mini"  
63 - :disabled="multiple"  
64 - @click="handleDelete"  
65 - v-hasPermi="['system:post:remove']"  
66 - >删除</el-button>  
67 - </el-col>  
68 - <el-col :span="1.5">  
69 - <el-button  
70 type="warning" 50 type="warning"
71 icon="el-icon-download" 51 icon="el-icon-download"
72 size="mini" 52 size="mini"
@@ -77,12 +57,11 @@ @@ -77,12 +57,11 @@
77 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> 57 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
78 </el-row> 58 </el-row>
79 59
80 - <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">  
81 - <el-table-column type="selection" width="55" align="center" />  
82 - <el-table-column label="岗位编号" align="center" prop="postId" />  
83 - <el-table-column label="岗位编码" align="center" prop="postCode" />  
84 - <el-table-column label="岗位名称" align="center" prop="postName" />  
85 - <el-table-column label="岗位排序" align="center" prop="postSort" /> 60 + <el-table v-loading="loading" :data="postList">
  61 + <el-table-column label="岗位编号" align="center" prop="id" />
  62 + <el-table-column label="岗位编码" align="center" prop="code" />
  63 + <el-table-column label="岗位名称" align="center" prop="name" />
  64 + <el-table-column label="岗位排序" align="center" prop="sort" />
86 <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" /> 65 <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
87 <el-table-column label="创建时间" align="center" prop="createTime" width="180"> 66 <el-table-column label="创建时间" align="center" prop="createTime" width="180">
88 <template slot-scope="scope"> 67 <template slot-scope="scope">
@@ -108,11 +87,11 @@ @@ -108,11 +87,11 @@
108 </template> 87 </template>
109 </el-table-column> 88 </el-table-column>
110 </el-table> 89 </el-table>
111 - 90 +
112 <pagination 91 <pagination
113 v-show="total>0" 92 v-show="total>0"
114 :total="total" 93 :total="total"
115 - :page.sync="queryParams.pageNum" 94 + :page.sync="queryParams.pageNo"
116 :limit.sync="queryParams.pageSize" 95 :limit.sync="queryParams.pageSize"
117 @pagination="getList" 96 @pagination="getList"
118 /> 97 />
@@ -120,22 +99,22 @@ @@ -120,22 +99,22 @@
120 <!-- 添加或修改岗位对话框 --> 99 <!-- 添加或修改岗位对话框 -->
121 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> 100 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
122 <el-form ref="form" :model="form" :rules="rules" label-width="80px"> 101 <el-form ref="form" :model="form" :rules="rules" label-width="80px">
123 - <el-form-item label="岗位名称" prop="postName">  
124 - <el-input v-model="form.postName" placeholder="请输入岗位名称" /> 102 + <el-form-item label="岗位名称" prop="name">
  103 + <el-input v-model="form.name" placeholder="请输入岗位名称" />
125 </el-form-item> 104 </el-form-item>
126 - <el-form-item label="岗位编码" prop="postCode">  
127 - <el-input v-model="form.postCode" placeholder="请输入编码名称" /> 105 + <el-form-item label="岗位编码" prop="code">
  106 + <el-input v-model="form.code" placeholder="请输入编码名称" />
128 </el-form-item> 107 </el-form-item>
129 - <el-form-item label="岗位顺序" prop="postSort">  
130 - <el-input-number v-model="form.postSort" controls-position="right" :min="0" /> 108 + <el-form-item label="岗位顺序" prop="sort">
  109 + <el-input-number v-model="form.sort" controls-position="right" :min="0" />
131 </el-form-item> 110 </el-form-item>
132 <el-form-item label="岗位状态" prop="status"> 111 <el-form-item label="岗位状态" prop="status">
133 <el-radio-group v-model="form.status"> 112 <el-radio-group v-model="form.status">
134 <el-radio 113 <el-radio
135 - v-for="dict in statusOptions"  
136 - :key="dict.dictValue"  
137 - :label="dict.dictValue"  
138 - >{{dict.dictLabel}}</el-radio> 114 + v-for="dict in statusDictDatas"
  115 + :key="parseInt(dict.value)"
  116 + :label="parseInt(dict.value)"
  117 + >{{dict.label}}</el-radio>
139 </el-radio-group> 118 </el-radio-group>
140 </el-form-item> 119 </el-form-item>
141 <el-form-item label="备注" prop="remark"> 120 <el-form-item label="备注" prop="remark">
@@ -153,6 +132,9 @@ @@ -153,6 +132,9 @@
153 <script> 132 <script>
154 import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/system/post"; 133 import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/system/post";
155 134
  135 +import {SysCommonStatusEnum} from '@/utils/constants'
  136 +import { getDictDataLabel, getDictDatas, DICT_TYPE } from '@/utils/dict'
  137 +
156 export default { 138 export default {
157 name: "Post", 139 name: "Post",
158 data() { 140 data() {
@@ -179,47 +161,49 @@ export default { @@ -179,47 +161,49 @@ export default {
179 statusOptions: [], 161 statusOptions: [],
180 // 查询参数 162 // 查询参数
181 queryParams: { 163 queryParams: {
182 - pageNum: 1, 164 + pageNo: 1,
183 pageSize: 10, 165 pageSize: 10,
184 - postCode: undefined,  
185 - postName: undefined, 166 + code: undefined,
  167 + name: undefined,
186 status: undefined 168 status: undefined
187 }, 169 },
188 // 表单参数 170 // 表单参数
189 form: {}, 171 form: {},
190 // 表单校验 172 // 表单校验
191 rules: { 173 rules: {
192 - postName: [ 174 + name: [
193 { required: true, message: "岗位名称不能为空", trigger: "blur" } 175 { required: true, message: "岗位名称不能为空", trigger: "blur" }
194 ], 176 ],
195 - postCode: [ 177 + code: [
196 { required: true, message: "岗位编码不能为空", trigger: "blur" } 178 { required: true, message: "岗位编码不能为空", trigger: "blur" }
197 ], 179 ],
198 - postSort: [ 180 + sort: [
199 { required: true, message: "岗位顺序不能为空", trigger: "blur" } 181 { required: true, message: "岗位顺序不能为空", trigger: "blur" }
200 ] 182 ]
201 - } 183 + },
  184 +
  185 + // 枚举
  186 + CommonStatusEnum: SysCommonStatusEnum,
  187 + // 数据字典
  188 + statusDictDatas: getDictDatas(DICT_TYPE.SYS_COMMON_STATUS)
202 }; 189 };
203 }, 190 },
204 created() { 191 created() {
205 this.getList(); 192 this.getList();
206 - this.getDicts("sys_normal_disable").then(response => {  
207 - this.statusOptions = response.data;  
208 - });  
209 }, 193 },
210 methods: { 194 methods: {
211 /** 查询岗位列表 */ 195 /** 查询岗位列表 */
212 getList() { 196 getList() {
213 this.loading = true; 197 this.loading = true;
214 listPost(this.queryParams).then(response => { 198 listPost(this.queryParams).then(response => {
215 - this.postList = response.rows;  
216 - this.total = response.total; 199 + this.postList = response.data.list;
  200 + this.total = response.data.total;
217 this.loading = false; 201 this.loading = false;
218 }); 202 });
219 }, 203 },
220 // 岗位状态字典翻译 204 // 岗位状态字典翻译
221 statusFormat(row, column) { 205 statusFormat(row, column) {
222 - return this.selectDictLabel(this.statusOptions, row.status); 206 + return getDictDataLabel(DICT_TYPE.SYS_COMMON_STATUS, row.status)
223 }, 207 },
224 // 取消按钮 208 // 取消按钮
225 cancel() { 209 cancel() {
@@ -229,18 +213,18 @@ export default { @@ -229,18 +213,18 @@ export default {
229 // 表单重置 213 // 表单重置
230 reset() { 214 reset() {
231 this.form = { 215 this.form = {
232 - postId: undefined,  
233 - postCode: undefined,  
234 - postName: undefined,  
235 - postSort: 0,  
236 - status: "0", 216 + id: undefined,
  217 + code: undefined,
  218 + name: undefined,
  219 + sort: 0,
  220 + status: SysCommonStatusEnum.ENABLE,
237 remark: undefined 221 remark: undefined
238 }; 222 };
239 this.resetForm("form"); 223 this.resetForm("form");
240 }, 224 },
241 /** 搜索按钮操作 */ 225 /** 搜索按钮操作 */
242 handleQuery() { 226 handleQuery() {
243 - this.queryParams.pageNum = 1; 227 + this.queryParams.pageNo = 1;
244 this.getList(); 228 this.getList();
245 }, 229 },
246 /** 重置按钮操作 */ 230 /** 重置按钮操作 */
@@ -248,12 +232,6 @@ export default { @@ -248,12 +232,6 @@ export default {
248 this.resetForm("queryForm"); 232 this.resetForm("queryForm");
249 this.handleQuery(); 233 this.handleQuery();
250 }, 234 },
251 - // 多选框选中数据  
252 - handleSelectionChange(selection) {  
253 - this.ids = selection.map(item => item.postId)  
254 - this.single = selection.length!=1  
255 - this.multiple = !selection.length  
256 - },  
257 /** 新增按钮操作 */ 235 /** 新增按钮操作 */
258 handleAdd() { 236 handleAdd() {
259 this.reset(); 237 this.reset();
@@ -263,8 +241,8 @@ export default { @@ -263,8 +241,8 @@ export default {
263 /** 修改按钮操作 */ 241 /** 修改按钮操作 */
264 handleUpdate(row) { 242 handleUpdate(row) {
265 this.reset(); 243 this.reset();
266 - const postId = row.postId || this.ids  
267 - getPost(postId).then(response => { 244 + const id = row.id
  245 + getPost(id).then(response => {
268 this.form = response.data; 246 this.form = response.data;
269 this.open = true; 247 this.open = true;
270 this.title = "修改岗位"; 248 this.title = "修改岗位";
@@ -274,7 +252,7 @@ export default { @@ -274,7 +252,7 @@ export default {
274 submitForm: function() { 252 submitForm: function() {
275 this.$refs["form"].validate(valid => { 253 this.$refs["form"].validate(valid => {
276 if (valid) { 254 if (valid) {
277 - if (this.form.postId != undefined) { 255 + if (this.form.id !== undefined) {
278 updatePost(this.form).then(response => { 256 updatePost(this.form).then(response => {
279 this.msgSuccess("修改成功"); 257 this.msgSuccess("修改成功");
280 this.open = false; 258 this.open = false;
@@ -292,13 +270,13 @@ export default { @@ -292,13 +270,13 @@ export default {
292 }, 270 },
293 /** 删除按钮操作 */ 271 /** 删除按钮操作 */
294 handleDelete(row) { 272 handleDelete(row) {
295 - const postIds = row.postId || this.ids;  
296 - this.$confirm('是否确认删除岗位编号为"' + postIds + '"的数据项?', "警告", { 273 + const ids = row.id;
  274 + this.$confirm('是否确认删除岗位编号为"' + ids + '"的数据项?', "警告", {
297 confirmButtonText: "确定", 275 confirmButtonText: "确定",
298 cancelButtonText: "取消", 276 cancelButtonText: "取消",
299 type: "warning" 277 type: "warning"
300 }).then(function() { 278 }).then(function() {
301 - return delPost(postIds); 279 + return delPost(ids);
302 }).then(() => { 280 }).then(() => {
303 this.getList(); 281 this.getList();
304 this.msgSuccess("删除成功"); 282 this.msgSuccess("删除成功");
@@ -319,4 +297,4 @@ export default { @@ -319,4 +297,4 @@ export default {
319 } 297 }
320 } 298 }
321 }; 299 };
322 -</script>  
323 \ No newline at end of file 300 \ No newline at end of file
  301 +</script>
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysPostController.java
@@ -2,15 +2,16 @@ package cn.iocoder.dashboard.modules.system.controller.dept; @@ -2,15 +2,16 @@ package cn.iocoder.dashboard.modules.system.controller.dept;
2 2
3 import cn.iocoder.dashboard.common.enums.CommonStatusEnum; 3 import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
4 import cn.iocoder.dashboard.common.pojo.CommonResult; 4 import cn.iocoder.dashboard.common.pojo.CommonResult;
5 -import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostSimpleRespVO; 5 +import cn.iocoder.dashboard.common.pojo.PageResult;
  6 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.*;
6 import cn.iocoder.dashboard.modules.system.convert.dept.SysPostConvert; 7 import cn.iocoder.dashboard.modules.system.convert.dept.SysPostConvert;
7 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; 8 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
8 import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; 9 import cn.iocoder.dashboard.modules.system.service.dept.SysPostService;
9 import io.swagger.annotations.Api; 10 import io.swagger.annotations.Api;
  11 +import io.swagger.annotations.ApiImplicitParam;
10 import io.swagger.annotations.ApiOperation; 12 import io.swagger.annotations.ApiOperation;
11 -import org.springframework.web.bind.annotation.GetMapping;  
12 -import org.springframework.web.bind.annotation.RequestMapping;  
13 -import org.springframework.web.bind.annotation.RestController; 13 +import org.springframework.validation.annotation.Validated;
  14 +import org.springframework.web.bind.annotation.*;
14 15
15 import javax.annotation.Resource; 16 import javax.annotation.Resource;
16 import java.util.Collections; 17 import java.util.Collections;
@@ -37,4 +38,54 @@ public class SysPostController { @@ -37,4 +38,54 @@ public class SysPostController {
37 return success(SysPostConvert.INSTANCE.convertList02(list)); 38 return success(SysPostConvert.INSTANCE.convertList02(list));
38 } 39 }
39 40
  41 + @ApiOperation("获得岗位分页列表")
  42 + @GetMapping("/page")
  43 +// @PreAuthorize("@ss.hasPermi('system:post:list')")
  44 + public CommonResult<PageResult<SysPostRespVO>> pagePosts(@Validated SysPostPageReqVO reqVO) {
  45 + return success(SysPostConvert.INSTANCE.convertPage(postService.pagePosts(reqVO)));
  46 + }
  47 +
  48 + @ApiOperation("新增岗位")
  49 + @PostMapping("/create")
  50 +// @PreAuthorize("@ss.hasPermi('system:post:add')")
  51 +// @Log(title = "岗位管理", businessType = BusinessType.INSERT)
  52 + public CommonResult<Long> createPost(@Validated @RequestBody SysPostCreateReqVO reqVO) {
  53 + Long postId = postService.createPost(reqVO);
  54 + return success(postId);
  55 + }
  56 +
  57 + @ApiOperation("修改岗位")
  58 + @PostMapping("/update")
  59 +// @PreAuthorize("@ss.hasPermi('system:post:edit')")
  60 +// @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
  61 + public CommonResult<Boolean> updatePost(@Validated @RequestBody SysPostUpdateReqVO reqVO) {
  62 + postService.updatePost(reqVO);
  63 + return success(true);
  64 + }
  65 +
  66 + @ApiOperation("删除岗位")
  67 + @PostMapping("/delete")
  68 +// @PreAuthorize("@ss.hasPermi('system:post:remove')")
  69 +// @Log(title = "岗位管理", businessType = BusinessType.DELETE)
  70 + public CommonResult<Boolean> deletePost(@RequestParam("id") Long id) {
  71 + postService.deletePost(id);
  72 + return success(true);
  73 + }
  74 +
  75 + @ApiOperation("获得岗位信息")
  76 + @ApiImplicitParam(name = "id", value = "岗位编号", readOnly = true, example = "1024")
  77 +// @PreAuthorize("@ss.hasPermi('system:post:query')")
  78 + @GetMapping(value = "/get")
  79 + public CommonResult<SysPostRespVO> getPost(@RequestParam("id") Long id) {
  80 + return success(SysPostConvert.INSTANCE.convert(postService.getPost(id)));
  81 + }
  82 +
  83 +// @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
  84 +// @PreAuthorize("@ss.hasPermi('system:post:export')")
  85 +// @GetMapping("/export")
  86 +// public AjaxResult export(SysPost post) {
  87 +// List<SysPost> list = postService.selectPostList(post);
  88 +// ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
  89 +// return util.exportExcel(list, "岗位数据");
  90 +// }
40 } 91 }
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/vo/post/SysPostBaseVO.java
@@ -27,6 +27,9 @@ public class SysPostBaseVO { @@ -27,6 +27,9 @@ public class SysPostBaseVO {
27 @NotBlank(message = "显示顺序不能为空") 27 @NotBlank(message = "显示顺序不能为空")
28 private String sort; 28 private String sort;
29 29
  30 + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
  31 + private Integer status;
  32 +
30 @ApiModelProperty(value = "备注", example = "快乐的备注") 33 @ApiModelProperty(value = "备注", example = "快乐的备注")
31 private String remark; 34 private String remark;
32 35
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/vo/post/SysPostPageReqVO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.controller.dept.vo.post;
  2 +
  3 +import cn.iocoder.dashboard.common.pojo.PageParam;
  4 +import io.swagger.annotations.ApiModel;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +import lombok.EqualsAndHashCode;
  8 +
  9 +@ApiModel("岗位分页 Request VO")
  10 +@Data
  11 +@EqualsAndHashCode(callSuper = true)
  12 +public class SysPostPageReqVO extends PageParam {
  13 +
  14 + @ApiModelProperty(value = "岗位名称", example = "芋道", notes = "模糊匹配")
  15 + private String name;
  16 +
  17 + @ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
  18 + private Integer status;
  19 +
  20 +}
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/vo/post/SysPostRespVO.java
@@ -15,9 +15,6 @@ public class SysPostRespVO extends SysPostBaseVO { @@ -15,9 +15,6 @@ public class SysPostRespVO extends SysPostBaseVO {
15 @ApiModelProperty(value = "岗位序号", required = true, example = "1024") 15 @ApiModelProperty(value = "岗位序号", required = true, example = "1024")
16 private Integer id; 16 private Integer id;
17 17
18 - @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类")  
19 - private Integer status;  
20 -  
21 @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") 18 @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
22 private Date createTime; 19 private Date createTime;
23 20
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/vo/post/SysPostUpdateReqVO.java
@@ -14,6 +14,6 @@ public class SysPostUpdateReqVO extends SysPostBaseVO { @@ -14,6 +14,6 @@ public class SysPostUpdateReqVO extends SysPostBaseVO {
14 14
15 @ApiModelProperty(value = "岗位编号", required = true, example = "1024") 15 @ApiModelProperty(value = "岗位编号", required = true, example = "1024")
16 @NotNull(message = "岗位编号不能为空") 16 @NotNull(message = "岗位编号不能为空")
17 - private Integer id; 17 + private Long id;
18 18
19 } 19 }
src/main/java/cn/iocoder/dashboard/modules/system/convert/dept/SysPostConvert.java
1 package cn.iocoder.dashboard.modules.system.convert.dept; 1 package cn.iocoder.dashboard.modules.system.convert.dept;
2 2
  3 +import cn.iocoder.dashboard.common.pojo.PageResult;
  4 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostCreateReqVO;
  5 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostRespVO;
3 import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostSimpleRespVO; 6 import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostSimpleRespVO;
  7 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostUpdateReqVO;
4 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; 8 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
  9 +import com.baomidou.mybatisplus.core.metadata.IPage;
5 import org.mapstruct.Mapper; 10 import org.mapstruct.Mapper;
  11 +import org.mapstruct.Mapping;
6 import org.mapstruct.factory.Mappers; 12 import org.mapstruct.factory.Mappers;
7 13
8 import java.util.List; 14 import java.util.List;
@@ -14,4 +20,15 @@ public interface SysPostConvert { @@ -14,4 +20,15 @@ public interface SysPostConvert {
14 20
15 List<SysPostSimpleRespVO> convertList02(List<SysPostDO> list); 21 List<SysPostSimpleRespVO> convertList02(List<SysPostDO> list);
16 22
  23 + PageResult<SysPostRespVO> convertPage(PageResult<SysPostDO> page);
  24 +
  25 + SysPostRespVO convert(SysPostDO id);
  26 +
  27 + @Mapping(source = "records", target = "list")
  28 + PageResult<SysPostDO> convertPage02(IPage<SysPostDO> page);
  29 +
  30 + SysPostDO convert(SysPostCreateReqVO bean);
  31 +
  32 + SysPostDO convert(SysPostUpdateReqVO reqVO);
  33 +
17 } 34 }
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dept/SysPostMapper.java
1 package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept; 1 package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept;
2 2
3 import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; 3 import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
  4 +import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils;
  5 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostPageReqVO;
4 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; 6 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
  7 +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  9 +import com.baomidou.mybatisplus.core.metadata.IPage;
6 import org.apache.ibatis.annotations.Mapper; 10 import org.apache.ibatis.annotations.Mapper;
7 11
8 import java.util.Collection; 12 import java.util.Collection;
@@ -16,4 +20,18 @@ public interface SysPostMapper extends BaseMapper&lt;SysPostDO&gt; { @@ -16,4 +20,18 @@ public interface SysPostMapper extends BaseMapper&lt;SysPostDO&gt; {
16 .inIfPresent("status", statuses)); 20 .inIfPresent("status", statuses));
17 } 21 }
18 22
  23 + default IPage<SysPostDO> selectList(SysPostPageReqVO reqVO) {
  24 + return selectPage(MyBatisUtils.buildPage(reqVO),
  25 + new QueryWrapperX<SysPostDO>().likeIfPresent("name", reqVO.getName())
  26 + .eqIfPresent("status", reqVO.getStatus()));
  27 + }
  28 +
  29 + default SysPostDO selectByName(String name) {
  30 + return selectOne(new QueryWrapper<SysPostDO>().eq("name", name));
  31 + }
  32 +
  33 + default SysPostDO selectByCode(String code) {
  34 + return selectOne(new QueryWrapper<SysPostDO>().eq("code", code));
  35 + }
  36 +
19 } 37 }
src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java
@@ -51,5 +51,7 @@ public interface SysErrorCodeConstants { @@ -51,5 +51,7 @@ public interface SysErrorCodeConstants {
51 // ========== 岗位模块 1002005000 ========== 51 // ========== 岗位模块 1002005000 ==========
52 ErrorCode POST_NOT_FOUND = new ErrorCode(1002005001, "当前岗位不存在"); 52 ErrorCode POST_NOT_FOUND = new ErrorCode(1002005001, "当前岗位不存在");
53 ErrorCode POST_NOT_ENABLE = new ErrorCode(1002005002, "岗位({}) 不处于开启状态,不允许选择"); 53 ErrorCode POST_NOT_ENABLE = new ErrorCode(1002005002, "岗位({}) 不处于开启状态,不允许选择");
  54 + ErrorCode POST_NAME_DUPLICATE = new ErrorCode(1002004001, "已经存在该名字的岗位");
  55 + ErrorCode POST_CODE_DUPLICATE = new ErrorCode(1002004001, "已经存在该标识的岗位");
54 56
55 } 57 }
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/SysPostService.java
1 package cn.iocoder.dashboard.modules.system.service.dept; 1 package cn.iocoder.dashboard.modules.system.service.dept;
2 2
  3 +import cn.iocoder.dashboard.common.pojo.PageResult;
  4 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostCreateReqVO;
  5 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostPageReqVO;
  6 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostUpdateReqVO;
3 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; 7 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
4 8
5 import javax.annotation.Nullable; 9 import javax.annotation.Nullable;
@@ -22,4 +26,42 @@ public interface SysPostService { @@ -22,4 +26,42 @@ public interface SysPostService {
22 */ 26 */
23 List<SysPostDO> listPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses); 27 List<SysPostDO> listPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses);
24 28
  29 + /**
  30 + * 获得岗位分页列表
  31 + *
  32 + * @param reqVO 分页条件
  33 + * @return 部门分页列表
  34 + */
  35 + PageResult<SysPostDO> pagePosts(SysPostPageReqVO reqVO);
  36 +
  37 + /**
  38 + * 获得岗位信息
  39 + *
  40 + * @param id 岗位编号
  41 + * @return 岗位信息
  42 + */
  43 + SysPostDO getPost(Long id);
  44 +
  45 + /**
  46 + * 创建岗位
  47 + *
  48 + * @param reqVO 岗位信息
  49 + * @return 岗位编号
  50 + */
  51 + Long createPost(SysPostCreateReqVO reqVO);
  52 +
  53 + /**
  54 + * 更新岗位
  55 + *
  56 + * @param reqVO 岗位信息
  57 + */
  58 + void updatePost(SysPostUpdateReqVO reqVO);
  59 +
  60 + /**
  61 + * 删除岗位信息
  62 + *
  63 + * @param id 岗位编号
  64 + */
  65 + void deletePost(Long id);
  66 +
25 } 67 }
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysDeptServiceImpl.java
@@ -175,7 +175,7 @@ public class SysDeptServiceImpl implements SysDeptService { @@ -175,7 +175,7 @@ public class SysDeptServiceImpl implements SysDeptService {
175 if (parentId.equals(id)) { 175 if (parentId.equals(id)) {
176 throw ServiceExceptionUtil.exception(DEPT_PARENT_ERROR); 176 throw ServiceExceptionUtil.exception(DEPT_PARENT_ERROR);
177 } 177 }
178 - // 父菜单不存在 178 + // 父岗位不存在
179 SysDeptDO dept = deptMapper.selectById(parentId); 179 SysDeptDO dept = deptMapper.selectById(parentId);
180 if (dept == null) { 180 if (dept == null) {
181 throw ServiceExceptionUtil.exception(DEPT_PARENT_NOT_EXITS); 181 throw ServiceExceptionUtil.exception(DEPT_PARENT_NOT_EXITS);
@@ -206,7 +206,7 @@ public class SysDeptServiceImpl implements SysDeptService { @@ -206,7 +206,7 @@ public class SysDeptServiceImpl implements SysDeptService {
206 if (menu == null) { 206 if (menu == null) {
207 return; 207 return;
208 } 208 }
209 - // 如果 id 为空,说明不用比较是否为相同 id 的菜单 209 + // 如果 id 为空,说明不用比较是否为相同 id 的岗位
210 if (id == null) { 210 if (id == null) {
211 throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE); 211 throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE);
212 } 212 }
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysPostServiceImpl.java
1 package cn.iocoder.dashboard.modules.system.service.dept.impl; 1 package cn.iocoder.dashboard.modules.system.service.dept.impl;
2 2
  3 +import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
  4 +import cn.iocoder.dashboard.common.pojo.PageResult;
  5 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostCreateReqVO;
  6 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostPageReqVO;
  7 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostUpdateReqVO;
  8 +import cn.iocoder.dashboard.modules.system.convert.dept.SysPostConvert;
3 import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept.SysPostMapper; 9 import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept.SysPostMapper;
4 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; 10 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
5 import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; 11 import cn.iocoder.dashboard.modules.system.service.dept.SysPostService;
@@ -9,6 +15,8 @@ import javax.annotation.Resource; @@ -9,6 +15,8 @@ import javax.annotation.Resource;
9 import java.util.Collection; 15 import java.util.Collection;
10 import java.util.List; 16 import java.util.List;
11 17
  18 +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
  19 +
12 /** 20 /**
13 * 岗位 Service 实现类 21 * 岗位 Service 实现类
14 * 22 *
@@ -25,4 +33,88 @@ public class SysPostServiceImpl implements SysPostService { @@ -25,4 +33,88 @@ public class SysPostServiceImpl implements SysPostService {
25 return postMapper.selectList(ids, statuses); 33 return postMapper.selectList(ids, statuses);
26 } 34 }
27 35
  36 + @Override
  37 + public PageResult<SysPostDO> pagePosts(SysPostPageReqVO reqVO) {
  38 + return SysPostConvert.INSTANCE.convertPage02(postMapper.selectList(reqVO));
  39 + }
  40 +
  41 + @Override
  42 + public SysPostDO getPost(Long id) {
  43 + return postMapper.selectById(id);
  44 + }
  45 +
  46 + @Override
  47 + public Long createPost(SysPostCreateReqVO reqVO) {
  48 + // 校验正确性
  49 + this.checkCreateOrUpdate(null, reqVO.getName(), reqVO.getCode());
  50 + // 插入岗位
  51 + SysPostDO post = SysPostConvert.INSTANCE.convert(reqVO);
  52 + postMapper.insert(post);
  53 + return post.getId();
  54 + }
  55 +
  56 + @Override
  57 + public void updatePost(SysPostUpdateReqVO reqVO) {
  58 + // 校验正确性
  59 + this.checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), reqVO.getCode());
  60 + // 更新岗位
  61 + SysPostDO updateObj = SysPostConvert.INSTANCE.convert(reqVO);
  62 + postMapper.updateById(updateObj);
  63 + }
  64 +
  65 + private void checkCreateOrUpdate(Long id, String name, String code) {
  66 + // 校验自己存在
  67 + checkPostExists(id);
  68 + // 校验岗位名的唯一性
  69 + checkPostNameUnique(id, name);
  70 + // 校验岗位编码的唯一性
  71 + checkPostCodeUnique(id, code);
  72 + }
  73 +
  74 + private void checkPostNameUnique(Long id, String name) {
  75 + SysPostDO post = postMapper.selectByName(name);
  76 + if (post == null) {
  77 + return;
  78 + }
  79 + // 如果 id 为空,说明不用比较是否为相同 id 的岗位
  80 + if (id == null) {
  81 + throw ServiceExceptionUtil.exception(POST_NAME_DUPLICATE);
  82 + }
  83 + if (!post.getId().equals(id)) {
  84 + throw ServiceExceptionUtil.exception(POST_NAME_DUPLICATE);
  85 + }
  86 + }
  87 +
  88 + private void checkPostCodeUnique(Long id, String code) {
  89 + SysPostDO post = postMapper.selectByCode(code);
  90 + if (post == null) {
  91 + return;
  92 + }
  93 + // 如果 id 为空,说明不用比较是否为相同 id 的岗位
  94 + if (id == null) {
  95 + throw ServiceExceptionUtil.exception(POST_CODE_DUPLICATE);
  96 + }
  97 + if (!post.getId().equals(id)) {
  98 + throw ServiceExceptionUtil.exception(POST_CODE_DUPLICATE);
  99 + }
  100 + }
  101 +
  102 + @Override
  103 + public void deletePost(Long id) {
  104 + // 校验是否存在
  105 + this.checkPostExists(id);
  106 + // 删除部门
  107 + postMapper.deleteById(id);
  108 + }
  109 +
  110 + private void checkPostExists(Long id) {
  111 + if (id == null) {
  112 + return;
  113 + }
  114 + SysPostDO post = postMapper.selectById(id);
  115 + if (post == null) {
  116 + throw ServiceExceptionUtil.exception(POST_NOT_FOUND);
  117 + }
  118 + }
  119 +
28 } 120 }