Browse Source

Revert "Revert "合并所有代码""

This reverts commit 24278bbd0c05a557870b801f3371308fb3dc2c50.
dingxin 6 years ago
parent
commit
b82bc98609

+ 36
- 8
src/main/java/com.huiju.welcome/controller/SysUserController.java View File

@@ -251,20 +251,41 @@ public class SysUserController extends BaseController {
251 251
                                        @RequestParam(value = "userName",required = false) String userName,
252 252
                                        @RequestParam(value = "phone",required = false) String phone) {
253 253
         IPage<SysUserRole> pg = new Page<>(pageNum, pageSize);
254
+
254 255
         ResponseBean userManagement= sysUserService.userManagementList(pg,userName,phone);
256
+
255 257
         return userManagement;
256 258
     }
257 259
 
258
-    @ApiOperation(value = "树形", notes = "树形")
259
-    @ApiImplicitParams({
260
-            @ApiImplicitParam(paramType = "body", dataType = "SysUser", name = "sysUser", value = "用户详情")
261
-    })
262
-    @RequestMapping(value = "/user/tree", method = RequestMethod.GET)
263
-    public ResponseBean userRoleTree(@RequestBody SysUser sysUser, HttpServletRequest request) {
264
-        ResponseBean tree= sysUserService.userRoleTree();
265
-        return tree;
260
+    @ApiOperation(value = "员工管理角色权限添加", notes = "员工管理角色权限添加")
261
+    @RequestMapping(value = "/addUserRole", method = RequestMethod.POST)
262
+    public ResponseBean userManagement(@RequestParam(value = "phone",required = false) String phone,
263
+                                       @RequestParam(value = "roleId",required = false) List<String> roleId) {
264
+        ResponseBean userManagement= sysUserService.addUserRole(phone,roleId);
265
+        return userManagement;
266 266
     }
267 267
 
268
+    @ApiOperation(value = "查询当前员工的角色权限", notes = "查询当前员工的角色权限")
269
+    @RequestMapping(value = "/userRoledetails", method = RequestMethod.GET)
270
+    public ResponseBean userRoledetails(@RequestParam(value = "userId",required = false) Integer userId) {
271
+         ResponseBean userRoledetails= sysUserService.userRoledetails(userId);
272
+        return userRoledetails;
273
+    }
274
+    @ApiOperation(value = "修改当前员工的角色权限", notes = "修改当前员工的角色权限")
275
+    @RequestMapping(value = "/updateUserRolede", method = RequestMethod.POST)
276
+    public ResponseBean updateUserRolede(@RequestParam(value = "userId",required = false) Integer userId,
277
+                                         @RequestParam(value = "menuArray",required = false) List<String> menuArray) {
278
+        ResponseBean updateUserRolede= sysUserService.updateUserRolede(userId,menuArray);
279
+        return updateUserRolede;
280
+    }
281
+    @ApiOperation(value = "获取所有角色权限", notes = "获取所有角色权限")
282
+    @RequestMapping(value = "/roleAll", method = RequestMethod.GET)
283
+    public ResponseBean roleAll() {
284
+        ResponseBean roleAll= sysUserService.roleAll();
285
+        return roleAll;
286
+    }
287
+
288
+
268 289
     @ApiOperation(value = "角色管理列表", notes = "角色管理列表")
269 290
     @ApiImplicitParams({
270 291
             @ApiImplicitParam(paramType = "body", dataType = "String", name = "userName", value = "角色名称"),
@@ -277,4 +298,11 @@ public class SysUserController extends BaseController {
277 298
         ResponseBean roleManagementList= sysUserService.roleManagementList(pg,roleName);
278 299
         return roleManagementList;
279 300
     }
301
+
302
+    @ApiOperation(value = "删除当前员工的角色权限", notes = "删除当前员工的角色权限")
303
+    @RequestMapping(value = "/deleteUserRole", method = RequestMethod.POST)
304
+    public ResponseBean deleteUserRole(@RequestParam(value = "userId",required = false) Integer userId) {
305
+        ResponseBean deleteUserRole= sysUserService.deleteUserRole(userId);
306
+        return deleteUserRole;
307
+    }
280 308
 }

+ 8
- 0
src/main/java/com.huiju.welcome/mapper/SysRoleMapper.java View File

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.huiju.welcome.model.SysRole;
6 6
 import org.apache.ibatis.annotations.Mapper;
7 7
 
8
+import java.util.List;
9
+
8 10
 /**
9 11
  * <p>
10 12
  *  Mapper 接口
@@ -23,4 +25,10 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
23 25
      * @return
24 26
      */
25 27
     IPage<SysRole> roleManagementList(IPage<SysRole> pg, String roleName);
28
+
29
+    /**
30
+     * 获取所有角色
31
+     * @return
32
+     */
33
+    List<SysRole> selectroleAll();
26 34
 }

+ 8
- 0
src/main/java/com.huiju.welcome/mapper/SysUserRoleMapper.java View File

@@ -8,6 +8,8 @@ import com.huiju.welcome.model.TaVisitorAppointment;
8 8
 import org.apache.ibatis.annotations.Mapper;
9 9
 import org.apache.ibatis.annotations.Param;
10 10
 
11
+import java.util.List;
12
+
11 13
 /**
12 14
  * <p>
13 15
  *  Mapper 接口
@@ -28,4 +30,10 @@ public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
28 30
      */
29 31
     IPage<SysUserRole> userManagementList(IPage<SysUserRole> pg, @Param("userName") String userName, @Param("phone") String phone);
30 32
 
33
+    /**
34
+     * 查询当用户的角色
35
+     * @param userId
36
+     * @return
37
+     */
38
+    List<SysUserRole> selectListSysUserRole(@Param("userId") Integer userId);
31 39
 }

