ConvertUtil.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. package com.fdkankan.modeldemo.utils;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DatePattern;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.io.FileUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import com.alibaba.fastjson.JSON;
  8. import com.alibaba.fastjson.JSONArray;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  11. import com.fdkankan.modeldemo.bean.SceneEditControlsBean;
  12. import com.fdkankan.modeldemo.bean.SceneJsonBean;
  13. import com.fdkankan.modeldemo.bean.TagBean;
  14. import com.fdkankan.modeldemo.constant.Constant;
  15. import com.fdkankan.modeldemo.constant.RedisKey;
  16. import com.fdkankan.modeldemo.entity.*;
  17. import com.fdkankan.modeldemo.service.*;
  18. import com.fdkankan.redis.RedisClient;
  19. import com.google.common.collect.Lists;
  20. import com.google.common.collect.Sets;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Component;
  24. import javax.annotation.Resource;
  25. import java.io.File;
  26. import java.nio.charset.StandardCharsets;
  27. import java.util.*;
  28. import java.util.stream.Collectors;
  29. @Slf4j
  30. @Component
  31. public class ConvertUtil {
  32. private static String RESULTS_DIR = "results";
  33. private static String DATA_DIR = "data";
  34. private static String WALLS = "walls";
  35. private static String SUBGROUP = "subgroup";
  36. private static String JSON_EXTNAME = ".json";
  37. private static String IMAGES_4K = "images/4k/";
  38. private static String IMAGES_512 = "images/512/";
  39. private static String IMAGES_8K = "images/8k/";
  40. private static String TITLE = "title";
  41. private final static String SHOOTTIME = "shootTime";
  42. private static String extinguisherJson = "extinguisher.json";
  43. @Autowired
  44. private SceneService sceneService;
  45. @Autowired
  46. private SceneFileMappingService sceneFileMappingService;
  47. @Resource
  48. private FdfsUtil fdfsUtil;
  49. @Resource
  50. private RedisClient redisClient;
  51. @Autowired
  52. private SceneEditInfoService sceneEditInfoService;
  53. @Autowired
  54. private SceneEditInfoExtService sceneEditInfoExtService;
  55. @Autowired
  56. private SceneEditControlsService sceneEditControlsService;
  57. @Resource
  58. private FYunFileService fYunFileService;
  59. private static String[] convertVisableHandler(JSONArray visibles, Map<Integer, String> uuidMap){
  60. int size = visibles.size();
  61. String[] visibleArr = new String[size];
  62. for(int j = 0; j < size; j++){
  63. int index = (Integer)visibles.get(j);
  64. String uuid = uuidMap.get(index);
  65. visibleArr[j] = uuid;
  66. }
  67. return visibleArr;
  68. }
  69. public static void main(String[] args) throws Exception {
  70. String test = "D:\\test\\111.json";
  71. if(FileUtil.exist(test)){
  72. String extinguisherStr = FileUtil.readUtf8String(test);
  73. JSONObject jsonObject = JSON.parseObject(extinguisherStr);
  74. JSONArray imgBoxsList = jsonObject.getJSONArray("imgBoxsList");
  75. boolean existExtinguisher = imgBoxsList.stream().anyMatch(box -> {
  76. JSONObject boxObj = (JSONObject) box;
  77. JSONArray shapes = boxObj.getJSONArray("shapes");
  78. return shapes.stream().anyMatch(shape -> {
  79. JSONObject shapeObj = (JSONObject) shape;
  80. if ("1111".equals(shapeObj.getString("category"))) {
  81. return true;
  82. }
  83. return false;
  84. });
  85. });
  86. System.out.println(existExtinguisher);
  87. }
  88. }
  89. public Map<String, String> convert(String sourcePath, String num, String stationCode, Date upTime, String convertType, String upTimeKey) throws Exception {
  90. Map<String, String> map = new HashMap<>();
  91. String dataViewPath = String.format(Constant.DATA_VIEW_PATH, num);
  92. String imgViewPath = String.format(Constant.IMG_VIEW_PATH, num);
  93. String obj2TxtPath = null;
  94. if(!sourcePath.endsWith(File.separator)){
  95. sourcePath = sourcePath + File.separator;
  96. }
  97. obj2TxtPath = sourcePath.substring(0, sourcePath.length() - 1) + "_obj2txt";
  98. FileUtil.mkdir(obj2TxtPath);
  99. //调用算法生成modeldata.txt
  100. String extrasPath = obj2TxtPath + File.separator + "extras";
  101. FileUtil.mkdir(extrasPath);
  102. FileUtil.copyContent(new File(sourcePath + DATA_DIR + File.separator + "mesh"), new File(extrasPath), true);
  103. //写data.json
  104. writeDataJson(obj2TxtPath);
  105. //调用算法建模
  106. build3dModel(obj2TxtPath);
  107. //校验算法是否正常结束
  108. String uploadJsonPath = obj2TxtPath + File.separator + RESULTS_DIR +File.separator+"upload.json";
  109. boolean success = checkComputeCompleted(uploadJsonPath, 5, 300);
  110. if(!success){
  111. throw new RuntimeException("计算失败,obj2TxtPath:" + obj2TxtPath);
  112. }
  113. String uploadData = FileUtil.readUtf8String(uploadJsonPath);
  114. JSONObject uploadJson = null;
  115. JSONArray array = null;
  116. if(uploadData!=null) {
  117. uploadJson = JSONObject.parseObject(uploadData);
  118. array = uploadJson.getJSONArray("upload");
  119. }
  120. JSONObject fileJson = null;
  121. String fileName = "";
  122. for(int i = 0, len = array.size(); i < len; i++) {
  123. fileJson = array.getJSONObject(i);
  124. fileName = fileJson.getString("file");
  125. //文件不存在抛出异常
  126. if (!new File(obj2TxtPath + File.separator + RESULTS_DIR + File.separator + fileName).exists()) {
  127. throw new Exception(obj2TxtPath + File.separator + RESULTS_DIR + File.separator + fileName + "文件不存在");
  128. }
  129. //tex文件夹
  130. if (fileJson.getIntValue("clazz") == 15) {
  131. // FileUtil.copy(obj2TxtPath + File.separator + RESULTS_DIR + File.separator + fileName,
  132. // targetImagePath + File.separator + "tieta_texture/" + fileName.replace("tex/", ""),true);
  133. map.put(imgViewPath + "tieta_texture/" + fileName.replace("tex/", ""), obj2TxtPath + File.separator + RESULTS_DIR + File.separator + fileName);
  134. }
  135. }
  136. //压缩成dam
  137. String damKey = imgViewPath + "tieta.dam";
  138. String damPath = obj2TxtPath + File.separator + RESULTS_DIR +File.separator + "dam.txt";
  139. CreateObjUtil.convertTxtToDam( obj2TxtPath + File.separator + RESULTS_DIR +File.separator+"modeldata.txt", damPath);
  140. map.put(damKey, damPath);
  141. //识别灭火器
  142. Integer extinguisher = this.getExtinguisher(num, sourcePath, map);
  143. //复制文件
  144. JSONObject standarFloor = null;
  145. Integer maxWallNum = 0;
  146. if(FileUtil.exist(sourcePath + DATA_DIR + "/floorplan.json")){
  147. String floorplanJson = FileUtil.readUtf8String(sourcePath + DATA_DIR + "/floorplan.json");
  148. JSONObject jsonObject = JSON.parseObject(floorplanJson);
  149. Integer currentId = jsonObject.getInteger("currentId");
  150. if(Objects.nonNull(currentId) && currentId == 0){
  151. FileUtil.del(sourcePath + DATA_DIR + "/floorplan.json");
  152. }else{
  153. JSONArray floors = jsonObject.getJSONArray("floors");
  154. for (Object floor : floors) {
  155. JSONObject floorObj = (JSONObject) floor;
  156. Map walls = floorObj.getObject(WALLS, Map.class);
  157. if(walls.keySet().size() > maxWallNum){
  158. maxWallNum = walls.keySet().size();
  159. standarFloor = floorObj;
  160. }
  161. }
  162. //切割,按subgroup分成多份
  163. for (Object floor : floors) {
  164. JSONObject floorObj = (JSONObject) floor;
  165. Integer subgroup = floorObj.getIntValue(SUBGROUP);
  166. floorObj.put(WALLS, standarFloor.getJSONObject(WALLS));
  167. floorObj.put("points", standarFloor.getJSONObject("points"));
  168. floorObj.put(SUBGROUP, 0);
  169. floorObj.put("id", 0);
  170. jsonObject.replace("floors", Arrays.asList(floorObj));
  171. String floorplanPath = sourcePath + DATA_DIR + "/floorplan" + "-" + subgroup + JSON_EXTNAME;
  172. FileUtil.writeUtf8String(jsonObject.toJSONString(), floorplanPath);
  173. }
  174. }
  175. }
  176. List<File> dataFiles = FileUtil.loopFiles(sourcePath + DATA_DIR + "/");
  177. for (File dataFile : dataFiles) {
  178. if(dataFile.getAbsolutePath().contains("floorplan")){
  179. continue;
  180. }
  181. map.put(dataFile.getAbsolutePath().replace(sourcePath + DATA_DIR + "/", dataViewPath) , dataFile.getAbsolutePath());
  182. }
  183. String finalSourcePath = sourcePath;
  184. if(FileUtil.exist(finalSourcePath + IMAGES_4K)){
  185. FileUtil.listFileNames(sourcePath + IMAGES_4K).stream().forEach(v->{
  186. map.put(imgViewPath + "pan/high/" + v.replaceAll("-", ""), finalSourcePath + IMAGES_4K + v);
  187. // FileUtil.copy(finalSourcePath + IMAGES_4K + v, targetImagePath + "/pan/high/" + v.replaceAll("-", ""), true);
  188. });
  189. }
  190. if(FileUtil.exist(finalSourcePath + IMAGES_512)){
  191. FileUtil.listFileNames(finalSourcePath + IMAGES_512).stream().forEach(v->{
  192. map.put(imgViewPath + "pan/low/" + v.replaceAll("-", ""), finalSourcePath + IMAGES_512 + v);
  193. // FileUtil.copy(finalSourcePath + IMAGES_512 + v, targetImagePath + "/pan/low/" + v.replaceAll("-", ""), true);
  194. });
  195. }
  196. if(FileUtil.exist(finalSourcePath + IMAGES_8K)) {
  197. FileUtil.listFileNames(finalSourcePath + IMAGES_8K).stream().forEach(v -> {
  198. map.put(imgViewPath + "pan/8k/" + v.replaceAll("-", ""), finalSourcePath + IMAGES_8K + v);
  199. // FileUtil.copy(finalSourcePath + IMAGES_8K + v, targetImagePath + "/pan/8k/" + v.replaceAll("-", ""), true);
  200. });
  201. }
  202. // FileUtil.copy(sourcePath + "images/vision.txt", targetImagePath + "/vision.txt", true);
  203. //单独上传一份全的vision.txt
  204. this.uploadVisionTxt(num, upTimeKey, sourcePath + "images/vision.txt");
  205. //生成vison.modeldata
  206. String visionStr = FileUtil.readUtf8String(sourcePath + "images/vision.txt");
  207. JSONObject visionObj = JSON.parseObject(visionStr);
  208. JSONArray sweepLocationsArr = visionObj.getJSONArray("sweepLocations");
  209. //分割中高低点位
  210. Map<Integer, List<String>> visibleMap = new HashMap();
  211. Map<Integer, List<JSONObject>> subgroupMap = new HashMap<>();
  212. for (Object item : sweepLocationsArr) {
  213. JSONObject obj = (JSONObject) item;
  214. int subgroup = obj.getIntValue(SUBGROUP);
  215. List<JSONObject> jsonObjects = subgroupMap.get(subgroup);
  216. if(jsonObjects == null){
  217. jsonObjects = new ArrayList<>();
  218. subgroupMap.put(subgroup, jsonObjects);
  219. }
  220. obj.put(SUBGROUP, 0);
  221. jsonObjects.add(obj);
  222. List<String> visible = visibleMap.get(subgroup);
  223. if(visible == null){
  224. visible = new ArrayList<>();
  225. visibleMap.put(subgroup, visible);
  226. }
  227. visible.add(obj.getString("uuid"));
  228. }
  229. for (Integer subgroup : subgroupMap.keySet()) {
  230. List<JSONObject> jsonObjects = subgroupMap.get(subgroup);
  231. List<String> uuidList = visibleMap.get(subgroup);
  232. for (JSONObject jsonObject : jsonObjects) {
  233. String uuid = jsonObject.getString("uuid");
  234. List<String> list = Lists.newArrayList(uuidList);
  235. list.remove(uuid);
  236. jsonObject.put("visibles",list);
  237. jsonObject.put("visibles2",list);
  238. jsonObject.put("visibles3",list);
  239. }
  240. }
  241. //生成场景标题
  242. JSONObject sceneBashInfo = this.getSceneBashInfo(num, sourcePath);
  243. //如果是高中低场景,需要上传三份数据
  244. for (Integer subgroup : subgroupMap.keySet()) {
  245. //拆分vision.txt
  246. String visionTxtPath = sourcePath + "images/vision" + "-" + subgroup + ".txt";
  247. String visionmodeldataPath = sourcePath + "images/visionmodeldata" + "-" + subgroup + ".txt";
  248. JSONObject visionTxtJson = new JSONObject();
  249. visionTxtJson.put("sweepLocations", subgroupMap.get(subgroup));
  250. FileUtil.writeUtf8String(visionTxtJson.toJSONString(), visionTxtPath);
  251. CreateObjUtil.convertTxtToVisionmodeldata(visionTxtPath, visionmodeldataPath);
  252. map.put(imgViewPath + "vision.modeldata", visionmodeldataPath);
  253. map.put(imgViewPath + "vision.txt", visionTxtPath);
  254. //拆分floorplan.json
  255. String floorplanPath = sourcePath + DATA_DIR + "/floorplan" + "-" + subgroup + JSON_EXTNAME;
  256. if(FileUtil.exist(floorplanPath)){
  257. map.put(dataViewPath + "floorplan.json", floorplanPath);
  258. }
  259. //生成scene.json
  260. String sceneJsonPath = sourcePath + DATA_DIR + "/scene" + "-" + subgroup + JSON_EXTNAME;
  261. SceneJsonBean sceneJsonBean = this.genSceneJson(num, sceneBashInfo.getString(TITLE), subgroup);
  262. FileUtil.writeUtf8String(JSON.toJSONString(sceneJsonBean), sceneJsonPath);
  263. map.put(dataViewPath + "scene.json", sceneJsonPath);
  264. String finalRoomId = num;
  265. map.keySet().stream().forEach(key->{
  266. List<SceneFileMapping> sceneFileMappingList = sceneFileMappingService.getByScene(finalRoomId, subgroup, upTimeKey, key);
  267. if(CollUtil.isNotEmpty(sceneFileMappingList)){
  268. List<String> deleteIds = sceneFileMappingList.stream().map(v -> v.getId()).collect(Collectors.toList());
  269. sceneFileMappingService.removeByIds(deleteIds);
  270. }
  271. SceneFileMapping sceneFileMapping = new SceneFileMapping();
  272. Map<String, String> mapping = fdfsUtil.uploadFile(map.get(key));
  273. sceneFileMapping.setNum(finalRoomId);
  274. sceneFileMapping.setFileid(mapping.get("file_id"));
  275. sceneFileMapping.setUrl(mapping.get("http_url"));
  276. sceneFileMapping.setKey(key);
  277. sceneFileMapping.setSubgroup(subgroup);
  278. sceneFileMapping.setUpTime(upTimeKey);
  279. sceneFileMappingService.save(sceneFileMapping);
  280. });
  281. // List<Scene> list = sceneService.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getSubgroup, subgroup).eq(Scene::getUpTimeKey, upTimeKey));
  282. // Scene scene = null;
  283. // if(CollUtil.isEmpty(list)){
  284. // scene = new Scene();
  285. // }else{
  286. // if(list.size() > 1){
  287. // sceneService.remove(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num));
  288. // scene = new Scene();
  289. // }else{
  290. // scene = list.get(0);
  291. // }
  292. // }
  293. Scene scene = new Scene();
  294. scene.setTitle(sceneBashInfo.getString(TITLE));
  295. scene.setNum(num);
  296. scene.setFloorlogosize(100);
  297. scene.setScenekind("pano");
  298. scene.setSceneresolution("4k");
  299. scene.setScenefrom("realsee");
  300. scene.setModelkind("dam");
  301. scene.setFloorplanangle(0);
  302. scene.setSubgroup(subgroup);
  303. scene.setStationcode(stationCode);
  304. scene.setShootTime(sceneBashInfo.getDate(SHOOTTIME));
  305. scene.setUpTime(upTime);
  306. scene.setAlgorithmTime(new Date());
  307. scene.setExtinguisher(extinguisher);
  308. scene.setUpTimeKey(upTimeKey);
  309. scene.setCacheKeyHasTime(1);
  310. sceneService.save(scene);
  311. SceneEditInfo sceneEditInfo = new SceneEditInfo();
  312. sceneEditInfo.setScenePlusId(scene.getId());
  313. sceneEditInfo.setTitle(scene.getTitle());
  314. sceneEditInfo.setDescription(scene.getDescription());
  315. sceneEditInfoService.save(sceneEditInfo);
  316. SceneEditInfoExt sceneEditInfoExt = new SceneEditInfoExt();
  317. sceneEditInfoExt.setScenePlusId(scene.getId());
  318. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  319. sceneEditInfoExtService.save(sceneEditInfoExt);
  320. SceneEditControls sceneEditControls = new SceneEditControls();
  321. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  322. sceneEditControlsService.save(sceneEditControls);
  323. //同步热点
  324. this.keepHot(scene, sceneEditInfo);
  325. }
  326. return map;
  327. }
  328. private void keepHot(Scene scene, SceneEditInfo sceneEditInfo){
  329. String num = scene.getNum();
  330. String upTimeKey = scene.getUpTimeKey();
  331. Integer subgroup = scene.getSubgroup();
  332. //查询最新的历史场景
  333. Scene preScene = sceneService.getOne(new LambdaQueryWrapper<Scene>()
  334. .eq(Scene::getNum, num)
  335. .eq(Scene::getSubgroup, subgroup)
  336. .lt(Scene::getUpTimeKey, upTimeKey)
  337. .orderByDesc(Scene::getUpTimeKey).last("limit 1"));
  338. if(Objects.isNull(preScene)){
  339. return;
  340. }
  341. //查询是否有热点
  342. String key = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(num, subgroup, preScene.getUpTimeKey(), preScene.getCacheKeyHasTime()));
  343. Map<String, String> allTagsMap = redisClient.hmget(RedisClient.scene_sys_code, key);
  344. if(CollUtil.isEmpty(allTagsMap)){
  345. return;
  346. }
  347. //如果有热点,复制redis和涉及的图片
  348. String newKey = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(num, subgroup, upTimeKey, scene.getCacheKeyHasTime()));
  349. redisClient.hmset(RedisClient.scene_sys_code, newKey, allTagsMap);
  350. sceneEditInfo.setTags(1);
  351. sceneEditInfoService.updateById(sceneEditInfo);
  352. //组装热点数据
  353. for (String sid : allTagsMap.keySet()) {
  354. String hot = allTagsMap.get(sid);
  355. JSONObject jsonObject = JSON.parseObject(hot);
  356. String type = jsonObject.getString("type");
  357. if(!"image".equals(type) && !"video".equals(type) && !"audio".equals(type)){
  358. continue;
  359. }
  360. JSONObject media = jsonObject.getJSONObject("media");
  361. JSONArray mediaDetail = media.getJSONArray(type);
  362. List<String> keyList = mediaDetail.stream().map(v -> {
  363. JSONObject content = (JSONObject) v;
  364. String src = content.getString("src");
  365. return String.format(Constant.USER_VIEW_PATH, num) + src;
  366. }).collect(Collectors.toList());
  367. if(CollUtil.isNotEmpty(keyList)){
  368. List<SceneFileMapping> fileMappingList = sceneFileMappingService.getBySceneBatch(num, subgroup, preScene.getUpTimeKey(), keyList);
  369. if(CollUtil.isNotEmpty(fileMappingList)){
  370. fileMappingList.stream().forEach(v->{
  371. v.setId(null);
  372. v.setUpTime(upTimeKey);
  373. });
  374. sceneFileMappingService.saveBatch(fileMappingList);
  375. }
  376. }
  377. }
  378. //发布热点
  379. this.publicHotData(scene);
  380. //复制icon
  381. //查询缓存是否包含icons
  382. String iconKey = String.format(RedisKey.SCENE_HOT_ICONS, RedisKey.getNumStr(num, subgroup, preScene.getUpTimeKey() ,preScene.getCacheKeyHasTime()));
  383. Set<String> icons = redisClient.sGet(RedisClient.scene_sys_code, iconKey);
  384. if(CollUtil.isNotEmpty(icons)){
  385. String newIconKey = String.format(RedisKey.SCENE_HOT_ICONS, RedisKey.getNumStr(num, subgroup, scene.getUpTimeKey() ,scene.getCacheKeyHasTime()));
  386. redisClient.sSet(RedisClient.scene_sys_code, newIconKey, icons);
  387. List<String> iconFileList = icons.stream().map(i -> {
  388. return String.format(Constant.USER_VIEW_PATH, num) + i;
  389. }).collect(Collectors.toList());
  390. if(CollUtil.isNotEmpty(iconFileList)){
  391. List<SceneFileMapping> fileMappingList = sceneFileMappingService.getBySceneBatch(num, subgroup, preScene.getUpTimeKey(), iconFileList);
  392. if(CollUtil.isNotEmpty(fileMappingList)){
  393. fileMappingList.stream().forEach(v->{
  394. v.setId(null);
  395. v.setUpTime(scene.getUpTimeKey());
  396. });
  397. sceneFileMappingService.saveBatch(fileMappingList);
  398. }
  399. }
  400. }
  401. }
  402. private void publicHotData(Scene scene) {
  403. String sceneNum = scene.getNum();
  404. Integer subgroup = scene.getSubgroup();
  405. String upTime = scene.getUpTimeKey();
  406. Integer cacheKeyHasTime = scene.getCacheKeyHasTime();
  407. String hotDataKey = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(sceneNum, subgroup,upTime,cacheKeyHasTime));
  408. Map<String, String> hotMap = redisClient.hmget(RedisClient.scene_sys_code, hotDataKey);
  409. JSONArray tags = new JSONArray();
  410. if(CollUtil.isNotEmpty(hotMap)){
  411. List<TagBean> tagBeanList = hotMap.entrySet().stream().map(entry -> {
  412. JSONObject jsonObject = JSON.parseObject(entry.getValue());
  413. return TagBean.builder()
  414. .createTime(jsonObject.getLong("createTime"))
  415. .tag(jsonObject).build();
  416. }).collect(Collectors.toList());
  417. //按创建时间倒叙排序
  418. tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
  419. //移除createTime字段
  420. tagBeanList.stream().forEach(tagBean -> {
  421. tags.add(tagBean.getTag());
  422. });
  423. }
  424. String hotJsonPath = String.format(Constant.USER_VIEW_PATH, sceneNum) + "hot.json";
  425. fYunFileService.uploadFile(sceneNum, subgroup, upTime, tags.toString().getBytes(StandardCharsets.UTF_8), hotJsonPath);
  426. }
  427. private Integer getExtinguisher(String num, String sourcePath, Map<String, String> map){
  428. int extinguisher = 0;
  429. try {
  430. String imgViewPath = String.format(Constant.IMG_VIEW_PATH, num);
  431. //灭火器标注识别
  432. String imagesPath = sourcePath + "images/";
  433. String annihilatorPath = imagesPath + "4k/";
  434. String cmd = "bash /home/ubuntu/bin/PotreeConverter.sh tieta_det " + annihilatorPath + " /home/ubuntu/bin/model/best.onnx " + imagesPath + extinguisherJson;
  435. log.info("---------start extinguisher, cmd:{}", cmd);
  436. CmdUtils.callLineSh(cmd);
  437. log.info("---------end extinguisher, cmd:{}", cmd);
  438. if(FileUtil.exist(imagesPath + extinguisherJson)){
  439. map.put(imgViewPath + extinguisherJson, imagesPath + extinguisherJson);
  440. String extinguisherStr = FileUtil.readUtf8String(imagesPath + extinguisherJson);
  441. JSONObject jsonObject = JSON.parseObject(extinguisherStr);
  442. JSONArray imgBoxsList = jsonObject.getJSONArray("imgBoxsList");
  443. boolean existExtinguisher = imgBoxsList.stream().anyMatch(box -> {
  444. JSONObject boxObj = (JSONObject) box;
  445. JSONArray shapes = boxObj.getJSONArray("shapes");
  446. if(CollUtil.isNotEmpty(shapes)){
  447. return shapes.stream().anyMatch(shape -> {
  448. JSONObject shapeObj = (JSONObject) shape;
  449. if ("extinguisher".equals(shapeObj.getString("category"))) {
  450. return true;
  451. }
  452. return false;
  453. });
  454. }
  455. return false;
  456. });
  457. if(existExtinguisher){
  458. extinguisher = 1;
  459. }
  460. }
  461. }catch (Exception e){
  462. log.error("getExtinguisher fail, num:{}", num, e);
  463. }
  464. return extinguisher;
  465. }
  466. private void uploadVisionTxt(String num, String upTime, String localVisionTxtPath){
  467. String key = String.format(Constant.IMG_VIEW_PATH, num) + "vision.txt";
  468. List<SceneFileMapping> sceneFileMappingList = sceneFileMappingService.getByScene(num, -1, upTime, key);
  469. if(CollUtil.isNotEmpty(sceneFileMappingList)){
  470. List<String> deleteIds = sceneFileMappingList.stream().map(v -> v.getId()).collect(Collectors.toList());
  471. sceneFileMappingService.removeByIds(deleteIds);
  472. }
  473. SceneFileMapping sceneFileMapping = new SceneFileMapping();
  474. Map<String, String> mapping = fdfsUtil.uploadFile(localVisionTxtPath);//sourcePath + "images/vision.txt"
  475. sceneFileMapping.setNum(num);
  476. sceneFileMapping.setFileid(mapping.get("file_id"));
  477. sceneFileMapping.setUrl(mapping.get("http_url"));
  478. sceneFileMapping.setKey(key);
  479. sceneFileMapping.setSubgroup(-1);
  480. sceneFileMapping.setUpTime(upTime);
  481. sceneFileMappingService.save(sceneFileMapping);
  482. }
  483. private SceneJsonBean genSceneJson(String roomId, String title, Integer subgroup){
  484. SceneEditControlsBean sceneEditControlsBean = SceneEditControlsBean.builder()
  485. .showDollhouse(1).showMap(1).showPanorama(1).showVR(1).showTitle(1).showFloorplan(1).build();
  486. SceneJsonBean sceneJsonBean = SceneJsonBean.builder()
  487. .title(title).description(null)
  488. .num(roomId).subgroup(subgroup).floorLogoSize(100).sceneKind("pano")
  489. .sceneResolution("4k").sceneFrom("realsee")
  490. .modelKind("dam").floorPlanAngle(0).controls(sceneEditControlsBean).build();
  491. return sceneJsonBean;
  492. }
  493. private JSONObject getSceneBashInfo(String roomId, String sourcePath){
  494. JSONObject info = new JSONObject();
  495. String sceneJsonPath = sourcePath + DATA_DIR + "/scene.json";
  496. if(!FileUtil.exist(sceneJsonPath)){
  497. return info;
  498. }
  499. String sceneJsonStr = FileUtil.readUtf8String(sceneJsonPath);
  500. JSONObject jsonObject = JSON.parseObject(sceneJsonStr);
  501. String title = jsonObject.getString(TITLE);
  502. if(StrUtil.isEmpty(title)){
  503. title = roomId;
  504. }
  505. info.put(TITLE, title);
  506. String shootTimeStr = jsonObject.getString(SHOOTTIME);
  507. if(StrUtil.isNotEmpty(shootTimeStr)){
  508. info.put(SHOOTTIME, DateUtil.parse(shootTimeStr, DatePattern.NORM_DATETIME_FORMAT));
  509. }
  510. return info;
  511. }
  512. public static void writeDataJson(String path){
  513. JSONObject dataJson = new JSONObject();
  514. dataJson.put("obj2txt", true);
  515. dataJson.put("split_type", "SPLIT_V6");
  516. dataJson.put("data_describe", "double spherical");
  517. dataJson.put("skybox_type", "SKYBOX_V5");
  518. FileUtil.writeUtf8String(dataJson.toString(), path + File.separator + "data.json");
  519. }
  520. public static void build3dModel(String folderName) throws Exception {
  521. System.out.println("开始建模");
  522. String command = "sudo bash /home/ubuntu/bin/Launcher.sh " + folderName;
  523. CmdUtils.callLineSh(command);
  524. System.out.println("计算完毕:" + command);
  525. }
  526. public static boolean checkComputeCompleted(String uploadJsonPath, int maxCheckTimes, long waitTime) throws Exception {
  527. int checkTimes = 1;
  528. boolean exist = false;
  529. do {
  530. if ((new File(uploadJsonPath)).exists()) {
  531. exist = true;
  532. break;
  533. }
  534. Thread.sleep(waitTime);
  535. ++checkTimes;
  536. } while(checkTimes <= maxCheckTimes);
  537. return exist;
  538. }
  539. }