Parcourir la source

判断用户是否为该部门的经理级别岗位
修复用户新增失败
修复岗位新增失败
修复部门新增失败

csg6 il y a 10 mois
Parent
commit
eae65094fd

+ 24 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/UserPostAuthority.java

@@ -0,0 +1,24 @@
1
+package com.ruoyi.system.domain;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 用户岗位权限实体类
7
+ */
8
+@Data
9
+public class UserPostAuthority {
10
+
11
+   private Long userId;
12
+   private String userName;
13
+   private String nickName;
14
+
15
+   private Long postId;
16
+   private String postCode;
17
+   private String postName;
18
+    /**
19
+     * 岗位级别:0-不设置;1-经理;
20
+     */
21
+   private Integer postLevel;
22
+
23
+
24
+}

+ 19 - 14
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysPostMapper.java

@@ -1,18 +1,20 @@
1 1
 package com.ruoyi.system.mapper;
2 2
 
3 3
 import java.util.List;
4
+
4 5
 import com.ruoyi.system.domain.SysPost;
6
+import com.ruoyi.system.domain.UserPostAuthority;
7
+import org.apache.ibatis.annotations.Param;
5 8
 
6 9
 /**
7 10
  * 岗位信息 数据层
8
- * 
11
+ *
9 12
  * @author ruoyi
10 13
  */
