AdmSpaceInfoController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. package com.persagy.proxy.report.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.fasterxml.jackson.databind.ObjectMapper;
  6. import com.fasterxml.jackson.databind.node.ArrayNode;
  7. import com.fasterxml.jackson.databind.node.ObjectNode;
  8. import com.persagy.dmp.common.constant.ResponseCode;
  9. import com.persagy.dmp.common.helper.SpringHelper;
  10. import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
  11. import com.persagy.proxy.adm.request.AdmDCSQueryRequest;
  12. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  13. import com.persagy.proxy.adm.request.AdmResponse;
  14. import com.persagy.proxy.adm.utils.AdmContextUtil;
  15. import com.persagy.proxy.adm.utils.GeoToolsUtil;
  16. import com.persagy.proxy.object.model.AdmEquipment;
  17. import com.persagy.proxy.object.model.AdmISpace;
  18. import com.persagy.proxy.object.model.AdmSpace;
  19. import com.persagy.proxy.object.model.AdmSystem;
  20. import com.persagy.proxy.object.service.*;
  21. import lombok.RequiredArgsConstructor;
  22. import org.springframework.web.bind.annotation.PostMapping;
  23. import org.springframework.web.bind.annotation.RequestBody;
  24. import org.springframework.web.bind.annotation.RequestMapping;
  25. import org.springframework.web.bind.annotation.RestController;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.ws.rs.QueryParam;
  28. import java.util.ArrayList;
  29. import java.util.List;
  30. import java.util.Set;
  31. /**
  32. *
  33. * @version 1.0.0
  34. * @company persagy
  35. * @author zhangqiankun
  36. * @date 2021年10月18日 上午10:55:24
  37. */
  38. @RestController
  39. @RequiredArgsConstructor
  40. @RequestMapping("/space")
  41. public class AdmSpaceInfoController {
  42. private final IAdmISpaceService ispaceService;
  43. private final IAdmFloorService floorService;
  44. private final IAdmSystemService systemService;
  45. private final IAdmEquipmentService equipmentService;
  46. private final IAdmSpaceService spaceService;
  47. /**
  48. * 统计 属于多建筑楼层的空间
  49. *
  50. * @param request
  51. * @return
  52. */
  53. @RequestMapping("/space-bd-fl")
  54. public JSONObject queryCount(HttpServletRequest request) {
  55. Set<String> spaceIds = spaceService.queryMultiBuildingOrFloorSpaceIds(request);
  56. JSONObject result = new JSONObject();
  57. result.put("count", spaceIds.size());
  58. result.put("message", "");
  59. result.put("result", "success");
  60. return result;
  61. }
  62. /**
  63. * 统计 属于多建筑楼层的空间数据
  64. *
  65. * @param request
  66. * @return
  67. */
  68. @RequestMapping("/space-bd-fl-data")
  69. public AdmResponse querySpaceBdFlObj(HttpServletRequest request) {
  70. return spaceService.queryMultiBuildingOrFloorSpaces(request);
  71. }
  72. /**
  73. * 查询没有和当前空间绑定的系统
  74. * description= "例如:prijectId=Pj4201050001,type=AirConditioningZone spaceId=Sp4201050001df2091cdf719443b80bb737aeabf0525 " + "spaceId 为当前空间id type为当前空间类型 "
  75. * @param type 空间类型 空间id确定,空间类型一定确定,此参数可以不用
  76. * @param spaceId 空间id
  77. *
  78. * @author lxy
  79. */
  80. @RequestMapping("/unspace-in-sys")
  81. public AdmResponse unSpaceSys(@QueryParam("type") String type, @QueryParam("spaceId") String spaceId, @RequestBody AdmQueryCriteria request){
  82. request.setName(AdmSystem.OBJ_TYPE);
  83. // 设置关系条件
  84. request.resetRelationCond(true, "MechInArch", "Sy2Sp", spaceId, false);
  85. return systemService.query(request);
  86. }
  87. /**
  88. * 查询没有和当前空间绑定的设备
  89. * description ="例如:prijectId=Pj4201050001,type=AirConditioningZone spaceId=Sp4201050001df2091cdf719443b80bb737aeabf0525 " + "spaceId 为当前空间id type为当前空间类型 "
  90. * @return
  91. */
  92. @PostMapping("/unspace-in-eq")
  93. public AdmResponse unSpaceEq(@QueryParam("type") String type, @QueryParam("spaceId") String spaceId, @RequestBody AdmQueryCriteria request) {
  94. return unSpaceEq(type, spaceId, request, "MechInArch", false);
  95. }
  96. /**
  97. * 查询没有服务于当前空间的设备
  98. * description ="例如:prijectId=Pj4201050001,type=AirConditioningZone spaceId=Sp4201050001df2091cdf719443b80bb737aeabf0525 " +
  99. * "spaceId 为当前空间id type为当前空间类型
  100. *
  101. * @return
  102. */
  103. @PostMapping("/unspace-for-eq")
  104. public AdmResponse unSpaceForEq(@QueryParam("type") String type, @QueryParam("spaceId") String spaceId, @RequestBody AdmQueryCriteria request) {
  105. return unSpaceEq(type, spaceId, request, "MechForArch",false);
  106. }
  107. /**
  108. * 空间内没有服务于当前空间的设备
  109. */
  110. @PostMapping("/unspace-for-eq-point")
  111. public AdmResponse unSpaceForEqPoint(@QueryParam("type") String type, @QueryParam("spaceId") String spaceId, @RequestBody AdmQueryCriteria request) {
  112. return unSpaceEq(type, spaceId, request, "MechForArch",true);
  113. }
  114. /**
  115. * 根据空间轮廓 计算设备的坐标是否在空间内
  116. */
  117. @PostMapping("/unspace-fIn-eq-point")
  118. public AdmResponse unSpaceInEqPoint(@QueryParam("type") String type, @QueryParam("spaceId") String spaceId, @RequestBody AdmQueryCriteria request) {
  119. return unSpaceEq(type, spaceId, request, "MechInArch", true);
  120. }
  121. /**
  122. * 未关联业务空间的元空间 Sp2Si
  123. */
  124. @PostMapping("/unspace-ispace")
  125. public AdmResponse unSpaceIspace(@QueryParam("objectType") String objectType, @RequestBody AdmDCSQueryRequest request) {
  126. //因现有floor没有轮廓线,先不做元空间和floor的轮廓的判断,使用关系查询
  127. request.setName(AdmISpace.OBJ_TYPE);
  128. // 设置关系条件
  129. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SP2SI;
  130. request.resetRelationCond(false, null, typeEnum.getRelCode(), objectType, null, false);
  131. request.addFilters("floorId = '"+request.getFloorId()+"'");
  132. AdmResponse responseIspace = ispaceService.doQuery(AdmContextUtil.toDmpContext(),request, AdmISpace.class);
  133. responseIspace.setFloorId(request.getFloorId());
  134. responseIspace.setZoneType(objectType);
  135. return responseIspace;
  136. }
  137. /*
  138. @PostMapping("/unspace-ispace")
  139. public AdmResponse unSpaceIspace(@QueryParam("objectType") String objectType, @RequestBody AdmDCSQueryRequest request) {
  140. // 查询楼层信息 需要楼层信息中的outline modelId
  141. AdmQueryCriteria admQueryCriteriaFl = new AdmQueryCriteria();
  142. admQueryCriteriaFl.setName(AdmFloor.OBJ_TYPE);
  143. admQueryCriteriaFl.setFilters(" id = '"+request.getFloorId()+"' ");
  144. AdmResponse responseFl = floorService.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteriaFl, AdmFloor.class);
  145. if(CollUtil.isEmpty(responseFl.getContent())){
  146. return AdmResponse.failure("floorId 为空");
  147. }
  148. AdmFloor floor = (AdmFloor) responseFl.getContent().get(0);
  149. request.setName(AdmISpace.OBJ_TYPE);
  150. // 设置关系条件
  151. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SP2SI;
  152. request.resetRelationCond(false, null, typeEnum.getRelCode(), objectType, null, false);
  153. // 补充楼层条件
  154. if(StrUtil.isNotBlank(request.getFloorId())) {
  155. request.addFilters("bimId startwith '"+floor.getBimIdPre()+"' ");
  156. }
  157. AdmResponse responseIspace = ispaceService.doQuery(AdmContextUtil.toDmpContext(),request, AdmISpace.class);
  158. // 按照楼层轮廓线计算出不在轮廓线内的空间
  159. if(CollUtil.isNotEmpty(floor.getOutline())){
  160. // 计算ispace.outLine 在floor.outLine 内的ispace
  161. List<AdmISpace> iSpaceListTarget = new ArrayList<>(responseIspace.getTotal().intValue());
  162. List<AdmISpace> iSpaceList = (List<AdmISpace>) responseIspace.getContent();
  163. for(AdmISpace iSpace : iSpaceListTarget){
  164. if(CollUtil.isEmpty(iSpace.getOutline())){
  165. continue;
  166. }
  167. List<ObjectNode> ispaceOutLine = JSONArray.parseArray(iSpace.getOutline().toString(), ObjectNode.class);
  168. // if(GeoToolsUtil.isPolyInPoly(ispaceOutLine, floor.getOutline())){
  169. // iSpaceList.add(iSpace);
  170. // }
  171. }
  172. AdmResponse admResponse = AdmResponse.success(iSpaceList,request);
  173. admResponse.setFloorId(request.getFloorId());
  174. admResponse.setZoneType(objectType);
  175. admResponse.setTotal(responseIspace.getTotal());
  176. return admResponse;
  177. }else{
  178. responseIspace.setFloorId(request.getFloorId());
  179. responseIspace.setZoneType(objectType);
  180. return responseIspace;
  181. }
  182. }*/
  183. /**
  184. * 根据空间和设备的关系,查询设备
  185. * @param type
  186. * @param spaceId
  187. * @param request
  188. * @param graphCode
  189. * @param isCalPoint 是否需要 设备的点位在空间轮廓线内 默认 true
  190. * @return
  191. */
  192. private AdmResponse unSpaceEq(String type, String spaceId, AdmQueryCriteria request, String graphCode, Boolean isCalPoint) {
  193. if (StrUtil.isBlank(spaceId)) {
  194. return AdmResponse.failure(ResponseCode.A0400.getDesc() + "空间id为空");
  195. }
  196. AdmResponse responseEq = null;
  197. AdmResponse responseSpace = null;
  198. if(isCalPoint){
  199. AdmQueryCriteria queryCriteria = new AdmQueryCriteria();
  200. queryCriteria.setName(AdmSpace.OBJ_TYPE);
  201. queryCriteria.setFilters(request.getFilters());
  202. queryCriteria.addFilters("id = '"+spaceId+"'");
  203. queryCriteria.addFilters("classCode = '"+type+"'");
  204. queryCriteria.setPageSize(1);
  205. responseSpace = spaceService.query(queryCriteria);
  206. }
  207. request.addFilters("not bimLocation isnull");
  208. request.setName(AdmEquipment.OBJ_TYPE);
  209. // 设置关系条件
  210. request.resetRelationCond(true, graphCode, "Eq2Sp", type, spaceId, false);
  211. responseEq = equipmentService.query(request);
  212. if(isCalPoint && CollUtil.isNotEmpty(responseEq.getContent()) && null != responseSpace && CollUtil.isNotEmpty(responseSpace.getContent())){
  213. //根据空间轮廓和设备坐标过滤掉不在空间内的设备
  214. List<AdmEquipment> equipmentList = (List<AdmEquipment>) responseEq.getContent();
  215. List<AdmEquipment> equipmentListNew = new ArrayList<>(16);
  216. AdmSpace admSpace = (AdmSpace) responseSpace.getContent().get(0);
  217. ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
  218. ArrayNode jsonNodes = admSpace.getOutline();
  219. for(AdmEquipment equipment : equipmentList){
  220. String[] location = equipment.getBimLocation().split(",");
  221. ObjectNode bimLocation = objectMapper.createObjectNode()
  222. .put("x", location[0])
  223. .put("y", location[1]);
  224. if(location.length > 2){
  225. bimLocation.put("z", location[2]);
  226. }
  227. if(GeoToolsUtil.isPointInPoly(bimLocation, jsonNodes)){
  228. equipmentListNew.add(equipment);
  229. }else{
  230. continue;
  231. }
  232. }
  233. if(CollUtil.isNotEmpty(equipmentListNew)){
  234. responseEq.setContent(equipmentListNew);
  235. responseEq.setTotal(equipmentListNew.size()*1L);
  236. }
  237. }
  238. return responseEq;
  239. }
  240. }