浏览代码

添加免token认证,需要在数据库tb_clent添加code,用于验证

wuweihao 4 年之前
父节点
当前提交
0a6f93614c

+ 6 - 0
README.md

@@ -9,6 +9,7 @@
          
          公网访问:
          http://space3d.4dage.com:8105/doc.html
+         owen owen
          http://47.107.252.54:8105/doc.html
          
          大场景列表:
@@ -18,6 +19,11 @@
     <Context path="" docBase="/root/user/java/tomcat_cmsBigScene_8105/webapps/cmsBigScene" debug="0" reloadable="true" crossContext="true"/>
     /root/user/java/tomcat_cmsBigScene_8105/webapps
     
+    
+    服务更更新日志
+        2020-09-25:
+            添加免token认证,需要在数据库tb_clent添加code,用于验证
+    
    
 
         

+ 3 - 2
gis_mapper/src/main/java/com/gis/mapper/SceneMapper.java

@@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.Update;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
+import java.util.Map;
 
 @Component
 @Mapper
@@ -22,8 +23,8 @@ public interface SceneMapper extends IBaseMapper<SceneEntity, Long> {
     @SelectProvider(type = SceneProvider.class, method = "search")
     List<SceneEntity> search(PageDto param);
 
-//    @Update("update tb_scene set display = 0 where display = 1 ")
-//    void setDisable();
+    @Select("select * from tb_client where code = #{code}")
+    Map findByCode(String code);
 //
 //    @Update("update tb_scene set display = 1 where id = #{id} ")
 //    void setDisplay(Long id);

+ 7 - 0
gis_service/src/main/java/com/gis/service/SceneService.java

@@ -4,7 +4,10 @@ package com.gis.service;
 import com.gis.common.util.Result;
 import com.gis.domain.dto.PageDto;
 import com.gis.domain.dto.RoamViableDto;
+import com.gis.domain.dto.SceneDataDto;
 import com.gis.domain.po.SceneEntity;
+import com.qiniu.common.QiniuException;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -20,4 +23,8 @@ public interface SceneService extends IBaseService<SceneEntity, Long> {
     List<SceneEntity> search(PageDto param);
 
     Result roamViable(RoamViableDto param) throws Exception;
+
+    Result editUpload(MultipartFile file, String sceneCode);
+
+    Result editScene(SceneDataDto param) throws QiniuException;
 }

+ 316 - 0
gis_service/src/main/java/com/gis/service/impl/SceneServiceImpl.java

@@ -1,29 +1,38 @@
 package com.gis.service.impl;
 
 import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.gis.common.proto.util.ConvertUtils;
 import com.gis.common.util.FileUtils;
 import com.gis.common.util.QiniuOssUtil;
 import com.gis.common.util.Result;
 import com.gis.domain.dto.PageDto;
 import com.gis.domain.dto.RoamViableDto;
+import com.gis.domain.dto.SceneDataDto;
 import com.gis.domain.po.SceneEntity;
 import com.gis.mapper.SceneMapper;
 import com.gis.mapper.IBaseMapper;
 import com.gis.service.SceneService;
+import com.qiniu.common.QiniuException;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.constraints.NotBlank;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Set;
 
 
 /**
@@ -145,6 +154,313 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
         return Result.success();
     }
 
+    /**
+     * 编辑场景上传
+     * @param file
+     * @param sceneCode
+     * @return
+     */
+    @Override
+    public Result editUpload(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("场景不存在");
+        }
+
+        String basePath = entity.getPath() + "/edit/";
+        // 时间戳重新命名
+        HashMap<String, String> map = null;
+        try {
+            map = FileUtils.upload(file, basePath);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        String newName = map.get("newName");
+        String savePath = basePath + newName;
+
+        log.info("文件写入成功: {}", savePath);
+
+        // 上传到oss
+        String ossUploadPath = OSS_PATH + sceneCode + "/edit/" + newName;
+        String ossPath = OSS_DOMAIN + ossUploadPath;
+        try {
+            QiniuOssUtil.upload(savePath, ossUploadPath);
+        } catch (QiniuException e) {
+            e.printStackTrace();
+        }
+        log.info("文件上传到oss完成: {}", ossPath);
+        return Result.success((Object) ossPath);
+    }
+
+    /**
+     * 编辑场景
+     * @param param
+     * @return
+     */
+    @Override
+    public Result editScene(SceneDataDto param) throws QiniuException {
+        String sceneCode = param.getSceneCode();
+
+        SceneEntity entity = this.findBySceneCode(sceneCode);
+        if (entity == null) {
+            log.error("场景不存在 : {}", sceneCode);
+            return Result.failure("场景不存在");
+        }
+
+
+        // 处理someData.json, 网络下载someData.json
+        String someDataName = "someData.json";
+        // 注意网络下载会有缓存,必须加时间戳
+        String someDataUrl = OSS_DOMAIN + OSS_PATH + sceneCode + "/" + someDataName+ "?m=" + System.currentTimeMillis();
+        log.info("网络下载文件地址: {}", someDataUrl);
+        String localBasePath = FILE_PATH + sceneCode;
+        FileUtils.downLoadFromUrl(someDataUrl, someDataName, localBasePath);
+        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) {
+                String name = infoJson.getString("name");
+                model.put("name", name);
+
+                // update 场景名称
+                if (!name.equals(entity.getSceneTitle())) {
+                    entity.setSceneTitle(name);
+                    entity.setUpdateTime(new Date());
+                    this.update(entity);
+                }
+
+                model.put("summary", infoJson.get("summary"));
+
+//                model.put("camera_start", infoJson.getJSONObject("camera_start"));
+
+                if (guidesArray != null) {
+                    model.put("images", guidesArray);
+                } else {
+                    model.put("images", new JSONArray());
+                }
+
+                // camera_start放到最外层
+//                someDataJson.put("camera_start", infoJson.getJSONObject("camera_start"));
+            }
+
+            // 更新someDataJson
+            someDataJson.put("model", model);
+
+            // 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写入完成");
+
+            // 将新的someDataJson上传oss
+            QiniuOssUtil.upload(someDataPath, OSS_PATH + sceneCode + "/" + someDataName);
+            log.info(someDataName+ "已上传到七牛云");
+
+        }
+
+        // 处理data2.js
+
+        String data2Name = "data2.js";
+        // 注意网络下载会有缓存,必须加时间戳
+        String data2Url = OSS_DOMAIN + OSS_PATH + sceneCode + "/" + data2Name+ "?m=" + System.currentTimeMillis();
+        log.info("网络下载文件地址: {}", data2Url);
+        FileUtils.downLoadFromUrl(data2Url, data2Name, localBasePath);
+
+        String data2Path = entity.getPath() + File.separator + data2Name;
+        log.info("data2.js文件位置: {}", data2Path);
+
+        if (!FileUtil.exist(data2Path)) {
+            log.error("data2.js文件不存在: {}", data2Path);
+            return Result.failure("data2.js文件不存在");
+        }
+
+
+        String data2 = FileUtil.readUtf8String(data2Path);
+        JSONObject data2Json = JSONObject.parseObject(data2);
+
+//        log.info("old data2Json: " + data2Json.toJSONString());
+
+        String tourAudio = param.getTourAudio();
+        if (tourAudio != null) {
+            data2Json.put("tourAudio", JSONObject.parseObject(tourAudio));
+        } else {
+            data2Json.put("tourAudio", new JSONObject());
+        }
+
+        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));
+
+                }
+//                log.info("audioJson: " + i + ":" + audioJson.toJSONString());
+            }
+
+            // 新增audio
+            data2Json.put("audio", audioJson);
+        }
+
+//        log.info("new datajs: " + data2Json.toJSONString());
+
+        // host在data2.js、data.js都需要处理
+        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;
+                // 将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写入完成");
+
+        // 将新的someDataJson上传oss
+        QiniuOssUtil.upload(data2Path, OSS_PATH + sceneCode + "/" + data2Name);
+        log.info(data2Name+ "已上传到七牛云");
+
+        //处理data.js 文件
+        editDataJs(sceneCode, entity, hots);
+
+        return Result.success();
+    }
+
+    /**
+     * 处理data.js 文件
+     */
+    private void editDataJs(String sceneCode, SceneEntity entity, String hots ) throws QiniuException {
+
+        // 因为data.js只是热点信息,所以直接创建上传oss
+        JSONObject dataJsJson = new JSONObject();
+        if (hots != null) {
+            dataJsJson = JSONObject.parseObject(hots);
+
+            Set<String> strings = dataJsJson.keySet();
+            for (String key: strings) {
+                JSONObject subJson = dataJsJson.getJSONObject(key);
+                JSONObject infoAttribute = subJson.getJSONObject("infoAttribute");
+                if (infoAttribute != null) {
+                    Set<String> infoKey = infoAttribute.keySet();
+
+                    for (String s: infoKey) {
+                        Object val = null;
+                        // 添加到第一层, 空值不添加
+                        if ("images".equals(s) || "styleImg".equals(s) || "model".equals(s) || "video".equals(s) || "iframe".equals(s)) {
+                            JSONArray jsonArray = infoAttribute.getJSONArray(s);
+                            if (jsonArray.size() == 0) {
+                                continue;
+                            }
+                            val = jsonArray;
+
+                        } else {
+                            String a = infoAttribute.getString(s);
+                            if (StringUtils.isBlank(a)){
+                                continue;
+                            }
+                            val = a;
+                        }
+
+                        subJson.put(s, val);
+                    }
+                }
+
+                // 删除infoAttribute
+                subJson.remove("infoAttribute");
+
+            }
+
+        }
+        String dataPath = entity.getPath() + "/data.js";
+        FileUtil.writeUtf8String(dataJsJson.toJSONString(), dataPath);
+//        log.info("data.js {}", dataJsJson);
+
+
+
+
+        //上传oss
+        String ossPath = OSS_PATH + sceneCode + "/hot/js/data.js";
+        QiniuOssUtil.upload(dataPath, ossPath);
+        log.info("data.js已上传到七牛云: {}", ossPath);
+
+
+    }
+
     @Test
     public void test() throws Exception {
         String urlPath = "https://super.4dage.com/data/690/vision.modeldata";

+ 38 - 827
gis_web/src/main/java/com/gis/web/controller/ApiController.java

@@ -1,877 +1,88 @@
 package com.gis.web.controller;
 
 
-import cn.hutool.core.io.FileUtil;
-import cn.hutool.http.HttpUtil;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.serializer.SerializerFeature;
-import com.gis.common.exception.BaseRuntimeException;
-import com.gis.common.proto.constant.ConstantFileName;
-import com.gis.common.proto.util.CreateObjUtil;
 import com.gis.common.util.*;
-import com.gis.domain.dto.PageDto;
 import com.gis.domain.dto.RoamViableDto;
 import com.gis.domain.dto.SceneDataDto;
-import com.gis.domain.po.SceneEntity;
+import com.gis.mapper.SceneMapper;
 import com.gis.service.SceneService;
-import com.github.pagehelper.PageInfo;
 import com.qiniu.common.QiniuException;
 import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
-import org.apache.commons.lang3.StringUtils;
-import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.ResourceUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Valid;
-import javax.validation.constraints.NotBlank;
 import java.io.IOException;
-import java.util.Date;
-import java.util.HashMap;
 import java.util.Map;
-import java.util.Set;
 
 /**
  * Created by owen on 2020/6/10 0010 10:44
  */
 @Log4j2
-@Api(tags = "")
+@Api(tags = "Api(免token)")
 @RestController
 @RequestMapping("api/scene")
 public class ApiController extends BaseController {
 
 
     @Autowired
-    private SceneService sceneService;
-
-
-
-
-
-//    /**
-//     *  map的key值是json参数,value是文件
-//     * @param param
-//     * @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配置静态资源让前端读取
-//            // http://192.168.0.44:8101/data/ar_I4Ef2SS4y/boxVideo/20180201_101827.mp4
-//            String boxVideoPath = "/data/" + 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 {
-//                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(entity.getWebSite());
-//    }
-
-
-
-
-//    @ApiImplicitParams({
-//            @ApiImplicitParam(name = "sceneCode", value = "场景码", required = true),
-//            @ApiImplicitParam(name = "param", value = "Map传参", required = true),
-//    })
-//    @ApiOperation(value = "Map表单上传多文件,指定保存路径,需要用postman测试", notes = "自定义上传位置")
-//    @PostMapping("uploads")
-//    public Result uploads(@RequestParam Map<String, MultipartFile> param, String sceneCode) throws Exception {
-//
-//        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
-//        if (entity != null) {
-//            log.error("场景码已存在,请更换新场景码: {}", sceneCode);
-//            return Result.failure("场景码已存在,请更换新场景码");
-//        }
-//
-//        // 服务器文件路径
-//        String serverPath = FILE_PATH + sceneCode;
-//
-//        // oss文件路径
-//        String ossPath = OSS_PATH + sceneCode;
-//
-//
-//        // oss上传封装
-//        HashMap<String, String> ossMap = new HashMap<>();
-//
-//        param.forEach((path, file)->{
-//
-//            if (StringUtils.isBlank(path)) {
-//                log.error("保存路径不能为空");
-//            }
-//
-//            if (file == null) {
-//                log.error("文件不能为空");
-//            }
-//
-//            String filePath = serverPath + path;
-//            log.info("savePath: {}", filePath);
-//            try {
-//                FileUtil.writeFromStream(file.getInputStream(), filePath);
-//                ossMap.put(filePath, ossPath + path);
-//            } catch (IOException e) {
-//                e.printStackTrace();
-//            }
-//
-//        });
-//
-//        log.info("文件上传完成");
-//
-//        entity = new SceneEntity();
-//        entity.setSceneCode(sceneCode);
-//        entity.setPath(FILE_PATH + sceneCode);
-//        entity.setUpdateTime(new Date());
-//
-//
-//        // 这个可以编辑的时候创建也可以
-////        createData2Js(entity.getPath());
-////        log.info("data2.js创建完成");
-//
-////        AliyunOssUtil.uploadMulFiles(ossMap);
-//        QiniuOssUtil.uploads(ossMap);
-//        log.info("oss文件上传完成");
-//
-//
-//        // 调用算法切图片转换
-////        String cmd = ConstantCmd.SLICE_SKYBOX + entity.getPath();
-////        log.info("cmd:{}", cmd);
-////        CreateObjUtil.callshell(cmd);
-////        log.info("算法切片完成");
-//
-//
-//        // 调用算法将obj转txt
-////        String objCmd = ConstantCmd.OBJ_TO_TXT + entity.getPath();
-////        log.info("objCmd:{}", objCmd);
-////        CreateObjUtil.callshell(objCmd);
-////        log.info("算法obj转txt完成");
-//
-//
-//        // 转换文件
-////        convert(entity.getPath(), sceneCode, sceneTitle);
-////        log.info("文件转换完成");
-//
-//        // 场景url
-//        String webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
-//        log.info("webSite: {}", webSite);
-//
-//
-//        entity.setWebSite(webSite);
-//        sceneService.save(entity);
-//
-//
-//        return Result.success(entity);
-//    }
-
-
-//    /**
-//     * 创建场景码
-//     */
-//    private String createSceneCode() {
-//        String code = null;
-//        boolean flag = true;
-//        while (flag) {
-//            code = RandomUtils.randowString(9);
-//            code = "b_" +code;
-//            SceneEntity e = sceneService.findBySceneCode(code);
-//            if (e == null) {
-//                break;
-//            }
-//        }
-//
-//        return code;
-//    }
-
-
-//    @ApiOperation("漫游可行")
-//    @PostMapping("roamViable")
-//    public Result roamViable(@RequestBody RoamViableDto param) throws Exception {
-//        return sceneService.roamViable(param);
-//    }
-
-
-//    @ApiOperation("获取场景")
-//    @GetMapping("getScene/{sceneCode}")
-//    @ApiImplicitParam(name = "sceneCode", value = "场景码", required = true)
-//    public Result getScene(@PathVariable String sceneCode) {
-//        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
-//        assert entity != null;
-//
-//        return Result.success(entity.getWebSite());
-//    }
-
-
-//    @ApiOperation("生成json")
-//    @GetMapping("getJson/{code}")
-//    @ApiImplicitParam(name = "code", value = "matterPort码", required = true)
-//    public Result getJson(@PathVariable String code) throws IOException {
-//        String url = "https://my.matterportvr.cn/api/player/models/" + code;
-//        log.info("url: {}", url);
-//        String s = HttpUtil.get(url);
-//        if (s == null) {
-//            log.error("matterPort码无效: {}", url);
-//            return Result.failure("matterPort码无效:" + url);
-//        }
-//
-////        Object someData = editMatterPortvrData(s);
-//
-//        return Result.success(editMatterPortvrData(s));
-//    }
-
-    @Test
-    public void testUrl(){
-        String s = HttpUtil.get("https://my.matterportvr.cn/api/player/models/W8f6HMwUgVA");
-        log.info("s: {}", s);
-    }
-
-//    /**
-//     * 处理matterportvr 数据转为大场景可使用的数据
-//     * @throws IOException
-//     */
-//    public JSONObject editMatterPortvrData(String data) throws IOException {
-////        String resourceUrl = FileUtils.getResourceUrl("data/mpo.json");
-////        String s = FileUtil.readUtf8String(resourceUrl);
-//        JSONObject mpoJson = JSONObject.parseObject(data);
-//
-//        // 1. 删除第一层无用字段
-//        String[] delFiles = new String[] {"image","enable_social_sharing","social_sharing_enabled","account_social_sharing_default",
-//                "icon","address","vr_url","is_vr","vision_version","created","unit_type","owner","has_public_access_password"};
-//        for (String key : delFiles) {
-//            mpoJson.remove(key);
-//        }
-//
-//        // 2. images数组只保留第一个
-//        JSONArray imagesArray = mpoJson.getJSONArray("images");
-//        JSONObject images0Json= imagesArray.getJSONObject(0);
-//        // 删除images0无用字段
-//        String[] delImage0Files = new String[] {"url", "signed_src", "thumbnail_signed_src", "download_url", "src"};
-//        for (String key : delImage0Files) {
-//            images0Json.remove(key);
-//        }
-//
-//
-//
-//        // 将images更新到mpoJson
-//        imagesArray = new JSONArray();
-//        imagesArray.add(images0Json);
-//
-//        mpoJson.put("images", imagesArray);
-//
-//
-//        // 3. 处理metadata, 封装到camera_start
-//        JSONObject metadataJson = images0Json.getJSONObject("metadata");
-//        String scanId = metadataJson.getString("scan_id");
-//        Integer orthZoom = metadataJson.getInteger("ortho_zoom");
-//        Integer cameraMode = metadataJson.getInteger("camera_mode");
-//        JSONObject cameraQuaternionJson = metadataJson.getJSONObject("camera_quaternion");
-//        Object x = cameraQuaternionJson.get("x");
-//        Object y = cameraQuaternionJson.get("y");
-//        Object z = cameraQuaternionJson.get("z");
-//        Object w = cameraQuaternionJson.get("w");
-//
-//        JSONObject cameraJson = new JSONObject();
-//        cameraJson.put("zoom", orthZoom);
-//
-//        JSONArray quaternionJson = new JSONArray();
-//        quaternionJson.add(0, x);
-//        quaternionJson.add(1, y);
-//        quaternionJson.add(2, z);
-//        quaternionJson.add(3, w);
-//
-//        cameraJson.put("quaternion", quaternionJson);
-//
-//        JSONObject cameraStartJson = new JSONObject();
-//        cameraStartJson.put("camera", cameraJson);
-//
-//        JSONObject uuidJson = new JSONObject();
-//        uuidJson.put("uuid", scanId);
-//        cameraStartJson.put("pano", uuidJson);
-//        cameraStartJson.put("mode", cameraMode);
-//
-//        // 更新camera_start
-//        mpoJson.put("camera_start", cameraStartJson);
-//
-//
-//        // 4. 处理player_options, defaultPlayer是默认值,
-//        HashMap<String, Object> defaultPlayer = new HashMap<>();
-//        defaultPlayer.put("presented_by", true);
-//        defaultPlayer.put("highlight_reel", true);
-//        defaultPlayer.put("floor_plan", true);
-//        defaultPlayer.put("tour_buttons", true);
-//        defaultPlayer.put("dollhouse", true);
-//        defaultPlayer.put("fast_transitions", false);
-//        defaultPlayer.put("autoplay", false);
-//
-//        // 更新默认值
-//        JSONObject playerOptionsJson = mpoJson.getJSONObject("player_options");
-//        defaultPlayer.forEach((key, value)->{
-//            playerOptionsJson.put(key, value);
-//        });
-//
-//        // 更新player_options
-//        mpoJson.put("player_options", playerOptionsJson);
-//
-//
-//        // 5. 添加files
-//        JSONArray templates = new JSONArray();
-//        templates.add("data/{{number}}/{{filename}}");
-//
-//        JSONObject templatesJson = new JSONObject();
-//        templatesJson.put("templates", templates);
-//
-//
-//        // 6. 创建model
-//        JSONObject someDataJson = new JSONObject();
-//        someDataJson.put("model", mpoJson);
-//        someDataJson.put("files", templatesJson);
-//
-//        // 处理json value null
-////        System.out.println(JSONObject.toJSONString(someDataJson, SerializerFeature.WriteMapNullValue));
-////        return JSONObject.toJSONString(someDataJson, SerializerFeature.WriteMapNullValue);
-//        return someDataJson;
-//
-//    }
-
+    private SceneMapper sceneMapper;
 
+    @Autowired
+    private SceneService sceneService;
 
     /**
-     * 给算法查询服务器文件位置
-     * m 是场景码
+     * @param param
+     * @param clientCode 用于验证,每次新增客户需要tb_client加上数据
+     * @return
+     * @throws QiniuException
+     * @throws InterruptedException
      */
-    @ApiOperation("查询服务器文件夹")
-    @GetMapping(value = "getFolder")
-    @ApiImplicitParam(name = "m", value = "场景码", required = true)
-    public Result getFolder(String m) {
-        SceneEntity entity = sceneService.findBySceneCode(m);
-        assert entity != null;
-        log.info("filePath: {}", entity.getPath());
-        return Result.success(entity.getPath());
+    @ApiOperation("编辑场景")
+    @PostMapping("edit/{clientCode}")
+    public Result edit(@Valid @RequestBody SceneDataDto param, @PathVariable String clientCode) throws QiniuException {
+
+        Map code = sceneMapper.findByCode(clientCode);
+        if (code == null) {
+            log.error("客户码有误");
+            return Result.failure("客户码有误,请重新输入");
+        }
+        return sceneService.editScene(param);
     }
 
+    @ApiOperation("漫游可行")
+    @PostMapping("roamViable/{clientCode}")
+    public Result roamViable(@RequestBody RoamViableDto param, @PathVariable String clientCode) throws Exception {
 
-    private void createData2Js(String basePath){
-        JSONObject data2 = new JSONObject();
-        data2.put("audio", "{}");
-        data2.put("hots", "{}");
-        data2.put("weixinDesc", "");
-        data2.put("tourAudio", "{}");
-        data2.put("overlays", "[]");
-        FileUtil.writeUtf8String(data2.toJSONString(),basePath +"/data2.js");
+        Map code = sceneMapper.findByCode(clientCode);
+        if (code == null) {
+            log.error("客户码有误");
+            return Result.failure("客户码有误,请重新输入");
+        }
 
+        return sceneService.roamViable(param);
     }
 
-
     /**
-     * 文件转换
+     * 编辑场景上传多媒体资料
+     * @param file
      * @param sceneCode
-     * @throws Exception
-     */
-//    private void convert(String basePath, String sceneCode, String sceneTitle) throws Exception {
-//
-//        // 将result文件夹的upload.json是否存在,并处理业务逻辑
-//        checkUploadJson(basePath);
-//
-//
-//        if(!FileUtil.exist(basePath+"/vision.txt")){
-//            log.error("文件不存在: " + basePath+"/vision.txt");
-//            Result.failure("文件不存在: " + basePath+"/vision.txt");
-//        }
-//
-//        // 2.vision.txt转vision.modeldata
-//        CreateObjUtil.convertTxtToVisionmodeldata(basePath+"/vision.txt", basePath+"/vision.modeldata");
-//        log.info("vision.modeldata转换完成");
-//
-//        // 3. 生成一个空的data2.js, 里面是一个空的json
-//        FileUtil.writeUtf8String("{}",basePath+"/data2.js");
-//        log.info("data2.js创建完成");
-//
-//        // 4. 创建someData.json, 修改sid值为场景码目录
-//        createSomeData(basePath, sceneCode, sceneTitle);
-//
-//
-//    }
-
-
-    @Test
-    public void createData2JsTest(){
-        String basePath = "F:\\test\\army";
-        FileUtil.writeUtf8String("{}",basePath+"/data2.js");
-    }
-
-
-//    /**
-//     * 创建someData.json
-//     */
-//    private static void createSomeData(String basePath, String sceneCode, String sceneTitle) throws IOException {
-//        String path = ResourceUtils.getURL("classpath:").getPath();
-//        path = path + "data/someData.json";
-//        log.info("path: {}", path);
-//        String os = FileUtil.readUtf8String(path);
-//        JSONObject jsonObject = JSONObject.parseObject(os);
-//        JSONObject model = jsonObject.getJSONObject("model");
-//
-//
-//        // 更新images json
-//        JSONArray imagesJson = updateImagesData(sceneCode);
-//        model.put("images", imagesJson);
-//
-//        // 修改sid值
-//        model.put("sid", sceneCode);
-//        model.put("name", sceneTitle);
-//
-//        // 更新json
-//        jsonObject.put("model", model);
-//
-//
-//        FileUtil.writeUtf8String(jsonObject.toJSONString(), basePath+"/someData.json");
-//
-//        log.info("someData.json创建完成");
-//
-//    }
-
-    public static void main(String[] args) throws IOException {
-        String path = "F:\\test\\army\\upload.json";
-
-        String suffix = StringUtils.substringAfterLast(path, ".");
-        System.out.println(suffix);
-
-
-
-    }
-
-
-    /**
-     * 创建images.json
-     * 如果数据格式有变动,要作出响应的修改
+     * @return
+     * @throws IOException
      */
-//    private static JSONArray updateImagesData(String sceneCode) throws IOException {
-//        String resourceUrl = FileUtils.getResourceUrl("data/images.json");
-//        String os = FileUtil.readUtf8String(resourceUrl);
-//        JSONObject imageObject = JSONObject.parseObject(os);
-//        imageObject.put("sid", sceneCode);
-//
-//        JSONArray imagesArray = new JSONArray();
-//        imagesArray.set(0, imageObject);
-//
-//        return imagesArray;
-//    }
+    @ApiOperation(value = "编辑场景上传", notes = "编辑场景使用,根据场景码位置上传")
+    @PostMapping(value = "upload/{sceneCode}", consumes = {"multipart/form-data"})
+    public Result upload(MultipartFile file , @PathVariable String sceneCode)  {
 
-    /**
-     * 检查upload.json文件是否存在,执行业务逻辑
-     */
-//    private static void checkUploadJson(String basePath) throws Exception {
-//        String uploadJsonPath = basePath + "/results/upload.json";
-////        String uploadJsonPath = "F:\\test\\army\\upload.json";
-//        boolean isUploadJsonPath = FileUtil.isFile(uploadJsonPath);
-//        if (!isUploadJsonPath) {
-//            log.error("算法的upload.json不存在");
-//            throw new BaseRuntimeException(5000, "算法的upload.json不存在");
-//
-//        }
-//        // 判断upload.json文件是否都存在
-//        String os = FileUtil.readUtf8String(uploadJsonPath);
-//        JSONObject imageObject = JSONObject.parseObject(os);
-//
-//        // json数组
-//        JSONArray jsonArray = imageObject.getJSONArray("upload");
-//        for (int i = 0; i < jsonArray.size(); i++) {
-//            JSONObject jsonObject = jsonArray.getJSONObject(i);
-//            String fileName = jsonObject.getString("file");
-//            String filePath = basePath + "/results/" + fileName;
-//
-//            boolean isFilePath = FileUtil.isFile(filePath);
-//            if (!isFilePath) {
-//                log.error("算法的upload.json数据文件:  {}", filePath );
-//                throw new BaseRuntimeException(5000, "算法的upload.json数据文件不存在");
-//
-//            }
-//
-//            String suffix = StringUtils.substringAfterLast(filePath, ".");
-//            // 把图片复制到指定目录(dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high)
-//            if ("jpg".equals(suffix)) {
-//                FileUtil.copy(filePath, basePath+"/" + ConstantFileName.modelUUID+"_50k_texture_jpg_high/" + fileName, true);
-//            }
-//
-//            // 将modeldata.txt转xxx.dam
-//            if ("txt".equals(suffix)) {
-//                CreateObjUtil.convertTxtToDam(filePath, basePath+"/" + ConstantFileName.modelUUID+"_50k.dam");
-//                log.info("dam转换完成");
-//
-//            }
-//
-//        }
-//    }
-
-
-    @Test
-    public void ba64(){
-        String basePath = "F:\\test\\army";
-        FileUtil.writeUtf8String("{}",basePath+"/data2.js");
-    }
-
-
-
-    @Test
-    public void modelDataTxtToDam() throws Exception {
-        String inPath = "C:\\Users\\Administrator\\Desktop\\test\\modeldata.txt";
-        String outPath = "C:\\Users\\Administrator\\Desktop\\test";
+        // 返回前端数据
+        return sceneService.editUpload(file, sceneCode);
 
-        CreateObjUtil.convertTxtToDam(inPath, outPath+"/" + ConstantFileName.modelUUID+"_50k.dam");
     }
 
 
-//    @ApiOperation("场景列表")
-//    @PostMapping("list")
-//    public Result<SceneEntity> list(@RequestBody PageDto param) {
-//
-//        startPage(param);
-//        PageInfo<SceneEntity> page = new PageInfo<>(sceneService.search(param));
-//        return Result.success(page);
-//    }
-
-
-//    @ApiOperation("编辑场景")
-//    @PostMapping("edit")
-//    public Result edit(@Valid @RequestBody SceneDataDto param) throws QiniuException {
-//
-//        String sceneCode = param.getSceneCode();
-//
-//        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
-//        if (entity == null) {
-//            log.error("场景不存在 : {}", sceneCode);
-//            return Result.failure("场景不存在");
-//        }
-//
-//
-//        // 处理someData.json, 网络下载someData.json
-//        String someDataName = "someData.json";
-//        // 注意网络下载会有缓存,必须加时间戳
-//        String someDataUrl = OSS_DOMAIN + OSS_PATH + sceneCode + "/" + someDataName+ "?m=" + System.currentTimeMillis();
-//        log.info("网络下载文件地址: {}", someDataUrl);
-//        String localBasePath = FILE_PATH + sceneCode;
-//        FileUtils.downLoadFromUrl(someDataUrl, someDataName, localBasePath);
-//        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) {
-//                String name = infoJson.getString("name");
-//                model.put("name", name);
-//
-//                // update 场景名称
-//                if (!name.equals(entity.getSceneTitle())) {
-//                    entity.setSceneTitle(name);
-//                    entity.setUpdateTime(new Date());
-//                    sceneService.update(entity);
-//                }
-//
-//                model.put("summary", infoJson.get("summary"));
-//                model.put("camera_start", infoJson.getJSONObject("camera_start"));
-//
-//                if (guidesArray != null) {
-//                    model.put("images", guidesArray);
-//                } else {
-//                    model.put("images", new JSONArray());
-//                }
-//
-//
-//            }
-//
-//            // 更新someDataJson
-//            someDataJson.put("model", model);
-//            someDataJson.put("loadlogo", infoJson.get("loadlogo"));
-//            someDataJson.put("supportsVR", infoJson.getBoolean("supportsVR"));
-//            someDataJson.put("backgroundMusic", infoJson.getString("backgroundMusic"));
-//
-//            // 删除旧someDataJson
-//            FileUtil.del(someDataPath);
-//            // 写入新someDataJson
-//            FileUtil.writeUtf8String(someDataJson.toJSONString(), someDataPath);
-//            log.info("someData.json写入完成");
-//
-//            // 将新的someDataJson上传oss
-//            QiniuOssUtil.upload(someDataPath, OSS_PATH + sceneCode + "/" + someDataName);
-//            log.info(someDataName+ "已上传到七牛云");
-//
-//        }
-//
-//        // 处理data2.js
-//
-//        String data2Name = "data2.js";
-//        // 注意网络下载会有缓存,必须加时间戳
-//        String data2Url = OSS_DOMAIN + OSS_PATH + sceneCode + "/" + data2Name+ "?m=" + System.currentTimeMillis();
-//        log.info("网络下载文件地址: {}", data2Url);
-//        FileUtils.downLoadFromUrl(data2Url, data2Name, localBasePath);
-//
-//        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());
-//        }
-//
-//        String overlays = param.getOverlays();
-//        if (overlays != null) {
-//            data2Json.put("overlays", JSONObject.parseArray(overlays));
-//        } else {
-//            data2Json.put("overlays", new JSONArray());
-//        }
-//
-//        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;
-//                // 将link 添加进去
-//                subJson.put("link", url);
-//            }
-//            data2Json.put("hots", hotJson);
-//        } else {
-//            data2Json.put("hots", new JSONObject());
-//        }
-//
-//        // 处理guidesArray,将scan_id的值作为key, value:  time":40000
-//        JSONObject audioJson = new JSONObject();
-//        JSONObject timeJson = new JSONObject();
-//        timeJson.put("time", 40000);
-//        if (guidesArray != null) {
-//
-//            for (int i = 0; i < guidesArray.size() ; i++) {
-//                JSONObject metadata = guidesArray.getJSONObject(i).getJSONObject("metadata");
-//                if (metadata != null) {
-//                    String scanId = metadata.getString("scan_id");
-//                    audioJson.put(scanId, timeJson);
-//                }
-//            }
-//
-//            data2Json.put("audio", audioJson);
-//        }
-//
-//
-//        // 删除旧data2.js
-//        FileUtil.del(data2Path);
-//        // 写入新data2.js
-//        FileUtil.writeUtf8String(data2Json.toJSONString(), data2Path);
-//        log.info("新data2.js写入完成");
-//
-//        // 将新的someDataJson上传oss
-//        QiniuOssUtil.upload(data2Path, OSS_PATH + sceneCode + "/" + data2Name);
-//        log.info(data2Name+ "已上传到七牛云");
-//
-//        //处理data.js 文件
-//        editDataJs(sceneCode, entity, hots);
-//
-//
-//        return Result.success();
-//    }
-
-
-//    /**
-//     * 处理data.js 文件
-//     */
-//    private void editDataJs(String sceneCode, SceneEntity entity, String hots ) throws QiniuException {
-//
-//        // 因为data.js只是热点信息,所以直接创建上传oss
-//        JSONObject dataJsJson = new JSONObject();
-//        if (hots != null) {
-//             dataJsJson = JSONObject.parseObject(hots);
-//
-//            Set<String> strings = dataJsJson.keySet();
-//            for (String key: strings) {
-//                JSONObject subJson = dataJsJson.getJSONObject(key);
-//                JSONObject infoAttribute = subJson.getJSONObject("infoAttribute");
-//                if (infoAttribute != null) {
-//                    Set<String> infoKey = infoAttribute.keySet();
-//
-//                    for (String s: infoKey) {
-//                        Object val = null;
-//                        // 添加到第一层, 空值不添加
-//                        if ("images".equals(s) || "styleImg".equals(s) || "model".equals(s) || "video".equals(s) || "iframe".equals(s)) {
-//                            JSONArray jsonArray = infoAttribute.getJSONArray(s);
-//                            if (jsonArray.size() == 0) {
-//                                continue;
-//                            }
-//                            val = jsonArray;
-//
-//                        } else {
-//                           String a = infoAttribute.getString(s);
-//                            if (StringUtils.isBlank(a)){
-//                                continue;
-//                            }
-//                            val = a;
-//                        }
-//
-//
-//                        subJson.put(s, val);
-//                    }
-//
-//                }
-//
-//                // 删除infoAttribute
-//                subJson.remove("infoAttribute");
-//
-//            }
-//
-//        }
-//        String dataPath = entity.getPath() + "/data.js";
-//        FileUtil.writeUtf8String(dataJsJson.toJSONString(), dataPath);
-////        log.info("data.js {}", dataJsJson);
-//
-//
-//
-//
-//        //上传oss
-//        String ossPath = OSS_PATH + sceneCode + "/hot/js/data.js";
-//        QiniuOssUtil.upload(dataPath, ossPath);
-//        log.info("data.js已上传到七牛云: {}", ossPath);
-//
-//
-//    }
-
-
-//    /**
-//     * 编辑场景上传多媒体资料
-//     * @param file
-//     * @param sceneCode
-//     * @return
-//     * @throws IOException
-//     */
-//    @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 basePath = entity.getPath() + "/edit/";
-//        // 时间戳重新命名
-//        HashMap<String, String> map = FileUtils.upload(file, basePath);
-//        String newName = map.get("newName");
-//        String savePath = basePath + newName;
-//
-//        log.info("文件写入成功: {}", savePath);
-//
-//        // 上传到oss
-//        String ossUploadPath = OSS_PATH + sceneCode + "/edit/" + newName;
-//        String ossPath = OSS_DOMAIN + ossUploadPath;
-//        QiniuOssUtil.upload(savePath, ossUploadPath);
-//        log.info("文件上传到oss完成: {}", ossPath);
-//
-//        // 返回前端数据
-//        return Result.success((Object) ossPath);
-//
-//    }
 
 
 }

+ 237 - 283
gis_web/src/main/java/com/gis/web/controller/SceneController.java

@@ -71,6 +71,12 @@ public class SceneController extends BaseController {
             return Result.failure("场景码不能为空");
         }
 
+        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
+        if (entity != null) {
+            log.error("场景码已存在");
+            return Result.failure("场景码已存在,请重新输入");
+        }
+
         // 场景url
         String webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
         log.info("webSite: {}", webSite);
@@ -94,7 +100,7 @@ public class SceneController extends BaseController {
         // data2.js上传oss
         QiniuOssUtil.upload(data2Path, ossPath + data2Info);
 
-        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
+
         if (entity == null) {
             entity = new SceneEntity();
             // 场景码数据库设置唯一
@@ -195,266 +201,212 @@ public class SceneController extends BaseController {
     }
 
 
+//    @ApiOperation("编辑场景")
+//    @PostMapping("edit")
+//    public Result edit(@Valid @RequestBody SceneDataDto param) throws QiniuException, InterruptedException {
+//
+//        String sceneCode = param.getSceneCode();
+//
+//        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
+//        if (entity == null) {
+//            log.error("场景不存在 : {}", sceneCode);
+//            return Result.failure("场景不存在");
+//        }
+//
+//
+//        // 处理someData.json, 网络下载someData.json
+//        String someDataName = "someData.json";
+//        // 注意网络下载会有缓存,必须加时间戳
+//        String someDataUrl = OSS_DOMAIN + OSS_PATH + sceneCode + "/" + someDataName+ "?m=" + System.currentTimeMillis();
+//        log.info("网络下载文件地址: {}", someDataUrl);
+//        String localBasePath = FILE_PATH + sceneCode;
+//        FileUtils.downLoadFromUrl(someDataUrl, someDataName, localBasePath);
+//        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) {
+//                String name = infoJson.getString("name");
+//                model.put("name", name);
+//
+//                // update 场景名称
+//                if (!name.equals(entity.getSceneTitle())) {
+//                    entity.setSceneTitle(name);
+//                    entity.setUpdateTime(new Date());
+//                    sceneService.update(entity);
+//                }
+//
+//                model.put("summary", infoJson.get("summary"));
+//
+////                model.put("camera_start", infoJson.getJSONObject("camera_start"));
+//
+//                if (guidesArray != null) {
+//                    model.put("images", guidesArray);
+//                } else {
+//                    model.put("images", new JSONArray());
+//                }
+//
+//                // camera_start放到最外层
+////                someDataJson.put("camera_start", infoJson.getJSONObject("camera_start"));
+//            }
+//
+//            // 更新someDataJson
+//            someDataJson.put("model", model);
+//
+//            // 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写入完成");
+//
+//            // 将新的someDataJson上传oss
+//            QiniuOssUtil.upload(someDataPath, OSS_PATH + sceneCode + "/" + someDataName);
+//            log.info(someDataName+ "已上传到七牛云");
+//
+//        }
+//
+//        // 处理data2.js
+//
+//        String data2Name = "data2.js";
+//        // 注意网络下载会有缓存,必须加时间戳
+//        String data2Url = OSS_DOMAIN + OSS_PATH + sceneCode + "/" + data2Name+ "?m=" + System.currentTimeMillis();
+//        log.info("网络下载文件地址: {}", data2Url);
+//        FileUtils.downLoadFromUrl(data2Url, data2Name, localBasePath);
+//
+//        String data2Path = entity.getPath() + File.separator + data2Name;
+//        log.info("data2.js文件位置: {}", data2Path);
+//
+//        if (!FileUtil.exist(data2Path)) {
+//            log.error("data2.js文件不存在: {}", data2Path);
+//            return Result.failure("data2.js文件不存在");
+//        }
+//
+//
+//        String data2 = FileUtil.readUtf8String(data2Path);
+//        JSONObject data2Json = JSONObject.parseObject(data2);
+//
+////        log.info("old data2Json: " + data2Json.toJSONString());
+//
+//        String tourAudio = param.getTourAudio();
+//        if (tourAudio != null) {
+//            data2Json.put("tourAudio", JSONObject.parseObject(tourAudio));
+//        } else {
+//            data2Json.put("tourAudio", new JSONObject());
+//        }
+//
+//        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));
+//
+//                }
+////                log.info("audioJson: " + i + ":" + audioJson.toJSONString());
+//            }
+//
+//            // 新增audio
+//            data2Json.put("audio", audioJson);
+//        }
+//
+////        log.info("new datajs: " + data2Json.toJSONString());
+//
+//        // host在data2.js、data.js都需要处理
+//        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;
+//                // 将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写入完成");
+//
+//        // 将新的someDataJson上传oss
+//        QiniuOssUtil.upload(data2Path, OSS_PATH + sceneCode + "/" + data2Name);
+//        log.info(data2Name+ "已上传到七牛云");
+//
+//        //处理data.js 文件
+//        editDataJs(sceneCode, entity, hots);
+//
+//
+//        return Result.success();
+//    }
+
+
     @ApiOperation("编辑场景")
     @PostMapping("edit")
     public Result edit(@Valid @RequestBody SceneDataDto param) throws QiniuException, InterruptedException {
-
-        String sceneCode = param.getSceneCode();
-
-        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
-        if (entity == null) {
-            log.error("场景不存在 : {}", sceneCode);
-            return Result.failure("场景不存在");
-        }
-
-
-        // 处理someData.json, 网络下载someData.json
-        String someDataName = "someData.json";
-        // 注意网络下载会有缓存,必须加时间戳
-        String someDataUrl = OSS_DOMAIN + OSS_PATH + sceneCode + "/" + someDataName+ "?m=" + System.currentTimeMillis();
-        log.info("网络下载文件地址: {}", someDataUrl);
-        String localBasePath = FILE_PATH + sceneCode;
-        FileUtils.downLoadFromUrl(someDataUrl, someDataName, localBasePath);
-        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) {
-                String name = infoJson.getString("name");
-                model.put("name", name);
-
-                // update 场景名称
-                if (!name.equals(entity.getSceneTitle())) {
-                    entity.setSceneTitle(name);
-                    entity.setUpdateTime(new Date());
-                    sceneService.update(entity);
-                }
-
-                model.put("summary", infoJson.get("summary"));
-
-//                model.put("camera_start", infoJson.getJSONObject("camera_start"));
-
-                if (guidesArray != null) {
-                    model.put("images", guidesArray);
-                } else {
-                    model.put("images", new JSONArray());
-                }
-
-                // camera_start放到最外层
-//                someDataJson.put("camera_start", infoJson.getJSONObject("camera_start"));
-            }
-
-            // 更新someDataJson
-            someDataJson.put("model", model);
-
-            // 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写入完成");
-
-            // 将新的someDataJson上传oss
-            QiniuOssUtil.upload(someDataPath, OSS_PATH + sceneCode + "/" + someDataName);
-            log.info(someDataName+ "已上传到七牛云");
-
-        }
-
-        // 处理data2.js
-
-        String data2Name = "data2.js";
-        // 注意网络下载会有缓存,必须加时间戳
-        String data2Url = OSS_DOMAIN + OSS_PATH + sceneCode + "/" + data2Name+ "?m=" + System.currentTimeMillis();
-        log.info("网络下载文件地址: {}", data2Url);
-        FileUtils.downLoadFromUrl(data2Url, data2Name, localBasePath);
-
-        String data2Path = entity.getPath() + File.separator + data2Name;
-        log.info("data2.js文件位置: {}", data2Path);
-
-        if (!FileUtil.exist(data2Path)) {
-            log.error("data2.js文件不存在: {}", data2Path);
-            return Result.failure("data2.js文件不存在");
-        }
-
-
-        String data2 = FileUtil.readUtf8String(data2Path);
-        JSONObject data2Json = JSONObject.parseObject(data2);
-
-//        log.info("old data2Json: " + data2Json.toJSONString());
-
-        String tourAudio = param.getTourAudio();
-        if (tourAudio != null) {
-            data2Json.put("tourAudio", JSONObject.parseObject(tourAudio));
-        } else {
-            data2Json.put("tourAudio", new JSONObject());
-        }
-
-        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));
-
-                }
-//                log.info("audioJson: " + i + ":" + audioJson.toJSONString());
-            }
-
-            // 新增audio
-            data2Json.put("audio", audioJson);
-        }
-
-//        log.info("new datajs: " + data2Json.toJSONString());
-
-        // host在data2.js、data.js都需要处理
-        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;
-                // 将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写入完成");
-
-        // 将新的someDataJson上传oss
-        QiniuOssUtil.upload(data2Path, OSS_PATH + sceneCode + "/" + data2Name);
-        log.info(data2Name+ "已上传到七牛云");
-
-        //处理data.js 文件
-        editDataJs(sceneCode, entity, hots);
-
-
-        return Result.success();
-    }
-
-
-    /**
-     * 处理data.js 文件
-     */
-    private void editDataJs(String sceneCode, SceneEntity entity, String hots ) throws QiniuException {
-
-        // 因为data.js只是热点信息,所以直接创建上传oss
-        JSONObject dataJsJson = new JSONObject();
-        if (hots != null) {
-            dataJsJson = JSONObject.parseObject(hots);
-
-            Set<String> strings = dataJsJson.keySet();
-            for (String key: strings) {
-                JSONObject subJson = dataJsJson.getJSONObject(key);
-                JSONObject infoAttribute = subJson.getJSONObject("infoAttribute");
-                if (infoAttribute != null) {
-                    Set<String> infoKey = infoAttribute.keySet();
-
-                    for (String s: infoKey) {
-                        Object val = null;
-                        // 添加到第一层, 空值不添加
-                        if ("images".equals(s) || "styleImg".equals(s) || "model".equals(s) || "video".equals(s) || "iframe".equals(s)) {
-                            JSONArray jsonArray = infoAttribute.getJSONArray(s);
-                            if (jsonArray.size() == 0) {
-                                continue;
-                            }
-                            val = jsonArray;
-
-                        } else {
-                            String a = infoAttribute.getString(s);
-                            if (StringUtils.isBlank(a)){
-                                continue;
-                            }
-                            val = a;
-                        }
-
-                        subJson.put(s, val);
-                    }
-                }
-
-                // 删除infoAttribute
-                subJson.remove("infoAttribute");
-
-            }
-
-        }
-        String dataPath = entity.getPath() + "/data.js";
-        FileUtil.writeUtf8String(dataJsJson.toJSONString(), dataPath);
-//        log.info("data.js {}", dataJsJson);
-
-
-
-
-        //上传oss
-        String ossPath = OSS_PATH + sceneCode + "/hot/js/data.js";
-        QiniuOssUtil.upload(dataPath, ossPath);
-        log.info("data.js已上传到七牛云: {}", ossPath);
-
-
+        return sceneService.editScene(param);
     }
 
 
