浏览代码

大场景
更新无用代码

wuweihao 5 年之前
父节点
当前提交
7bae900414

+ 3 - 0
README.md

@@ -11,6 +11,9 @@
          http://space3d.4dage.com/8105/doc.html
          http://47.107.252.54:8105/doc.html
          
+         大场景列表:
+         http://47.107.252.54:8105/list/index.html
+         
     
     <Context path="" docBase="/root/user/java/tomcat_cmsBigScene_8105/webapps/cmsBigScene" debug="0" reloadable="true" crossContext="true"/>
     /root/user/java/tomcat_cmsBigScene_8105/webapps

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

@@ -53,7 +53,8 @@ logging.level.com.gis=debug
 
 # ±¾µØ±£´æÂ·¾¶
 file.path=F:\\test\\ngin\\bin_scene\\
-server.domain =http://192.168.0.135/
+#server.domain =http://192.168.0.135/
+server.domain =http://www.4dmodel.com/
 
 # ÆßÅ£ oss info
 oss.file.path=data/

+ 0 - 38
gis_domain/src/main/java/com/gis/domain/po/FileEntity.java

@@ -1,38 +0,0 @@
-package com.gis.domain.po;
-
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-
-import javax.persistence.Table;
-import java.io.Serializable;
-
-/**
- * 文件表
- */
-@Data
-@Table(name = "tb_file")
-public class FileEntity extends BaseEntity implements Serializable {
-
-    private static final long serialVersionUID = -5191917184688236778L;
-
-
-    @ApiModelProperty(value = "文件名")
-    private String fileName;
-
-    @ApiModelProperty(value = "文件保存路径")
-    private String filePath;
-
-    @ApiModelProperty(value = "访问url")
-    private String urlPath;
-
-    @ApiModelProperty(value = "缩略图url")
-    private String thumb;
-
-    @ApiModelProperty(value = "封面图,1:是,0:否")
-    private Integer cover;
-
-    @ApiModelProperty(value = "外键id")
-    private String fkId;
-
-
-}

+ 0 - 25
gis_mapper/src/main/java/com/gis/mapper/FileMapper.java

@@ -1,25 +0,0 @@
-package com.gis.mapper;
-
-
-import com.gis.domain.po.FileEntity;
-import com.gis.mapper.provider.FileProvider;
-import org.apache.ibatis.annotations.*;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-
-
-@Component
-@Mapper
-public interface FileMapper extends IBaseMapper<FileEntity, Long> {
-
-
-    @SelectProvider(type = FileProvider.class, method = "setFkIdByIds")
-    void setFkIdByIds(String ids, String fkId);
-
-    @Select(value = "select * from tb_file where rec_status = 'A' AND fk_id = #{fkId}")
-    List<FileEntity> findByFkId(String fkId);
-
-    @Delete(value = "DELETE FROM tb_file WHERE fk_id = #{fkId}")
-    void deleteByFkId(String fkId);
-}

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

@@ -22,9 +22,9 @@ 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();
-
-    @Update("update tb_scene set display = 1 where id = #{id} ")
-    void setDisplay(Long id);
+//    @Update("update tb_scene set display = 0 where display = 1 ")
+//    void setDisable();
+//
+//    @Update("update tb_scene set display = 1 where id = #{id} ")
+//    void setDisplay(Long id);
 }

+ 0 - 27
gis_mapper/src/main/java/com/gis/mapper/provider/FileProvider.java

@@ -1,27 +0,0 @@
-package com.gis.mapper.provider;
-
-import lombok.extern.log4j.Log4j2;
-
-/**
- * Created by owen on 2020/6/13 0013 10:56
- */
-@Log4j2
-public class FileProvider {
-
-
-    public String setFkIdByIds(String ids, String fkId){
-        StringBuffer sql = new StringBuffer(
-                        "UPDATE tb_file SET");
-
-        if (fkId != null) {
-            sql.append(" fk_id = '").append(fkId).append("'");
-        }
-
-        if (ids != null) {
-            sql.append("  WHERE id in ( ").append(ids).append(" )");
-        }
-
-        log.info("sql: {}", sql.toString());
-        return sql.toString();
-    }
-}

