AdmModelRelServiceImpl.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. package com.persagy.proxy.adm.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.fasterxml.jackson.databind.JsonNode;
  6. import com.fasterxml.jackson.databind.node.ArrayNode;
  7. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  8. import com.fasterxml.jackson.databind.node.ObjectNode;
  9. import com.persagy.dmp.basic.model.QueryCriteria;
  10. import com.persagy.dmp.digital.entity.ObjectRelationProjectCal;
  11. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  12. import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
  13. import com.persagy.proxy.adm.model.*;
  14. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  15. import com.persagy.proxy.adm.request.AdmResponse;
  16. import com.persagy.proxy.adm.service.*;
  17. import com.persagy.proxy.adm.utils.GeoToolsUtil;
  18. import com.persagy.proxy.common.entity.InstanceUrlParam;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.apache.commons.lang.StringUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23. import javax.management.Query;
  24. import java.util.*;
  25. /**
  26. * @ClassName AdmModelRelServiceImpl
  27. * @Description: 模型修改设备元空间的建筑楼层信息
  28. * @Author linhuili
  29. * @Date 2021/8/31 14:31
  30. * @Version V1.0
  31. **/
  32. @Service
  33. @Slf4j
  34. public class AdmModelRelServiceImpl extends AbstractAdmBaseServiceImpl<AdmModelRel> implements IAdmModelRelService {
  35. @Autowired
  36. private IAdmFloorService floorService;
  37. @Autowired
  38. private IAdmEquipmentService equipmentService;
  39. @Autowired
  40. private IAdmISpaceService iSpaceService;
  41. @Autowired
  42. private IAdmObjectRelationCalService iAdmObjectRelationCalService;
  43. /**
  44. * 模型修改设备元空间的建筑楼层信息
  45. * @param context
  46. * @param clazz
  47. * @param vo
  48. * @return
  49. */
  50. @Override
  51. public List<AdmModelRel> doUpdateModelInfo(InstanceUrlParam context, Class<AdmModelRel> clazz, AdmModelRel vo) throws Exception{
  52. //1.查询模型文件是否有楼层在使用
  53. AdmModelRel floorCriteria = new AdmModelRel();
  54. floorCriteria.setModelId(vo.getModelId());
  55. List<AdmFloor> floorList = queryFloorEntity(context,floorCriteria);
  56. if(CollUtil.isNotEmpty(floorList)){
  57. Set<String> floorQueryTypes = getFloorQueryTypes(floorList);
  58. List<ObjectRelationProjectCal> relationProjectCals = iAdmObjectRelationCalService.queryCalRelByRelationType(context, floorQueryTypes);
  59. if(CollUtil.isNotEmpty(relationProjectCals)){
  60. //更新边类型计算状态:computationalState为2
  61. relationProjectCals.forEach(item->{
  62. item.setComputationalState(2);
  63. });
  64. iAdmObjectRelationCalService.updateObjectCalRel(context,relationProjectCals);
  65. }
  66. }
  67. //2.修改设备和元空间的建筑楼层信息
  68. String oldBimId = vo.getOldBimId();
  69. String bimId = vo.getBimId();
  70. if(StringUtils.isNotEmpty(oldBimId) && !oldBimId.equals(bimId)){
  71. //根据模型id重置设备元空间的建筑楼层信息
  72. resetEquipIspaceInfo(context,vo);
  73. }
  74. //查询楼层实体
  75. floorCriteria = new AdmModelRel();
  76. floorCriteria.setFloorId(vo.getFloorId());
  77. List<AdmFloor> admFloors = queryFloorEntity(context, floorCriteria);
  78. if(CollUtil.isEmpty(admFloors)){
  79. throw new Exception("楼层不存在");
  80. }
  81. AdmFloor floorEntity = admFloors.get(0);
  82. //2.1 模型修改设备的建筑楼层信息
  83. if(CollUtil.isEmpty(floorEntity.getOutline())){
  84. //如果楼层的轮廓线为空的话,直接修改
  85. updateEquipModelInfo(context, vo,floorEntity);
  86. }else{
  87. //判断该设备的坐标是否在层楼的轮廓中,若在,修改;不在,不修改
  88. List<AdmEquipment> admEquipments = queryModelEquip(context, vo);
  89. Boolean pointInPolygon = isPointInPolygon(admEquipments, floorEntity);
  90. if(pointInPolygon){
  91. updateEquipModelInfo(context, vo,floorEntity);
  92. }
  93. }
  94. //2.2 模型修改元空间的建筑楼层信息
  95. updateIspaceModelInfo(context, vo,floorEntity);
  96. //3. 修改楼层平面图地址
  97. if(StringUtils.isNotEmpty(vo.getFloorMap())){
  98. floorEntity.setFloorMap(vo.getFloorMap());
  99. }
  100. floorEntity.setModelId(vo.getModelId());
  101. floorEntity.setBimIdPre(vo.getBimId());
  102. //4.处理楼层自定义属性:楼层标高
  103. ObjectNode attributeMap = vo.getAttributeMap();
  104. if(attributeMap!=null){
  105. updateFloorElevation(vo.getAttributeMap().toString(),floorEntity);
  106. }
  107. //5.修改楼层信息
  108. ArrayList<AdmFloor> floors = new ArrayList<>();
  109. floors.add(floorEntity);
  110. List<AdmFloor> floorUpresult = floorService.doUpdate(context, AdmFloor.class, floors);
  111. if(CollUtil.isEmpty(floorUpresult)) {
  112. //6.发送消息,BDTP已发送,不再重复发送修改对象消息
  113. }
  114. return null;
  115. }
  116. /**
  117. * 模型修改设备的建筑楼层信息
  118. */
  119. private void updateEquipModelInfo(InstanceUrlParam context, AdmModelRel modelRel,AdmFloor floorEntity){
  120. //查询模型下的设备信息
  121. AdmQueryCriteria criteria = new AdmQueryCriteria();
  122. criteria.setFilters("bimId = '"+modelRel.getBimId()+"'");
  123. criteria.setFilters("floorId = '"+modelRel.getFloorId()+"'");
  124. AdmResponse admResponse = equipmentService.doQuery(context, criteria, AdmEquipment.class);
  125. List<AdmEquipment> content = (List<AdmEquipment>) admResponse.getContent();
  126. if(CollUtil.isEmpty(content)){
  127. return;
  128. }
  129. for (AdmEquipment admEquipment : content) {
  130. //修改设备的建筑楼层信息
  131. admEquipment.setBuildingId(floorEntity.getBuildingId());
  132. admEquipment.setFloorId(floorEntity.getId());
  133. }
  134. List<AdmEquipment> admEquipments = equipmentService.doUpdate(context, AdmEquipment.class, content);
  135. log.info("模型修改设备建筑楼层信息结果"+admEquipments);
  136. }
  137. /**
  138. * 模型修改元空间的建筑楼层信息
  139. */
  140. private void updateIspaceModelInfo(InstanceUrlParam context, AdmModelRel modelRel,AdmFloor floorEntity){
  141. //查询模型下的元空间信息
  142. AdmQueryCriteria criteria = new AdmQueryCriteria();
  143. criteria.setFilters("bimId = '"+modelRel.getBimId()+"'");
  144. criteria.setFilters("floorId = '"+modelRel.getFloorId()+"'");
  145. AdmResponse admResponse = iSpaceService.doQuery(context, criteria, AdmISpace.class);
  146. List<AdmISpace> content = (List<AdmISpace>) admResponse.getContent();
  147. if(CollUtil.isEmpty(content)){
  148. return;
  149. }
  150. for (AdmISpace admIspace : content) {
  151. //修改设备的建筑楼层信息
  152. admIspace.setBuildingId(floorEntity.getBuildingId());
  153. admIspace.setFloorId(floorEntity.getId());
  154. }
  155. List<AdmISpace> admEquipments = iSpaceService.doUpdate(context, AdmISpace.class, content);
  156. log.info("模型修改元空间的建筑楼层信息结果"+admEquipments);
  157. }
  158. /**
  159. * 判断点是否在面中
  160. * @return
  161. */
  162. private Boolean isPointInPolygon(List<AdmEquipment> equipments,AdmFloor floor){
  163. if(CollUtil.isEmpty(equipments)){
  164. return false;
  165. }
  166. Boolean flag = true;
  167. //楼层轮廓线
  168. List<ObjectNode> outline = floor.getOutline();
  169. for (AdmEquipment equipment : equipments) {
  170. //设备BIM坐标
  171. String bimLocation = equipment.getBimLocation();
  172. //判断点是否在面中:即设备位置是否在该楼层轮廓线中
  173. if(StringUtils.isEmpty(bimLocation)){
  174. continue;
  175. }
  176. String[] split = bimLocation.split(",");
  177. ObjectNode node = JsonNodeFactory.instance.objectNode();
  178. node.put("x",Double.valueOf(split[0]));
  179. node.put("y",Double.valueOf(split[1]));
  180. node.put("z",Double.valueOf(split[2]));
  181. flag = GeoToolsUtil.isPointInPoly(node,outline);
  182. if(!flag){
  183. return flag;
  184. }
  185. }
  186. return flag;
  187. }
  188. /**
  189. * 楼层属性修改
  190. * @param floorMapStr
  191. * @param floorEntity
  192. */
  193. private void updateFloorMap(String floorMapStr,AdmFloor floorEntity){
  194. if(StringUtils.isEmpty(floorMapStr)){
  195. return;
  196. }
  197. Map<String, Object> floorMap = JSONObject.toJavaObject(JSON.parseObject(floorMapStr), Map.class);
  198. Map<String, Object> infos = floorEntity.getInfos();
  199. for(Map.Entry<String,Object> map : floorMap.entrySet()){
  200. infos.put(map.getKey(),map.getValue());
  201. }
  202. floorEntity.setInfos(infos);
  203. }
  204. /**
  205. * 处理楼层标高
  206. * @param floorMapStr
  207. * @param floorEntity
  208. */
  209. private void updateFloorElevation(String floorMapStr,AdmFloor floorEntity){
  210. if(StringUtils.isEmpty(floorMapStr)){
  211. return;
  212. }
  213. Map<String, Object> floorMap = JSONObject.toJavaObject(JSON.parseObject(floorMapStr), Map.class);
  214. Map<String, Object> infos = floorEntity.getInfos();
  215. if(floorMap.containsKey(AdmCommonConstant.FLOOR_ELEVATION)){
  216. Object object = floorMap.get(AdmCommonConstant.FLOOR_ELEVATION);
  217. if(object != null){
  218. double floorElevation = Double.valueOf(object.toString()) / 1000;
  219. infos.put(AdmCommonConstant.FLOOR_ELEVATION,floorElevation);
  220. }
  221. }
  222. }
  223. /**
  224. * 根据模型id重置设备元空间的建筑楼层信息
  225. * @param context
  226. * @param vo
  227. */
  228. private void resetEquipIspaceInfo(InstanceUrlParam context, AdmModelRel vo){
  229. //重置历史设备的建筑楼层信息
  230. List<AdmEquipment> admEquipments = queryEquipmentByBimId(context, vo);
  231. if(CollUtil.isNotEmpty(admEquipments)){
  232. admEquipments.forEach(item->{
  233. item.setFloorId(null);
  234. item.setBuildingId(null);
  235. });
  236. }
  237. equipmentService.doUpdate(context,AdmEquipment.class,admEquipments);
  238. //重置历史元空间的建筑楼层信息
  239. List<AdmISpace> admISpaces = queryIspaceByBimId(context, vo);
  240. if(CollUtil.isNotEmpty(admISpaces)){
  241. admISpaces.forEach(item->{
  242. item.setFloorId(null);
  243. item.setBuildingId(null);
  244. });
  245. }
  246. iSpaceService.doUpdate(context,AdmISpace.class,admISpaces);
  247. }
  248. /**
  249. * 查询设备信息
  250. * @param context
  251. * @param modelRel
  252. */
  253. private List<AdmEquipment> queryModelEquip(InstanceUrlParam context, AdmModelRel modelRel){
  254. //查询模型下的设备信息
  255. AdmQueryCriteria criteria = new AdmQueryCriteria();
  256. criteria.setFilters("bimId = '"+modelRel.getBimId()+"' and floorId = '"+modelRel.getFloorId()+"'");
  257. // criteria.setFilters("floorId = '"+modelRel.getFloorId()+"'");
  258. AdmResponse admResponse = equipmentService.doQuery(context, criteria, AdmEquipment.class);
  259. if(CollUtil.isEmpty(admResponse.getContent())){
  260. return new ArrayList<>();
  261. }
  262. return (List<AdmEquipment>) admResponse.getContent();
  263. }
  264. /**
  265. * 根据BIMID查询历史设备信息
  266. */
  267. private List<AdmEquipment> queryEquipmentByBimId(InstanceUrlParam context, AdmModelRel vo){
  268. AdmQueryCriteria criteria = new AdmQueryCriteria();
  269. criteria.setFilters("bimId = '"+vo.getOldBimId()+"'");
  270. AdmResponse admResponse = equipmentService.doQuery(context, criteria, AdmEquipment.class);
  271. return (List<AdmEquipment>)admResponse.getContent();
  272. }
  273. /**
  274. * 根据BIMID查询历史元空间信息
  275. */
  276. private List<AdmISpace> queryIspaceByBimId(InstanceUrlParam context, AdmModelRel vo){
  277. AdmQueryCriteria criteria = new AdmQueryCriteria();
  278. criteria.setFilters("bimId = '"+vo.getOldBimId()+"'");
  279. AdmResponse admResponse = iSpaceService.doQuery(context, criteria, AdmISpace.class);
  280. return (List<AdmISpace>)admResponse.getContent();
  281. }
  282. /**
  283. * 查询模型文件是否有楼层在使用
  284. */
  285. private List<AdmFloor> queryFloorEntity(InstanceUrlParam context, AdmModelRel vo){
  286. AdmQueryCriteria criteria = new AdmQueryCriteria();
  287. if(StringUtils.isNotEmpty(vo.getModelId())){
  288. criteria.setFilters("modelId = '"+vo.getModelId()+"'");
  289. }
  290. if(StringUtils.isNotEmpty(vo.getFloorId())){
  291. criteria.setFilters("id = '"+vo.getFloorId()+"'");
  292. }
  293. criteria.setName("floor");
  294. AdmResponse admResponse = floorService.doQuery(context, criteria, AdmFloor.class);
  295. return (List<AdmFloor>)admResponse.getContent();
  296. }
  297. /**
  298. * 获取楼层查询类型
  299. * @param floorList
  300. */
  301. private Set<String> getFloorQueryTypes(List<AdmFloor> floorList){
  302. Set<String> types = new HashSet<>();
  303. for (AdmFloor admFloor : floorList) {
  304. if(CollUtil.isNotEmpty(admFloor.getOutline())){
  305. types.add(AdmRelationTypeEnum.EQ2FL.getRelCode());
  306. types.add(AdmRelationTypeEnum.FL2SP.getRelCode());
  307. types.add(AdmRelationTypeEnum.BD2SP.getRelCode());
  308. }
  309. }
  310. types.add(AdmRelationTypeEnum.EQ2SP_IN.getRelCode());
  311. types.add(AdmRelationTypeEnum.EQ2EQ_ACAIRNETWORK_2.getRelCode());
  312. types.add(AdmRelationTypeEnum.EQ2EQ_CONDWATERNETWORK_1.getRelCode());
  313. types.add(AdmRelationTypeEnum.EQ2EQ_VENTNETWORK_2.getRelCode());
  314. types.add(AdmRelationTypeEnum.EQ2EQ_ACAIRNETWORK_3.getRelCode());
  315. types.add(AdmRelationTypeEnum.EQ2EQ_HEATWATERLOOP_4.getRelCode());
  316. types.add(AdmRelationTypeEnum.EQ2EQ_HEATWATERLOOP_1.getRelCode());
  317. types.add(AdmRelationTypeEnum.EQ2EQ_DHWNETWORK_1.getRelCode());
  318. types.add(AdmRelationTypeEnum.EQ2EQ_RECYCLEWATERNETWORK_1.getRelCode());
  319. types.add(AdmRelationTypeEnum.EQ2EQ_FIREVENTNETWORK_1.getRelCode());
  320. types.add(AdmRelationTypeEnum.EQ2EQ_FIREWATERNETWORK_1.getRelCode());
  321. types.add(AdmRelationTypeEnum.EQ2EQ_VRFNETWORK_1.getRelCode());
  322. types.add(AdmRelationTypeEnum.EQ2EQ_CHILLWATERLOOP_2.getRelCode());
  323. types.add(AdmRelationTypeEnum.EQ2EQFRESHAIRNETWORK_1.getRelCode());
  324. types.add(AdmRelationTypeEnum.EQ2EQ_CHILLWATERLOOP_1.getRelCode());
  325. types.add(AdmRelationTypeEnum.EQ2EQ_DRINKINGWATERNETWORK_1.getRelCode());
  326. types.add(AdmRelationTypeEnum.EQ2EQ_COOLINGWATERLOOP_2.getRelCode());
  327. types.add(AdmRelationTypeEnum.EQ2EQ_VENTNETWORK_1.getRelCode());
  328. types.add(AdmRelationTypeEnum.EQ2EQ_HEATWATERLOOP_2.getRelCode());
  329. types.add(AdmRelationTypeEnum.EQ2EQ_COOLINGWATERLOOP_1.getRelCode());
  330. types.add(AdmRelationTypeEnum.EQ2EQ_ACAIRNETWORK_1.getRelCode());
  331. types.add(AdmRelationTypeEnum.EQ2EQ_SUPPLYWATERNETWORK_1.getRelCode());
  332. types.add(AdmRelationTypeEnum.EQ2EQ_DRAININGWATERNETWORK_1.getRelCode());
  333. return types;
  334. }
  335. }