@@ -597,33 +549,35 @@ public class SceneController extends BaseController {
     @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 basePath = entity.getPath() + "/edit/";
-        // 时间戳重新命名
-        HashMap<String, String> map = FileUtils.upload(file, basePath);
-        String newName = map.get("newName");
-        String savePath = basePath + newName;
-
-        log.info("文件写入成功: {}", savePath);
-
-        // 上传到oss
-        String ossUploadPath = OSS_PATH + sceneCode + "/edit/" + newName;
-        String ossPath = OSS_DOMAIN + ossUploadPath;
-        QiniuOssUtil.upload(savePath, ossUploadPath);
-        log.info("文件上传到oss完成: {}", ossPath);
+//        Result result = sceneService.editUpload(file, sceneCode);
+
+//        if (file == null) {
+//            log.error("文件不能为空");
+//            return Result.failure("文件不能为空");
+//        }
+//
+//        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
+//        if (entity == null) {
+//            log.error("场景不存在: {}", sceneCode);
+//            return Result.failure("场景不存在");
+//        }
+//
+//        String basePath = entity.getPath() + "/edit/";
+//        // 时间戳重新命名
+//        HashMap<String, String> map = FileUtils.upload(file, basePath);
+//        String newName = map.get("newName");
+//        String savePath = basePath + newName;
+//
+//        log.info("文件写入成功: {}", savePath);
+//
+//        // 上传到oss
+//        String ossUploadPath = OSS_PATH + sceneCode + "/edit/" + newName;
+//        String ossPath = OSS_DOMAIN + ossUploadPath;
+//        QiniuOssUtil.upload(savePath, ossUploadPath);
+//        log.info("文件上传到oss完成: {}", ossPath);
 
         // 返回前端数据
-        return Result.success((Object) ossPath);
+        return sceneService.editUpload(file, sceneCode);
 
     }