IFdkkLaserServiceImpl.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package com.fdkankan.contro.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.fdkankan.common.util.DateUtil;
  4. import com.fdkankan.common.util.FileUtils;
  5. import com.fdkankan.contro.entity.Camera;
  6. import com.fdkankan.contro.entity.ScenePlus;
  7. import com.fdkankan.contro.entity.ScenePlusExt;
  8. import com.fdkankan.contro.entity.ScenePro;
  9. import com.fdkankan.contro.service.IFdkkLaserService;
  10. import com.fdkankan.contro.service.IScenePlusService;
  11. import com.fdkankan.web.response.Result;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.http.HttpStatus;
  16. import org.springframework.http.ResponseEntity;
  17. import org.springframework.stereotype.Service;
  18. import org.springframework.util.ObjectUtils;
  19. import org.springframework.web.client.RestTemplate;
  20. import java.io.File;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. @Service
  24. @Slf4j
  25. public class IFdkkLaserServiceImpl implements IFdkkLaserService {
  26. private final String SAVE_SCENE_URL_TEMPLATE = "/laser/init/%s/saveOrEdit";
  27. private final String EDIT_LASER_BUILD_STATUS_URL = "/laser/4dage/scene/editBuildStatus";
  28. private final String ENABLE_COOPERATION_CAMERA_URL = "/laser/4dage/scene/cooperation/cameraSave";
  29. @Value("${4dkk.laserService.host}")
  30. private String laserHost;
  31. @Autowired
  32. private IScenePlusService scenePlusService;
  33. private RestTemplate restTemplate = new RestTemplate();
  34. public void updateSceneStatus(String sceneCode, int sceneStatus, String path) {
  35. String url = laserHost + String.format(SAVE_SCENE_URL_TEMPLATE, sceneCode);
  36. Map<String, Object> params = new HashMap<>();
  37. params.put("sceneCode", sceneCode);
  38. params.put("status", sceneStatus);
  39. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
  40. params.put("createTime", DateUtil.date2String(scenePlus.getCreateTime(), null));
  41. if (!ObjectUtils.isEmpty(path)) {
  42. params.put("path", path);
  43. }
  44. log.info("自研激光转台相机同步,url:{},params:{}", url, JSONObject.toJSONString(params));
  45. ResponseEntity<Result> responseEntity = restTemplate.postForEntity(url, params, Result.class);
  46. log.info("自研激光转台相机同步,url:{},params:{},结果:{}", url, JSONObject.toJSONString(params), JSONObject.toJSONString(responseEntity.getBody()));
  47. if (responseEntity.getStatusCode() != HttpStatus.OK || responseEntity.getBody().getCode() != HttpStatus.OK.value()) {
  48. log.error("激光场景状态同步失败!");
  49. }
  50. }
  51. public void syncBuildResult(String sceneNum, String dataSource) {
  52. log.info("激光转台相机构建结果 同步 请求 ");
  53. try {
  54. String jgPath = dataSource;
  55. //创建目录
  56. if (dataSource.lastIndexOf("/") != -1) {
  57. jgPath = jgPath + "_laserData";
  58. } else {
  59. jgPath = jgPath.substring(0, jgPath.length() - 1) + "_laserData";
  60. }
  61. FileUtils.createDir(jgPath + "/extras");
  62. log.info("生成 激光相机目录 " + jgPath);
  63. //生成data.json
  64. JSONObject jgDataJson = new JSONObject();
  65. jgDataJson.put("split_type", "SPLIT_V15");
  66. jgDataJson.put("skybox_type", "SKYBOX_V5");
  67. jgDataJson.put("extras", null);
  68. FileUtils.writeFile(jgPath + File.separator + "data.json", jgDataJson.toString());
  69. // result/mesh/mesh.obj --> jgPath/laserData/laser.obj
  70. log.info("开始拷贝obj文件");
  71. FileUtils.copyDirectiory(dataSource + "/results/mesh", jgPath + "/laserData/mesh");
  72. FileUtils.copyDirectiory(dataSource + "/results/laserData/cover", jgPath + "/extras");
  73. FileUtils.copyFile(dataSource + "/results/laserData", jgPath, true);
  74. updateSceneStatus(sceneNum, 2, jgPath + File.separator + "laserData");
  75. } catch (Exception e) {
  76. log.error("激光转台相机同步失败", e);
  77. }
  78. }
  79. @Override
  80. public void pushBuildStatusToLaserSystem(String projectNum, String laserObjFilePath) {
  81. String url = laserHost + EDIT_LASER_BUILD_STATUS_URL;
  82. Map<String, String> params = new HashMap<>();
  83. params.put("sceneCode", projectNum);
  84. params.put("objPath", laserObjFilePath);
  85. log.info("激光系统同步BuildStatus,url:{},params:{}", ENABLE_COOPERATION_CAMERA_URL, JSONObject.toJSONString(params));
  86. ResponseEntity<com.fdkankan.contro.common.Result> responseEntity = restTemplate.postForEntity(url, params, com.fdkankan.contro.common.Result.class);
  87. log.info("激光系统同步BuildStatus,url:{},params:{},结果:{}", url, JSONObject.toJSONString(params), JSONObject.toJSONString(responseEntity.getBody()));
  88. if (responseEntity.getStatusCode() != HttpStatus.OK || responseEntity.getBody().getCode() != HttpStatus.OK.value()) {
  89. log.error("激光系统同步BuildStatus");
  90. }
  91. }
  92. public void saveScene(ScenePlus scenePlus, String scenePassword, Camera cameraEntity, String phone, boolean rebuild) {
  93. String url = laserHost + String.format(SAVE_SCENE_URL_TEMPLATE, scenePlus.getNum());
  94. Map<String, Object> params = new HashMap<>();
  95. params.put("childName", cameraEntity.getChildName());
  96. params.put("createTime", DateUtil.date2String(scenePlus.getCreateTime(), null));
  97. params.put("phone", phone);
  98. params.put("sceneCode", scenePlus.getNum());
  99. params.put("snCode", cameraEntity.getSnCode());
  100. params.put("status", scenePlus.getSceneStatus());
  101. if (!rebuild) {
  102. params.put("password", scenePassword);
  103. } else {
  104. params.put("status", 4);
  105. }
  106. params.put("title", scenePlus.getTitle());
  107. params.put("userId", scenePlus.getUserId());
  108. log.info("自研激光转台相机同步,url:{},params:{}", url, JSONObject.toJSONString(params));
  109. ResponseEntity<Result> responseEntity = restTemplate.postForEntity(url, params, Result.class);
  110. log.info("自研激光转台相机同步,url:{},params:{},结果,{}", url, JSONObject.toJSONString(params), JSONObject.toJSONString(responseEntity.getBody()));
  111. if (responseEntity.getStatusCode() != HttpStatus.OK || responseEntity.getBody().getCode() != HttpStatus.OK.value()) {
  112. log.error("激光场景状态同步失败!");
  113. }
  114. }
  115. public void saveScene(ScenePro scenePro, String scenePassword, Camera cameraEntity, String phone, boolean rebuild) {
  116. String url = laserHost + String.format(SAVE_SCENE_URL_TEMPLATE, scenePro.getNum());
  117. Map<String, Object> params = new HashMap<>();
  118. params.put("childName", cameraEntity.getChildName());
  119. params.put("createTime", DateUtil.date2String(scenePro.getCreateTime(), null));
  120. params.put("phone", phone);
  121. params.put("sceneCode", scenePro.getNum());
  122. params.put("snCode", cameraEntity.getSnCode());
  123. params.put("status", scenePro.getStatus());
  124. if (!rebuild) {
  125. params.put("password", scenePassword);
  126. } else {
  127. params.put("status", 4);
  128. }
  129. params.put("title", scenePro.getSceneName());
  130. params.put("userId", scenePro.getUserId());
  131. log.info("自研激光转台相机同步,url:{},params:{}", url, JSONObject.toJSONString(params));
  132. ResponseEntity<Result> responseEntity = restTemplate.postForEntity(url, params, Result.class);
  133. log.info("自研激光转台相机同步,url:{},params:{},结果,{}", url, JSONObject.toJSONString(params), JSONObject.toJSONString(responseEntity.getBody()));
  134. if (responseEntity.getStatusCode() != HttpStatus.OK || responseEntity.getBody().getCode() != HttpStatus.OK.value()) {
  135. log.error("激光场景状态同步失败!");
  136. }
  137. }
  138. }