浏览代码

平面图ai识别

dengsixing 3 月之前
父节点
当前提交
1843895b7b

+ 107 - 112
src/main/java/com/fdkankan/contro/mq/service/impl/BuildSceneServiceImpl.java

@@ -2,9 +2,7 @@ package com.fdkankan.contro.mq.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.FileUtil;
-import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.StrUtil;
-import cn.hutool.core.util.ZipUtil;
 import cn.hutool.extra.qrcode.QrCodeUtil;
 import cn.hutool.extra.qrcode.QrConfig;
 import cn.hutool.http.HttpUtil;
@@ -146,7 +144,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
     private ILinkPanService linkPanService;
 
     @Override
-    public void buildScenePre(BuildSceneCallMessage message) throws Exception{
+    public void buildScenePre(BuildSceneCallMessage message) throws Exception {
         String num = message.getSceneNum();
         try {
             Map<String, Object> sceneStatusParam = new HashMap<>();
@@ -154,11 +152,11 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             sceneStatusParam.put("status", 0);
             commonService.sendUpdateSceneStatusMqToQueues(sceneStatusParam);
             //重新计算时需要删除文件夹,否知使用缓存
-            if(new File(message.getPath() + File.separator + "results").exists()){
+            if (new File(message.getPath() + File.separator + "results").exists()) {
                 FileUtils.deleteDirectory(message.getPath() + File.separator + "results");
             }
             //由于刘强说caches会影响计算结果,所以这里删除caches
-            if(new File(message.getPath() + File.separator + "caches").exists()){
+            if (new File(message.getPath() + File.separator + "caches").exists()) {
                 FileUtils.deleteDirectory(message.getPath() + File.separator + "caches");
             }
 
@@ -167,7 +165,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
                     && message.getExt().containsKey("deleteExtras")
                     && (Boolean) message.getExt().get("deleteExtras")) {
                 String extras = String.format(UploadFilePath.scene_result_data_path, num).concat("extras");
-                if(CollUtil.isNotEmpty(fYunFileService.listRemoteFiles(extras))){
+                if (CollUtil.isNotEmpty(fYunFileService.listRemoteFiles(extras))) {
                     fYunFileService.deleteFolder(extras);
                 }
             }
@@ -180,9 +178,9 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             this.downLoadSource(message, message.getPath());
 
             List<String> linkPanTargetList = linkPanService.genLinkPanPre(num);
-            if(CollUtil.isNotEmpty(linkPanTargetList)){
+            if (CollUtil.isNotEmpty(linkPanTargetList)) {
                 Map<String, Object> ext = message.getExt();
-                if(Objects.isNull(ext)){
+                if (Objects.isNull(ext)) {
                     ext = new HashMap<>();
                     message.setExt(ext);
                 }
@@ -210,19 +208,19 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
 
             if (rewrite) {
                 Integer location = fdageJson.getInteger("location");
-                if(location != null && location == 6 && fdageJson.containsKey("exportMeshObj")){
+                if (location != null && location == 6 && fdageJson.containsKey("exportMeshObj")) {
                     fdageJson.remove("exportMeshObj");
                 }
                 FileUtils.writeFile(message.getPath().concat("/capture/data.fdage"), fdageJson.toJSONString());
             }
 
-            message.getBuildContext().put("cameraType",message.getCameraType());
+            message.getBuildContext().put("cameraType", message.getCameraType());
 
             //查询是否超过比例50%,如果超过,则启动128G服务器弹性伸缩
             Float maxRate = fdageJson.getFloat("maxRate");
-            if(env.equals("gn") && Objects.nonNull(maxRate) && maxRate > 50){
+            if (env.equals("gn") && Objects.nonNull(maxRate) && maxRate > 50) {
                 Map<String, Object> ext = message.getExt();
-                if(Objects.isNull(ext)){
+                if (Objects.isNull(ext)) {
                     ext = new HashMap<>();
                     message.setExt(ext);
                 }
@@ -231,8 +229,8 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
 
             log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
 
-        }catch (Exception e){
-            log.error("场景计算前置处理出错,num"+num, e);
+        } catch (Exception e) {
+            log.error("场景计算前置处理出错,num" + num, e);
             buildSceneDTService.handBaseFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
             haixinService.noticHaixin(num, false);
             throw e;
@@ -250,7 +248,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
     }
 
     @Override
-    public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
+    public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage, String path) {
         String ossPath = getOssPath(path);
         fYunFileService.downloadFileByCommand(path + File.separator + "capture", ossPath);
     }
@@ -278,12 +276,12 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
                 buildSceneDTService.handModelFail("计算失败", message.getPath(), sceneCode, message.getHostName());
                 return;
             }
-            JSONObject fdageData = getFdageData(path + File.separator + "capture" +File.separator+"data.fdage");
+            JSONObject fdageData = getFdageData(path + File.separator + "capture" + File.separator + "data.fdage");
 
             ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
 
             Integer cameraType = Integer.parseInt(message.getBuildContext().get("cameraType").toString());
-            Map<String, String> uploadFiles = getUploadFiles(scenePlus,path,cameraType,fdageData);
+            Map<String, String> uploadFiles = getUploadFiles(scenePlus, path, cameraType, fdageData);
 
             scenePlus.setPayStatus(PayStatus.PAY.code());
             scenePlus.setUpdateTime(new Date());
@@ -306,10 +304,10 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             fYunFileService.uploadMulFiles(uploadFiles);
 
             //修改oss上dam的内容编码
-            Map<String,String> damFileHeaders = new HashMap<>();
-            damFileHeaders.put("Content-Encoding","gzip");
+            Map<String, String> damFileHeaders = new HashMap<>();
+            damFileHeaders.put("Content-Encoding", "gzip");
             String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
-            fYunFileService.uploadFile(damPath,  String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ConstantFileName.modelUUID + "_50k.dam", damFileHeaders);
+            fYunFileService.uploadFile(damPath, String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ConstantFileName.modelUUID + "_50k.dam", damFileHeaders);
 
             //拷贝部分文件到编辑目录,用于用户编辑
             this.copyToEditDir(sceneCode);
@@ -330,15 +328,11 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             //江门需求,算法识别平面图
             commonService.uploadFloorplanAi(sceneCode, path);
 
-            boolean detFloorplan = false;
-            Map<String, Object> ext = message.getExt();
-            if(CollUtil.isNotEmpty(ext) && ext.containsKey("detFloorplan") && Objects.nonNull(ext.get("detFloorplan"))){
-                detFloorplan = (Boolean) ext.get("detFloorplan");
-            }
+            LinkedHashMap<Integer, Boolean> detFloorplan = message.getDetFloorplan();
             boolean hasFloorplanAi = commonService.detFloorPlanAi(sceneCode, path, detFloorplan);
-            if(hasFloorplanAi){
+            if (hasFloorplanAi) {
                 scenePlus.setHasFloorplanAi(CommonStatus.YES.code().intValue());
-            }else{
+            } else {
                 scenePlus.setHasFloorplanAi(CommonStatus.NO.code().intValue());
             }
 
@@ -359,12 +353,12 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             Long space = commonService.getSpace(sceneCode);
 
             //写入数据库
-            this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), message.getComputeTime(),isObj,scenePlusExt);
+            this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), message.getComputeTime(), isObj, scenePlusExt);
 
             Object[] editInfoArr = commonService.updateEditInfo(scenePlus);
-            SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
-            SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
-            SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
+            SceneEditInfo sceneEditInfo = (SceneEditInfo) editInfoArr[0];
+            SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt) editInfoArr[1];
+            SceneEditControls sceneEditControls = (SceneEditControls) editInfoArr[2];
             sceneEditInfoExt.setLinks(links);
             sceneEditInfoExtService.updateById(sceneEditInfoExt);
 
@@ -377,11 +371,11 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             if (cameraType == 14) {
                 //计算成功  激光转台相机 同步 请求
                 fdkkLaserService.syncBuildResult(scenePlus.getNum(), path, scenePlus.getCreateTime(), Calendar.getInstance().getTime(), scenePlusExt.getShootCount(), scenePlus.getPayStatus());
-                sceneEditControlsService.update(new LambdaUpdateWrapper<SceneEditControls>().set(SceneEditControls::getShowMap,0)
-                        .eq(SceneEditControls::getEditInfoId,sceneEditInfo.getId()));
+                sceneEditControlsService.update(new LambdaUpdateWrapper<SceneEditControls>().set(SceneEditControls::getShowMap, 0)
+                        .eq(SceneEditControls::getEditInfoId, sceneEditInfo.getId()));
                 sceneEditControls.setShowMap(0);
             } else if (new File(path + "/results/laserData/vision_edit.txt").exists()) {
-                fdkkLaserService.cloudPointBuild(sceneCode,path);
+                fdkkLaserService.cloudPointBuild(sceneCode, path);
             }
 
 
@@ -389,7 +383,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
             Company company = !ObjectUtils.isEmpty(cameraDetail.getCompanyId()) ? companyService.getById(cameraDetail.getCompanyId()) : null;
             //写scene.json
-            commonService.writeSceneJson(sceneCode, videosJson,sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus,scenePlusExt,company);
+            commonService.writeSceneJson(sceneCode, videosJson, sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus, scenePlusExt, company);
 
             String qrLogo = !ObjectUtils.isEmpty(company) && !ObjectUtils.isEmpty(company.getQrLogo()) ? company.getQrLogo() : null;
 
@@ -400,10 +394,10 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             //计算成功,通知APP
             Integer pushChannel = fdageData.getInteger("pushChannel");
             String pushToken = fdageData.getString("pushToken");
-            this.pushMsgToApp(pushChannel,pushToken, cameraType, scenePlus.getTitle(), scenePlusExt.getWebSite());
+            this.pushMsgToApp(pushChannel, pushToken, cameraType, scenePlus.getTitle(), scenePlusExt.getWebSite());
 
 //            //删除计算目录
-            if(CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)){
+            if (CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)) {
                 CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/"));
             }
 
@@ -414,7 +408,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             scenePlusExtService.updateById(scenePlusExt);
 
             //国际环境需要发邮件通知
-            if("eur".equals(env)){
+            if ("eur".equals(env)) {
                 commonService.sendEmail(sceneCode);
             }
 
@@ -422,8 +416,8 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
 
             log.info("场景计算结果处理结束,场景码:{}", sceneCode);
 
-        }catch (Exception e){
-            log.error("场景计算结果处理出错,num"+sceneCode, e);
+        } catch (Exception e) {
+            log.error("场景计算结果处理出错,num" + sceneCode, e);
             buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
             throw e;
         } finally {
@@ -437,9 +431,9 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         }
     }
 
-    private void removeSceneAsynOperLog(String num){
+    private void removeSceneAsynOperLog(String num) {
         List<SceneAsynOperLog> list = sceneAsynOperLogService.list(new LambdaQueryWrapper<SceneAsynOperLog>().eq(SceneAsynOperLog::getNum, num));
-        if(CollUtil.isEmpty(list)){
+        if (CollUtil.isEmpty(list)) {
             return;
         }
         //删除数据库记录
@@ -447,7 +441,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         sceneAsynOperLogService.removeByIds(deleteIdList);
 
         list.parallelStream().forEach(item -> {
-            if(StrUtil.isNotEmpty(item.getUrl())){
+            if (StrUtil.isNotEmpty(item.getUrl())) {
                 try {
                     fYunFileService.deleteFile(item.getUrl());
                 } catch (IOException e) {
@@ -475,7 +469,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
 //        });
 //    }
 
-    private Map<String, String> getUploadFiles(ScenePlus scenePlus,String path,Integer cameraType,JSONObject fdageData) throws Exception {
+    private Map<String, String> getUploadFiles(ScenePlus scenePlus, String path, Integer cameraType, JSONObject fdageData) throws Exception {
         if (ObjectUtils.isEmpty(scenePlus)) {
             throw new Exception("未找到场景信息:" + path);
         }
@@ -545,34 +539,34 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
 
         //exportMeshObj这个是字段由app写入的
         boolean genModel = true;//是否生成模型 默认生成,深时场景要根据 exportMeshObj判断是否生成
-        if(!ObjectUtils.isEmpty(cameraType)
+        if (!ObjectUtils.isEmpty(cameraType)
                 && cameraType == 14
-                && (!fdageData.containsKey("exportMeshObj") || fdageData.getIntValue("exportMeshObj") != 1)){
+                && (!fdageData.containsKey("exportMeshObj") || fdageData.getIntValue("exportMeshObj") != 1)) {
             genModel = false;
         }
         boolean gen3dTiles = true;//是否生成3dtiles模型 默认生成
-        if(!ModelKind.THREE_D_TILE.code().equals(modelKind)
+        if (!ModelKind.THREE_D_TILE.code().equals(modelKind)
                 || CollUtil.isEmpty(sdTilesSceneSourceList)
-                || !sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){
+                || !sdTilesSceneSourceList.contains(scenePlus.getSceneSource())) {
             gen3dTiles = false;
         }
 
         log.info("--------------genModel:{}, gen3dTiles:{}----------------------", genModel, gen3dTiles);
 
-        if(genModel){
+        if (genModel) {
             if (!gen3dTiles) {
                 String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
                 CreateObjUtil.convertTxtToDam(path + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", damPath);
 //                FileUtil.writeBytes(ZipUtil.gzip(new File(damPath)), damPath);
                 map.put(damPath, imagesPath + ConstantFileName.modelUUID + "_50k.dam");
-            }else{
+            } else {
                 List<String> list = FileUtils.list(new File(path + File.separator + "results" + File.separator + ModelKind.THREE_D_TILE.code()));
                 log.info("3dtiles list:{}", JSON.toJSONString(list));
-                if(CollUtil.isEmpty(list)){
+                if (CollUtil.isEmpty(list)) {
                     log.error("3dtiles目录异常,3dtiles地址:{}", new File(path + File.separator + "results" + File.separator + ModelKind.THREE_D_TILE.code()));
                     throw new Exception("3dtiles目录异常");
                 }
-                list.stream().forEach(str->{
+                list.stream().forEach(str -> {
                     map.put(str, str.replace(path + File.separator + "results" + File.separator, imagesPath));
                 });
             }
@@ -583,7 +577,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         map.put(resultsPath + "vision.modeldata", imagesPath + "vision.modeldata");
 
         log.info("数据转换完成:" + projectNum);
-        if(!new File("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum).exists()){
+        if (!new File("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum).exists()) {
             FileUtil.mkdir("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum);
         }
 //        map.put(resultsPath + "floorplan.json", dataViewPath + "floor.json");
@@ -602,20 +596,20 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         String data = FileUtils.readFile(dataFdagePath);
         //获取data.fdage的内容
         JSONObject dataJson = new JSONObject();
-        if(data!=null){
+        if (data != null) {
             dataJson = JSONObject.parseObject(data);
         }
         return dataJson;
     }
 
-    private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles){
+    private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles) {
 
         //户型图上传
-        String  dataViewPath = UploadFilePath.DATA_VIEW_PATH + "floor-cad-%s.%s";
+        String dataViewPath = UploadFilePath.DATA_VIEW_PATH + "floor-cad-%s.%s";
         String floorCadPath = path + "/results/floorplan_cad";
         List<String> floorCadList = FileUtils.getFileList(floorCadPath);
-        if(CollUtil.isNotEmpty(floorCadList)){
-            floorCadList.stream().forEach(str->{
+        if (CollUtil.isNotEmpty(floorCadList)) {
+            floorCadList.stream().forEach(str -> {
                 String substring = str.substring(str.lastIndexOf(File.separator) + 1);
                 String[] arr = substring.split("floor");
                 String[] arr2 = arr[1].split("\\.");
@@ -625,12 +619,12 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
 
     }
 
-    private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt){
+    private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt) {
         String num = scenePlus.getNum();
         String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
 
         Integer status = 1;
-        if(scenePlus.getSceneSource() == 4 || scenePlus.getSceneSource() == 5){//如果是激光场景,需要激光系统那边完全处理好之后再发mq通知更新状态
+        if (scenePlus.getSceneSource() == 4 || scenePlus.getSceneSource() == 5) {//如果是激光场景,需要激光系统那边完全处理好之后再发mq通知更新状态
             status = 0;
         }
 
@@ -660,12 +654,12 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             }
         }
         //生成二维码
-        String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png";
-        String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png";
+        String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/" + num + ".png";
+        String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/" + num + "_en.png";
         QrConfig qrConfig = QrConfig.create();
         qrConfig.setWidth(1024);
         qrConfig.setHeight(1024);
-        if(StrUtil.isNotEmpty(localLogoPath)){
+        if (StrUtil.isNotEmpty(localLogoPath)) {
             qrConfig.setImg(localLogoPath);
         }
         QrCodeUtil.generate(scenePlusExt.getWebSite(), qrConfig, FileUtil.file(outPathZh));
@@ -674,52 +668,52 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
         fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
 
-        if(!ObjectUtils.isEmpty(localLogoPath)){
+        if (!ObjectUtils.isEmpty(localLogoPath)) {
             FileUtils.deleteFile(localLogoPath);
         }
     }
 
-    private void pushMsgToApp(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
+    private void pushMsgToApp(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite) {
         log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
-        if(Objects.isNull(pushChannel) || StrUtil.isBlank(pushToken)){
+        if (Objects.isNull(pushChannel) || StrUtil.isBlank(pushToken)) {
             return;
         }
 
         String title = sceneName + "计算完成";
         String body = "您上传的" + sceneName + "计算完成,点击查看";
 
-        try{
-            if(FYunTypeEnum.AWS.code().equals(fYunFileService.getFyunType())){
+        try {
+            if (FYunTypeEnum.AWS.code().equals(fYunFileService.getFyunType())) {
                 PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
-                        title, body , webSite);
+                        title, body, webSite);
                 return;
             }
 
             PushMessageConfig pushConfig = null;
-            if(pushChannel == 0){
-                if(cameraType == 10 || cameraType == 13){
+            if (pushChannel == 0) {
+                if (cameraType == 10 || cameraType == 13) {
                     //ios
                     pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY_Z, PushMessageConfig.IOS_SECRET_Z);
-                    pushConfig.sendIOSUnicast(pushToken,  "四维看看Minion",title, body, webSite);
-                }else {
+                    pushConfig.sendIOSUnicast(pushToken, "四维看看Minion", title, body, webSite);
+                } else {
                     //ios
                     pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY, PushMessageConfig.IOS_SECRET);
-                    pushConfig.sendIOSUnicast(pushToken, "四维看看Pro",title, body, webSite);
+                    pushConfig.sendIOSUnicast(pushToken, "四维看看Pro", title, body, webSite);
                 }
-            }else {
-                if(cameraType == 10 || cameraType == 13){
+            } else {
+                if (cameraType == 10 || cameraType == 13) {
                     //ios
                     //安卓
                     pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY_Z, PushMessageConfig.ANDROID_SECRET_Z);
-                    pushConfig.sendAndroidUnicast2(pushToken, "四维看看Minion",title, body, webSite);
-                }else {
+                    pushConfig.sendAndroidUnicast2(pushToken, "四维看看Minion", title, body, webSite);
+                } else {
                     //安卓
                     pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY, PushMessageConfig.ANDROID_SECRET);
-                    pushConfig.sendAndroidUnicast(pushToken, "四维看看Pro",title, body, webSite);
+                    pushConfig.sendAndroidUnicast(pushToken, "四维看看Pro", title, body, webSite);
                 }
             }
             log.info("消息推送结束!");
-        }catch (Exception e){
+        } catch (Exception e) {
             log.error("推送消息失败:", e);
         }
     }
@@ -738,7 +732,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
 
         for (Entry<String, String> entry : map.entrySet()) {
-                fYunFileService.copyFileInBucket(entry.getValue(), entry.getKey());
+            fYunFileService.copyFileInBucket(entry.getValue(), entry.getKey());
         }
     }
 
@@ -747,23 +741,23 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         Map<String, Object> videoMap = new HashMap<>();
         String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
         JSONArray videoArray = null;
-        if(StringUtils.isNotEmpty(videosHdr)){
+        if (StringUtils.isNotEmpty(videosHdr)) {
             videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
         }
-        if(videoArray != null){
-            for(int i = 0, len = videoArray.size(); i < len; i++) {
+        if (videoArray != null) {
+            for (int i = 0, len = videoArray.size(); i < len; i++) {
                 videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
-                if(videoArray.getJSONObject(i).containsKey("fov")){
+                if (videoArray.getJSONObject(i).containsKey("fov")) {
                     videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
                 }
             }
         }
 
         //获取upload中的video视频名称
-        String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
+        String uploadData = FileUtils.readFile(path + File.separator + "results" + File.separator + "upload.json");
         JSONObject uploadJson = null;
         JSONArray array = null;
-        if(uploadData!=null) {
+        if (uploadData != null) {
             uploadJson = JSONObject.parseObject(uploadData);
             array = uploadJson.getJSONArray("upload");
         }
@@ -775,25 +769,25 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         JSONObject videoJson = null;
         JSONObject videosJson = new JSONObject();
         long videoSize = 0L;
-        for(int i = 0, len = array.size(); i < len; i++) {
+        for (int i = 0, len = array.size(); i < len; i++) {
             fileJson = array.getJSONObject(i);
             fileName = fileJson.getString("file");
-            if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
+            if (fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")) {
                 videoJson = new JSONObject();
                 videoJson.put("id", fileName.substring(
-                    0, fileName.lastIndexOf(".")).replace("videos/", ""));
+                        0, fileName.lastIndexOf(".")).replace("videos/", ""));
 
                 //如果ts文件存在,就计算ts大小
-                if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
-                    videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
+                if (new File(path + File.separator + "results" + File.separator + fileName.replace(".mp4", ".ts")).exists()) {
+                    videoSize = new File(path + File.separator + "results" + File.separator + fileName.replace(".mp4", ".ts")).length();
                     videoJson.put("tsSize", videoSize);
                 }
-                if(videoMap.containsKey(videoJson.get("id"))){
+                if (videoMap.containsKey(videoJson.get("id"))) {
                     videoJson.put("value", videoMap.get(videoJson.get("id")));
                 }
-                if(videoMap.containsKey(videoJson.get("id") + "_fov")){
+                if (videoMap.containsKey(videoJson.get("id") + "_fov")) {
                     videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
-                }else {
+                } else {
                     videoJson.put("blend_fov", 7);
                 }
                 jsonArray.add(videoJson);
@@ -801,30 +795,31 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         }
 
         videosJson.put("data", jsonArray);
-        if(Objects.nonNull(videoVersion) && videoVersion >= 4){
+        if (Objects.nonNull(videoVersion) && videoVersion >= 4) {
             videosJson.put("version", 3);
             videosJson.put("upPath", String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up.xml");
-            if(cameraType == 13 || cameraType == 14){
+            if (cameraType == 13 || cameraType == 14) {
                 //转台相机
                 videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
             }
-        }else {
+        } else {
             videosJson.put("version", 1);
             videosJson.put("upPath", String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up2.xml");
-            if(cameraType == 13 || cameraType == 14){
+            if (cameraType == 13 || cameraType == 14) {
                 //转台相机
                 videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
             }
         }
 
-        if(cameraType == 5 || cameraType == 6){
+        if (cameraType == 5 || cameraType == 6) {
             videosJson.put("version", 1);
             videosJson.put("upPath", String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "stitch_params.txt");
         }
 
         return videosJson;
     }
-    private void updateDbPlus(int sceneSource,Long space,String videosJson, Long computeTime,boolean isObj,ScenePlusExt scenePlusExt){
+
+    private void updateDbPlus(int sceneSource, Long space, String videosJson, Long computeTime, boolean isObj, ScenePlusExt scenePlusExt) {
 
         scenePlusExt.setSpace(space);
         scenePlusExt.setComputeTime(computeTime.toString());
@@ -832,11 +827,11 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         scenePlusExt.setVideos(videosJson);
         scenePlusExt.setIsObj(isObj ? 1 : 0);
 
-        if(ModelTypeEnums.TILE_CODE.equals(modelType)){
+        if (ModelTypeEnums.TILE_CODE.equals(modelType)) {
             scenePlusExt.setSceneScheme(3);
         }
 
-        switch (SceneSource.get(sceneSource)){
+        switch (SceneSource.get(sceneSource)) {
             case BM:
                 scenePlusExt.setSceneResolution(SceneResolution.two_K.code());
                 scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
@@ -859,7 +854,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
                 break;
         }
 
-        String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
+        String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code() : SceneKind.TILES.code();
         scenePlusExt.setSceneKind(sceneKind);
 //        scenePlusExt.setModelKind(modelKind);
 
@@ -869,27 +864,27 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         scenePlusExtService.updateById(scenePlusExt);
     }
 
-    private Integer getShootCount(ScenePlusExt scenePlusExt){
+    private Integer getShootCount(ScenePlusExt scenePlusExt) {
         Integer shootCount = null;
         String homePath = SceneUtil.getHomePath(scenePlusExt.getDataSource());
         JSONObject dataFdageObj = JSON.parseObject(fYunFileService.getFileContent(homePath.concat("data.fdage")));
-        if(Objects.nonNull(dataFdageObj)){
+        if (Objects.nonNull(dataFdageObj)) {
             JSONArray points = dataFdageObj.getJSONArray("points");
-            if(CollUtil.isNotEmpty(points)){
+            if (CollUtil.isNotEmpty(points)) {
                 shootCount = points.size();
             }
         }
-        if(Objects.nonNull(shootCount) && shootCount > 0){
+        if (Objects.nonNull(shootCount) && shootCount > 0) {
             return shootCount;
         }
 
         String slamDataStr = fYunFileService.getFileContent(homePath.concat("slam_data.json"));
         JSONObject slamDataObj = JSON.parseObject(slamDataStr);
-        if(Objects.nonNull(slamDataObj)){
+        if (Objects.nonNull(slamDataObj)) {
             JSONArray viewsInfo = slamDataObj.getJSONArray("views_info");
-            if(CollUtil.isNotEmpty(viewsInfo)){
+            if (CollUtil.isNotEmpty(viewsInfo)) {
                 shootCount = viewsInfo.stream().mapToInt(info -> {
-                    return  ((JSONObject) info).getJSONArray("list_pose").size();
+                    return ((JSONObject) info).getJSONArray("list_pose").size();
                 }).sum();
             }
         }
@@ -910,7 +905,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             return false;
         }
         JSONObject json = CreateHouseJsonUtil.createHouseTypeJsonByCad(floorPlanCardFilePath);
-        if(Objects.isNull(json)){
+        if (Objects.isNull(json)) {
             return false;
         }
         String hourseTypeJsonPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "houseType.json";

+ 3 - 2
src/main/java/com/fdkankan/contro/service/ICommonService.java

@@ -2,10 +2,10 @@ package com.fdkankan.contro.service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.contro.entity.*;
-import com.fdkankan.contro.vo.ScenePlusVO;
 import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
 
 import java.io.IOException;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -54,5 +54,6 @@ public interface ICommonService {
 
     void uploadFloorplanAi(String num, String path) throws IOException;
 
-    boolean detFloorPlanAi(String num, String path, boolean detFloorplan) throws IOException;
+    boolean detFloorPlanAi(String num, String path, LinkedHashMap<Integer, Boolean> detFloorplan) throws IOException;
+
 }

+ 49 - 37
src/main/java/com/fdkankan/contro/service/impl/CommonServiceImpl.java

@@ -3,22 +3,23 @@ package com.fdkankan.contro.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.fdkankan.common.util.FileUtils;
-import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.common.constant.CommonStatus;
 import com.fdkankan.common.constant.PayStatus;
 import com.fdkankan.common.constant.SpaceType;
+import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.contro.bean.SceneJsonBean;
 import com.fdkankan.contro.constant.DetectType;
 import com.fdkankan.contro.entity.*;
 import com.fdkankan.contro.factory.UserEditData.UserEditDataHandler;
 import com.fdkankan.contro.factory.UserEditData.UserEditDataHandlerFactory;
-import com.fdkankan.contro.service.ICommonService;
 import com.fdkankan.contro.service.*;
 import com.fdkankan.contro.vo.SceneEditControlsVO;
 import com.fdkankan.fyun.config.FYunFileConfig;
@@ -42,11 +43,6 @@ import javax.annotation.Resource;
 import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
 import java.util.*;
 
 @Slf4j
@@ -106,10 +102,10 @@ public class CommonServiceImpl implements ICommonService {
     private RabbitMqProducer rabbitMqProducer;
     @Autowired
     private ISceneInfoSyncMqConfigService sceneInfoSyncMqConfigService;
+    @Resource
+    private FYunFileServiceInterface fYunFileService;
     @Autowired
     private ISceneMarkShapeService sceneMarkShapeService;
-    @Autowired
-    private SceneShapeEnumService sceneShapeEnumService;
 
     @Override
     public void uploadBuildResultData(String num, String dataSource, String version) {
@@ -533,27 +529,53 @@ public class CommonServiceImpl implements ICommonService {
     }
 
     @Override
-    public boolean detFloorPlanAi(String num, String path, boolean detFloorplan) throws IOException {
-        String workDir = path + "/detFloorplan/";
-        String detectPath = workDir + "detect.json";
+    public boolean detFloorPlanAi(String num, String path, LinkedHashMap<Integer, Boolean> detFloorplan) throws IOException {
+
         try {
-            if (!detFloorplan) {
-                return false;
+            String aiJsonKey = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "floorplan/ai.json";
+            //先清空历史数据,因为数据格式改动很多个版本,已经无法按照规律进行过滤删除,所以这里先删除历史数据,而后再根据算法生成去插入数据
+            sceneMarkShapeService.remove(new LambdaQueryWrapper<SceneMarkShape>().eq(SceneMarkShape::getNum, num).eq(SceneMarkShape::getType, DetectType.PLAN.getCode()));
+            if(fYunFileService.fileExist(aiJsonKey)){
+                fYunFileService.deleteFile(aiJsonKey);
             }
-            SceneMarkShape sceneMarkShape = sceneMarkShapeService.readDetectJson(detectPath);
-            if (ObjectUtil.isNull(sceneMarkShape)){
+            if(CollUtil.isEmpty(detFloorplan)){
                 return false;
             }
-            sceneMarkShape.setNum(num);
-            SceneMarkShape shape = sceneMarkShapeService.findByNumAndImagePathAndType(num, sceneMarkShape.getImagePath(), DetectType.PLAN.getCode());
-            if (ObjectUtil.isNotNull(shape)){
-                sceneMarkShape.setId(shape.getId());
-                sceneMarkShape.setUpdateTime(new Date());
-                sceneMarkShapeService.updateById(sceneMarkShape);
-            }else {
+            boolean hasFloorplanAi = false;
+            String workDir = path + "/detFloorplan/";
+            for (Integer subgroup : detFloorplan.keySet()) {
+                Boolean yes = detFloorplan.get(subgroup);
+                SceneMarkShape sceneMarkShape = null;
+                if(yes){
+                    String detectPath = workDir + subgroup + "/detect.json";
+                    sceneMarkShape = sceneMarkShapeService.readDetectJson(detectPath);
+                }
+                if (ObjUtil.isNull(sceneMarkShape)){
+                    sceneMarkShape = new SceneMarkShape();
+                    String infoJsonPath = path + "/results/floorplan/info.json";
+                    JSONObject infoObj = JSON.parseObject(FileUtil.readUtf8String(infoJsonPath));
+                    JSONArray floors = infoObj.getJSONArray("floors");
+                    for (Object floor : floors) {
+                        JSONObject floorObj = (JSONObject)floor;
+                        Integer group = floorObj.getInteger("subgroup");
+                        if(!subgroup.equals(group)){
+                            continue;
+                        }
+                        JSONObject resolution = floorObj.getJSONObject("resolution");
+                        sceneMarkShape.setImageWidth(resolution.getInteger("width"));
+                        sceneMarkShape.setImageHeight(resolution.getInteger("height"));
+                    }
+                }
+                if(Objects.isNull(sceneMarkShape.getShapes())){
+                    sceneMarkShape.setShapes(new ArrayList<>());
+                }
+                sceneMarkShape.setNum(num);
                 sceneMarkShape.setCreateTime(new Date());
                 sceneMarkShape.setType(DetectType.PLAN.getCode());
                 sceneMarkShapeService.save(sceneMarkShape);
+                if(CollUtil.isNotEmpty(sceneMarkShape.getShapes())){
+                    hasFloorplanAi = true;
+                }
             }
 
             List<SceneMarkShape> sceneMarkShapes = sceneMarkShapeService.findByNumAndType(num, DetectType.PLAN.getCode());
@@ -561,10 +583,6 @@ public class CommonServiceImpl implements ICommonService {
                 if (ObjectUtil.isNotEmpty(ms.getShapes())){
                     for (JSONObject s : ms.getShapes()) {
                         String category = s.getString("category");
-                        SceneShapeEnum sceneShapeEnum = sceneShapeEnumService.findByClassName(category);
-                        if (ObjectUtil.isNotNull(sceneShapeEnum)){
-                            s.put("name",sceneShapeEnum.getName());
-                        }
                         if (category.contains("Tag_")){
                             s.put("category","Tag");
                         }
@@ -572,14 +590,9 @@ public class CommonServiceImpl implements ICommonService {
                 }
             }
 
-            String aiJsonKey = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "floorplan/ai.json";
-            if(CollUtil.isNotEmpty(sceneMarkShapes)){
-                fYunFileServiceInterface.uploadFile(JSON.toJSONString(sceneMarkShapes).getBytes(StandardCharsets.UTF_8), aiJsonKey);
-                return true;
-            }else{
-                fYunFileServiceInterface.deleteFile(aiJsonKey);
-                return false;
-            }
+            fYunFileService.uploadFile(JSON.toJSONString(sceneMarkShapes).getBytes(StandardCharsets.UTF_8), aiJsonKey);
+
+            return hasFloorplanAi;
         }catch (Exception e){
             log.error("平面图ai识别处理报错", e);
             return false;
@@ -587,5 +600,4 @@ public class CommonServiceImpl implements ICommonService {
 //            FileUtil.del(workDir);
         }
     }
-
 }