+ 5 - 2
gis_mapper/src/main/java/com/gis/mapper/provider/SceneProvider.java

@@ -17,10 +17,13 @@ public class SceneProvider {
 
         String searchKey = param.getSearchKey();
         if(!StringUtils.isAllBlank(searchKey)){
-            sql.append(" and ( scene_title like '%").append(searchKey).append("%' )");
+            sql.append(" and (");
+            sql.append("( scene_title like '%").append(searchKey).append("%' )");
+            sql.append(" or ( scene_code like '%").append(searchKey).append("%' )");
+            sql.append(")");
         }
 
-        sql.append(" order by display desc, create_time desc");
+        sql.append(" order by create_time desc");
         log.info("sql: {}", sql.toString());
         return sql.toString();
     }

+ 0 - 19
gis_service/src/main/java/com/gis/service/FileService.java

@@ -1,19 +0,0 @@
-package com.gis.service;
-
-
-import com.gis.domain.po.FileEntity;
-
-import java.util.List;
-
-/**
- * Created by owen on 2020/5/11 0011 16:14
- */
-public interface FileService extends IBaseService<FileEntity, Long> {
-
-
-    void setFkIdByIds(String ids, String fkId);
-
-    List<FileEntity> findByFkId(String fkId);
-
-    void deleteByFkId(String fkId);
-}

+ 0 - 42
gis_service/src/main/java/com/gis/service/impl/FileServiceImpl.java

@@ -1,42 +0,0 @@
-package com.gis.service.impl;
-
-import com.gis.domain.po.FileEntity;
-import com.gis.mapper.FileMapper;
-import com.gis.mapper.IBaseMapper;
-import com.gis.service.FileService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-
-/**
- * Created by owen on 2020/5/11 0011 16:16
- */
-@Service
-public class FileServiceImpl extends IBaseServiceImpl<FileEntity, Long> implements FileService {
-
-    @Autowired
-    private FileMapper entityMapper;
-
-    @Override
-    public IBaseMapper<FileEntity, Long> getBaseMapper() {
-        return this.entityMapper;
-    }
-
-
-    @Override
-    public void setFkIdByIds(String ids, String fkId) {
-        entityMapper.setFkIdByIds(ids, fkId);
-    }
-
-    @Override
-    public List<FileEntity> findByFkId(String fkId) {
-        return entityMapper.findByFkId(fkId);
-    }
-
-    @Override
-    public void deleteByFkId(String fkId) {
-        entityMapper.deleteByFkId(fkId);
-    }
-}

+ 12 - 8
gis_web/src/main/java/com/gis/web/aop/WebLogAspect.java

