AdmReportEquipController.java 50 KB

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