资源更新02

master
youahng 4 months ago committed by yh
parent 77fed5d052
commit 7bb85618a6
  1. 81
      src/main/java/com/teaching/backend/constant/TypeEnum.java
  2. 3
      src/main/java/com/teaching/backend/model/dto/resource/ResourceUploadDto.java
  3. 2
      src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java
  4. 3
      src/main/java/com/teaching/backend/utils/MinioUtils.java

@ -0,0 +1,81 @@
package com.teaching.backend.constant;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* @Author:youhang
* @Date:2024-08-07-9:14
* @Description:
*/
public enum TypeEnum {
DEFAULT("default",0),
PNG("png", 1),
JPEG("jpeg", 2),
JPG("jpg", 3),
GIF("gif", 4),
DOCX("docx", 5),
PDF("pdf", 6),
MD("md", 7),
XLSX("xlsx", 8),
TXT("txt", 9),
WBMP("wbmp", 10),
TIFF("tiff", 11),
JFIF("jfif", 12),
TIF("tif", 13),
FAX("fax", 14),
JPE("jpe", 15),
NET("net", 16),
RP("rp", 17),
ICO("ico", 18),
MP4("mp4", 19);
private String prefix;
private Integer type;
private static final Map<String, TypeEnum> ENUM_MAP = new HashMap<>();
static {
TypeEnum[] values = values();
for (TypeEnum value : values) {
ENUM_MAP.put(value.getPrefix(), value);
}
}
TypeEnum(String prefix, Integer type) {
this.prefix = prefix;
this.type = type;
}
public String getPrefix() {
return prefix;
}
public Integer getType() {
return type;
}
public static Integer getTypeByPrefix(String prefix) {
if(StringUtils.isEmpty(prefix)){
return DEFAULT.getType();
}
prefix = prefix.substring(prefix.lastIndexOf(".") + 1);
TypeEnum viewContentTypeEnum = ENUM_MAP.get(prefix);
if (viewContentTypeEnum == null) {
return DEFAULT.getType();
}
Integer type = viewContentTypeEnum.getType();
if (type != null) {
return type;
}
return DEFAULT.getType();
}
}

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

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

@ -5,6 +5,7 @@ import cn.hutool.json.JSONUtil;
import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode; import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils; import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.constant.TypeEnum;
import com.teaching.backend.constant.ViewContentTypeEnum; import com.teaching.backend.constant.ViewContentTypeEnum;
import com.teaching.backend.model.dto.resource.BucketPolicyConfigDto; import com.teaching.backend.model.dto.resource.BucketPolicyConfigDto;
import com.teaching.backend.model.dto.resource.ResourceUploadDto; import com.teaching.backend.model.dto.resource.ResourceUploadDto;
@ -92,7 +93,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)); minioUploadDto.setType(TypeEnum.getTypeByPrefix(objectName));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
LOGGER.info("上传发生错误: {}!", e.getMessage()); LOGGER.info("上传发生错误: {}!", e.getMessage());

Loading…
Cancel
Save