123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- package com.fdkankan.openApi.service.www.impl;
- import cn.hutool.core.util.ObjectUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.dynamic.datasource.annotation.DS;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.openApi.dto.SceneJsonDTO;
- import com.fdkankan.openApi.dto.SceneMarkShapeBoxPostDTO;
- import com.fdkankan.openApi.entity.www.SceneMarkShape;
- import com.fdkankan.openApi.entity.www.SceneMarkShapeBox;
- import com.fdkankan.openApi.httpclient.client.ShapesBoxClient;
- import com.fdkankan.openApi.mapper.www.MarkShapeBoxMapper;
- import com.fdkankan.openApi.service.www.ISceneMarkShapeBoxService;
- import com.fdkankan.openApi.service.www.ISceneMarkShapeService;
- import com.fdkankan.web.response.ResultData;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * Created by Xiewj on 2023-8-31 10:44:46
- */
- @Slf4j
- @Service
- @DS("www")
- public class SceneMarkShapeBoxServiceImpl extends ServiceImpl<MarkShapeBoxMapper, SceneMarkShapeBox> implements ISceneMarkShapeBoxService {
- @Autowired
- ISceneMarkShapeService sceneMarkShapeService;
- @Resource
- ShapesBoxClient shapesBoxClient;
- @Value("${4dkk.nodeService.basePath}")
- private String planeCovertBasePathUrl;
- @Value("${4dkk.nodeService.api.planeCovert}")
- private String planeCovert;
- // @Autowired
- // SceneShapeEnumService sceneShapeEnumService;
- @Override
- public SceneMarkShapeBox findBySceneNum(String sceneNum) {
- LambdaQueryWrapper<SceneMarkShapeBox> wrapper = Wrappers.lambdaQuery();
- wrapper.eq(SceneMarkShapeBox::getSceneNum,sceneNum);
- return getOne(wrapper);
- }
- @Override
- public SceneMarkShapeBox planeCovert(String sceneNum) {
- List<SceneMarkShape> sceneMarkShapes = sceneMarkShapeService.findByNum(sceneNum);
- SceneMarkShapeBoxPostDTO sceneMarkShapeBoxPostVO =new SceneMarkShapeBoxPostDTO(sceneNum,sceneMarkShapes);
- ResultData res = shapesBoxClient.post(planeCovertBasePathUrl + planeCovert, JSONObject.toJSONString(sceneMarkShapeBoxPostVO));
- log.info("请求node转换服务-{}",res);
- SceneMarkShapeBox data = null;
- if (res.getCode()==200){
- JSONObject resData = (JSONObject)res.getData();
- data = JSONObject.parseObject(resData.toJSONString(),SceneMarkShapeBox.class);
- SceneMarkShapeBox sceneMarkShapeBox = findBySceneNum(sceneNum);
- if (ObjectUtil.isNotNull(sceneMarkShapeBox)){
- log.info("存在shapesBox数据进行替换");
- sceneMarkShapeBox.setBoxes(data.getBoxes());
- sceneMarkShapeBox.setBoundingBox(data.getBoundingBox());
- updateById(sceneMarkShapeBox);
- return sceneMarkShapeBox;
- }else {
- log.info("不存在shapesBox数据进行保存");
- save(data);
- return data;
- }
- }
- return data;
- }
- @Override
- public void saveExternalBox(SceneJsonDTO param) {
- SceneMarkShapeBox sceneMarkShapeBox = this.findBySceneNum(param.getNum());
- sceneMarkShapeBox.setExternalBoxes(param.getData());
- sceneMarkShapeBox.setUpdateTime(new Date());
- this.saveOrUpdate(sceneMarkShapeBox);
- }
- @Override
- public Map<String, Object> getShapBox(String num, Integer showOrig) {
- SceneMarkShapeBox sceneMarkShapeBox = this.findBySceneNum(num);
- if(Objects.isNull(sceneMarkShapeBox)){
- return null;
- }
- Map<String, Object> result = new HashMap<>();
- result.put("boundingBox", sceneMarkShapeBox.getBoundingBox());
- if(Objects.nonNull(showOrig) && showOrig == 1){
- List<SceneMarkShape> shapes = sceneMarkShapeService.findByNum(num);
- List<Map<String, Object>> shapeList = shapes.stream().map(v -> {
- Map<String, Object> map = new HashMap<>();
- map.put("imagePath", v.getImagePath());
- map.put("shapes", v.getShapes());
- return map;
- }).collect(Collectors.toList());
- result.put("result", shapeList);
- }else{
- if(Objects.nonNull(sceneMarkShapeBox.getExternalBoxes())){
- result.put("result", sceneMarkShapeBox.getExternalBoxes());
- }else {
- result.put("result", sceneMarkShapeBox.getBoxes());
- }
- }
- return result;
- }
- // @Override
- // public String covertToShapeBox(String sceneNum) {
- // SceneMarkShapeBox sceneMarkShapeBox = planeCovert(sceneNum);
- // if (ObjectUtil.isNotNull(sceneMarkShapeBox)){
- // JSONObject shapeBox=new JSONObject();
- // JSONArray decoration=new JSONArray();
- // List<JSONObject> boxes = sceneMarkShapeBox.getBoxes();
- // JSONObject boundingBox = sceneMarkShapeBox.getBoundingBox();
- // JSONArray max = boundingBox.getJSONArray("max");
- // JSONArray min = boundingBox.getJSONArray("min");
- // ShapeBoxVO shapeBoxVO=new ShapeBoxVO();
- // Point3D maxp=new Point3D(max.getDouble(0),max.getDouble(1),max.getDouble(2));
- // Point3D minp=new Point3D(min.getDouble(0),min.getDouble(1),min.getDouble(2));
- // shapeBoxVO.setBoundingBox( new ShapeBoxVO.BoundingBox(maxp,minp));
- // for (JSONObject box : boxes) {
- // List<CubeUtil.Point> points=new ArrayList<>();
- // JSONArray pointsJson = box.getJSONArray("points");
- // for (Object o : pointsJson) {
- // JSONArray point = JSONArray.parseArray(JSONObject.toJSON(o).toString());
- // points.add(new CubeUtil.Point(point.getDouble(0), point.getDouble(1), point.getDouble(2)));
- // }
- // CubeUtil cubeUtil = new CubeUtil(points);
- // String category=box.getString("category");
- // JSONArray quaternion=box.getJSONArray("quaternion");
- // SceneShapeEnum sceneShapeEnum = sceneShapeEnumService.findByClassName(category);
- // if (ObjectUtil.isNotNull(sceneShapeEnum)){
- // cubeUtil.setResource_id(sceneShapeEnum.getResourceId());
- // cubeUtil.setType_id(sceneShapeEnum.getTypeId());
- // }
- // if (CollectionUtil.isNotEmpty(quaternion)){
- // cubeUtil.setQuaternion(quaternion);
- // }
- // decoration.add(cubeUtil);
- // }
- // if (decoration.size() >0){
- // shapeBoxVO.setDecoration(decoration);
- // }
- // String srcPath = String.format(ConstantFilePath.SCENE_VIEW_DATA_USER,sceneNum) + "shapeBox.json" ;
- // return fileStorageTemplate.uploadFileBytes(srcPath, JSONObject.toJSONString(shapeBoxVO).getBytes());
- // }
- // return "";
- // }
- }
|