|
@@ -1,23 +1,28 @@
|
|
|
package com.fdkankan.modeldemo.utils;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fdkankan.modeldemo.bean.SceneEditControlsBean;
|
|
|
import com.fdkankan.modeldemo.bean.SceneJsonBean;
|
|
|
import com.fdkankan.modeldemo.constant.Constant;
|
|
|
import com.fdkankan.modeldemo.entity.Scene;
|
|
|
+import com.fdkankan.modeldemo.entity.SceneFileMapping;
|
|
|
+import com.fdkankan.modeldemo.service.SceneFileMappingService;
|
|
|
import com.fdkankan.modeldemo.service.SceneService;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Component
|
|
|
public class ConvertUtil {
|
|
@@ -25,23 +30,101 @@ public class ConvertUtil {
|
|
|
@Autowired
|
|
|
private SceneService sceneService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SceneFileMappingService sceneFileMappingService;
|
|
|
+ @Resource
|
|
|
+ private FdfsUtil fdfsUtil;
|
|
|
+
|
|
|
+ private static String[] convertVisableHandler(JSONArray visibles, Map<Integer, String> uuidMap){
|
|
|
+ int size = visibles.size();
|
|
|
+ String[] visibleArr = new String[size];
|
|
|
+ for(int j = 0; j < size; j++){
|
|
|
+ int index = (Integer)visibles.get(j);
|
|
|
+ String uuid = uuidMap.get(index);
|
|
|
+ visibleArr[j] = uuid;
|
|
|
+ }
|
|
|
+ return visibleArr;
|
|
|
+ }
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
|
- String srcPath = args[0];
|
|
|
- System.out.println(srcPath);
|
|
|
- String targetPath = args[1];
|
|
|
- System.out.println(targetPath);
|
|
|
+ String sourcePath = "D:\\test\\";
|
|
|
+ String visionPath = "D:\\test\\images\\vision.txt";
|
|
|
+
|
|
|
+// String visionStr = FileUtil.readUtf8String(visionPath);
|
|
|
+// JSONObject visionObj = JSON.parseObject(visionStr);
|
|
|
+// JSONArray array = visionObj.getJSONArray("sweepLocations");
|
|
|
+// Map<Integer, String> uuidMap = new HashMap<>();
|
|
|
+// for(int i = 0; i < array.size(); i++){
|
|
|
+// JSONObject o = (JSONObject)array.get(i);
|
|
|
+// uuidMap.put(i, o.getString("uuid"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// for(int i = 0; i < array.size(); i++){
|
|
|
+// JSONObject o = (JSONObject)array.get(i);
|
|
|
+// JSONArray visibles = o.getJSONArray("visibles");
|
|
|
+// o.put("visibles", convertVisableHandler(visibles,uuidMap));
|
|
|
+//
|
|
|
+// JSONArray visibles2 = o.getJSONArray("visibles2");
|
|
|
+// o.put("visibles2", convertVisableHandler(visibles2,uuidMap));
|
|
|
+//
|
|
|
+// JSONArray visibles3 = o.getJSONArray("visibles3");
|
|
|
+// o.put("visibles3", convertVisableHandler(visibles3,uuidMap));
|
|
|
+// }
|
|
|
+//
|
|
|
+// FileUtil.writeUtf8String(JSON.toJSONString(visionObj), visionPath);
|
|
|
|
|
|
-// convert(srcPath, targetPath);
|
|
|
-// scanner.close();
|
|
|
+
|
|
|
+ //生成vison.modeldata
|
|
|
+ String visionStr = FileUtil.readUtf8String(sourcePath + "images/vision.txt");
|
|
|
+ JSONObject visionObj = JSON.parseObject(visionStr);
|
|
|
+ JSONArray sweepLocationsArr = visionObj.getJSONArray("sweepLocations");
|
|
|
+ //分割中高低点位
|
|
|
+ Map<Integer, List<String>> visibleMap = new HashMap();
|
|
|
+ Map<Integer, List<JSONObject>> subgroupMap = new HashMap<>();
|
|
|
+ for (Object item : sweepLocationsArr) {
|
|
|
+ JSONObject obj = (JSONObject) item;
|
|
|
+ int subgroup = obj.getIntValue("subgroup");
|
|
|
+ List<JSONObject> jsonObjects = subgroupMap.get(subgroup);
|
|
|
+ if(jsonObjects == null){
|
|
|
+ jsonObjects = new ArrayList<>();
|
|
|
+ subgroupMap.put(subgroup, jsonObjects);
|
|
|
+ }
|
|
|
+ obj.put("subgroup", 0);
|
|
|
+ jsonObjects.add(obj);
|
|
|
+
|
|
|
+ List<String> visible = visibleMap.get(subgroup);
|
|
|
+ if(visible == null){
|
|
|
+ visible = new ArrayList<>();
|
|
|
+ visibleMap.put(subgroup, visible);
|
|
|
+ }
|
|
|
+ visible.add(obj.getString("uuid"));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Integer subgroup : subgroupMap.keySet()) {
|
|
|
+ List<JSONObject> jsonObjects = subgroupMap.get(subgroup);
|
|
|
+ List<String> uuidList = visibleMap.get(subgroup);
|
|
|
+ for (JSONObject jsonObject : jsonObjects) {
|
|
|
+ String uuid = jsonObject.getString("uuid");
|
|
|
+ List<String> list = Lists.newArrayList(uuidList);
|
|
|
+ list.remove(uuid);
|
|
|
+ jsonObject.put("visibles",list);
|
|
|
+ jsonObject.put("visibles2",list);
|
|
|
+ jsonObject.put("visibles3",list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果是高中低场景,需要上传三份数据
|
|
|
+ for (Integer subgroup : subgroupMap.keySet()) {
|
|
|
+ //拆分vision.txt
|
|
|
+ String visionTxtPath = sourcePath + "images/vision" + "-" + subgroup + ".txt";
|
|
|
+ String visionmodeldataPath = sourcePath + "images/visionmodeldata" + "-" + subgroup + ".txt";
|
|
|
+ JSONObject visionTxtJson = new JSONObject();
|
|
|
+ visionTxtJson.put("sweepLocations", subgroupMap.get(subgroup));
|
|
|
+ FileUtil.writeUtf8String(visionTxtJson.toJSONString(), visionTxtPath);
|
|
|
+ CreateObjUtil.convertTxtToVisionmodeldata(visionTxtPath, visionmodeldataPath);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param sourcePath 原始资源目录
|
|
|
- * @param targetPath 目标资源目录
|
|
|
- * @return boolean true-转换成功 false-转换失败
|
|
|
- */
|
|
|
public Map<String, String> convert(String sourcePath, String num) throws Exception {
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
@@ -101,21 +184,49 @@ public class ConvertUtil {
|
|
|
|
|
|
//压缩成dam
|
|
|
String damKey = imgViewPath + "tieta.dam";
|
|
|
- String damPath = obj2TxtPath + File.separator + "results" +File.separator + "tieta.dam";
|
|
|
+ String damPath = obj2TxtPath + File.separator + "results" +File.separator + "dam.txt";
|
|
|
CreateObjUtil.convertTxtToDam( obj2TxtPath + File.separator + "results" +File.separator+"modeldata.txt", damPath);
|
|
|
map.put(damKey, damPath);
|
|
|
|
|
|
//复制文件
|
|
|
- if(FileUtil.exist(sourcePath + "data/" + "floorplan.json")){
|
|
|
- String floorplanJson = FileUtil.readUtf8String(sourcePath + "data/" + "floorplan.json");
|
|
|
+ JSONObject standarFloor = null;
|
|
|
+ Integer maxWallNum = 0;
|
|
|
+ if(FileUtil.exist(sourcePath + "data/floorplan.json")){
|
|
|
+ String floorplanJson = FileUtil.readUtf8String(sourcePath + "data/floorplan.json");
|
|
|
JSONObject jsonObject = JSON.parseObject(floorplanJson);
|
|
|
Integer currentId = jsonObject.getInteger("currentId");
|
|
|
if(Objects.nonNull(currentId) && currentId == 0){
|
|
|
FileUtil.del(sourcePath + "data/" + "floorplan.json");
|
|
|
+ }else{
|
|
|
+ JSONArray floors = jsonObject.getJSONArray("floors");
|
|
|
+ for (Object floor : floors) {
|
|
|
+ JSONObject floorObj = (JSONObject) floor;
|
|
|
+ Map walls = floorObj.getObject("walls", Map.class);
|
|
|
+ if(walls.keySet().size() > maxWallNum){
|
|
|
+ maxWallNum = walls.keySet().size();
|
|
|
+ standarFloor = floorObj;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //切割,按subgroup分成多份
|
|
|
+ for (Object floor : floors) {
|
|
|
+ JSONObject floorObj = (JSONObject) floor;
|
|
|
+ Integer subgroup = floorObj.getIntValue("subgroup");
|
|
|
+ floorObj.put("walls", standarFloor.getJSONObject("walls"));
|
|
|
+ floorObj.put("points", standarFloor.getJSONObject("points"));
|
|
|
+ floorObj.put("subgroup", 0);
|
|
|
+ floorObj.put("id", 0);
|
|
|
+ jsonObject.replace("floors", Arrays.asList(floorObj));
|
|
|
+ String floorplanPath = sourcePath + "data/floorplan" + "-" + subgroup + ".json";
|
|
|
+ FileUtil.writeUtf8String(jsonObject.toJSONString(), floorplanPath);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
List<File> dataFiles = FileUtil.loopFiles(sourcePath + "data/");
|
|
|
for (File dataFile : dataFiles) {
|
|
|
+ if(dataFile.getAbsolutePath().contains("floorplan")){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
map.put(dataFile.getAbsolutePath().replace(sourcePath + "data/", dataViewPath) , dataFile.getAbsolutePath());
|
|
|
}
|
|
|
|
|
@@ -141,46 +252,155 @@ public class ConvertUtil {
|
|
|
});
|
|
|
|
|
|
}
|
|
|
- map.put(imgViewPath + "vision.txt", sourcePath + "images/vision.txt");
|
|
|
// FileUtil.copy(sourcePath + "images/vision.txt", targetImagePath + "/vision.txt", true);
|
|
|
+ //单独上传一份全的vision.txt
|
|
|
+ this.uploadVisionTxt(num, sourcePath + "images/vision.txt");
|
|
|
|
|
|
//生成vison.modeldata
|
|
|
- CreateObjUtil.convertTxtToVisionmodeldata(sourcePath + "images/vision.txt", sourcePath + "images/vision.modeldata");
|
|
|
- map.put(imgViewPath + "vision.modeldata", sourcePath + "images/vision.modeldata");
|
|
|
+ String visionStr = FileUtil.readUtf8String(sourcePath + "images/vision.txt");
|
|
|
+ JSONObject visionObj = JSON.parseObject(visionStr);
|
|
|
+ JSONArray sweepLocationsArr = visionObj.getJSONArray("sweepLocations");
|
|
|
+ //分割中高低点位
|
|
|
+ Map<Integer, List<String>> visibleMap = new HashMap();
|
|
|
+ Map<Integer, List<JSONObject>> subgroupMap = new HashMap<>();
|
|
|
+ for (Object item : sweepLocationsArr) {
|
|
|
+ JSONObject obj = (JSONObject) item;
|
|
|
+ int subgroup = obj.getIntValue("subgroup");
|
|
|
+ List<JSONObject> jsonObjects = subgroupMap.get(subgroup);
|
|
|
+ if(jsonObjects == null){
|
|
|
+ jsonObjects = new ArrayList<>();
|
|
|
+ subgroupMap.put(subgroup, jsonObjects);
|
|
|
+ }
|
|
|
+ obj.put("subgroup", 0);
|
|
|
+ jsonObjects.add(obj);
|
|
|
+
|
|
|
+ List<String> visible = visibleMap.get(subgroup);
|
|
|
+ if(visible == null){
|
|
|
+ visible = new ArrayList<>();
|
|
|
+ visibleMap.put(subgroup, visible);
|
|
|
+ }
|
|
|
+ visible.add(obj.getString("uuid"));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Integer subgroup : subgroupMap.keySet()) {
|
|
|
+ List<JSONObject> jsonObjects = subgroupMap.get(subgroup);
|
|
|
+ List<String> uuidList = visibleMap.get(subgroup);
|
|
|
+ for (JSONObject jsonObject : jsonObjects) {
|
|
|
+ String uuid = jsonObject.getString("uuid");
|
|
|
+ List<String> list = Lists.newArrayList(uuidList);
|
|
|
+ list.remove(uuid);
|
|
|
+ jsonObject.put("visibles",list);
|
|
|
+ jsonObject.put("visibles2",list);
|
|
|
+ jsonObject.put("visibles3",list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//生成场景标题
|
|
|
String title = this.getTitle(num, sourcePath);
|
|
|
|
|
|
- //生成scene.json
|
|
|
- SceneJsonBean sceneJsonBean = this.genSceneJson(num, title);
|
|
|
- FileUtil.writeUtf8String(JSON.toJSONString(sceneJsonBean), sourcePath + "data/scene.json");
|
|
|
- map.put(dataViewPath + "scene.json", sourcePath + "data/scene.json");
|
|
|
+ //如果是高中低场景,需要上传三份数据
|
|
|
+ for (Integer subgroup : subgroupMap.keySet()) {
|
|
|
+
|
|
|
+ //拆分vision.txt
|
|
|
+ String visionTxtPath = sourcePath + "images/vision" + "-" + subgroup + ".txt";
|
|
|
+ String visionmodeldataPath = sourcePath + "images/visionmodeldata" + "-" + subgroup + ".txt";
|
|
|
+ JSONObject visionTxtJson = new JSONObject();
|
|
|
+ visionTxtJson.put("sweepLocations", subgroupMap.get(subgroup));
|
|
|
+ FileUtil.writeUtf8String(visionTxtJson.toJSONString(), visionTxtPath);
|
|
|
+ CreateObjUtil.convertTxtToVisionmodeldata(visionTxtPath, visionmodeldataPath);
|
|
|
+ map.put(imgViewPath + "vision.modeldata", visionmodeldataPath);
|
|
|
+ map.put(imgViewPath + "vision.txt", visionTxtPath);
|
|
|
+
|
|
|
+ //拆分floorplan.json
|
|
|
+ String floorplanPath = sourcePath + "data/floorplan" + "-" + subgroup + ".json";
|
|
|
+ if(FileUtil.exist(floorplanPath)){
|
|
|
+ map.put(dataViewPath + "floorplan.json", floorplanPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成scene.json
|
|
|
+ String sceneJsonPath = sourcePath + "data/scene" + "-" + subgroup + ".json";
|
|
|
+ SceneJsonBean sceneJsonBean = this.genSceneJson(num, title, subgroup);
|
|
|
+ FileUtil.writeUtf8String(JSON.toJSONString(sceneJsonBean), sceneJsonPath);
|
|
|
+ map.put(dataViewPath + "scene.json", sceneJsonPath);
|
|
|
+
|
|
|
+ String finalRoomId = num;
|
|
|
+ map.keySet().stream().forEach(key->{
|
|
|
+ List<SceneFileMapping> sceneFileMappingList = sceneFileMappingService.getByNumAndKey(finalRoomId, subgroup, key);
|
|
|
+ if(CollUtil.isNotEmpty(sceneFileMappingList)){
|
|
|
+ List<String> deleteIds = sceneFileMappingList.stream().map(v -> v.getId()).collect(Collectors.toList());
|
|
|
+ sceneFileMappingService.removeByIds(deleteIds);
|
|
|
+ }
|
|
|
+ SceneFileMapping sceneFileMapping = new SceneFileMapping();
|
|
|
+ Map<String, String> mapping = fdfsUtil.uploadFile(map.get(key));
|
|
|
+ sceneFileMapping.setNum(finalRoomId);
|
|
|
+ sceneFileMapping.setFileid(mapping.get("file_id"));
|
|
|
+ sceneFileMapping.setUrl(mapping.get("http_url"));
|
|
|
+ sceneFileMapping.setKey(key);
|
|
|
+ sceneFileMapping.setSubgroup(subgroup);
|
|
|
+ sceneFileMappingService.save(sceneFileMapping);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ List<Scene> list = sceneService.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getSubgroup, subgroup));
|
|
|
+ Scene scene = null;
|
|
|
+ if(CollUtil.isEmpty(list)){
|
|
|
+ scene = new Scene();
|
|
|
+ }else{
|
|
|
+ if(list.size() > 1){
|
|
|
+ sceneService.remove(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num));
|
|
|
+ scene = new Scene();
|
|
|
+ }else{
|
|
|
+ scene = list.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ scene.setTitle(title);
|
|
|
+ scene.setNum(num);
|
|
|
+ scene.setFloorlogosize(100);
|
|
|
+ scene.setScenekind("pano");
|
|
|
+ scene.setSceneresolution("4k");
|
|
|
+ scene.setScenefrom("realsee");
|
|
|
+ scene.setModelkind("dam");
|
|
|
+ scene.setFloorplanangle(0);
|
|
|
+ scene.setSubgroup(subgroup);
|
|
|
+ sceneService.saveOrUpdate(scene);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// map.put(imgViewPath + "vision.modeldata", sourcePath + "images/visionmodeldata.txt");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- private SceneJsonBean genSceneJson(String roomId, String title){
|
|
|
-
|
|
|
- Scene scene = sceneService.getByNum(roomId);
|
|
|
- if(Objects.isNull(scene)){
|
|
|
- scene = new Scene();
|
|
|
+ private void uploadVisionTxt(String num, String localVisionTxtPath){
|
|
|
+ String key = String.format(Constant.IMG_VIEW_PATH, num) + "vision.txt";
|
|
|
+ List<SceneFileMapping> sceneFileMappingList = sceneFileMappingService.list(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getKey, key).eq(SceneFileMapping::getNum, num).eq(SceneFileMapping::getSubgroup, -1));
|
|
|
+ if(CollUtil.isNotEmpty(sceneFileMappingList)){
|
|
|
+ List<String> deleteIds = sceneFileMappingList.stream().map(v -> v.getId()).collect(Collectors.toList());
|
|
|
+ sceneFileMappingService.removeByIds(deleteIds);
|
|
|
}
|
|
|
- scene.setTitle(title);
|
|
|
- scene.setNum(roomId);
|
|
|
- scene.setFloorlogosize(100);
|
|
|
- scene.setScenekind("pano");
|
|
|
- scene.setSceneresolution("4k");
|
|
|
- scene.setScenefrom("realsee");
|
|
|
- scene.setModelkind("dam");
|
|
|
- scene.setFloorplanangle(0);
|
|
|
- sceneService.saveOrUpdate(scene);
|
|
|
+ SceneFileMapping sceneFileMapping = new SceneFileMapping();
|
|
|
+ Map<String, String> mapping = fdfsUtil.uploadFile(localVisionTxtPath);//sourcePath + "images/vision.txt"
|
|
|
+ sceneFileMapping.setNum(num);
|
|
|
+ sceneFileMapping.setFileid(mapping.get("file_id"));
|
|
|
+ sceneFileMapping.setUrl(mapping.get("http_url"));
|
|
|
+ sceneFileMapping.setKey(key);
|
|
|
+ sceneFileMapping.setSubgroup(-1);
|
|
|
+ sceneFileMappingService.save(sceneFileMapping);
|
|
|
+ }
|
|
|
|
|
|
+ private SceneJsonBean genSceneJson(String roomId, String title, Integer subgroup){
|
|
|
SceneEditControlsBean sceneEditControlsBean = SceneEditControlsBean.builder()
|
|
|
.showDollhouse(1).showMap(1).showPanorama(1).showVR(1).showTitle(1).showFloorplan(1).build();
|
|
|
|
|
|
SceneJsonBean sceneJsonBean = SceneJsonBean.builder()
|
|
|
.title(title).description(null)
|
|
|
- .num(roomId).floorLogoSize(100).sceneKind("pano")
|
|
|
+ .num(roomId).subgroup(subgroup).floorLogoSize(100).sceneKind("pano")
|
|
|
.sceneResolution("4k").sceneFrom("realsee")
|
|
|
.modelKind("dam").floorPlanAngle(0).controls(sceneEditControlsBean).build();
|
|
|
|
|
@@ -196,7 +416,10 @@ public class ConvertUtil {
|
|
|
String sceneJsonStr = FileUtil.readUtf8String(sceneJsonPath);
|
|
|
JSONObject jsonObject = JSON.parseObject(sceneJsonStr);
|
|
|
String title = jsonObject.getString("title");
|
|
|
- return Objects.isNull(title) ? roomId : title;
|
|
|
+ if(StrUtil.isEmpty(title)){
|
|
|
+ return roomId;
|
|
|
+ }
|
|
|
+ return title;
|
|
|
}
|
|
|
|
|
|
public static void writeDataJson(String path){
|