Przeglądaj źródła

添加box视频上传

wuweihao 5 lat temu
rodzic
commit
0ab30a7f4c

+ 1 - 1
gis_application/src/main/resources/application-dev.properties

@@ -53,6 +53,6 @@ logging.config=classpath:logback-spring.xml
 logging.level.com.fdkanfang=debug
 
 # \u672C\u5730\u4FDD\u5B58\u8DEF\u5F84
-file.path=F:\\test\\army\\images
+file.path=F:\\test\\army\\images\\
 server.domain =http://192.168.0.135:8101/
 

+ 1 - 1
gis_common/src/main/java/com/gis/common/util/FileUtils.java

@@ -62,7 +62,7 @@ public class FileUtils {
 
 
     /**
-     * 文件上传
+     * 文件上传
      * @param file
      * @param savePath
      * @return

+ 83 - 4
gis_web/src/main/java/com/gis/web/controller/ApiController.java

@@ -45,6 +45,88 @@ public class ApiController extends BaseController {
     @Autowired
     private SceneService sceneService;
 
+    /**
+     *  map的key值是json参数,value是文件
+     * @param param
+     * @param sceneCode
+     * @param request
+     * @return
+     */
+    @ApiOperation("box视频上传")
+    @PostMapping("uploadBox")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "sceneCode", value = "场景码", required = true),
+            @ApiImplicitParam(name = "param", value = "Map传参", required = true),
+    })
+
+    public Result uploadBox(@RequestParam Map<String, MultipartFile> param, String sceneCode, HttpServletRequest request) throws IOException {
+
+        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
+        if (entity == null) {
+            log.error("对象不存在:{}", sceneCode);
+            return Result.failure("场景码不存在");
+        }
+
+        // 保存位置(箭头函数传参,需要定义final, 使用时需要赋值使用)
+        String basePath = entity.getPath();
+        final String saveBasePath = basePath + "/boxVideo/";
+
+        // box视频信息
+        JSONArray overlaysArray = new JSONArray();
+
+        param.forEach((key, file)->{
+
+            if (StringUtils.isBlank(key)) {
+                log.error("key值不能为空");
+                return;
+            }
+
+            if (file == null) {
+                log.error("文件不能为空");
+                return;
+            }
+
+            String fileName = file.getOriginalFilename();
+
+            JSONObject keyJson = JSONObject.parseObject(key);
+
+            // 给相对路径,tomcat配置静态资源让前端读取
+            String boxVideoPath = "/boxVideo/" + fileName;
+//            log.info("boxVideoPath: {}", boxVideoPath);
+
+            // 添加视频参数到overlayJaon
+            keyJson.put("file", boxVideoPath);
+            overlaysArray.add(keyJson);
+
+
+            // final值需要赋值使用
+            String filePath = saveBasePath;
+
+            filePath += fileName;
+            log.info("filePath: {}", filePath);
+            try {
+                FileUtils.upload(file, filePath);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+        });
+
+        JSONObject dataJson = new JSONObject();
+        dataJson.put("overlays", overlaysArray);
+
+        // 创建data2.js文件
+        String saveDataJsonPath = basePath + "/data2.js";
+        log.info("data2.js path :{}", saveDataJsonPath);
+        FileUtil.writeUtf8String(dataJson.toJSONString(), saveDataJsonPath);
+        log.info("data2.js创建完成");
+
+        return Result.success();
+    }
+
+
+
+
 
     @ApiOperation("Map表单上传多文件,指定保存路径,需要用postman测试")
     @PostMapping("uploads")
@@ -78,7 +160,7 @@ public class ApiController extends BaseController {
             }
 
             path = FILE_PATH + path;
-            log.warn("savePath: {}", path);
+            log.info("savePath: {}", path);
             try {
                 FileUtils.upload(file, path);
             } catch (IOException e) {
@@ -139,9 +221,6 @@ public class ApiController extends BaseController {
     }
 
 
-
-
-
     @ApiOperation("获取场景码")
     @GetMapping("getSceneCode")
     public Result getSceneCode() {