Commit 0d740b4deaa8c2f95dd41c8f7e4ebd24e469a41e

Authored by pengyongcheng
1 parent 327d5130

数据权限-授权缓存

ant-design-vue-jeecg/src/views/system/DataPermissionList.vue
... ... @@ -44,7 +44,7 @@
44 44 <a href="javascript:" @click="handleDetail(record)">详情</a>
45 45 </a-menu-item>
46 46 <a-menu-item v-has="'permission:addChildren'">
47   - <a href="javascript:" @click="handleAddSub(record)">添加下级</a>
  47 + <a href="javascript:" v-if="record.type === 0" @click="handleAddSub(record)">添加下级</a>
48 48 </a-menu-item>
49 49 <a-menu-item v-has="'permission:delete'">
50 50 <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
... ... @@ -170,7 +170,7 @@ export default {
170 170 handleAddSub(record) {
171 171 this.$refs.modalForm.title = '添加子数据权限'
172 172 this.$refs.modalForm.disableSubmit = false
173   - this.$refs.modalForm.edit({ status: '1', permsType: '1', route: true, 'parentId': record.id, type: 1 })
  173 + this.$refs.modalForm.edit({ status: '1', type: 1, parentId: record.id, perms: record.perms + ":" })
174 174 },
175 175 handleExpandedRowsChange(expandedRows) {
176 176 this.expandedRowKeys = expandedRows
... ... @@ -191,7 +191,7 @@ export default {
191 191 color = 'red'
192 192 }
193 193 return color
194   - },
  194 + }
195 195 }
196 196 }
197 197 </script>
... ...
ant-design-vue-jeecg/src/views/system/modules/DataPermissionModal.vue
... ... @@ -12,8 +12,8 @@
12 12  
13 13 <a-form-model-item label="资源类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
14 14 <a-radio-group v-model="model.type">
15   - <a-radio :value="0">标识</a-radio>
16   - <a-radio :value="1">权限</a-radio>
  15 + <a-radio v-if="model.type === 0" :value="0">标识</a-radio>
  16 + <a-radio v-if="model.type === 1" :value="1">权限</a-radio>
