Browse Source

修改激光场景重新计算逻辑

tianboguang 2 years ago
parent
commit
ba1620b15b

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

@@ -1,5 +1,6 @@
 package com.fdkankan.contro.service;
 
+import com.fdkankan.contro.entity.Camera;
 import com.fdkankan.contro.entity.ScenePlus;
 import com.fdkankan.contro.entity.ScenePlusExt;
 
@@ -12,11 +13,9 @@ import com.fdkankan.contro.entity.ScenePlusExt;
  * @since 2022/1/14
  **/
 public interface IFdkkLaserService {
-
-    void updateSceneStatus(String sceneCode,int status);
-
     void syncBuildResult(ScenePlus scenePlus, ScenePlusExt scenePlusExt);
 
     void pushBuildStatusToLaserSystem(String projectNum, String laserObjFilePath);
 
+    void saveScene(ScenePlus scenePlus, String scenePassword, Camera cameraEntity, String userName, boolean b);
 }

+ 60 - 65
src/main/java/com/fdkankan/contro/service/impl/IFdkkLaserServiceImpl.java

@@ -1,27 +1,22 @@
 package com.fdkankan.contro.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
-import com.fdkankan.common.constant.ErrorCode;
-import com.fdkankan.common.constant.HttpCode;
-import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.common.util.DateUtil;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.contro.entity.Camera;
 import com.fdkankan.contro.entity.ScenePlus;
 import com.fdkankan.contro.entity.ScenePlusExt;
-import com.fdkankan.contro.entity.User;
-import com.fdkankan.contro.service.ICameraService;
 import com.fdkankan.contro.service.IFdkkLaserService;
-import com.fdkankan.contro.service.IUserService;
+import com.fdkankan.contro.service.IScenePlusService;
 import com.fdkankan.model.utils.CreateObjUtil;
 import com.fdkankan.web.response.Result;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.client.RestTemplate;
 
 import java.io.File;
