From e8117601cc8bead7f4343313ce8510cc2992c7d9 Mon Sep 17 00:00:00 2001 From: youahng <2998465706@qq.com> Date: Mon, 12 Aug 2024 10:20:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/constant/ViewContentTypeEnum.java | 59 ++++++++++++++----- .../mapper/resource/ResourcesRepository.java | 2 +- .../model/dto/resource/ResourceUploadDto.java | 3 + .../model/entity/resource/Resources.java | 4 ++ .../impl/resource/ResourceServiceImpl.java | 1 + .../teaching/backend/utils/MinioUtils.java | 1 + 6 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/teaching/backend/constant/ViewContentTypeEnum.java b/src/main/java/com/teaching/backend/constant/ViewContentTypeEnum.java index cb5b6b2..8532b7d 100644 --- a/src/main/java/com/teaching/backend/constant/ViewContentTypeEnum.java +++ b/src/main/java/com/teaching/backend/constant/ViewContentTypeEnum.java @@ -1,5 +1,6 @@ package com.teaching.backend.constant; +import io.swagger.models.auth.In; import org.apache.commons.lang3.StringUtils; import java.util.HashMap; @@ -11,24 +12,25 @@ import java.util.Map; * @Description: */ public enum ViewContentTypeEnum { - DEFAULT("default","application/octet-stream"), - PNG("png", "image/png"), - JPEG("jpeg", "image/jpeg"), - JPG("jpg", "image/jpeg"), - GIF("gif", "image/gif"), - WBMP("wbmp", "image/vnd.wap.wbmp"), - TIFF("tiff", "image/tiff"), - JFIF("jfif", "image/jpeg"), - TIF("tif", "image/tiff"), - FAX("fax", "image/fax"), - JPE("jpe", "image/jpeg"), - NET("net", "image/pnetvue"), - RP("rp", "image/vnd.rn-realpix"), - ICO("ico", "image/x-icon"); + DEFAULT("default","application/octet-stream",0), + PNG("png", "image/png",1), + JPEG("jpeg", "image/jpeg",2), + JPG("jpg", "image/jpeg",3), + GIF("gif", "image/gif",4), + WBMP("wbmp", "image/vnd.wap.wbmp", 5), + TIFF("tiff", "image/tiff", 6), + JFIF("jfif", "image/jpeg", 7), + TIF("tif", "image/tiff", 8), + FAX("fax", "image/fax", 9), + JPE("jpe", "image/jpeg", 10), + NET("net", "image/pnetvue", 11), + RP("rp", "image/vnd.rn-realpix", 12), + ICO("ico", "image/x-icon", 13); private String prefix; private String type; + private Integer num; private static final Map ENUM_MAP = new HashMap<>(); @@ -59,9 +61,10 @@ public enum ViewContentTypeEnum { return DEFAULT.getType(); } - ViewContentTypeEnum(String prefix, String type) { + ViewContentTypeEnum(String prefix, String type, int num) { this.prefix = prefix; this.type = type; + this.num = num; } public String getPrefix() { @@ -71,4 +74,30 @@ public enum ViewContentTypeEnum { public String getType() { return type; } + public Integer getNum() { + return num; + } + + public static Integer getNumByPrefix(String prefix) { + ViewContentTypeEnum viewContentTypeEnum = ENUM_MAP.get(prefix); + if (viewContentTypeEnum == null) { + return 0; + } + return viewContentTypeEnum.getNum(); + } + + + public static Integer getNumByName(String prefix) { + if(StringUtils.isEmpty(prefix)){ + return DEFAULT.getNum(); + } + prefix = prefix.substring(prefix.lastIndexOf(".") + 1); + Integer num = getNumByPrefix(prefix); + if (num != null) { + return num; + } + return DEFAULT.getNum(); + } + + } diff --git a/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java b/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java index 94889d6..ec4ad2e 100644 --- a/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java +++ b/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java @@ -42,7 +42,7 @@ public interface ResourcesRepository extends Neo4jRepository { Set queryResourcesByChapterId(Long chapterId); //查询二级节点下资源 - @Query("MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m") + @Query("MATCh (p:Know)-[*0..1]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m") Set queryBesidesKnowToResources(Long KnowId); diff --git a/src/main/java/com/teaching/backend/model/dto/resource/ResourceUploadDto.java b/src/main/java/com/teaching/backend/model/dto/resource/ResourceUploadDto.java index 0fd2f4d..9f669ef 100644 --- a/src/main/java/com/teaching/backend/model/dto/resource/ResourceUploadDto.java +++ b/src/main/java/com/teaching/backend/model/dto/resource/ResourceUploadDto.java @@ -18,5 +18,8 @@ public class ResourceUploadDto { private String name; + private Integer num; + + private String objectName; } diff --git a/src/main/java/com/teaching/backend/model/entity/resource/Resources.java b/src/main/java/com/teaching/backend/model/entity/resource/Resources.java index c2cc9bb..ab33fdb 100644 --- a/src/main/java/com/teaching/backend/model/entity/resource/Resources.java +++ b/src/main/java/com/teaching/backend/model/entity/resource/Resources.java @@ -25,6 +25,10 @@ public class Resources { @Property private Integer status; + @Property + private Integer type; + + @Property private String url; } diff --git a/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java index dbfd340..d49c716 100644 --- a/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java @@ -78,6 +78,7 @@ public class ResourceServiceImpl implements ResourceService { //添加到图数据库中 Resources resource = new Resources(); + resource.setType(resourceUploadDto.getNum()); resource.setName(objectName); resource.setStatus(0); resource.setUrl(url); diff --git a/src/main/java/com/teaching/backend/utils/MinioUtils.java b/src/main/java/com/teaching/backend/utils/MinioUtils.java index df7188c..e2d4671 100644 --- a/src/main/java/com/teaching/backend/utils/MinioUtils.java +++ b/src/main/java/com/teaching/backend/utils/MinioUtils.java @@ -92,6 +92,7 @@ public class MinioUtils { minioUploadDto.setName(filename); minioUploadDto.setUrl(ENDPOINT + "/" + BUCKET_NAME + "/" + objectName); minioUploadDto.setObjectName(objectName); + minioUploadDto.setNum(ViewContentTypeEnum.DEFAULT.getNumByName(objectName)); } catch (Exception e) { e.printStackTrace(); LOGGER.info("上传发生错误: {}!", e.getMessage());