mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善
This commit is contained in:
@@ -24,7 +24,7 @@ public class ResourceEntity extends CommonEntity {
|
||||
private ResourceEntity parent;
|
||||
|
||||
|
||||
@Comment("资源类型")
|
||||
@Comment("资源类型 0 菜单 1 按钮 3 url")
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
@@ -2,10 +2,7 @@ package cn.lihongjie.coal.runner;
|
||||
|
||||
import cn.lihongjie.coal.entity.OrganizationEntity;
|
||||
import cn.lihongjie.coal.entity.UserEntity;
|
||||
import cn.lihongjie.coal.service.CoalParameterDefService;
|
||||
import cn.lihongjie.coal.service.OrganizationService;
|
||||
import cn.lihongjie.coal.service.SessionService;
|
||||
import cn.lihongjie.coal.service.UserService;
|
||||
import cn.lihongjie.coal.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
@@ -27,6 +24,8 @@ public class InitDataRunner implements CommandLineRunner {
|
||||
@Autowired
|
||||
CoalParameterDefService coalParameterDefService;
|
||||
|
||||
@Autowired
|
||||
ResourceService resourceService;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
@@ -48,6 +47,8 @@ public class InitDataRunner implements CommandLineRunner {
|
||||
|
||||
coalParameterDefService.initDefault();
|
||||
|
||||
// resourceService.initUrlResource();
|
||||
|
||||
} finally {
|
||||
SecurityContextHolder.clearContext();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -17,8 +18,16 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
import org.springframework.web.util.pattern.PathPattern;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -97,4 +106,38 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
|
||||
}).stream().findFirst();
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
RequestMappingHandlerMapping requestMappingHandlerMapping;
|
||||
|
||||
public void initUrlResource(){
|
||||
|
||||
List<ResourceEntity> all = findAll().stream().filter(x -> StringUtils.equals(x.getType(), "3")).toList();
|
||||
|
||||
Map<String, ResourceEntity> map = all.stream().collect(Collectors.toMap(e -> e.getCode(), e -> e));
|
||||
|
||||
|
||||
getAllUrls();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void getAllUrls() {
|
||||
Map<RequestMappingInfo, HandlerMethod> handlerMethods = requestMappingHandlerMapping.getHandlerMethods();
|
||||
List<String> urls = new ArrayList<>();
|
||||
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : handlerMethods.entrySet()) {
|
||||
|
||||
|
||||
RequestMappingInfo info = entry.getKey();
|
||||
HandlerMethod method = entry.getValue();
|
||||
if (!method.getMethod().getDeclaringClass().getCanonicalName().startsWith("cn.lihongjie")) {
|
||||
continue;
|
||||
}
|
||||
for (PathPattern pattern : info.getPathPatternsCondition().getPatterns()) {
|
||||
String ps = pattern.getPatternString();
|
||||
urls.add(ps);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user