IFdkkLaserServiceImpl.java 8.5 KB

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