11
-public interface SysPostMapper
12
-{
14
+public interface SysPostMapper {
13 15
     /**
14 16
      * 查询岗位数据集合
15
-     * 
17
+     *
16 18
      * @param post 岗位信息
17 19
      * @return 岗位数据集合
18 20
      */
@@ -20,14 +22,14 @@ public interface SysPostMapper
20 22
 
21 23
     /**
22 24
      * 查询所有岗位
23
-     * 
25
+     *
24 26
      * @return 岗位列表
25 27
      */
26 28
     public List<SysPost> selectPostAll();
27 29
 
28 30
     /**
29 31
      * 通过岗位ID查询岗位信息
30
-     * 
32
+     *
31 33
      * @param postId 岗位ID
32 34
      * @return 角色对象信息
33 35
      */
@@ -35,7 +37,7 @@ public interface SysPostMapper
35 37
 
36 38
     /**
37 39
      * 根据用户ID获取岗位选择框列表
38
-     * 
40
+     *
39 41
      * @param userId 用户ID
40 42
      * @return 选中岗位ID列表
41 43
      */
@@ -43,7 +45,7 @@ public interface SysPostMapper
43 45
 
44 46
     /**
45 47
      * 查询用户所属岗位组
46
-     * 
48
+     *
47 49
      * @param userName 用户名
48 50
      * @return 结果
49 51
      */
@@ -51,7 +53,7 @@ public interface SysPostMapper
51 53
 
52 54
     /**
53 55
      * 删除岗位信息
54
-     * 
56
+     *
55 57
      * @param postId 岗位ID
56 58
      * @return 结果
57 59
      */
@@ -59,7 +61,7 @@ public interface SysPostMapper
59 61
 
60 62
     /**
61 63
      * 批量删除岗位信息
62
-     * 
64
+     *
63 65
      * @param postIds 需要删除的岗位ID
64 66
      * @return 结果
65 67
      */
@@ -67,7 +69,7 @@ public interface SysPostMapper
67 69
 
68 70
     /**
69 71
      * 修改岗位信息
70
-     * 
72
+     *
71 73
      * @param post 岗位信息
72 74
      * @return 结果
73 75
      */
@@ -75,7 +77,7 @@ public interface SysPostMapper
75 77
 
76 78
     /**
77 79
      * 新增岗位信息
78
-     * 
80
+     *
79 81
      * @param post 岗位信息
80 82
      * @return 结果
81 83
      */
@@ -83,7 +85,7 @@ public interface SysPostMapper
83 85
 
84 86
     /**
85 87
      * 校验岗位名称
86
-     * 
88
+     *
87 89
      * @param postName 岗位名称
88 90
      * @return 结果
89 91
      */
@@ -91,7 +93,7 @@ public interface SysPostMapper
91 93
 
92 94
     /**
93 95
      * 校验岗位编码
94
-     * 
96
+     *
95 97
      * @param postCode 岗位编码
96 98
      * @return 结果
97 99
      */
@@ -99,8 +101,11 @@ public interface SysPostMapper
99 101
 
100 102
     /**
101 103
      * 根据部门查询岗位
104
+     *
102 105
      * @param deptId
103 106
      * @return
104 107
      */
105 108
     public SysPost selectPostByDeptId(Long deptId);
109
+
110
+    List<UserPostAuthority> userPostAuthorityList(@Param("deptId") Long deptId, @Param("postLevel") Integer postLevel);
106 111
 }

+ 28 - 12
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java

@@ -3,17 +3,18 @@ package com.ruoyi.system.service;
3 3
 import java.util.List;
4 4
 
5 5
 import com.ruoyi.system.domain.SysPost;
6
+import com.ruoyi.system.domain.UserPostAuthority;
6 7
 
7 8
 /**
8 9
  * 岗位信息 服务层
9
- * 
10
+ *
10 11
  * @author ruoyi
11 12
  */
12 13
 public interface ISysPostService
13 14
 {
14 15
     /**
15 16
      * 查询岗位信息集合
16
-     * 
17
+     *
17 18
      * @param post 岗位信息
18 19
      * @return 岗位列表
19 20
      */
@@ -21,14 +22,14 @@ public interface ISysPostService
21 22
 
22 23
     /**
23 24
      * 查询所有岗位
24
-     * 
25
+     *
25 26
      * @return 岗位列表
26 27
      */
27 28
     public List<SysPost> selectPostAll();
28 29
 
29 30
     /**
30 31
      * 通过岗位ID查询岗位信息
31
-     * 
32
+     *
32 33
      * @param postId 岗位ID
33 34
      * @return 角色对象信息
34 35
      */
@@ -36,7 +37,7 @@ public interface ISysPostService
36 37
 
37 38
     /**
38 39
      * 根据用户ID获取岗位选择框列表
39
-     * 
40
+     *
40 41
      * @param userId 用户ID
41 42
      * @return 选中岗位ID列表
42 43
      */
@@ -44,7 +45,7 @@ public interface ISysPostService
44 45
 
45 46
     /**
46 47
      * 校验岗位名称
47
-     * 
48
+     *
48 49
      * @param post 岗位信息
49 50
      * @return 结果
50 51
      */
@@ -52,7 +53,7 @@ public interface ISysPostService
52 53
 
53 54
     /**
54 55
      * 校验岗位编码
55
-     * 
56
+     *
56 57
      * @param post 岗位信息
57 58
      * @return 结果
58 59
      */
@@ -60,7 +61,7 @@ public interface ISysPostService
60 61
 
61 62
     /**
62 63
      * 通过岗位ID查询岗位使用数量
63
-     * 
64
+     *
64 65
      * @param postId 岗位ID
65 66
      * @return 结果
66 67
      */
@@ -68,7 +69,7 @@ public interface ISysPostService
68 69
 
69 70
     /**
70 71
      * 删除岗位信息
71
-     * 
72
+     *
72 73
      * @param postId 岗位ID
73 74
      * @return 结果
74 75
      */
@@ -76,7 +77,7 @@ public interface ISysPostService
76 77
 
77 78
     /**
78 79
      * 批量删除岗位信息
79
-     * 
80
+     *
80 81
      * @param postIds 需要删除的岗位ID
81 82
      * @return 结果
82 83
      */
@@ -84,7 +85,7 @@ public interface ISysPostService
84 85
 
85 86
     /**
86 87
      * 新增保存岗位信息
87
-     * 
88
+     *
88 89
      * @param post 岗位信息
89 90
      * @return 结果
90 91
      */
@@ -92,7 +93,7 @@ public interface ISysPostService
92 93
 
93 94
     /**
94 95
      * 修改保存岗位信息
95
-     * 
96
+     *
96 97
      * @param post 岗位信息
97 98
      * @return 结果
98 99
      */
@@ -104,4 +105,19 @@ public interface ISysPostService
104 105
      * @return
105 106
      */
106 107
     public SysPost selectPostByDeptId(Long deptId);
108
+
109
+    /**
110
+     * 查询部门经理级别岗位下的人员列表
111
+     * @param deptId 部门ID
112
+     * @param postLevel 岗位级别:0-不设置;1-经理;
113
+     * @return
114
+     */
115
+    List<UserPostAuthority> userPostAuthorityList(Long deptId,Integer postLevel);
116
+
117
+    /**
118
+     * 当前登录用户是否为部门经理级别
119
+     * @param deptId 部门ID
120
+     * @return
121
+     */
122
+   boolean userHaveAuthority(Long deptId);
107 123
 }

+ 56 - 88
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@@ -4,6 +4,8 @@ import java.util.ArrayList;
4 4
 import java.util.Iterator;
5 5
 import java.util.List;
6 6
 import java.util.stream.Collectors;
7
+
8
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
7 9
 import org.springframework.beans.factory.annotation.Autowired;
8 10
 import org.springframework.stereotype.Service;
9 11
 import com.ruoyi.common.annotation.DataScope;
@@ -23,12 +25,11 @@ import com.ruoyi.system.service.ISysDeptService;
23 25
 
24 26
 /**
25 27
  * 部门管理 服务实现
26
- * 
28
+ *
27 29
  * @author ruoyi
28 30
  */
29 31
 @Service
30
-public class SysDeptServiceImpl implements ISysDeptService
31
-{
32
+public class SysDeptServiceImpl implements ISysDeptService {
32 33
     @Autowired
33 34
     private SysDeptMapper deptMapper;
34 35
 
@@ -37,52 +38,46 @@ public class SysDeptServiceImpl implements ISysDeptService
37 38
 
38 39
     /**
39 40
      * 查询部门管理数据
40
-     * 
41
+     *
41 42
      * @param dept 部门信息
42 43
      * @return 部门信息集合
43 44
      */
44 45
     @Override
45 46
     @DataScope(deptAlias = "d")
46
-    public List<SysDept> selectDeptList(SysDept dept)
47
-    {
47
+    public List<SysDept> selectDeptList(SysDept dept) {
48 48
         return deptMapper.selectDeptList(dept);
49 49
     }
50 50
 
51 51
     /**
52 52
      * 查询部门树结构信息
53
-     * 
53
+     *
54 54
      * @param dept 部门信息
55 55
      * @return 部门树信息集合
56 56
      */
57 57
     @Override
58
-    public List<TreeSelect> selectDeptTreeList(SysDept dept)
59
-    {
58
+    public List<TreeSelect> selectDeptTreeList(SysDept dept) {
60 59
         List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
61 60
         return buildDeptTreeSelect(depts);
62 61
     }
63 62
 
64 63
     /**
65 64
      * 构建前端所需要树结构
66
-     * 
65
+     *
67 66
      * @param depts 部门列表
68 67
      * @return 树结构列表
69 68
      */
70 69
     @Override
71
-    public List<SysDept> buildDeptTree(List<SysDept> depts)
72
-    {
70
+    public List<SysDept> buildDeptTree(List<SysDept> depts) {
73 71
         List<SysDept> returnList = new ArrayList<SysDept>();
74 72
         List<Long> tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList());
75
-        for (SysDept dept : depts)
76
-        {
73
+        for (SysDept dept : depts) {
77 74
             // 如果是顶级节点, 遍历该父节点的所有子节点
78
-            if (!tempList.contains(dept.getParentId()))
79
-            {
75
+            if (!tempList.contains(dept.getParentId())) {
80 76
                 recursionFn(depts, dept);
81 77
                 returnList.add(dept);
82 78
             }
83 79
         }
84
-        if (returnList.isEmpty())
85
-        {
80
+        if (returnList.isEmpty()) {
86 81
             returnList = depts;
87 82
         }
88 83
         return returnList;
@@ -90,93 +85,85 @@ public class SysDeptServiceImpl implements ISysDeptService
90 85
 
91 86
     /**
92 87
      * 构建前端所需要下拉树结构
93
-     * 
88
+     *
94 89
      * @param depts 部门列表
95 90
      * @return 下拉树结构列表
96 91
      */
97 92
     @Override
98
-    public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts)
99
-    {
93
+    public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts) {
100 94
         List<SysDept> deptTrees = buildDeptTree(depts);
101 95
         return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
102 96
     }
103 97
 
104 98
     /**
105 99
      * 根据角色ID查询部门树信息
106
-     * 
100
+     *
107 101
      * @param roleId 角色ID
108 102
      * @return 选中部门列表
109 103
      */
110 104
     @Override
111
-    public List<Long> selectDeptListByRoleId(Long roleId)
112
-    {
105
+    public List<Long> selectDeptListByRoleId(Long roleId) {
113 106
         SysRole role = roleMapper.selectRoleById(roleId);
114 107
         return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());
115 108
     }
116 109
 
117 110
     /**
118 111
      * 根据部门ID查询信息
119
-     * 
112
+     *
120 113
      * @param deptId 部门ID
121 114
      * @return 部门信息
122 115
      */
123 116
     @Override
124
-    public SysDept selectDeptById(Long deptId)
125
-    {
117
+    public SysDept selectDeptById(Long deptId) {
126 118
         return deptMapper.selectDeptById(deptId);
127 119
     }
128 120
 
129 121
     /**
130 122
      * 根据ID查询所有子部门(正常状态)
131
-     * 
123
+     *
132 124
      * @param deptId 部门ID
133 125
      * @return 子部门数
134 126
      */
135 127
     @Override
136
-    public int selectNormalChildrenDeptById(Long deptId)
137
-    {
128
+    public int selectNormalChildrenDeptById(Long deptId) {
138 129
         return deptMapper.selectNormalChildrenDeptById(deptId);
139 130
     }
140 131
 
141 132
     /**
142 133
      * 是否存在子节点
143
-     * 
134
+     *
144 135
      * @param deptId 部门ID
145 136
      * @return 结果
146 137
      */
147 138
     @Override
148
-    public boolean hasChildByDeptId(Long deptId)
149
-    {
139
+    public boolean hasChildByDeptId(Long deptId) {
150 140
         int result = deptMapper.hasChildByDeptId(deptId);
151 141
         return result > 0;
152 142
     }
153 143
 
154 144
     /**
155 145
      * 查询部门是否存在用户
156
-     * 
146
+     *
157 147
      * @param deptId 部门ID
158 148
      * @return 结果 true 存在 false 不存在
159 149
      */
160 150
     @Override
161
-    public boolean checkDeptExistUser(Long deptId)
162
-    {
151
+    public boolean checkDeptExistUser(Long deptId) {
163 152
         int result = deptMapper.checkDeptExistUser(deptId);
164 153
         return result > 0;
165 154
     }
166 155
 
167 156
     /**
168 157
      * 校验部门名称是否唯一
169
-     * 
158
+     *
170 159
      * @param dept 部门信息
171 160
      * @return 结果
172 161
      */
173 162
     @Override
174
-    public boolean checkDeptNameUnique(SysDept dept)
175
-    {
163
+    public boolean checkDeptNameUnique(SysDept dept) {
176 164
         Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
177 165
         SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
178
-        if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())
179
-        {
166
+        if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) {
180 167
             return UserConstants.NOT_UNIQUE;
181 168
         }
182 169
         return UserConstants.UNIQUE;
@@ -184,19 +171,16 @@ public class SysDeptServiceImpl implements ISysDeptService
184 171
 
185 172
     /**
186 173
      * 校验部门是否有数据权限
187
-     * 
174
+     *
188 175
      * @param deptId 部门id
189 176
      */
190 177
     @Override
191
-    public void checkDeptDataScope(Long deptId)
192
-    {
193
-        if (!SysUser.isAdmin(SecurityUtils.getUserId()))
194
-        {
178
+    public void checkDeptDataScope(Long deptId) {
179
+        if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
195 180
             SysDept dept = new SysDept();
196 181
             dept.setDeptId(deptId);
197 182
             List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
198
-            if (StringUtils.isEmpty(depts))
199
-            {
183
+            if (StringUtils.isEmpty(depts)) {
200 184
                 throw new ServiceException("没有权限访问部门数据!");
201 185
             }
202 186
         }
@@ -204,36 +188,33 @@ public class SysDeptServiceImpl implements ISysDeptService
204 188
 
205 189
     /**
206 190
      * 新增保存部门信息
207
-     * 
191
+     *
208 192
      * @param dept 部门信息
209 193
      * @return 结果
210 194
      */
211 195
     @Override
212
-    public int insertDept(SysDept dept)
213
-    {
196
+    public int insertDept(SysDept dept) {
214 197
         SysDept info = deptMapper.selectDeptById(dept.getParentId());
215 198
         // 如果父节点不为正常状态,则不允许新增子节点
216
-        if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
217
-        {
199
+        if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
218 200
             throw new ServiceException("部门停用,不允许新增");
219 201
         }
220 202
         dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
203
+        dept.setDeptId(Long.parseLong(IdWorker.getIdStr().substring(4)));
221 204
         return deptMapper.insertDept(dept);
222 205
     }
223 206
 
224 207
     /**
225 208
      * 修改保存部门信息
226
-     * 
209
+     *
227 210
      * @param dept 部门信息
228 211
      * @return 结果
229 212
      */
230 213
     @Override
231
-    public int updateDept(SysDept dept)
232
-    {
214
+    public int updateDept(SysDept dept) {
233 215
         SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
234 216
         SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
235
-        if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
236
-        {
217
+        if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) {
237 218
             String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
238 219
             String oldAncestors = oldDept.getAncestors();
239 220
             dept.setAncestors(newAncestors);
@@ -241,8 +222,7 @@ public class SysDeptServiceImpl implements ISysDeptService
241 222
         }
242 223
         int result = deptMapper.updateDept(dept);
243 224
         if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
244
-                && !StringUtils.equals("0", dept.getAncestors()))
245
-        {
225
+                && !StringUtils.equals("0", dept.getAncestors())) {
246 226
             // 如果该部门是启用状态,则启用该部门的所有上级部门
247 227
             updateParentDeptStatusNormal(dept);
248 228
         }
@@ -251,11 +231,10 @@ public class SysDeptServiceImpl implements ISysDeptService
251 231
 
252 232
     /**
253 233
      * 修改该部门的父级部门状态
254
-     * 
234
+     *
255 235
      * @param dept 当前部门
256 236
      */
257
-    private void updateParentDeptStatusNormal(SysDept dept)
258
-    {
237
+    private void updateParentDeptStatusNormal(SysDept dept) {
259 238
         String ancestors = dept.getAncestors();
260 239
         Long[] deptIds = Convert.toLongArray(ancestors);
261 240
         deptMapper.updateDeptStatusNormal(deptIds);
@@ -263,48 +242,41 @@ public class SysDeptServiceImpl implements ISysDeptService
263 242
 
264 243
     /**
265 244
      * 修改子元素关系
266
-     * 
267
-     * @param deptId 被修改的部门ID
245
+     *
246
+     * @param deptId       被修改的部门ID
268 247
      * @param newAncestors 新的父ID集合
269 248
      * @param oldAncestors 旧的父ID集合
270 249
      */
271
-    public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors)
272
-    {
250
+    public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
273 251
         List<SysDept> children = deptMapper.selectChildrenDeptById(deptId);
274
-        for (SysDept child : children)
275
-        {
252
+        for (SysDept child : children) {
276 253
             child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
277 254
         }
278
-        if (children.size() > 0)
279
-        {
255
+        if (children.size() > 0) {
280 256
             deptMapper.updateDeptChildren(children);
281 257
         }
282 258
     }
283 259
 
284 260
     /**
285 261
      * 删除部门管理信息
286
-     * 
262
+     *
287 263
      * @param deptId 部门ID
288 264
      * @return 结果
289 265
      */
290 266
     @Override
291
-    public int deleteDeptById(Long deptId)
292
-    {
267
+    public int deleteDeptById(Long deptId) {
293 268
         return deptMapper.deleteDeptById(deptId);
294 269
     }
295 270
 
296 271
     /**
297 272
      * 递归列表
298 273
      */
299
-    private void recursionFn(List<SysDept> list, SysDept t)
300
-    {
274
+    private void recursionFn(List<SysDept> list, SysDept t) {
301 275
         // 得到子节点列表
302 276
         List<SysDept> childList = getChildList(list, t);
303 277
         t.setChildren(childList);
304
-        for (SysDept tChild : childList)
305
-        {
306
-            if (hasChild(list, tChild))
307
-            {
278
+        for (SysDept tChild : childList) {
279
+            if (hasChild(list, tChild)) {
308 280
                 recursionFn(list, tChild);
309 281
             }
310 282
         }
@@ -313,15 +285,12 @@ public class SysDeptServiceImpl implements ISysDeptService
313 285
     /**
314 286
      * 得到子节点列表
315 287
      */
316
-    private List<SysDept> getChildList(List<SysDept> list, SysDept t)
317
-    {
288
+    private List<SysDept> getChildList(List<SysDept> list, SysDept t) {
318 289
         List<SysDept> tlist = new ArrayList<SysDept>();
319 290
         Iterator<SysDept> it = list.iterator();
320
-        while (it.hasNext())
321
-        {
291
+        while (it.hasNext()) {
322 292
             SysDept n = (SysDept) it.next();
323
-            if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue())
324
-            {
293
+            if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) {
325 294
                 tlist.add(n);
326 295
             }
327 296
         }
@@ -331,8 +300,7 @@ public class SysDeptServiceImpl implements ISysDeptService
331 300
     /**
332 301
      * 判断是否有子节点
333 302
      */
334
-    private boolean hasChild(List<SysDept> list, SysDept t)
335
-    {
303
+    private boolean hasChild(List<SysDept> list, SysDept t) {
336 304
         return getChildList(list, t).size() > 0;
337 305
     }
338 306
 }

+ 73 - 44
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java

@@ -1,6 +1,12 @@
1 1
 package com.ruoyi.system.service.impl;
2 2
 
3 3
 import java.util.List;
4
+import java.util.stream.Collectors;
5
+
6
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
7
+import com.ruoyi.common.exception.base.BaseException;
8
+import com.ruoyi.common.utils.SecurityUtils;
9
+import com.ruoyi.system.domain.UserPostAuthority;
4 10
 import org.springframework.beans.factory.annotation.Autowired;
5 11
 import org.springframework.stereotype.Service;
6 12
 import com.ruoyi.common.constant.UserConstants;
@@ -10,15 +16,15 @@ import com.ruoyi.system.domain.SysPost;
10 16
 import com.ruoyi.system.mapper.SysPostMapper;
11 17
 import com.ruoyi.system.mapper.SysUserPostMapper;
12 18
 import com.ruoyi.system.service.ISysPostService;
19
+import org.springframework.util.CollectionUtils;
13 20
 
14 21
 /**
15 22
  * 岗位信息 服务层处理
16
- * 
23
+ *
17 24
  * @author ruoyi
18 25
  */
19 26
 @Service
20
-public class SysPostServiceImpl implements ISysPostService
21
-{
27
+public class SysPostServiceImpl implements ISysPostService {
22 28
     @Autowired
23 29
     private SysPostMapper postMapper;
24 30
 
@@ -27,64 +33,58 @@ public class SysPostServiceImpl implements ISysPostService
27 33
 
28 34
     /**
29 35
      * 查询岗位信息集合
30
-     * 
36
+     *
31 37
      * @param post 岗位信息
32 38
      * @return 岗位信息集合
33 39
      */
34 40
     @Override
35
-    public List<SysPost> selectPostList(SysPost post)
36
-    {
41
+    public List<SysPost> selectPostList(SysPost post) {
37 42
         return postMapper.selectPostList(post);
38 43
     }
39 44
 
40 45
     /**
41 46
      * 查询所有岗位
42
-     * 
47
+     *
43 48
      * @return 岗位列表
44 49
      */
45 50
     @Override
46
-    public List<SysPost> selectPostAll()
47
-    {
51
+    public List<SysPost> selectPostAll() {
48 52
         return postMapper.selectPostAll();
49 53
     }
50 54
 
51 55
     /**
52 56
      * 通过岗位ID查询岗位信息
53
-     * 
57
+     *
54 58
      * @param postId 岗位ID
55 59
      * @return 角色对象信息
56 60
      */
57 61
     @Override
58
-    public SysPost selectPostById(Long postId)
59
-    {
62
+    public SysPost selectPostById(Long postId) {
60 63
         return postMapper.selectPostById(postId);
61 64
     }
62 65
 
63 66
     /**
64 67
      * 根据用户ID获取岗位选择框列表
65
-     * 
68
+     *
66 69
      * @param userId 用户ID
67 70
      * @return 选中岗位ID列表
68 71
      */
69 72
     @Override
70
-    public List<Long> selectPostListByUserId(Long userId)
71
-    {
73
+    public List<Long> selectPostListByUserId(Long userId) {
72 74
         return postMapper.selectPostListByUserId(userId);
73 75
     }
74 76
 
75 77
     /**
76 78
      * 校验岗位名称是否唯一
77
-     * 
79
+     *
78 80
      * @param post 岗位信息
79 81
      * @return 结果
80 82
      */
81 83
     @Override
82
-    public boolean checkPostNameUnique(SysPost post)
83
-    {
84
+    public boolean checkPostNameUnique(SysPost post) {
84 85
         Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
85 86
         SysPost info = postMapper.checkPostNameUnique(post.getPostName());
86
-        if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue())
87
-        {
87
+        if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
88 88
             return UserConstants.NOT_UNIQUE;
89 89
         }
90 90
         return UserConstants.UNIQUE;
@@ -92,17 +92,15 @@ public class SysPostServiceImpl implements ISysPostService
92 92
 
93 93
     /**
94 94
      * 校验岗位编码是否唯一
95
-     * 
95
+     *
96 96
      * @param post 岗位信息
97 97
      * @return 结果
98 98
      */
99 99
     @Override
100
-    public boolean checkPostCodeUnique(SysPost post)
101
-    {
100
+    public boolean checkPostCodeUnique(SysPost post) {
102 101
         Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
103 102
         SysPost info = postMapper.checkPostCodeUnique(post.getPostCode());
104
-        if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue())
105
-        {
103
+        if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
106 104
             return UserConstants.NOT_UNIQUE;
107 105
         }
108 106
         return UserConstants.UNIQUE;
@@ -110,42 +108,37 @@ public class SysPostServiceImpl implements ISysPostService
110 108
 
111 109
     /**
112 110
      * 通过岗位ID查询岗位使用数量
113
-     * 
111
+     *
114 112
      * @param postId 岗位ID
115 113
      * @return 结果
116 114
      */
117 115
     @Override
118
-    public int countUserPostById(Long postId)
119
-    {
116
+    public int countUserPostById(Long postId) {
120 117
         return userPostMapper.countUserPostById(postId);
121 118
     }
122 119
 
123 120
     /**
124 121
      * 删除岗位信息
125
-     * 
122
+     *
126 123
      * @param postId 岗位ID
127 124
      * @return 结果
128 125
      */
129 126
     @Override
130
-    public int deletePostById(Long postId)
131
-    {
127
+    public int deletePostById(Long postId) {
132 128
         return postMapper.deletePostById(postId);
133 129
     }
134 130
 
135 131
     /**
136 132
      * 批量删除岗位信息
137
-     * 
133
+     *
138 134
      * @param postIds 需要删除的岗位ID
139 135
      * @return 结果
140 136
      */
141 137
     @Override
142
-    public int deletePostByIds(Long[] postIds)
143
-    {
144
-        for (Long postId : postIds)
145
-        {
138
+    public int deletePostByIds(Long[] postIds) {
139
+        for (Long postId : postIds) {
146 140
             SysPost post = selectPostById(postId);
147
-            if (countUserPostById(postId) > 0)
148
-            {
141
+            if (countUserPostById(postId) > 0) {
149 142
                 throw new ServiceException(String.format("%1$s已分配,不能删除", post.getPostName()));
150 143
             }
151 144
         }
@@ -154,30 +147,30 @@ public class SysPostServiceImpl implements ISysPostService
154 147
 
155 148
     /**
156 149
      * 新增保存岗位信息
157
-     * 
150
+     *
158 151
      * @param post 岗位信息
159 152
      * @return 结果
160 153
      */
161 154
     @Override
162
-    public int insertPost(SysPost post)
163
-    {
155
+    public int insertPost(SysPost post) {
156
+        post.setPostId(Long.parseLong(IdWorker.getIdStr().substring(4)));
164 157
         return postMapper.insertPost(post);
165 158
     }
166 159
 
167 160
     /**
168 161
      * 修改保存岗位信息
169
-     * 
162
+     *
170 163
      * @param post 岗位信息
171 164
      * @return 结果
172 165
      */
173 166
     @Override
174
-    public int updatePost(SysPost post)
175
-    {
167
+    public int updatePost(SysPost post) {
176 168
         return postMapper.updatePost(post);
177 169
     }
178 170
 
179 171
     /**
180 172
      * 根据部门查询岗位
173
+     *
181 174
      * @param deptId
182 175
      * @return
183 176
      */
@@ -185,4 +178,40 @@ public class SysPostServiceImpl implements ISysPostService
185 178
     public SysPost selectPostByDeptId(Long deptId) {
186 179
         return postMapper.selectPostByDeptId(deptId);
187 180
     }
181
+
182
+    /**
183
+     * 查询部门经理级别岗位下的人员列表
184
+     *
185
+     * @param deptId    部门ID
186
+     * @param postLevel 岗位级别
187
+     * @return
188
+     */
189
+    @Override
190
+    public List<UserPostAuthority> userPostAuthorityList(Long deptId, Integer postLevel) {
191
+
192
+        return postMapper.userPostAuthorityList(deptId, postLevel);
193
+    }
194
+
195
+    /**
196
+     * 当前登录用户是否为部门经理级别
197
+     *
198
+     * @param deptId 部门ID
199
+     * @return
200
+     */
201
+    @Override
202
+    public boolean userHaveAuthority(Long deptId) {
203
+        Integer postLevel = 1;//岗位级别:0-不设置;1-经理;
204
+        Long userId = SecurityUtils.getUserId();
205
+
206
+        // 判断岗位是否在权限范围内
207
+        List<UserPostAuthority> userPostAuthorityList = userPostAuthorityList(deptId, postLevel);
208
+        if (CollectionUtils.isEmpty(userPostAuthorityList)) {
209
+            return false;
210
+        }
211
+        List<Long> haveAuthorityUserList = userPostAuthorityList.stream().map(t -> t.getUserId()).collect(Collectors.toList());
212
+        if (haveAuthorityUserList.contains(userId)) {
213
+            return true;
214
+        }
215
+        return false;
216
+    }
188 217
 }

+ 60 - 111
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -4,6 +4,8 @@ import java.util.ArrayList;
4 4
 import java.util.List;
5 5
 import java.util.stream.Collectors;
6 6
 import javax.validation.Validator;
7
+
8
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
7 9
 import org.slf4j.Logger;
8 10
 import org.slf4j.LoggerFactory;
9 11
 import org.springframework.beans.factory.annotation.Autowired;
@@ -36,8 +38,7 @@ import com.ruoyi.system.service.ISysUserService;
36 38
  * @author ruoyi
37 39
  */
38 40
 @Service
39
-public class SysUserServiceImpl implements ISysUserService
40
-{
41
+public class SysUserServiceImpl implements ISysUserService {
41 42
     private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
42 43
 
43 44
     @Autowired
@@ -69,8 +70,7 @@ public class SysUserServiceImpl implements ISysUserService
69 70
      */
70 71
     @Override
71 72
     @DataScope(deptAlias = "d", userAlias = "u")
72
-    public List<SysUser> selectUserList(SysUser user)
73
-    {
73
+    public List<SysUser> selectUserList(SysUser user) {
74 74
         return userMapper.selectUserList(user);
75 75
     }
76 76
 
@@ -82,8 +82,7 @@ public class SysUserServiceImpl implements ISysUserService
82 82
      */
83 83
     @Override
84 84
     @DataScope(deptAlias = "d", userAlias = "u")
85
-    public List<SysUser> selectAllocatedList(SysUser user)
86
-    {
85
+    public List<SysUser> selectAllocatedList(SysUser user) {
87 86
         return userMapper.selectAllocatedList(user);
88 87
     }
89 88
 
@@ -95,8 +94,7 @@ public class SysUserServiceImpl implements ISysUserService
95 94
      */
96 95
     @Override
97 96
     @DataScope(deptAlias = "d", userAlias = "u")
98
-    public List<SysUser> selectUnallocatedList(SysUser user)
99
-    {
97
+    public List<SysUser> selectUnallocatedList(SysUser user) {
100 98
         return userMapper.selectUnallocatedList(user);
101 99
     }
102 100
 
@@ -107,8 +105,7 @@ public class SysUserServiceImpl implements ISysUserService
107 105
      * @return 用户对象信息
108 106
      */
109 107
     @Override
110
-    public SysUser selectUserByUserName(String userName)
111
-    {
108
+    public SysUser selectUserByUserName(String userName) {
112 109
         return userMapper.selectUserByUserName(userName);
113 110
     }
114 111
 
@@ -119,8 +116,7 @@ public class SysUserServiceImpl implements ISysUserService
119 116
      * @return 用户对象信息
120 117
      */
121 118
     @Override
122
-    public SysUser selectUserById(Long userId)
123
-    {
119
+    public SysUser selectUserById(Long userId) {
124 120
         return userMapper.selectUserById(userId);
125 121
     }
126 122
 
@@ -131,11 +127,9 @@ public class SysUserServiceImpl implements ISysUserService
131 127
      * @return 结果
132 128
      */
133 129
     @Override
134
-    public String selectUserRoleGroup(String userName)
135
-    {
130
+    public String selectUserRoleGroup(String userName) {
136 131
         List<SysRole> list = roleMapper.selectRolesByUserName(userName);
137
-        if (CollectionUtils.isEmpty(list))
138
-        {
132
+        if (CollectionUtils.isEmpty(list)) {
139 133
             return StringUtils.EMPTY;
140 134
         }
141 135
         return list.stream().map(SysRole::getRoleName).collect(Collectors.joining(","));
@@ -148,11 +142,9 @@ public class SysUserServiceImpl implements ISysUserService
148 142
      * @return 结果
149 143
      */
150 144
     @Override
151
-    public String selectUserPostGroup(String userName)
152
-    {
145
+    public String selectUserPostGroup(String userName) {
153 146
         List<SysPost> list = postMapper.selectPostsByUserName(userName);
154
-        if (CollectionUtils.isEmpty(list))
155
-        {
147
+        if (CollectionUtils.isEmpty(list)) {
156 148
             return StringUtils.EMPTY;
157 149
         }
158 150
         return list.stream().map(SysPost::getPostName).collect(Collectors.joining(","));
@@ -165,12 +157,10 @@ public class SysUserServiceImpl implements ISysUserService
165 157
      * @return 结果
166 158
      */
167 159
     @Override
168
-    public boolean checkUserNameUnique(SysUser user)
169
-    {
160
+    public boolean checkUserNameUnique(SysUser user) {
170 161
         Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
171 162
         SysUser info = userMapper.checkUserNameUnique(user.getUserName());
172
-        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
173
-        {
163
+        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
174 164
             return UserConstants.NOT_UNIQUE;
175 165
         }
176 166
         return UserConstants.UNIQUE;
@@ -183,12 +173,10 @@ public class SysUserServiceImpl implements ISysUserService
183 173
      * @return
184 174
      */
185 175
     @Override
186
-    public boolean checkPhoneUnique(SysUser user)
187
-    {
176
+    public boolean checkPhoneUnique(SysUser user) {
188 177
         Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
189 178
         SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber());
190
-        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
191
-        {
179
+        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
192 180
             return UserConstants.NOT_UNIQUE;
193 181
         }
194 182
         return UserConstants.UNIQUE;
@@ -201,12 +189,10 @@ public class SysUserServiceImpl implements ISysUserService
201 189
      * @return
202 190
      */
203 191
     @Override
204
-    public boolean checkEmailUnique(SysUser user)
205
-    {
192
+    public boolean checkEmailUnique(SysUser user) {
206 193
         Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
207 194
         SysUser info = userMapper.checkEmailUnique(user.getEmail());
208
-        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
209
-        {
195
+        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
210 196
             return UserConstants.NOT_UNIQUE;
211 197
         }
212 198
         return UserConstants.UNIQUE;
@@ -218,10 +204,8 @@ public class SysUserServiceImpl implements ISysUserService
218 204
      * @param user 用户信息
219 205
      */
220 206
     @Override
221
-    public void checkUserAllowed(SysUser user)
222
-    {
223
-        if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin())
224
-        {
207
+    public void checkUserAllowed(SysUser user) {
208
+        if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) {
225 209
             throw new ServiceException("不允许操作超级管理员用户");
226 210
         }
227 211
     }
@@ -232,15 +216,12 @@ public class SysUserServiceImpl implements ISysUserService
232 216
      * @param userId 用户id
233 217
      */
234 218
     @Override
235
-    public void checkUserDataScope(Long userId)
236
-    {
237
-        if (!SysUser.isAdmin(SecurityUtils.getUserId()))
238
-        {
219
+    public void checkUserDataScope(Long userId) {
220
+        if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
239 221
             SysUser user = new SysUser();
240 222
             user.setUserId(userId);
241 223
             List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user);
242
-            if (StringUtils.isEmpty(users))
243
-            {
224
+            if (StringUtils.isEmpty(users)) {
244 225
                 throw new ServiceException("没有权限访问用户数据!");
245 226
             }
246 227
         }
@@ -254,8 +235,8 @@ public class SysUserServiceImpl implements ISysUserService
254 235
      */
255 236
     @Override
256 237
     @Transactional
257
-    public int insertUser(SysUser user)
258
-    {
238
+    public int insertUser(SysUser user) {
239
+        user.setUserId(Long.parseLong(IdWorker.getIdStr().substring(4)));
259 240
         // 新增用户信息
260 241
         int rows = userMapper.insertUser(user);
261 242
         // 新增用户岗位关联
@@ -272,8 +253,7 @@ public class SysUserServiceImpl implements ISysUserService
272 253
      * @return 结果
273 254
      */
274 255
     @Override
275
-    public boolean registerUser(SysUser user)
276
-    {
256
+    public boolean registerUser(SysUser user) {
277 257
         return userMapper.insertUser(user) > 0;
278 258
     }
279 259
 
@@ -285,8 +265,7 @@ public class SysUserServiceImpl implements ISysUserService
285 265
      */
286 266
     @Override
287 267
     @Transactional
288
-    public int updateUser(SysUser user)
289
-    {
268
+    public int updateUser(SysUser user) {
290 269
         Long userId = user.getUserId();
291 270
         // 删除用户与角色关联
292 271
         userRoleMapper.deleteUserRoleByUserId(userId);
@@ -302,13 +281,12 @@ public class SysUserServiceImpl implements ISysUserService
302 281
     /**
303 282
      * 用户授权角色
304 283
      *
305
-     * @param userId 用户ID
284
+     * @param userId  用户ID
306 285
      * @param roleIds 角色组
307 286
      */
308 287
     @Override
309 288
     @Transactional
310
-    public void insertUserAuth(Long userId, Long[] roleIds)
311
-    {
289
+    public void insertUserAuth(Long userId, Long[] roleIds) {
312 290
         userRoleMapper.deleteUserRoleByUserId(userId);
313 291
         insertUserRole(userId, roleIds);
314 292
     }
@@ -320,8 +298,7 @@ public class SysUserServiceImpl implements ISysUserService
320 298
      * @return 结果
321 299
      */
322 300
     @Override
323
-    public int updateUserStatus(SysUser user)
324
-    {
301
+    public int updateUserStatus(SysUser user) {
325 302
         return userMapper.updateUser(user);
326 303
     }
327 304
 
@@ -332,8 +309,7 @@ public class SysUserServiceImpl implements ISysUserService
332 309
      * @return 结果
333 310
      */
334 311
     @Override
335
-    public int updateUserProfile(SysUser user)
336
-    {
312
+    public int updateUserProfile(SysUser user) {
337 313
         return userMapper.updateUser(user);
338 314
     }
339 315
 
@@ -341,12 +317,11 @@ public class SysUserServiceImpl implements ISysUserService
341 317
      * 修改用户头像
342 318
      *
343 319
      * @param userName 用户名
344
-     * @param avatar 头像地址
320
+     * @param avatar   头像地址
345 321
      * @return 结果
346 322
      */
347 323
     @Override
348
-    public boolean updateUserAvatar(String userName, String avatar)
349
-    {
324
+    public boolean updateUserAvatar(String userName, String avatar) {
350 325
         return userMapper.updateUserAvatar(userName, avatar) > 0;
351 326
     }
352 327
 
@@ -357,8 +332,7 @@ public class SysUserServiceImpl implements ISysUserService
357 332
      * @return 结果
358 333
      */
359 334
     @Override
360
-    public int resetPwd(SysUser user)
361
-    {
335
+    public int resetPwd(SysUser user) {
362 336
         return userMapper.updateUser(user);
363 337
     }
364 338
 
@@ -370,8 +344,7 @@ public class SysUserServiceImpl implements ISysUserService
370 344
      * @return 结果
371 345
      */
372 346
     @Override
373
-    public int resetUserPwd(String userName, String password)
374
-    {
347
+    public int resetUserPwd(String userName, String password) {
375 348
         return userMapper.resetUserPwd(userName, password);
376 349
     }
377 350
 
@@ -380,8 +353,7 @@ public class SysUserServiceImpl implements ISysUserService
380 353
      *
381 354
      * @param user 用户对象
382 355
      */
383
-    public void insertUserRole(SysUser user)
384
-    {
356
+    public void insertUserRole(SysUser user) {
385 357
         this.insertUserRole(user.getUserId(), user.getRoleIds());
386 358
     }
387 359
 
@@ -390,15 +362,12 @@ public class SysUserServiceImpl implements ISysUserService
390 362
      *
391 363
      * @param user 用户对象
392 364
      */
393
-    public void insertUserPost(SysUser user)
394
-    {
365
+    public void insertUserPost(SysUser user) {
395 366
         Long[] posts = user.getPostIds();
396
-        if (StringUtils.isNotEmpty(posts))
397
-        {
367
+        if (StringUtils.isNotEmpty(posts)) {
398 368
             // 新增用户与岗位管理
399
-            List<SysUserPost> list = new ArrayList<SysUserPost>(posts.length);
400
-            for (Long postId : posts)
401
-            {
369
+            List<SysUserPost> list = new ArrayList<>(posts.length);
370
+            for (Long postId : posts) {
402 371
                 SysUserPost up = new SysUserPost();
403 372
                 up.setUserId(user.getUserId());
404 373
                 up.setPostId(postId);
@@ -411,17 +380,14 @@ public class SysUserServiceImpl implements ISysUserService
411 380
     /**
412 381
      * 新增用户角色信息
413 382
      *
414
-     * @param userId 用户ID
383
+     * @param userId  用户ID
415 384
      * @param roleIds 角色组
416 385
      */
417
-    public void insertUserRole(Long userId, Long[] roleIds)
418
-    {
419
-        if (StringUtils.isNotEmpty(roleIds))
420
-        {
386
+    public void insertUserRole(Long userId, Long[] roleIds) {
387
+        if (StringUtils.isNotEmpty(roleIds)) {
421 388
             // 新增用户与角色管理
422 389
             List<SysUserRole> list = new ArrayList<SysUserRole>(roleIds.length);
423
-            for (Long roleId : roleIds)
424
-            {
390
+            for (Long roleId : roleIds) {
425 391
                 SysUserRole ur = new SysUserRole();
426 392
                 ur.setUserId(userId);
427 393
                 ur.setRoleId(roleId);
@@ -439,8 +405,7 @@ public class SysUserServiceImpl implements ISysUserService
439 405
      */
440 406
     @Override
441 407
     @Transactional
442
-    public int deleteUserById(Long userId)
443
-    {
408
+    public int deleteUserById(Long userId) {
444 409
         // 删除用户与角色关联
445 410
         userRoleMapper.deleteUserRoleByUserId(userId);
446 411
         // 删除用户与岗位表
@@ -456,10 +421,8 @@ public class SysUserServiceImpl implements ISysUserService
456 421
      */
457 422
     @Override
458 423
     @Transactional
459
-    public int deleteUserByIds(Long[] userIds)
460
-    {
461
-        for (Long userId : userIds)
462
-        {
424
+    public int deleteUserByIds(Long[] userIds) {
425
+        for (Long userId : userIds) {
463 426
             checkUserAllowed(new SysUser(userId));
464 427
             checkUserDataScope(userId);
465 428
         }
@@ -473,16 +436,14 @@ public class SysUserServiceImpl implements ISysUserService
473 436
     /**
474 437
      * 导入用户数据
475 438
      *
476
-     * @param userList 用户数据列表
439
+     * @param userList        用户数据列表
477 440
      * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
478
-     * @param operName 操作用户
441
+     * @param operName        操作用户
479 442
      * @return 结果
480 443
      */
481 444
     @Override
482
-    public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName)
483
-    {
484
-        if (StringUtils.isNull(userList) || userList.size() == 0)
485
-        {
445
+    public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) {
446
+        if (StringUtils.isNull(userList) || userList.size() == 0) {
486 447
             throw new ServiceException("导入用户数据不能为空!");
487 448
         }
488 449
         int successNum = 0;
@@ -490,23 +451,18 @@ public class SysUserServiceImpl implements ISysUserService
490 451
         StringBuilder successMsg = new StringBuilder();
491 452
         StringBuilder failureMsg = new StringBuilder();
492 453
         String password = configService.selectConfigByKey("sys.user.initPassword");
493
-        for (SysUser user : userList)
494
-        {
495
-            try
496
-            {
454
+        for (SysUser user : userList) {
455
+            try {
497 456
                 // 验证是否存在这个用户
498 457
                 SysUser u = userMapper.selectUserByUserName(user.getUserName());
499
-                if (StringUtils.isNull(u))
500
-                {
458
+                if (StringUtils.isNull(u)) {
501 459
                     BeanValidators.validateWithException(validator, user);
502 460
                     user.setPassword(SecurityUtils.encryptPassword(password));
503 461
                     user.setCreateBy(operName);
504 462
                     userMapper.insertUser(user);
505 463
                     successNum++;
506 464
                     successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
507
-                }
508
-                else if (isUpdateSupport)
509
-                {
465
+                } else if (isUpdateSupport) {
510 466
                     BeanValidators.validateWithException(validator, user);
511 467
                     checkUserAllowed(u);
512 468
                     checkUserDataScope(u.getUserId());
@@ -515,28 +471,21 @@ public class SysUserServiceImpl implements ISysUserService
515 471
                     userMapper.updateUser(user);
516 472
                     successNum++;
517 473
                     successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
518
-                }
519
-                else
520
-                {
474
+                } else {
521 475
                     failureNum++;
522 476
                     failureMsg.append("<br/>" + failureNum + "、账号 " + user.getUserName() + " 已存在");
523 477
                 }
524
-            }
525
-            catch (Exception e)
526
-            {
478
+            } catch (Exception e) {
527 479
                 failureNum++;
528 480
                 String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
529 481
                 failureMsg.append(msg + e.getMessage());
530 482
                 log.error(msg, e);
531 483
             }
532 484
         }
533
-        if (failureNum > 0)
534
-        {
485
+        if (failureNum > 0) {
535 486
             failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
536 487
             throw new ServiceException(failureMsg.toString());
537
-        }
538
-        else
539
-        {
488
+        } else {
540 489
             successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
541 490
         }
542 491
         return successMsg.toString();
@@ -553,6 +502,6 @@ public class SysUserServiceImpl implements ISysUserService
553 502
     @Override
554 503
     public List<SysUser> postUserList(Long deptId, String postName) {
555 504
 
556
-        return userMapper.postUserList(deptId,postName);
505
+        return userMapper.postUserList(deptId, postName);
557 506
     }
558 507
 }

+ 20 - 0
ruoyi-system/src/main/resources/mapper/system/SysPostMapper.xml

@@ -136,4 +136,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
136 136
 		where p.dept_id = #{deptId}
137 137
 	</select>
138 138
 
139
+
140
+	<select id="userPostAuthorityList"  resultType="UserPostAuthority">
141
+		SELECT
142
+			su."user_id" as userId,
143
+			su."user_name" as userName,
144
+			su."nick_name" as nickName,
145
+			sp."post_id" as postId,
146
+			sp."post_code" as postCode,
147
+			sp."post_name" as postName,
148
+			sp."post_level" as postLevel
149
+		FROM sys_post sp
150
+		INNER JOIN "sys_dept" sd ON  sd."dept_id" = sp."dept_id"
151
+		INNER JOIN "sys_user_post" sup ON sup."post_id" = sp."post_id"
152
+		INNER JOIN "public"."sys_users" su  ON su."user_id"  = sup."user_id"
153
+		WHERE sd."dept_id" = #{dept_id}
154
+		<if test="postLevel != null">
155
+			AND sp."post_level" = #{postLevel}
156
+		</if>
157
+	</select>
158
+
139 159
 </mapper>