+ 5
- 3
src/main/java/com.huiju.welcome/model/SysUserRole.java View File

@@ -1,8 +1,11 @@
1 1
 package com.huiju.welcome.model;
2 2
 
3 3
 import java.io.Serializable;
4
+import java.util.List;
4 5
 
6
+import com.baomidou.mybatisplus.annotation.IdType;
5 7
 import com.baomidou.mybatisplus.annotation.TableField;
8
+import com.baomidou.mybatisplus.annotation.TableId;
6 9
 import lombok.Data;
7 10
 import lombok.EqualsAndHashCode;
8 11
 import lombok.experimental.Accessors;
@@ -15,9 +18,10 @@ import lombok.experimental.Accessors;
15 18
  * @author jobob
16 19
  * @since 2019-07-12
17 20
  */
18
-@Data
21
+
19 22
 @EqualsAndHashCode(callSuper = false)
20 23
 @Accessors(chain = true)
24
+@Data
21 25
 public class SysUserRole implements Serializable {
22 26
 
23 27
     private static final long serialVersionUID = 1L;
@@ -44,6 +48,4 @@ public class SysUserRole implements Serializable {
44 48
      */
45 49
     @TableField("`roleName`")
46 50
     private String roleName;
47
-
48
-
49 51
 }

+ 37
- 0
src/main/java/com.huiju.welcome/service/ISysUserService.java View File

@@ -8,6 +8,8 @@ import com.huiju.welcome.model.SysUser;
8 8
 import com.huiju.welcome.model.SysUserRole;
9 9
 import com.huiju.welcome.model.TaVisitorAppointment;
10 10
 
11
+import java.util.List;
12
+
11 13
 /**
12 14
  * <p>
13 15
  *  服务类
@@ -44,4 +46,39 @@ public interface ISysUserService extends IService<SysUser> {
44 46
      * @return
45 47
      */
46 48
     ResponseBean roleManagementList(IPage<SysRole> pg, String roleName);
49
+
50
+    /**
51
+     * 添加角色权限
52
+     * @param phone
53
+     * @param role
54
+     * @return
55
+     */
56
+    ResponseBean addUserRole(String phone, List<String> role);
57
+
58
+    /**
59
+     * 查询当前员工所有权限
60
+     * @param userId
61
+     * @return
62
+     */
63
+    ResponseBean userRoledetails(Integer userId);
64
+
65
+    /**
66
+     * 修改当前员工的角色权限
67
+     * @param userId
68
+     * @return
69
+     */
70
+    ResponseBean updateUserRolede(Integer userId,List<String> role);
71
+
72
+    /**
73
+     * 获取所有角色
74
+     * @return
75
+     */
76
+    ResponseBean roleAll();
77
+
78
+    /**
79
+     * 删除当前员工权限
80
+     * @param userId
81
+     * @return
82
+     */
83
+    ResponseBean deleteUserRole(Integer userId);
47 84
 }

+ 83
- 0
src/main/java/com.huiju.welcome/service/impl/SysUserServiceImpl.java View File

@@ -11,6 +11,8 @@ import com.huiju.welcome.utils.StatusUtils;
11 11
 import org.springframework.beans.factory.annotation.Autowired;
12 12
 import org.springframework.stereotype.Service;
13 13
 
14
+import java.util.ArrayList;
15
+import java.util.HashMap;
14 16
 import java.util.List;
15 17
 
