From c2fccb01b972176dc3da5a497b5e904025e9e98d Mon Sep 17 00:00:00 2001
From: bsw215583320 <baoshiwei121@163.com>
Date: 星期二, 16 四月 2024 15:06:51 +0800
Subject: [PATCH] Merge branch 'master' of http://210.22.126.130:1111/r/dry/herb

---
 jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysPermissionController.java |  990 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 990 insertions(+), 0 deletions(-)

diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysPermissionController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysPermissionController.java
new file mode 100644
index 0000000..939bc66
--- /dev/null
+++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysPermissionController.java
@@ -0,0 +1,990 @@
+package org.jeecg.modules.system.controller;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.apache.shiro.authz.annotation.RequiresRoles;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.constant.SymbolConstant;
+import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.Md5Util;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.config.JeecgBaseConfig;
+import org.jeecg.modules.base.service.BaseCommonService;
+import org.jeecg.modules.system.entity.*;
+import org.jeecg.modules.system.model.SysPermissionTree;
+import org.jeecg.modules.system.model.TreeModel;
+import org.jeecg.modules.system.service.*;
+import org.jeecg.modules.system.util.PermissionDataUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ * 鑿滃崟鏉冮檺琛� 鍓嶇鎺у埗鍣�
+ * </p>
+ *
+ * @Author scott
+ * @since 2018-12-21
+ */
+@Slf4j
+@RestController
+@RequestMapping("/sys/permission")
+public class SysPermissionController {
+
+	@Autowired
+	private ISysPermissionService sysPermissionService;
+
+	@Autowired
+	private ISysRolePermissionService sysRolePermissionService;
+
+	@Autowired
+	private ISysPermissionDataRuleService sysPermissionDataRuleService;
+
+	@Autowired
+	private ISysDepartPermissionService sysDepartPermissionService;
+
+	@Autowired
+	private ISysUserService sysUserService;
+
+	@Autowired
+	private JeecgBaseConfig jeecgBaseConfig;
+
+	@Autowired
+    private BaseCommonService baseCommonService;
+
+	@Autowired
+	private ISysRoleIndexService sysRoleIndexService;
+
+    /**
+     * 瀛愯彍鍗�
+     */
+	private static final String CHILDREN = "children";
+
+	/**
+	 * 鍔犺浇鏁版嵁鑺傜偣
+	 *
+	 * @return
+	 */
+	//@RequiresPermissions("system:permission:list")
+	@RequestMapping(value = "/list", method = RequestMethod.GET)
+	public Result<List<SysPermissionTree>> list(SysPermission sysPermission, HttpServletRequest req) {
+        long start = System.currentTimeMillis();
+		Result<List<SysPermissionTree>> result = new Result<>();
+		try {
+			LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
+			query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
+			query.orderByAsc(SysPermission::getSortNo);
+
+			//鏀寔閫氳繃鑿滃崟鍚嶅瓧锛屾ā绯婃煡璇�
+			if(oConvertUtils.isNotEmpty(sysPermission.getName())){
+				query.like(SysPermission::getName, sysPermission.getName());
+			}
+			List<SysPermission> list = sysPermissionService.list(query);
+			List<SysPermissionTree> treeList = new ArrayList<>();
+
+			//濡傛灉鏈夎彍鍗曞悕鏌ヨ鏉′欢锛屽垯骞抽摵鏁版嵁 涓嶅仛涓婁笅绾�
+			if(oConvertUtils.isNotEmpty(sysPermission.getName())){
+				if(list!=null && list.size()>0){
+					treeList = list.stream().map(e -> {
+						e.setLeaf(true);
+						return new SysPermissionTree(e);
+					}).collect(Collectors.toList());
+				}
+			}else{
+				getTreeList(treeList, list, null);
+			}
+			result.setResult(treeList);
+			result.setSuccess(true);
+            log.info("======鑾峰彇鍏ㄩ儴鑿滃崟鏁版嵁=====鑰楁椂:" + (System.currentTimeMillis() - start) + "姣");
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+		}
+		return result;
+	}
+
+	/*update_begin author:wuxianquan date:20190908 for:鍏堟煡璇竴绾ц彍鍗曪紝褰撶敤鎴风偣鍑诲睍寮�鑿滃崟鏃跺姞杞藉瓙鑿滃崟 */
+	/**
+	 * 绯荤粺鑿滃崟鍒楄〃(涓�绾ц彍鍗�)
+	 *
+	 * @return
+	 */
+	@RequestMapping(value = "/getSystemMenuList", method = RequestMethod.GET)
+	public Result<List<SysPermissionTree>> getSystemMenuList() {
+        long start = System.currentTimeMillis();
+		Result<List<SysPermissionTree>> result = new Result<>();
+		try {
+			LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
+			query.eq(SysPermission::getMenuType,CommonConstant.MENU_TYPE_0);
+			query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
+			query.orderByAsc(SysPermission::getSortNo);
+			List<SysPermission> list = sysPermissionService.list(query);
+			List<SysPermissionTree> sysPermissionTreeList = new ArrayList<SysPermissionTree>();
+			for(SysPermission sysPermission : list){
+				SysPermissionTree sysPermissionTree = new SysPermissionTree(sysPermission);
+				sysPermissionTreeList.add(sysPermissionTree);
+			}
+			result.setResult(sysPermissionTreeList);
+			result.setSuccess(true);
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+		}
+        log.info("======鑾峰彇涓�绾ц彍鍗曟暟鎹�=====鑰楁椂:" + (System.currentTimeMillis() - start) + "姣");
+		return result;
+	}
+
+	/**
+	 * 鏌ヨ瀛愯彍鍗�
+	 * @param parentId
+	 * @return
+	 */
+	@RequestMapping(value = "/getSystemSubmenu", method = RequestMethod.GET)
+	public Result<List<SysPermissionTree>> getSystemSubmenu(@RequestParam("parentId") String parentId){
+		Result<List<SysPermissionTree>> result = new Result<>();
+		try{
+			LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
+			query.eq(SysPermission::getParentId,parentId);
+			query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
+			query.orderByAsc(SysPermission::getSortNo);
+			List<SysPermission> list = sysPermissionService.list(query);
+			List<SysPermissionTree> sysPermissionTreeList = new ArrayList<SysPermissionTree>();
+			for(SysPermission sysPermission : list){
+				SysPermissionTree sysPermissionTree = new SysPermissionTree(sysPermission);
+				sysPermissionTreeList.add(sysPermissionTree);
+			}
+			result.setResult(sysPermissionTreeList);
+			result.setSuccess(true);
+		}catch (Exception e){
+			log.error(e.getMessage(), e);
+		}
+		return result;
+	}
+	/*update_end author:wuxianquan date:20190908 for:鍏堟煡璇竴绾ц彍鍗曪紝褰撶敤鎴风偣鍑诲睍寮�鑿滃崟鏃跺姞杞藉瓙鑿滃崟 */
+
+	// update_begin author:sunjianlei date:20200108 for: 鏂板鎵归噺鏍规嵁鐖禝D鏌ヨ瀛愮骇鑿滃崟鐨勬帴鍙� -------------
+	/**
+	 * 鏌ヨ瀛愯彍鍗�
+	 *
+	 * @param parentIds 鐖禝D锛堝涓噰鐢ㄥ崐瑙掗�楀彿鍒嗗壊锛�
+	 * @return 杩斿洖 key-value 鐨� Map
+	 */
+	@GetMapping("/getSystemSubmenuBatch")
+	public Result getSystemSubmenuBatch(@RequestParam("parentIds") String parentIds) {
+		try {
+			LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
+			List<String> parentIdList = Arrays.asList(parentIds.split(","));
+			query.in(SysPermission::getParentId, parentIdList);
+			query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
+			query.orderByAsc(SysPermission::getSortNo);
+			List<SysPermission> list = sysPermissionService.list(query);
+			Map<String, List<SysPermissionTree>> listMap = new HashMap(5);
+			for (SysPermission item : list) {
+				String pid = item.getParentId();
+				if (parentIdList.contains(pid)) {
+					List<SysPermissionTree> mapList = listMap.get(pid);
+					if (mapList == null) {
+						mapList = new ArrayList<>();
+					}
+					mapList.add(new SysPermissionTree(item));
+					listMap.put(pid, mapList);
+				}
+			}
+			return Result.ok(listMap);
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			return Result.error("鎵归噺鏌ヨ瀛愯彍鍗曞け璐ワ細" + e.getMessage());
+		}
+	}
+	// update_end author:sunjianlei date:20200108 for: 鏂板鎵归噺鏍规嵁鐖禝D鏌ヨ瀛愮骇鑿滃崟鐨勬帴鍙� -------------
+
+//	/**
+//	 * 鏌ヨ鐢ㄦ埛鎷ユ湁鐨勮彍鍗曟潈闄愬拰鎸夐挳鏉冮檺锛堟牴鎹敤鎴疯处鍙凤級
+//	 *
+//	 * @return
+//	 */
+//	@RequestMapping(value = "/queryByUser", method = RequestMethod.GET)
+//	public Result<JSONArray> queryByUser(HttpServletRequest req) {
+//		Result<JSONArray> result = new Result<>();
+//		try {
+//			String username = req.getParameter("username");
+//			List<SysPermission> metaList = sysPermissionService.queryByUser(username);
+//			JSONArray jsonArray = new JSONArray();
+//			this.getPermissionJsonArray(jsonArray, metaList, null);
+//			result.setResult(jsonArray);
+//			result.success("鏌ヨ鎴愬姛");
+//		} catch (Exception e) {
+//			result.error500("鏌ヨ澶辫触:" + e.getMessage());
+//			log.error(e.getMessage(), e);
+//		}
+//		return result;
+//	}
+
+	/**
+	 * 鏌ヨ鐢ㄦ埛鎷ユ湁鐨勮彍鍗曟潈闄愬拰鎸夐挳鏉冮檺
+	 *
+	 * @return
+	 */
+	@RequestMapping(value = "/getUserPermissionByToken", method = RequestMethod.GET)
+	//@DynamicTable(value = DynamicTableConstant.SYS_ROLE_INDEX)
+	public Result<?> getUserPermissionByToken(HttpServletRequest request) {
+		Result<JSONObject> result = new Result<JSONObject>();
+		try {
+			//鐩存帴鑾峰彇褰撳墠鐢ㄦ埛涓嶉�傜敤鍓嶇token
+			LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+			if (oConvertUtils.isEmpty(loginUser)) {
+				return Result.error("璇风櫥褰曠郴缁燂紒");
+			}
+			List<SysPermission> metaList = sysPermissionService.queryByUser(loginUser.getUsername());
+			//娣诲姞棣栭〉璺敱
+			//update-begin-author:taoyan date:20200211 for: TASK #3368 銆愯矾鐢辩紦瀛樸�戦椤电殑缂撳瓨璁剧疆鏈夐棶棰橈紝闇�瑕佹牴鎹悗鍙扮殑璺敱閰嶇疆鏉ュ疄鐜版槸鍚︾紦瀛�
+			if(!PermissionDataUtil.hasIndexPage(metaList)){
+//				SysPermission indexMenu = sysPermissionService.list(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getName,"棣栭〉")).get(0);
+//				metaList.add(0,indexMenu);
+			}
+			//update-end-author:taoyan date:20200211 for: TASK #3368 銆愯矾鐢辩紦瀛樸�戦椤电殑缂撳瓨璁剧疆鏈夐棶棰橈紝闇�瑕佹牴鎹悗鍙扮殑璺敱閰嶇疆鏉ュ疄鐜版槸鍚︾紦瀛�
+
+			//update-begin--Author:zyf Date:20220425  for:鑷畾涔夐椤靛湴鍧� LOWCOD-1578
+			String version = request.getHeader(CommonConstant.VERSION);
+			//update-begin---author:liusq ---date:2022-06-29  for锛氭帴鍙h繑鍥炲�间慨鏀癸紝鍚屾淇敼杩欓噷鐨勫垽鏂�昏緫-----------
+			SysRoleIndex roleIndex= sysUserService.getDynamicIndexByUserRole(loginUser.getUsername(),version);
+			//update-end---author:liusq ---date:2022-06-29  for锛氭帴鍙h繑鍥炲�间慨鏀癸紝鍚屾淇敼杩欓噷鐨勫垽鏂�昏緫-----------
+			//update-end--Author:zyf  Date:20220425  for锛氳嚜瀹氫箟棣栭〉鍦板潃 LOWCOD-1578
+
+			if(roleIndex!=null){
+				List<SysPermission> menus = metaList.stream().filter(sysPermission -> "棣栭〉".equals(sysPermission.getName())).collect(Collectors.toList());
+				//update-begin---author:liusq ---date:2022-06-29  for锛氳缃嚜瀹氫箟棣栭〉鍦板潃鍜岀粍浠�----------
+				String component = roleIndex.getComponent();
+				String routeUrl = roleIndex.getUrl();
+				boolean route = roleIndex.isRoute();
+				if(oConvertUtils.isNotEmpty(routeUrl)){
+					menus.get(0).setComponent(component);
+					menus.get(0).setRoute(route);
+					menus.get(0).setUrl(routeUrl);
+				}else{
+					menus.get(0).setComponent(component);
+				}
+				//update-end---author:liusq ---date:2022-06-29  for锛氳缃嚜瀹氫箟棣栭〉鍦板潃鍜岀粍浠�-----------
+			}
+
+			JSONObject json = new JSONObject();
+			JSONArray menujsonArray = new JSONArray();
+			this.getPermissionJsonArray(menujsonArray, metaList, null);
+			//涓�绾ц彍鍗曚笅鐨勫瓙鑿滃崟鍏ㄩ儴鏄殣钘忚矾鐢憋紝鍒欎竴绾ц彍鍗曚笉鏄剧ず
+			this.handleFirstLevelMenuHidden(menujsonArray);
+
+			JSONArray authjsonArray = new JSONArray();
+			this.getAuthJsonArray(authjsonArray, metaList);
+			//鏌ヨ鎵�鏈夌殑鏉冮檺
+			LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
+			query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
+			query.eq(SysPermission::getMenuType, CommonConstant.MENU_TYPE_2);
+			//query.eq(SysPermission::getStatus, "1");
+			List<SysPermission> allAuthList = sysPermissionService.list(query);
+			JSONArray allauthjsonArray = new JSONArray();
+			this.getAllAuthJsonArray(allauthjsonArray, allAuthList);
+			//璺敱鑿滃崟
+			json.put("menu", menujsonArray);
+			//鎸夐挳鏉冮檺锛堢敤鎴锋嫢鏈夌殑鏉冮檺闆嗗悎锛�
+			json.put("auth", authjsonArray);
+			//鍏ㄩ儴鏉冮檺閰嶇疆闆嗗悎锛堟寜閽潈闄愶紝璁块棶鏉冮檺锛�
+			json.put("allAuth", allauthjsonArray);
+			json.put("sysSafeMode", jeecgBaseConfig.getSafeMode());
+			result.setResult(json);
+		} catch (Exception e) {
+			result.error500("鏌ヨ澶辫触:" + e.getMessage());
+			log.error(e.getMessage(), e);
+		}
+		return result;
+	}
+
+	/**
+	 * 銆恦ue3涓撶敤銆戣幏鍙�
+	 * 1銆佹煡璇㈢敤鎴锋嫢鏈夌殑鎸夐挳/琛ㄥ崟璁块棶鏉冮檺
+	 * 2銆佹墍鏈夋潈闄� (鑿滃崟鏉冮檺閰嶇疆)
+	 * 3銆佺郴缁熷畨鍏ㄦā寮� (寮�鍚垯online鎶ヨ〃鐨勬暟鎹簮蹇呭~)
+	 */
+	@RequestMapping(value = "/getPermCode", method = RequestMethod.GET)
+	public Result<?> getPermCode() {
+		try {
+			// 鐩存帴鑾峰彇褰撳墠鐢ㄦ埛
+			LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+			if (oConvertUtils.isEmpty(loginUser)) {
+				return Result.error("璇风櫥褰曠郴缁燂紒");
+			}
+			// 鑾峰彇褰撳墠鐢ㄦ埛鐨勬潈闄愰泦鍚�
+			List<SysPermission> metaList = sysPermissionService.queryByUser(loginUser.getUsername());
+            // 鎸夐挳鏉冮檺锛堢敤鎴锋嫢鏈夌殑鏉冮檺闆嗗悎锛�
+            List<String> codeList = metaList.stream()
+                    .filter((permission) -> CommonConstant.MENU_TYPE_2.equals(permission.getMenuType()) && CommonConstant.STATUS_1.equals(permission.getStatus()))
+                    .collect(ArrayList::new, (list, permission) -> list.add(permission.getPerms()), ArrayList::addAll);
+            //
+			JSONArray authArray = new JSONArray();
+			this.getAuthJsonArray(authArray, metaList);
+			// 鏌ヨ鎵�鏈夌殑鏉冮檺
+			LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
+			query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
+			query.eq(SysPermission::getMenuType, CommonConstant.MENU_TYPE_2);
+			List<SysPermission> allAuthList = sysPermissionService.list(query);
+			JSONArray allAuthArray = new JSONArray();
+			this.getAllAuthJsonArray(allAuthArray, allAuthList);
+			JSONObject result = new JSONObject();
+            // 鎵�鎷ユ湁鐨勬潈闄愮紪鐮�
+			result.put("codeList", codeList);
+			//鎸夐挳鏉冮檺锛堢敤鎴锋嫢鏈夌殑鏉冮檺闆嗗悎锛�
+			result.put("auth", authArray);
+			//鍏ㄩ儴鏉冮檺閰嶇疆闆嗗悎锛堟寜閽潈闄愶紝璁块棶鏉冮檺锛�
+			result.put("allAuth", allAuthArray);
+            // 绯荤粺瀹夊叏妯″紡
+			result.put("sysSafeMode", jeecgBaseConfig.getSafeMode());
+            return Result.OK(result);
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+            return Result.error("鏌ヨ澶辫触:" + e.getMessage());
+		}
+	}
+
+	/**
+	  * 娣诲姞鑿滃崟
+	 * @param permission
+	 * @return
+	 */
+    @RequiresPermissions("system:permission:add")
+	@RequestMapping(value = "/add", method = RequestMethod.POST)
+	public Result<SysPermission> add(@RequestBody SysPermission permission) {
+		Result<SysPermission> result = new Result<SysPermission>();
+		try {
+			permission = PermissionDataUtil.intelligentProcessData(permission);
+			sysPermissionService.addPermission(permission);
+			result.success("娣诲姞鎴愬姛锛�");
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			result.error500("鎿嶄綔澶辫触");
+		}
+		return result;
+	}
+
+	/**
+	  * 缂栬緫鑿滃崟
+	 * @param permission
+	 * @return
+	 */
+    @RequiresPermissions("system:permission:edit")
+	@RequestMapping(value = "/edit", method = { RequestMethod.PUT, RequestMethod.POST })
+	public Result<SysPermission> edit(@RequestBody SysPermission permission) {
+		Result<SysPermission> result = new Result<>();
+		try {
+			permission = PermissionDataUtil.intelligentProcessData(permission);
+			sysPermissionService.editPermission(permission);
+			result.success("淇敼鎴愬姛锛�");
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			result.error500("鎿嶄綔澶辫触");
+		}
+		return result;
+	}
+
+	/**
+	 * 妫�娴嬭彍鍗曡矾寰勬槸鍚﹀瓨鍦�
+	 * @param id
+	 * @param url
+	 * @return
+	 */
+	@RequestMapping(value = "/checkPermDuplication", method = RequestMethod.GET)
+	public Result<String> checkPermDuplication(@RequestParam(name = "id", required = false) String id,@RequestParam(name = "url") String url,@RequestParam(name = "alwaysShow") Boolean alwaysShow) {
+		Result<String> result = new Result<>();
+		try {
+			boolean check=sysPermissionService.checkPermDuplication(id,url,alwaysShow);
+			if(check){
+				return Result.ok("璇ュ�煎彲鐢紒");
+			}
+			return Result.error("璁块棶璺緞涓嶅厑璁搁噸澶嶏紝璇烽噸瀹氫箟锛�");
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			result.error500("鎿嶄綔澶辫触");
+		}
+		return result;
+	}
+
+	/**
+	  * 鍒犻櫎鑿滃崟
+	 * @param id
+	 * @return
+	 */
+    @RequiresPermissions("system:permission:delete")
+	@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
+	public Result<SysPermission> delete(@RequestParam(name = "id", required = true) String id) {
+		Result<SysPermission> result = new Result<>();
+		try {
+			sysPermissionService.deletePermission(id);
+			result.success("鍒犻櫎鎴愬姛!");
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			result.error500(e.getMessage());
+		}
+		return result;
+	}
+
+	/**
+	  * 鎵归噺鍒犻櫎鑿滃崟
+	 * @param ids
+	 * @return
+	 */
+    @RequiresPermissions("system:permission:deleteBatch")
+	@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
+	public Result<SysPermission> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+		Result<SysPermission> result = new Result<>();
+		try {
+            String[] arr = ids.split(",");
+			for (String id : arr) {
+				if (oConvertUtils.isNotEmpty(id)) {
+					try {
+						sysPermissionService.deletePermission(id);
+					} catch (JeecgBootException e) {
+						if(e.getMessage()!=null && e.getMessage().contains("鏈壘鍒拌彍鍗曚俊鎭�")){
+							log.warn(e.getMessage());
+						}else{
+							throw e;
+						}
+					}
+				}
+			}
+			result.success("鍒犻櫎鎴愬姛!");
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			result.error500("鍒犻櫎澶辫触!");
+		}
+		return result;
+	}
+
+	/**
+	 * 鑾峰彇鍏ㄩ儴鐨勬潈闄愭爲
+	 *
+	 * @return
+	 */
+	@RequestMapping(value = "/queryTreeList", method = RequestMethod.GET)
+	public Result<Map<String, Object>> queryTreeList() {
+		Result<Map<String, Object>> result = new Result<>();
+		// 鍏ㄩ儴鏉冮檺ids
+		List<String> ids = new ArrayList<>();
+		try {
+			LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
+			query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
+			query.orderByAsc(SysPermission::getSortNo);
+			List<SysPermission> list = sysPermissionService.list(query);
+			for (SysPermission sysPer : list) {
+				ids.add(sysPer.getId());
+			}
+			List<TreeModel> treeList = new ArrayList<>();
+			getTreeModelList(treeList, list, null);
+
+			Map<String, Object> resMap = new HashMap<String, Object>(5);
+            // 鍏ㄩ儴鏍戣妭鐐规暟鎹�
+			resMap.put("treeList", treeList);
+            // 鍏ㄩ儴鏍慽ds
+			resMap.put("ids", ids);
+			result.setResult(resMap);
+			result.setSuccess(true);
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+		}
+		return result;
+	}
+
+	/**
+	 * 寮傛鍔犺浇鏁版嵁鑺傜偣 [鎺ュ彛鏄簾鐨�,娌℃湁鐢ㄥ埌]
+	 *
+	 * @return
+	 */
+	@RequestMapping(value = "/queryListAsync", method = RequestMethod.GET)
+	public Result<List<TreeModel>> queryAsync(@RequestParam(name = "pid", required = false) String parentId) {
+		Result<List<TreeModel>> result = new Result<>();
+		try {
+			List<TreeModel> list = sysPermissionService.queryListByParentId(parentId);
+			if (list == null || list.size() <= 0) {
+				result.error500("鏈壘鍒拌鑹蹭俊鎭�");
+			} else {
+				result.setResult(list);
+				result.setSuccess(true);
+			}
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+		}
+
+		return result;
+	}
+
+	/**
+	 * 鏌ヨ瑙掕壊鎺堟潈
+	 *
+	 * @return
+	 */
+	@RequestMapping(value = "/queryRolePermission", method = RequestMethod.GET)
+	public Result<List<String>> queryRolePermission(@RequestParam(name = "roleId", required = true) String roleId) {
+		Result<List<String>> result = new Result<>();
+		try {
+			List<SysRolePermission> list = sysRolePermissionService.list(new QueryWrapper<SysRolePermission>().lambda().eq(SysRolePermission::getRoleId, roleId));
+			result.setResult(list.stream().map(sysRolePermission -> String.valueOf(sysRolePermission.getPermissionId())).collect(Collectors.toList()));
+			result.setSuccess(true);
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+		}
+		return result;
+	}
+
+	/**
+	 * 淇濆瓨瑙掕壊鎺堟潈
+	 *
+	 * @return
+	 */
+	@RequestMapping(value = "/saveRolePermission", method = RequestMethod.POST)
+    @RequiresPermissions("system:permission:saveRole")
+	public Result<String> saveRolePermission(@RequestBody JSONObject json) {
+		long start = System.currentTimeMillis();
+		Result<String> result = new Result<>();
+		try {
+			String roleId = json.getString("roleId");
+			String permissionIds = json.getString("permissionIds");
+			String lastPermissionIds = json.getString("lastpermissionIds");
+			this.sysRolePermissionService.saveRolePermission(roleId, permissionIds, lastPermissionIds);
+			//update-begin---author:wangshuai ---date:20220316  for锛歔VUEN-234]鐢ㄦ埛绠$悊瑙掕壊鎺堟潈娣诲姞鏁忔劅鏃ュ織------------
+            LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+			baseCommonService.addLog("淇敼瑙掕壊ID: "+roleId+" 鐨勬潈闄愰厤缃紝鎿嶄綔浜猴細 " +loginUser.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
+            //update-end---author:wangshuai ---date:20220316  for锛歔VUEN-234]鐢ㄦ埛绠$悊瑙掕壊鎺堟潈娣诲姞鏁忔劅鏃ュ織------------
+			result.success("淇濆瓨鎴愬姛锛�");
+			log.info("======瑙掕壊鎺堟潈鎴愬姛=====鑰楁椂:" + (System.currentTimeMillis() - start) + "姣");
+		} catch (Exception e) {
+			result.error500("鎺堟潈澶辫触锛�");
+			log.error(e.getMessage(), e);
+		}
+		return result;
+	}
+
+	private void getTreeList(List<SysPermissionTree> treeList, List<SysPermission> metaList, SysPermissionTree temp) {
+		for (SysPermission permission : metaList) {
+			String tempPid = permission.getParentId();
+			SysPermissionTree tree = new SysPermissionTree(permission);
+			if (temp == null && oConvertUtils.isEmpty(tempPid)) {
+				treeList.add(tree);
+				if (!tree.getIsLeaf()) {
+					getTreeList(treeList, metaList, tree);
+				}
+			} else if (temp != null && tempPid != null && tempPid.equals(temp.getId())) {
+				temp.getChildren().add(tree);
+				if (!tree.getIsLeaf()) {
+					getTreeList(treeList, metaList, tree);
+				}
+			}
+
+		}
+	}
+
+	private void getTreeModelList(List<TreeModel> treeList, List<SysPermission> metaList, TreeModel temp) {
+		for (SysPermission permission : metaList) {
+			String tempPid = permission.getParentId();
+			TreeModel tree = new TreeModel(permission);
+			if (temp == null && oConvertUtils.isEmpty(tempPid)) {
+				treeList.add(tree);
+				if (!tree.getIsLeaf()) {
+					getTreeModelList(treeList, metaList, tree);
+				}
+			} else if (temp != null && tempPid != null && tempPid.equals(temp.getKey())) {
+				temp.getChildren().add(tree);
+				if (!tree.getIsLeaf()) {
+					getTreeModelList(treeList, metaList, tree);
+				}
+			}
+
+		}
+	}
+
+	/**
+	 * 涓�绾ц彍鍗曠殑瀛愯彍鍗曞叏閮ㄦ槸闅愯棌璺敱锛屽垯涓�绾ц彍鍗曚笉鏄剧ず
+	 * @param jsonArray
+	 */
+	private void handleFirstLevelMenuHidden(JSONArray jsonArray) {
+		jsonArray = jsonArray.stream().map(obj -> {
+			JSONObject returnObj = new JSONObject();
+			JSONObject jsonObj = (JSONObject)obj;
+			if(jsonObj.containsKey(CHILDREN)){
+				JSONArray childrens = jsonObj.getJSONArray(CHILDREN);
+                childrens = childrens.stream().filter(arrObj -> !"true".equals(((JSONObject) arrObj).getString("hidden"))).collect(Collectors.toCollection(JSONArray::new));
+                if(childrens==null || childrens.size()==0){
+                    jsonObj.put("hidden",true);
+
+                    //vue3鐗堟湰鍏煎浠g爜
+                    JSONObject meta = new JSONObject();
+                    meta.put("hideMenu",true);
+                    jsonObj.put("meta", meta);
+                }
+			}
+			return returnObj;
+		}).collect(Collectors.toCollection(JSONArray::new));
+	}
+
+
+	/**
+	  *  鑾峰彇鏉冮檺JSON鏁扮粍
+	 * @param jsonArray
+	 * @param allList
+	 */
+	private void getAllAuthJsonArray(JSONArray jsonArray,List<SysPermission> allList) {
+		JSONObject json = null;
+		for (SysPermission permission : allList) {
+			json = new JSONObject();
+			json.put("action", permission.getPerms());
+			json.put("status", permission.getStatus());
+			//1鏄剧ず2绂佺敤
+			json.put("type", permission.getPermsType());
+			json.put("describe", permission.getName());
+			jsonArray.add(json);
+		}
+	}
+
+	/**
+	  *  鑾峰彇鏉冮檺JSON鏁扮粍
+	 * @param jsonArray
+	 * @param metaList
+	 */
+	private void getAuthJsonArray(JSONArray jsonArray,List<SysPermission> metaList) {
+		for (SysPermission permission : metaList) {
+			if(permission.getMenuType()==null) {
+				continue;
+			}
+			JSONObject json = null;
+			if(permission.getMenuType().equals(CommonConstant.MENU_TYPE_2) &&CommonConstant.STATUS_1.equals(permission.getStatus())) {
+				json = new JSONObject();
+				json.put("action", permission.getPerms());
+				json.put("type", permission.getPermsType());
+				json.put("describe", permission.getName());
+				jsonArray.add(json);
+			}
+		}
+	}
+	/**
+	  *  鑾峰彇鑿滃崟JSON鏁扮粍
+	 * @param jsonArray
+	 * @param metaList
+	 * @param parentJson
+	 */
+	private void getPermissionJsonArray(JSONArray jsonArray, List<SysPermission> metaList, JSONObject parentJson) {
+		for (SysPermission permission : metaList) {
+			if (permission.getMenuType() == null) {
+				continue;
+			}
+			String tempPid = permission.getParentId();
+			JSONObject json = getPermissionJsonObject(permission);
+			if(json==null) {
+				continue;
+			}
+			if (parentJson == null && oConvertUtils.isEmpty(tempPid)) {
+				jsonArray.add(json);
+				if (!permission.isLeaf()) {
+					getPermissionJsonArray(jsonArray, metaList, json);
+				}
+			} else if (parentJson != null && oConvertUtils.isNotEmpty(tempPid) && tempPid.equals(parentJson.getString("id"))) {
+				// 绫诲瀷( 0锛氫竴绾ц彍鍗� 1锛氬瓙鑿滃崟 2锛氭寜閽� )
+				if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_2)) {
+					JSONObject metaJson = parentJson.getJSONObject("meta");
+					if (metaJson.containsKey("permissionList")) {
+						metaJson.getJSONArray("permissionList").add(json);
+					} else {
+						JSONArray permissionList = new JSONArray();
+						permissionList.add(json);
+						metaJson.put("permissionList", permissionList);
+					}
+					// 绫诲瀷( 0锛氫竴绾ц彍鍗� 1锛氬瓙鑿滃崟 2锛氭寜閽� )
+				} else if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_1) || permission.getMenuType().equals(CommonConstant.MENU_TYPE_0)) {
+					if (parentJson.containsKey("children")) {
+						parentJson.getJSONArray("children").add(json);
+					} else {
+						JSONArray children = new JSONArray();
+						children.add(json);
+						parentJson.put("children", children);
+					}
+
+					if (!permission.isLeaf()) {
+						getPermissionJsonArray(jsonArray, metaList, json);
+					}
+				}
+			}
+
+		}
+	}
+
+	/**
+	 * 鏍规嵁鑿滃崟閰嶇疆鐢熸垚璺敱json
+	 * @param permission
+	 * @return
+	 */
+		private JSONObject getPermissionJsonObject(SysPermission permission) {
+		JSONObject json = new JSONObject();
+		// 绫诲瀷(0锛氫竴绾ц彍鍗� 1锛氬瓙鑿滃崟 2锛氭寜閽�)
+		if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_2)) {
+			//json.put("action", permission.getPerms());
+			//json.put("type", permission.getPermsType());
+			//json.put("describe", permission.getName());
+			return null;
+		} else if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_0) || permission.getMenuType().equals(CommonConstant.MENU_TYPE_1)) {
+			json.put("id", permission.getId());
+			if (permission.isRoute()) {
+                //琛ㄧず鐢熸垚璺敱
+				json.put("route", "1");
+			} else {
+                //琛ㄧず涓嶇敓鎴愯矾鐢�
+				json.put("route", "0");
+			}
+
+			if (isWwwHttpUrl(permission.getUrl())) {
+				json.put("path", Md5Util.md5Encode(permission.getUrl(), "utf-8"));
+			} else {
+				json.put("path", permission.getUrl());
+			}
+
+			// 閲嶈瑙勫垯锛氳矾鐢眓ame (閫氳繃URL鐢熸垚璺敱name,璺敱name渚涘墠绔紑鍙戯紝椤甸潰璺宠浆浣跨敤)
+			if (oConvertUtils.isNotEmpty(permission.getComponentName())) {
+				json.put("name", permission.getComponentName());
+			} else {
+				json.put("name", urlToRouteName(permission.getUrl()));
+			}
+
+			JSONObject meta = new JSONObject();
+			// 鏄惁闅愯棌璺敱锛岄粯璁ら兘鏄樉绀虹殑
+			if (permission.isHidden()) {
+				json.put("hidden", true);
+                //vue3鐗堟湰鍏煎浠g爜
+                meta.put("hideMenu",true);
+			}
+			// 鑱氬悎璺敱
+			if (permission.isAlwaysShow()) {
+				json.put("alwaysShow", true);
+			}
+			json.put("component", permission.getComponent());
+			// 鐢辩敤鎴疯缃槸鍚︾紦瀛橀〉闈� 鐢ㄥ竷灏斿��
+			if (permission.isKeepAlive()) {
+				meta.put("keepAlive", true);
+			} else {
+				meta.put("keepAlive", false);
+			}
+
+			/*update_begin author:wuxianquan date:20190908 for:寰�鑿滃崟淇℃伅閲屾坊鍔犲閾捐彍鍗曟墦寮�鏂瑰紡 */
+			//澶栭摼鑿滃崟鎵撳紑鏂瑰紡
+			if (permission.isInternalOrExternal()) {
+				meta.put("internalOrExternal", true);
+			} else {
+				meta.put("internalOrExternal", false);
+			}
+			/* update_end author:wuxianquan date:20190908 for: 寰�鑿滃崟淇℃伅閲屾坊鍔犲閾捐彍鍗曟墦寮�鏂瑰紡*/
+
+			meta.put("title", permission.getName());
+
+			//update-begin--Author:scott  Date:20201015 for锛氳矾鐢辩紦瀛橀棶棰橈紝鍏抽棴浜唗ab椤垫椂鍐嶆墦寮�灏变笉鍒锋柊 #842
+			String component = permission.getComponent();
+			if(oConvertUtils.isNotEmpty(permission.getComponentName()) || oConvertUtils.isNotEmpty(component)){
+				meta.put("componentName", oConvertUtils.getString(permission.getComponentName(),component.substring(component.lastIndexOf("/")+1)));
+			}
+			//update-end--Author:scott  Date:20201015 for锛氳矾鐢辩紦瀛橀棶棰橈紝鍏抽棴浜唗ab椤垫椂鍐嶆墦寮�灏变笉鍒锋柊 #842
+
+			if (oConvertUtils.isEmpty(permission.getParentId())) {
+				// 涓�绾ц彍鍗曡烦杞湴鍧�
+				json.put("redirect", permission.getRedirect());
+				if (oConvertUtils.isNotEmpty(permission.getIcon())) {
+					meta.put("icon", permission.getIcon());
+				}
+			} else {
+				if (oConvertUtils.isNotEmpty(permission.getIcon())) {
+					meta.put("icon", permission.getIcon());
+				}
+			}
+			if (isWwwHttpUrl(permission.getUrl())) {
+				meta.put("url", permission.getUrl());
+			}
+			// update-begin--Author:sunjianlei  Date:20210918 for锛氭柊澧為�傞厤vue3椤圭洰鐨勯殣钘弔ab鍔熻兘
+			if (permission.isHideTab()) {
+				meta.put("hideTab", true);
+			}
+			// update-end--Author:sunjianlei  Date:20210918 for锛氭柊澧為�傞厤vue3椤圭洰鐨勯殣钘弔ab鍔熻兘
+			json.put("meta", meta);
+		}
+
+		return json;
+	}
+
+	/**
+	 * 鍒ゆ柇鏄惁澶栫綉URL 渚嬪锛� http://localhost:8080/jeecg-boot/swagger-ui.html#/ 鏀寔鐗规畩鏍煎紡锛� {{
+	 * window._CONFIG['domianURL'] }}/druid/ {{ JS浠g爜鐗囨 }}锛屽墠鍙拌В鏋愪細鑷姩鎵цJS浠g爜鐗囨
+	 *
+	 * @return
+	 */
+	private boolean isWwwHttpUrl(String url) {
+        boolean flag = url != null && (url.startsWith(CommonConstant.HTTP_PROTOCOL) || url.startsWith(CommonConstant.HTTPS_PROTOCOL) || url.startsWith(SymbolConstant.DOUBLE_LEFT_CURLY_BRACKET));
+        if (flag) {
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * 閫氳繃URL鐢熸垚璺敱name锛堝幓鎺塙RL鍓嶇紑鏂滄潬锛屾浛鎹㈠唴瀹逛腑鐨勬枩鏉犫��/鈥欎负-锛� 涓句緥锛� URL = /isystem/role RouteName =
+	 * isystem-role
+	 *
+	 * @return
+	 */
+	private String urlToRouteName(String url) {
+		if (oConvertUtils.isNotEmpty(url)) {
+			if (url.startsWith(SymbolConstant.SINGLE_SLASH)) {
+				url = url.substring(1);
+			}
+			url = url.replace("/", "-");
+
+			// 鐗规畩鏍囪
+			url = url.replace(":", "@");
+			return url;
+		} else {
+			return null;
+		}
+	}
+
+	/**
+	 * 鏍规嵁鑿滃崟id鏉ヨ幏鍙栧叾瀵瑰簲鐨勬潈闄愭暟鎹�
+	 *
+	 * @param sysPermissionDataRule
+	 * @return
+	 */
+	@RequestMapping(value = "/getPermRuleListByPermId", method = RequestMethod.GET)
+	public Result<List<SysPermissionDataRule>> getPermRuleListByPermId(SysPermissionDataRule sysPermissionDataRule) {
+		List<SysPermissionDataRule> permRuleList = sysPermissionDataRuleService.getPermRuleListByPermId(sysPermissionDataRule.getPermissionId());
+		Result<List<SysPermissionDataRule>> result = new Result<>();
+		result.setSuccess(true);
+		result.setResult(permRuleList);
+		return result;
+	}
+
+	/**
+	 * 娣诲姞鑿滃崟鏉冮檺鏁版嵁
+	 *
+	 * @param sysPermissionDataRule
+	 * @return
+	 */
+    @RequiresPermissions("system:permission:addRule")
+	@RequestMapping(value = "/addPermissionRule", method = RequestMethod.POST)
+	public Result<SysPermissionDataRule> addPermissionRule(@RequestBody SysPermissionDataRule sysPermissionDataRule) {
+		Result<SysPermissionDataRule> result = new Result<SysPermissionDataRule>();
+		try {
+			sysPermissionDataRule.setCreateTime(new Date());
+			sysPermissionDataRuleService.savePermissionDataRule(sysPermissionDataRule);
+			result.success("娣诲姞鎴愬姛锛�");
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			result.error500("鎿嶄綔澶辫触");
+		}
+		return result;
+	}
+
+    @RequiresPermissions("system:permission:editRule")
+	@RequestMapping(value = "/editPermissionRule", method = { RequestMethod.PUT, RequestMethod.POST })
+	public Result<SysPermissionDataRule> editPermissionRule(@RequestBody SysPermissionDataRule sysPermissionDataRule) {
+		Result<SysPermissionDataRule> result = new Result<SysPermissionDataRule>();
+		try {
+			sysPermissionDataRuleService.saveOrUpdate(sysPermissionDataRule);
+			result.success("鏇存柊鎴愬姛锛�");
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			result.error500("鎿嶄綔澶辫触");
+		}
+		return result;
+	}
+
+	/**
+	 * 鍒犻櫎鑿滃崟鏉冮檺鏁版嵁
+	 *
+	 * @param id
+	 * @return
+	 */
+    @RequiresPermissions("system:permission:deleteRule")
+	@RequestMapping(value = "/deletePermissionRule", method = RequestMethod.DELETE)
+	public Result<SysPermissionDataRule> deletePermissionRule(@RequestParam(name = "id", required = true) String id) {
+		Result<SysPermissionDataRule> result = new Result<SysPermissionDataRule>();
+		try {
+			sysPermissionDataRuleService.deletePermissionDataRule(id);
+			result.success("鍒犻櫎鎴愬姛锛�");
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			result.error500("鎿嶄綔澶辫触");
+		}
+		return result;
+	}
+
+	/**
+	 * 鏌ヨ鑿滃崟鏉冮檺鏁版嵁
+	 *
+	 * @param sysPermissionDataRule
+	 * @return
+	 */
+	@RequestMapping(value = "/queryPermissionRule", method = RequestMethod.GET)
+	public Result<List<SysPermissionDataRule>> queryPermissionRule(SysPermissionDataRule sysPermissionDataRule) {
+		Result<List<SysPermissionDataRule>> result = new Result<>();
+		try {
+			List<SysPermissionDataRule> permRuleList = sysPermissionDataRuleService.queryPermissionRule(sysPermissionDataRule);
+			result.setResult(permRuleList);
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			result.error500("鎿嶄綔澶辫触");
+		}
+		return result;
+	}
+
+	/**
+	 * 閮ㄩ棬鏉冮檺琛�
+	 * @param departId
+	 * @return
+	 */
+	@RequestMapping(value = "/queryDepartPermission", method = RequestMethod.GET)
+	public Result<List<String>> queryDepartPermission(@RequestParam(name = "departId", required = true) String departId) {
+		Result<List<String>> result = new Result<>();
+		try {
+			List<SysDepartPermission> list = sysDepartPermissionService.list(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId));
+			result.setResult(list.stream().map(sysDepartPermission -> String.valueOf(sysDepartPermission.getPermissionId())).collect(Collectors.toList()));
+			result.setSuccess(true);
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+		}
+		return result;
+	}
+
+	/**
+	 * 淇濆瓨閮ㄩ棬鎺堟潈
+	 *
+	 * @return
+	 */
+	@RequestMapping(value = "/saveDepartPermission", method = RequestMethod.POST)
+    @RequiresPermissions("system:permission:saveDepart")
+	public Result<String> saveDepartPermission(@RequestBody JSONObject json) {
+		long start = System.currentTimeMillis();
+		Result<String> result = new Result<>();
+		try {
+			String departId = json.getString("departId");
+			String permissionIds = json.getString("permissionIds");
+			String lastPermissionIds = json.getString("lastpermissionIds");
+			this.sysDepartPermissionService.saveDepartPermission(departId, permissionIds, lastPermissionIds);
+			result.success("淇濆瓨鎴愬姛锛�");
+			log.info("======閮ㄩ棬鎺堟潈鎴愬姛=====鑰楁椂:" + (System.currentTimeMillis() - start) + "姣");
+		} catch (Exception e) {
+			result.error500("鎺堟潈澶辫触锛�");
+			log.error(e.getMessage(), e);
+		}
+		return result;
+	}
+
+}

--
Gitblit v1.9.3