소스 검색

角色删除自动维护员工关联关系, 修复 删除角色后, 员工登陆问题

weiximei 6 년 전
부모
커밋
d6521bebd3

+ 7
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/dao/ToSysUserRoleMapper.java 파일 보기

27
      * @return
27
      * @return
28
      */
28
      */
29
     List<ToSysUserRole> selelctByRoleId(@Param("roleId") Integer roleId);
29
     List<ToSysUserRole> selelctByRoleId(@Param("roleId") Integer roleId);
30
+
31
+    /**
32
+     * 根据 角色id 删除关联关系
33
+     * @param list
34
+     * @return
35
+     */
36
+    int deleteByRoleId(List<Integer> list);
30
 }
37
 }

+ 7
- 4
CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/impl/ToSysRoleServiceImpl.java 파일 보기

190
     public ResponseBean deleteRole(List<Integer> ids, UserElement userElement) {
190
     public ResponseBean deleteRole(List<Integer> ids, UserElement userElement) {
191
         ResponseBean responseBean = new ResponseBean();
191
         ResponseBean responseBean = new ResponseBean();
192
         ids.forEach(e ->{
192
         ids.forEach(e ->{
193
-            List<ToSysUserRole> userRoleList = toSysUserRoleMapper.selelctByRoleId(e);
194
-            if (CollectionUtils.isNotEmpty(userRoleList)) {
195
-                throw new WisdomException("角色存在用户关联关系, 无法删除!");
196
-            }
193
+//            List<ToSysUserRole> userRoleList = toSysUserRoleMapper.selelctByRoleId(e);
194
+//            if (CollectionUtils.isNotEmpty(userRoleList)) {
195
+//                throw new WisdomException("角色存在用户关联关系, 无法删除!");
196
+//            }
197
             ToSysRole toSysRole = toSysRoleMapper.selectByPrimaryKey(e);
197
             ToSysRole toSysRole = toSysRoleMapper.selectByPrimaryKey(e);
198
             if (null == toSysRole) {
198
             if (null == toSysRole) {
199
                 throw new WisdomException("删除失败, 角色编号 " + e + " 不存在!");
199
                 throw new WisdomException("删除失败, 角色编号 " + e + " 不存在!");
203
             toSysRole.setUpdateDate(new Date());
203
             toSysRole.setUpdateDate(new Date());
204
             toSysRoleMapper.updateByPrimaryKeySelective(toSysRole);
204
             toSysRoleMapper.updateByPrimaryKeySelective(toSysRole);
205
         });
205
         });
206
+        // 删除这个角色下关联关系
207
+        toSysUserRoleMapper.deleteByRoleId(ids);
208
+
206
         responseBean.addSuccess("操作成功!");
209
         responseBean.addSuccess("操作成功!");
207
         return responseBean;
210
         return responseBean;
208
     }
211
     }

+ 14
- 5
CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/impl/ToUserServerImpl.java 파일 보기

18
 import com.github.pagehelper.Page;
18
 import com.github.pagehelper.Page;
19
 import com.github.pagehelper.PageHelper;
19
 import com.github.pagehelper.PageHelper;
20
 import lombok.extern.slf4j.Slf4j;
20
 import lombok.extern.slf4j.Slf4j;
21
+import org.apache.commons.collections.CollectionUtils;
21
 import org.apache.commons.lang.StringUtils;
22
 import org.apache.commons.lang.StringUtils;
22
 import org.springframework.beans.BeanUtils;
23
 import org.springframework.beans.BeanUtils;
23
 import org.springframework.beans.factory.annotation.Autowired;
24
 import org.springframework.beans.factory.annotation.Autowired;
24
 import org.springframework.stereotype.Service;
25
 import org.springframework.stereotype.Service;
25
 
26
 
26
-import javax.security.auth.callback.TextOutputCallback;
27
 import java.util.*;
27
 import java.util.*;
28
 
28
 
29
 @Service("iToUserServer")
29
 @Service("iToUserServer")
87
         ToUserVO toUserVO = new ToUserVO();
87
         ToUserVO toUserVO = new ToUserVO();
88
         BeanUtils.copyProperties(toUser,toUserVO);
88
         BeanUtils.copyProperties(toUser,toUserVO);
89
 
89
 
90
-        List<ToSysRole> sysRoleList = toSysRoleMapper.selectRoleByUserId(userId);
91
-        toUserVO.setRoles(sysRoleList);
92
-        // 菜单权限
93
-        toUserVO.setPermissionList(getPermission(userId));
90
+        List<ToSysRole> roleList = toSysRoleMapper.selectRoleByUserId(userId);
91
+        if (CollectionUtils.isNotEmpty(roleList)) {
92
+            List<ToSysRole> sysRoleList = toSysRoleMapper.selectRoleByUserId(userId);
93
+            toUserVO.setRoles(sysRoleList);
94
+            // 菜单权限
95
+            toUserVO.setPermissionList(getPermission(userId));
96
+        } else {
97
+            ToSysRole toSysRole = new ToSysRole();
98
+            toSysRole.setRoleName("没有角色");
99
+            toUserVO.setRoles(Arrays.asList(toSysRole));
100
+            // 菜单权限
101
+            toUserVO.setPermissionList(Collections.EMPTY_LIST);
102
+        }
94
         response.addSuccess(toUserVO);
103
         response.addSuccess(toUserVO);
95
 
104
 
96
         return response;
105
         return response;

+ 10
- 0
CODE/smart-community/operate-api/src/main/resources/mapper/ToSysUserRoleMapper.xml 파일 보기

83
     where role_id = #{roleId,jdbcType=INTEGER}
83
     where role_id = #{roleId,jdbcType=INTEGER}
84
   </select>
84
   </select>
85
 
85
 
86
+  <delete id="deleteByRoleId" parameterType="list" >
87
+    delete from
88
+    to_sys_user_role
89
+    where role_id in (
90
+      <foreach collection="list" item="item" separator=",">
91
+        #{item}
92
+      </foreach>
93
+    )
94
+  </delete>
95
+
86
 </mapper>
96
 </mapper>

+ 6
- 5
VUECODE/smart-operate-manage/src/store/modules/user.js 파일 보기

50
       return new Promise((resolve, reject) => {
50
       return new Promise((resolve, reject) => {
51
         getInfo().then(response => {
51
         getInfo().then(response => {
52
           const data = response.data
52
           const data = response.data
53
-          if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
54
-            commit('SET_ROLES', data.roles)
55
-          } else {
56
-            reject('getInfo: roles must be a non-null array !')
57
-          }
53
+          // if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
54
+          //   commit('SET_ROLES', data.roles)
55
+          // } else {
56
+          //   reject('getInfo: roles must be a non-null array !')
57
+          // }
58
+          commit('SET_ROLES', data.roles)
58
           commit('SET_NAME', data.userName)
59
           commit('SET_NAME', data.userName)
59
           commit('SET_AVATAR', data.loginName)
60
           commit('SET_AVATAR', data.loginName)
60
           commit('SET_USER_DATA', data)
61
           commit('SET_USER_DATA', data)