瀏覽代碼

更改场景放到data 目录

wuweihao 3 年之前
父節點
當前提交
1131a0771b

+ 53 - 46
gis_scene/src/main/java/com/gis/scene/controller/SceneController.java

@@ -102,55 +102,62 @@ public class SceneController  {
 
 
 
-    @ApiOperation(value = "上传到指定场景码目录", notes = "时间戳命名")
+    @ApiOperation(value = "上传到指定场景码目录", notes = "热点-时间戳命名")
     @PostMapping(value = "upload/{sceneCode}", consumes = {"multipart/form-data"})
-    public Result upload(MultipartFile file , @PathVariable String sceneCode) throws IOException {
-
-        if (file == null) {
-            log.error("文件不能为空");
-            return Result.failure("文件不能为空");
-        }
-
-        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
-        if (entity == null) {
-            log.error("场景不存在: {}", sceneCode);
-            return Result.failure("场景不存在");
-        }
-
-        String fileName = file.getOriginalFilename();
-        log.info("原始文件名: {}", fileName);
-//        String time = DateUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmssSSS");
-//        String suffix = StringUtils.substringAfterLast(fileName, ".");
-//        suffix = StringUtils.lowerCase(suffix);
-
-//        String newName = time  + "."  +suffix;
-
-
-
-
-        // 去除特殊符号
-        String pinyinName = RegexUtil.specificSymbol(fileName);
-        pinyinName = PinyinUtil.getPinyin(pinyinName, "");
-
-        // 转小写
-        pinyinName =  StringUtils.lowerCase(pinyinName);
-
-
-
-        String basePath = configConstant.serverBasePath + sceneCode;
-        String savePath = basePath + "/edit/" + pinyinName;
-        log.info("文件保存位置:" + savePath);
-        FileUtil.writeFromStream(file.getInputStream(), savePath);
-
-
-        Object urlPath =  entity.getPath() + "/edit/" + pinyinName;
-
-        log.info("文件写入成功: {}", urlPath);
+    public Result upload(MultipartFile file , @PathVariable String sceneCode) {
+        return sceneService.upload(file, sceneCode);
+    }
 
-        // 返回前端数据
-        return Result.success(urlPath);
 
-    }
+//    @ApiOperation(value = "上传到指定场景码目录", notes = "时间戳命名")
+//    @PostMapping(value = "upload/{sceneCode}", consumes = {"multipart/form-data"})
+//    public Result upload(MultipartFile file , @PathVariable String sceneCode) throws IOException {
+//
+//        if (file == null) {
+//            log.error("文件不能为空");
+//            return Result.failure("文件不能为空");
+//        }
+//
+//        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
+//        if (entity == null) {
+//            log.error("场景不存在: {}", sceneCode);
+//            return Result.failure("场景不存在");
+//        }
+//
+//        String fileName = file.getOriginalFilename();
+//        log.info("原始文件名: {}", fileName);
+////        String time = DateUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmssSSS");
+////        String suffix = StringUtils.substringAfterLast(fileName, ".");
+////        suffix = StringUtils.lowerCase(suffix);
+//
+////        String newName = time  + "."  +suffix;
+//
+//
+//
+//
+//        // 去除特殊符号
+//        String pinyinName = RegexUtil.specificSymbol(fileName);
+//        pinyinName = PinyinUtil.getPinyin(pinyinName, "");
+//
+//        // 转小写
+//        pinyinName =  StringUtils.lowerCase(pinyinName);
+//
+//
+//
+//        String basePath = configConstant.serverBasePath + sceneCode;
+//        String savePath = basePath + "/edit/" + pinyinName;
+//        log.info("文件保存位置:" + savePath);
+//        FileUtil.writeFromStream(file.getInputStream(), savePath);
+//
+//
+//        Object urlPath =  entity.getPath() + "/edit/" + pinyinName;
+//
+//        log.info("文件写入成功: {}", urlPath);
+//
+//        // 返回前端数据
+//        return Result.success(urlPath);
+//
+//    }
 
 
 }

+ 3 - 0
gis_scene/src/main/java/com/gis/scene/service/SceneService.java

@@ -7,6 +7,7 @@ import com.gis.common.util.Result;
 import com.gis.scene.entity.dto.RoamViableDto;
 import com.gis.scene.entity.dto.SceneDataDto;
 import com.gis.scene.entity.po.SceneEntity;
+import org.springframework.web.multipart.MultipartFile;
 
 
 /**
@@ -28,4 +29,6 @@ public interface SceneService extends IBaseService<SceneEntity, Long> {
     Result addStar(Long id);
 
     Result addVisit(Long id);
+
+    Result upload(MultipartFile file, String sceneCode);
 }

+ 26 - 3
gis_scene/src/main/java/com/gis/scene/service/impl/SceneServiceImpl.java

@@ -20,7 +20,9 @@ import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.util.Map;
 import java.util.Set;
 
 
@@ -70,7 +72,7 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
         // 注意网络下载会有缓存,必须加时间戳
 //        log.info("网络下载文件地址: {}", urlPath);
 //        String localBasePath = FILE_PATH + sceneCode;
-        String localBasePath = configConstant.serverBasePath +"/" + sceneCode;
+        String localBasePath = configConstant.serverBasePath +"/data/" + sceneCode;
 
         // 2. 将vision.modeldata 转 vision.json
         String visionModelDataPath = localBasePath + "/" + visionModelDataName;
@@ -151,7 +153,7 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
             return Result.failure("场景不存在");
         }
 
-        String basePath = configConstant.serverBasePath +"/" + sceneCode;
+        String basePath = configConstant.serverBasePath +"/data/" + sceneCode;
 
 
         // 处理someData.json
@@ -323,6 +325,27 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
         return Result.success();
     }
 
+
+    @Override
+    public Result upload(MultipartFile file, String sceneCode) {
+        if (file == null) {
+            log.error("文件不能为空");
+            return Result.failure("文件不能为空");
+        }
+
+        SceneEntity entity = this.findBySceneCode(sceneCode);
+        if (entity == null) {
+            log.error("场景不存在: {}", sceneCode);
+            return Result.failure("场景不存在");
+        }
+
+        Map<String, Object> uploadMap = fileUtils.uploadMap(file, "/data/" + sceneCode + "/edit/hot", false);
+
+
+        return Result.success(uploadMap.get("filePath"));
+    }
+
+
     /**
      * 2021.04.02 处理infoAttribute的m_title
      * String url  = "https://www.4dmodel.com/SuperTwo/hot_online/index.html?m=" + key;
@@ -392,7 +415,7 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
         }
 
         log.info("out data.js : {}", dataJsJson);
-        String basePath = configConstant.serverBasePath +"/" + entity.getSceneCode();
+        String basePath = configConstant.serverBasePath +"/data/" + entity.getSceneCode();
 
         String dataPath = basePath + "/hot/js/data.js";
         FileUtil.writeUtf8String(dataJsJson.toJSONString(), dataPath);