AdmReportEquipController.java 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.ReflectUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import cn.hutool.json.JSONUtil;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.fasterxml.jackson.databind.JsonNode;
  8. import com.fasterxml.jackson.databind.node.ArrayNode;
  9. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  10. import com.fasterxml.jackson.databind.node.ObjectNode;
  11. import com.persagy.dmp.basic.dto.RequestData;
  12. import com.persagy.dmp.basic.model.QueryCriteria;
  13. import com.persagy.dmp.common.constant.ResponseCode;
  14. import com.persagy.dmp.common.model.entity.BaseEntity;
  15. import com.persagy.dmp.define.client.DigitalObjectInfoFacade;
  16. import com.persagy.dmp.define.entity.ObjectInfoDefine;
  17. import com.persagy.dmp.digital.client.DigitalObjectFacade;
  18. import com.persagy.dmp.digital.client.DigitalRelationFacade;
  19. import com.persagy.dmp.digital.entity.ObjectRelation;
  20. import com.persagy.dmp.simple.client.DigitalObjectSimpleFacade;
  21. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  22. import com.persagy.proxy.adm.constant.enums.AdmDictCategoryEnum;
  23. import com.persagy.proxy.adm.model.*;
  24. import com.persagy.proxy.adm.model.equip.EquipUpDateEnclosure;
  25. import com.persagy.proxy.adm.request.AdmCreateRequest;
  26. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  27. import com.persagy.proxy.adm.request.AdmResponse;
  28. import com.persagy.proxy.adm.service.IAdmComponentService;
  29. import com.persagy.proxy.adm.service.IAdmDictService;
  30. import com.persagy.proxy.adm.service.IAdmEquipmentService;
  31. import com.persagy.proxy.adm.service.IAdmSystemService;
  32. import com.persagy.proxy.adm.utils.AdmContextUtil;
  33. import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
  34. import com.persagy.proxy.common.entity.DmpResult;
  35. import com.persagy.proxy.common.entity.InstanceUrlParam;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.beans.factory.annotation.Value;
  38. import org.springframework.web.bind.annotation.*;
  39. import javax.ws.rs.QueryParam;
  40. import java.lang.reflect.Field;
  41. import java.util.*;
  42. import java.util.stream.Collectors;
  43. /**
  44. * 设备报表API
  45. * @author lvxy
  46. * @date 2021/9/18
  47. */
  48. @RestController
  49. @RequestMapping("/equip-query")
  50. public class AdmReportEquipController {
  51. @Value("${middleware.group.code}")
  52. private String groupCode;
  53. @Autowired
  54. private IAdmDictService dictService;
  55. @Autowired
  56. private IAdmEquipmentService equipmentService;
  57. @Autowired
  58. private IAdmComponentService componentService;
  59. @Autowired
  60. private IAdmSystemService systemService;
  61. /**
  62. * 查询设备信息 关联的部件 资产信息
  63. * 查询设备关联资产部件数量
  64. *
  65. *
  66. * @param request
  67. * @return
  68. * @throws Exception
  69. */
  70. @PostMapping("/equip-components")
  71. public AdmResponse getEquipAssetComponents(@RequestBody AdmQueryCriteria request) throws Exception {
  72. //查询设备
  73. request.setName(AdmEquipment.OBJ_TYPE);
  74. List<AdmQueryCriteria> cascade = new ArrayList<>();
  75. //查询设备关联的部件
  76. AdmQueryCriteria cascadeCom = new AdmQueryCriteria();
  77. cascadeCom.setName("component");
  78. cascade.add(cascadeCom);
  79. //查询设备关联的系统
  80. AdmQueryCriteria cascadeSys = new AdmQueryCriteria();
  81. cascadeSys.setName("linkSystem");
  82. cascade.add(cascadeSys);
  83. request.setCascade(cascade);
  84. AdmResponse admResponse = equipmentService.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
  85. List<AdmEquipment> equipmentList = (List<AdmEquipment>) admResponse.getContent();
  86. if(CollUtil.isNotEmpty(equipmentList)){
  87. equipmentList.stream().forEach(equip -> {
  88. if (CollUtil.isNotEmpty(equip.getComponent())) {
  89. equip.setCount(equip.getComponent().size());
  90. equip.setComponent(null);
  91. } else {
  92. equip.setCount(0);
  93. }
  94. });
  95. //查询设备的类型信息,取list中的第一个数据
  96. AdmEquipment admEquipment = equipmentList.get(0);
  97. QueryCriteria defineCriteria = new QueryCriteria();
  98. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  99. criteria.put("code", admEquipment.getClassCode());
  100. defineCriteria.setCriteria(criteria);
  101. AdmResponse defRes = dictService.doQueryObjectType(AdmContextUtil.toDmpContext(), defineCriteria, AdmObjectType.class);
  102. if (CollUtil.isNotEmpty(defRes.getContent())) {
  103. List<AdmObjectType> componentCategory = (List<AdmObjectType>) defRes.getContent();
  104. admEquipment.setComponentCategory(componentCategory);
  105. equipmentList.set(0, admEquipment);
  106. }
  107. }else{
  108. equipmentList = new ArrayList<>();
  109. }
  110. return AdmResponse.success(equipmentList);
  111. }
  112. /**
  113. * 查询当前设备类型下的部件分类以及数量
  114. *
  115. * @param request 查询信息条件
  116. * @return 查询结果
  117. */
  118. @PostMapping("/components-count")
  119. public AdmResponse getEquipComponentsCount(@RequestBody AdmQueryCriteria request){
  120. QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request);
  121. ObjectNode criteria = queryCriteria.getCriteria();
  122. if(JSONUtil.isNull(criteria)){
  123. return AdmResponse.failure("请求参数错误");
  124. }
  125. JsonNode euipId = criteria.get("id");
  126. RequestData requestData = new RequestData();
  127. requestData.setEquipmentId(String.valueOf(euipId));
  128. List result = DigitalObjectSimpleFacade.queryComponentsCountByEquipId(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmContextUtil.toDmpContext().getAppId(),null,requestData);
  129. if(CollUtil.isNotEmpty(result)){
  130. return AdmResponse.success(result);
  131. }else{
  132. return AdmResponse.success();
  133. }
  134. }
  135. /**
  136. * 查詢部件关联的资产
  137. * 资产相关暂未支持
  138. *
  139. * @param request 查询信息条件
  140. * @return 查询结果
  141. */
  142. @PostMapping("/components-property")
  143. public AdmResponse getComponentProperty(@RequestBody AdmQueryCriteria request){
  144. request.setName(AdmComponent.OBJ_TYPE);
  145. return componentService.doQuery(AdmContextUtil.toDmpContext(), request, AdmComponent.class);
  146. }
  147. /**
  148. *查询当前设备类型的允许下所有部件类型,设备下的部件对应数量
  149. *
  150. * @param id 设备id
  151. * @param category 分类
  152. */
  153. @GetMapping("/equip-compon")
  154. public AdmResponse getEquipCompon(@QueryParam("id") String id, @QueryParam("category") String category){
  155. //return rEquipComponService.getEquipCompon(id,category)
  156. RequestData requestData = new RequestData();
  157. if(StrUtil.isNotEmpty(id)){
  158. requestData.setEquipmentId(id);
  159. }
  160. if(StrUtil.isNotEmpty(category)){
  161. requestData.setClassCode(category);
  162. }
  163. List result = DigitalObjectSimpleFacade.queryEquipComponentsByProjectId(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmContextUtil.toDmpContext().getAppId(),null, requestData);
  164. if(CollUtil.isNotEmpty(result)){
  165. return AdmResponse.success(result);
  166. }else{
  167. return AdmResponse.success();
  168. }
  169. }
  170. /**
  171. * TODO
  172. * 根据设备批量创建资产
  173. * 资产相关暂未支持
  174. */
  175. @PostMapping("/creat-propertys")
  176. public AdmResponse batchCreation(@RequestBody AdmCreateRequest<AdmEquipment> createRequest, @QueryParam("projectId") String projectId) {
  177. //return EquipmentService.batchCreationProperty(request)
  178. return null;
  179. }
  180. /**
  181. * 根据条件查询统计数量 查询设备或部件
  182. * 例子: 根据设备类型或部件类型查询(\"Filters\": \"category ='SISU'\")," +
  183. * "根据设备类型和建筑查询(\"Filters\": \"category ='FASE';buildingId = '建筑id'\")," +
  184. * "根据设备类型和建筑楼层查询(\"Filters\": \"category ='FASE';buildingId = '建筑id';floorId = '楼层id'\")"
  185. */
  186. @PostMapping("/count")
  187. public AdmResponse count(@RequestBody AdmQueryCriteria request) {
  188. QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request);
  189. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  190. if(StrUtil.isNotEmpty(request.getFilters()) && request.getFilters().contains("category")){
  191. criteria.put("classCode", criteria.get("category").textValue());
  192. criteria.remove("category");
  193. }
  194. queryCriteria.setCriteria(criteria);
  195. queryCriteria.setOnlyCount(true);
  196. List<ObjectNode> euipCom = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteria);
  197. if(CollUtil.isNotEmpty(euipCom)){
  198. return AdmResponse.success(euipCom);
  199. }else{
  200. return AdmResponse.success();
  201. }
  202. }
  203. /**
  204. * 查询设备或部件
  205. *
  206. * 例子: 根据设备类型或部件类型查询(\"Filters\": \"category ='SISU'\")," +
  207. * "根据设备类型和建筑查询(\"Filters\": \"category ='FASE';buildingId = '建筑id'\")," +
  208. * "根据设备类型和建筑楼层查询(\"Filters\": \"category ='FASE';buildingId = '建筑id';floorId = '楼层id'\")"
  209. */
  210. @PostMapping("/pagequery")
  211. public AdmResponse pageQuery(@RequestBody AdmQueryCriteria request) {
  212. QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request);
  213. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  214. queryCriteria.setCriteria(criteria);
  215. if(StrUtil.isNotEmpty(request.getFilters()) && request.getFilters().contains("category")){
  216. criteria.put("classCode", criteria.get("category").textValue());
  217. criteria.remove("category");
  218. }
  219. List<ObjectNode> euipCom = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteria);
  220. if(CollUtil.isNotEmpty(euipCom)){
  221. return AdmResponse.success(euipCom);
  222. }else{
  223. return AdmResponse.success();
  224. }
  225. }
  226. /**
  227. * 跟维新确认过 暂未使用
  228. *
  229. * 根据建筑, 楼层, 业务空间类型, 业务空间id 查询设备
  230. *
  231. * description = "例子: 根据设备类型或部件类型查询(\"Filters\": \"category ='SISU'\")," +
  232. * "根据设备类型和建筑查询(\"Filters\": \"category ='FASE';buildingId = '建筑id'\")," +
  233. * "根据设备类型和建筑楼层查询(\"Filters\": \"category ='FASE';buildingId = '建筑id';floorId = '楼层id'\")" +
  234. * "所属业务空间类型填在ZoneType字段, 所属业务空间id填在ZoneId字段" +
  235. * "如果是查询不属于任何业务空间的对象, 设置notInZone = true"
  236. */
  237. @PostMapping("/zone-query")
  238. public AdmResponse zoneQuery(@RequestBody AdmZoneEquipQueryRequest request) {
  239. request.setName(AdmEquipment.OBJ_TYPE);
  240. if(StrUtil.isAllEmpty(request.getZoneType(),request.getZoneId())){
  241. return pageQuery(request);
  242. }else{
  243. }
  244. return null;
  245. }
  246. /**
  247. * 跟维新确认过 暂未使用
  248. * 根据建筑, 楼层, 业务空间类型, 业务空间id 查询部件
  249. *
  250. * 根据建筑, 楼层, 业务空间类型, 业务空间id查询部件", description = "例子: 根据设备类型或部件类型查询(\"Filters\": \"category ='SISU'\")," +
  251. * "根据设备类型和建筑查询(\"Filters\": \"category ='FASE';buildingId = '建筑id'\")," +
  252. * "根据设备类型和建筑楼层查询(\"Filters\": \"category ='FASE';buildingId = '建筑id';floorId = '楼层id'\")" +
  253. * "所属业务空间类型填在ZoneType字段, 所属业务空间id填在ZoneId字段" +
  254. * "如果是查询不属于任何业务空间的对象, 设置notInZone = true"
  255. */
  256. @PostMapping("/zone-component-query")
  257. public AdmResponse zoneComponentQuery(@RequestBody AdmZoneEquipQueryRequest request) {
  258. if(StrUtil.isAllEmpty(request.getZoneType(),request.getZoneId())){
  259. request.setName(AdmComponent.OBJ_TYPE);
  260. return pageQuery(request);
  261. }
  262. return null;
  263. }
  264. /**
  265. * 批量创建设备同时创建资产、创建设备和系统的关系
  266. *
  267. */
  268. @PostMapping("/creat-equip-pro")
  269. public AdmResponse create(@RequestBody AdmCreateRequest<AdmEquipment> createRequest){
  270. //return EquipmentProSyService.createList(request)
  271. List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
  272. vos = equipmentService.doInsertEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
  273. return AdmResponse.success(vos);
  274. }
  275. /**
  276. * 查询不在当前系统下的设备
  277. */
  278. @PostMapping("/equip-sys")
  279. public AdmResponse pageQueryEquipSys(@RequestBody AdmQueryCriteria request,@QueryParam("sysId") String sysId){
  280. //return EquipmentService.queryBeforeEquipSy(sysId,request)
  281. QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request);
  282. ObjectNode criteriaEquip = JsonNodeFactory.instance.objectNode();
  283. criteriaEquip.put("objType", AdmEquipment.OBJ_TYPE);
  284. JSONObject relationTo = new JSONObject();
  285. relationTo.put("relCode", "Sy2Eq");
  286. relationTo.put("graphCode", "MechSubset");
  287. JSONObject objFrom = new JSONObject();
  288. objFrom.put("$ne",sysId);
  289. relationTo.put("objFrom", objFrom);
  290. criteriaEquip.putPOJO("relationTo",relationTo);
  291. queryCriteria.setCriteria(criteriaEquip);
  292. List<ObjectNode> equips = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteria);
  293. if (CollUtil.isEmpty(equips))
  294. return AdmResponse.success();
  295. else
  296. return AdmResponse.success(equips);
  297. }
  298. /**
  299. * 查询当前系统下的设备
  300. *
  301. * datacenter 查询目标是SysEquip 没先查询系统,根据系统id查询系统和设备的关系,根据关系查询设备,拼接数据
  302. */
  303. @PostMapping("/sys-equip")
  304. public AdmResponse pageQuerySysEquip(@RequestBody AdmQueryCriteria request){
  305. //return SysEquipService.pageQuery(request, arrayListOf(SFilter.eq("projectId", SPageAdmContextUtil.toDmpContext().getHeader("projectId").toString())))
  306. request.setName(AdmSystem.OBJ_TYPE);
  307. QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request);
  308. queryCriteria.setSize(500l);
  309. List<ObjectNode> objectNodeList = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteria);
  310. if(CollUtil.isEmpty(objectNodeList)){
  311. return AdmResponse.success();
  312. }
  313. List<AdmSystem> admSystemList = JSONUtil.toList(objectNodeList.toString(), AdmSystem.class);
  314. Map<String, AdmSystem> admSystemMap = CollUtil.fieldValueMap(admSystemList, BaseEntity.PROP_ID);
  315. QueryCriteria queryCriteriaRelation = new QueryCriteria();
  316. queryCriteriaRelation.setPage(request.getPageNumber() == null ? 0 : request.getPageNumber()*1l);
  317. queryCriteriaRelation.setSize(request.getPageSize() == null ? 0 : request.getPageSize()*1l);
  318. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  319. criteria.put("relCode", "Sy2Eq");
  320. criteria.put("graphCode", "MechSubset");
  321. ArrayNode arrayNode = criteria.putObject("objTo").putArray("$in");
  322. admSystemMap.keySet().stream().forEach(id -> arrayNode.add(id));
  323. queryCriteriaRelation.setCriteria(criteria);
  324. List<ObjectRelation> relations = DigitalRelationFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteriaRelation);
  325. if(CollUtil.isEmpty(relations)){
  326. AdmResponse.success();
  327. }
  328. //objfrom = euipId
  329. Map<String, ObjectRelation> relationMap = CollUtil.fieldValueMap(relations,"objFrom");
  330. QueryCriteria queryCriteriaEqu = new QueryCriteria();
  331. ObjectNode criteriaEquip = JsonNodeFactory.instance.objectNode();
  332. criteriaEquip.put("objType", AdmEquipment.OBJ_TYPE);
  333. ArrayNode array = criteriaEquip.putObject("id").putArray("$in");
  334. relationMap.keySet().stream().forEach(id -> array.add(id));
  335. queryCriteriaEqu.setCriteria(criteriaEquip);
  336. List<ObjectNode> equips = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteriaEqu);
  337. List<AdmEquipment> equipsList = JSONUtil.toList(equips.toString(), AdmEquipment.class);
  338. Map<String, AdmEquipment> admEquipmentMap = CollUtil.fieldValueMap(equipsList, BaseEntity.PROP_ID);
  339. List<AdmSystem> admSystems = new ArrayList<>(relations.size());
  340. relationMap.keySet().stream().forEach(euipId -> {
  341. ObjectRelation relation = relationMap.get(euipId);
  342. AdmSystem admSystem = admSystemMap.get(relation.getObjTo());
  343. admSystem.setEquipId(euipId);
  344. admSystem.setEquipLocalName(admEquipmentMap.get(euipId).getLocalName());
  345. admSystems.add(admSystem);
  346. });
  347. AdmResponse admResponse = new AdmResponse();
  348. admResponse.setPageNumber(request.getPageNumber());
  349. admResponse.setPageSize(admSystems.size());
  350. admResponse.setContent(admSystems);
  351. admResponse.setResult(DmpResult.SUCCESS);
  352. return admResponse;
  353. }
  354. /**
  355. * 查询项目下的所有设备和部件的类型、以及类型名称
  356. */
  357. @GetMapping("/equip-compon-category")
  358. public AdmResponse equipORComponCategory(@QueryParam("projectId") String projectId){
  359. //return EquipORComponCategoryService.getEquipORComponCategory()
  360. RequestData requestData = new RequestData();
  361. if(StrUtil.isNotEmpty(projectId)){
  362. requestData.setProjectId(projectId);
  363. }
  364. requestData.setObjTypes(CollUtil.newHashSet(AdmEquipment.OBJ_TYPE, AdmComponent.OBJ_TYPE));
  365. List<Map<String, Object>> result = DigitalObjectSimpleFacade.queryDefineInfoByObjType(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmContextUtil.toDmpContext().getAppId(),null,requestData);
  366. if(CollUtil.isNotEmpty(result)){
  367. return AdmResponse.success(result);
  368. }else{
  369. return AdmResponse.success();
  370. }
  371. }
  372. /**
  373. * 批量处理设备关联资产、 查询接口
  374. * 查询项目下的设备或部件-根据项目、建筑、楼层、设备或部件分类、业务空间实例筛选设备 然后通过计算匹配资产
  375. * 查询条件中建筑id必须书写为buildingId,楼层id必须书写为floorId,spacrType物理世界定义的空间类型,spaceIdList业务空间实例id列表,category设备或部件类型
  376. * TODO 资产相关功能暂时不提供,之后根据业务进行需求处理
  377. */
  378. @PostMapping("/equip-category-property")
  379. public AdmResponse equipProperty(@QueryParam("category") String category, @RequestBody AdmQueryCriteria request, @RequestBody List<String> spaceIdList, @QueryParam("spacrType") String spacrType){
  380. //return EquipmentComService.equipProperty(category, request, spaceIdList, spacrType)
  381. return null;
  382. }
  383. /**
  384. * 批量添加设备和资产的关系
  385. * TODO 资产相关功能暂时不提供,之后根据业务进行需求处理
  386. */
  387. @PostMapping("/equip-r-property")
  388. public AdmResponse equipRelationshipProperty(@RequestBody AdmCreateRequest<AdmProperty> createRequest, @QueryParam("projectId") String projectId) {
  389. //return EquipmentComService.equipPro(request)
  390. return null;
  391. }
  392. /**
  393. * 修改设备的附件功能
  394. * {
  395. * "content":"{....}" EquipUpDateEnclosure 实体list
  396. * }
  397. */
  398. @PostMapping("/update")
  399. public AdmResponse equipUpDateEnclosure(@RequestBody ObjectNode equipUpDateEnclosureRequest) {
  400. //return EquipmentService.equipUpDateEnclosurs(equipUpDateEnclosureRequest)
  401. if(JSONUtil.isNull(equipUpDateEnclosureRequest)){
  402. return AdmResponse.failure(ResponseCode.A0400.getDesc()+",不能为空");
  403. }
  404. List<EquipUpDateEnclosure> equipUpDateEnclosure = JSONUtil.toList(equipUpDateEnclosureRequest.get("content").toString(), EquipUpDateEnclosure.class);
  405. if(CollUtil.isNotEmpty(equipUpDateEnclosure)){
  406. Map<String, EquipUpDateEnclosure> equipUpDateEnclosureMap = CollUtil.fieldValueMap(equipUpDateEnclosure, BaseEntity.PROP_ID);
  407. if(equipUpDateEnclosureMap.size() < equipUpDateEnclosure.size()) {
  408. return AdmResponse.failure("设备id不能为空");
  409. }
  410. //获取待更新的设备
  411. QueryCriteria queryCriteria = new QueryCriteria();
  412. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  413. criteria.put("objType", AdmEquipment.OBJ_TYPE);
  414. ArrayNode arrayNode = criteria.putObject("id").putArray("$in");
  415. equipUpDateEnclosureMap.keySet().stream().forEach(equipId -> arrayNode.add(equipId));
  416. queryCriteria.setCriteria(criteria);
  417. AdmResponse equips = equipmentService.doQuery(AdmContextUtil.toDmpContext(), queryCriteria, AdmEquipment.class);
  418. if(CollUtil.isEmpty(equips.getContent())){
  419. return AdmResponse.failure(ResponseCode.A0400.getDesc());
  420. }
  421. //将需要更新的数据放到待更新的设备中
  422. List<AdmEquipment> equipmentList = JSONUtil.toList(equips.getContent().toString(), AdmEquipment.class);
  423. //获取所有属性
  424. Map<String, Field> fieldMap = ReflectUtil.getFieldMap(EquipUpDateEnclosure.class);
  425. //对每个设备更新属性
  426. equipmentList.stream().forEach(admEquipment -> {
  427. fieldMap.keySet().forEach(fieldName -> {
  428. EquipUpDateEnclosure enclosure = equipUpDateEnclosureMap.get(admEquipment.getId());
  429. List<AdmTaskPic> newAttr = (List<AdmTaskPic>) ReflectUtil.getFieldValue(enclosure,fieldName);
  430. if(CollUtil.isNotEmpty(newAttr)){
  431. dealTaskFiles(admEquipment, fieldName, newAttr);
  432. }
  433. });
  434. });
  435. List<AdmEquipment> vos = equipmentService.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, equipmentList);
  436. return AdmResponse.success(vos);
  437. }else{
  438. return AdmResponse.failure(ResponseCode.A0400.getDesc());
  439. }
  440. }
  441. /**
  442. * 根据模型id查询待删除的设备数量
  443. [{
  444. * "modelId":"",
  445. * "count":""
  446. * }]
  447. */
  448. @PostMapping("/equip-del-com")
  449. public AdmResponse equipComDel(@RequestBody List<ObjectNode> equipComDelList){
  450. //return EquipmentService.equipComDels(equipComDelList)
  451. if(CollUtil.isEmpty(equipComDelList)){
  452. return AdmResponse.failure(ResponseCode.A0400.getCode());
  453. }
  454. QueryCriteria queryCriteriaEuip = new QueryCriteria();
  455. ObjectNode criteriaEquip = JsonNodeFactory.instance.objectNode();
  456. criteriaEquip.put("objType", AdmEquipment.OBJ_TYPE);
  457. criteriaEquip.put("taskState",-1);
  458. ArrayNode array = criteriaEquip.putObject("modelId").putArray("$in");
  459. equipComDelList.stream().forEach(nodeObj -> {
  460. if(StrUtil.isNotEmpty(nodeObj.get("modelId").textValue())) {
  461. array.add(nodeObj.get("modelId").textValue());
  462. }
  463. });
  464. queryCriteriaEuip.setCriteria(criteriaEquip);
  465. List<ObjectNode> equipList = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteriaEuip);
  466. if(CollUtil.isEmpty(equipList)){
  467. return AdmResponse.success(equipComDelList);
  468. }
  469. Map<String, ObjectNode> equipDelMap = new HashMap<>(equipComDelList.size());
  470. for (ObjectNode equipComDel : equipComDelList) {
  471. String modelIdObj = equipComDel.get("modelId").toString();
  472. equipDelMap.put(modelIdObj, equipComDel);
  473. }
  474. equipList.stream().forEach(euip -> {
  475. String modelIdEq = euip.get("modelId").textValue();
  476. if(equipDelMap.containsKey(modelIdEq)){
  477. Integer count = Integer.parseInt(equipDelMap.get(modelIdEq).get("count").textValue()) + 1;
  478. equipDelMap.get(modelIdEq).put("count", count);
  479. }
  480. });
  481. return AdmResponse.success(equipDelMap.values().stream().collect(Collectors.toList()));
  482. }
  483. /**
  484. * 根据模型id查询待补充的设备数量
  485. * [{
  486. * "modelId":"",
  487. * "count":""
  488. * }]
  489. */
  490. @PostMapping("/equip-supply")
  491. public AdmResponse equipPropertySupply(@RequestBody List<ObjectNode> equipComDelList){
  492. //return EquipmentService.equipPropertySupplys(equipComDelList)
  493. //
  494. if(CollUtil.isEmpty(equipComDelList)){
  495. return AdmResponse.failure(ResponseCode.A0400.getCode());
  496. }
  497. //1. 根据modelId查询楼层信息
  498. QueryCriteria queryCriteria = new QueryCriteria();
  499. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  500. criteria.put("objType", AdmFloor.OBJ_TYPE);
  501. ArrayNode arrayNode = criteria.putObject("modelId").putArray("$in");
  502. equipComDelList.stream().forEach(node -> {
  503. arrayNode.add(node.get("modelId").textValue());
  504. });
  505. queryCriteria.setCriteria(criteria);
  506. List<ObjectNode> floorList = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteria);
  507. if(CollUtil.isEmpty(floorList)){
  508. return AdmResponse.success();
  509. }
  510. List<AdmFloor> admFloorList = JSONUtil.toList(floorList.toString(), AdmFloor.class);
  511. Map<String, AdmFloor> admFloorMap = CollUtil.fieldValueMap(admFloorList, BaseEntity.PROP_ID);
  512. //2. 根据楼层信息 查询需要补充设备(bimId isnull,bimLocation not isnull,modelId isnull)数量
  513. QueryCriteria queryCriteriaEuip = new QueryCriteria();
  514. ObjectNode criteriaEquip = JsonNodeFactory.instance.objectNode();
  515. criteriaEquip.put("objType", AdmEquipment.OBJ_TYPE);
  516. ArrayNode array = criteriaEquip.putObject("floorId").putArray("$in");
  517. admFloorMap.keySet().stream().forEach(id -> array.add(id));
  518. JSONObject bimId = new JSONObject();
  519. bimId.put("$null", true);
  520. criteria.putPOJO("bimId", bimId);
  521. JSONObject bimLocation = new JSONObject();
  522. bimId.put("$null", false);
  523. criteriaEquip.putPOJO("bimLocation", bimLocation);
  524. JSONObject modelId = new JSONObject();
  525. modelId.put("$null", true);
  526. criteriaEquip.putPOJO("modelId", modelId);
  527. queryCriteriaEuip.setCriteria(criteriaEquip);
  528. List<ObjectNode> equipList = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteriaEuip);
  529. if(CollUtil.isEmpty(equipList)){
  530. return AdmResponse.success(equipComDelList);
  531. }
  532. equipList.stream().forEach(equip -> {
  533. String floolId = equip.get("floorId").textValue();
  534. if(admFloorMap.containsKey(floolId)){
  535. Integer count = Integer.parseInt(admFloorMap.get(floolId).getCount()) + 1;
  536. admFloorMap.get(floolId).setCount(count.toString());
  537. }
  538. });
  539. // 3 根据floorId,modelId 汇总
  540. Map<String, ObjectNode> equipDelMap = new HashMap<>(equipComDelList.size());
  541. for (ObjectNode equipComDel : equipComDelList) {
  542. String modelIdObj = equipComDel.get("modelId").toString();
  543. equipDelMap.put(modelIdObj, equipComDel);
  544. }
  545. admFloorMap.values().stream().forEach(floor -> {
  546. String modelIdFl = floor.getModelId();
  547. if(equipDelMap.containsKey(modelIdFl)){
  548. Integer count = Integer.parseInt(equipDelMap.get(modelIdFl).get("count").textValue()) + Integer.parseInt(floor.getCount());
  549. equipDelMap.get(modelIdFl).put("count", count);
  550. }
  551. });
  552. return AdmResponse.success(equipDelMap.values().stream().collect(Collectors.toList()));
  553. }
  554. /**
  555. * 模型质量报告 待删除的设备
  556. * 级联-任务(scanTaskBase)、资产(property)、设备类型(equipCategory),级联任务的时候需要设置条件(TaskState = 0 添加时间降序 取第一个值 )
  557. */
  558. @PostMapping("/equip-comm-del")
  559. public AdmResponse equipCommDel(@RequestBody AdmQueryCriteria request){
  560. //return EquipDelService.pageQuery(sQueryRequest,withFilterList)
  561. //e.task_state = '-1'::integer
  562. //AND NOT e.model_id IS NULL
  563. //TODO 关联 revit.model_floor revit.model_folder 展示模型相关内容
  564. request.setName(AdmEquipment.OBJ_TYPE);
  565. QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request);
  566. ObjectNode criteria = queryCriteria.getCriteria();
  567. JSONObject modelId = new JSONObject();
  568. modelId.put("$null", false);
  569. criteria.putPOJO("modelId", modelId);
  570. criteria.put("taskState","-1");
  571. queryCriteria.setCriteria(criteria);
  572. AdmResponse equipRes = equipmentService.doQuery(AdmContextUtil.toDmpContext(), queryCriteria, AdmEquipment.class);
  573. return equipRes;
  574. }
  575. /**
  576. * 模型质量报告 待补充的设备
  577. * 级联-设备类型(equipFamily)
  578. */
  579. @PostMapping("/property-equip-supp")
  580. public AdmResponse propertyEquip(@RequestBody AdmQueryCriteria request){
  581. //return EquipmentService.equipPropertySupp(sQueryRequest)
  582. //equipment.bim_id IS NULL
  583. // AND equipment.model_id IS NULL
  584. // AND NOT equipment.bim_location IS NULL;
  585. AdmQueryCriteria admQueryCriteria = request;
  586. StringBuilder filters = new StringBuilder();
  587. filters.append("floorId startwith 'Eq'");
  588. filters.append(";buildingId startwith 'Bd'");
  589. filters.append(";bimId isnull");
  590. filters.append(";modelId isnull");
  591. admQueryCriteria.setFilters(filters.toString());
  592. admQueryCriteria.setName(AdmEquipment.OBJ_TYPE);
  593. QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteria);
  594. ObjectNode criteria = queryCriteria.getCriteria();
  595. JSONObject bimLocation = new JSONObject();
  596. bimLocation.put("$null", false);
  597. criteria.putPOJO("bimLocation", bimLocation);
  598. queryCriteria.setCriteria(criteria);
  599. AdmResponse equipRes = equipmentService.doQuery(AdmContextUtil.toDmpContext(), queryCriteria, AdmEquipment.class);
  600. if(CollUtil.isNotEmpty(equipRes.getContent())){
  601. List<AdmEquipment> admEquipments = JSONUtil.toList(equipRes.getContent().toString(), AdmEquipment.class);
  602. Map<String, AdmEquipment> admEquipmentMap = CollUtil.fieldValueMap(admEquipments, BaseEntity.PROP_ID);
  603. if(CollUtil.isEmpty(request.getCascade())){
  604. List<AdmQueryCriteria> cascade = new ArrayList<>();
  605. AdmQueryCriteria admQueryCriteriaBd = new AdmQueryCriteria();
  606. admQueryCriteriaBd.setName(AdmBuilding.OBJ_TYPE);
  607. cascade.add(admQueryCriteriaBd);
  608. AdmQueryCriteria admQueryCriteriaFl = new AdmQueryCriteria();
  609. admQueryCriteriaFl.setName(AdmFloor.OBJ_TYPE);
  610. cascade.add(admQueryCriteriaFl);
  611. request.setCascade(cascade);
  612. request.setName(AdmEquipment.OBJ_TYPE);
  613. }
  614. ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode();
  615. admEquipmentMap.keySet().stream().forEach(id -> arrayNode.add(id));
  616. String filter = "";
  617. if(StrUtil.isNotEmpty(request.getFilters())){
  618. filter = request.getFilters();
  619. }
  620. filter = filter + ";id in "+arrayNode.toString();
  621. request.setFilters(filter);
  622. AdmResponse admResponse = equipmentService.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
  623. if(CollUtil.isNotEmpty(admResponse.getContent())){
  624. //处理数据
  625. List<ObjectNode> objectNodeList = (List<ObjectNode>) admResponse.getContent();
  626. objectNodeList.stream().forEach(equip ->{
  627. JsonNode building = equip.get("building");
  628. JsonNode floor = equip.get("floor");
  629. if(!JSONUtil.isNull(building)){
  630. equip.put("buildingName", building.get("localName").textValue());
  631. }
  632. if(!JSONUtil.isNull(floor)){
  633. equip.put("floorName", floor.get("localName").textValue());
  634. equip.put("modelId", floor.get("modelId").textValue());
  635. }
  636. });
  637. }
  638. return admResponse;
  639. }else{
  640. return AdmResponse.success();
  641. }
  642. /** sql
  643. * SELECT equipment.id,
  644. * equipment.name,
  645. * equipment.local_id,
  646. * equipment.local_name,
  647. * equipment.bim_id,
  648. * equipment.bim_location,
  649. * equipment.floor_id,
  650. * equipment.building_id,
  651. * equipment.cad_id,
  652. * equipment.project_id,
  653. * equipment.find_people,
  654. * equipment.class_code,
  655. * equipment.infos,
  656. * JSON_EXTRACT(floor.infos, '$.modeId') as model_id,
  657. * floor.local_name as floor_name,
  658. * (SELECT building.local_name
  659. * FROM dt_object building
  660. * WHERE building.id = JSON_EXTRACT(equipment.infos, '$.buildingId') and building.obj_type = 'building') AS building_name,
  661. *
  662. * (SELECT def_class.name
  663. * FROM dt_define_type def_class
  664. * WHERE def_class.code = equipment.class_code
  665. * LIMIT 1) AS code_name
  666. *
  667. * from ( SELECT equipment.id,
  668. * equipment.name,
  669. * equipment.local_id,
  670. * equipment.local_name,
  671. * equipment.class_code,
  672. * JSON_EXTRACT(equipment.infos, '$.bimId') bim_id,
  673. * JSON_EXTRACT(equipment.infos, '$.bimLocation') bim_location,
  674. * JSON_EXTRACT(equipment.infos, '$.floorId') floor_id,
  675. * JSON_EXTRACT(equipment.infos, '$.buildingId') building_id,
  676. * JSON_EXTRACT(equipment.infos, '$.cadId') cad_id,
  677. * equipment.project_id,
  678. * JSON_EXTRACT(equipment.infos, '$.findPeople') find_people,
  679. * equipment.infos
  680. * FROM dt_object equipment
  681. * WHERE equipment.obj_type='equipment'
  682. * AND JSON_EXTRACT(equipment.infos, '$.bimId') IS NULL
  683. * AND JSON_EXTRACT(equipment.infos, '$.modeId') IS NULL
  684. * AND JSON_EXTRACT(equipment.infos, '$.buildingId') IS NOT NULL
  685. * AND JSON_EXTRACT(equipment.infos, '$.floorId') IS NOT NULL
  686. * AND JSON_EXTRACT(equipment.infos, '$.bimLocation') IS NOT NULL
  687. * ) equipment left join dt_object floor on fl
  688. */
  689. }
  690. /**
  691. * 设备信息点
  692. * 统计设备信息点与总数据占比
  693. */
  694. @PostMapping("/info-point")
  695. public AdmResponse infoPoint(@QueryParam("projectId") String projectId) {
  696. //return customSqlService.infoPoints()
  697. JSONObject gatherInfoPoint = calInfoPointByObjType(AdmEquipment.OBJ_TYPE, false, false);
  698. JSONObject infoPoint = new JSONObject();
  699. infoPoint.put("dynamicInfoPoint",gatherInfoPoint.getString("gatherDynamicInfoPointCounts"));
  700. infoPoint.put("staticInfoPoint",gatherInfoPoint.getString("gatherStaticInfoPointCounts"));
  701. return AdmResponse.success(CollUtil.newArrayList(infoPoint));
  702. }
  703. /**
  704. * 设备已采集信息点
  705. * 统计设备信息点与需采集数据占比
  706. */
  707. @PostMapping("/gather-info-point")
  708. public AdmResponse gatherInfoPoint(@QueryParam("projectId") String projectId) {
  709. //return customSqlService.gatherInfoPoints()
  710. if(StrUtil.isEmpty(projectId)){
  711. return AdmResponse.failure(ResponseCode.A0400.getCode());
  712. }
  713. JSONObject gatherInfoPoint = calInfoPointByObjType(AdmEquipment.OBJ_TYPE, true, true);
  714. return AdmResponse.success(CollUtil.newArrayList(gatherInfoPoint));
  715. }
  716. /**
  717. * 统计系统信息点与需采集数据占比
  718. */
  719. @PostMapping("/system-info-point")
  720. public AdmResponse systemInfoPoin(@QueryParam("projectId") String projectId) {
  721. if(StrUtil.isEmpty(projectId)){
  722. return AdmResponse.failure(ResponseCode.A0400.getCode());
  723. }
  724. JSONObject gatherInfoPoint = calInfoPointByObjType(AdmSystem.OBJ_TYPE,true, true);
  725. return AdmResponse.success(CollUtil.newArrayList(gatherInfoPoint));
  726. }
  727. /**
  728. * 台账中待删除的对象 数量统计
  729. */
  730. @PostMapping("/del-equip-comm-pro")
  731. public AdmResponse deleteObj(@QueryParam("projectId") String projectId){
  732. QueryCriteria queryCriteria = new QueryCriteria();
  733. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  734. criteria.put("taskState", -1);
  735. criteria.put("objType","['equipment','component']");
  736. queryCriteria.setCriteria(criteria);
  737. queryCriteria.setOnlyCount(true);
  738. List<ObjectNode> euipCom = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteria);
  739. if(CollUtil.isNotEmpty(euipCom)){
  740. return AdmResponse.success(euipCom);
  741. }else{
  742. return AdmResponse.success();
  743. }
  744. }
  745. /**
  746. * 项目下的所有设备类型以及名称
  747. *
  748. * @return 返回对象列表
  749. */
  750. @PostMapping("/type")
  751. public AdmResponse equipType(@QueryParam("projectId") String projectId){
  752. RequestData requestData = new RequestData();
  753. if(StrUtil.isNotEmpty(projectId)){
  754. requestData.setProjectId(projectId);
  755. }
  756. requestData.setObjType(AdmEquipment.OBJ_TYPE);
  757. List<Map<String, Object>> result = DigitalObjectSimpleFacade.queryDefineInfoByObjType(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmContextUtil.toDmpContext().getAppId(),null,requestData);
  758. if(CollUtil.isNotEmpty(result)){
  759. return AdmResponse.success(result);
  760. }else{
  761. return AdmResponse.success();
  762. }
  763. }
  764. /**
  765. * 查询系统-设备类树
  766. * @return
  767. * @throws Exception
  768. */
  769. @GetMapping("/type/tree")
  770. public AdmResponse querySystemEquipCategory() throws Exception {
  771. // 组装上下文条件
  772. AdmDict request = new AdmDict();
  773. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  774. request.setType(AdmDictCategoryEnum.SYSTEM_EQUIP.getValue());
  775. return dictService.queryCategory(context,request,AdmObjectType.class);
  776. }
  777. /**
  778. * 计算动态、静态信息点
  779. */
  780. private Map<String, Integer> calculate(List<ObjectInfoDefine> dynamicInfoPointCodes, List<ObjectInfoDefine> staticInfoPointCodes, List<ObjectNode> objectNodeList, Integer num) {
  781. Map<String, Integer> hashMap = new HashMap<String, Integer>();
  782. int dynamicInfoPoint = 0;
  783. int staticInfoPoint = 0;
  784. int customInfoPoint=0;
  785. Iterator<ObjectInfoDefine> iterator1 = staticInfoPointCodes.iterator();
  786. for (ObjectNode objectNode : objectNodeList) {
  787. while (iterator1.hasNext()) {
  788. ObjectInfoDefine infoDefine = iterator1.next();
  789. if (objectNode.get("id") != null && "id" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) {
  790. staticInfoPoint++;
  791. iterator1.remove();
  792. }
  793. if (objectNode.get("name") != null && "name" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) {
  794. staticInfoPoint++;
  795. iterator1.remove();
  796. }
  797. if (objectNode.get("localId") != null && "localId" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) {
  798. staticInfoPoint++;
  799. iterator1.remove();
  800. }
  801. if (objectNode.get("localName") != null && "localName" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) {
  802. staticInfoPoint++;
  803. iterator1.remove();
  804. }
  805. if (objectNode.get("qrCode") != null && "qRCode" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) {
  806. staticInfoPoint++;
  807. iterator1.remove();
  808. }
  809. if (objectNode.get("cADID") != null && "cADID" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode() && num==0) {
  810. staticInfoPoint++;
  811. iterator1.remove();
  812. }
  813. if (objectNode.get("bimId") != null && "bimId" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode() && num==0) {
  814. staticInfoPoint++;
  815. iterator1.remove();
  816. }
  817. if (objectNode.get("bimLocation") != null && "bimLocation" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) {
  818. staticInfoPoint++;
  819. iterator1.remove();
  820. }
  821. if (objectNode.get("equipSerial") != null && "equipSerial" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) {
  822. staticInfoPoint++;
  823. iterator1.remove();
  824. }
  825. if (objectNode.get("bimFamilyName") != null && "bimFamilyName" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) {
  826. staticInfoPoint++;
  827. iterator1.remove();
  828. }
  829. if (objectNode.get("bimFamilySymbol") != null && "bimFamilySymbol" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) {
  830. staticInfoPoint++;
  831. iterator1.remove();
  832. }
  833. }
  834. }
  835. for (ObjectNode objectNode : objectNodeList) {
  836. if (objectNode.get("infos") != null) {
  837. Map<String,Object> dynamic = calculateInfoPoints(objectNode.get("infos").toString(), objectNode.get("classCode").textValue().toString(), dynamicInfoPointCodes);
  838. Map<String,Object> staticMap = calculateInfoPoints(objectNode.get("infos").toString(), objectNode.get("classCode").textValue().toString(), staticInfoPointCodes);
  839. dynamicInfoPoint += Integer.parseInt(dynamic.get("counts").toString());
  840. staticInfoPoint += Integer.parseInt(staticMap.get("counts").toString());
  841. dynamicInfoPointCodes.remove(dynamic.get("next"));
  842. staticInfoPointCodes.remove(staticMap.get("next"));
  843. }
  844. }
  845. hashMap.put("dynamicInfoPoint", dynamicInfoPoint);
  846. hashMap.put("staticInfoPoint", staticInfoPoint);
  847. hashMap.put("customInfoPoint", customInfoPoint);
  848. return hashMap;
  849. }
  850. /**
  851. * 计算信息点
  852. *
  853. */
  854. private Map<String,Object> calculateInfoPoints(String str, String type, List<ObjectInfoDefine> infoPointCodes) {
  855. int counts = 0;
  856. Map<String,Object> hashMap = new HashMap<String,Object>();
  857. Iterator<ObjectInfoDefine> iterator = infoPointCodes.iterator();
  858. while (iterator.hasNext()){
  859. ObjectInfoDefine nextInfo = iterator.next();
  860. if(str.contains(nextInfo.getCode()) && type==nextInfo.getClassCode()){
  861. counts ++;
  862. hashMap.put("next", nextInfo);
  863. iterator.remove();
  864. }
  865. }
  866. hashMap.put("counts", counts);
  867. return hashMap;
  868. }
  869. private JSONObject calInfoPointByObjType(String objType, Boolean visible, Boolean getInfoCounts){
  870. //1 查询项目下所有现有的系统
  871. AdmQueryCriteria admQueryCriteriaObj = new AdmQueryCriteria();
  872. if(objType.equals(AdmEquipment.OBJ_TYPE)){
  873. admQueryCriteriaObj.setProjection(Arrays.asList("id","name","localId","localName","cadId","bimId","bimLocation","infos","classCode","equipSerial","bimFamilyName","bimFamilySymbol"));
  874. }else{
  875. admQueryCriteriaObj.setProjection(Arrays.asList("id","name","localId","localName","cadId","bimId","infos","classCode"));
  876. }
  877. admQueryCriteriaObj.setName(objType);
  878. QueryCriteria queryCriteriaSys = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteriaObj);
  879. List<ObjectNode> admObjList = DigitalObjectFacade.query(groupCode, AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteriaSys);
  880. //2 获取动态 静态 信息点
  881. // 2.1 根据objType获取定义
  882. Set<String> classCodeSet = new HashSet<>();
  883. if(AdmSystem.OBJ_TYPE.equals(objType)){
  884. QueryCriteria queryCriteriaType = new QueryCriteria();
  885. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  886. criteria.put("objType", objType);
  887. queryCriteriaType.setCriteria(criteria);
  888. AdmResponse admResponseType = dictService.doQueryObjectType(AdmContextUtil.toDmpContext(), queryCriteriaType, AdmObjectType.class);
  889. if(CollUtil.isEmpty(admResponseType.getContent())){
  890. return null;
  891. }
  892. List<AdmObjectType> admObjectTypes = (List<AdmObjectType>) admResponseType.getContent();
  893. Map<String, AdmObjectType> admObjectTypeMap = CollUtil.fieldValueMap(admObjectTypes, "code");
  894. classCodeSet = admObjectTypeMap.keySet();
  895. }else {
  896. List<AdmEquipment> equipmentList = JSONUtil.toList(admObjList.toString(), AdmEquipment.class);
  897. Map<String, AdmEquipment> admObjectTypeMap = CollUtil.fieldValueMap(equipmentList, "code");
  898. classCodeSet = admObjectTypeMap.keySet();
  899. }
  900. JSONObject gatherInfoPoint = new JSONObject();
  901. if(CollUtil.isEmpty(admObjList)){
  902. gatherInfoPoint.put("gatherInfoPointCounts", 0);
  903. gatherInfoPoint.put("gatherCustomInfoPointCounts",0);
  904. gatherInfoPoint.put("gatherDynamicInfoPointCounts",0);
  905. gatherInfoPoint.put("gatherStaticInfoPointCounts",0);
  906. } else {
  907. // 2.2 根据定义获取信息点
  908. //查询当前实例所有信息点总数
  909. long controlInfoCounts = 0l;
  910. QueryCriteria queryCriteria = new QueryCriteria();
  911. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  912. criteria = JsonNodeFactory.instance.objectNode();
  913. ArrayNode arrayNode = criteria.putObject("classCode").putArray("$in");
  914. classCodeSet.stream().forEach(classCode -> arrayNode.add(classCode));
  915. criteria.put("type", "commo");
  916. if(getInfoCounts){
  917. criteria.put("valid","['0','1']");
  918. queryCriteria.setCriteria(criteria);
  919. queryCriteria.setOnlyCount(true);
  920. List<ObjectInfoDefine> totalInfo = DigitalObjectInfoFacade.query(groupCode, AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteria);
  921. controlInfoCounts = totalInfo.size();
  922. criteria.remove("valid");
  923. }
  924. //静态信息点
  925. criteria.put("category","STATIC");
  926. if(visible){
  927. criteria.put("valid", "1");
  928. }else{
  929. criteria.put("valid","['0','1']");
  930. }
  931. queryCriteria.setCriteria(criteria);
  932. List<ObjectInfoDefine> staticInfoCode = DigitalObjectInfoFacade.query(groupCode, AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteria);
  933. criteria.remove("category");
  934. //动态信息点
  935. JSONObject category = new JSONObject();
  936. category.put("$ne","STATIC");
  937. criteria.putPOJO("category", category);
  938. queryCriteria.setCriteria(criteria);
  939. List<ObjectInfoDefine> dynamicInfoCode = DigitalObjectInfoFacade.query(groupCode, AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteria);
  940. //4 计算已采集的和需要采集的信息点占比
  941. //return customSqlService.systemInfoPoins()
  942. Map<String, Integer> hashMap = calculate(dynamicInfoCode, staticInfoCode, admObjList, 1);
  943. gatherInfoPoint.put("gatherCustomInfoPointCounts",hashMap.get("customInfoPoint"));
  944. gatherInfoPoint.put("gatherDynamicInfoPointCounts",hashMap.get("dynamicInfoPoint"));
  945. gatherInfoPoint.put("gatherStaticInfoPointCounts",hashMap.get("staticInfoPoint"));
  946. gatherInfoPoint.put("gatherInfoPointCounts", controlInfoCounts);
  947. }
  948. return gatherInfoPoint;
  949. }
  950. /**
  951. * 处理设备属性文件 -> 设备的信息点
  952. * @param equip
  953. * @param attribute
  954. */
  955. private void dealTaskFiles(AdmEquipment equip, String attribute, List<AdmTaskPic> upTarget){
  956. Map<String, Object> infos = equip.getInfos();
  957. boolean containsKey1 = infos.containsKey(attribute);
  958. if (containsKey1) {
  959. if (infos.get(attribute) != null && StrUtil.isNotEmpty(infos.get(attribute).toString())){
  960. List<AdmTaskPic> list = JSONUtil.toList(infos.get(attribute).toString(), AdmTaskPic.class);
  961. list.addAll(upTarget);
  962. infos.put(attribute, list);
  963. }else {
  964. infos.put(attribute, upTarget);
  965. }
  966. } else {
  967. infos.put(attribute, upTarget);
  968. }
  969. }
  970. }