dengsixing 10 месяцев назад
Родитель
Сommit
8a7f2a952a

+ 3 - 0
src/main/java/com/fdkankan/modeldemo/entity/SceneConvertLog.java

@@ -57,6 +57,9 @@ public class SceneConvertLog extends Model<SceneConvertLog> {
     @TableField("TIME_CONSUMING")
     private String timeConsuming;
 
+    @TableField("CONVERT_TYPE")
+    private String converttype;
+
 
 //    @Override
 //    protected Serializable pkVal() {

+ 72 - 61
src/main/java/com/fdkankan/modeldemo/mq/ConvertListener.java

@@ -1,5 +1,6 @@
 package com.fdkankan.modeldemo.mq;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.date.TimeInterval;
@@ -12,6 +13,7 @@ import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.modeldemo.bean.SceneEditControlsBean;
 import com.fdkankan.modeldemo.bean.SceneJsonBean;
 import com.fdkankan.modeldemo.constant.Constant;
@@ -36,10 +38,7 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.io.File;
 import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * <p>
@@ -140,13 +139,15 @@ public class ConvertListener{
         SceneConvertLog sceneConvertLog = new SceneConvertLog();
         String dataSource = null;
         String convertIngKey = null;
+        String convertType = null;
         try {
             String msg = new String(message.getBody(), StandardCharsets.UTF_8);
             log.info("msg:{}", msg);
             JSONObject jsonObject = JSON.parseObject(msg);
             stationCode = jsonObject.getString("stationCode");
             entityId = jsonObject.getString("entityId");
-            String upTimeStr = jsonObject.getString("upTime");;
+            String upTimeStr = jsonObject.getString("upTime");
+            convertType = jsonObject.getString("convertType");
             if(StrUtil.isNotEmpty(upTimeStr)){
                 upTime = DateUtil.parse(upTimeStr, DatePattern.NORM_DATETIME_PATTERN);
             }
@@ -164,73 +165,83 @@ public class ConvertListener{
             sceneConvertLog.setStationCode(stationCode);
             sceneConvertLog.setEntityId(entityId);
             sceneConvertLog.setCreateTime(new Date());
+            sceneConvertLog.setConverttype(convertType);
 
-            //校验文件是否齐全
-            boolean exists512 = fileList.stream().anyMatch(v -> {
-                JSONObject obj = (JSONObject) v;
-                return "1".equals(obj.getString("fileType"));
-            });
+            if(convertType.equals("upTime")){//只更新上传时间
+                List<Scene> list = sceneService.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, entityId).eq(Scene::getStationcode, stationCode).isNull(Scene::getUpTime));
+                if(CollUtil.isNotEmpty(list)){
+                    Date finalUpTime = upTime;
+                    list.stream().forEach(v->v.setUpTime(finalUpTime));
+                    sceneService.updateBatchById(list);
+                }
+            }else{
+                //校验文件是否齐全
+                boolean exists512 = fileList.stream().anyMatch(v -> {
+                    JSONObject obj = (JSONObject) v;
+                    return "1".equals(obj.getString("fileType"));
+                });
 
-            boolean exists4k = fileList.stream().anyMatch(v -> {
-                JSONObject obj = (JSONObject) v;
-                return "2".equals(obj.getString("fileType"));
-            });
+                boolean exists4k = fileList.stream().anyMatch(v -> {
+                    JSONObject obj = (JSONObject) v;
+                    return "2".equals(obj.getString("fileType"));
+                });
 
-            boolean exists8k = fileList.stream().anyMatch(v -> {
-                JSONObject obj = (JSONObject) v;
-                return "3".equals(obj.getString("fileType"));
-            });
+                boolean exists8k = fileList.stream().anyMatch(v -> {
+                    JSONObject obj = (JSONObject) v;
+                    return "3".equals(obj.getString("fileType"));
+                });
 
 
-            dataSource = baseZipPath + stationCode + "_" + entityId + "/";
-            String imagePath = dataSource + "images/";
-            String dataPath = dataSource + "data/";
-            String meshPath = dataPath + "mesh/";
-            String image512Path = imagePath + "512/";
-            String image4kPath = imagePath + "4k/";
-            String image8kPath = imagePath + "8k/";
-            FileUtil.mkdir(image512Path);
-            FileUtil.mkdir(image4kPath);
+                dataSource = baseZipPath + stationCode + "_" + entityId + "/";
+                String imagePath = dataSource + "images/";
+                String dataPath = dataSource + "data/";
+                String meshPath = dataPath + "mesh/";
+                String image512Path = imagePath + "512/";
+                String image4kPath = imagePath + "4k/";
+                String image8kPath = imagePath + "8k/";
+                FileUtil.mkdir(image512Path);
+                FileUtil.mkdir(image4kPath);
 
-            fileList.stream().forEach(o->{
-                JSONObject obj = (JSONObject) o;
-                String fileName = obj.getString("fileName");
-                String fileType = obj.getString("fileType");
-                String fileUrl = obj.getString("fileUrl");
-                if("7".equals(fileType)){//vision.txt
-                    HttpUtilExt.downloadFileAndCheck(fileUrl, imagePath + fileName, 300000);
-                }
-                if("1".equals(fileType)){//512图
-                    HttpUtilExt.downloadFileAndCheck(fileUrl, image512Path + fileName, 300000);
-                }
-                if("2".equals(fileType)){//4k图
-                    HttpUtilExt.downloadFileAndCheck(fileUrl, image4kPath + fileName, 300000);
-                    if(!exists512){
-                        ImgUtil.scale(new File(image4kPath + fileName), new File(image512Path + fileName), 0.125f);
+                fileList.stream().forEach(o->{
+                    JSONObject obj = (JSONObject) o;
+                    String fileName = obj.getString("fileName");
+                    String fileType = obj.getString("fileType");
+                    String fileUrl = obj.getString("fileUrl");
+                    if("7".equals(fileType)){//vision.txt
+                        HttpUtilExt.downloadFileAndCheck(fileUrl, imagePath + fileName, 300000);
                     }
-                }
-                if(!exists4k){//如果资源中没有4k,需要用8k图做一下像素压缩
-                    if("3".equals(fileType)){
-                        HttpUtilExt.downloadFileAndCheck(fileUrl, image8kPath + fileName, 30000);
-                        ImgUtil.scale(new File(image8kPath + fileName),new File(image4kPath + fileName), 0.5f);
+                    if("1".equals(fileType)){//512图
+                        HttpUtilExt.downloadFileAndCheck(fileUrl, image512Path + fileName, 300000);
+                    }
+                    if("2".equals(fileType)){//4k图
+                        HttpUtilExt.downloadFileAndCheck(fileUrl, image4kPath + fileName, 300000);
                         if(!exists512){
-                            ImgUtil.scale(new File(image8kPath + fileName),new File(image512Path + fileName), 0.0625f);
+                            ImgUtil.scale(new File(image4kPath + fileName), new File(image512Path + fileName), 0.125f);
                         }
                     }
-                }
-                if("11".equals(fileType)){//mesh.obj
-                    HttpUtilExt.downloadFileAndCheck(fileUrl, meshPath + fileName, 300000);
-                }
-                if("5".equals(fileType)){//floorplan.json
-                    HttpUtilExt.downloadFileAndCheck(fileUrl, dataPath + fileName, 300000);
-                }
-                if("12".equals(fileType)){//scene.json
-                    HttpUtilExt.downloadFileAndCheck(fileUrl, dataPath + fileName, 300000);
-                }
-            });
+                    if(!exists4k){//如果资源中没有4k,需要用8k图做一下像素压缩
+                        if("3".equals(fileType)){
+                            HttpUtilExt.downloadFileAndCheck(fileUrl, image8kPath + fileName, 30000);
+                            ImgUtil.scale(new File(image8kPath + fileName),new File(image4kPath + fileName), 0.5f);
+                            if(!exists512){
+                                ImgUtil.scale(new File(image8kPath + fileName),new File(image512Path + fileName), 0.0625f);
+                            }
+                        }
+                    }
+                    if("11".equals(fileType)){//mesh.obj
+                        HttpUtilExt.downloadFileAndCheck(fileUrl, meshPath + fileName, 300000);
+                    }
+                    if("5".equals(fileType)){//floorplan.json
+                        HttpUtilExt.downloadFileAndCheck(fileUrl, dataPath + fileName, 300000);
+                    }
+                    if("12".equals(fileType)){//scene.json
+                        HttpUtilExt.downloadFileAndCheck(fileUrl, dataPath + fileName, 300000);
+                    }
+                });
 
-            //转换并上传文件
-            convertUtil.convert(dataSource, entityId, stationCode, upTime);
+                //转换并上传文件
+                convertUtil.convert(dataSource, entityId, stationCode, upTime);
+            }
 
             sceneConvertLog.setStatus("1");
             sceneConvertLog.setTimeConsuming(String.valueOf(timeInterval.intervalSecond()));