123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package com.fdkankan.contro.service.impl;
- import com.alibaba.fastjson.JSONObject;
- 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.ScenePro;
- import com.fdkankan.contro.service.IFdkkLaserService;
- import com.fdkankan.contro.service.IScenePlusService;
- import com.fdkankan.web.response.Result;
- import lombok.extern.slf4j.Slf4j;
- 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;
- import java.util.HashMap;
- import java.util.Map;
- @Service
- @Slf4j
- public class IFdkkLaserServiceImpl implements IFdkkLaserService {
- 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 IScenePlusService scenePlusService;
- private RestTemplate restTemplate = new RestTemplate();
- 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);
- }
- 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(String sceneNum, String dataSource) {
- log.info("激光转台相机构建结果 同步 请求 ");
- try {
- String jgPath = dataSource;
- //创建目录
- if (dataSource.lastIndexOf("/") != -1) {
- jgPath = jgPath + "_laserData";
- } else {
- jgPath = jgPath.substring(0, jgPath.length() - 1) + "_laserData";
- }
- FileUtils.createDir(jgPath + "/extras");
- log.info("生成 激光相机目录 " + jgPath);
- //生成data.json
- JSONObject jgDataJson = new JSONObject();
- jgDataJson.put("split_type", "SPLIT_V15");
- jgDataJson.put("skybox_type", "SKYBOX_V5");
- jgDataJson.put("extras", null);
- FileUtils.writeFile(jgPath + File.separator + "data.json", jgDataJson.toString());
- // result/mesh/mesh.obj --> jgPath/laserData/laser.obj
- log.info("开始拷贝obj文件");
- FileUtils.copyDirectiory(dataSource + "/results/mesh", jgPath + "/laserData/mesh");
- FileUtils.copyDirectiory(dataSource + "/results/laserData/cover", jgPath + "/extras");
- FileUtils.copyFile(dataSource + "/results/laserData", jgPath, true);
- updateSceneStatus(sceneNum, 2, jgPath + File.separator + "laserData");
- } catch (Exception e) {
- log.error("激光转台相机同步失败", e);
- }
- }
- @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()) {
- log.error("激光系统同步BuildStatus");
- }
- }
- public void saveScene(ScenePlus scenePlus, String scenePassword, Camera cameraEntity, String phone, boolean rebuild) {
- String url = laserHost + String.format(SAVE_SCENE_URL_TEMPLATE, scenePlus.getNum());
- Map<String, Object> params = new HashMap<>();
- params.put("childName", cameraEntity.getChildName());
- params.put("createTime", DateUtil.date2String(scenePlus.getCreateTime(), null));
- params.put("phone", phone);
- params.put("sceneCode", scenePlus.getNum());
- params.put("snCode", cameraEntity.getSnCode());
- params.put("status", scenePlus.getSceneStatus());
- if (!rebuild) {
- params.put("password", scenePassword);
- } else {
- params.put("status", 4);
- }
- params.put("title", scenePlus.getTitle());
- params.put("userId", scenePlus.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("激光场景状态同步失败!");
- }
- }
- public void saveScene(ScenePro scenePro, String scenePassword, Camera cameraEntity, String phone, boolean rebuild) {
- String url = laserHost + String.format(SAVE_SCENE_URL_TEMPLATE, scenePro.getNum());
- Map<String, Object> params = new HashMap<>();
- params.put("childName", cameraEntity.getChildName());
- params.put("createTime", DateUtil.date2String(scenePro.getCreateTime(), null));
- params.put("phone", phone);
- params.put("sceneCode", scenePro.getNum());
- params.put("snCode", cameraEntity.getSnCode());
- params.put("status", scenePro.getStatus());
- if (!rebuild) {
- params.put("password", scenePassword);
- } else {
- params.put("status", 4);
- }
- params.put("title", scenePro.getSceneName());
- params.put("userId", scenePro.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("激光场景状态同步失败!");
- }
- }
- }
|