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.ScenePro; import com.fdkankan.contro.service.IFdkkLaserService; import com.fdkankan.contro.service.IScenePlusService; import com.fdkankan.contro.service.ISceneProService; 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.Date; 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; private RestTemplate restTemplate = new RestTemplate(); @Autowired private ISceneProService sceneProService; @Autowired private IScenePlusService scenePlusService; public void updateSceneStatus(String sceneCode, int sceneStatus, String path, Date createTime) { String url = laserHost + String.format(SAVE_SCENE_URL_TEMPLATE, sceneCode); Map params = new HashMap<>(); params.put("sceneCode", sceneCode); params.put("status", sceneStatus); params.put("version",getSceneVersion(sceneCode)); params.put("createTime", DateUtil.date2String(createTime, null)); if (!ObjectUtils.isEmpty(path)) { params.put("path", path); } log.info("自研激光转台相机同步,url:{},params:{}", url, JSONObject.toJSONString(params)); ResponseEntity 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,Date createTime) { 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",createTime); } catch (Exception e) { log.error("激光转台相机同步失败", e); } } @Override public void pushBuildStatusToLaserSystem(String projectNum, String laserObjFilePath) { String url = laserHost + EDIT_LASER_BUILD_STATUS_URL; Map params = new HashMap<>(); params.put("sceneCode", projectNum); params.put("objPath", laserObjFilePath); log.info("激光系统同步BuildStatus,url:{},params:{}", ENABLE_COOPERATION_CAMERA_URL, JSONObject.toJSONString(params)); ResponseEntity 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 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("version",getSceneVersion(scenePlus.getNum())); params.put("title", scenePlus.getTitle()); params.put("userId", scenePlus.getUserId()); log.info("自研激光转台相机同步,url:{},params:{}", url, JSONObject.toJSONString(params)); ResponseEntity 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 params = new HashMap<>(); params.put("childName", cameraEntity.getChildName()); if(ObjectUtils.isEmpty(scenePro.getCreateTime())){ scenePro.setCreateTime(new Date()); } 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("version",getSceneVersion(scenePro.getNum())); params.put("title", scenePro.getSceneName()); params.put("userId", scenePro.getUserId()); log.info("自研激光转台相机同步,url:{},params:{}", url, JSONObject.toJSONString(params)); ResponseEntity 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("激光场景状态同步失败!"); } } private String getSceneVersion(String num) { String version = "V3"; ScenePro scenepro = sceneProService.getByNum(num); if (scenepro == null || scenepro.getIsUpgrade() == 1) { ScenePlus plus = scenePlusService.getScenePlusByNum(num); if (plus != null) { version = "V4"; } } return version; } }