|
@@ -1,395 +0,0 @@
|
|
|
-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.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.github.pagehelper.PageInfo;
|
|
|
-import lombok.extern.log4j.Log4j2;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by owen on 2020/3/11 0011 16:16
|
|
|
- */
|
|
|
-@Log4j2
|
|
|
-@Service
|
|
|
-public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implements SceneService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SceneMapper entityMapper;
|
|
|
-
|
|
|
- @Override
|
|
|
- public IBaseMapper<SceneEntity, Long> getBaseMapper() {
|
|
|
- return this.entityMapper;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public SceneEntity findBySceneCode(String m) {
|
|
|
- return entityMapper.findBySceneCode(m);
|
|
|
- }
|
|
|
-
|
|
|
-// @Override
|
|
|
-// public List<SceneEntity> search(ScenePageDto param) {
|
|
|
-// return entityMapper.search(param);
|
|
|
-// }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result<SceneEntity> search(PageDto param) {
|
|
|
- startPage(param);
|
|
|
- PageInfo<SceneEntity> page = new PageInfo<>(entityMapper.search(param));
|
|
|
- return Result.success(page);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 漫游可行
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Result roamViable(RoamViableDto param) throws Exception {
|
|
|
- String sceneCode = param.getSceneCode();
|
|
|
- SceneEntity entity = entityMapper.findBySceneCode(param.getSceneCode());
|
|
|
- if (entity == null) {
|
|
|
- log.error("场景不存在:{}", sceneCode);
|
|
|
- return Result.failure("场景不存在");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 1. 从oss下载vision.modeldata
|
|
|
- String visionModelDataName = "vision.modeldata";
|
|
|
- // 注意网络下载会有缓存,必须加时间戳
|
|
|
-// log.info("网络下载文件地址: {}", urlPath);
|
|
|
-// String localBasePath = FILE_PATH + sceneCode;
|
|
|
- String localBasePath = configConstant.serverBasePath + sceneCode;
|
|
|
-
|
|
|
- // 2. 将vision.modeldata 转 vision.json
|
|
|
- String visionModelDataPath = localBasePath + "/" + visionModelDataName;
|
|
|
- if (!FileUtil.exist(visionModelDataPath)) {
|
|
|
- log.error("vision.modeldata不存在 : {}", visionModelDataPath);
|
|
|
- return Result.failure("vision.modeldata不存在");
|
|
|
- }
|
|
|
-// log.info(visionModelDataName+ "下载完成");
|
|
|
-
|
|
|
-
|
|
|
- String visionJsonPath = localBasePath + "/vision.json";
|
|
|
- ConvertUtils.convertVisionModelDataToTxt(visionModelDataPath, visionJsonPath);
|
|
|
- if (!FileUtil.exist(visionJsonPath)) {
|
|
|
- log.error("vision.json不存在 : {}", visionJsonPath);
|
|
|
- return Result.failure("vision.modeldata不存在");
|
|
|
- }
|
|
|
-
|
|
|
- // 3. 编辑新数据到vision.json
|
|
|
- JSONArray inputDates = JSONObject.parseArray(param.getData());
|
|
|
-
|
|
|
- JSONObject visionJson = JSONObject.parseObject(FileUtil.readUtf8String(visionJsonPath));
|
|
|
- JSONArray sweepLocations = visionJson.getJSONArray("sweepLocations");
|
|
|
-
|
|
|
- for (int i = 0; i < sweepLocations.size(); i++) {
|
|
|
- JSONObject pano = sweepLocations.getJSONObject(i);
|
|
|
-
|
|
|
- for (int j = 0; j < inputDates.size(); j++) {
|
|
|
- JSONObject jo = inputDates.getJSONObject(j);
|
|
|
- String panoID = jo.getString("panoID");
|
|
|
- JSONArray visibles3 = jo.getJSONArray("visibles3");
|
|
|
-
|
|
|
- // 去掉uuid 的“-”
|
|
|
- String uuid = pano.getString("uuid");
|
|
|
- String s = StringUtils.replaceAll(uuid, "-", "");
|
|
|
- if (s.equals(panoID)) {
|
|
|
- log.info("uuid: {}, panoID: {}", uuid, panoID);
|
|
|
- pano.put("visibles", visibles3);
|
|
|
- log.info("visibles: {},visibles3:{}", pano.get("visibles"), visibles3);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 删除旧vision.json,vision.modeldata
|
|
|
- FileUtil.del(visionJsonPath);
|
|
|
- FileUtil.del(visionModelDataPath);
|
|
|
-
|
|
|
- // 写入新vision.json
|
|
|
- FileUtil.writeUtf8String(visionJson.toJSONString(), visionJsonPath);
|
|
|
- if (!FileUtil.exist(visionJsonPath)) {
|
|
|
- log.error("new vision.json不存在");
|
|
|
- }
|
|
|
-
|
|
|
- log.info( "新vision.json创建完成 :{}", visionJsonPath);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // 4. 将vision.json转vision.modeldata
|
|
|
- ConvertUtils.convertTxtToVisionModelData(visionJsonPath, visionModelDataPath);
|
|
|
-
|
|
|
- // 5. 将新的vision.modeldata上传到oss
|
|
|
- if (!FileUtil.exist(visionModelDataPath)) {
|
|
|
- log.error("vision.modeldata不存在");
|
|
|
- }
|
|
|
- log.info("新" + visionModelDataName+ "创建完成 :{}", visionModelDataPath);
|
|
|
-
|
|
|
-
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result edit(SceneDataDto param) {
|
|
|
- String sceneCode = param.getSceneCode();
|
|
|
- SceneEntity entity = this.findBySceneCode(param.getSceneCode());
|
|
|
- if (entity == null) {
|
|
|
- log.error("场景不存在 : {}", sceneCode);
|
|
|
- return Result.failure("场景不存在");
|
|
|
- }
|
|
|
-
|
|
|
- String basePath = configConstant.serverBasePath + sceneCode;
|
|
|
-
|
|
|
-
|
|
|
- // 处理someData.json
|
|
|
-
|
|
|
-// String someDataPath = entity.getPath() + "/someData.json";
|
|
|
- String someDataPath = basePath + "/someData.json";
|
|
|
- if (!FileUtil.isFile(someDataPath)) {
|
|
|
- log.error("someData.json文件不存在");
|
|
|
- return Result.failure("someData.json文件不存在");
|
|
|
- }
|
|
|
-
|
|
|
- // 读取someDataJson
|
|
|
- String someData = FileUtil.readUtf8String(someDataPath);
|
|
|
- JSONObject someDataJson = JSONObject.parseObject(someData);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- String info = param.getInfo();
|
|
|
- String guides = param.getGuides();
|
|
|
- JSONArray guidesArray = new JSONArray();
|
|
|
- if (guides != null) {
|
|
|
- guidesArray = JSONObject.parseArray(guides);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (info != null) {
|
|
|
- JSONObject infoJson = JSONObject.parseObject(info);
|
|
|
-
|
|
|
- // 处理model
|
|
|
- JSONObject model = someDataJson.getJSONObject("model");
|
|
|
- if (model != null) {
|
|
|
- if (guidesArray != null) {
|
|
|
- model.put("images", guidesArray);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // 更新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写入完成");
|
|
|
- }
|
|
|
-
|
|
|
- // 处理data2.js
|
|
|
- String data2Path = basePath + "/data2.js";
|
|
|
- boolean file = FileUtil.isFile(data2Path);
|
|
|
- if (!file) {
|
|
|
- log.error("data2.js文件不存在");
|
|
|
- return Result.failure("data2.js文件不存在");
|
|
|
- }
|
|
|
-
|
|
|
- String data2 = FileUtil.readUtf8String(data2Path);
|
|
|
- JSONObject data2Json = JSONObject.parseObject(data2);
|
|
|
-
|
|
|
- String tourAudio = param.getTourAudio();
|
|
|
- if (tourAudio != null) {
|
|
|
- data2Json.put("tourAudio", JSONObject.parseObject(tourAudio));
|
|
|
- } else {
|
|
|
- data2Json.put("tourAudio", new JSONObject());
|
|
|
- }
|
|
|
-
|
|
|
- // overlays是数组
|
|
|
- String overlays = param.getOverlays();
|
|
|
- if (overlays != null) {
|
|
|
- data2Json.put("overlays", JSONObject.parseArray(overlays));
|
|
|
- } else {
|
|
|
- data2Json.put("overlays", new JSONArray());
|
|
|
- }
|
|
|
-
|
|
|
- // 处理guidesArray,将scan_id的值作为key, value: time":40000
|
|
|
- JSONObject audioJson = new JSONObject();
|
|
|
- JSONObject timeJson = new JSONObject();
|
|
|
- timeJson.put("time", 40000);
|
|
|
- if (guidesArray != null) {
|
|
|
-
|
|
|
- // 将旧的audio字段删除
|
|
|
- data2Json.remove("audio");
|
|
|
-
|
|
|
- for (int i = 0; i < guidesArray.size() ; i++) {
|
|
|
- JSONObject metadata = guidesArray.getJSONObject(i).getJSONObject("metadata");
|
|
|
- if (metadata != null) {
|
|
|
- String scanId = metadata.getString("scan_id");
|
|
|
- if (scanId == null) {
|
|
|
- log.error("guides.metadata.scan_id为空: {}", i);
|
|
|
- return Result.failure("guides.metadata.scan_id为空: " + i);
|
|
|
- }
|
|
|
- // Fastjson-fastjson中$ref对象重复引用问题,拿不到想要的效果
|
|
|
- audioJson.put(scanId, JSON.toJSONString(timeJson, SerializerFeature.DisableCircularReferenceDetect));
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 新增audio
|
|
|
- data2Json.put("audio", audioJson);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // host在data2.js、data.js都需要处理
|
|
|
- String hots = param.getHots();
|
|
|
- log.info("input hots: {}", hots);
|
|
|
- if (hots != null) {
|
|
|
- // 获取所有key
|
|
|
- JSONObject hotJson = JSONObject.parseObject(hots);
|
|
|
-
|
|
|
- Set<String> strings = hotJson.keySet();
|
|
|
- for (String key: strings) {
|
|
|
- JSONObject subJson = hotJson.getJSONObject(key);
|
|
|
-
|
|
|
- // 2021.04.02 处理link
|
|
|
- String link = getLink(subJson, key);
|
|
|
-
|
|
|
- // 将link 添加进去
|
|
|
- subJson.put("link", link);
|
|
|
- }
|
|
|
- data2Json.put("hots", hotJson);
|
|
|
- } else {
|
|
|
- data2Json.put("hots", new JSONObject());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 删除旧data2.js
|
|
|
- FileUtil.del(data2Path);
|
|
|
-
|
|
|
-
|
|
|
- // 写入新data2.js
|
|
|
- FileUtil.writeUtf8String(data2Json.toJSONString(), data2Path);
|
|
|
- log.info("新data2.js写入完成");
|
|
|
-
|
|
|
-
|
|
|
- //处理data.js 文件
|
|
|
- editDataJs(entity, hots);
|
|
|
-
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result display(Long id) {
|
|
|
- SceneEntity entity = findById(id);
|
|
|
- if (entity == null) {
|
|
|
- return Result.failure("场景不存在, id: " + id);
|
|
|
- }
|
|
|
- // 需求:只有一个是可用;先禁用,再启用
|
|
|
- entityMapper.setDisable();
|
|
|
- entityMapper.setDisplay(id);
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 2021.04.02 处理infoAttribute的m_title
|
|
|
- * String url = "https://www.4dmodel.com/SuperTwo/hot_online/index.html?m=" + key;
|
|
|
- * String url = SERVER_DOMAIN + "edit-backstage/hot_online/index.html?m=" + key;
|
|
|
- * m_title:[]
|
|
|
- * 有值: link = "/edit-backstage/hot_online1/index.html?m=" + key
|
|
|
- * 无值: link = "/edit-backstage/hot_online/index.html?m=" + key
|
|
|
- */
|
|
|
- private String getLink(JSONObject param, String key){
|
|
|
- JSONObject infoAttribute = param.getJSONObject("infoAttribute");
|
|
|
- // m_title可能会没有这个属性key, 需要判断
|
|
|
- JSONArray m_title = infoAttribute.getJSONArray("m_title");
|
|
|
- String url = "/edit-backstage/hot_online/index.html#/?m=" + key;
|
|
|
- if (m_title != null && m_title.size() > 0){
|
|
|
- url = "/edit-backstage/hot_online1/index.html#/?m=" + key;
|
|
|
- }
|
|
|
- return url;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理data.js 文件
|
|
|
- */
|
|
|
- private void editDataJs(SceneEntity entity, String hots ) {
|
|
|
-
|
|
|
- // 因为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");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- log.info("out data.js : {}", dataJsJson);
|
|
|
- String basePath = configConstant.serverBasePath + entity.getSceneCode();
|
|
|
-
|
|
|
- String dataPath = basePath + "/hot/js/data.js";
|
|
|
- FileUtil.writeUtf8String(dataJsJson.toJSONString(), dataPath);
|
|
|
-
|
|
|
- log.info("新data.js写入完成: {}", dataPath);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-}
|