Bläddra i källkod

修改素材库文件上传逻辑

songyh 4 år sedan
förälder
incheckning
0dd9be99c7

+ 33 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MD5Util.java

@@ -3,6 +3,10 @@ package org.jeecg.common.util;
 import org.springframework.util.DigestUtils;
 
 import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 
@@ -30,6 +34,35 @@ public class MD5Util {
 		return String.valueOf(str);
 	}
 
+	public static String md5ByUrl(String imgUrl){
+		String md5 = "";
+		InputStream inputStream = null;
+		try {
+			//url路径
+			URL url=new URL(imgUrl);
+			//获取连接
+			HttpURLConnection connection=(HttpURLConnection)url.openConnection();
+			connection.setConnectTimeout(3*1000);
+			//设置请求头
+			connection.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36");
+			inputStream = connection.getInputStream();
+			//DigestUtils为org.apache.commons.codec.digest.DigestUtils下的类
+			md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(inputStream);
+		} catch (IOException e) {
+			e.printStackTrace();
+		} finally{
+			try {
+				if (inputStream != null) {
+					//关闭流
+					inputStream.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return  md5;
+	}
+
 	public static String getMd5(String url) {
 		MessageDigest md5 = MD5.get();
 		md5.reset();

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

@@ -82,4 +82,6 @@ public interface IMaterialInfoService extends IService<MaterialInfo> {
     JSONArray getIdListByProject(Long projectId);
 
     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);
 }

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

@@ -24,6 +24,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.system.entity.SysUser;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.MD5Util;
 import org.jeecg.common.util.encryption.AesEncryptUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -501,6 +502,126 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
      * @return
      */
     @Override
+    public void correlationUploadV2(JSONObject json) {
+        String userId = json.getString("userId");
+        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");
+            }
+            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"))) {
+                info.setWatermarkUrl(json.getString("watermarkUrl"));
+            }
+            info.setUrl(url);
+            info.setUserId(userId);
+            info.setProjectId(projectId);
+            info.setProductId(productId);
+            info.setWatermarkCode(json.getString("watermarkCode"));
+            info.setStatus(0);
+            info.setMaterialName(StringUtils.getFileNameNoEx(json.getString("materialName")));
+            info.setWatermarkMaterialName(json.getString("watermarkMaterialName"));
+            info.setMaterialDescribe(json.getString("materialDescribe"));
+            info.setCreateTime(new Date());
+            info.setUpdateTime(new Date());
+            info.setType(type);
+
+            if (!Check.isNull(project.getSupplierCode())) {
+                info.setSupplierCode(project.getSupplierCode());
+            }
+
+            MaterialCutFrame cutFrame = materialCutFrameService.getCutFrameByCode(code);
+            if (Check.isNull(cutFrame)) {
+                String videoUrl = URLDecoder.decode(info.getUrl()).replace("https://media-1301855440.cos.ap-chongqing.myqcloud.com/", "");
+                String loadImage = "cutFrame/" + code + "/zero.jpg";
+                String coverUrl = CloudVideoProcessUtil.videoCutPictureHandle(videoUrl, loadImage);
+                info.setCoverUrl(coverUrl);
+                Thread thread = new Thread() {
+                    @Override
+                    public void run() {
+                        try {
+                            log.info("开始抽帧,code:{}", code);
+                            materialCutFrameService.getTencentCutFrame(videoUrl, code, coverUrl);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                };
+                thread.start();
+            } else {
+                info.setCoverUrl(cutFrame.getUrl());
+            }
+            this.save(info);
+            JSONArray imageArr = json.getJSONArray("imageArr");
+            if (!Check.isNull(imageArr)) {
+                JSONObject imageJson = new JSONObject();
+                imageJson.put("videoId", info.getCode());
+                imageJson.put("userId", userId);
+                imageJson.put("imageArr", imageArr);
+                materialImageInfoService.insertImage(imageJson);
+            }
+            Map<String, Object> deleteMap = new HashMap<>();
+            deleteMap.put("material_id", info.getCode());
+            JSONObject ascription = json.getJSONObject("ascription");
+            if (!Check.isNull(ascription)) {
+                MaterialAscription materialAscription = new MaterialAscription();
+                materialAscription.setMaterialId(info.getCode());
+                String clipId = ascription.getString("clipId");
+                if (null != clipId && !"".equals(clipId.trim())) {
+                    materialAscription.setClipId(clipId);
+                }
+                materialAscription.setShotId(ascription.getString("shotId"));
+                materialAscription.setPlanId(ascription.getString("planId"));
+                materialAscription.setPlaneId(ascription.getString("planeId"));
+                materialAscription.setCode(info.getCode());
+                materialAscriptionMapper.deleteByMap(deleteMap);
+                //TODO 需要添加获取设计负责人代码
+                SysUser clip = userService.getById(clipId);
+                String roleCode = userService.getRoleCodeByUserId(clipId);
+                if("designTeamLeader".equals(roleCode)){
+                    materialAscription.setLeaderId(clipId);
+                    materialAscription.setLeaderName(clip.getRealname());
+                }else{
+                    materialAscription.setLeaderId(clip.getLeaderId());
+                    materialAscription.setLeaderName(clip.getLeaderName());
+                }
+                int result = materialAscriptionMapper.insert(materialAscription);
+                if (result > 0) {
+                    log.info("素材归属信息入库完成,MaterialId:{}", info.getId());
+                }
+            }
+            materialTagInfoService.deleteByCode(code);
+            JSONArray modalityTagList = json.getJSONArray("modalityTagList");
+            insertTagList(code, userId, modalityTagList);
+            JSONArray contentTagList = json.getJSONArray("contentTagList");
+            insertTagList(code, userId, contentTagList);
+            JSONArray senceTagList = json.getJSONArray("senceTagList");
+            insertTagList(code, userId, senceTagList);
+            JSONArray modTagList = json.getJSONArray("modTagList");
+            insertTagList(code, userId, modTagList);
+            getFile(info);
+            ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
+        } catch (Exception e) {
+            ResultMapUtils.setResultMap(resultMap, StatusCode.MATERIAL_UPLOAD_FAIL.getCode());
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 素材库关联上传素材 1
+     *
+     * @param json
+     * @return
+     */
+    @Override
     public Map<String, Object> correlationUpload(JSONObject json) {
         String userId = json.getString("userId");
         Map<String, Object> resultMap = new HashMap<>();

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

@@ -41,7 +41,7 @@ public class FileController {
     public Map<String, Object> imageCheck(String code, String videoId) {
         return materialImageInfoService.checkMaterialInfo(code, videoId);
     }
-    
+
     @PostMapping("/insertV2")
     public Map<String, Object> insertV2(@RequestBody JSONObject json) {
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
@@ -50,14 +50,17 @@ public class FileController {
     }
 
     @PostMapping("/insertV3")
-    public Map<String, Object> insertV3(@RequestBody JSONArray array) {
+    public Map<String, Object> insertV3(@RequestBody JSONObject data) {
         Map<String,Object>result = new HashMap<>();
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        Long projectId = data.getLong("projectId");
+        JSONArray array = data.getJSONArray("videoArray");
         if(null!=array&&!array.isEmpty()){
             for (int i=0;i<array.size();i++){
                 JSONObject json = array.getJSONObject(i);
                 json.put("userId", user.getId());
-                materialInfoService.correlationUpload(json);
+                json.put("projectId",projectId);
+                materialInfoService.correlationUploadV2(json);
             }
         }
         ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);