|
@@ -261,6 +261,9 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
sceneJson.setVideos(scenePlusExt.getVideos());
|
|
|
}
|
|
|
|
|
|
+ //发布马赛克列表
|
|
|
+ sceneJson.setMosaicList(this.getMosaicList(num));
|
|
|
+
|
|
|
//处理热点数据,生成hot.json
|
|
|
this.publicHotData(num, sceneEditInfo);
|
|
|
|
|
@@ -471,6 +474,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
sceneInfoVO.setSceneFrom(scenePlusExt.getSceneFrom());
|
|
|
sceneInfoVO.setSceneKind(scenePlusExt.getSceneKind());
|
|
|
sceneInfoVO.setVideos(scenePlusExt.getVideos());
|
|
|
+ sceneInfoVO.setMosaicList(this.getMosaicList(num));
|
|
|
|
|
|
// TODO: 2022/4/24 v3版本停机要切换---------------------------start
|
|
|
// this.setExtData(sceneInfoVO, scenePlus.getCameraId());
|
|
@@ -1678,172 +1682,126 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
@Override
|
|
|
public ResultData addMosaics(BaseDataParamVO param) throws Exception {
|
|
|
|
|
|
- JSONArray mosaicArr = JSONArray.parseArray(param.getData());
|
|
|
- if (CollUtil.isEmpty(mosaicArr) || mosaicArr.size() > 1) {
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
|
- }
|
|
|
- JSONObject mosicObj= mosaicArr.getJSONObject(0);
|
|
|
-
|
|
|
ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
if(Objects.isNull(scenePlus)){
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
}
|
|
|
- ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
|
|
|
- SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
|
|
|
|
|
|
- String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, param.getNum());
|
|
|
- String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, param.getNum());
|
|
|
+ //如果redis数据丢失,从本地文件中同步马赛克数据到redis
|
|
|
+ this.syncMosaicFromFileToRedis(param.getNum());
|
|
|
|
|
|
- String path = scenePlusExt.getDataSource();
|
|
|
- if(StrUtil.isNotEmpty(path) && path.startsWith("http")){
|
|
|
- path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ JSONArray jsonArray = JSON.parseArray(param.getData());
|
|
|
+ for (Object o : jsonArray) {
|
|
|
+ JSONObject mosaic = (JSONObject) o;
|
|
|
+ String panoId = mosaic.getString("panoId");
|
|
|
+ if(StrUtil.isEmpty(panoId)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
|
+ }
|
|
|
+ map.put(panoId, JSON.toJSONString(mosaic));
|
|
|
}
|
|
|
- String target = path + "_roi";
|
|
|
-
|
|
|
- cn.hutool.core.io.FileUtil.del(target);
|
|
|
+ String key = String.format(RedisKey.SCENE_MOSAIC_DATA, param.getNum());
|
|
|
+ redisUtil.hmset(key, map);
|
|
|
|
|
|
- //文件上传的位置可以自定义
|
|
|
- String filePath = target + File.separator + "extras" + File.separator + "images/";
|
|
|
- File imageFile = new File(filePath);
|
|
|
- if(!imageFile.getParentFile().exists()){
|
|
|
- imageFile.getParentFile().mkdirs();
|
|
|
- }
|
|
|
- FileUtils.copyFolderAllFiles(path + "/caches/images/", filePath, true);
|
|
|
+ //写入本地文件,作为备份
|
|
|
+ this.writeMosaic(param.getNum());
|
|
|
|
|
|
- String mosaicData = sceneEditInfoExt.getMosaics();
|
|
|
- JSONArray jsonArray = new JSONArray();
|
|
|
- if(StrUtil.isNotEmpty(mosaicData)){
|
|
|
- jsonArray = JSONArray.parseArray(mosaicData);
|
|
|
- }
|
|
|
- jsonArray.add(mosicObj);
|
|
|
+ //更新数据库
|
|
|
+ this.updateMosaicFlag(param.getNum());
|
|
|
|
|
|
- // 准备算法数据
|
|
|
- List<JSONObject> mosaicsList = new ArrayList<>();
|
|
|
- for(int i = 0, len = jsonArray.size(); i < len; i++){
|
|
|
- JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
- boolean contains = false;
|
|
|
- for (JSONObject item : mosaicsList) {
|
|
|
- if(StringUtils.equals(item.getString("panoId"),jsonObject.getString("panoId"))){
|
|
|
- contains = true;
|
|
|
- item.getJSONArray("rect").addAll(jsonObject.getJSONArray("rect"));
|
|
|
- }
|
|
|
- }
|
|
|
- if(!contains){
|
|
|
- mosaicsList.add(jsonObject);
|
|
|
- }
|
|
|
- }
|
|
|
- JSONObject roiImageJSon = new JSONObject();
|
|
|
- roiImageJSon.put("batch",mosaicsList);
|
|
|
+ //更新版本号
|
|
|
+ this.upgradeVersionById(sceneEditInfo.getId());
|
|
|
|
|
|
- FileUtils.writeFile(target + File.separator + "extras" + File.separator + "image-ROI.json", JSON.toJSONString(roiImageJSon,SerializerFeature.DisableCircularReferenceDetect));
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
|
|
|
- FileUtils.copyFile(path + File.separator + "results/vision.txt", target + File.separator+"extras/vision.txt", true);
|
|
|
- FileUtils.copyFile(path + File.separator + "results/vision2.txt", target + File.separator+"extras/vision2.txt", true);
|
|
|
- FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
|
|
|
- String data = FileUtils.readFile(target + File.separator+"data.json");
|
|
|
- if(data != null){
|
|
|
- JSONObject floorplanJson = new JSONObject();
|
|
|
- floorplanJson.put("has_source_images", true);
|
|
|
- floorplanJson.put("has_vision_txt", true);
|
|
|
+ private void updateMosaicFlag(String num){
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId());
|
|
|
|
|
|
- JSONObject dataJson = JSONObject.parseObject(data);
|
|
|
- dataJson.put("extras", floorplanJson);
|
|
|
- //V5表示不需要生成high,low文件
|
|
|
- dataJson.put("skybox_type", "SKYBOX_V6");
|
|
|
- if(scenePlusExt.getSceneScheme() == 11){
|
|
|
- dataJson.put("skybox_type", "SKYBOX_V7");
|
|
|
- }
|
|
|
- dataJson.put("split_type", "SPLIT_V18");
|
|
|
- //sceneScheme为3切成瓦片图
|
|
|
- if(scenePlusExt.getSceneScheme() == 3){
|
|
|
- dataJson.put("skybox_type", "SKYBOX_V4");
|
|
|
- }
|
|
|
- FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
|
|
|
+ String key = String.format(RedisKey.SCENE_MOSAIC_DATA, num);
|
|
|
+ boolean flag = redisUtil.hasKey(key);
|
|
|
+ if(flag){
|
|
|
+ sceneEditInfoExt.setMosaic(Integer.valueOf(CommonStatus.YES.code()));
|
|
|
+ }else{
|
|
|
+ sceneEditInfoExt.setMosaic(Integer.valueOf(CommonStatus.NO.code()));
|
|
|
}
|
|
|
+ sceneEditInfoExtService.updateById(sceneEditInfoExt);
|
|
|
+ }
|
|
|
|
|
|
- FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
|
|
|
-
|
|
|
- //进行计算
|
|
|
- log.info("马赛克建模开始, num:{}, path:{}" + param.getNum(), target);
|
|
|
- CreateObjUtil.build3dModel2(target , "1");
|
|
|
- log.info("马赛克建模结束, num:{}, path:{}" + param.getNum(), target);
|
|
|
+ /**
|
|
|
+ * <p>
|
|
|
+ 保证马赛克数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
|
|
|
+ **/
|
|
|
+ private void syncMosaicFromFileToRedis(String num) throws Exception{
|
|
|
|
|
|
- //读取upload文件,检验需要上传的文件是否存在
|
|
|
- String uploadJsonPath = target + File.separator + "results" + File.separator + "upload.json";
|
|
|
- boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
|
|
|
- if(!exist){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5042);
|
|
|
+ String key = String.format(RedisKey.SCENE_MOSAIC_DATA, num);
|
|
|
+ boolean exist = redisUtil.hasKey(key);
|
|
|
+ if(exist){
|
|
|
+ return;
|
|
|
}
|
|
|
- String uploadData = FileUtils.readFile(target + File.separator + "results" + File.separator + "upload.json");
|
|
|
- JSONObject uploadJson = JSONObject.parseObject(uploadData);
|
|
|
- JSONArray array = uploadJson.getJSONArray("upload");
|
|
|
- Map<String,String> map = new HashMap<>();
|
|
|
- JSONObject fileJson = null;
|
|
|
- String fileName = "";
|
|
|
- for(int i = 0, len = array.size(); i < len; i++){
|
|
|
- fileJson = array.getJSONObject(i);
|
|
|
- fileName = fileJson.getString("file");
|
|
|
- //文件不存在抛出异常
|
|
|
- if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
|
|
|
- throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
|
|
|
- }
|
|
|
-
|
|
|
- //high文件夹
|
|
|
- if(fileJson.getIntValue("clazz") == 3){
|
|
|
- map.put(target + File.separator + "results" +File.separator+ fileName,
|
|
|
- imgViewPath + "pan/high/"+ fileName.replace("high/", ""));
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_MOSAIC_DATA_SYNC, num);
|
|
|
+ boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
|
|
|
+ if(!lock){
|
|
|
+ throw new BusinessException(ErrorCode.SYSTEM_BUSY);
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ exist = redisUtil.hasKey(key);
|
|
|
+ if(exist){
|
|
|
+ return;
|
|
|
}
|
|
|
- //low文件夹
|
|
|
- if(fileJson.getIntValue("clazz") == 4){
|
|
|
- map.put(target + File.separator + "results" +File.separator+ fileName,
|
|
|
- imgViewPath + "pan/low/"+ fileName.replace("low/", ""));
|
|
|
+ String filePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
|
|
|
+ String mosaicData = FileUtils.readFile(filePath + "mosaic.json");
|
|
|
+ if(StrUtil.isEmpty(mosaicData)){
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
- //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
|
|
|
- if(fileJson.getIntValue("clazz") == 5){
|
|
|
- map.put(target + File.separator + "results" + File.separator+ fileName,
|
|
|
- imgViewPath + fileName);
|
|
|
+ JSONArray jsonArray = JSON.parseArray(mosaicData);
|
|
|
+ if(CollUtil.isEmpty(jsonArray)){
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
- //tiles文件夹,亚马逊瓦片图
|
|
|
- if(fileJson.getIntValue("clazz") == 7 ){
|
|
|
- map.put(target + File.separator + "results" + File.separator+ fileName,
|
|
|
- imgViewPath + fileName);
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ for (Object o : jsonArray) {
|
|
|
+ JSONObject jo = (JSONObject)o;
|
|
|
+ map.put(jo.getString("panoId"), jo.toJSONString());
|
|
|
}
|
|
|
+ redisUtil.hmset(key, map);
|
|
|
+ }finally {
|
|
|
+ redisLockUtil.unlockLua(lockKey);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- for(String imagesName : imageFile.list()){
|
|
|
- //覆盖原始图片资源
|
|
|
- FileUtils.copyFile(target + File.separator + "extras/images/" + imagesName,
|
|
|
- path + File.separator + "caches/images/" + imagesName, true);
|
|
|
- FileUtils.deleteFile(target + File.separator + "extras/images/" + imagesName);
|
|
|
- }
|
|
|
-
|
|
|
- uploadToOssUtil.uploadMulFiles(map);
|
|
|
-
|
|
|
- this.upgradeVersionById(sceneEditInfo.getId());
|
|
|
+ /**
|
|
|
+ * <p>
|
|
|
+ 保证马赛克数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
|
|
|
+ **/
|
|
|
+ private void writeMosaic(String num) throws Exception{
|
|
|
|
|
|
- sceneEditInfoExt.setMosaics(JSON.toJSONString(jsonArray,SerializerFeature.DisableCircularReferenceDetect));
|
|
|
- sceneEditInfoExtService.updateById(sceneEditInfoExt);
|
|
|
+ String mosaicPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "mosaic.json";
|
|
|
|
|
|
- // 更新 scene.json
|
|
|
- String sceneJsonPath = dataViewPath + "scene.json";
|
|
|
- String sceneJson = uploadToOssUtil.getObjectContent(this.bucket, sceneJsonPath);
|
|
|
- JSONObject scenejson = new JSONObject();
|
|
|
- if(StrUtil.isNotEmpty(sceneJson)) {
|
|
|
- scenejson = JSONObject.parseObject(sceneJson);
|
|
|
+ String key = String.format(RedisKey.SCENE_MOSAIC_DATA, num);
|
|
|
+ Map<String, String> mosaicMap = redisUtil.hmget(key);
|
|
|
+ if(CollUtil.isEmpty(mosaicMap)){
|
|
|
+ FileUtils.deleteFile(mosaicPath);
|
|
|
+ return;
|
|
|
}
|
|
|
- scenejson.put("mosaics",JSON.toJSONString(jsonArray, SerializerFeature.DisableCircularReferenceDetect));
|
|
|
- Integer version = scenejson.getIntValue("version");
|
|
|
- version = Objects.isNull(version) ? 1 : version + 1;
|
|
|
- scenejson.put("version", version);
|
|
|
- uploadToOssUtil.upload(scenejson.toJSONString().getBytes(), sceneJsonPath);
|
|
|
+ List<String> mosaicList = Lists.newArrayList(mosaicMap.values());
|
|
|
+ JSONArray jsonArr = new JSONArray();
|
|
|
+ mosaicList.stream().forEach(mosaic->{
|
|
|
+ jsonArr.add(JSONObject.parseObject(mosaic));
|
|
|
+ });
|
|
|
|
|
|
- Map<String,Object> result = new HashMap<>(1);
|
|
|
- result.put("mosaics",jsonArray);
|
|
|
|
|
|
- return ResultData.ok(result);
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_MOSAIC_JSON, num);
|
|
|
+ boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
|
|
|
+ if(!lock){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ FileUtils.writeFile(mosaicPath, jsonArr.toJSONString());
|
|
|
+ }finally {
|
|
|
+ redisLockUtil.unlockLua(lockKey);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -2576,4 +2534,79 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
uploadToOssUtil.upload(localFilePath.replace("mp4", "flv"), userEditPath+flvFileName);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResultData deleteMosaics(DeleteMosaicParamVO param) throws Exception {
|
|
|
+
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
+ if(Objects.isNull(scenePlus)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+ SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
|
|
|
+
|
|
|
+ //如果redis数据丢失,从本地文件中同步马赛克数据到redis
|
|
|
+ this.syncMosaicFromFileToRedis(param.getNum());
|
|
|
+
|
|
|
+ String key = String.format(RedisKey.SCENE_MOSAIC_DATA, param.getNum());
|
|
|
+ redisUtil.hdel(key, param.getPanoIdList().toArray());
|
|
|
+
|
|
|
+ //写入本地文件,作为备份
|
|
|
+ this.writeMosaic(param.getNum());
|
|
|
+
|
|
|
+ //更新数据库
|
|
|
+ this.updateMosaicFlag(param.getNum());
|
|
|
+
|
|
|
+ //更新版本号
|
|
|
+ this.upgradeVersionById(sceneEditInfo.getId());
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> getMosaicList(String num) throws Exception {
|
|
|
+
|
|
|
+ //如果redis数据丢失,从本地文件中同步马赛克数据到redis
|
|
|
+ this.syncMosaicFromFileToRedis(num);
|
|
|
+
|
|
|
+ String key = String.format(RedisKey.SCENE_MOSAIC_DATA, num);
|
|
|
+ Map<String, String> map = redisUtil.hmget(key);
|
|
|
+ if(CollUtil.isEmpty(map)){
|
|
|
+ ResultData.ok(new String[0]);
|
|
|
+ }
|
|
|
+ return map.values().stream()
|
|
|
+ .map(mosaic-> JSON.parseObject(mosaic))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData addWaterMark(BaseFileParamVO param) throws Exception {
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
+ if(Objects.isNull(scenePlus)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService
|
|
|
+ .getByScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfoExt.setWaterMark(param.getFileName());
|
|
|
+ sceneEditInfoExtService.updateById(sceneEditInfoExt);
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData deleteWaterMark(BaseFileParamVO param) throws Exception {
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
+ if(Objects.isNull(scenePlus)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+ sceneUploadService.delete(
|
|
|
+ DeleteFileParamVO.builder()
|
|
|
+ .num(param.getNum())
|
|
|
+ .fileNames(Lists.newArrayList(param.getFileName()))
|
|
|
+ .bizType(FileBizType.WATERMARK.code()).build());
|
|
|
+
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfoExt.setWaterMark("");
|
|
|
+ sceneEditInfoExtService.updateById(sceneEditInfoExt);
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
}
|