@@ -36,20 +36,24 @@ public class WebLogAspect {
     @Before("controllerLog()") //在切入点的方法run之前要干的
     public void logBeforeController(JoinPoint joinPoint) throws Exception {
 
-        // 获取token
-        String token = request.getHeader("token");
-        Long userId = null;
-        if (token != null) {
-            userId = JwtUtil.getUserId(token);
-        }
-
-        // 记录下请求内容
+        // 记录请求内容
         log.warn("start : {}" , request.getRequestURI());
         log.info("request Method : {}" , request.getMethod());
         log.info("request IP : {}" , request.getRemoteAddr());
         log.info("request Args : {}" , Arrays.toString(joinPoint.getArgs()));
 
+        // 获取token
+        String token = request.getHeader("token");
+
+        // 排除登录接口
+        if (request.getRequestURI().contains("/admin/login") || request.getRequestURI().contains("/manage/scene/uploads")) {
+            return;
+        }
 
+//        Long userId = null;
+//        if (token != null) {
+//            userId = JwtUtil.getUserId(token);
+//        }
 
         String description = getControllerLogDescription(joinPoint);
 

文件差异内容过多而无法显示
+ 524 - 521
gis_web/src/main/java/com/gis/web/controller/ApiController.java


+ 1 - 7
gis_web/src/main/java/com/gis/web/controller/BaseController.java

@@ -1,7 +1,6 @@
 package com.gis.web.controller;
 
 import com.gis.domain.po.SysUserEntity;
-import com.gis.service.FileService;
 import com.gis.service.SysUserService;
 import com.gis.web.shiro.JwtUtil;
 import com.github.pagehelper.PageHelper;
@@ -24,8 +23,6 @@ public class BaseController {
     public SysUserService sysUserService;
 
 
-    @Autowired
-    public FileService fileService;
 
 
     /**
@@ -60,10 +57,7 @@ public class BaseController {
         return JwtUtil.getUserId(getToken());
     }
 
-    /** 获取用户角色*/
-//    String getTokenUserRole(){
-//        return JwtUtil.getUserRole(getToken());
-//    }
+
 
     SysUserEntity getSysUser(){
         return sysUserService.findById(getTokenUserId());

+ 0 - 181
gis_web/src/main/java/com/gis/web/controller/FileController.java

@@ -1,181 +0,0 @@
-package com.gis.web.controller;
-
-
-import cn.hutool.core.img.ImgUtil;
-import cn.hutool.core.io.FileUtil;
-import com.gis.common.util.FileUtils;
-import com.gis.common.util.Result;
-import com.gis.domain.po.FileEntity;
-import com.gis.service.FileService;
-import io.swagger.annotations.Api;
-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.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-import springfox.documentation.annotations.ApiIgnore;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-
-/**
- * Created by owen on 2020/5/9 0018 12:17
- */
-@ApiIgnore
-@Log4j2
-@Api(tags = "文件服务")
-@RestController
-@RequestMapping("manage/file")
-public class FileController extends BaseController {
-
-    @Autowired
-    private FileService fileService;
-
-    /**
-     * 到时后商量是否全部图片都要生成缩略图
-     * @param file
-     * @return
-     * @throws IOException
-     */
-    @ApiOperation(value = "上传")
-    @PostMapping(value = "upload", consumes = {"multipart/form-data"})
-    public Result upload(MultipartFile file) throws IOException {
-
-        if (file == null) {
-            log.error("文件不能为空");
-            return Result.failure("文件不能为空");
-        }
-
-        // 写入本地服务器
-        HashMap<String, String> fileInfo = FileUtils.upload(file, FILE_PATH);
-
-
-        // 保存db
-        FileEntity entity = new FileEntity();
-        entity.setFileName(fileInfo.get("name"));
-
-        String filePath = fileInfo.get("path");
-        entity.setFilePath(filePath);
-
-        String newName = fileInfo.get("newName");
-        String urlPath = SERVER_DOMAIN+"data/media/" + newName;
-        entity.setUrlPath(urlPath);
-        log.info("文件生成完成: {}", urlPath);
-
-
-
-        // 图片生成缩略图
-//        if (ifImage(newName)) {
-//
-//            String thumbPath = basePath + "thumb_" + newName;
-//            createThumb(filePath, thumbPath);
-//
-//            String thumbUrl = SERVER_DOMAIN+"data/media/thumb_" + newName;
-//            entity.setThumb(thumbUrl);
-//        }
-
-
-        fileService.save(entity);
-
-        // 返回前端数据
-        return Result.success(entity);
-
-    }
-
-
-    @ApiIgnore
-    @ApiOperation("上传, 可以接收多个文件")
-    @PostMapping(value = "uploads", consumes = {"multipart/form-data"})
-    public Result uploads(MultipartFile [] file ) throws IOException {
-
-        if (file.length <= 0) {
-            log.error("文件不能为空");
-            return Result.failure("文件不能为空");
-        }
-
-        // 写入本地服务器
-        List<Map<String, String>> uploads = FileUtils.uploads(file, FILE_PATH);
-
-        HashMap<String, String> resultMap = new HashMap<>();
-        String dir = null;
-        for (Map<String, String> map: uploads) {
-            String fileName = map.get("name");
-            String newName = map.get("newName");
-            String path = FILE_PATH+"/" + newName;
-            String filePath = map.get("path");
-            log.info("local {}, ", filePath);
-            // urlPath
-            dir = map.get("dir");
-            String urlPath = SERVER_DOMAIN+"data/"+dir+"/"+newName;
-
-            // 保存db
-            FileEntity entity = new FileEntity();
-            entity.setFileName(fileName);
-//            String ossUrl = OSS_DOMAIN+ossPath;
-            entity.setFilePath(filePath);
-            entity.setUrlPath(urlPath);
-
-            // 创建缩略图
-
-            fileService.save(entity);
-
-            // 返回前端数据
-            resultMap.put(entity.getId().toString(), entity.getUrlPath());
-//            dir = map.get("dir");
-        }
-
-        // 删除本地服务器物理文件,用删除目录的方式
-//        FileUtil.del(OUT_PATH + dir);
-
-        return Result.success(resultMap);
-
-    }
-
-    /**
-     * 创建缩略图
-     * @param filePath
-     * @return
-     */
-    private String createThumb(String filePath, String savePath){
-        ImgUtil.scale(FileUtil.file(filePath), FileUtil.file(savePath), 0.2f);
-
-        return null;
-    }
-
-
-
-
-
-
-    /**
-     * 硬删除物理文件
-     */
-    @ApiOperation("删除")
-    @GetMapping("remove/{id}")
-    public Result remove(@PathVariable Long id) {
-        FileEntity entity = fileService.findById(id);
-        if (entity == null) {
-            log.error("对象id不存在: {}", id);
-            return Result.failure("对象id不存在");
-        }
-
-        FileUtil.del(entity.getFilePath());
-
-        fileService.delete(entity);
-        return Result.success();
-    }
-
-
-    private boolean ifImage(String fileName){
-        String s = StringUtils.substringAfterLast(fileName, ".");
-        List<String> strings = Arrays.asList("jpg", "png","jpeg");
-        return strings.contains(s);
-    }
-
-}

+ 1 - 2
gis_web/src/main/java/com/gis/web/controller/IndexController.java

@@ -65,8 +65,7 @@ public class IndexController extends BaseController{
         HashMap<String, Object> tokenMap = new HashMap<>();
         tokenMap.put("userName", entity.getUserName());
         tokenMap.put("id", entity.getId());
-//        tokenMap.put("role", userEntity.getRole());
-//        tokenMap.put("manager", entity.getManager());
+
 
         // 创建新token
         String token = JwtUtil.createJWT(TOKEN_EXPIRE, tokenMap);

+ 467 - 223
gis_web/src/main/java/com/gis/web/controller/SceneController.java

@@ -1,38 +1,33 @@
 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.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.FileEntity;
 import com.gis.domain.po.SceneEntity;
 import com.gis.mapper.SceneMapper;
 import com.gis.service.SceneService;
 import com.gis.web.aop.WebControllerLog;
 import com.github.pagehelper.PageInfo;
-import com.github.xiaoymin.knife4j.annotations.ApiSort;
+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.apache.shiro.authz.annotation.Logical;
-import org.apache.shiro.authz.annotation.RequiresRoles;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Valid;
 import java.io.IOException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 /**
@@ -61,125 +56,58 @@ public class SceneController extends BaseController {
         return Result.success(page);
     }
 
-//    @ApiOperation("场景编辑")
-//    @PostMapping("edit")
-//    public Result edit(@Valid @RequestBody SceneDataDto param) {
-//
-//        SceneEntity entity = sceneService.findBySceneCode(param.getSceneCode());
-//        if (entity == null) {
-//            log.error("场景不存在 : {}", param.getSceneCode());
-//            return Result.failure("场景不存在");
-//        }
-//
-//
-//
-//        // 处理someData.json
-//        // 下载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) {
-//                model.put("name", infoJson.get("name"));
-//                model.put("summary", infoJson.get("summary"));
-//                model.put("camera_start", infoJson.getJSONObject("camera_start"));
-////                model.put("camera_start", infoJson.get("camera_start"));
-//
-//                if (guidesArray != null) {
-//                    model.put("images", guidesArray);
-//                }
-//
-//
-//            }
-//
-//            // 更新someDataJson
-//            someDataJson.put("model", model);
-//            someDataJson.put("loadlogo", infoJson.get("loadlogo"));
-//
-//            // 删除旧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));
-////            data2Json.put("tourAudio", tourAudio);
-//        }
-//
-//        String overlays = param.getOverlays();
-//        if (overlays != null) {
-//            data2Json.put("overlays", JSONObject.parseObject(overlays));
-////            data2Json.put("overlays", overlays);
-//        }
-//
-//        String hots = param.getHots();
-//        if (hots != null) {
-//            data2Json.put("hots", JSONObject.parseObject(hots));
-////            data2Json.put("hots", hots);
-//        }
-//
-//        // 处理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++) {
-//                String scanId = guidesArray.getJSONObject(i).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写入完成");
-//
-//
-//
-//        return Result.success();
-//    }
+
+    @ApiOperation("创建场景码")
+    @GetMapping("createSceneCode/{sceneCode}")
+    public Result createSceneCode(@PathVariable String sceneCode) throws QiniuException {
+        if (StringUtils.isBlank(sceneCode)) {
+            log.error("场景码不能为空");
+            return Result.failure("场景码不能为空");
+        }
+
+
+
+        // 场景url
+        String webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
+        log.info("webSite: {}", webSite);
+
+        // 服务器文件路径
+        String serverPath = FILE_PATH + sceneCode;
+
+        // oss文件路径
+        String ossPath = OSS_PATH + sceneCode;
+
+
+        // 创建data2.js
+        String data2Info = "/data2.js";
+        String data2Path = serverPath + data2Info;
+        FileUtil.writeUtf8String("{}", data2Path);
+        if (!FileUtil.exist(data2Path)){
+            log.error("data2.js不存在");
+            return Result.failure("data2.js不存在");
+        }
+
+        // data2.js上传oss
+        QiniuOssUtil.upload(data2Path, ossPath + data2Info);
+
+        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
+        if (entity == null) {
+            entity = new SceneEntity();
+            entity.setSceneCode(sceneCode);
+            entity.setWebSite(webSite);
+            entity.setPath(serverPath);
+            entity.setOssPath(ossPath);
+            entity.setSceneTitle(sceneCode);
+            sceneService.save(entity);
+        }
+
+
+
+        return Result.success(entity);
+    }
+
+
+
 
 
     /**
@@ -196,6 +124,8 @@ public class SceneController extends BaseController {
             sceneService.update(entity);
         }
 
+
+
         return Result.success();
     }
 
@@ -213,131 +143,445 @@ public class SceneController extends BaseController {
     }
 
 
-//    /**
-//     * 只有一个场景是显示状态
-//     */
-//    @ApiOperation("场景显示")
-//    @GetMapping("display/{id}")
-//    public Result display(@PathVariable Long id) {
-//        SceneEntity entity = sceneService.findById(id);
-//        if (entity == null) {
-//            log.error("对象id不存在 : {}", id);
-//            return Result.failure("对象id不存在");
-//        }
-//
-//        // 把所有禁止
-//        sceneMapper.setDisable();
-//        // 开启对应id
-//        sceneMapper.setDisplay(id);
-//
-//        return Result.success();
-//    }
-
-
-//    @ApiOperation(value = "场景上传")
-//    @PostMapping(value = "upload", consumes = {"multipart/form-data"})
-//    public Result upload(MultipartFile file, String sceneCode) throws IOException {
-//
-//        if (file == null) {
-//            log.error("文件不能为空");
-//            return Result.failure("文件不能为空");
-//        }
-//
-//        String basePath = FILE_PATH + sceneCode + "/";
-//
-//        String fileName = file.getOriginalFilename();
-//        String savePath = basePath + fileName;
-//
-//        FileUtil.writeFromStream(file.getInputStream(), savePath);
-//
-//        // 上传到oss
-//        String ossPath = OSS_DOMAIN + OSS_PATH + fileName;
-//        QiniuOssUtil.upload(savePath, ossPath);
-//        log.info("文件上传到oss完成: {}", ossPath);
-//
-//        // 返回前端数据
-//        return Result.success();
-//
-//    }
-
-
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "sceneCode", value = "场景码", required = true),
-            @ApiImplicitParam(name = "param", value = "Map传参", required = true),
-    })
-    @ApiOperation(value = "场景上传", notes = "自定义上传位置,Map表单上传多文件,指定保存路径,需要用postman测试")
-    @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)->{
+    @ApiOperation(value = "场景上传")
+    @PostMapping("uploads")
+    public Result uploads(MultipartFile file, String path)  {
 
             if (StringUtils.isBlank(path)) {
                 log.error("保存路径不能为空");
+                return Result.failure("保存路径不能为空");
             }
 
             if (file == null) {
                 log.error("文件不能为空");
+                return Result.failure("文件不能为空");
             }
 
-            String filePath = serverPath + path;
+            String filePath = FILE_PATH + path;
             log.info("savePath: {}", filePath);
             try {
                 FileUtil.writeFromStream(file.getInputStream(), filePath);
-                ossMap.put(filePath, ossPath + path);
+                log.info("文件写入完成");
+                if (!FileUtil.exist(filePath)) {
+                    log.error("文件不存在: {}", filePath);
+                    return Result.failure("文件不存在 : " + filePath);
+                }
+
+                QiniuOssUtil.upload(filePath, OSS_PATH + path);
+                log.info("oss文件上传完成 ");
             } catch (IOException e) {
                 e.printStackTrace();
             }
 
+        return Result.success();
+    }
+
+
+    @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);
+
+
+    }
+
+
+    @ApiOperation("漫游可行")
+    @PostMapping("roamViable")
+    public Result roamViable(@RequestBody RoamViableDto param) throws Exception {
+        return sceneService.roamViable(param);
+    }
+
+    @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);
+        }
+
+
+        return Result.success(editMatterPortvrData(s));
+    }
+
+
+    /**
+     * 处理matterportvr 数据转为大场景可使用的数据
+     * @throws IOException
+     */
+    public JSONObject editMatterPortvrData(String data) throws IOException {
+        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);
         });
 
