AdmReportEquipController.java 50 KB

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