Преглед на файлове

处理fastjson中$ref对象重复引用问题

wuweihao преди 5 години
родител
ревизия
a6f15c2edc

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

@@ -53,7 +53,8 @@ logging.level.com.gis=debug
 
 # ±¾µØ±£´æÂ·¾¶
 file.path=/root/user/cms_bin_scene_data/
-server.domain =http://47.107.252.54:8105/
+#server.domain =http://47.107.252.54:8105/
+server.domain =http://www.4dmodel.com/
 
 # ÆßÅ£ oss info
 oss.file.path=data/

+ 2 - 0
gis_common/src/main/java/com/gis/common/config/WebMvcConfig.java

@@ -62,8 +62,10 @@ public class WebMvcConfig implements WebMvcConfigurer {
         // 设置全程返回时间
         fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
         // 设置返回值为null是时输出,不写的话,null 字段 不返回。也可以设置返回空串, 可以同时设置多个
+
         fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullStringAsEmpty);
 
+
         fastJson.setFastJsonConfig(fastJsonConfig);
 
         //3、中文乱码解决方案

+ 2 - 0
gis_web/src/main/java/com/gis/web/aop/WebLogAspect.java

@@ -1,5 +1,7 @@
 package com.gis.web.aop;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.gis.web.shiro.JwtUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;

+ 33 - 13
gis_web/src/main/java/com/gis/web/controller/SceneController.java

@@ -2,8 +2,10 @@ package com.gis.web.controller;
 
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.http.HttpUtil;
+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.util.FileUtils;
 import com.gis.common.util.QiniuOssUtil;
 import com.gis.common.util.Result;
@@ -21,11 +23,13 @@ import io.swagger.annotations.ApiImplicitParam;
 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 javax.validation.Valid;
+import java.io.File;
 import java.io.IOException;
 import java.util.*;
 
@@ -42,10 +46,6 @@ public class SceneController extends BaseController {
     @Autowired
     private SceneService sceneService;
 
-    @Autowired
-    private SceneMapper sceneMapper;
-
-
 
     @ApiOperation("场景列表")
     @PostMapping("list")
@@ -111,12 +111,11 @@ public class SceneController extends BaseController {
 
 
     /**
-     * 素材文件,真删除
+     * 删除
      */
-    @WebControllerLog(description = "大场景-删除")
     @ApiOperation("场景删除")
     @GetMapping("removes/{ids}")
-    public Result detail(@PathVariable String ids) {
+    public Result removes(@PathVariable String ids) {
         List<SceneEntity> entities = sceneService.findByIds(ids);
         for (SceneEntity entity: entities) {
             entity.setRecStatus("I");
@@ -181,7 +180,7 @@ public class SceneController extends BaseController {
 
     @ApiOperation("编辑场景")
     @PostMapping("edit")
-    public Result edit(@Valid @RequestBody SceneDataDto param) throws QiniuException {
+    public Result edit(@Valid @RequestBody SceneDataDto param) throws QiniuException, InterruptedException {
 
         String sceneCode = param.getSceneCode();
 
@@ -275,16 +274,20 @@ public class SceneController extends BaseController {
         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文件不存在");
+        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));
@@ -322,17 +325,32 @@ public class SceneController extends BaseController {
         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");
-                    audioJson.put(scanId, timeJson);
+                    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());
+
 
         // 删除旧data2.js
         FileUtil.del(data2Path);
@@ -585,4 +603,6 @@ public class SceneController extends BaseController {
     }
 
 
+
+
 }