-        // 创建data.js、 data2.js
-        String data2Info = "/data2.js";
-//        String dataInfo = "/hot/js/data2.js";
+        // 更新player_options
+        mpoJson.put("player_options", playerOptionsJson);
 
-        String data2Path = serverPath + data2Info;
-//        String dataPath = serverPath + dataInfo;
 
-        FileUtil.writeUtf8String("{}", data2Path);
-//        FileUtil.writeUtf8String("{}", dataPath);
+        // 5. 添加files
+        JSONArray templates = new JSONArray();
+        templates.add("data/{{number}}/{{filename}}");
 
-        ossMap.put(data2Path, ossPath + data2Info);
-//        ossMap.put(dataPath, ossPath + dataInfo);
-        log.info("文件上传完成");
+        JSONObject templatesJson = new JSONObject();
+        templatesJson.put("templates", templates);
 
-        QiniuOssUtil.uploads(ossMap);
-        log.info("oss文件上传完成");
 
+        // 6. 创建model
+        JSONObject someDataJson = new JSONObject();
+        someDataJson.put("model", mpoJson);
+        someDataJson.put("files", templatesJson);
 
+        // 处理json value null
+        return someDataJson;
 
-        // 场景url
-        String webSite = SERVER_DOMAIN + "SuperTwo/index.html?m=" + sceneCode;
-        log.info("webSite: {}", webSite);
+    }
 
 
-        entity = new SceneEntity();
-        entity.setSceneCode(sceneCode);
-        entity.setWebSite(webSite);
-        entity.setPath(serverPath);
-        entity.setOssPath(ossPath);
-        sceneService.save(entity);
+    /**
+     * 编辑场景上传多媒体资料
+     * @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);
 
-        return Result.success(entity);
     }
 
 

+ 2 - 1
gis_web/src/main/java/com/gis/web/shiro/ShiroConfig.java

@@ -66,7 +66,8 @@ public class ShiroConfig {
         filterRuleMap.put("/logout", "anon");
         filterRuleMap.put("/admin", "anon");
         filterRuleMap.put("/admin/login", "anon");
-        filterRuleMap.put("/test/**", "anon");
+
+        // 特殊处理,这个接口不拦截
 
 
         // swagger 不拦截