SceneMarkShapeBoxServiceImpl.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.fdkankan.openApi.service.www.impl;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.dynamic.datasource.annotation.DS;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  7. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  8. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  9. import com.fdkankan.openApi.dto.SceneJsonDTO;
  10. import com.fdkankan.openApi.dto.SceneMarkShapeBoxPostDTO;
  11. import com.fdkankan.openApi.entity.www.SceneMarkShape;
  12. import com.fdkankan.openApi.entity.www.SceneMarkShapeBox;
  13. import com.fdkankan.openApi.httpclient.client.ShapesBoxClient;
  14. import com.fdkankan.openApi.mapper.www.MarkShapeBoxMapper;
  15. import com.fdkankan.openApi.service.www.ISceneMarkShapeBoxService;
  16. import com.fdkankan.openApi.service.www.ISceneMarkShapeService;
  17. import com.fdkankan.web.response.ResultData;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.beans.factory.annotation.Value;
  21. import org.springframework.stereotype.Service;
  22. import javax.annotation.Resource;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. import java.util.Objects;
  27. /**
  28. * Created by Xiewj on 2023-8-31 10:44:46
  29. */
  30. @Slf4j
  31. @Service
  32. @DS("www")
  33. public class SceneMarkShapeBoxServiceImpl extends ServiceImpl<MarkShapeBoxMapper, SceneMarkShapeBox> implements ISceneMarkShapeBoxService {
  34. @Autowired
  35. ISceneMarkShapeService sceneMarkShapeService;
  36. @Resource
  37. ShapesBoxClient shapesBoxClient;
  38. @Value("${4dkk.nodeService.basePath}")
  39. private String planeCovertBasePathUrl;
  40. @Value("${4dkk.nodeService.api.planeCovert}")
  41. private String planeCovert;
  42. // @Autowired
  43. // SceneShapeEnumService sceneShapeEnumService;
  44. @Override
  45. public SceneMarkShapeBox findBySceneNum(String sceneNum) {
  46. LambdaQueryWrapper<SceneMarkShapeBox> wrapper = Wrappers.lambdaQuery();
  47. wrapper.eq(SceneMarkShapeBox::getSceneNum,sceneNum);
  48. return getOne(wrapper);
  49. }
  50. @Override
  51. public SceneMarkShapeBox planeCovert(String sceneNum) {
  52. List<SceneMarkShape> sceneMarkShapes = sceneMarkShapeService.findByNum(sceneNum);
  53. SceneMarkShapeBoxPostDTO sceneMarkShapeBoxPostVO =new SceneMarkShapeBoxPostDTO(sceneNum,sceneMarkShapes);
  54. ResultData res = shapesBoxClient.post(planeCovertBasePathUrl + planeCovert, JSONObject.toJSONString(sceneMarkShapeBoxPostVO));
  55. log.info("请求node转换服务-{}",res);
  56. SceneMarkShapeBox data = null;
  57. if (res.getCode()==200){
  58. JSONObject resData = (JSONObject)res.getData();
  59. data = JSONObject.parseObject(resData.toJSONString(),SceneMarkShapeBox.class);
  60. SceneMarkShapeBox sceneMarkShapeBox = findBySceneNum(sceneNum);
  61. if (ObjectUtil.isNotNull(sceneMarkShapeBox)){
  62. log.info("存在shapesBox数据进行替换");
  63. sceneMarkShapeBox.setBoxes(data.getBoxes());
  64. sceneMarkShapeBox.setBoundingBox(data.getBoundingBox());
  65. updateById(sceneMarkShapeBox);
  66. return sceneMarkShapeBox;
  67. }else {
  68. log.info("不存在shapesBox数据进行保存");
  69. save(data);
  70. return data;
  71. }
  72. }
  73. return data;
  74. }
  75. @Override
  76. public void saveExternalBox(SceneJsonDTO param) {
  77. SceneMarkShapeBox sceneMarkShapeBox = this.findBySceneNum(param.getNum());
  78. sceneMarkShapeBox.setExternalBoxes(param.getData());
  79. this.saveOrUpdate(sceneMarkShapeBox);
  80. }
  81. @Override
  82. public Map<String, Object> getShapBox(String num) {
  83. SceneMarkShapeBox sceneMarkShapeBox = this.findBySceneNum(num);
  84. if(Objects.isNull(sceneMarkShapeBox)){
  85. return null;
  86. }
  87. Map<String, Object> result = new HashMap<>();
  88. result.put("boundingBox", sceneMarkShapeBox.getBoundingBox());
  89. if(Objects.nonNull(sceneMarkShapeBox.getExternalBoxes())){
  90. result.put("boxes", sceneMarkShapeBox.getExternalBoxes());
  91. }else {
  92. result.put("boxes", sceneMarkShapeBox.getBoxes());
  93. }
  94. return result;
  95. }
  96. // @Override
  97. // public String covertToShapeBox(String sceneNum) {
  98. // SceneMarkShapeBox sceneMarkShapeBox = planeCovert(sceneNum);
  99. // if (ObjectUtil.isNotNull(sceneMarkShapeBox)){
  100. // JSONObject shapeBox=new JSONObject();
  101. // JSONArray decoration=new JSONArray();
  102. // List<JSONObject> boxes = sceneMarkShapeBox.getBoxes();
  103. // JSONObject boundingBox = sceneMarkShapeBox.getBoundingBox();
  104. // JSONArray max = boundingBox.getJSONArray("max");
  105. // JSONArray min = boundingBox.getJSONArray("min");
  106. // ShapeBoxVO shapeBoxVO=new ShapeBoxVO();
  107. // Point3D maxp=new Point3D(max.getDouble(0),max.getDouble(1),max.getDouble(2));
  108. // Point3D minp=new Point3D(min.getDouble(0),min.getDouble(1),min.getDouble(2));
  109. // shapeBoxVO.setBoundingBox( new ShapeBoxVO.BoundingBox(maxp,minp));
  110. // for (JSONObject box : boxes) {
  111. // List<CubeUtil.Point> points=new ArrayList<>();
  112. // JSONArray pointsJson = box.getJSONArray("points");
  113. // for (Object o : pointsJson) {
  114. // JSONArray point = JSONArray.parseArray(JSONObject.toJSON(o).toString());
  115. // points.add(new CubeUtil.Point(point.getDouble(0), point.getDouble(1), point.getDouble(2)));
  116. // }
  117. // CubeUtil cubeUtil = new CubeUtil(points);
  118. // String category=box.getString("category");
  119. // JSONArray quaternion=box.getJSONArray("quaternion");
  120. // SceneShapeEnum sceneShapeEnum = sceneShapeEnumService.findByClassName(category);
  121. // if (ObjectUtil.isNotNull(sceneShapeEnum)){
  122. // cubeUtil.setResource_id(sceneShapeEnum.getResourceId());
  123. // cubeUtil.setType_id(sceneShapeEnum.getTypeId());
  124. // }
  125. // if (CollectionUtil.isNotEmpty(quaternion)){
  126. // cubeUtil.setQuaternion(quaternion);
  127. // }
  128. // decoration.add(cubeUtil);
  129. // }
  130. // if (decoration.size() >0){
  131. // shapeBoxVO.setDecoration(decoration);
  132. // }
  133. // String srcPath = String.format(ConstantFilePath.SCENE_VIEW_DATA_USER,sceneNum) + "shapeBox.json" ;
  134. // return fileStorageTemplate.uploadFileBytes(srcPath, JSONObject.toJSONString(shapeBoxVO).getBytes());
  135. // }
  136. // return "";
  137. // }
  138. }