资源更新

master
youahng 3 months ago committed by yh
parent 2a42c9de00
commit e8117601cc
  1. 59
      src/main/java/com/teaching/backend/constant/ViewContentTypeEnum.java
  2. 2
      src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java
  3. 3
      src/main/java/com/teaching/backend/model/dto/resource/ResourceUploadDto.java
  4. 4
      src/main/java/com/teaching/backend/model/entity/resource/Resources.java
  5. 1
      src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java
  6. 1
      src/main/java/com/teaching/backend/utils/MinioUtils.java

@ -1,5 +1,6 @@
package com.teaching.backend.constant; package com.teaching.backend.constant;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.HashMap; import java.util.HashMap;
@ -11,24 +12,25 @@ import java.util.Map;
* @Description: * @Description:
*/ */
public enum ViewContentTypeEnum { public enum ViewContentTypeEnum {
DEFAULT("default","application/octet-stream"), DEFAULT("default","application/octet-stream",0),
PNG("png", "image/png"), PNG("png", "image/png",1),
JPEG("jpeg", "image/jpeg"), JPEG("jpeg", "image/jpeg",2),
JPG("jpg", "image/jpeg"), JPG("jpg", "image/jpeg",3),
GIF("gif", "image/gif"), GIF("gif", "image/gif",4),
WBMP("wbmp", "image/vnd.wap.wbmp"), WBMP("wbmp", "image/vnd.wap.wbmp", 5),
TIFF("tiff", "image/tiff"), TIFF("tiff", "image/tiff", 6),
JFIF("jfif", "image/jpeg"), JFIF("jfif", "image/jpeg", 7),
TIF("tif", "image/tiff"), TIF("tif", "image/tiff", 8),
FAX("fax", "image/fax"), FAX("fax", "image/fax", 9),
JPE("jpe", "image/jpeg"), JPE("jpe", "image/jpeg", 10),
NET("net", "image/pnetvue"), NET("net", "image/pnetvue", 11),
RP("rp", "image/vnd.rn-realpix"), RP("rp", "image/vnd.rn-realpix", 12),
ICO("ico", "image/x-icon"); ICO("ico", "image/x-icon", 13);
private String prefix; private String prefix;
private String type; private String type;
private Integer num;
private static final Map<String, ViewContentTypeEnum> ENUM_MAP = new HashMap<>(); private static final Map<String, ViewContentTypeEnum> ENUM_MAP = new HashMap<>();
@ -59,9 +61,10 @@ public enum ViewContentTypeEnum {
return DEFAULT.getType(); return DEFAULT.getType();
} }
ViewContentTypeEnum(String prefix, String type) { ViewContentTypeEnum(String prefix, String type, int num) {
this.prefix = prefix; this.prefix = prefix;
this.type = type; this.type = type;
this.num = num;
} }
public String getPrefix() { public String getPrefix() {
@ -71,4 +74,30 @@ public enum ViewContentTypeEnum {
public String getType() { public String getType() {
return type; 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();
}
} }

@ -42,7 +42,7 @@ public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
Set<Resources> queryResourcesByChapterId(Long chapterId); Set<Resources> 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<Resources> queryBesidesKnowToResources(Long KnowId); Set<Resources> queryBesidesKnowToResources(Long KnowId);

@ -18,5 +18,8 @@ public class ResourceUploadDto {
private String name; private String name;
private Integer num;
private String objectName; private String objectName;
} }

@ -25,6 +25,10 @@ public class Resources {
@Property @Property
private Integer status; private Integer status;
@Property
private Integer type;
@Property @Property
private String url; private String url;
} }

@ -78,6 +78,7 @@ public class ResourceServiceImpl implements ResourceService {
//添加到图数据库中 //添加到图数据库中
Resources resource = new Resources(); Resources resource = new Resources();
resource.setType(resourceUploadDto.getNum());
resource.setName(objectName); resource.setName(objectName);
resource.setStatus(0); resource.setStatus(0);
resource.setUrl(url); resource.setUrl(url);

@ -92,6 +92,7 @@ public class MinioUtils {
minioUploadDto.setName(filename); minioUploadDto.setName(filename);
minioUploadDto.setUrl(ENDPOINT + "/" + BUCKET_NAME + "/" + objectName); minioUploadDto.setUrl(ENDPOINT + "/" + BUCKET_NAME + "/" + objectName);
minioUploadDto.setObjectName(objectName); minioUploadDto.setObjectName(objectName);
minioUploadDto.setNum(ViewContentTypeEnum.DEFAULT.getNumByName(objectName));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
LOGGER.info("上传发生错误: {}!", e.getMessage()); LOGGER.info("上传发生错误: {}!", e.getMessage());

Loading…
Cancel
Save