AdmSystemController.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.fasterxml.jackson.databind.node.ArrayNode;
  5. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  6. import com.fasterxml.jackson.databind.node.ObjectNode;
  7. import com.persagy.dmp.basic.model.QueryCriteria;
  8. import com.persagy.dmp.common.model.entity.BaseEntity;
  9. import com.persagy.dmp.define.client.DigitalDefineFacade;
  10. import com.persagy.dmp.define.entity.ObjectTypeDefine;
  11. import com.persagy.dmp.digital.client.DigitalObjectFacade;
  12. import com.persagy.dmp.digital.client.DigitalRelationFacade;
  13. import com.persagy.dmp.digital.entity.ObjectRelation;
  14. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  15. import com.persagy.proxy.adm.model.*;
  16. import com.persagy.proxy.adm.request.AdmCreateRequest;
  17. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  18. import com.persagy.proxy.adm.request.AdmResponse;
  19. import com.persagy.proxy.adm.service.IAdmBuildingService;
  20. import com.persagy.proxy.adm.service.IAdmFloorService;
  21. import com.persagy.proxy.adm.service.IAdmSystemService;
  22. import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
  23. import com.persagy.proxy.adm.utils.ObjectNameUtil;
  24. import com.persagy.proxy.common.entity.InstanceUrlParam;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.beans.factory.annotation.Value;
  27. import org.springframework.web.bind.annotation.*;
  28. import javax.json.JsonObject;
  29. import javax.validation.constraints.NotNull;
  30. import javax.ws.rs.QueryParam;
  31. import java.util.ArrayList;
  32. import java.util.List;
  33. import java.util.Map;
  34. /**
  35. * Adm 系统 API
  36. * @author lvxy
  37. * @date 2021/8/16
  38. */
  39. @RestController
  40. @RequestMapping("/object/general-system")
  41. public class AdmSystemController {
  42. @Autowired
  43. private IAdmSystemService service;
  44. @Autowired
  45. private IAdmBuildingService buildingService;
  46. @Autowired
  47. private IAdmFloorService floorService;
  48. @Value("${middleware.group.code}")
  49. private String groupCode;
  50. /**
  51. * 统计
  52. * @param projectId
  53. * @param request
  54. * @return
  55. * @throws Exception
  56. */
  57. @PostMapping("/count")
  58. public AdmResponse count(@QueryParam("projectId") String projectId,
  59. @RequestBody AdmQueryCriteria request) throws Exception {
  60. // 组装上下文条件
  61. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  62. request.setName(AdmSystem.OBJ_TYPE);
  63. request.setOnlyCount(true);
  64. return service.doQuery(context, request, AdmSystem.class);
  65. }
  66. /**
  67. * 创建
  68. * @param createRequest
  69. * @return
  70. * @throws Exception
  71. */
  72. @PostMapping("/create")
  73. public AdmResponse create(@RequestBody AdmCreateRequest<AdmSystem> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  74. // 组装上下文条件
  75. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  76. List<AdmSystem> vos = CollUtil.newArrayList(createRequest.getContent());
  77. vos = service.doInsert(context, AdmSystem.class, vos);
  78. return AdmResponse.success(vos);
  79. }
  80. /**
  81. * 创建系统信息-处理建筑楼层
  82. * @param createRequest
  83. * @return
  84. * @throws Exception
  85. */
  86. @PostMapping("/create-bd-fl")
  87. public AdmResponse createBdFl(@RequestBody AdmCreateRequest<AdmSystem> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  88. // 组装上下文条件
  89. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  90. List<AdmSystem> vos = CollUtil.newArrayList(createRequest.getContent());
  91. Map<String, AdmSystem> admSystemMap = CollUtil.fieldValueMap(vos, "classCode");
  92. QueryCriteria defineCriteria = new QueryCriteria();
  93. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  94. ArrayNode array = criteria.putObject("code").putArray("$in");
  95. admSystemMap.keySet().stream().forEach(classCode -> array.add(classCode));
  96. defineCriteria.setCriteria(criteria);
  97. List<ObjectTypeDefine> defineList = DigitalDefineFacade.queryObjectType(context.getGroupCode(),context.getProjectId(),context.getAppId(),null,defineCriteria);
  98. Map<String, ObjectTypeDefine> defineMap = CollUtil.fieldValueMap(defineList, "code");
  99. vos.stream().forEach(admSystem -> {
  100. if(StrUtil.isEmpty(admSystem.getName())){
  101. if(CollUtil.isNotEmpty(defineList) && defineMap.containsKey(admSystem.getClassCode())){
  102. admSystem.setName(ObjectNameUtil.objectName(defineMap.get(admSystem.getClassCode()).getName()+"系统-"));
  103. }else {
  104. admSystem.setName(ObjectNameUtil.objectName("系统-"));
  105. }
  106. }
  107. });
  108. vos = service.doInsert(context, AdmSystem.class, vos);
  109. return AdmResponse.success(vos);
  110. }
  111. /**
  112. * 根据ID删除
  113. * @param vos
  114. * @return
  115. * @throws Exception
  116. */
  117. @PostMapping("/delete")
  118. public AdmResponse delete(@QueryParam("projectId") String projectId, @RequestBody List<AdmSystem> vos) throws Exception {
  119. // 组装上下文条件
  120. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  121. service.doDelete(context, vos);
  122. return AdmResponse.success();
  123. }
  124. /**
  125. * 更新
  126. * @param createRequest
  127. * @return
  128. * @throws Exception
  129. */
  130. @PostMapping("/update")
  131. public AdmResponse update(@RequestBody AdmCreateRequest<AdmSystem> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  132. // 组装上下文条件
  133. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  134. List<AdmSystem> vos = CollUtil.newArrayList(createRequest.getContent());
  135. vos = service.doUpdate(context, AdmSystem.class, vos);
  136. return AdmResponse.success(vos);
  137. }
  138. /**
  139. * 系统绑定的动态信息点或静态信息点
  140. * type: static(静态),iot (动态)
  141. * @param projectId
  142. * @param request
  143. * @return
  144. * @throws Exception
  145. */
  146. @GetMapping("/export")
  147. public AdmResponse exportInfos(@QueryParam("projectId") String projectId,
  148. @RequestBody AdmQueryCriteria request) throws Exception {
  149. // 组装上下文条件
  150. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  151. request.setName(AdmSystem.OBJ_TYPE);
  152. return service.doQuery(context, request, AdmSystem.class);
  153. }
  154. /**
  155. * 创建系统下的设备关系
  156. * @param createRequest
  157. * @return
  158. * @throws Exception
  159. */
  160. @PostMapping("/link-equip")
  161. public AdmResponse createRelateEquip(@RequestBody JsonObject createRequest, @QueryParam("projectId") String projectId) throws Exception {
  162. // 组装上下文条件
  163. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  164. String sysId = createRequest.get("sysId").toString();
  165. List<String> equipIdList = (List<String>)createRequest.get("equipIdList");
  166. List<ObjectNode> relations = new ArrayList<>(equipIdList.size());
  167. equipIdList.stream().forEach(euipId -> {
  168. ObjectNode objectNode = JsonNodeFactory.instance.objectNode();
  169. objectNode.put("relCode", "Sy2Eq");
  170. objectNode.put("graphCode","MechSubset");
  171. objectNode.put("objFrom", sysId);
  172. objectNode.put("objTo", euipId);
  173. });
  174. List<ObjectRelation> list = DigitalRelationFacade.create(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, relations);
  175. return AdmResponse.success(list);
  176. }
  177. /**
  178. * 查询
  179. * @param projectId
  180. * @param request
  181. * @return
  182. * @throws Exception
  183. */
  184. @PostMapping("/query")
  185. public AdmResponse query(@QueryParam("projectId") String projectId,
  186. @RequestBody AdmQueryCriteria request) throws Exception {
  187. // 组装上下文条件
  188. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  189. request.setName(AdmSystem.OBJ_TYPE);
  190. return service.doQuery(context, request, AdmSystem.class);
  191. }
  192. /**
  193. * 查询系统信息-系统建筑楼层一对多
  194. * MajorName 专业名称 ,级联查询 系统分类名(categoryNames),系统下的设备(equipmentList),系统下的竖井(shaftList),业务空间(zoneSpaceBaseTableList)
  195. *
  196. * 这个参见中心代码,
  197. * @param projectId
  198. * @param buildingId buildingId=1,未明确建筑
  199. * @param floorId floorId=1,未明确楼层
  200. * @param request
  201. * @return
  202. * @throws Exception
  203. */
  204. @PostMapping("/query-new")
  205. public AdmResponse queryNew(@QueryParam("projectId") String projectId, @QueryParam("buildingId") String buildingId,
  206. @QueryParam("floorId") String floorId, @RequestBody AdmQueryCriteria request) throws Exception {
  207. if(StrUtil.isEmpty(projectId)){
  208. return AdmResponse.failure("项目id为空");
  209. }
  210. // 组装上下文条件
  211. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  212. if(StrUtil.isAllNotEmpty(buildingId, floorId) && !"1".equals(buildingId) && !"1".equals(floorId)){
  213. //系统级联建筑 楼层
  214. AdmResponse syses = service.doQuery(context, request, AdmSystem.class);
  215. if(CollUtil.isEmpty(syses.getContent())){
  216. return syses;
  217. }
  218. AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
  219. admQueryCriteria.setName(AdmBuilding.OBJ_TYPE);
  220. admQueryCriteria.setFilters("id = "+buildingId);
  221. AdmResponse buildings = buildingService.doQuery(context, request, AdmBuilding.class);
  222. admQueryCriteria = new AdmQueryCriteria();
  223. admQueryCriteria.setName(AdmFloor.OBJ_TYPE);
  224. admQueryCriteria.setFilters("id = "+floorId);
  225. AdmResponse floors = floorService.doQuery(context, request, AdmFloor.class);
  226. //处理数据 BuildingFloorInfo
  227. AdmBuildingFloorInfo buildingFloorInfo = new AdmBuildingFloorInfo();
  228. if(CollUtil.isNotEmpty(floors.getContent())){
  229. AdmFloor floor = (AdmFloor) floors.getContent().get(0);
  230. buildingFloorInfo.setFloorName(floor.getLocalName());
  231. buildingFloorInfo.setFloorID(floorId);
  232. }
  233. if(CollUtil.isNotEmpty(buildings.getContent())){
  234. AdmBuilding building = (AdmBuilding) floors.getContent().get(0);
  235. buildingFloorInfo.setBuildName(building.getLocalName());
  236. buildingFloorInfo.setBuildID(buildingId);
  237. }
  238. List<AdmSystem> admSystemList = (List<AdmSystem>) syses.getContent();
  239. admSystemList.stream().forEach( admSystem -> {
  240. admSystem.setBuildingFloorInfoList(CollUtil.newArrayList(buildingFloorInfo));
  241. });
  242. syses.setContent(admSystemList);
  243. return syses;
  244. }
  245. return null;
  246. /*
  247. QueryCriteria queryCriteria_sysInFl = new QueryCriteria();
  248. ObjectNode criteria_sysInFl = JsonNodeFactory.instance.objectNode();
  249. criteria_sysInFl.put("relCode","Sy2Fl");
  250. criteria_sysInFl.put("graphCode", "MechInArch");
  251. QueryCriteria queryCriteria_sysInBd = new QueryCriteria();
  252. ObjectNode criteria_sysInBd= JsonNodeFactory.instance.objectNode();
  253. criteria_sysInBd.put("graphCode", "MechInArch");
  254. criteria_sysInBd.put("relCode","Sy2Bd");
  255. QueryCriteria queryCriteriaObj = AdmQueryCriteriaHelper.toDmpCriteria(request);
  256. ObjectNode criteria_obj = JsonNodeFactory.instance.objectNode();
  257. criteria_obj.put("objType", AdmSystem.OBJ_TYPE);
  258. Set<String> sysIds = new HashSet<>();
  259. List<ObjectRelation> relations_SysInFl = null;
  260. if(StrUtil.isAllNotEmpty(buildingId,floorId)&&!floorId.equals("1")){
  261. *//** 楼层id不为空且不为1,建筑id为空 ---> 系统和楼层关系表 取系统id 408 --> 明确建筑明确楼层->空间*//*
  262. criteria_sysInFl.put("objTo", floorId);
  263. queryCriteria_sysInFl.setCriteria(criteria_sysInFl);
  264. relations_SysInFl = DigitalRelationFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteria_sysInFl);
  265. if(CollUtil.isNotEmpty(relations_SysInFl)){
  266. sysIds = relations_SysInFl.stream().map(ObjectRelation::getObjFrom).collect(Collectors.toSet());
  267. }
  268. ensureCondion(context, null, sysIds, criteria_obj,true);
  269. }else if(StrUtil.isAllNotEmpty(buildingId,floorId)&&floorId.equals("1")&&!buildingId.equals("1")){
  270. *//** 楼层id为空,建筑id不为空且不为1 ---> 系统和建筑关系表 取系统id 421*//*
  271. // 明确建筑 未明确楼层
  272. relations_SysInFl = DigitalRelationFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteria_sysInFl);
  273. if(CollUtil.isNotEmpty(relations_SysInFl)){
  274. List<String> sysIds_floor = relations_SysInFl.stream().map(ObjectRelation::getObjFrom).collect(Collectors.toList());
  275. criteria_sysInBd.put("objTo", buildingId);
  276. ArrayNode arrayNode = criteria_sysInBd.putObject("$notcontains").putArray("objFrom");
  277. sysIds_floor.stream().forEach(id -> arrayNode.add(id));
  278. queryCriteria_sysInBd.setCriteria(criteria_sysInBd);
  279. ensureCondion(context, queryCriteria_sysInBd, sysIds, criteria_obj,true);
  280. }
  281. }else if(StrUtil.isEmpty(floorId) && StrUtil.isNotEmpty(buildingId) && buildingId.equals("1")){
  282. *//** 楼层id为1,建筑id为1 ---> 系统id不在(系统和楼层关系表 取系统id 系统和建筑关系表 取系统id)之内 450*//*
  283. //未明确建筑 没有Sy2Bd关系的系统
  284. ensureCondion(context, queryCriteria_sysInBd, sysIds, criteria_obj,false);
  285. }else if(StrUtil.isEmpty(floorId) && StrUtil.isNotEmpty(buildingId) && !buildingId.equals("1")){
  286. *//** 楼层id不为空,建筑id不为空 ---> 系统和楼层关系表 取系统id 将建筑id作为条件 461*//*
  287. criteria_sysInBd.put("objTo", buildingId);
  288. queryCriteria_sysInBd.setCriteria(criteria_sysInBd);
  289. ensureCondion(context, queryCriteria_sysInBd, sysIds, criteria_obj,true);
  290. } else if(StrUtil.isAllEmpty(floorId, buildingId)){
  291. *//** 楼层id为空,建筑id为空 ---> 查询所有 *//*
  292. }
  293. queryCriteriaObj.setCriteria(criteria_obj);
  294. List<ObjectNode> systems = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteriaObj);
  295. if(CollUtil.isNotEmpty(systems)){
  296. List<AdmSystem> admSystemList = JSONUtil.toList(systems.toString(), AdmSystem.class);
  297. if(StrUtil.isNotEmpty(buildingId)){
  298. if(!buildingId.equals("1")){
  299. //处理数据 添加每个系统关联的建筑楼层信息, 查看全部信息展示所在建筑
  300. //查询关联的建筑信息
  301. QueryCriteria queryCriteriaInfo = new QueryCriteria();
  302. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  303. ArrayNode arrayNode = criteria.putObject("id").putArray("$in");
  304. arrayNode.add(buildingId);
  305. if(StrUtil.isNotEmpty(floorId)){
  306. //明确的建筑,明确的楼层 查询建筑关联的楼层信息 如果Sy2Fl -> Sy2Bd & Bd2Fl
  307. if(!floorId.equals("1")){
  308. arrayNode.add(floorId);
  309. }
  310. queryCriteriaInfo.setCriteria(criteria);
  311. List<ObjectNode> objs = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteriaInfo);
  312. if(CollUtil.isNotEmpty(objs)){
  313. List<ObjectDigital> objectDigitals = JSONUtil.toList(objs.toString(), ObjectDigital.class);
  314. AdmBuildingFloorInfo admBuildingFloorInfo = new AdmBuildingFloorInfo();
  315. objectDigitals.forEach(objectDigital -> {
  316. if(objectDigital.getObjType().equals(AdmFloor.OBJ_TYPE)){
  317. admBuildingFloorInfo.setFloorID(objectDigital.getId());
  318. admBuildingFloorInfo.setFloorName(objectDigital.getLocalName());
  319. }
  320. if(objectDigital.getObjType().equals(AdmBuilding.OBJ_TYPE)){
  321. admBuildingFloorInfo.setBuildID(objectDigital.getId());
  322. admBuildingFloorInfo.setBuildName(objectDigital.getLocalName());
  323. }
  324. });
  325. admSystemList.stream().forEach(admSystem -> admSystem.setBuildingFloorInfoList(CollUtil.newArrayList(admBuildingFloorInfo)));
  326. }
  327. }
  328. }
  329. }else{
  330. //查询每个系统的建筑楼层信息
  331. Map<String, AdmSystem> admSystemMap = CollUtil.fieldValueMap(admSystemList, BaseEntity.PROP_ID);
  332. //查询
  333. //查询楼层
  334. }
  335. return AdmResponse.success(systems);
  336. }else{
  337. return AdmResponse.success();
  338. }*/
  339. }
  340. /*private void ensureCondion(InstanceUrlParam context, QueryCriteria queryCriteria_sysInBd, Set<String>sysIds, ObjectNode criteria_obj, boolean ifInCondition){
  341. if(queryCriteria_sysInBd != null){
  342. List<ObjectRelation> relations_SysInBd = DigitalRelationFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteria_sysInBd);
  343. if(CollUtil.isNotEmpty(relations_SysInBd)){
  344. sysIds = relations_SysInBd.stream().map(ObjectRelation::getObjFrom).collect(Collectors.toSet());
  345. }
  346. }
  347. if(CollUtil.isNotEmpty(sysIds)){
  348. if(ifInCondition){
  349. criteria_obj.put("id", sysIds.toArray().toString());
  350. }else {
  351. ArrayNode arrayNode = criteria_obj.putObject("$notcontains").putArray("id");
  352. sysIds.stream().forEach(id -> arrayNode.add(id));
  353. }
  354. }
  355. }*/
  356. /**
  357. * 查询系统信息-试图级联建筑楼层 暂未使用
  358. * @param projectId
  359. * @param request
  360. * @return
  361. * @throws Exception
  362. */
  363. @PostMapping("/query-bdfl")
  364. public AdmResponse queryUnBdFl(@QueryParam("projectId") String projectId,
  365. @RequestBody AdmQueryCriteria request) throws Exception {
  366. // 组装上下文条件
  367. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  368. request.setName(AdmSystem.OBJ_TYPE);
  369. return service.doQuery(context, request, AdmSystem.class);
  370. }
  371. /**
  372. * 查询没有和当前系统关联的设备
  373. * id 为系统id
  374. * @param projectId
  375. * @param request
  376. * @return
  377. * @throws Exception
  378. */
  379. @PostMapping("/un-sys-equip")
  380. public AdmResponse queryUnEquip(@QueryParam("projectId") String projectId, @NotNull @QueryParam("sysId") String sysId,
  381. @RequestBody AdmQueryCriteria request) throws Exception {
  382. // 组装上下文条件
  383. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  384. AdmResponse admResponse = queryObjectByType(context,sysId,request,"Sy2Eq","MechSubset", AdmEquipment.OBJ_TYPE);
  385. return admResponse;
  386. }
  387. /**
  388. * 查询没有和当前系统关联的竖井
  389. * id 为系统id
  390. * @param projectId
  391. * @param request
  392. * @return
  393. * @throws Exception
  394. */
  395. @PostMapping("/un-sys-shaft")
  396. public AdmResponse queryUnSh(@QueryParam("projectId") String projectId, @NotNull @QueryParam("sysId") String sysId,
  397. @RequestBody AdmQueryCriteria request) throws Exception {
  398. // 组装上下文条件
  399. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  400. AdmResponse admResponse = queryObjectByType(context,sysId,request,"Sy2Sh",null, AdmShaft.OBJ_TYPE);
  401. return admResponse;
  402. }
  403. /**
  404. * 查询没有和当前系统关联的业务空间
  405. * id 为系统id
  406. * @param projectId
  407. * @param request
  408. * @return
  409. * @throws Exception
  410. */
  411. @PostMapping("/un-sys-zoneSpaceBaseTable")
  412. public AdmResponse queryUnZoneSp(@QueryParam("projectId") String projectId,@NotNull @QueryParam("sysId") String sysId,
  413. @RequestBody AdmQueryCriteria request) throws Exception {
  414. // 组装上下文条件
  415. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  416. AdmResponse admResponse = queryObjectByType(context,sysId,request,"Sy2Sp",null, AdmSpace.OBJ_TYPE);
  417. return admResponse;
  418. }
  419. /**
  420. * 查询没有和当前空间绑定的系统
  421. * 例如:prijectId=Pj4201050001,type=AirConditioningZone spaceId=Sp4201050001df2091cdf719443b80bb737aeabf0525 spaceId 为当前空间id type为当前空间类型
  422. * @param projectId
  423. * @param request
  424. * @return
  425. * @throws Exception
  426. */
  427. @PostMapping("/unspace-sys")
  428. public AdmResponse queryUnSpSy(@QueryParam("projectId") String projectId, @QueryParam("type") String type, @QueryParam("spaceId") String spaceId,
  429. @RequestBody AdmQueryCriteria request) throws Exception {
  430. // 组装上下文条件
  431. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  432. if(StrUtil.isNotEmpty(spaceId)){
  433. AdmResponse admResponse = queryObjectByType(context, spaceId, request,"Sy2Sp",null, AdmSystem.OBJ_TYPE);
  434. return admResponse;
  435. }else{
  436. if(StrUtil.isNotEmpty(type)){
  437. QueryCriteria queryCriteriaObj = AdmQueryCriteriaHelper.toDmpCriteria(request);
  438. ObjectNode criteriaObj = JsonNodeFactory.instance.objectNode();
  439. criteriaObj.put("objType", AdmSpace.OBJ_TYPE);
  440. queryCriteriaObj.setCriteria(criteriaObj);
  441. List<ObjectNode> objs = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteriaObj);
  442. QueryCriteria queryCriteriaObjSys = AdmQueryCriteriaHelper.toDmpCriteria(request);
  443. ObjectNode criteriaSys = JsonNodeFactory.instance.objectNode();
  444. criteriaObj.put("objType", AdmSystem.OBJ_TYPE);
  445. if(CollUtil.isNotEmpty(objs)){
  446. ArrayNode arrayNode = criteriaObj.putObject("id").putArray("$notcontains");
  447. for(ObjectNode objectNode: objs){
  448. arrayNode.add(objectNode.get("id").toString());
  449. }
  450. }
  451. queryCriteriaObj.setCriteria(criteriaObj);
  452. List<ObjectNode> syses = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteriaObjSys);
  453. return AdmResponse.success(syses);
  454. }
  455. return AdmResponse.success();
  456. }
  457. }
  458. private AdmResponse queryObjectByType(InstanceUrlParam context, String sysId, AdmQueryCriteria request, String relCode, String graphCode, String objType){
  459. QueryCriteria queryCriteria = new QueryCriteria();
  460. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  461. criteria.put("objFrom", sysId);
  462. criteria.put("relCode", relCode);
  463. if(StrUtil.isNotEmpty(graphCode)){
  464. criteria.put("graphCode", graphCode);
  465. }
  466. queryCriteria.setCriteria(criteria);
  467. queryCriteria.setSize(request.getPageSize()*1L);
  468. queryCriteria.setPage(request.getPageNumber()*1L);
  469. List<ObjectRelation> relations = DigitalRelationFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteria);
  470. QueryCriteria queryCriteriaObj = AdmQueryCriteriaHelper.toDmpCriteria(request);
  471. ObjectNode criteriaObj = JsonNodeFactory.instance.objectNode();
  472. criteriaObj.put("objType", objType);
  473. if(CollUtil.isNotEmpty(relations)){
  474. Map<String, ObjectRelation> objectRelationMap = CollUtil.fieldValueMap(relations,BaseEntity.PROP_ID);
  475. ArrayNode arrayNode = criteriaObj.putObject("id").putArray("$notcontains");
  476. objectRelationMap.keySet().stream().forEach(id -> arrayNode.add(id));
  477. }
  478. queryCriteriaObj.setCriteria(criteriaObj);
  479. List<ObjectNode> obj = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteriaObj);
  480. return AdmResponse.success(obj);
  481. }
  482. }