Quellcode durchsuchen

role删除调整

jingzhongge vor 2 Jahren
Ursprung
Commit
6568d80bc3

+ 15 - 4
webapidemo-api/src/main/java/com/example/controller/knowledge/KbDetailsController.java

@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.example.controller.BaseController;
7
+import com.example.entity.database.knowledge.KbClassify;
7 8
 import com.example.entity.database.knowledge.KbDetails;
8 9
 import com.example.entity.input.PageInput;
9 10
 import com.example.model.AjaxResult;
11
+import com.example.service.knowledge.IKbClassifyService;
10 12
 import com.example.service.knowledge.IKbDetailsService;
11 13
 import com.example.util.helper.ExcelHelper;
12 14
 import com.example.util.helper.StringHelper;
@@ -30,7 +32,7 @@ public class KbDetailsController extends BaseController {
30 32
     @Autowired
31 33
     private IKbDetailsService kbDetailsService;
32 34
     @Autowired
33
-    private IKbDetailsService kbderailsService;
35
+    private IKbClassifyService kbClassifyService;
34 36
 
35 37
     @ApiOperation("列表")
36 38
     @GetMapping
@@ -55,10 +57,10 @@ public class KbDetailsController extends BaseController {
55 57
                 .eq(input.getUpdate_time() != null, KbDetails::getUpdate_time, input.getUpdate_time());
56 58
         Page<KbDetails> page = GetPage(pageInput);
57 59
         if (page != null) {
58
-            IPage<KbDetails> iPage = kbderailsService.getListPage(page, qw);
60
+            IPage<KbDetails> iPage = kbDetailsService.getListPage(page, qw);
59 61
             return Success("成功", iPage.getRecords(), iPage.getTotal());
60 62
         } else {
61
-            return Success("成功", kbderailsService.getList(qw));
63
+            return Success("成功", kbDetailsService.getList(qw));
62 64
         }
63 65
     }
64 66
 
@@ -134,7 +136,16 @@ public class KbDetailsController extends BaseController {
134 136
         LambdaQueryWrapper<KbDetails> qw = new LambdaQueryWrapper<>();
135 137
         qw.eq(KbDetails::getDel_flag,"0");
136 138
         List<KbDetails> list = kbDetailsService.getList(qw);
137
-
139
+        LambdaQueryWrapper<KbClassify> qw2 = new LambdaQueryWrapper<>();
140
+        qw2.eq(KbClassify::getDel_flag,"0");
141
+        List<KbClassify> entity = kbClassifyService.getList(qw2);
142
+        for (KbDetails details : list) {
143
+            for (KbClassify kbClassify : entity) {
144
+               if (details.getClassify_id().equals(kbClassify.getClassify_id())){
145
+                   details.setClassifyName(kbClassify.getName());
146
+               }
147
+            }
148
+        }
138 149
         ExcelHelper<KbDetails> excel = new ExcelHelper<>(KbDetails.class);
139 150
         excel.exportExcel(response, "xlsx", list);
140 151
     }

+ 5 - 4
webapidemo-api/src/main/java/com/example/controller/system/DeptController.java

@@ -11,14 +11,13 @@ import com.example.mapper.system.DeptMapper;
11 11
 import com.example.model.AjaxResult;
12 12
 import com.example.service.system.IDeptService;
13 13
 import com.example.util.helper.StringHelper;
14
-import org.apache.commons.lang3.ArrayUtils;
15 14
 import io.swagger.annotations.Api;
16 15
 import io.swagger.annotations.ApiOperation;
16
+import org.apache.commons.lang3.ArrayUtils;
17 17
 import org.springframework.beans.factory.annotation.Autowired;
18 18
 import org.springframework.util.StringUtils;
19 19
 import org.springframework.web.bind.annotation.*;
20 20
 
21
-import java.util.ArrayList;
22 21
 import java.util.List;
23 22
 
24 23
 @Api(value = "部门表",tags = "部门表")
@@ -62,7 +61,9 @@ public class DeptController extends BaseController {
62 61
     @GetMapping("/exclude/{deptId}")
63 62
     public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
64 63
     {
65
-        List<Dept> depts = new ArrayList<>();
64
+        LambdaQueryWrapper<Dept> qw = new LambdaQueryWrapper<>();
65
+        qw.eq(Dept::getDel_flag,"0");
66
+        List<Dept> depts = deptService.getList(qw);
66 67
         depts.removeIf(d -> d.getDept_id().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
67 68
         return Success("查询成功",depts);
68 69
     }
@@ -123,7 +124,7 @@ public class DeptController extends BaseController {
123 124
 
124 125
     @ApiOperation("删除")
125 126
     @DeleteMapping("/{ids}")
126
-    public AjaxResult delete(@PathVariable long[] ids)  {
127
+    public AjaxResult delete(@PathVariable Long[] ids)  {
127 128
         for (long id : ids) {
128 129
             if (deptService.hasChildByDeptId(id))
129 130
             {

+ 1 - 0
webapidemo-api/src/main/java/com/example/controller/system/RoleController.java

@@ -111,6 +111,7 @@ public class RoleController extends BaseController {
111 111
     @ApiOperation("删除")
112 112
     @DeleteMapping("/{ids}")
113 113
     public AjaxResult delete(@PathVariable Long[] ids) {
114
+        roleService.deleteRoleByIds(ids);
114 115
         LambdaQueryWrapper<Role> qw = new LambdaQueryWrapper<>();
115 116
         qw.in(Role::getRole_id, ids);
116 117
         List<Role> list = roleService.getList(qw);

+ 6 - 6
webapidemo-entity/src/main/java/com/example/entity/database/knowledge/KbDetails.java

@@ -49,15 +49,15 @@ public class KbDetails
49 49
     private String file_ids;
50 50
 
51 51
     /** 排序规则 */
52
-    @ApiModelProperty("排序规则")
52
+   // @ApiModelProperty("排序规则")
53 53
     private Long sort;
54 54
 
55 55
     /** 状态(0正常 1停用) */
56
-    @ApiModelProperty("状态(0正常 1停用)")
56
+   // @ApiModelProperty("状态(0正常 1停用)")
57 57
     private String status;
58 58
 
59 59
     /** 删除标志(0正常 2删除) */
60
-    @ApiModelProperty("删除标志(0正常 2删除)")
60
+    //@ApiModelProperty("删除标志(0正常 2删除)")
61 61
     private String del_flag;
62 62
 
63 63
     /** 浏览次数 */
@@ -73,7 +73,7 @@ public class KbDetails
73 73
     private Long unpraise_num;
74 74
 
75 75
     /** 部门id */
76
-    @ApiModelProperty("部门id")
76
+    //@ApiModelProperty("部门id")
77 77
     private Long dept_id;
78 78
 
79 79
     /** 创建者 */
@@ -85,11 +85,11 @@ public class KbDetails
85 85
     private Date create_time;
86 86
 
87 87
     /** 修改者 */
88
-    @ApiModelProperty("修改者")
88
+    //@ApiModelProperty("修改者")
89 89
     private String update_by;
90 90
 
91 91
     /** 修改时间 */
92
-    @ApiModelProperty("修改时间")
92
+    //@ApiModelProperty("修改时间")
93 93
     private Date update_time;
94 94
 
95 95
 

+ 66 - 17
webapidemo-entity/src/main/java/com/example/entity/database/system/Role.java

@@ -14,59 +14,108 @@ import java.util.Date;
14 14
 @Data
15 15
 @TableName("sys_role")
16 16
 public class Role {
17
-    /** 角色ID */
17
+    /**
18
+     * 角色ID
19
+     */
18 20
     @ApiModelProperty("角色ID")
19 21
     @TableId(type = IdType.AUTO)
20 22
     private Long role_id;
21
-    /** 角色名称 */
23
+    /**
24
+     * 角色名称
25
+     */
22 26
     @ApiModelProperty("角色名称")
23 27
     private String role_name;
24
-    /** 角色权限字符串 */
28
+    /**
29
+     * 角色权限字符串
30
+     */
25 31
     @ApiModelProperty("角色权限字符串")
26 32
     private String role_key;
27
-    /** 显示顺序 */
33
+    /**
34
+     * 显示顺序
35
+     */
28 36
     @ApiModelProperty("显示顺序")
29 37
     private Long role_sort;
30 38
 
31
-    /** 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限) */
39
+    /**
40
+     * 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
41
+     */
32 42
     @ApiModelProperty("数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)")
33 43
     private String data_scope;
34 44
 
35
-    /** 菜单树选择项是否关联显示 */
45
+    /**
46
+     * 菜单树选择项是否关联显示
47
+     */
36 48
     @ApiModelProperty("菜单树选择项是否关联显示")
37 49
     private Long menu_check_strictly;
38 50
 
39
-    /** 部门树选择项是否关联显示 */
51
+    /**
52
+     * 部门树选择项是否关联显示
53
+     */
40 54
     @ApiModelProperty("部门树选择项是否关联显示")
41 55
     private Long dept_check_strictly;
42 56
 
43
-    /** 角色状态(0正常 1停用) */
57
+    /**
58
+     * 角色状态(0正常 1停用)
59
+     */
44 60
     @ApiModelProperty("角色状态(0正常 1停用)")
45 61
     private String status;
46
-    /** 删除标志(0代表存在 2代表删除) */
62
+    /**
63
+     * 删除标志(0代表存在 2代表删除)
64
+     */
47 65
     @ApiModelProperty("删除标志(0代表存在 2代表删除)")
48 66
     private String del_flag;
49
-    /** 创建者 */
67
+    /**
68
+     * 创建者
69
+     */
50 70
     @ApiModelProperty("创建者")
51 71
     private String create_by;
52
-    /** 创建时间 */
72
+    /**
73
+     * 创建时间
74
+     */
53 75
     @ApiModelProperty("创建时间")
54 76
     private Date create_time;
55
-    /** 更新者 */
77
+    /**
78
+     * 更新者
79
+     */
56 80
     @ApiModelProperty("更新者")
57 81
     private String update_by;
58
-    /** 更新时间 */
82
+    /**
83
+     * 更新时间
84
+     */
59 85
     @ApiModelProperty("更新时间")
60 86
     private Date update_time;
61
-    /** 备注 */
87
+    /**
88
+     * 备注
89
+     */
62 90
     @ApiModelProperty("备注")
63 91
     private String remark;
64 92
 
65
-    /** 菜单组 */
93
+    /**
94
+     * 菜单组
95
+     */
66 96
     @TableField(exist = false)
67 97
     private Long[] menuIds;
68 98
 
69
-    /** 部门组(数据权限) */
99
+    /**
100
+     * 部门组(数据权限)
101
+     */
70 102
     @TableField(exist = false)
71 103
     private Long[] deptIds;
72
-}
104
+
105
+    public Role(Long role_id) {
106
+        this.role_id = role_id;
107
+    }
108
+
109
+    public Role() {
110
+
111
+    }
112
+
113
+    public boolean isAdmin() {
114
+        return isAdmin(this.role_id);
115
+    }
116
+
117
+    public static boolean isAdmin(Long roleId) {
118
+        return roleId != null && 1L == roleId;
119
+
120
+    }
121
+}

+ 26 - 0
webapidemo-service/src/main/java/com/example/service/system/IRoleService.java

@@ -38,4 +38,30 @@ public interface IRoleService extends IBaseService<Role> {
38 38
      * @return 结果
39 39
      */
40 40
     public int insertAuthUsers(Long roleId, Long[] userIds);
41
+    /**
42
+     * 批量删除角色信息
43
+     *
44
+     * @param roleIds 需要删除的角色ID
45
+     * @return 结果
46
+     */
47
+    public void deleteRoleByIds(Long[] roleIds);
48
+    /**
49
+     * 校验角色是否允许操作
50
+     *
51
+     * @param role 角色信息
52
+     */
53
+    public void checkRoleAllowed(Role role);
54
+    /**
55
+     * 校验角色是否有数据权限
56
+     *
57
+     * @param roleId 角色id
58
+     */
59
+    public void checkRoleDataScope(Long roleId);
60
+    /**
61
+     * 通过角色ID查询角色使用数量
62
+     *
63
+     * @param roleId 角色ID
64
+     * @return 结果
65
+     */
66
+    public int countUserRoleByRoleId(Long roleId);
41 67
 }

+ 87 - 1
webapidemo-service/src/main/java/com/example/service/system/impl/RoleServiceImpl.java

@@ -1,16 +1,20 @@
1 1
 package com.example.service.system.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
3 4
 import com.example.entity.database.system.Role;
4 5
 import com.example.entity.database.system.SysRoleDept;
5 6
 import com.example.entity.database.system.SysUserRole;
6 7
 import com.example.mapper.system.RoleMapper;
7 8
 import com.example.mapper.system.SysRoleDeptMapper;
9
+import com.example.mapper.system.SysRoleMenuMapper;
8 10
 import com.example.mapper.system.SysUserRoleMapper;
9 11
 import com.example.service.BaseServiceImpl;
10 12
 import com.example.service.system.IRoleService;
13
+import com.example.util.helper.StringHelper;
11 14
 import org.springframework.beans.factory.annotation.Autowired;
12 15
 import org.springframework.stereotype.Service;
13 16
 import org.springframework.transaction.annotation.Transactional;
17
+import org.springframework.util.StringUtils;
14 18
 
15 19
 import java.util.ArrayList;
16 20
 import java.util.List;
@@ -25,9 +29,14 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
25 29
     private SysRoleDeptMapper sysRoleDeptMapper;
26 30
     @Autowired
27 31
     private IRoleService roleService;
32
+    @Autowired
33
+    private SysRoleMenuMapper roleMenuMapper;
34
+    @Autowired
35
+    private SysRoleDeptMapper roleDeptMapper;
36
+    @Autowired
37
+    private SysUserRoleMapper userRoleMapper;
28 38
     /**
29 39
      * 修改数据权限信息
30
-     *
31 40
      * @param role 角色信息
32 41
      * @return 结果
33 42
      */
@@ -111,4 +120,81 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
111 120
         }
112 121
         return sysUserRoleMapper.batchUserRole(list);
113 122
     }
123
+
124
+    /**
125
+     * 批量删除角色信息
126
+     *
127
+     * @param roleIds 需要删除的角色ID
128
+     * @return 结果
129
+     */
130
+    @Override
131
+    public void deleteRoleByIds(Long[] roleIds)
132
+    {
133
+        for (Long role_id : roleIds)
134
+        {
135
+            checkRoleAllowed(new Role(role_id));
136
+            checkRoleDataScope(role_id);
137
+           //Role role = selectRoleById(roleId);
138
+            LambdaQueryWrapper<Role> qw = new LambdaQueryWrapper<>();
139
+            qw.eq(Role::getRole_id,role_id);
140
+            Role role = this.getEntity(qw);
141
+            if (countUserRoleByRoleId(role_id) > 0)
142
+            {
143
+                throw new RuntimeException(String.format("%1$s已分配,不能删除", role.getRole_name()));
144
+            }
145
+        }
146
+        // 删除角色与菜单关联
147
+        roleMenuMapper.deleteRoleMenu(roleIds);
148
+        // 删除角色与部门关联
149
+        roleDeptMapper.deleteRoleDept(roleIds);
150
+    }
151
+    /**
152
+     * 校验角色是否允许操作
153
+     *
154
+     * @param role 角色信息
155
+     */
156
+    @Override
157
+    public void checkRoleAllowed(Role role)
158
+    {
159
+        if (!StringHelper.isNull(role.getRole_id()) && role.isAdmin())
160
+        {
161
+           // throw new ServiceException("不允许操作超级管理员角色");
162
+            throw new RuntimeException("不允许操作超级管理员角色");
163
+        }
164
+    }
165
+
166
+    /**
167
+     * 校验角色是否有数据权限
168
+     *
169
+     * @param roleId 角色id
170
+     */
171
+    @Override
172
+    public void checkRoleDataScope(Long roleId)
173
+    {
174
+        //if (!User.isAdmin(SecurityUtils.getUserId()))
175
+       // {
176
+            Role role = new Role();
177
+            role.setRole_id(roleId);
178
+            //List<Role> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
179
+            //List<Role> roles = this.selectRoleList(role);
180
+            List<Role> roles = this.getList();
181
+        if (StringUtils.isEmpty(roles))
182
+            {
183
+                throw new RuntimeException("没有权限访问角色数据!");
184
+            }
185
+        //}
186
+    }
187
+    /**
188
+     * 通过角色ID查询角色使用数量
189
+     *
190
+     * @param roleId 角色ID
191
+     * @return 结果
192
+     */
193
+    @Override
194
+    public int countUserRoleByRoleId(Long roleId)
195
+    {
196
+        return userRoleMapper.countUserRoleByRoleId(roleId);
197
+    }
198
+
199
+
114 200
 }