From f09e05514d9a9e2623cfa73c4de1ffa98bb30bf8 Mon Sep 17 00:00:00 2001
From: xiejun <xiejun@vci-tech.com>
Date: 星期二, 23 一月 2024 10:09:07 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/RoleServiceImpl.java |   38 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/RoleServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/RoleServiceImpl.java
index 8ec1b9b..b145ad3 100644
--- a/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/RoleServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/RoleServiceImpl.java
@@ -16,29 +16,35 @@
  */
 package com.vci.ubcs.system.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.vci.ubcs.system.entity.Menu;
 import com.vci.ubcs.system.mapper.RoleMapper;
+import com.vci.ubcs.system.service.IMenuService;
 import com.vci.ubcs.system.service.IRoleMenuService;
 import com.vci.ubcs.system.service.IRoleScopeService;
 import com.vci.ubcs.system.service.IRoleService;
 import com.vci.ubcs.system.vo.DeptVO;
 import com.vci.ubcs.system.wrapper.RoleWrapper;
 import lombok.AllArgsConstructor;
+import org.springblade.core.log.annotation.GrantLog;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.constant.BladeConstant;
 import org.springblade.core.tool.constant.RoleConstant;
 import org.springblade.core.tool.node.ForestNodeMerger;
+import org.springblade.core.tool.node.TreeNode;
 import org.springblade.core.tool.utils.CollectionUtil;
 import org.springblade.core.tool.utils.Func;
 import com.vci.ubcs.system.entity.Role;
 import com.vci.ubcs.system.entity.RoleMenu;
 import com.vci.ubcs.system.entity.RoleScope;
 import com.vci.ubcs.system.vo.RoleVO;
+import org.springblade.core.tool.utils.StringUtil;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
@@ -64,6 +70,7 @@
 
 	private final IRoleMenuService roleMenuService;
 	private final IRoleScopeService roleScopeService;
+	private final IMenuService menuService;
 
 	@Override
 	public IPage<RoleVO> selectRolePage(IPage<RoleVO> page, RoleVO role) {
@@ -91,6 +98,32 @@
 	@Transactional(rollbackFor = Exception.class)
 	public boolean grant(@NotEmpty List<Long> roleIds, List<Long> menuIds, List<Long> dataScopeIds, List<Long> apiScopeIds) {
 		return grantRoleMenu(roleIds, menuIds) && grantDataScope(roleIds, dataScopeIds) && grantApiScope(roleIds, apiScopeIds);
+	}
+
+	/**
+	 * 瑙掕壊鏉冮檺閰嶇疆鏃ュ織璁板綍
+	 * @param roleRes
+	 * @return
+	 */
+	@Override
+	@GrantLog("grantRole")
+	public boolean grantLog(String roleRes, boolean isException) {
+
+		return false;
+	}
+
+	/**
+	 * 鑾峰彇瑙掕壊鎺堟潈鏃ュ織鐨勪俊鎭�
+	 * @param roleId
+	 * @return
+	 */
+	@Override
+	public String getGrantRoleResString(List<Long> roleId) {
+		// 鑾峰彇鍒拌彍鍗曚俊鎭紝鍐嶈幏鍙栧埌瑙掕壊淇℃伅锛岃繘琛屾嫾鎺�
+		List<TreeNode> menuTree = menuService.grantTreeByRoleIds(roleId);
+		List<String> roleNames = this.baseMapper.getRoleNames(new Long[]{roleId.get(0)});
+		String res = roleNames.get(0) + "鎺堟潈涓�:{" + JSON.toJSONString(menuTree)+"}";
+		return res;
 	}
 
 	private boolean grantRoleMenu(List<Long> roleIds, List<Long> menuIds) {
@@ -196,8 +229,11 @@
 			}
 		}
 		if (Func.isEmpty(role.getParentId())) {
-			role.setTenantId(AuthUtil.getTenantId());
 			role.setParentId(BladeConstant.TOP_PARENT_ID);
+			// 鍓嶇浼犱簡鏄睘浜庨偅涓鎴穒d涓嬬殑瑙掕壊
+			if(Func.isEmpty(role.getTenantId())){
+				role.setTenantId(AuthUtil.getTenantId());
+			}
 		}
 		if (role.getParentId() > 0) {
 			Role parent = getById(role.getParentId());

--
Gitblit v1.9.3