AdmModelRelServiceImpl.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. package com.persagy.proxy.dictionary.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.map.MapUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  6. import com.fasterxml.jackson.databind.node.ObjectNode;
  7. import com.persagy.dmp.common.exception.BusinessException;
  8. import com.persagy.dmp.digital.entity.ObjectRelationProjectCal;
  9. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  10. import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
  11. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  12. import com.persagy.proxy.adm.request.AdmResponse;
  13. import com.persagy.proxy.adm.service.impl.AbstractAdmBaseServiceImpl;
  14. import com.persagy.proxy.adm.utils.GeoToolsUtil;
  15. import com.persagy.proxy.calculation.service.IAdmObjectRelationCalService;
  16. import com.persagy.proxy.common.entity.InstanceUrlParam;
  17. import com.persagy.proxy.dictionary.model.AdmModelRel;
  18. import com.persagy.proxy.dictionary.service.IAdmModelRelService;
  19. import com.persagy.proxy.object.model.AdmEquipment;
  20. import com.persagy.proxy.object.model.AdmFloor;
  21. import com.persagy.proxy.object.model.AdmISpace;
  22. import com.persagy.proxy.object.service.IAdmEquipmentService;
  23. import com.persagy.proxy.object.service.IAdmFloorService;
  24. import com.persagy.proxy.object.service.IAdmISpaceService;
  25. import lombok.extern.slf4j.Slf4j;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import java.util.*;
  29. /**
  30. * @ClassName AdmModelRelServiceImpl
  31. * @Description: 模型修改设备元空间的建筑楼层信息
  32. * @Author linhuili
  33. * @Date 2021/8/31 14:31
  34. * @Version V1.0
  35. **/
  36. @Service
  37. @Slf4j
  38. public class AdmModelRelServiceImpl extends AbstractAdmBaseServiceImpl<AdmModelRel> implements IAdmModelRelService {
  39. @Autowired
  40. private IAdmFloorService floorService;
  41. @Autowired
  42. private IAdmEquipmentService equipmentService;
  43. @Autowired
  44. private IAdmISpaceService iSpaceService;
  45. @Autowired
  46. private IAdmObjectRelationCalService relationCalService;
  47. /**
  48. * 模型修改设备元空间的建筑楼层信息
  49. * @param context
  50. * @param clazz
  51. * @param vo
  52. * @return
  53. */
  54. @Override
  55. public void doUpdateModelInfo(InstanceUrlParam context, Class<AdmModelRel> clazz, AdmModelRel vo){
  56. // 查询楼层实体
  57. List<AdmFloor> admFloors = queryFloorEntity(context, null, vo.getFloorId());
  58. if(CollUtil.isEmpty(admFloors)){
  59. throw new BusinessException("楼层不存在");
  60. }
  61. log.info("模型修改设备元空间参数{},{}"+context,vo);
  62. // 在用模型的楼层计算状态改为2
  63. processFloorCalState(context, vo.getModelId());
  64. AdmFloor floorEntity = admFloors.get(0);
  65. processRelObjects(context, vo.getOldBimId(), vo.getBimId(), floorEntity);
  66. // 补充楼层属性
  67. Map<String, Object> infos = floorEntity.getInfos();
  68. if(CollUtil.isEmpty(infos)){
  69. infos = new HashMap<>(16);
  70. floorEntity.setInfos(infos);
  71. }
  72. infos.put("floorMap",vo.getFloorMap());
  73. Double floorElevation = MapUtil.getDouble(vo.getAttributeMap(), AdmCommonConstant.FLOOR_ELEVATION);
  74. if(floorElevation != null){
  75. infos.put(AdmCommonConstant.FLOOR_ELEVATION, floorElevation/1000);
  76. }
  77. floorEntity.setModelId(vo.getModelId());
  78. floorEntity.setBimIdPre(vo.getBimId());
  79. //5.修改楼层信息
  80. floorService.doUpdate(context, AdmFloor.class, CollUtil.newArrayList(floorEntity));
  81. }
  82. /**
  83. * 处理在用模型文件的楼层计算状态
  84. * @param context
  85. * @param modelId
  86. */
  87. private void processFloorCalState(InstanceUrlParam context, String modelId) {
  88. List<AdmFloor> floorList = queryFloorEntity(context, modelId, null);
  89. if(CollUtil.isEmpty(floorList)) {
  90. return;
  91. }
  92. Set<String> floorQueryTypes = getFloorQueryTypes(floorList);
  93. List<ObjectRelationProjectCal> needCals = relationCalService.queryCalRelByRelationType(context, floorQueryTypes);
  94. if(CollUtil.isEmpty(needCals)) {
  95. return;
  96. }
  97. //更新边类型计算状态:computationalState为2
  98. needCals.forEach(item->{
  99. item.setComputationalState(2);
  100. });
  101. relationCalService.updateObjectCalRel(context, needCals);
  102. }
  103. /**
  104. * 处理关联的元空间和设备
  105. * @param context
  106. * @param oldBimId
  107. * @param bimId
  108. * @param floor
  109. */
  110. private void processRelObjects(InstanceUrlParam context, String oldBimId, String bimId, AdmFloor floor) {
  111. // 如果bimId不一致,则清空原来的楼层信息
  112. if(StrUtil.isNotBlank(oldBimId) && !StrUtil.equals(oldBimId, bimId)) {
  113. updateRelEquipments(context, oldBimId, floor, true);
  114. updateRelISpace(context, oldBimId, floor, true);
  115. }
  116. // 更新新关联的
  117. updateRelEquipments(context, bimId, floor, false);
  118. updateRelISpace(context, bimId, floor, false);
  119. }
  120. /**
  121. * 更新设备
  122. * @param context
  123. * @param bimId
  124. * @param floor
  125. */
  126. private void updateRelEquipments(InstanceUrlParam context, String bimId,
  127. AdmFloor floor, boolean deleteFlag) {
  128. if(StrUtil.isBlank(bimId)) {
  129. return;
  130. }
  131. //查询模型下的设备信息
  132. AdmQueryCriteria criteria = new AdmQueryCriteria();
  133. criteria.addFilters("bimId startwith '" + bimId + ":'");
  134. // 如果是删除,只删本楼层的
  135. if(deleteFlag) {
  136. criteria.addFilters("floorId = '" + floor.getId() + "'");
  137. }
  138. criteria.setName(AdmEquipment.OBJ_TYPE);
  139. AdmResponse admResponse = equipmentService.doQuery(context, criteria, AdmEquipment.class);
  140. List<AdmEquipment> content = (List<AdmEquipment>) admResponse.getContent();
  141. if(CollUtil.isEmpty(content)) {
  142. return;
  143. }
  144. List<AdmEquipment> rsList = new ArrayList<>();
  145. for (AdmEquipment admEquipment : content) {
  146. if(deleteFlag) {
  147. admEquipment.setBuildingId(null);
  148. admEquipment.setFloorId(null);
  149. rsList.add(admEquipment);
  150. continue;
  151. }
  152. if(!isPointInPolygon(admEquipment, floor.getOutline())) {
  153. continue;
  154. }
  155. //修改设备的建筑楼层信息
  156. admEquipment.setBuildingId(floor.getBuildingId());
  157. admEquipment.setFloorId(floor.getId());
  158. rsList.add(admEquipment);
  159. }
  160. if(CollUtil.isEmpty(rsList)) {
  161. return;
  162. }
  163. equipmentService.doUpdate(context, AdmEquipment.class, rsList);
  164. }
  165. /**
  166. * 更新元空间
  167. * @param context
  168. * @param bimId
  169. * @param floor
  170. */
  171. private void updateRelISpace(InstanceUrlParam context, String bimId,
  172. AdmFloor floor, boolean deleteFlag) {
  173. if(StrUtil.isBlank(bimId)) {
  174. return;
  175. }
  176. //查询模型下的设备信息
  177. AdmQueryCriteria criteria = new AdmQueryCriteria();
  178. criteria.addFilters("bimId startwith '" + bimId + ":'");
  179. // 如果是删除,只删本楼层的
  180. if(deleteFlag) {
  181. criteria.addFilters("floorId = '" + floor.getId() + "'");
  182. }
  183. criteria.setName(AdmISpace.OBJ_TYPE);
  184. AdmResponse admResponse = iSpaceService.doQuery(context, criteria, AdmISpace.class);
  185. List<AdmISpace> content = (List<AdmISpace>) admResponse.getContent();
  186. if(CollUtil.isEmpty(content)) {
  187. return;
  188. }
  189. Set<String> nullList = CollUtil.newHashSet("buildingId", "floorId");
  190. for (AdmISpace iSpace : content) {
  191. if(deleteFlag) {
  192. iSpace.setBuildingId(null);
  193. iSpace.setFloorId(null);
  194. iSpace.setNullList(nullList);
  195. continue;
  196. }
  197. //修改设备的建筑楼层信息
  198. iSpace.setBuildingId(floor.getBuildingId());
  199. iSpace.setFloorId(floor.getId());
  200. }
  201. iSpaceService.doUpdate(context, AdmISpace.class, content);
  202. }
  203. /**
  204. * 判断点是否在面中
  205. * @return
  206. */
  207. private boolean isPointInPolygon(AdmEquipment equipment, List<ObjectNode> outline){
  208. // 如果为空,表示无限边界
  209. if(CollUtil.isEmpty(outline)) {
  210. return true;
  211. }
  212. Boolean flag = true;
  213. //设备BIM坐标
  214. String bimLocation = equipment.getBimLocation();
  215. //判断点是否在面中:即设备位置是否在该楼层轮廓线中
  216. if(StrUtil.isBlank(bimLocation)){
  217. return false;
  218. }
  219. String[] split = bimLocation.split(",");
  220. ObjectNode node = JsonNodeFactory.instance.objectNode();
  221. node.put("x",Double.valueOf(split[0]));
  222. node.put("y",Double.valueOf(split[1]));
  223. node.put("z",Double.valueOf(split[2]));
  224. return GeoToolsUtil.isPointInPoly(node,outline);
  225. }
  226. /**
  227. * 查询模型文件是否有楼层在使用
  228. */
  229. private List<AdmFloor> queryFloorEntity(InstanceUrlParam context, String modelId, String floorId){
  230. if(StrUtil.isBlank(modelId) && StrUtil.isBlank(floorId)){
  231. return new ArrayList<>();
  232. }
  233. AdmQueryCriteria criteria = new AdmQueryCriteria();
  234. if(StrUtil.isNotBlank(modelId)) {
  235. criteria.addFilters(" modelId = '" + modelId + "' ");
  236. }
  237. if(StrUtil.isNotBlank(floorId)) {
  238. criteria.addFilters(" id = '"+floorId+"' ");
  239. }
  240. criteria.setName(AdmFloor.OBJ_TYPE);
  241. AdmResponse admResponse = floorService.doQuery(context, criteria, AdmFloor.class);
  242. return (List<AdmFloor>)admResponse.getContent();
  243. }
  244. /**
  245. * 获取楼层查询类型
  246. * @param floorList
  247. */
  248. private Set<String> getFloorQueryTypes(List<AdmFloor> floorList){
  249. Set<String> types = new HashSet<>();
  250. for (AdmFloor admFloor : floorList) {
  251. if(CollUtil.isNotEmpty(admFloor.getOutline())){
  252. types.add(AdmRelationTypeEnum.EQ2FL.getRelCode());
  253. types.add(AdmRelationTypeEnum.FL2SP.getRelCode());
  254. types.add(AdmRelationTypeEnum.BD2SP.getRelCode());
  255. }
  256. }
  257. types.add(AdmRelationTypeEnum.EQ2SP_IN.getRelCode());
  258. types.add(AdmRelationTypeEnum.EQ2EQ_ACAIRNETWORK_2.getRelCode());
  259. types.add(AdmRelationTypeEnum.EQ2EQ_CONDWATERNETWORK_1.getRelCode());
  260. types.add(AdmRelationTypeEnum.EQ2EQ_VENTNETWORK_2.getRelCode());
  261. types.add(AdmRelationTypeEnum.EQ2EQ_ACAIRNETWORK_3.getRelCode());
  262. types.add(AdmRelationTypeEnum.EQ2EQ_HEATWATERLOOP_4.getRelCode());
  263. types.add(AdmRelationTypeEnum.EQ2EQ_HEATWATERLOOP_1.getRelCode());
  264. types.add(AdmRelationTypeEnum.EQ2EQ_DHWNETWORK_1.getRelCode());
  265. types.add(AdmRelationTypeEnum.EQ2EQ_RECYCLEWATERNETWORK_1.getRelCode());
  266. types.add(AdmRelationTypeEnum.EQ2EQ_FIREVENTNETWORK_1.getRelCode());
  267. types.add(AdmRelationTypeEnum.EQ2EQ_FIREWATERNETWORK_1.getRelCode());
  268. types.add(AdmRelationTypeEnum.EQ2EQ_VRFNETWORK_1.getRelCode());
  269. types.add(AdmRelationTypeEnum.EQ2EQ_CHILLWATERLOOP_2.getRelCode());
  270. types.add(AdmRelationTypeEnum.EQ2EQFRESHAIRNETWORK_1.getRelCode());
  271. types.add(AdmRelationTypeEnum.EQ2EQ_CHILLWATERLOOP_1.getRelCode());
  272. types.add(AdmRelationTypeEnum.EQ2EQ_DRINKINGWATERNETWORK_1.getRelCode());
  273. types.add(AdmRelationTypeEnum.EQ2EQ_COOLINGWATERLOOP_2.getRelCode());
  274. types.add(AdmRelationTypeEnum.EQ2EQ_VENTNETWORK_1.getRelCode());
  275. types.add(AdmRelationTypeEnum.EQ2EQ_HEATWATERLOOP_2.getRelCode());
  276. types.add(AdmRelationTypeEnum.EQ2EQ_COOLINGWATERLOOP_1.getRelCode());
  277. types.add(AdmRelationTypeEnum.EQ2EQ_ACAIRNETWORK_1.getRelCode());
  278. types.add(AdmRelationTypeEnum.EQ2EQ_SUPPLYWATERNETWORK_1.getRelCode());
  279. types.add(AdmRelationTypeEnum.EQ2EQ_DRAININGWATERNETWORK_1.getRelCode());
  280. return types;
  281. }
  282. }