Browse Source

更新- data2.js -> m_title处理逻辑

wuweihao 4 năm trước cách đây
mục cha
commit
0d7d14f600

+ 23 - 4
gis_service/src/main/java/com/gis/service/impl/SceneServiceImpl.java

@@ -270,12 +270,12 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
             Set<String> strings = hotJson.keySet();
             for (String key: strings) {
                 JSONObject subJson = hotJson.getJSONObject(key);
-//                String url  = "https://www.4dmodel.com/SuperTwo/hot_online/index.html?m=" + key;
-//                String url  = SERVER_DOMAIN + "edit-backstage/hot_online/index.html?m=" + key;
-                String url  = "/edit-backstage/hot_online/index.html?m=" + key;
+
+                // 2021.04.02 处理link
+                String link = getLink(subJson, key);
 
                 // 将link 添加进去
-                subJson.put("link", url);
+                subJson.put("link", link);
             }
             data2Json.put("hots", hotJson);
         } else {
@@ -299,6 +299,25 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
     }
 
     /**
+     * 2021.04.02 处理infoAttribute的m_title
+     * String url  = "https://www.4dmodel.com/SuperTwo/hot_online/index.html?m=" + key;
+     * String url  = SERVER_DOMAIN + "edit-backstage/hot_online/index.html?m=" + key;
+     * m_title:[]
+     * 有值: link = "/edit-backstage/hot_online1/index.html?m=" + key
+     * 无值: link = "/edit-backstage/hot_online/index.html?m=" + key
+     */
+    private String getLink(JSONObject param, String key){
+        JSONObject infoAttribute = param.getJSONObject("infoAttribute");
+        // m_title可能会没有这个属性key, 需要判断
+        JSONArray m_title = infoAttribute.getJSONArray("m_title");
+        String url  = "/edit-backstage/hot_online/index.html#/?m=" + key;
+        if (m_title != null && m_title.size() > 0){
+            url  = "/edit-backstage/hot_online1/index.html#/?m=" + key;
+        }
+        return url;
+    }
+
+    /**
      * 处理data.js 文件
      */
     private void editDataJs(SceneEntity entity, String hots )  {

+ 103 - 372
gis_web/src/main/java/com/gis/web/controller/SceneController.java

@@ -76,174 +76,6 @@ public class SceneController extends BaseController {
         return Result.success(page);
     }
 
-    /**
-     * 应用程序部门需要用到
-     * @param param
-     * @return
-     */
-
-
-/*    @ApiOperation("场景编辑")
-    @PostMapping("edit")
-    public Result edit(@Valid @RequestBody SceneDataDto param) {
-        String sceneCode = param.getSceneCode();
-        SceneEntity entity = sceneService.findBySceneCode(param.getSceneCode());
-        if (entity == null) {
-            log.error("场景不存在 : {}", sceneCode);
-            return Result.failure("场景不存在");
-        }
-
-
-
-        // 处理someData.json
-
-        String someDataPath = entity.getPath() + "/someData.json";
-        if (!FileUtil.isFile(someDataPath)) {
-            log.error("someData.json文件不存在");
-            return Result.failure("someData.json文件不存在");
-        }
-
-        // 读取someDataJson
-        String someData = FileUtil.readUtf8String(someDataPath);
-        JSONObject someDataJson = JSONObject.parseObject(someData);
-
-
-
-        String info = param.getInfo();
-        String guides = param.getGuides();
-        JSONArray guidesArray = new JSONArray();
-        if (guides != null) {
-            guidesArray = JSONObject.parseArray(guides);
-
-        }
-
-
-        if (info != null) {
-            JSONObject infoJson = JSONObject.parseObject(info);
-
-            // 处理model
-            JSONObject model = someDataJson.getJSONObject("model");
-            if (model != null) {
-                if (guidesArray != null) {
-                    model.put("images", guidesArray);
-                }
-
-                // camera_start放最外层
-//                someDataJson.put("camera_start", infoJson.getJSONObject("camera_start"));
-            }
-
-            // 更新someDataJson
-            someDataJson.put("model", model);
-//            someDataJson.put("loadlogo", infoJson.get("loadlogo"));
-
-            // info信息添加到someDataJson最外层
-            Set<String> infoKey = infoJson.keySet();
-            for (String key : infoKey) {
-
-                someDataJson.put(key, infoJson.get(key));
-            }
-
-            // 删除旧someDataJson
-            FileUtil.del(someDataPath);
-            // 写入新someDataJson
-            FileUtil.writeUtf8String(someDataJson.toJSONString(), someDataPath);
-            log.info("someData.json写入完成");
-        }
-
-        // 处理data2.js
-        String data2Path = entity.getPath() + "/data2.js";
-        boolean file = FileUtil.isFile(data2Path);
-        if (!file) {
-            log.error("data2.js文件不存在");
-            return Result.failure("data2.js文件不存在");
-        }
-
-        String data2 = FileUtil.readUtf8String(data2Path);
-        JSONObject data2Json = JSONObject.parseObject(data2);
-
-        String tourAudio = param.getTourAudio();
-        if (tourAudio != null) {
-            data2Json.put("tourAudio", JSONObject.parseObject(tourAudio));
-        } else {
-            data2Json.put("tourAudio", new JSONObject());
-        }
-
-        // overlays是数组
-        String overlays = param.getOverlays();
-        if (overlays != null) {
-            data2Json.put("overlays", JSONObject.parseArray(overlays));
-        } else {
-            data2Json.put("overlays", new JSONArray());
-        }
-
-        // 处理guidesArray,将scan_id的值作为key, value:  time":40000
-        JSONObject audioJson = new JSONObject();
-        JSONObject timeJson = new JSONObject();
-        timeJson.put("time", 40000);
-        if (guidesArray != null) {
-
-            // 将旧的audio字段删除
-            data2Json.remove("audio");
-
-            for (int i = 0; i < guidesArray.size() ; i++) {
-                JSONObject metadata = guidesArray.getJSONObject(i).getJSONObject("metadata");
-                if (metadata != null) {
-                    String scanId = metadata.getString("scan_id");
-                    if (scanId == null) {
-                        log.error("guides.metadata.scan_id为空: {}", i);
-                        return Result.failure("guides.metadata.scan_id为空: " + i);
-                    }
-                    // Fastjson-fastjson中$ref对象重复引用问题,拿不到想要的效果
-//                    JSONObject timeJson = new JSONObject();
-//                    timeJson.put("time", 40000);
-                    audioJson.put(scanId, JSON.toJSONString(timeJson, SerializerFeature.DisableCircularReferenceDetect));
-
-                }
-            }
-
-            // 新增audio
-            data2Json.put("audio", audioJson);
-        }
-
-
-        // host在data2.js、data.js都需要处理
-        String hots = param.getHots();
-        log.info("input hots: {}", hots);
-        if (hots != null) {
-            // 获取所有key
-            JSONObject hotJson = JSONObject.parseObject(hots);
-
-            Set<String> strings = hotJson.keySet();
-            for (String key: strings) {
-                JSONObject subJson = hotJson.getJSONObject(key);
-//                String url  = "https://www.4dmodel.com/SuperTwo/hot_online/index.html?m=" + key;
-//                String url  = SERVER_DOMAIN + "edit-backstage/hot_online/index.html?m=" + key;
-                String url  = "/edit-backstage/hot_online/index.html?m=" + key;
-
-                // 将link 添加进去
-                subJson.put("link", url);
-            }
-            data2Json.put("hots", hotJson);
-        } else {
-            data2Json.put("hots", new JSONObject());
-        }
-
-
-        // 删除旧data2.js
-        FileUtil.del(data2Path);
-
-
-        // 写入新data2.js
-        FileUtil.writeUtf8String(data2Json.toJSONString(), data2Path);
-        log.info("新data2.js写入完成");
-
-
-        //处理data.js 文件
-        editDataJs(entity, hots);
-
-        return Result.success();
-    }*/
-
 
     @ApiOperation("场景编辑")
     @PostMapping("edit")
@@ -336,191 +168,90 @@ public class SceneController extends BaseController {
      * @param request
      * @return
      */
-    @ApiOperation(value = "box视频上传", notes = "自定义上传位置,文件名需要验证中文字符")
-    @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 = configConstant.serverBasePath + sceneCode;
-        final String saveBasePath = basePath + "/boxVideo/";
-
-        // box视频信息
-        JSONArray overlaysArray = new JSONArray();
-
-        param.forEach((key, file)->{
-
-            if (StringUtils.isBlank(key)) {
-                log.error("key值不能为空");
-                throw new BaseRuntimeException("key值不能为空");
-            }
-
-            if (file == null) {
-                log.error("文件不能为空");
-                throw new BaseRuntimeException("文件不能为空");
-            }
-
-            String fileName = file.getOriginalFilename();
-
-            if (Validator.hasChinese(fileName)) {
-                log.error("文件名不能有中文字符: {}", fileName);
-                throw new BaseRuntimeException("文件名不能有中文字符");
-            }
-
-
-
-            JSONObject keyJson = JSONObject.parseObject(key);
-
-            // 给相对路径,tomcat配置静态资源让前端读取
-            // http://192.168.0.44:8101/data/ar_I4Ef2SS4y/boxVideo/20180201_101827.mp4
-//            String boxVideoPath = FILE_ADDRESS + entity.getSceneCode()+ "/boxVideo/" + fileName;
-            String boxVideoPath = configConstant.serverUrlPrefix + entity.getSceneCode()+ "/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 {
-                FileUtil.writeFromStream(file.getInputStream(), 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(entity.getWebSite());
-    }
-
-
-    /**
-     * 创建场景
-     * @param param
-     * @param sceneTitle
-     * @param sceneCode
-     * @return
-     * @throws Exception
-     */
-//    @ApiOperation(value = "Map表单上传多文件,指定保存路径,需要用postman测试", notes = "自定义上传位置,文件名需要验证中文字符")
-//    @PostMapping("uploads")
-//    public Result uploads(@RequestParam Map<String, MultipartFile> param, String sceneTitle, String sceneCode , String type) throws Exception {
+//    @ApiOperation(value = "box视频上传", notes = "自定义上传位置,文件名需要验证中文字符")
+//    @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 {
 //
-//        if (StringUtils.isBlank(sceneCode)){
-//            log.error("场景码不能为空");
-//            return Result.failure("场景码不能为空");
+//        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
+//        if (entity == null) {
+//            log.error("对象不存在:{}", sceneCode);
+//            return Result.failure("场景码不存在");
 //        }
 //
-//        if (StringUtils.isBlank(sceneTitle)){
-//            log.error("场景标题不能为空");
-//            return Result.failure("场景标题不能为空");
-//        }
+//        // 保存位置(箭头函数传参,需要定义final, 使用时需要赋值使用)
+//        String basePath = configConstant.serverBasePath + sceneCode;
+//        final String saveBasePath = basePath + "/boxVideo/";
 //
-//        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
-//        if (entity != null) {
-//            log.error("场景码已存在,请更换新场景码: {}", sceneCode);
-//            return Result.failure("场景码已存在,请更换新场景码");
-//        }
+//        // box视频信息
+//        JSONArray overlaysArray = new JSONArray();
 //
-//        param.forEach((path, file)->{
+//        param.forEach((key, file)->{
 //
-//            if (StringUtils.isBlank(path)) {
-//                log.error("保存路径不能为空");
-//                throw new BaseRuntimeException("保存路径不能为空");
+//            if (StringUtils.isBlank(key)) {
+//                log.error("key值不能为空");
+//                throw new BaseRuntimeException("key值不能为空");
 //            }
 //
 //            if (file == null) {
 //                log.error("文件不能为空");
-//                throw new BaseRuntimeException("文件为空");
+//                throw new BaseRuntimeException("文件不能为空");
 //            }
+//
 //            String fileName = file.getOriginalFilename();
+//
 //            if (Validator.hasChinese(fileName)) {
 //                log.error("文件名不能有中文字符: {}", fileName);
-//                throw new BaseRuntimeException("文件名不能有中文字符:" + fileName);
-//            }
-//
-//            path = FILE_PATH + path;
-//            log.info("savePath: {}", path);
-//            try {
-//                FileUtil.writeFromStream(file.getInputStream(), path);
-//            } catch (IOException e) {
-//                e.printStackTrace();
+//                throw new BaseRuntimeException("文件名不能有中文字符");
 //            }
 //
-//        });
-//
-//        entity = new SceneEntity();
-//        entity.setSceneCode(sceneCode);
-//        entity.setPath(FILE_PATH + sceneCode);
-//        entity.setSceneTitle(sceneTitle);
-//
-//        Long userId = getTokenUserId();
-//        SysUserEntity userEntity = sysUserService.findById(userId);
-//
-//        entity.setSubmitId(userId);
-//        entity.setSubmitName(userEntity.getRealName());
-//        entity.setType(type);
-//        entity.setUpdateTime(new Date());
-//
-//
 //
 //
-//        // 调用算法切图片转换
-//        String cmd = ConstantCmd.SLICE_SKYBOX + entity.getPath();
-//        log.info("cmd:{}", cmd);
-//        CreateObjUtil.callshell(cmd);
-//        log.info("算法切片完成");
+//            JSONObject keyJson = JSONObject.parseObject(key);
 //
+//            // 给相对路径,tomcat配置静态资源让前端读取
+//            // http://192.168.0.44:8101/data/ar_I4Ef2SS4y/boxVideo/20180201_101827.mp4
+////            String boxVideoPath = FILE_ADDRESS + entity.getSceneCode()+ "/boxVideo/" + fileName;
+//            String boxVideoPath = configConstant.serverUrlPrefix + entity.getSceneCode()+ "/boxVideo/" + fileName;
+////            log.info("boxVideoPath: {}", boxVideoPath);
 //
-//        // 调用算法将obj转txt
-//        String objCmd = ConstantCmd.OBJ_TO_TXT + entity.getPath();
-//        log.info("objCmd:{}", objCmd);
-//        CreateObjUtil.callshell(objCmd);
-//        log.info("算法obj转txt完成");
+//            // 添加视频参数到overlayJaon
+//            keyJson.put("file", boxVideoPath);
+//            overlaysArray.add(keyJson);
 //
 //
-//        // 转换文件
-//        convert(entity.getPath(), sceneCode, sceneTitle);
-//        log.info("文件转换完成");
+//            // final值需要赋值使用
+//            String filePath = saveBasePath;
 //
-//        // 场景url
-//        String webSite = SERVER_DOMAIN + "edit-backstage/index.html?m=" + sceneCode;
-//        log.info("webSite: {}", webSite);
+//            filePath += fileName;
+//            log.info("filePath: {}", filePath);
+//            try {
+//                FileUtil.writeFromStream(file.getInputStream(), filePath);
+//            } catch (IOException e) {
+//                e.printStackTrace();
+//            }
 //
+//        });
 //
-//        entity.setWebSite(webSite);
-//        sceneService.save(entity);
+//        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(entity.getWebSite());
 //    }
 
 
+
+
     /**
      * 文件转换
      * @param sceneCode
@@ -693,57 +424,57 @@ public class SceneController extends BaseController {
      * 参数只用:hots、sceneCode
      * @return
      */
-    @ApiOperation(value = "编辑热点(应用程序项目部)", notes = "应用程序项目部编辑场景热点")
-    @PostMapping("editHots")
-    public Result editHots(@Valid @RequestBody SceneDataDto param){
-        String sceneCode = param.getSceneCode();
-        SceneEntity entity = sceneService.findBySceneCode(param.getSceneCode());
-        if (entity == null) {
-            log.error("场景不存在 : {}", sceneCode);
-            return Result.failure("场景不存在");
-        }
-        String basePath = configConstant.serverBasePath + sceneCode;
-
-        // 处理data2.js
-        String data2Path = basePath + "/data2.js";
-        boolean file = FileUtil.isFile(data2Path);
-        if (!file) {
-            log.error("data2.js文件不存在");
-            return Result.failure("data2.js文件不存在");
-        }
-
-        String data2 = FileUtil.readUtf8String(data2Path);
-        JSONObject data2Json = JSONObject.parseObject(data2);
-
-        String hots = param.getHots();
-        if (hots != null) {
-            // 获取所有key
-            JSONObject hotJson = JSONObject.parseObject(hots);
-
-            Set<String> strings = hotJson.keySet();
-            for (String key: strings) {
-                JSONObject subJson = hotJson.getJSONObject(key);
-//                String url  = "https://www.4dmodel.com/SuperTwo/hot_online/index.html?m=" + key;
-//                String url  = SERVER_DOMAIN + "edit-backstage/hot_online/index.html?m=" + key;
-                String url  = "/edit-backstage/hot_online/index.html?m=" + key;
-                // 将link 添加进去
-                subJson.put("link", url);
-            }
-            data2Json.put("hots", hotJson);
-        }
-
-        // 删除旧data2.js
-        FileUtil.del(data2Path);
-        // 写入新data2.js
-        FileUtil.writeUtf8String(data2Json.toJSONString(), data2Path);
-        log.info("新data2.js写入完成");
-
-        //处理data.js 文件
-        editDataJs(entity, hots);
-
-
-        return Result.success();
-    }
+//    @ApiOperation(value = "编辑热点(应用程序项目部)", notes = "应用程序项目部编辑场景热点")
+//    @PostMapping("editHots")
+//    public Result editHots(@Valid @RequestBody SceneDataDto param){
+//        String sceneCode = param.getSceneCode();
+//        SceneEntity entity = sceneService.findBySceneCode(param.getSceneCode());
+//        if (entity == null) {
+//            log.error("场景不存在 : {}", sceneCode);
+//            return Result.failure("场景不存在");
+//        }
+//        String basePath = configConstant.serverBasePath + sceneCode;
+//
+//        // 处理data2.js
+//        String data2Path = basePath + "/data2.js";
+//        boolean file = FileUtil.isFile(data2Path);
+//        if (!file) {
+//            log.error("data2.js文件不存在");
+//            return Result.failure("data2.js文件不存在");
+//        }
+//
+//        String data2 = FileUtil.readUtf8String(data2Path);
+//        JSONObject data2Json = JSONObject.parseObject(data2);
+//
+//        String hots = param.getHots();
+//        if (hots != null) {
+//            // 获取所有key
+//            JSONObject hotJson = JSONObject.parseObject(hots);
+//
+//            Set<String> strings = hotJson.keySet();
+//            for (String key: strings) {
+//                JSONObject subJson = hotJson.getJSONObject(key);
+////                String url  = "https://www.4dmodel.com/SuperTwo/hot_online/index.html?m=" + key;
+////                String url  = SERVER_DOMAIN + "edit-backstage/hot_online/index.html?m=" + key;
+//                String url  = "/edit-backstage/hot_online/index.html?m=" + key;
+//                // 将link 添加进去
+//                subJson.put("link", url);
+//            }
+//            data2Json.put("hots", hotJson);
+//        }
+//
+//        // 删除旧data2.js
+//        FileUtil.del(data2Path);
+//        // 写入新data2.js
+//        FileUtil.writeUtf8String(data2Json.toJSONString(), data2Path);
+//        log.info("新data2.js写入完成");
+//
+//        //处理data.js 文件
+//        editDataJs(entity, hots);
+//
+//
+//        return Result.success();
+//    }
 
 
     /**