SceneMarkShapeBoxServiceImpl.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.*;
  24. import java.util.stream.Collectors;
  25. /**
  26. * Created by Xiewj on 2023-8-31 10:44:46
  27. */
  28. @Slf4j
  29. @Service
  30. @DS("www")
  31. public class SceneMarkShapeBoxServiceImpl extends ServiceImpl<MarkShapeBoxMapper, SceneMarkShapeBox> implements ISceneMarkShapeBoxService {
  32. @Autowired
  33. ISceneMarkShapeService sceneMarkShapeService;
  34. @Resource
  35. ShapesBoxClient shapesBoxClient;
  36. @Value("${4dkk.nodeService.basePath}")
  37. private String planeCovertBasePathUrl;
  38. @Value("${4dkk.nodeService.api.planeCovert}")
  39. private String planeCovert;
  40. // @Autowired
  41. // SceneShapeEnumService sceneShapeEnumService;
  42. @Override
  43. public SceneMarkShapeBox findBySceneNum(String sceneNum) {
  44. LambdaQueryWrapper<SceneMarkShapeBox> wrapper = Wrappers.lambdaQuery();
  45. wrapper.eq(SceneMarkShapeBox::getSceneNum,sceneNum);
  46. return getOne(wrapper);
  47. }
  48. @Override
  49. public SceneMarkShapeBox planeCovert(String sceneNum) {
  50. List<SceneMarkShape> sceneMarkShapes = sceneMarkShapeService.findByNum(sceneNum);
  51. SceneMarkShapeBoxPostDTO sceneMarkShapeBoxPostVO =new SceneMarkShapeBoxPostDTO(sceneNum,sceneMarkShapes);
  52. ResultData res = shapesBoxClient.post(planeCovertBasePathUrl + planeCovert, JSONObject.toJSONString(sceneMarkShapeBoxPostVO));
  53. log.info("请求node转换服务-{}",res);
  54. SceneMarkShapeBox data = null;
  55. if (res.getCode()==200){
  56. JSONObject resData = (JSONObject)res.getData();
  57. data = JSONObject.parseObject(resData.toJSONString(),SceneMarkShapeBox.class);
  58. SceneMarkShapeBox sceneMarkShapeBox = findBySceneNum(sceneNum);
  59. if (ObjectUtil.isNotNull(sceneMarkShapeBox)){
  60. log.info("存在shapesBox数据进行替换");
  61. sceneMarkShapeBox.setBoxes(data.getBoxes());
  62. sceneMarkShapeBox.setBoundingBox(data.getBoundingBox());
  63. updateById(sceneMarkShapeBox);
  64. return sceneMarkShapeBox;
  65. }else {
  66. log.info("不存在shapesBox数据进行保存");
  67. save(data);
  68. return data;
  69. }
  70. }
  71. return data;
  72. }
  73. @Override
  74. public void saveExternalBox(SceneJsonDTO param) {
  75. SceneMarkShapeBox sceneMarkShapeBox = this.findBySceneNum(param.getNum());
  76. sceneMarkShapeBox.setExternalBoxes(param.getData());
  77. sceneMarkShapeBox.setUpdateTime(new Date());
  78. this.saveOrUpdate(sceneMarkShapeBox);
  79. }
  80. @Override
  81. public Map<String, Object> getShapBox(String num, Integer showOrig) {
  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(showOrig) && showOrig == 1){
  89. List<SceneMarkShape> shapes = sceneMarkShapeService.findByNum(num);
  90. List<Map<String, Object>> shapeList = shapes.stream().map(v -> {
  91. Map<String, Object> map = new HashMap<>();
  92. map.put("imagePath", v.getImagePath());
  93. map.put("shapes", v.getShapes());
  94. return map;
  95. }).collect(Collectors.toList());
  96. result.put("result", shapeList);
  97. }else{
  98. if(Objects.nonNull(sceneMarkShapeBox.getExternalBoxes())){
  99. result.put("result", sceneMarkShapeBox.getExternalBoxes());
  100. }else {
  101. result.put("result", sceneMarkShapeBox.getBoxes());
  102. }
  103. }
  104. return result;
  105. }
  106. // @Override
  107. // public String covertToShapeBox(String sceneNum) {
  108. // SceneMarkShapeBox sceneMarkShapeBox = planeCovert(sceneNum);
  109. // if (ObjectUtil.isNotNull(sceneMarkShapeBox)){
  110. // JSONObject shapeBox=new JSONObject();
  111. // JSONArray decoration=new JSONArray();
  112. // List<JSONObject> boxes = sceneMarkShapeBox.getBoxes();
  113. // JSONObject boundingBox = sceneMarkShapeBox.getBoundingBox();
  114. // JSONArray max = boundingBox.getJSONArray("max");
  115. // JSONArray min = boundingBox.getJSONArray("min");
  116. // ShapeBoxVO shapeBoxVO=new ShapeBoxVO();
  117. // Point3D maxp=new Point3D(max.getDouble(0),max.getDouble(1),max.getDouble(2));
  118. // Point3D minp=new Point3D(min.getDouble(0),min.getDouble(1),min.getDouble(2));
  119. // shapeBoxVO.setBoundingBox( new ShapeBoxVO.BoundingBox(maxp,minp));
  120. // for (JSONObject box : boxes) {
  121. // List<CubeUtil.Point> points=new ArrayList<>();
  122. // JSONArray pointsJson = box.getJSONArray("points");
  123. // for (Object o : pointsJson) {
  124. // JSONArray point = JSONArray.parseArray(JSONObject.toJSON(o).toString());
  125. // points.add(new CubeUtil.Point(point.getDouble(0), point.getDouble(1), point.getDouble(2)));
  126. // }
  127. // CubeUtil cubeUtil = new CubeUtil(points);
  128. // String category=box.getString("category");
  129. // JSONArray quaternion=box.getJSONArray("quaternion");
  130. // SceneShapeEnum sceneShapeEnum = sceneShapeEnumService.findByClassName(category);
  131. // if (ObjectUtil.isNotNull(sceneShapeEnum)){
  132. // cubeUtil.setResource_id(sceneShapeEnum.getResourceId());
  133. // cubeUtil.setType_id(sceneShapeEnum.getTypeId());
  134. // }
  135. // if (CollectionUtil.isNotEmpty(quaternion)){
  136. // cubeUtil.setQuaternion(quaternion);
  137. // }
  138. // decoration.add(cubeUtil);
  139. // }
  140. // if (decoration.size() >0){
  141. // shapeBoxVO.setDecoration(decoration);
  142. // }
  143. // String srcPath = String.format(ConstantFilePath.SCENE_VIEW_DATA_USER,sceneNum) + "shapeBox.json" ;
  144. // return fileStorageTemplate.uploadFileBytes(srcPath, JSONObject.toJSONString(shapeBoxVO).getBytes());
  145. // }
  146. // return "";
  147. // }
  148. }