|
@@ -216,7 +216,7 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result editScene_1(SceneDataDto param){
|
|
|
+ public Result editScene(SceneDataDto param){
|
|
|
BaseRuntimeException.isBlank(param, null, "参数不能为空");
|
|
|
|
|
|
// 1. 处理SomeData.json
|
|
@@ -325,8 +325,8 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
|
|
|
|
|
|
// 将新的someDataJson上传oss
|
|
|
QiniuOssUtil.upload(someDataPath, OSS_PATH + sceneCode + "/" + someDataName);
|
|
|
- log.info(someDataName + "已上传到七牛云");
|
|
|
- log.info("处理以完成: someData.json");
|
|
|
+// log.info(someDataName + "已上传到七牛云");
|
|
|
+ log.info("处理以完成: someData.json, 已上传七牛云");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -441,8 +441,8 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
|
|
|
|
|
|
// 将新的someDataJson上传oss
|
|
|
QiniuOssUtil.upload(data2Path, OSS_PATH + sceneCode + "/" + data2Name);
|
|
|
- log.info(data2Name+ "已上传到七牛云");
|
|
|
- log.info("处理以完成: data2.js");
|
|
|
+// log.info(data2Name+ "已上传到七牛云");
|
|
|
+ log.info("处理以完成: data2.js, 已上传七牛云");
|
|
|
|
|
|
}
|
|
|
|
|
@@ -504,224 +504,14 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
|
|
|
//上传oss
|
|
|
String ossPath = OSS_PATH + sceneCode + "/hot/js/data.js";
|
|
|
QiniuOssUtil.upload(dataPath, ossPath);
|
|
|
- log.info("data.js已上传到七牛云: {}", ossPath);
|
|
|
- log.info("处理以完成: data.js");
|
|
|
+// log.info("data.js已上传到七牛云: {}", ossPath);
|
|
|
+ log.info("处理以完成: data.js, 已上传七牛云");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 编辑场景
|
|
|
- * @param param
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Result editScene(SceneDataDto param) throws QiniuException {
|
|
|
-
|
|
|
- BaseRuntimeException.isBlank(param, null, "参数不能为空");
|
|
|
-
|
|
|
- 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"));
|
|
|
-
|
|
|
-
|
|
|
- if (guidesArray != null) {
|
|
|
- model.put("images", guidesArray);
|
|
|
- } else {
|
|
|
- model.put("images", new JSONArray());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // 更新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);
|
|
|
- // 2021-9-23 备份someData.json
|
|
|
- String dateTime = DateUtils.getDateTime();
|
|
|
- FileUtil.writeUtf8String(someDataJson.toJSONString(), entity.getPath() + "/someData_"+ dateTime +".json");
|
|
|
-
|
|
|
- BaseRuntimeException.isTrue(!FileUtil.isFile(someDataPath), null, "上传七牛云的someData文件不存在");
|
|
|
- long someDataSize = FileUtil.size(new File(someDataPath));
|
|
|
- log.info("someData.json写入完成,文件大小:{} kb" , someDataSize);
|
|
|
-
|
|
|
- // 将新的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);
|
|
|
-
|
|
|
-
|
|
|
- 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对象重复引用问题,拿不到想要的效果
|
|
|
- audioJson.put(scanId, JSON.toJSONString(timeJson, SerializerFeature.DisableCircularReferenceDetect));
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 新增audio
|
|
|
- data2Json.put("audio", audioJson);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 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_online1/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);
|
|
|
-
|
|
|
- // 2021-09-23 备份data2.js
|
|
|
- String dateTime = DateUtils.getDateTime();
|
|
|
- FileUtil.writeUtf8String(data2Json.toJSONString(), entity.getPath() + File.separator + "data2_" + dateTime + ".js");
|
|
|
-
|
|
|
-
|
|
|
- log.info("新data2.js写入完成");
|
|
|
-
|
|
|
- BaseRuntimeException.isTrue(!FileUtil.isFile(data2Path), null, "上传七牛云的data2.js文件不存在");
|
|
|
-
|
|
|
- // 将新的someDataJson上传oss
|
|
|
- QiniuOssUtil.upload(data2Path, OSS_PATH + sceneCode + "/" + data2Name);
|
|
|
- log.info(data2Name+ "已上传到七牛云");
|
|
|
-
|
|
|
- //处理data.js 文件
|
|
|
- editDataJs(sceneCode, entity, hots);
|
|
|
-
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Result uploadVisionModelDataToVisionJson(MultipartFile file) {
|
|
|
String fileName = file.getOriginalFilename();
|
|
@@ -772,67 +562,7 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
|
|
|
return Result.success(entityMapper.getVisit(sceneCode));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 处理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);
|
|
|
-
|
|
|
- // 2021-09-23 备份数据用
|
|
|
- String dateTime = DateUtils.getDateTime();
|
|
|
- FileUtil.writeUtf8String(dataJsJson.toJSONString(), entity.getPath() + "/data_"+ dateTime + ".js");
|
|
|
|
|
|
- BaseRuntimeException.isTrue(!FileUtil.isFile(dataPath), null, "上传七牛云的data.js文件不存在");
|
|
|
- //上传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 {
|