SceneMarkShapeBoxServiceImpl.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. if (res.getCode()==200){
  57. JSONObject resData = (JSONObject)res.getData();
  58. SceneMarkShapeBox data= JSONObject.parseObject(resData.toJSONString(),SceneMarkShapeBox.class);
  59. SceneMarkShapeBox sceneMarkShapeBox = findBySceneNum(sceneNum);
  60. if (ObjectUtil.isNotNull(sceneMarkShapeBox)){
  61. log.info("存在shapesBox数据进行替换");
  62. sceneMarkShapeBox.setBoxes(data.getBoxes());
  63. sceneMarkShapeBox.setBoundingBox(data.getBoundingBox());
  64. updateById(sceneMarkShapeBox);
  65. return sceneMarkShapeBox;
  66. }else {
  67. log.info("不存在shapesBox数据进行保存");
  68. save(data);
  69. return data;
  70. }
  71. }
  72. return null;
  73. }
  74. @Override
  75. public void saveExternalBox(SceneJsonDTO param) {
  76. SceneMarkShapeBox sceneMarkShapeBox = this.findBySceneNum(param.getNum());
  77. sceneMarkShapeBox.setExternalBoxes(param.getData());
  78. this.saveOrUpdate(sceneMarkShapeBox);
  79. }
  80. @Override
  81. public Map<String, Object> getShapBox(String num) {
  82. SceneMarkShapeBox sceneMarkShapeBox = this.findBySceneNum(num);
  83. if(Objects.isNull(sceneMarkShapeBox)){
  84. return null;
  85. }
  86. Map<String, Object> result = new HashMap<>();
  87. result.put("boundingBox", sceneMarkShapeBox.getBoundingBox());
  88. if(Objects.nonNull(sceneMarkShapeBox.getExternalBoxes())){
  89. result.put("boxes", sceneMarkShapeBox.getExternalBoxes());
  90. }else {
  91. result.put("boxes", sceneMarkShapeBox.getBoxes());
  92. }
  93. return result;
  94. }
  95. // @Override
  96. // public String covertToShapeBox(String sceneNum) {
  97. // SceneMarkShapeBox sceneMarkShapeBox = planeCovert(sceneNum);
  98. // if (ObjectUtil.isNotNull(sceneMarkShapeBox)){
  99. // JSONObject shapeBox=new JSONObject();
  100. // JSONArray decoration=new JSONArray();
  101. // List<JSONObject> boxes = sceneMarkShapeBox.getBoxes();
  102. // JSONObject boundingBox = sceneMarkShapeBox.getBoundingBox();
  103. // JSONArray max = boundingBox.getJSONArray("max");
  104. // JSONArray min = boundingBox.getJSONArray("min");
  105. // ShapeBoxVO shapeBoxVO=new ShapeBoxVO();
  106. // Point3D maxp=new Point3D(max.getDouble(0),max.getDouble(1),max.getDouble(2));
  107. // Point3D minp=new Point3D(min.getDouble(0),min.getDouble(1),min.getDouble(2));
  108. // shapeBoxVO.setBoundingBox( new ShapeBoxVO.BoundingBox(maxp,minp));
  109. // for (JSONObject box : boxes) {
  110. // List<CubeUtil.Point> points=new ArrayList<>();
  111. // JSONArray pointsJson = box.getJSONArray("points");
  112. // for (Object o : pointsJson) {
  113. // JSONArray point = JSONArray.parseArray(JSONObject.toJSON(o).toString());
  114. // points.add(new CubeUtil.Point(point.getDouble(0), point.getDouble(1), point.getDouble(2)));
  115. // }
  116. // CubeUtil cubeUtil = new CubeUtil(points);
  117. // String category=box.getString("category");
  118. // JSONArray quaternion=box.getJSONArray("quaternion");
  119. // SceneShapeEnum sceneShapeEnum = sceneShapeEnumService.findByClassName(category);
  120. // if (ObjectUtil.isNotNull(sceneShapeEnum)){
  121. // cubeUtil.setResource_id(sceneShapeEnum.getResourceId());
  122. // cubeUtil.setType_id(sceneShapeEnum.getTypeId());
  123. // }
  124. // if (CollectionUtil.isNotEmpty(quaternion)){
  125. // cubeUtil.setQuaternion(quaternion);
  126. // }
  127. // decoration.add(cubeUtil);
  128. // }
  129. // if (decoration.size() >0){
  130. // shapeBoxVO.setDecoration(decoration);
  131. // }
  132. // String srcPath = String.format(ConstantFilePath.SCENE_VIEW_DATA_USER,sceneNum) + "shapeBox.json" ;
  133. // return fileStorageTemplate.uploadFileBytes(srcPath, JSONObject.toJSONString(shapeBoxVO).getBytes());
  134. // }
  135. // return "";
  136. // }
  137. }