|
@@ -7,6 +7,7 @@ import java.time.ZoneOffset;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
@@ -28,6 +29,7 @@ import com.zkqy.system.domain.SysTenantMenu;
|
|
|
import com.zkqy.system.mapper.*;
|
|
|
import com.zkqy.system.service.ISysUserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.core.io.Resource;
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
@@ -200,9 +202,11 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
// module.addDeserializer(Date.class, new CustomDateDeserializer());
|
|
|
// objectMapper.registerModule(module);
|
|
|
try {
|
|
|
- Resource resource = resourceLoader.getResource("classpath:sql/initialize_sys_tenant_menu.json");
|
|
|
+ //这个东西在部署环境下会出现问题
|
|
|
+// Resource resource = resourceLoader.getResource("classpath:sql/initialize_sys_tenant_menu.json");
|
|
|
+ Resource resource = new ClassPathResource("sql/initialize_sys_tenant_menu.json");
|
|
|
//获取租户默认菜单信息
|
|
|
- List<SysMenu> menus = objectMapper.readValue(resource.getFile(), objectMapper.getTypeFactory().constructCollectionType(List.class, SysMenu.class));
|
|
|
+ List<SysMenu> menus = objectMapper.readValue(resource.getInputStream(), objectMapper.getTypeFactory().constructCollectionType(List.class, SysMenu.class));
|
|
|
//字符串备用方案
|
|
|
//List<SysMenu> menus = JSON.parseObject(ass, new TypeReference<List<SysMenu>>() {});
|
|
|
// int a=10/0;
|
|
@@ -360,6 +364,69 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
return sysTenantMapper.selectTenantTree(tenantId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> selectCodeTenantAllList() {
|
|
|
+/* {
|
|
|
+ id: 1,
|
|
|
+ label: 'a',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ id: 4,
|
|
|
+ label: 'aa',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ id: 6,
|
|
|
+ label: 'aaa',
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ },*/
|
|
|
+ List<SysTenant> sysTenants = sysTenantMapper.selectCodeSysTenantList();
|
|
|
+ List<Map<String, Object>> maps = this.buildTree(sysTenants);
|
|
|
+ return maps;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Map<String, Object>> buildTree(List<SysTenant> sysTenants) {
|
|
|
+ // 构造一个Map,方便根据tenantId查找SysTenant
|
|
|
+ Map<Long, SysTenant> tenantMap = sysTenants.stream()
|
|
|
+ .collect(Collectors.toMap(SysTenant::getTenantId, Function.identity()));
|
|
|
+ // 获取所有父节点
|
|
|
+ List<Map<String, Object>> parentNodes = sysTenants.stream()
|
|
|
+ .filter(m -> m.getTenantParentId().equals("0"))
|
|
|
+ .map(sysTenant -> {
|
|
|
+ Map<String, Object> node = new HashMap<>();
|
|
|
+ node.put("id", sysTenant.getTenantId());
|
|
|
+ node.put("label", sysTenant.getTenantName());
|
|
|
+ // 递归查找子节点
|
|
|
+ List<Map<String, Object>> children = findChildren(sysTenant.getTenantId(), tenantMap);
|
|
|
+ if (!children.isEmpty()) {
|
|
|
+ node.put("children", children);
|
|
|
+ }
|
|
|
+ return node;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return parentNodes;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> findChildren(Long parentId, Map<Long, SysTenant> tenantMap) {
|
|
|
+ return tenantMap.values().stream()
|
|
|
+ .filter(child -> child.getTenantParentId().equals(parentId.toString()))
|
|
|
+ .map(child -> {
|
|
|
+ Map<String, Object> childNode = new HashMap<>();
|
|
|
+ childNode.put("id", child.getTenantId());
|
|
|
+ childNode.put("label", child.getTenantName());
|
|
|
+ // 递归查找孙子节点
|
|
|
+ List<Map<String, Object>> grandchildren = findChildren(child.getTenantId(), tenantMap);
|
|
|
+ if (!grandchildren.isEmpty()) {
|
|
|
+ childNode.put("children", grandchildren);
|
|
|
+ }
|
|
|
+ return childNode;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 从当前时间往后续期租户时间
|
|
|
*
|