Jelajahi Sumber

优化文件模型字段

woody 1 tahun lalu
induk
melakukan
76fc3d2237

+ 5 - 0
framework-common/src/main/java/com/chelvc/framework/common/model/File.java

@@ -18,6 +18,11 @@ import lombok.experimental.SuperBuilder;
 @NoArgsConstructor
 @AllArgsConstructor
 public class File implements Serializable {
+    /**
+     * 文件名称
+     */
+    private String name;
+
     /**
      * 媒体类型
      */

+ 38 - 1
framework-common/src/main/java/com/chelvc/framework/common/model/Media.java

@@ -1,5 +1,11 @@
 package com.chelvc.framework.common.model;
 
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import com.chelvc.framework.common.util.StringUtils;
 import lombok.Getter;
 
 /**
@@ -18,14 +24,45 @@ public enum Media implements Enumeration {
     /**
      * 视频
      */
-    VIDEO("视频");
+    VIDEO("视频"),
+
+    /**
+     * 普通
+     */
+    NORMAL("普通");
 
     /**
      * 媒体描述
      */
     private final String description;
 
+    /**
+     * 媒体类型枚举项键/值映射表
+     */
+    private static final Map<String, Media> MEDIAS =
+            Stream.of(Media.values()).collect(Collectors.toMap(Media::name, business -> business));
+
     Media(String description) {
         this.description = description;
     }
+
+    /**
+     * 判断指定媒体类型是否相同
+     *
+     * @param media 媒体类型
+     * @return true/false
+     */
+    public boolean matches(String media) {
+        return StringUtils.nonEmpty(media) && Objects.equals(this.name(), media);
+    }
+
+    /**
+     * 匹配指定媒体类型
+     *
+     * @param media 媒体类型
+     * @return 媒体类型枚举
+     */
+    public static Media parse(String media) {
+        return StringUtils.ifEmpty(media, MEDIAS::get);
+    }
 }