17 17 </a-radio-group>
18 18 </a-form-model-item>
19 19  
... ... @@ -118,7 +118,7 @@ export default {
118 118 validatorRules: function() {
119 119 return {
120 120 name: [{ required: true, message: '请输入权限标题!' }],
121   - perms: [{ required: false, message: '请输入授权标识!' }, { validator: this.validatePerms }]
  121 + perms: [{ required: true, message: '请输入授权标识!' }, { validator: this.validatePerms }]
122 122 }
123 123 }
124 124 },
... ... @@ -146,6 +146,7 @@ export default {
146 146 edit(record) {
147 147 this.resetScreenSize() // 调用此方法,根据屏幕宽度自适应调整抽屉的宽度
148 148 this.model = { ...record }
  149 + debugger;
149 150 if (this.model.type === 0) {
150 151 // 如果资源类型是标识,则没有状态
151 152 this.model.status = null
... ... @@ -164,7 +165,7 @@ export default {
164 165 // 触发表单验证
165 166 this.$refs.form.validate(valid => {
166 167 if (valid) {
167   - if ((this.model.type === 1 || this.model.type === 2) && !this.model.parentId) {
  168 + if (this.model.type === 1 && !this.model.parentId) {
168 169 that.validateStatus = 'error'
169 170 that.$message.error('请检查你填的类型以及信息是否正确!')
170 171 return
... ... @@ -201,7 +202,7 @@ export default {
201 202 if (value && value.length > 0) {
202 203 //校验授权标识是否存在
203 204 let params = {
204   - tableName: 'sys_permission',
  205 + tableName: 'sys_data_permission',
205 206 fieldName: 'perms',
206 207 fieldVal: value,
207 208 dataId: this.model.id
... ...
ant-design-vue-jeecg/src/views/system/modules/UserRoleModal.vue
... ... @@ -38,7 +38,6 @@
38 38 :checkedKeys="dataCheckedKeys"
39 39 :treeData="dataTreeData"
40 40 @expand="dataOnExpand"
41   - @select="dataOnTreeNodeSelect"
42 41 :selectedKeys="dataSelectedKeys"
43 42 :expandedKeys="dataExpandedKeys"
44 43 :checkStrictly="dataCheckStrictly">
... ... @@ -80,7 +79,7 @@
80 79  
81 80 </template>
82 81 <script>
83   -import { queryDataTreeListForRole, queryRoleDataPermission, queryRolePermission, queryTreeListForRole, saveRolePermission } from '@/api/api'
  82 +import { queryRolePermission, queryTreeListForRole, saveRolePermission } from '@/api/api'
84 83 import RoleDataruleModal from './RoleDataruleModal.vue'
85 84  
86 85 export default {
... ... @@ -122,12 +121,6 @@ export default {
122 121 }
123 122 this.$refs.datarule.show(this.selectedKeys[0], this.roleId)
124 123 },
125   - dataOnTreeNodeSelect(id) {
126   - if (id && id.length > 0) {
127   - this.dataSelectedKeys = id
128   - }
129   - this.$refs.datarule.show(this.dataSelectedKeys[0], this.roleId)
130   - },
131 124 onCheck(o) {
132 125 if (this.checkStrictly) {
133 126 this.checkedKeys = o.checked
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/SysDataPermissionController.java
1 1 package org.jeecg.modules.system.controller;
2 2  
  3 +import cn.hutool.core.util.ObjectUtil;
  4 +import cn.hutool.core.util.StrUtil;
3 5 import com.alibaba.fastjson.JSONArray;
4 6 import com.alibaba.fastjson.JSONObject;
5 7 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
6 8 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
7 9 import lombok.extern.slf4j.Slf4j;
8   -import org.apache.commons.lang3.StringUtils;
9 10 import org.apache.shiro.SecurityUtils;
10 11 import org.apache.shiro.authz.annotation.RequiresPermissions;
11 12 import org.jeecg.common.api.vo.Result;
12 13 import org.jeecg.common.constant.CommonConstant;
13   -import org.jeecg.common.constant.enums.RoleIndexConfigEnum;
14 14 import org.jeecg.common.system.vo.LoginUser;
15 15 import org.jeecg.common.util.oConvertUtils;
16 16 import org.jeecg.config.JeeccgBaseConfig;
17   -import org.jeecg.modules.system.entity.*;
  17 +import org.jeecg.modules.system.entity.SysDataPermission;
  18 +import org.jeecg.modules.system.entity.SysRoleDataPermission;
  19 +import org.jeecg.modules.system.entity.SysRolePermission;
18 20 import org.jeecg.modules.system.model.SysDataPermissionTree;
19 21 import org.jeecg.modules.system.model.TreeModel;
20 22 import org.jeecg.modules.system.service.*;
21   -import org.jeecg.modules.system.util.DataPermissionDataUtil;
  23 +import org.jeecg.utils.constant.QuantityConstant;
22 24 import org.springframework.beans.factory.annotation.Autowired;
23 25 import org.springframework.web.bind.annotation.*;
24 26  
... ... @@ -27,7 +29,7 @@ import java.util.stream.Collectors;
27 29  
28 30 /**
29 31 * <p>
30   - * 菜单权限表 前端控制器
  32 + * 数据权限表 前端控制器
31 33 * </p>
32 34 *
33 35 * @Author scott
... ... @@ -54,9 +56,6 @@ public class SysDataPermissionController {
54 56 private ISysDepartPermissionService sysDepartPermissionService;
55 57  
56 58 @Autowired
57   - private ISysUserService sysUserService;
58   -
59   - @Autowired
60 59 private JeeccgBaseConfig jeeccgBaseConfig;
61 60  
62 61 /**
... ... @@ -77,17 +76,17 @@ public class SysDataPermissionController {
77 76 getTreeList(treeList, list, null);
78 77 result.setResult(treeList);
79 78 result.setSuccess(true);
80   - log.info("======获取全部菜单数据=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
  79 + log.info("======获取全部数据权限=====耗时:{}毫秒", System.currentTimeMillis() - start);
81 80 } catch (Exception e) {
82 81 log.error(e.getMessage(), e);
83 82 }
84 83 return result;
85 84 }
86 85  
87   - /* update_begin author:wuxianquan date:20190908 for:先查询一级菜单,当用户点击展开菜单时加载子菜单 */
  86 + /* update_begin author:wuxianquan date:20190908 for:先查询一级数据,当用户点击展开数据时加载子数据 */
88 87  
89 88 /**
90   - * 系统菜单列表(一级菜单)
  89 + * 系统数据列表(一级数据)
91 90 *
92 91 * @return
93 92 */
... ... @@ -111,12 +110,12 @@ public class SysDataPermissionController {
111 110 } catch (Exception e) {
112 111 log.error(e.getMessage(), e);
113 112 }
114   - log.info("======获取一级菜单数据=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
  113 + log.info("======获取一级数据权限=====耗时:{}毫秒", System.currentTimeMillis() - start);
115 114 return result;
116 115 }
117 116  
118 117 /**
119   - * 查询子菜单
  118 + * 查询子权限
120 119 *
121 120 * @param parentId
122 121 * @return
... ... @@ -142,12 +141,12 @@ public class SysDataPermissionController {
142 141 }
143 142 return result;
144 143 }
145   - /* update_end author:wuxianquan date:20190908 for:先查询一级菜单,当用户点击展开菜单时加载子菜单 */
  144 + /* update_end author:wuxianquan date:20190908 for:先查询一级权限,当用户点击展开权限时加载子权限 */
146 145  
147   - // update_begin author:sunjianlei date:20200108 for: 新增批量根据父ID查询子级菜单的接口 -------------
  146 + // update_begin author:sunjianlei date:20200108 for: 新增批量根据父ID查询子级权限的接口 -------------
148 147  
149 148 /**
150   - * 查询子菜单
  149 + * 查询子权限
151 150 *
152 151 * @param parentIds 父ID(多个采用半角逗号分割)
153 152 * @return 返回 key-value 的 Map
... ... @@ -176,41 +175,19 @@ public class SysDataPermissionController {
176 175 return Result.ok(listMap);
177 176 } catch (Exception e) {
178 177 log.error(e.getMessage(), e);
179   - return Result.error("批量查询子菜单失败:" + e.getMessage());
  178 + return Result.error("批量查询子权限失败:" + e.getMessage());
180 179 }
181 180 }
182   - // update_end author:sunjianlei date:20200108 for: 新增批量根据父ID查询子级菜单的接口 -------------
183   -
184   -// /**
185   -// * 查询用户拥有的菜单权限和按钮权限(根据用户账号)
186   -// *
187   -// * @return
188   -// */
189   -// @RequestMapping(value = "/queryByUser", method = RequestMethod.GET)
190   -// public Result<JSONArray> queryByUser(HttpServletRequest req) {
191   -// Result<JSONArray> result = new Result<>();
192   -// try {
193   -// String username = req.getParameter("username");
194   -// List<sysDataPermission> metaList = sysDataPermissionService.queryByUser(username);
195   -// JSONArray jsonArray = new JSONArray();
196   -// this.getPermissionJsonArray(jsonArray, metaList, null);
197   -// result.setResult(jsonArray);
198   -// result.success("查询成功");
199   -// } catch (Exception e) {
200   -// result.error500("查询失败:" + e.getMessage());
201   -// log.error(e.getMessage(), e);
202   -// }
203   -// return result;
204   -// }
  181 + // update_end author:sunjianlei date:20200108 for: 新增批量根据父ID查询子级权限的接口 -------------
205 182  
206 183 /**
207   - * 查询用户拥有的菜单权限和按钮权限
  184 + * 查询用户拥有的数据权限
208 185 *
209 186 * @return
210 187 */
211   - @RequestMapping(value = "/getUserPermissionByToken", method = RequestMethod.GET)
  188 + @RequestMapping(value = "/getDataPermissionByToken", method = RequestMethod.GET)
212 189 public Result<?> getUserPermissionByToken() {
213   - Result<JSONObject> result = new Result<JSONObject>();
  190 + Result<JSONArray> result = new Result<>();
214 191 try {
215 192 // 直接获取当前用户不适用前端token
216 193 LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
... ... @@ -218,45 +195,18 @@ public class SysDataPermissionController {
218 195 return Result.error("请登录系统!");
219 196 }
220 197 List<SysDataPermission> metaList = sysDataPermissionService.queryByUser(loginUser.getUsername());
221   - // 添加首页路由
222   - // update-begin-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
223   - if (!DataPermissionDataUtil.hasIndexPage(metaList)) {
224   - SysDataPermission indexMenu = sysDataPermissionService.list(new LambdaQueryWrapper<SysDataPermission>().eq(SysDataPermission::getName, "首页")).get(0);
225   - metaList.add(0, indexMenu);
226   - }
227   - // update-end-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
228   -
229   - // update-begin--Author:liusq Date:20210624 for:自定义首页地址LOWCOD-1578
230   - List<String> roles = sysUserService.getRole(loginUser.getUsername());
231   - String compUrl = RoleIndexConfigEnum.getIndexByRoles(roles);
232   - if (StringUtils.isNotBlank(compUrl)) {
233   - List<SysDataPermission> menus = metaList.stream().filter(sysDataPermission -> "首页".equals(sysDataPermission.getName())).collect(Collectors.toList());
234   - }
235 198 // update-end--Author:liusq Date:20210624 for:自定义首页地址LOWCOD-1578
236   - JSONObject json = new JSONObject();
237   - JSONArray menujsonArray = new JSONArray();
238   - this.getPermissionJsonArray(menujsonArray, metaList, null);
239   - // 一级菜单下的子菜单全部是隐藏路由,则一级菜单不显示
240   - this.handleFirstLevelMenuHidden(menujsonArray);
  199 + //JSONObject json = new JSONObject();
241 200  
242 201 JSONArray authjsonArray = new JSONArray();
243 202 this.getAuthJsonArray(authjsonArray, metaList);
244 203 // 查询所有的权限
245 204 LambdaQueryWrapper<SysDataPermission> query = new LambdaQueryWrapper<>();
246   - query.eq(SysDataPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
247   - query.eq(SysDataPermission::getType, CommonConstant.MENU_TYPE_2);
248   - // query.eq(sysDataPermission::getStatus, "1");
249   - List<SysDataPermission> allAuthList = sysDataPermissionService.list(query);
250   - JSONArray allauthjsonArray = new JSONArray();
251   - this.getAllAuthJsonArray(allauthjsonArray, allAuthList);
252   - // 路由菜单
253   - json.put("menu", menujsonArray);
254   - // 按钮权限(用户拥有的权限集合)
255   - json.put("auth", authjsonArray);
256   - // 全部权限配置集合(按钮权限,访问权限)
257   - json.put("allAuth", allauthjsonArray);
258   - json.put("sysSafeMode", jeeccgBaseConfig.getSafeMode());
259   - result.setResult(json);
  205 + query.eq(SysDataPermission::getDelFlag, CommonConstant.DEL_FLAG_0)
  206 + .eq(SysDataPermission::getType, CommonConstant.MENU_TYPE_1)
  207 + .eq(SysDataPermission::getStatus, QuantityConstant.STATUS_ENABLE);
  208 + //json.put("sysSafeMode", jeeccgBaseConfig.getSafeMode());
  209 + result.setResult(authjsonArray);
260 210 } catch (Exception e) {
261 211 result.error500("查询失败:" + e.getMessage());
262 212 log.error(e.getMessage(), e);
... ... @@ -267,7 +217,7 @@ public class SysDataPermissionController {
267 217 /**
268 218 * 【vue3专用】获取
269 219 * 1、查询用户拥有的按钮/表单访问权限
270   - * 2、所有权限 (菜单权限配置)
  220 + * 2、所有权限 (数据权限配置)
271 221 * 3、系统安全模式 (开启则online报表的数据源必填)
272 222 */
273 223 @RequestMapping(value = "/getPermCode", method = RequestMethod.GET)
... ... @@ -311,7 +261,7 @@ public class SysDataPermissionController {
311 261 }
312 262  
313 263 /**
314   - * 添加菜单
  264 + * 添加数据权限
315 265 *
316 266 * @param permission
317 267 * @return
... ... @@ -322,7 +272,6 @@ public class SysDataPermissionController {
322 272 public Result<SysDataPermission> add(@RequestBody SysDataPermission permission) {
323 273 Result<SysDataPermission> result = new Result<>();
324 274 try {
325   - permission = DataPermissionDataUtil.intelligentProcessData(permission);
326 275 sysDataPermissionService.addPermission(permission);
327 276 result.success("添加成功!");
328 277 } catch (Exception e) {
... ... @@ -333,7 +282,7 @@ public class SysDataPermissionController {
333 282 }
334 283  
335 284 /**
336   - * 编辑菜单
  285 + * 编辑数据权限
337 286 *
338 287 * @param permission
339 288 * @return
... ... @@ -344,7 +293,6 @@ public class SysDataPermissionController {
344 293 public Result<SysDataPermission> edit(@RequestBody SysDataPermission permission) {
345 294 Result<SysDataPermission> result = new Result<>();
346 295 try {
347   - permission = DataPermissionDataUtil.intelligentProcessData(permission);
348 296 sysDataPermissionService.editPermission(permission);
349 297 result.success("修改成功!");
350 298 } catch (Exception e) {
... ... @@ -355,7 +303,7 @@ public class SysDataPermissionController {
355 303 }
356 304  
357 305 /**
358   - * 删除菜单
  306 + * 删除数据权限
359 307 *
360 308 * @param id
361 309 * @return
... ... @@ -376,7 +324,7 @@ public class SysDataPermissionController {
376 324 }
377 325  
378 326 /**
379   - * 批量删除菜单
  327 + * 批量删除数据权限
380 328 *
381 329 * @param ids
382 330 * @return
... ... @@ -443,7 +391,7 @@ public class SysDataPermissionController {
443 391 Result<List<TreeModel>> result = new Result<>();
444 392 try {
445 393 List<TreeModel> list = sysDataPermissionService.queryListByParentId(parentId);
446   - if (list == null || list.size() <= 0) {
  394 + if (list == null || list.isEmpty()) {
447 395 result.error500("未找到角色信息");
448 396 } else {
449 397 result.setResult(list);
... ... @@ -452,7 +400,6 @@ public class SysDataPermissionController {
452 400 } catch (Exception e) {
453 401 log.error(e.getMessage(), e);
454 402 }
455   -
456 403 return result;
457 404 }
458 405  
... ... @@ -480,30 +427,6 @@ public class SysDataPermissionController {
480 427 return result;
481 428 }
482 429  
483   - /**
484   - * 保存角色授权
485   - *
486   - * @return
487   - */
488   - /*@RequestMapping(value = "/saveRolePermission", method = RequestMethod.POST)
489   - // @RequiresRoles({ "admin" })
490   - public Result<String> saveRolePermission(@RequestBody JSONObject json) {
491   - long start = System.currentTimeMillis();
492   - Result<String> result = new Result<>();
493   - try {
494   - String roleId = json.getString("roleId");
495   - String permissionIds = json.getString("permissionIds");
496   - String lastPermissionIds = json.getString("lastpermissionIds");
497   - this.sysRolePermissionService.saveRolePermission(roleId, permissionIds, lastPermissionIds);
498   - result.success("保存成功!");
499   - log.info("======角色授权成功=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
500   - } catch (Exception e) {
501   - result.error500("授权失败!");
502   - log.error(e.getMessage(), e);
503   - }
504   - return result;
505   - }*/
506   -
507 430 private void getTreeList(List<SysDataPermissionTree> treeList, List<SysDataPermission> metaList, SysDataPermissionTree temp) {
508 431 for (SysDataPermission permission : metaList) {
509 432 String tempPid = String.valueOf(permission.getParentId());
... ... @@ -519,7 +442,6 @@ public class SysDataPermissionController {
519 442 getTreeList(treeList, metaList, tree);
520 443 }
521 444 }
522   -
523 445 }
524 446 }
525 447  
... ... @@ -543,43 +465,19 @@ public class SysDataPermissionController {
543 465 }
544 466  
545 467 /**
546   - * 一级菜单的子菜单全部是隐藏路由,则一级菜单不显示
547   - *
548   - * @param jsonArray
549   - */
550   - private void handleFirstLevelMenuHidden(JSONArray jsonArray) {
551   - jsonArray = jsonArray.stream().map(obj -> {
552   - JSONObject returnObj = new JSONObject();
553   - JSONObject jsonObj = (JSONObject) obj;
554   - if (jsonObj.containsKey("children")) {
555   - JSONArray childrens = jsonObj.getJSONArray("children");
556   - childrens =
557   - childrens.stream().filter(arrObj -> !"true".equals(((JSONObject) arrObj).getString("hidden"))).collect(Collectors.toCollection(JSONArray::new));
558   - if (childrens == null || childrens.size() == 0) {
559   - jsonObj.put("hidden", true);
560   -
561   - // vue3版本兼容代码
562   - JSONObject meta = new JSONObject();
563   - meta.put("hideMenu", true);
564   - jsonObj.put("meta", meta);
565   - }
566   - }
567   - return returnObj;
568   - }).collect(Collectors.toCollection(JSONArray::new));
569   - }
570   -
571   - /**
572 468 * 获取权限JSON数组
573 469 *
574 470 * @param jsonArray
575 471 * @param allList
576 472 */
577 473 private void getAllAuthJsonArray(JSONArray jsonArray, List<SysDataPermission> allList) {
578   - JSONObject json = null;
  474 + JSONObject json;
579 475 for (SysDataPermission permission : allList) {
580 476 json = new JSONObject();
581 477 json.put("action", permission.getPerms());
582   - json.put("describe", permission.getName());
  478 + json.put("status", permission.getStatus());
  479 + json.put("type", permission.getType());
  480 + json.put("describe", permission.getDescription());
583 481 jsonArray.add(json);
584 482 }
585 483 }
... ... @@ -591,258 +489,30 @@ public class SysDataPermissionController {
591 489 * @param metaList
592 490 */
593 491 private void getAuthJsonArray(JSONArray jsonArray, List<SysDataPermission> metaList) {
594   - for (SysDataPermission permission : metaList) {
595   - if (permission.getType() == null) {
596   - continue;
597   - }
598   - /*JSONObject json = null;
599   - if (permission.getType().equals(CommonConstant.MENU_TYPE_2)) {
600   - json = new JSONObject();
601   - json.put("action", permission.getPerms());
602   - json.put("type", permission.getPermsType());
603   - json.put("describe", permission.getName());
604   - jsonArray.add(json);
605   - }*/
606   - }
607   - }
608   -
609   - /**
610   - * 获取菜单JSON数组
611   - *
612   - * @param jsonArray
613   - * @param metaList
614   - * @param parentJson
615   - */
616   - private void getPermissionJsonArray(JSONArray jsonArray, List<SysDataPermission> metaList, JSONObject parentJson) {
617   - for (SysDataPermission permission : metaList) {
618   - if (permission.getType() == null) {
619   - continue;
620   - }
621   - String tempPid = String.valueOf(permission.getParentId());
622   - JSONObject json = getPermissionJsonObject(permission);
623   - if (json == null) {
624   - continue;
625   - }
626   - if (parentJson == null && oConvertUtils.isEmpty(tempPid)) {
627   - jsonArray.add(json);
628   - if (!permission.isLeaf()) {
629   - getPermissionJsonArray(jsonArray, metaList, json);
630   - }
631   - } else if (parentJson != null && oConvertUtils.isNotEmpty(tempPid) && tempPid.equals(parentJson.getString("id"))) {
632   - // 类型( 0:一级菜单 1:子菜单 2:按钮 )
633   - if (permission.getType().equals(CommonConstant.MENU_TYPE_2)) {
634   - JSONObject metaJson = parentJson.getJSONObject("meta");
635   - if (metaJson.containsKey("permissionList")) {
636   - metaJson.getJSONArray("permissionList").add(json);
637   - } else {
638   - JSONArray permissionList = new JSONArray();
639   - permissionList.add(json);
640   - metaJson.put("permissionList", permissionList);
641   - }
642   - // 类型( 0:一级菜单 1:子菜单 2:按钮 )
643   - } else if (permission.getType().equals(CommonConstant.MENU_TYPE_1) || permission.getType().equals(CommonConstant.MENU_TYPE_0)) {
644   - if (parentJson.containsKey("children")) {
645   - parentJson.getJSONArray("children").add(json);
646   - } else {
647   - JSONArray children = new JSONArray();
648   - children.add(json);
649   - parentJson.put("children", children);
650   - }
651   -
652   - if (!permission.isLeaf()) {
653   - getPermissionJsonArray(jsonArray, metaList, json);
654   - }
655   - }
656   - }
657   -
658   - }
659   - }
660   -
661   - /**
662   - * 根据菜单配置生成路由json
663   - *
664   - * @param permission
665   - * @return
666   - */
667   - private JSONObject getPermissionJsonObject(SysDataPermission permission) {
668   - JSONObject json = new JSONObject();
669   - // 类型(0:一级菜单 1:子菜单 2:按钮)
670   - if (permission.getType().equals(CommonConstant.MENU_TYPE_2)) {
671   - // json.put("action", permission.getPerms());
672   - // json.put("type", permission.getPermsType());
673   - // json.put("describe", permission.getName());
674   - return null;
675   - } else if (permission.getType().equals(CommonConstant.MENU_TYPE_0) || permission.getType().equals(CommonConstant.MENU_TYPE_1)) {
676   - json.put("id", permission.getId());
677   - }
678   -
679   - return json;
680   - }
681   -
682   - /**
683   - * 判断是否外网URL 例如: http://localhost:8080/jeecg-boot/swagger-ui.html#/ 支持特殊格式: {{
684   - * window._CONFIG['domianURL'] }}/druid/ {{ JS代码片段 }},前台解析会自动执行JS代码片段
685   - *
686   - * @return
687   - */
688   - private boolean isWWWHttpUrl(String url) {
689   - if (url != null && (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("{{"))) {
690   - return true;
691   - }
692   - return false;
693   - }
694   -
695   - /**
696   - * 通过URL生成路由name(去掉URL前缀斜杠,替换内容中的斜杠‘/’为-) 举例: URL = /isystem/role RouteName =
697   - * isystem-role
698   - *
699   - * @return
700   - */
701   - private String urlToRouteName(String url) {
702   - if (oConvertUtils.isNotEmpty(url)) {
703   - if (url.startsWith("/")) {
704   - url = url.substring(1);
705   - }
706   - url = url.replace("/", "-");
707   -
708   - // 特殊标记
709   - url = url.replace(":", "@");
710   - return url;
711   - } else {
712   - return null;
713   - }
714   - }
  492 + List<SysDataPermission> parentList = metaList.stream()
  493 + .filter(permission -> Objects.isNull(permission.getParentId()))
  494 + .collect(Collectors.toList());
  495 + parentList.forEach(parentPermission -> {
  496 + List<SysDataPermission> childPermissionList = metaList.stream().filter(permission -> ObjectUtil.isNotNull(permission.getParentId()) && permission.getParentId().equals(parentPermission.getId()))
  497 + .collect(Collectors.toList());
715 498  
716   - /**
717   - * 根据菜单id来获取其对应的权限数据
718   - *
719   - * @param sysPermissionDataRule
720   - * @return
721   - */
722   - @RequestMapping(value = "/getPermRuleListByPermId", method = RequestMethod.GET)
723   - public Result<List<SysPermissionDataRule>> getPermRuleListByPermId(SysPermissionDataRule sysPermissionDataRule) {
724   - List<SysPermissionDataRule> permRuleList = sysPermissionDataRuleService.getPermRuleListByPermId(sysPermissionDataRule.getPermissionId().toString());
725   - Result<List<SysPermissionDataRule>> result = new Result<>();
726   - result.setSuccess(true);
727   - result.setResult(permRuleList);
728   - return result;
729   - }
730   -
731   - /**
732   - * 添加菜单权限数据
733   - *
734   - * @param sysPermissionDataRule
735   - * @return
736   - */
737   - // @RequiresRoles({ "admin" })
738   - @RequestMapping(value = "/addPermissionRule", method = RequestMethod.POST)
739   - public Result<SysPermissionDataRule> addPermissionRule(@RequestBody SysPermissionDataRule sysPermissionDataRule) {
740   - Result<SysPermissionDataRule> result = new Result<SysPermissionDataRule>();
741   - try {
742   - sysPermissionDataRule.setCreateTime(new Date());
743   - sysPermissionDataRuleService.savePermissionDataRule(sysPermissionDataRule);
744   - result.success("添加成功!");
745   - } catch (Exception e) {
746   - log.error(e.getMessage(), e);
747   - result.error500("操作失败");
748   - }
749   - return result;
750   - }
751   -
752   - // @RequiresRoles({ "admin" })
753   - @RequestMapping(value = "/editPermissionRule", method = {RequestMethod.PUT, RequestMethod.POST})
754   - public Result<SysPermissionDataRule> editPermissionRule(@RequestBody SysPermissionDataRule sysPermissionDataRule) {
755   - Result<SysPermissionDataRule> result = new Result<SysPermissionDataRule>();
756   - try {
757   - sysPermissionDataRuleService.saveOrUpdate(sysPermissionDataRule);
758   - result.success("更新成功!");
759   - } catch (Exception e) {
760   - log.error(e.getMessage(), e);
761   - result.error500("操作失败");
762   - }
763   - return result;
764   - }
765   -
766   - /**
767   - * 删除菜单权限数据
768   - *
769   - * @param id
770   - * @return
771   - */
772   - // @RequiresRoles({ "admin" })
773   - @RequestMapping(value = "/deletePermissionRule", method = RequestMethod.DELETE)
774   - public Result<SysPermissionDataRule> deletePermissionRule(@RequestParam(name = "id", required = true) String id) {
775   - Result<SysPermissionDataRule> result = new Result<SysPermissionDataRule>();
776   - try {
777   - sysPermissionDataRuleService.deletePermissionDataRule(id);
778   - result.success("删除成功!");
779   - } catch (Exception e) {
780   - log.error(e.getMessage(), e);
781   - result.error500("操作失败");
782   - }
783   - return result;
784   - }
785   -
786   - /**
787   - * 查询菜单权限数据
788   - *
789   - * @param sysPermissionDataRule
790   - * @return
791   - */
792   - @RequestMapping(value = "/queryPermissionRule", method = RequestMethod.GET)
793   - public Result<List<SysPermissionDataRule>> queryPermissionRule(SysPermissionDataRule sysPermissionDataRule) {
794   - Result<List<SysPermissionDataRule>> result = new Result<>();
795   - try {
796   - List<SysPermissionDataRule> permRuleList = sysPermissionDataRuleService.queryPermissionRule(sysPermissionDataRule);
797   - result.setResult(permRuleList);
798   - } catch (Exception e) {
799   - log.error(e.getMessage(), e);
800   - result.error500("操作失败");
801   - }
802   - return result;
803   - }
804   -
805   - /**
806   - * 部门权限表
807   - *
808   - * @param departId
809   - * @return
810   - */
811   - @RequestMapping(value = "/queryDepartPermission", method = RequestMethod.GET)
812   - public Result<List<String>> queryDepartPermission(@RequestParam(name = "departId", required = true) String departId) {
813   - Result<List<String>> result = new Result<>();
814   - try {
815   - List<SysDepartPermission> list =
816   - sysDepartPermissionService.list(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId));
817   - result.setResult(list.stream().map(SysDepartPermission -> String.valueOf(SysDepartPermission.getPermissionId())).collect(Collectors.toList()));
818   - result.setSuccess(true);
819   - } catch (Exception e) {
820   - log.error(e.getMessage(), e);
821   - }
822   - return result;
823   - }
824   -
825   - /**
826   - * 保存部门授权
827   - *
828   - * @return
829   - */
830   - @RequestMapping(value = "/saveDepartPermission", method = RequestMethod.POST)
831   - // @RequiresRoles({ "admin" })
832   - public Result<String> saveDepartPermission(@RequestBody JSONObject json) {
833   - long start = System.currentTimeMillis();
834   - Result<String> result = new Result<>();
835   - try {
836   - String departId = json.getString("departId");
837   - String permissionIds = json.getString("permissionIds");
838   - String lastPermissionIds = json.getString("lastpermissionIds");
839   - this.sysDepartPermissionService.saveDepartPermission(departId, permissionIds, lastPermissionIds);
840   - result.success("保存成功!");
841   - log.info("======部门授权成功=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
842   - } catch (Exception e) {
843   - result.error500("授权失败!");
844   - log.error(e.getMessage(), e);
845   - }
846   - return result;
  499 + JSONObject json = new JSONObject();
  500 + List<Map<String, Object>> params = new ArrayList<>();
  501 + childPermissionList.forEach(childPermission -> {
  502 + Map<String, Object> map = new HashMap<>();
  503 +
  504 + String[] split = childPermission.getPerms().split(StrUtil.COLON);
  505 + String perms = split.length == 2 ? split[1] : childPermission.getPerms();
  506 + map.put("name", childPermission.getName());
  507 + map.put("perms", perms);
  508 + map.put("type", childPermission.getType());
  509 + map.put("status", childPermission.getStatus());
  510 + map.put("describe", childPermission.getDescription());
  511 + params.add(map);
  512 + });
  513 +
  514 + json.put(parentPermission.getPerms(), params);
  515 + jsonArray.add(json);
  516 + });
847 517 }
848 518 }
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/entity/SysDataPermission.java
... ... @@ -3,6 +3,7 @@ package org.jeecg.modules.system.entity;
3 3 import com.baomidou.mybatisplus.annotation.IdType;
4 4 import com.baomidou.mybatisplus.annotation.TableField;
5 5 import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.fasterxml.jackson.annotation.JsonInclude;
6 7 import lombok.Data;
7 8 import lombok.EqualsAndHashCode;
8 9 import lombok.experimental.Accessors;
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/mapper/xml/SysDataPermissionMapper.xml
... ... @@ -27,7 +27,7 @@
27 27 ,name
28 28 ,icon
29 29 ,is_leaf
30   - FROM sys_permission
  30 + FROM sys_data_permission
31 31 WHERE 1=1
32 32 <choose>
33 33 <when test="parentId != null and parentId != ''">
... ... @@ -43,21 +43,19 @@
43 43 <select id="queryByUser" parameterType="Object" resultMap="SysDataPermission">
44 44 SELECT * FROM (
45 45 SELECT p.*
46   - FROM sys_permission p
  46 + FROM sys_data_permission p
47 47 WHERE (exists(
48   - select a.id from sys_role_permission a
  48 + select a.id from sys_role_data_permission a
49 49 join sys_role b on a.role_id = b.id
50 50 join sys_user_role c on c.role_id = b.id
51 51 join sys_user d on d.id = c.user_id
52 52 where p.id = a.permission_id AND d.username = #{username,jdbcType=VARCHAR}
53   - )
54   - or (p.url like '%:code' and p.url like '/online%' and p.hidden = 1)
55   - or p.url = '/online')
  53 + ))
56 54 and p.del_flag = 0
57 55 <!--update begin Author:lvdandan Date:20200213 for:加入部门权限 -->
58 56 UNION
59 57 SELECT p.*
60   - FROM sys_permission p
  58 + FROM sys_data_permission p
61 59 WHERE exists(
62 60 select a.id from sys_depart_role_permission a
63 61 join sys_depart_role b on a.role_id = b.id
... ... @@ -70,13 +68,12 @@
70 68 ) h order by h.sort_no ASC
71 69 </select>
72 70  
73   -
74 71 <!-- 根据用户账号查询菜单权限 -->
75 72 <select id="queryCountByUsername" parameterType="Object" resultType="int">
76 73 select sum(cnt) from (
77 74 select count(*) as cnt
78   - from sys_role_permission a
79   - join sys_permission b on a.permission_id = b.id
  75 + from sys_role_data_permission a
  76 + join sys_data_permission b on a.permission_id = b.id
80 77 join sys_role c on a.role_id = c.id
81 78 join sys_user_role d on d.role_id = c.id
82 79 join sys_user e on d.user_id = e.id
... ... @@ -84,12 +81,9 @@
84 81 <if test="permission.id !=null and permission.id != ''">
85 82 and b.id = #{permission.id}
86 83 </if>
87   - <if test="permission.url !=null and permission.url != ''">
88   - and b.url = #{permission.url}
89   - </if>
90 84 union all
91 85 select count(*) as cnt
92   - from sys_permission z
  86 + from sys_data_permission z
93 87 join sys_depart_role_permission y on z.id = y.permission_id
94 88 join sys_depart_role x on y.role_id = x.id
95 89 join sys_depart_role_user w on w.drole_id = x.id
... ... @@ -98,11 +92,6 @@
98 92 <if test="permission.id !=null and permission.id != ''">
99 93 and z.id = #{permission.id}
100 94 </if>
101   - <if test="permission.url !=null and permission.url != ''">
102   - and z.url = #{permission.url}
103   - </if>
104 95 ) temp
105 96 </select>
106   -
107   -
108 97 </mapper>
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysDataPermissionServiceImpl.java
... ... @@ -214,6 +214,7 @@ public class SysDataPermissionServiceImpl extends ServiceImpl&lt;SysDataPermissionM
214 214 }
215 215  
216 216 @Override
  217 + @Cacheable(value = "sys:cache:userDataPermission", key = "#username", unless = "#result == null ")
217 218 public List<SysDataPermission> queryByUser(String username) {
218 219 return this.sysDataPermissionMapper.queryByUser(username);
219 220 }
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysRoleDataPermissionServiceImpl.java
... ... @@ -9,6 +9,7 @@ import org.jeecg.common.util.oConvertUtils;
9 9 import org.jeecg.modules.system.entity.SysRoleDataPermission;
10 10 import org.jeecg.modules.system.mapper.SysRoleDataPermissionMapper;
11 11 import org.jeecg.modules.system.service.ISysRoleDataPermissionService;
  12 +import org.springframework.cache.annotation.CacheEvict;
12 13 import org.springframework.stereotype.Service;
13 14  
14 15 import javax.servlet.http.HttpServletRequest;
... ... @@ -18,8 +19,9 @@ import java.util.*;
18 19 * <p>
19 20 * 角色数据权限表 服务实现类
20 21 * </p>
  22 + *
21 23 * @Author scott
22   - * @since 2018-12-21
  24 + * @since 2018-12-21
23 25 */
24 26 @Service
25 27 public class SysRoleDataPermissionServiceImpl extends ServiceImpl<SysRoleDataPermissionMapper, SysRoleDataPermission> implements ISysRoleDataPermissionService {
... ... @@ -51,6 +53,7 @@ public class SysRoleDataPermissionServiceImpl extends ServiceImpl&lt;SysRoleDataPer
51 53 }
52 54  
53 55 @Override
  56 + @CacheEvict(value = "sys:cache:userDataPermission", allEntries = true)
54 57 public void saveRoleDataPermission(String roleId, String permissionIds, String lastPermissionIds) {
55 58 String ip = "";
56 59 try {
... ... @@ -79,15 +82,16 @@ public class SysRoleDataPermissionServiceImpl extends ServiceImpl&lt;SysRoleDataPer
79 82 if (delete != null && !delete.isEmpty()) {
80 83 for (String permissionId : delete) {
81 84 this.remove(
82   - new QueryWrapper<SysRoleDataPermission>().lambda().eq(SysRoleDataPermission::getRoleId, roleId).eq(SysRoleDataPermission::getPermissionId, permissionId));
  85 + new QueryWrapper<SysRoleDataPermission>().lambda().eq(SysRoleDataPermission::getRoleId, roleId).eq(SysRoleDataPermission::getPermissionId, permissionId));
83 86 }
84 87 }
85 88 }
86 89  
87 90 /**
88 91 * 从diff中找出main中没有的元素
89   - * @param main
90   - * @param diff
  92 + *
  93 + * @param main
  94 + * @param diff
91 95 * @return
92 96 */
93 97 private List<String> getDiff(String main, String diff) {
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/util/DataPermissionDataUtil.java deleted
1   -package org.jeecg.modules.system.util;
2   -
3   -import org.jeecg.common.util.oConvertUtils;
4   -import org.jeecg.modules.system.entity.SysDataPermission;
5   -
6   -import java.util.List;
7   -
8   -/**
9   - * @Author: scott
10   - * @Date: 2019-04-03
11   - */
12   -public class DataPermissionDataUtil {
13   -
14   - /**
15   - * 智能处理错误数据,简化用户失误操作
16   - * @param permission
17   - */
18   - public static SysDataPermission intelligentProcessData(SysDataPermission permission) {
19   - if (permission == null) {
20   - return null;
21   - }
22   - return permission;
23   - }
24   -
25   - /**
26   - * 如果没有index页面 需要new 一个放到list中
27   - * @param metaList
28   - */
29   - public static void addIndexPage(List<SysDataPermission> metaList) {
30   - boolean hasIndexMenu = false;
31   - for (SysDataPermission sysDataPermission : metaList) {
32   - if ("首页".equals(sysDataPermission.getName())) {
33   - hasIndexMenu = true;
34   - break;
35   - }
36   - }
37   - if (!hasIndexMenu) {
38   - metaList.add(0, new SysDataPermission(true));
39   - }
40   - }
41   -
42   - /**
43   - * 判断是否授权首页
44   - * @param metaList
45   - * @return
46   - */
47   - public static boolean hasIndexPage(List<SysDataPermission> metaList) {
48   - boolean hasIndexMenu = false;
49   - for (SysDataPermission sysDataPermission : metaList) {
50   - if ("首页".equals(sysDataPermission.getName())) {
51   - hasIndexMenu = true;
52   - break;
53   - }
54   - }
55   - return hasIndexMenu;
56   - }
57   -
58   -}