Browse Source

:bug: Fixing a bug. 租户套餐问题

aeizzz 1 year ago
parent
commit
17218f639e

+ 0 - 5
pigx-upms/pigx-upms-biz/pom.xml

@@ -128,11 +128,6 @@
 			<artifactId>pigx-common-swagger</artifactId>
 		</dependency>
 
-
-		<dependency>
-			<groupId>com.pig4cloud</groupId>
-			<artifactId>pigx-common-datasource</artifactId>
-		</dependency>
 	</dependencies>
 
     <build>

+ 1 - 0
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ClientDetailsInitRunner.java

@@ -17,6 +17,7 @@ import org.springframework.data.redis.listener.ChannelTopic;
 import org.springframework.data.redis.listener.RedisMessageListenerContainer;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.event.TransactionalEventListener;
 
 /**
  * @author lengleng

+ 18 - 0
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysTenantMenuController.java

@@ -1,12 +1,16 @@
 package com.pig4cloud.pigx.admin.controller;
 
+import cn.hutool.core.lang.tree.Tree;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.pig4cloud.pigx.admin.api.entity.SysTenantMenu;
+import com.pig4cloud.pigx.admin.service.SysMenuService;
 import com.pig4cloud.pigx.admin.service.SysTenantMenuService;
 import com.pig4cloud.pigx.common.core.constant.CacheConstants;
 import com.pig4cloud.pigx.common.core.constant.CommonConstants;
 import com.pig4cloud.pigx.common.core.util.R;
+import com.pig4cloud.pigx.common.data.resolver.ParamResolver;
+import com.pig4cloud.pigx.common.data.tenant.TenantBroker;
 import com.pig4cloud.pigx.common.log.annotation.SysLog;
 import com.pig4cloud.pigx.common.security.annotation.Inner;
 import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -17,6 +21,7 @@ import org.springframework.http.HttpHeaders;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @RestController
@@ -28,6 +33,8 @@ public class SysTenantMenuController {
 
 	private final SysTenantMenuService sysTenantMenuService;
 
+	private final SysMenuService sysMenuService;
+
 	/**
 	 * 分页查询
 	 * @param page 分页对象
@@ -100,4 +107,15 @@ public class SysTenantMenuController {
 		return R.ok(tenants);
 	}
 
+	@GetMapping(value = "/tree/menu")
+	public R getTree() {
+		Long defaultId = ParamResolver.getLong("TENANT_DEFAULT_ID", 1L);
+		List<Tree<Long>> trees = new ArrayList<>();
+		TenantBroker.runAs(defaultId, (id) -> {
+			trees.addAll(sysMenuService.treeMenu(null, null));
+		});
+
+		return R.ok(trees);
+	}
+
 }

+ 11 - 7
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysTenantServiceImpl.java

@@ -26,6 +26,7 @@ import com.pig4cloud.pigx.admin.service.*;
 import com.pig4cloud.pigx.common.core.constant.CacheConstants;
 import com.pig4cloud.pigx.common.core.constant.CommonConstants;
 import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
+import com.pig4cloud.pigx.common.data.datascope.DataScopeTypeEnum;
 import com.pig4cloud.pigx.common.data.resolver.ParamResolver;
 import com.pig4cloud.pigx.common.data.tenant.TenantBroker;
 import lombok.AllArgsConstructor;
@@ -128,8 +129,11 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
 			dictIdList.addAll(dictList.stream().map(SysDict::getId).collect(Collectors.toList()));
 			dictItemList.addAll(
 					dictItemService.list(Wrappers.<SysDictItem>lambdaQuery().in(SysDictItem::getDictId, dictIdList)));
+			SysTenantMenu tenantMenu = sysTenantMenuService.getById(sysTenant.getMenuId());
+			String[] split = tenantMenu.getMenuIds().split(",");
+			List<SysMenu> newMenuList = menuService.list(Wrappers.<SysMenu>lambdaQuery().in(SysMenu::getMenuId, split));
 			// 查询当前租户菜单
-			menuList.addAll(menuService.list());
+			menuList.addAll(newMenuList);
 			// 查询客户端配置
 			clientDetailsList.addAll(clientServices.list());
 			// 查询系统参数配置
@@ -157,12 +161,14 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
 			SysRole roleDefault = new SysRole();
 			roleDefault.setRoleCode(userDefaultRoleCode);
 			roleDefault.setRoleName(userDefaultRoleName);
+			roleDefault.setDsType(DataScopeTypeEnum.SELF_LEVEL.getType());
 			roleService.save(roleDefault);
 
 			// 构造新角色 管理员角色
 			SysRole role = new SysRole();
 			role.setRoleCode(defaultRoleCode);
 			role.setRoleName(defaultRoleName);
+			role.setDsType(DataScopeTypeEnum.ALL.getType());
 			roleService.save(role);
 			// 用户角色关系
 			SysUserRole userRole = new SysUserRole();
@@ -172,19 +178,17 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
 			// 插入新的菜单
 			saveTenantMenu(menuList, CommonConstants.MENU_TREE_ROOT_ID, CommonConstants.MENU_TREE_ROOT_ID);
 
-			SysTenantMenu tenantMenu = sysTenantMenuService.getById(sysTenant.getMenuId());
-
-			List<SysMenu> newMenuList = menuService
-					.list(Wrappers.<SysMenu>lambdaQuery().in(SysMenu::getMenuId, tenantMenu.getMenuIds()));
+			// 重新查询出所有的菜单关联角色
+			List<SysMenu> list = menuService.list();
 
 			// 查询全部菜单,构造角色菜单关系
-			List<SysRoleMenu> roleMenuList = newMenuList.stream().map(menu -> {
+			List<SysRoleMenu> roleMenuList = list.stream().map(menu -> {
 				SysRoleMenu roleMenu = new SysRoleMenu();
 				roleMenu.setRoleId(role.getRoleId());
 				roleMenu.setMenuId(menu.getMenuId());
 				return roleMenu;
 			}).collect(Collectors.toList());
-			roleMenuList.forEach(ele -> roleMenuMapper.insert(ele));
+			roleMenuList.forEach(roleMenuMapper::insert);
 			// 插入系统字典
 			dictService.saveBatch(dictList.stream().peek(d -> d.setId(null)).collect(Collectors.toList()));
 			// 处理字典项最新关联的字典ID