Explorar o código

后端校验视频素材重复

songyh %!s(int64=3) %!d(string=hai) anos
pai
achega
5ff8ed17a7

+ 2 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/IMaterialInfoService.java

@@ -84,4 +84,6 @@ public interface IMaterialInfoService extends IService<MaterialInfo> {
     Map<String, Object> getListByParams(String tagCode, String type, Integer status, String materialName, List<Long> projectIds, String code, String startDate, String endDate, String userId, String clipId, String shotId, String planId, String leaderName,Integer offlineFlag, Integer pageNo, Integer pageSize);
 
     void correlationUploadV2(JSONObject json);
+
+    JSONArray checkArrayCode(JSONArray array);
 }

+ 25 - 8
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java

@@ -455,7 +455,6 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
                         e.printStackTrace();
                     } catch (EncoderException e) {
                         e.printStackTrace();
-
                     } finally {
                         try {
                             if (fis != null) {
@@ -467,8 +466,6 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
                     }
                 }
             }
-
-
         });
     }
 
@@ -507,15 +504,13 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
         Map<String, Object> resultMap = new HashMap<>();
         try {
             String type = json.getString("type");
-            String url = "";
-            if (!Check.isNull(json.getString("url"))) {
-                url = "https:" + json.getString("url");
-            }
+            String url = json.getString("url");
+            String code = json.getString("code");
             MaterialInfo info = new MaterialInfo();
             Long projectId = json.getLong("projectId");
             Project project = projectService.getById(projectId);
             Long productId = project.getProductId();
-            String code = MD5Util.md5ByUrl(url);
+
             info.setId(UUID.randomUUID().toString().replace("-", ""));
             info.setCode(code);
             if (!Check.isNull(json.getString("watermarkUrl"))) {
@@ -621,6 +616,28 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
         }
     }
 
+    @Override
+    public JSONArray checkArrayCode(JSONArray array) {
+        if(null == array||array.isEmpty()){
+            return new JSONArray();
+        }
+        Map<String,String> codeMap = new HashMap<>();
+        JSONArray resultArray = new JSONArray();
+        for(int i=0;i<array.size();i++){
+            JSONObject data = array.getJSONObject(i);
+            String url = "https:"+data.getString("url");
+            data.put("url",url);
+            String code = MD5Util.md5ByUrl(url);
+            if(codeMap.containsKey(code)){
+                continue;
+            }
+            codeMap.put(code,code);
+            data.put("code",code);
+            resultArray.add(data);
+        }
+        return resultArray;
+    }
+
     /**
      * 素材库关联上传素材 1
      *

+ 3 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/fileupload/controller/FileController.java

@@ -55,7 +55,9 @@ public class FileController {
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         Long projectId = data.getLong("projectId");
         JSONArray array = data.getJSONArray("videoArray");
-        if(null!=array&&!array.isEmpty()){
+        //校验重复code逻辑
+        JSONArray checkArray = materialInfoService.checkArrayCode(array);
+        if(null!=checkArray&&!checkArray.isEmpty()){
             for (int i=0;i<array.size();i++){
                 JSONObject json = array.getJSONObject(i);
                 json.put("userId", user.getId());