16 18
 /**
@@ -75,4 +77,85 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
75 77
         responseBean.addSuccess(list);
76 78
         return responseBean;
77 79
     }
80
+
81
+    @Override
82
+    public ResponseBean addUserRole(String phone, List<String> role) {
83
+        ResponseBean responseBean = new ResponseBean<>();
84
+        String[] strArray = role.toArray(new String[role.size()]);
85
+        /*查询当前号码是否存在*/
86
+        QueryWrapper<SysUser> sysUserQueryWrapper= new QueryWrapper<>();
87
+        sysUserQueryWrapper.eq("phone",phone);
88
+        SysUser sysUser = sysUserMapper.selectOne(sysUserQueryWrapper);
89
+        if (null == sysUser){
90
+            responseBean.addError("此号码不存在");
91
+            return responseBean;
92
+        }
93
+        // 查询当前人员角色权限是否存在
94
+        List<SysUserRole> sysUserRole= sysUserRoleMapper.selectListSysUserRole(sysUser.getUserId());
95
+        if (sysUserRole!=null && !sysUserRole.isEmpty()){
96
+            responseBean.addError("此用户已存在权限,请点击修改");
97
+            return responseBean;
98
+        }
99
+        for (String id:strArray){
100
+            SysUserRole userRole= new SysUserRole();
101
+            userRole.setUserId(sysUser.getUserId()).setRoleId(Integer.valueOf(id));
102
+            sysUserRoleMapper.insert(userRole);
103
+        }
104
+        responseBean.addSuccess(sysUser);
105
+        return responseBean;
106
+    }
107
+
108
+    @Override
109
+    public ResponseBean userRoledetails(Integer userId) {
110
+        ResponseBean responseBean= new ResponseBean<>();
111
+        List<Integer> arrayList= new ArrayList<>();
112
+        SysUser user= sysUserMapper.selectById(userId);
113
+        List<SysRole> sysRole= sysRoleMapper.selectroleAll();
114
+        List<SysUserRole> sysUserRoleList= sysUserRoleMapper.selectListSysUserRole(userId);
115
+        for (SysUserRole sysUserRole:sysUserRoleList){
116
+            arrayList.add(sysUserRole.getRoleId());
117
+        }
118
+        HashMap<Object,Object> map = new HashMap<>();
119
+        map.put("arrayList",arrayList);
120
+        map.put("user",user);
121
+        map.put("sysRole",sysRole);
122
+        responseBean.addSuccess(map);
123
+        return responseBean;
124
+    }
125
+
126
+    @Override
127
+    public ResponseBean updateUserRolede(Integer userId,List<String> role) {
128
+        ResponseBean responseBean= new ResponseBean<>();
129
+        // 查出当前用户的所有权限,先删除后添加
130
+        List<SysUserRole> sysUserRoleList= sysUserRoleMapper.selectListSysUserRole(userId);
131
+        for (SysUserRole sysUserRole:sysUserRoleList){
132
+            sysUserRoleMapper.delete(new QueryWrapper<SysUserRole>().eq("user_id",userId));
133
+        }
134
+        String[] array = role.toArray(new String[role.size()]);
135
+        for (String id:array){
136
+            SysUserRole sysRole= new SysUserRole();
137
+            sysRole.setRoleId(Integer.valueOf(id)).setUserId(userId);
138
+            sysUserRoleMapper.insert(sysRole);
139
+        }
140
+        responseBean.addSuccess("成功");
141
+        return responseBean;
142
+    }
143
+
144
+    @Override
145
+    public ResponseBean roleAll() {
146
+       ResponseBean responseBean=  new ResponseBean<>();
147
+        List<SysRole> sysRole= sysRoleMapper.selectroleAll();
148
+        responseBean.addSuccess(sysRole);
149
+        return responseBean;
150
+    }
151
+
152
+    @Override
153
+    public ResponseBean deleteUserRole(Integer userId) {
154
+        ResponseBean responseBean= new ResponseBean<>();
155
+        QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<>();
156
+        sysUserRoleQueryWrapper.eq("user_id",userId);
157
+        int sysUserRole=  sysUserRoleMapper.delete(sysUserRoleQueryWrapper);
158
+        responseBean.addSuccess(sysUserRole);
159
+        return responseBean;
160
+    }
78 161
 }

+ 4
- 0
src/main/resources/mapper/SysRoleMapper.xml View File

@@ -6,4 +6,8 @@
6 6
         select * from sys_role order by create_date desc
7 7
     </select>
8 8
 
9
+    <select id="selectroleAll" resultType="com.huiju.welcome.model.SysUserRole">
10
+        select * from  sys_role
11
+    </select>
12
+
9 13
 </mapper>

+ 8
- 1
src/main/resources/mapper/SysUserRoleMapper.xml View File

@@ -5,7 +5,8 @@
5 5
         select
6 6
         u.username,
7 7
         u.phone,
8
-        r.role_name as roleName
8
+        u.user_id as userId,
9
+        GROUP_CONCAT(r.role_name) roleName
9 10
         from sys_user_role ur
10 11
         left join sys_user u on  ur.user_id = u.user_id
11 12
         left join sys_role r on  ur.role_id = r.role_id
@@ -17,5 +18,11 @@
17 18
                 u.phone LIKE CONCAT('%',#{phone},'%')
18 19
             </if>
19 20
         </where>
21
+        GROUP BY
22
+        ur.user_id
23
+    </select>
24
+    
25
+    <select id="selectListSysUserRole" resultType="com.huiju.welcome.model.SysUserRole">
26
+        select * from sys_user_role where  user_id = #{userId};
20 27
     </select>
21 28
 </mapper>