ConvertUtil.java 28 KB

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