@@ -32,49 +27,42 @@ import java.util.Map;
 @Slf4j
 public class IFdkkLaserServiceImpl implements IFdkkLaserService {
 
-    private final String UPDATE_SCENE_STATUS_URL_TEMPLATE="/indoor/%s/scene/useStatus/%s";
-    private final String UPGRADE_TO_V4="/api/user/scene?num=%s";
-    private final String EDIT_LASER_BUILD_STATUS_URL="/laser/4dage/scene/editBuildStatus";
-    private final String DISABLE_COOPERATION_SCENE_URL="/laser/4dage/scene/cooperation/disable";
-    private final String ENABLE_COOPERATION_CAMERA_URL="/laser/4dage/scene/cooperation/cameraSave";
-    private final String GET_LASER_SCENE_USER_URL="/laser/4dage/getSceneNum";
-    private final String GET_LASER_SCENE_CODE_URL="/laser/4dage/scene/getScenesBySnCode";
-    private final String GET_LASER_SCENE_CNT_URL="/laser/4dage/scene/getSceneNumByCamera";
+    private final String SAVE_SCENE_URL_TEMPLATE = "/laser/init/%s/saveOrEdit";
+    private final String EDIT_LASER_BUILD_STATUS_URL = "/laser/4dage/scene/editBuildStatus";
+    private final String ENABLE_COOPERATION_CAMERA_URL = "/laser/4dage/scene/cooperation/cameraSave";
 
     @Value("${4dkk.laserService.host}")
     private String laserHost;
 
     @Autowired
-    private ICameraService cameraService;
-
-    @Autowired
-    private IUserService userService;
+    private IScenePlusService scenePlusService;
 
     private RestTemplate restTemplate = new RestTemplate();
 
-    public void updateSceneStatus(String sceneCode,int status){
-        String url = laserHost + String.format(UPDATE_SCENE_STATUS_URL_TEMPLATE,sceneCode,status);
-        ResponseEntity<Result> response = restTemplate.getForEntity(url, Result.class);
-        if(response.getStatusCode() != HttpStatus.OK){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_7001);
+    public void updateSceneStatus(String sceneCode, int sceneStatus, String path) {
+        String url = laserHost + String.format(SAVE_SCENE_URL_TEMPLATE, sceneCode);
+        Map<String, Object> params = new HashMap<>();
+        params.put("sceneCode", sceneCode);
+        params.put("status", sceneStatus);
+        ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
+        params.put("createTime", DateUtil.date2String(scenePlus.getCreateTime(), null));
+        if (!ObjectUtils.isEmpty(path)) {
+            params.put("path", path);
         }
-        if(response.getBody().getCode() != HttpCode.SC_SUCCESS){
-            throw new BusinessException(response.getBody().getCode(), response.getBody().getMsg());
+        log.info("自研激光转台相机同步,url:{},params:{}", url, JSONObject.toJSONString(params));
+        ResponseEntity<Result> responseEntity = restTemplate.postForEntity(url, params, Result.class);
+        log.info("自研激光转台相机同步,url:{},params:{},结果:{}", url, JSONObject.toJSONString(params), JSONObject.toJSONString(responseEntity.getBody()));
+        if (responseEntity.getStatusCode() != HttpStatus.OK || responseEntity.getBody().getCode() != HttpStatus.OK.value()) {
+            log.error("激光场景状态同步失败!");
         }
     }
 
     public void syncBuildResult(ScenePlus scenePlus, ScenePlusExt scenePlusExt) {
         log.info("激光转台相机构建结果 同步 请求 ");
         try {
-            String title = "";
-            String sceneName = scenePlus.getTitle();
-            if (StringUtils.isNotEmpty(sceneName)) {
-                title = sceneName;
-            }
-            String dataSource = scenePlusExt.getDataSource();
-            String jgPath = dataSource;
+            String jgPath = scenePlusExt.getDataSource();
             //创建目录
-            if (dataSource.lastIndexOf("/") != -1) {
+            if (scenePlusExt.getDataSource().lastIndexOf("/") != -1) {
                 jgPath = jgPath + "_laserData";
             } else {
                 jgPath = jgPath.substring(0, jgPath.length() - 1) + "_laserData";
@@ -90,31 +78,14 @@ public class IFdkkLaserServiceImpl implements IFdkkLaserService {
             jgDataJson.put("extras", null);
             FileUtils.writeFile(jgPath + File.separator + "data.json", jgDataJson.toString());
 
-            CreateObjUtil.cpfile(dataSource + "/results/laserData/cover", jgPath + "/extras/");
-            CreateObjUtil.cplaserfile(dataSource + "/results/laserData", jgPath + File.separator);
-
-            Camera camera = cameraService.getById(scenePlus.getCameraId());
-            String cameraName = camera.getChildName();
-            //激光相机
-            String url = laserHost + "/indoor/{sceneCode}/service/init?path="
-                    + jgPath + File.separator + "laserData" + "&title=" + title
-                    + "&childName=" + cameraName + "&createTime=" + scenePlus.getCreateTime()
-                    + "&snCode=" + cameraName;
-
-            if (scenePlus.getUserId() != null) {
-                url = url + "&userId=" + scenePlus.getUserId();
-            }
-
-            User user = userService.getById(scenePlus.getUserId());
+            // result/mesh/mesh.obj  --> jgPath/laserData/laser.obj
+            log.info("开始拷贝obj文件");
+            FileUtils.copyFolderAllFiles(scenePlusExt.getDataSource() + "/results/mesh", jgPath + "/laserData/mesh/", true);
 
-            if (ObjectUtils.isNotEmpty(user)) {
-                url = url + "&phone=" + user.getUserName();
-            }
+            CreateObjUtil.cpfile(scenePlusExt.getDataSource() + "/results/laserData/cover", jgPath + "/extras/");
+            CreateObjUtil.cplaserfile(scenePlusExt.getDataSource() + "/results/laserData", jgPath + File.separator);
 
-            url = url.replace("{sceneCode}", scenePlus.getNum());
-            log.info("激光转台相机 同步 :" + url);
-            JSONObject hotListJson = JSONObject.parseObject(restTemplate.getForObject(url, String.class));
-            log.info("激光转台相机 同步结束 :" + hotListJson);
+            updateSceneStatus(scenePlus.getNum(), 2, jgPath + File.separator + "laserData");
         } catch (Exception e) {
             log.error("激光转台相机同步失败", e);
         }
@@ -123,15 +94,39 @@ public class IFdkkLaserServiceImpl implements IFdkkLaserService {
     @Override
     public void pushBuildStatusToLaserSystem(String projectNum, String laserObjFilePath) {
         String url = laserHost + EDIT_LASER_BUILD_STATUS_URL;
-        Map<String,String> params = new HashMap<>();
-        params.put("sceneCode",projectNum);
-        params.put("objPath",laserObjFilePath);
-        log.info("激光系统同步BuildStatus,url:{},params:{}",ENABLE_COOPERATION_CAMERA_URL, JSONObject.toJSONString(params));
-        ResponseEntity<com.fdkankan.contro.common.Result> responseEntity = restTemplate.postForEntity(url,params, com.fdkankan.contro.common.Result.class);
-        log.info("激光系统同步BuildStatus,url:{},params:{},结果:{}",url, JSONObject.toJSONString(params),JSONObject.toJSONString(responseEntity.getBody()));
-        if(responseEntity.getStatusCode() != HttpStatus.OK || responseEntity.getBody().getCode() != HttpStatus.OK.value()){
+        Map<String, String> params = new HashMap<>();
+        params.put("sceneCode", projectNum);
+        params.put("objPath", laserObjFilePath);
+        log.info("激光系统同步BuildStatus,url:{},params:{}", ENABLE_COOPERATION_CAMERA_URL, JSONObject.toJSONString(params));
+        ResponseEntity<com.fdkankan.contro.common.Result> responseEntity = restTemplate.postForEntity(url, params, com.fdkankan.contro.common.Result.class);
+        log.info("激光系统同步BuildStatus,url:{},params:{},结果:{}", url, JSONObject.toJSONString(params), JSONObject.toJSONString(responseEntity.getBody()));
+        if (responseEntity.getStatusCode() != HttpStatus.OK || responseEntity.getBody().getCode() != HttpStatus.OK.value()) {
             log.error("激光系统同步BuildStatus");
         }
     }
 
+    public void saveScene(ScenePlus sceneProEntity, String scenePassword, Camera cameraEntity, String phone, boolean rebuild) {
+        String url = laserHost + String.format(SAVE_SCENE_URL_TEMPLATE, sceneProEntity.getNum());
+        Map<String, Object> params = new HashMap<>();
+        params.put("childName", cameraEntity.getChildName());
+        params.put("createTime", DateUtil.date2String(sceneProEntity.getCreateTime(), null));
+        params.put("phone", phone);
+        params.put("sceneCode", sceneProEntity.getNum());
+        params.put("snCode", cameraEntity.getSnCode());
+        params.put("status", sceneProEntity.getSceneStatus());
+        if (!rebuild) {
+            params.put("password", scenePassword);
+        } else {
+            params.put("status", 4);
+        }
+        params.put("title", sceneProEntity.getTitle());
+        params.put("userId", sceneProEntity.getUserId());
+        log.info("自研激光转台相机同步,url:{},params:{}", url, JSONObject.toJSONString(params));
+        ResponseEntity<Result> responseEntity = restTemplate.postForEntity(url, params, Result.class);
+        log.info("自研激光转台相机同步,url:{},params:{},结果,{}", url, JSONObject.toJSONString(params), JSONObject.toJSONString(responseEntity.getBody()));
+        if (responseEntity.getStatusCode() != HttpStatus.OK || responseEntity.getBody().getCode() != HttpStatus.OK.value()) {
+            log.error("激光场景状态同步失败!");
+        }
+    }
+
 }

+ 2 - 1
src/main/java/com/fdkankan/contro/service/impl/SceneFileBuildServiceImpl.java

@@ -1158,7 +1158,8 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
         }
 
         if(sceneSource == 4){
-            fdkkLaserService.updateSceneStatus(num,0);
+            Camera cameraEntity = cameraService.getByChildName(cameraName);
+            fdkkLaserService.saveScene(scenePlus,null,cameraEntity,userName,true);
             BuildSceneCallMessage buildSceneMqMessage =this.getBuildSceneMqMessage(
                 num, cameraName, unicode, cameraType, fileId,
                 dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")