mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
添加接口树和菜单树的接口
This commit is contained in:
@@ -6,6 +6,7 @@ import eu.bitwalker.useragentutils.UserAgent;
|
||||
import eu.bitwalker.useragentutils.Version;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@UtilityClass
|
||||
public class RequestUtils {
|
||||
@@ -41,18 +42,27 @@ public class RequestUtils {
|
||||
|
||||
public static String getUa(HttpServletRequest request) {
|
||||
|
||||
UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
|
||||
Browser browser = userAgent.getBrowser();
|
||||
try {
|
||||
|
||||
String browserName = browser.getName();
|
||||
//or
|
||||
// String browserName = browser.getGroup().getName();
|
||||
Version browserVersion = userAgent.getBrowserVersion();
|
||||
String header = request.getHeader("User-Agent");
|
||||
if (StringUtils.isEmpty(header)) {
|
||||
return "";
|
||||
}
|
||||
UserAgent userAgent = UserAgent.parseUserAgentString(header);
|
||||
Browser browser = userAgent.getBrowser();
|
||||
|
||||
OperatingSystem os = userAgent.getOperatingSystem();
|
||||
String browserName = browser.getName();
|
||||
//or
|
||||
// String browserName = browser.getGroup().getName();
|
||||
Version browserVersion = userAgent.getBrowserVersion();
|
||||
|
||||
return os.getName() + " " + browserName + browserVersion.toString();
|
||||
OperatingSystem os = userAgent.getOperatingSystem();
|
||||
|
||||
return os.getName() + " " + browserName + browserVersion.toString();
|
||||
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,19 @@ public class ResourceController {
|
||||
@Autowired
|
||||
ResourceService service;
|
||||
|
||||
|
||||
|
||||
@PostMapping("/apiTree")
|
||||
@SysLog(action = "获取接口树")
|
||||
public ResourceTreeDto apiTree() {
|
||||
return this.service.apiTree();
|
||||
}
|
||||
@PostMapping("/menuTree")
|
||||
@SysLog(action = "获取菜单树")
|
||||
public ResourceTreeDto menuTree() {
|
||||
return this.service.menuTree();
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(action = "新增")
|
||||
public ResourceDto create(@RequestBody CreateResourceDto dto) {
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package cn.lihongjie.coal.dao;
|
||||
|
||||
import cn.lihongjie.coal.entity.ResourceEntity;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ResourceRepository extends BaseRepository<ResourceEntity> {
|
||||
|
||||
|
||||
@EntityGraph(attributePaths = {"children"})
|
||||
ResourceEntity findByTypeAndParentIsNull(String type);
|
||||
}
|
||||
11
src/main/java/cn/lihongjie/coal/dto/ResourceTreeDto.java
Normal file
11
src/main/java/cn/lihongjie/coal/dto/ResourceTreeDto.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ResourceTreeDto extends ResourceDto {
|
||||
|
||||
private List<ResourceTreeDto> children;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class ResourceEntity extends CommonEntity {
|
||||
|
||||
public void addChildren(ResourceEntity newRs) {
|
||||
|
||||
log.info("addChildren1 {} {}", this.getUrl(), newRs.getUrl());
|
||||
// log.info("addChildren1 {} {}", this.getUrl(), newRs.getUrl());
|
||||
if (this.children == null) {
|
||||
this.children = new ArrayList<>();
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class ResourceEntity extends CommonEntity {
|
||||
|
||||
|
||||
this.children.add(r);
|
||||
log.info("addChildren2 {} {}", r.getUrl(), this.getUrl());
|
||||
// log.info("addChildren2 {} {}", r.getUrl(), this.getUrl());
|
||||
|
||||
r.addChildren(newRs);
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package cn.lihongjie.coal.entity.base;
|
||||
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.entity.OrganizationEntity;
|
||||
import cn.lihongjie.coal.entity.base.CommonEntity;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hibernate.annotations.Filter;
|
||||
import org.hibernate.annotations.FilterDef;
|
||||
import org.hibernate.annotations.ParamDef;
|
||||
|
||||
@MappedSuperclass
|
||||
@Getter
|
||||
@Setter
|
||||
@FilterDef(name = "orgFilter", parameters = @ParamDef(name = "organizationId", type = String.class))
|
||||
@Filter(name = "orgFilter", condition = "organizationId = :organizationId")
|
||||
public class OrgCommonEntity extends CommonEntity {
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package cn.lihongjie.coal.mapper;
|
||||
|
||||
import cn.lihongjie.coal.dto.CreateResourceDto;
|
||||
import cn.lihongjie.coal.dto.ResourceDto;
|
||||
import cn.lihongjie.coal.dto.ResourceTreeDto;
|
||||
import cn.lihongjie.coal.dto.UpdateResourceDto;
|
||||
import cn.lihongjie.coal.entity.ResourceEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
@@ -23,4 +24,6 @@ public interface ResourceMapper {
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget ResourceEntity entity, UpdateResourceDto dto);
|
||||
|
||||
ResourceTreeDto toTreeDto(ResourceEntity byTypeAndParentIsNull);
|
||||
}
|
||||
|
||||
@@ -182,4 +182,14 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
|
||||
|
||||
return urls;
|
||||
}
|
||||
|
||||
public ResourceTreeDto menuTree() {
|
||||
|
||||
return this.mapper.toTreeDto(this.repository.findByTypeAndParentIsNull("0"));
|
||||
|
||||
}
|
||||
|
||||
public ResourceTreeDto apiTree() {
|
||||
return this.mapper.toTreeDto(this.repository.findByTypeAndParentIsNull("3"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user