xiewj 6 ماه پیش
والد
کامیت
1ab927b227

+ 14 - 19
720yun_fd_consumer/gis_consumer/src/main/java/com/gis/listener/SceneListener.java

@@ -213,7 +213,8 @@ public class SceneListener {
                     scenePanoService.updateById(scenePanoEntity);
                 }
 
-                String visionUrl = domain4dKK+"/oss/scene_view_data/"+param.getSceneCode()+"/images/vision.txt";
+                String visionUrl = domain4dKK+"/scene_view_data/"+param.getSceneCode()+"/images/vision.txt";
+
                 HttpResponse execute = HttpRequest.get(visionUrl+"?m="+System.currentTimeMillis()).execute();
                 JSONArray sweepLocations = new JSONArray();
                 if (execute.getStatus()==200){
@@ -349,23 +350,16 @@ public class SceneListener {
     private void updateOssStatusJson(String sceneCode, int status) throws IOException {
         //修改OSS,status状态 scene_view_data/场景码/data/status.json
         String statusJson = "scene_view_data/"+sceneCode+"/data/status.json";
-        String statusJsonUrl =domain4dKK+"/oss/"+statusJson;
-        HttpResponse execute = HttpRequest.get(statusJsonUrl+"?m="+System.currentTimeMillis()).execute();
-        if (execute.getStatus()==200){
-            log.info("statusJson存在: {}");
-            JSONObject statusJsonObj = JSONObject.parseObject(execute.body());
-            statusJsonObj.put("status",status);
-//            fileAndOssUtil.upload("4dkankan",statusJsonObj.toJSONString().getBytes(StandardCharsets.UTF_8), statusJson);
-
-            File tempDir = Files.createTempDirectory("temp").toFile();
-            tempDir.deleteOnExit(); // 设置临时文件夹在JVM退出时删除
-            // 在临时文件夹中创建一个临时文件
-            File tempFile = File.createTempFile("temp", ".json", tempDir);
-            tempFile.deleteOnExit(); // 设置临时文件在JVM退出时删除
-            FileWriter writer = new FileWriter(tempFile);
-            writer.write(statusJsonObj.toJSONString());
-            fileAndOssUtil.uploadBySh(tempFile.getAbsolutePath(), statusJson,"4dkankan","local");
-            tempFile.delete();
+        Boolean exist=fileAndOssUtil.existKey("4dkankan",statusJson);
+        if (exist){
+            String statusJsonUrl = domain4dKK+"/"+statusJson;
+            HttpResponse execute = HttpRequest.get(statusJsonUrl+"?m="+System.currentTimeMillis()).execute();
+            if (execute.getStatus()==200){
+                log.info("statusJson存在: {}");
+                JSONObject statusJsonObj = JSONObject.parseObject(execute.body());
+                statusJsonObj.put("status",status);
+                fileAndOssUtil.upload("4dkankan",statusJsonObj.toJSONString().getBytes(StandardCharsets.UTF_8), statusJson);
+            }
         }
     }
 
@@ -426,7 +420,8 @@ public class SceneListener {
             sceneCode = RandomUtils.getSceneCode("fd720_");
             newName = sceneCode + ".jpg";
             filePath = configConstant.serverBasePath + sceneCode+ "/" + newName;
-            fileAndOssUtil.downloadBySh(item, filePath,"4dkankan","local");
+            fileAndOssUtil.downloadFile("4dkankan",item,filePath );
+
             entity = new ScenePanoEntity();
             entity.setFilePath(filePath);
             entity.setFileName(FileUtil.getName(filePath));

+ 21 - 0
720yun_fd_consumer/gis_consumer_oss/src/main/java/com/gis/oss/util/FileAndOssUtil.java

@@ -1,5 +1,6 @@
 package com.gis.oss.util;
 
+import com.aliyun.oss.OSSClient;
 import com.fdkankan.filestorage.FileStorageTemplate;
 import com.gis.oss.constant.StorageType;
 import lombok.extern.slf4j.Slf4j;
@@ -67,4 +68,24 @@ public class FileAndOssUtil {
 		log.info("开始上传文件 源路径:{},目标路径:{}, type:{}" , filePath, key);
 		OssShUtil.yunDownloadOther(key,filePath,bucket,active);
 	}
+	/**
+	 * 获取文件内容-阿里云
+	 * @param objectName
+	 * @return
+	 */
+	public boolean existKey(String bucket,String objectName){
+		//创建oss客户端
+		// ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
+		try{
+			boolean exist = ossUtil.doesObjectExist(bucket, objectName);
+			return exist;
+		}catch (Exception e){
+			log.error("s4判断是否存在key异常,key=" + objectName, e);
+		}
+		return false;
+	}
+
+	public void downloadFile(String bucket, String ossKey, String filePath) {
+		ossUtil.downloadFile(bucket,ossKey,filePath);
+	}
 }