package com.persagy.proxy.adm.controller; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; import com.persagy.dmp.basic.dto.RequestData; import com.persagy.dmp.basic.model.QueryCriteria; import com.persagy.dmp.common.constant.ResponseCode; import com.persagy.dmp.common.model.entity.BaseEntity; import com.persagy.dmp.define.client.DigitalObjectInfoFacade; import com.persagy.dmp.define.entity.ObjectInfoDefine; import com.persagy.dmp.digital.client.DigitalObjectFacade; import com.persagy.dmp.digital.client.DigitalRelationFacade; import com.persagy.dmp.digital.entity.ObjectRelation; import com.persagy.dmp.simple.client.DigitalObjectSimpleFacade; import com.persagy.proxy.adm.constant.AdmCommonConstant; import com.persagy.proxy.adm.constant.enums.AdmDictCategoryEnum; import com.persagy.proxy.adm.model.*; import com.persagy.proxy.adm.model.equip.EquipUpDateEnclosure; import com.persagy.proxy.adm.request.AdmCreateRequest; import com.persagy.proxy.adm.request.AdmQueryCriteria; import com.persagy.proxy.adm.request.AdmResponse; import com.persagy.proxy.adm.service.IAdmComponentService; import com.persagy.proxy.adm.service.IAdmDictService; import com.persagy.proxy.adm.service.IAdmEquipmentService; import com.persagy.proxy.adm.service.IAdmSystemService; import com.persagy.proxy.adm.utils.AdmContextUtil; import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper; import com.persagy.proxy.common.entity.DmpResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import javax.ws.rs.QueryParam; import java.lang.reflect.Field; import java.util.*; import java.util.stream.Collectors; /** * 设备报表API * @author lvxy * @date 2021/9/18 */ @RestController @RequestMapping("/equip-query") public class AdmReportEquipController { @Value("${middleware.group.code}") private String groupCode; @Autowired private IAdmDictService dictService; @Autowired private IAdmEquipmentService equipmentService; @Autowired private IAdmComponentService componentService; @Autowired private IAdmSystemService systemService; /** * 查询设备信息 关联的部件 资产信息 * 查询设备关联资产部件数量 * * * @param request * @return * @throws Exception */ @PostMapping("/equip-components") public AdmResponse getEquipAssetComponents(@RequestBody AdmQueryCriteria request) throws Exception { //查询设备 request.setName(AdmEquipment.OBJ_TYPE); List cascade = new ArrayList<>(); //查询设备关联的部件 AdmQueryCriteria cascadeCom = new AdmQueryCriteria(); cascadeCom.setName("component"); cascade.add(cascadeCom); //查询设备关联的系统 AdmQueryCriteria cascadeSys = new AdmQueryCriteria(); cascadeSys.setName("linkSystem"); cascade.add(cascadeSys); request.setCascade(cascade); AdmResponse admResponse = equipmentService.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class); List equipmentList = (List) admResponse.getContent(); if(CollUtil.isNotEmpty(equipmentList)){ equipmentList.stream().forEach(equip -> { if (CollUtil.isNotEmpty(equip.getComponent())) { equip.setCount(equip.getComponent().size()); equip.setComponent(null); } else { equip.setCount(0); } }); //查询设备的类型信息,取list中的第一个数据 AdmEquipment admEquipment = equipmentList.get(0); QueryCriteria defineCriteria = new QueryCriteria(); ObjectNode criteria = JsonNodeFactory.instance.objectNode(); criteria.put("code", admEquipment.getClassCode()); defineCriteria.setCriteria(criteria); AdmResponse defRes = dictService.doQueryObjectType(AdmContextUtil.toDmpContext(), defineCriteria, AdmObjectType.class); if (CollUtil.isNotEmpty(defRes.getContent())) { List componentCategory = (List) defRes.getContent(); admEquipment.setComponentCategory(componentCategory); equipmentList.set(0, admEquipment); } }else{ equipmentList = new ArrayList<>(); } return AdmResponse.success(equipmentList); } /** * 查询当前设备类型下的部件分类以及数量 * * @param request 查询信息条件 * @return 查询结果 */ @PostMapping("/components-count") public AdmResponse getEquipComponentsCount(@RequestBody AdmQueryCriteria request){ QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request); ObjectNode criteria = queryCriteria.getCriteria(); if(JSONUtil.isNull(criteria)){ return AdmResponse.failure("请求参数错误"); } JsonNode euipId = criteria.get("id"); RequestData requestData = new RequestData(); requestData.setEquipmentId(String.valueOf(euipId)); List result = DigitalObjectSimpleFacade.queryComponentsCountByEquipId(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmContextUtil.toDmpContext().getAppId(),null,requestData); if(CollUtil.isNotEmpty(result)){ return AdmResponse.success(result); }else{ return AdmResponse.success(); } } /** * 查詢部件关联的资产 * 资产相关暂未支持 * * @param request 查询信息条件 * @return 查询结果 */ @PostMapping("/components-property") public AdmResponse getComponentProperty(@RequestBody AdmQueryCriteria request){ request.setName(AdmComponent.OBJ_TYPE); return componentService.doQuery(AdmContextUtil.toDmpContext(), request, AdmComponent.class); } /** *查询当前设备类型的允许下所有部件类型,设备下的部件对应数量 * * @param id 设备id * @param category 分类 */ @GetMapping("/equip-compon") public AdmResponse getEquipCompon(@QueryParam("id") String id, @QueryParam("category") String category){ //return rEquipComponService.getEquipCompon(id,category) RequestData requestData = new RequestData(); if(StrUtil.isNotEmpty(id)){ requestData.setEquipmentId(id); } if(StrUtil.isNotEmpty(category)){ requestData.setClassCode(category); } List result = DigitalObjectSimpleFacade.queryEquipComponentsByProjectId(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmContextUtil.toDmpContext().getAppId(),null, requestData); if(CollUtil.isNotEmpty(result)){ return AdmResponse.success(result); }else{ return AdmResponse.success(); } } /** * TODO * 根据设备批量创建资产 * 资产相关暂未支持 */ @PostMapping("/creat-propertys") public AdmResponse batchCreation(@RequestBody AdmCreateRequest createRequest, @QueryParam("projectId") String projectId) { //return EquipmentService.batchCreationProperty(request) return null; } /** * 根据条件查询统计数量 查询设备或部件 * 例子: 根据设备类型或部件类型查询(\"Filters\": \"category ='SISU'\")," + * "根据设备类型和建筑查询(\"Filters\": \"category ='FASE';buildingId = '建筑id'\")," + * "根据设备类型和建筑楼层查询(\"Filters\": \"category ='FASE';buildingId = '建筑id';floorId = '楼层id'\")" */ @PostMapping("/count") public AdmResponse count(@RequestBody AdmQueryCriteria request) { QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request); ObjectNode criteria = JsonNodeFactory.instance.objectNode(); if(StrUtil.isNotEmpty(request.getFilters()) && request.getFilters().contains("category")){ criteria.put("classCode", criteria.get("category").textValue()); criteria.remove("category"); } queryCriteria.setCriteria(criteria); queryCriteria.setOnlyCount(true); List euipCom = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteria); if(CollUtil.isNotEmpty(euipCom)){ return AdmResponse.success(euipCom); }else{ return AdmResponse.success(); } } /** * 查询设备或部件 * * 例子: 根据设备类型或部件类型查询(\"Filters\": \"category ='SISU'\")," + * "根据设备类型和建筑查询(\"Filters\": \"category ='FASE';buildingId = '建筑id'\")," + * "根据设备类型和建筑楼层查询(\"Filters\": \"category ='FASE';buildingId = '建筑id';floorId = '楼层id'\")" */ @PostMapping("/pagequery") public AdmResponse pageQuery(@RequestBody AdmQueryCriteria request) { QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request); ObjectNode criteria = JsonNodeFactory.instance.objectNode(); queryCriteria.setCriteria(criteria); if(StrUtil.isNotEmpty(request.getFilters()) && request.getFilters().contains("category")){ criteria.put("classCode", criteria.get("category").textValue()); criteria.remove("category"); } List euipCom = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteria); if(CollUtil.isNotEmpty(euipCom)){ return AdmResponse.success(euipCom); }else{ return AdmResponse.success(); } } /** * 跟维新确认过 暂未使用 * * 根据建筑, 楼层, 业务空间类型, 业务空间id 查询设备 * * description = "例子: 根据设备类型或部件类型查询(\"Filters\": \"category ='SISU'\")," + * "根据设备类型和建筑查询(\"Filters\": \"category ='FASE';buildingId = '建筑id'\")," + * "根据设备类型和建筑楼层查询(\"Filters\": \"category ='FASE';buildingId = '建筑id';floorId = '楼层id'\")" + * "所属业务空间类型填在ZoneType字段, 所属业务空间id填在ZoneId字段" + * "如果是查询不属于任何业务空间的对象, 设置notInZone = true" */ @PostMapping("/zone-query") public AdmResponse zoneQuery(@RequestBody AdmZoneEquipQueryRequest request) { request.setName(AdmEquipment.OBJ_TYPE); if(StrUtil.isAllEmpty(request.getZoneType(),request.getZoneId())){ return pageQuery(request); }else{ } return null; } /** * 跟维新确认过 暂未使用 * 根据建筑, 楼层, 业务空间类型, 业务空间id 查询部件 * * 根据建筑, 楼层, 业务空间类型, 业务空间id查询部件", description = "例子: 根据设备类型或部件类型查询(\"Filters\": \"category ='SISU'\")," + * "根据设备类型和建筑查询(\"Filters\": \"category ='FASE';buildingId = '建筑id'\")," + * "根据设备类型和建筑楼层查询(\"Filters\": \"category ='FASE';buildingId = '建筑id';floorId = '楼层id'\")" + * "所属业务空间类型填在ZoneType字段, 所属业务空间id填在ZoneId字段" + * "如果是查询不属于任何业务空间的对象, 设置notInZone = true" */ @PostMapping("/zone-component-query") public AdmResponse zoneComponentQuery(@RequestBody AdmZoneEquipQueryRequest request) { if(StrUtil.isAllEmpty(request.getZoneType(),request.getZoneId())){ request.setName(AdmComponent.OBJ_TYPE); return pageQuery(request); } return null; } /** * 批量创建设备同时创建资产、创建设备和系统的关系 * */ @PostMapping("/creat-equip-pro") public AdmResponse create(@RequestBody AdmCreateRequest createRequest){ //return EquipmentProSyService.createList(request) List vos = CollUtil.newArrayList(createRequest.getContent()); vos = equipmentService.doInsertEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos); return AdmResponse.success(vos); } /** * 查询不在当前系统下的设备 */ @PostMapping("/equip-sys") public AdmResponse pageQueryEquipSys(@RequestBody AdmQueryCriteria request,@QueryParam("sysId") String sysId){ //return EquipmentService.queryBeforeEquipSy(sysId,request) QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request); ObjectNode criteriaEquip = JsonNodeFactory.instance.objectNode(); criteriaEquip.put("objType", AdmEquipment.OBJ_TYPE); JSONObject relationTo = new JSONObject(); relationTo.put("relCode", "Sy2Eq"); relationTo.put("graphCode", "MechSubset"); JSONObject objFrom = new JSONObject(); objFrom.put("$ne",sysId); relationTo.put("objFrom", objFrom); criteriaEquip.putPOJO("relationTo",relationTo); queryCriteria.setCriteria(criteriaEquip); List equips = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteria); return AdmResponse.success(equips); } /** * 查询当前系统下的设备 * * datacenter 查询目标是SysEquip 没先查询系统,根据系统id查询系统和设备的关系,根据关系查询设备,拼接数据 */ @PostMapping("/sys-equip") public AdmResponse pageQuerySysEquip(@RequestBody AdmQueryCriteria request){ //return SysEquipService.pageQuery(request, arrayListOf(SFilter.eq("projectId", SPageAdmContextUtil.toDmpContext().getHeader("projectId").toString()))) request.setName(AdmSystem.OBJ_TYPE); QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request); queryCriteria.setSize(500L); List objectNodeList = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteria); if(CollUtil.isEmpty(objectNodeList)){ return AdmResponse.success(); } List admSystemList = JSONUtil.toList(objectNodeList.toString(), AdmSystem.class); Map admSystemMap = CollUtil.fieldValueMap(admSystemList, BaseEntity.PROP_ID); QueryCriteria queryCriteriaRelation = new QueryCriteria(); queryCriteriaRelation.setPage(request.getPageNumber() == null ? 0 : request.getPageNumber()*1L); queryCriteriaRelation.setSize(request.getPageSize() == null ? 0 : request.getPageSize()*1L); ObjectNode criteria = JsonNodeFactory.instance.objectNode(); criteria.put("relCode", "Sy2Eq"); criteria.put("graphCode", "MechSubset"); ArrayNode arrayNode = criteria.putObject("objTo").putArray("$in"); admSystemMap.keySet().stream().forEach(id -> arrayNode.add(id)); queryCriteriaRelation.setCriteria(criteria); List relations = DigitalRelationFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteriaRelation); if(CollUtil.isEmpty(relations)){ AdmResponse.success(); } //objfrom = euipId Map relationMap = CollUtil.fieldValueMap(relations,"objFrom"); QueryCriteria queryCriteriaEqu = new QueryCriteria(); ObjectNode criteriaEquip = JsonNodeFactory.instance.objectNode(); criteriaEquip.put("objType", AdmEquipment.OBJ_TYPE); ArrayNode array = criteriaEquip.putObject("id").putArray("$in"); relationMap.keySet().stream().forEach(id -> array.add(id)); queryCriteriaEqu.setCriteria(criteriaEquip); List equips = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteriaEqu); List equipsList = JSONUtil.toList(equips.toString(), AdmEquipment.class); Map admEquipmentMap = CollUtil.fieldValueMap(equipsList, BaseEntity.PROP_ID); List admSystems = new ArrayList<>(relations.size()); relationMap.keySet().stream().forEach(euipId -> { ObjectRelation relation = relationMap.get(euipId); AdmSystem admSystem = admSystemMap.get(relation.getObjTo()); admSystem.setEquipId(euipId); admSystem.setEquipLocalName(admEquipmentMap.get(euipId).getLocalName()); admSystems.add(admSystem); }); AdmResponse admResponse = new AdmResponse(); admResponse.setPageNumber(request.getPageNumber()); admResponse.setPageSize(admSystems.size()); admResponse.setContent(admSystems); admResponse.setResult(DmpResult.SUCCESS); return admResponse; } /** * 查询项目下的所有设备和部件的类型、以及类型名称 */ @GetMapping("/equip-compon-category") public AdmResponse equipORComponCategory(@QueryParam("projectId") String projectId){ //return EquipORComponCategoryService.getEquipORComponCategory() RequestData requestData = new RequestData(); if(StrUtil.isNotEmpty(projectId)){ requestData.setProjectId(projectId); } requestData.setObjTypes(CollUtil.newHashSet(AdmEquipment.OBJ_TYPE, AdmComponent.OBJ_TYPE)); List> result = DigitalObjectSimpleFacade.queryDefineInfoByObjType(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmContextUtil.toDmpContext().getAppId(),null,requestData); if(CollUtil.isNotEmpty(result)){ return AdmResponse.success(result); }else{ return AdmResponse.success(); } } /** * 批量处理设备关联资产、 查询接口 * 查询项目下的设备或部件-根据项目、建筑、楼层、设备或部件分类、业务空间实例筛选设备 然后通过计算匹配资产 * 查询条件中建筑id必须书写为buildingId,楼层id必须书写为floorId,spacrType物理世界定义的空间类型,spaceIdList业务空间实例id列表,category设备或部件类型 * TODO 资产相关功能暂时不提供,之后根据业务进行需求处理 */ @PostMapping("/equip-category-property") public AdmResponse equipProperty(@QueryParam("category") String category, @RequestBody AdmQueryCriteria request, @RequestBody List spaceIdList, @QueryParam("spacrType") String spacrType){ //return EquipmentComService.equipProperty(category, request, spaceIdList, spacrType) return null; } /** * 批量添加设备和资产的关系 * TODO 资产相关功能暂时不提供,之后根据业务进行需求处理 */ @PostMapping("/equip-r-property") public AdmResponse equipRelationshipProperty(@RequestBody AdmCreateRequest createRequest, @QueryParam("projectId") String projectId) { //return EquipmentComService.equipPro(request) return null; } /** * 修改设备的附件功能 * { * "content":"{....}" EquipUpDateEnclosure 实体list * } */ @PostMapping("/update") public AdmResponse equipUpDateEnclosure(@RequestBody ObjectNode equipUpDateEnclosureRequest) { //return EquipmentService.equipUpDateEnclosurs(equipUpDateEnclosureRequest) if(JSONUtil.isNull(equipUpDateEnclosureRequest)){ return AdmResponse.failure(ResponseCode.A0400.getDesc()+",不能为空"); } List equipUpDateEnclosure = JSONUtil.toList(equipUpDateEnclosureRequest.get("content").toString(), EquipUpDateEnclosure.class); if(CollUtil.isNotEmpty(equipUpDateEnclosure)){ Map equipUpDateEnclosureMap = CollUtil.fieldValueMap(equipUpDateEnclosure, BaseEntity.PROP_ID); if(equipUpDateEnclosureMap.size() < equipUpDateEnclosure.size()) { return AdmResponse.failure("设备id不能为空"); } //获取待更新的设备 QueryCriteria queryCriteria = new QueryCriteria(); ObjectNode criteria = JsonNodeFactory.instance.objectNode(); criteria.put("objType", AdmEquipment.OBJ_TYPE); ArrayNode arrayNode = criteria.putObject("id").putArray("$in"); equipUpDateEnclosureMap.keySet().stream().forEach(equipId -> arrayNode.add(equipId)); queryCriteria.setCriteria(criteria); AdmResponse equips = equipmentService.doQuery(AdmContextUtil.toDmpContext(), queryCriteria, AdmEquipment.class); if(CollUtil.isEmpty(equips.getContent())){ return AdmResponse.failure(ResponseCode.A0400.getDesc()); } //将需要更新的数据放到待更新的设备中 List equipmentList = JSONUtil.toList(equips.getContent().toString(), AdmEquipment.class); //获取所有属性 Map fieldMap = ReflectUtil.getFieldMap(EquipUpDateEnclosure.class); //对每个设备更新属性 equipmentList.stream().forEach(admEquipment -> { fieldMap.keySet().forEach(fieldName -> { EquipUpDateEnclosure enclosure = equipUpDateEnclosureMap.get(admEquipment.getId()); List newAttr = (List) ReflectUtil.getFieldValue(enclosure,fieldName); if(CollUtil.isNotEmpty(newAttr)){ dealTaskFiles(admEquipment, fieldName, newAttr); } }); }); List vos = equipmentService.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, equipmentList); return AdmResponse.success(vos); }else{ return AdmResponse.failure(ResponseCode.A0400.getDesc()); } } /** * 根据模型id查询待删除的设备数量 [{ * "modelId":"", * "count":"" * }] */ @PostMapping("/equip-del-com") public AdmResponse equipComDel(@RequestBody List equipComDelList){ //return EquipmentService.equipComDels(equipComDelList) if(CollUtil.isEmpty(equipComDelList)){ return AdmResponse.success(); } QueryCriteria queryCriteriaEuip = new QueryCriteria(); ObjectNode criteriaEquip = JsonNodeFactory.instance.objectNode(); criteriaEquip.put("objType", AdmEquipment.OBJ_TYPE); criteriaEquip.put("taskState",-1); ArrayNode array = criteriaEquip.putObject("modelId").putArray("$in"); equipComDelList.stream().forEach(nodeObj -> { if(StrUtil.isNotEmpty(nodeObj.get("modelId").textValue())) { array.add(nodeObj.get("modelId").textValue()); } }); queryCriteriaEuip.setCriteria(criteriaEquip); List equipList = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteriaEuip); if(CollUtil.isEmpty(equipList)){ return AdmResponse.success(equipComDelList); } Map equipDelMap = new HashMap<>(equipComDelList.size()); for (ObjectNode equipComDel : equipComDelList) { String modelIdObj = equipComDel.get("modelId").toString(); equipDelMap.put(modelIdObj, equipComDel); } equipList.stream().forEach(euip -> { String modelIdEq = euip.get("modelId").textValue(); if(equipDelMap.containsKey(modelIdEq)){ Integer count = Integer.parseInt(equipDelMap.get(modelIdEq).get("count").textValue()) + 1; equipDelMap.get(modelIdEq).put("count", count); } }); return AdmResponse.success(equipDelMap.values().stream().collect(Collectors.toList())); } /** * 根据模型id查询待补充的设备数量 * [{ * "modelId":"", * "count":"" * }] */ @PostMapping("/equip-supply") public AdmResponse equipPropertySupply(@RequestBody List equipComDelList){ //return EquipmentService.equipPropertySupplys(equipComDelList) // if(CollUtil.isEmpty(equipComDelList)){ return AdmResponse.success(); } //1. 根据modelId查询楼层信息 QueryCriteria queryCriteria = new QueryCriteria(); ObjectNode criteria = JsonNodeFactory.instance.objectNode(); criteria.put("objType", AdmFloor.OBJ_TYPE); ArrayNode arrayNode = criteria.putObject("modelId").putArray("$in"); equipComDelList.stream().forEach(node -> { arrayNode.add(node.get("modelId").textValue()); }); queryCriteria.setCriteria(criteria); List floorList = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteria); if(CollUtil.isEmpty(floorList)){ return AdmResponse.success(); } List admFloorList = JSONUtil.toList(floorList.toString(), AdmFloor.class); Map admFloorMap = CollUtil.fieldValueMap(admFloorList, BaseEntity.PROP_ID); //2. 根据楼层信息 查询需要补充设备(bimId isnull,bimLocation not isnull,modelId isnull)数量 QueryCriteria queryCriteriaEuip = new QueryCriteria(); ObjectNode criteriaEquip = JsonNodeFactory.instance.objectNode(); criteriaEquip.put("objType", AdmEquipment.OBJ_TYPE); ArrayNode array = criteriaEquip.putObject("floorId").putArray("$in"); admFloorMap.keySet().stream().forEach(id -> array.add(id)); JSONObject bimId = new JSONObject(); bimId.put("$null", true); criteria.putPOJO("bimId", bimId); JSONObject bimLocation = new JSONObject(); bimId.put("$null", false); criteriaEquip.putPOJO("bimLocation", bimLocation); JSONObject modelId = new JSONObject(); modelId.put("$null", true); criteriaEquip.putPOJO("modelId", modelId); queryCriteriaEuip.setCriteria(criteriaEquip); List equipList = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteriaEuip); if(CollUtil.isEmpty(equipList)){ return AdmResponse.success(equipComDelList); } equipList.stream().forEach(equip -> { String floolId = equip.get("floorId").textValue(); if(admFloorMap.containsKey(floolId)){ Integer count = Integer.parseInt(admFloorMap.get(floolId).getCount()) + 1; admFloorMap.get(floolId).setCount(count.toString()); } }); // 3 根据floorId,modelId 汇总 Map equipDelMap = new HashMap<>(equipComDelList.size()); for (ObjectNode equipComDel : equipComDelList) { String modelIdObj = equipComDel.get("modelId").toString(); equipDelMap.put(modelIdObj, equipComDel); } admFloorMap.values().stream().forEach(floor -> { String modelIdFl = floor.getModelId(); if(equipDelMap.containsKey(modelIdFl)){ Integer count = Integer.parseInt(equipDelMap.get(modelIdFl).get("count").textValue()) + Integer.parseInt(floor.getCount()); equipDelMap.get(modelIdFl).put("count", count); } }); return AdmResponse.success(equipDelMap.values().stream().collect(Collectors.toList())); } /** * 模型质量报告 待删除的设备 * 级联-任务(scanTaskBase)、资产(property)、设备类型(equipCategory),级联任务的时候需要设置条件(TaskState = 0 添加时间降序 取第一个值 ) */ @PostMapping("/equip-comm-del") public AdmResponse equipCommDel(@RequestBody AdmQueryCriteria request){ //return EquipDelService.pageQuery(sQueryRequest,withFilterList) //e.task_state = '-1'::integer //AND NOT e.model_id IS NULL //TODO 关联 revit.model_floor revit.model_folder 展示模型相关内容 request.setName(AdmEquipment.OBJ_TYPE); QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request); ObjectNode criteria = queryCriteria.getCriteria(); JSONObject modelId = new JSONObject(); modelId.put("$null", false); criteria.putPOJO("modelId", modelId); criteria.put("taskState","-1"); queryCriteria.setCriteria(criteria); AdmResponse equipRes = equipmentService.doQuery(AdmContextUtil.toDmpContext(), queryCriteria, AdmEquipment.class); return equipRes; } /** * 模型质量报告 待补充的设备 * 级联-设备类型(equipFamily) */ @PostMapping("/property-equip-supp") public AdmResponse propertyEquip(@RequestBody AdmQueryCriteria request){ //return EquipmentService.equipPropertySupp(sQueryRequest) //equipment.bim_id IS NULL // AND equipment.model_id IS NULL // AND NOT equipment.bim_location IS NULL; AdmQueryCriteria admQueryCriteria = request; StringBuilder filters = new StringBuilder(); filters.append("floorId startwith 'Eq'"); filters.append(";buildingId startwith 'Bd'"); filters.append(";bimId isnull"); filters.append(";modelId isnull"); admQueryCriteria.setFilters(filters.toString()); admQueryCriteria.setName(AdmEquipment.OBJ_TYPE); QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteria); ObjectNode criteria = queryCriteria.getCriteria(); JSONObject bimLocation = new JSONObject(); bimLocation.put("$null", false); criteria.putPOJO("bimLocation", bimLocation); queryCriteria.setCriteria(criteria); AdmResponse equipRes = equipmentService.doQuery(AdmContextUtil.toDmpContext(), queryCriteria, AdmEquipment.class); if(CollUtil.isNotEmpty(equipRes.getContent())){ List admEquipments = JSONUtil.toList(equipRes.getContent().toString(), AdmEquipment.class); Map admEquipmentMap = CollUtil.fieldValueMap(admEquipments, BaseEntity.PROP_ID); if(CollUtil.isEmpty(request.getCascade())){ List cascade = new ArrayList<>(); AdmQueryCriteria admQueryCriteriaBd = new AdmQueryCriteria(); admQueryCriteriaBd.setName(AdmBuilding.OBJ_TYPE); cascade.add(admQueryCriteriaBd); AdmQueryCriteria admQueryCriteriaFl = new AdmQueryCriteria(); admQueryCriteriaFl.setName(AdmFloor.OBJ_TYPE); cascade.add(admQueryCriteriaFl); request.setCascade(cascade); request.setName(AdmEquipment.OBJ_TYPE); } ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(); admEquipmentMap.keySet().stream().forEach(id -> arrayNode.add(id)); String filter = ""; if(StrUtil.isNotEmpty(request.getFilters())){ filter = request.getFilters(); } filter = filter + ";id in "+arrayNode.toString(); request.setFilters(filter); AdmResponse admResponse = equipmentService.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class); if(CollUtil.isNotEmpty(admResponse.getContent())){ //处理数据 List objectNodeList = (List) admResponse.getContent(); objectNodeList.stream().forEach(equip ->{ JsonNode building = equip.get("building"); JsonNode floor = equip.get("floor"); if(!JSONUtil.isNull(building)){ equip.put("buildingName", building.get("localName").textValue()); } if(!JSONUtil.isNull(floor)){ equip.put("floorName", floor.get("localName").textValue()); equip.put("modelId", floor.get("modelId").textValue()); } }); } return admResponse; }else{ return AdmResponse.success(); } /** sql * SELECT equipment.id, * equipment.name, * equipment.local_id, * equipment.local_name, * equipment.bim_id, * equipment.bim_location, * equipment.floor_id, * equipment.building_id, * equipment.cad_id, * equipment.project_id, * equipment.find_people, * equipment.class_code, * equipment.infos, * JSON_EXTRACT(floor.infos, '$.modeId') as model_id, * floor.local_name as floor_name, * (SELECT building.local_name * FROM dt_object building * WHERE building.id = JSON_EXTRACT(equipment.infos, '$.buildingId') and building.obj_type = 'building') AS building_name, * * (SELECT def_class.name * FROM dt_define_type def_class * WHERE def_class.code = equipment.class_code * LIMIT 1) AS code_name * * from ( SELECT equipment.id, * equipment.name, * equipment.local_id, * equipment.local_name, * equipment.class_code, * JSON_EXTRACT(equipment.infos, '$.bimId') bim_id, * JSON_EXTRACT(equipment.infos, '$.bimLocation') bim_location, * JSON_EXTRACT(equipment.infos, '$.floorId') floor_id, * JSON_EXTRACT(equipment.infos, '$.buildingId') building_id, * JSON_EXTRACT(equipment.infos, '$.cadId') cad_id, * equipment.project_id, * JSON_EXTRACT(equipment.infos, '$.findPeople') find_people, * equipment.infos * FROM dt_object equipment * WHERE equipment.obj_type='equipment' * AND JSON_EXTRACT(equipment.infos, '$.bimId') IS NULL * AND JSON_EXTRACT(equipment.infos, '$.modeId') IS NULL * AND JSON_EXTRACT(equipment.infos, '$.buildingId') IS NOT NULL * AND JSON_EXTRACT(equipment.infos, '$.floorId') IS NOT NULL * AND JSON_EXTRACT(equipment.infos, '$.bimLocation') IS NOT NULL * ) equipment left join dt_object floor on fl */ } /** * 设备信息点 * 统计设备信息点与总数据占比 */ @PostMapping("/info-point") public AdmResponse infoPoint(@QueryParam("projectId") String projectId) { //return customSqlService.infoPoints() JSONObject gatherInfoPoint = calInfoPointByObjType(AdmEquipment.OBJ_TYPE, false, false); JSONObject infoPoint = new JSONObject(); infoPoint.put("dynamicInfoPoint",gatherInfoPoint.getString("gatherDynamicInfoPointCounts")); infoPoint.put("staticInfoPoint",gatherInfoPoint.getString("gatherStaticInfoPointCounts")); return AdmResponse.success(CollUtil.newArrayList(infoPoint)); } /** * 设备已采集信息点 * 统计设备信息点与需采集数据占比 */ @PostMapping("/gather-info-point") public AdmResponse gatherInfoPoint(@QueryParam("projectId") String projectId) { //return customSqlService.gatherInfoPoints() if(StrUtil.isEmpty(projectId)){ return AdmResponse.failure(ResponseCode.A0400.getCode()); } JSONObject gatherInfoPoint = calInfoPointByObjType(AdmEquipment.OBJ_TYPE, true, true); return AdmResponse.success(CollUtil.newArrayList(gatherInfoPoint)); } /** * 统计系统信息点与需采集数据占比 */ @PostMapping("/system-info-point") public AdmResponse systemInfoPoin(@QueryParam("projectId") String projectId) { if(StrUtil.isEmpty(projectId)){ return AdmResponse.failure(ResponseCode.A0400.getCode()); } JSONObject gatherInfoPoint = calInfoPointByObjType(AdmSystem.OBJ_TYPE,true, true); return AdmResponse.success(CollUtil.newArrayList(gatherInfoPoint)); } /** * 台账中待删除的对象 数量统计 */ @PostMapping("/del-equip-comm-pro") public AdmResponse deleteObj(@QueryParam("projectId") String projectId){ QueryCriteria queryCriteria = new QueryCriteria(); ObjectNode criteria = JsonNodeFactory.instance.objectNode(); criteria.put("taskState", -1); criteria.put("objType","['equipment','component']"); queryCriteria.setCriteria(criteria); queryCriteria.setOnlyCount(true); List euipCom = DigitalObjectFacade.query(groupCode,AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteria); if(CollUtil.isNotEmpty(euipCom)){ return AdmResponse.success(euipCom); }else{ return AdmResponse.success(); } } /** * 项目下的所有设备类型以及名称 * * @return 返回对象列表 */ @PostMapping("/type") public AdmResponse equipType(@QueryParam("projectId") String projectId){ RequestData requestData = new RequestData(); if(StrUtil.isNotEmpty(projectId)){ requestData.setProjectId(projectId); } requestData.setObjType(AdmEquipment.OBJ_TYPE); List> result = DigitalObjectSimpleFacade.queryDefineInfoByObjType(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmContextUtil.toDmpContext().getAppId(),null,requestData); if(CollUtil.isNotEmpty(result)){ return AdmResponse.success(result); }else{ return AdmResponse.success(); } } /** * 查询系统-设备类树 * @return * @throws Exception */ @GetMapping("/type/tree") public AdmResponse querySystemEquipCategory() throws Exception { // 组装上下文条件 AdmDict request = AdmDict.builder().type(AdmDictCategoryEnum.SYSTEM_EQUIP.getValue()).build(); return dictService.queryCategory(AdmContextUtil.toDmpContext(),request,AdmObjectType.class); } /** * 计算动态、静态信息点 */ private Map calculate(List dynamicInfoPointCodes, List staticInfoPointCodes, List objectNodeList, Integer num) { Map hashMap = new HashMap(); int dynamicInfoPoint = 0; int staticInfoPoint = 0; int customInfoPoint=0; Iterator iterator1 = staticInfoPointCodes.iterator(); for (ObjectNode objectNode : objectNodeList) { while (iterator1.hasNext()) { ObjectInfoDefine infoDefine = iterator1.next(); if (objectNode.get("id") != null && "id" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) { staticInfoPoint++; iterator1.remove(); } if (objectNode.get("name") != null && "name" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) { staticInfoPoint++; iterator1.remove(); } if (objectNode.get("localId") != null && "localId" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) { staticInfoPoint++; iterator1.remove(); } if (objectNode.get("localName") != null && "localName" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) { staticInfoPoint++; iterator1.remove(); } if (objectNode.get("qrCode") != null && "qRCode" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) { staticInfoPoint++; iterator1.remove(); } if (objectNode.get("cADID") != null && "cADID" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode() && num==0) { staticInfoPoint++; iterator1.remove(); } if (objectNode.get("bimId") != null && "bimId" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode() && num==0) { staticInfoPoint++; iterator1.remove(); } if (objectNode.get("bimLocation") != null && "bimLocation" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) { staticInfoPoint++; iterator1.remove(); } if (objectNode.get("equipSerial") != null && "equipSerial" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) { staticInfoPoint++; iterator1.remove(); } if (objectNode.get("bimFamilyName") != null && "bimFamilyName" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) { staticInfoPoint++; iterator1.remove(); } if (objectNode.get("bimFamilySymbol") != null && "bimFamilySymbol" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) { staticInfoPoint++; iterator1.remove(); } } } for (ObjectNode objectNode : objectNodeList) { if (objectNode.get("infos") != null) { Map dynamic = calculateInfoPoints(objectNode.get("infos").toString(), objectNode.get("classCode").textValue().toString(), dynamicInfoPointCodes); Map staticMap = calculateInfoPoints(objectNode.get("infos").toString(), objectNode.get("classCode").textValue().toString(), staticInfoPointCodes); dynamicInfoPoint += Integer.parseInt(dynamic.get("counts").toString()); staticInfoPoint += Integer.parseInt(staticMap.get("counts").toString()); dynamicInfoPointCodes.remove(dynamic.get("next")); staticInfoPointCodes.remove(staticMap.get("next")); } } hashMap.put("dynamicInfoPoint", dynamicInfoPoint); hashMap.put("staticInfoPoint", staticInfoPoint); hashMap.put("customInfoPoint", customInfoPoint); return hashMap; } /** * 计算信息点 * */ private Map calculateInfoPoints(String str, String type, List infoPointCodes) { int counts = 0; Map hashMap = new HashMap(); Iterator iterator = infoPointCodes.iterator(); while (iterator.hasNext()){ ObjectInfoDefine nextInfo = iterator.next(); if(str.contains(nextInfo.getCode()) && type==nextInfo.getClassCode()){ counts ++; hashMap.put("next", nextInfo); iterator.remove(); } } hashMap.put("counts", counts); return hashMap; } private JSONObject calInfoPointByObjType(String objType, Boolean visible, Boolean getInfoCounts){ //1 查询项目下所有现有的系统 AdmQueryCriteria admQueryCriteriaObj = new AdmQueryCriteria(); if(objType.equals(AdmEquipment.OBJ_TYPE)){ admQueryCriteriaObj.setProjection(Arrays.asList("id","name","localId","localName","cadId","bimId","bimLocation","infos","classCode","equipSerial","bimFamilyName","bimFamilySymbol")); }else{ admQueryCriteriaObj.setProjection(Arrays.asList("id","name","localId","localName","cadId","bimId","infos","classCode")); } admQueryCriteriaObj.setName(objType); QueryCriteria queryCriteriaSys = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteriaObj); List admObjList = DigitalObjectFacade.query(groupCode, AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteriaSys); //2 获取动态 静态 信息点 // 2.1 根据objType获取定义 Set classCodeSet = new HashSet<>(); if(AdmSystem.OBJ_TYPE.equals(objType)){ QueryCriteria queryCriteriaType = new QueryCriteria(); ObjectNode criteria = JsonNodeFactory.instance.objectNode(); criteria.put("objType", objType); queryCriteriaType.setCriteria(criteria); AdmResponse admResponseType = dictService.doQueryObjectType(AdmContextUtil.toDmpContext(), queryCriteriaType, AdmObjectType.class); if(CollUtil.isEmpty(admResponseType.getContent())){ return null; } List admObjectTypes = (List) admResponseType.getContent(); Map admObjectTypeMap = CollUtil.fieldValueMap(admObjectTypes, "code"); classCodeSet = admObjectTypeMap.keySet(); }else { List equipmentList = JSONUtil.toList(admObjList.toString(), AdmEquipment.class); Map admObjectTypeMap = CollUtil.fieldValueMap(equipmentList, "code"); classCodeSet = admObjectTypeMap.keySet(); } JSONObject gatherInfoPoint = new JSONObject(); if(CollUtil.isEmpty(admObjList)){ gatherInfoPoint.put("gatherInfoPointCounts", 0); gatherInfoPoint.put("gatherCustomInfoPointCounts",0); gatherInfoPoint.put("gatherDynamicInfoPointCounts",0); gatherInfoPoint.put("gatherStaticInfoPointCounts",0); } else { // 2.2 根据定义获取信息点 //查询当前实例所有信息点总数 long controlInfoCounts = 0L; QueryCriteria queryCriteria = new QueryCriteria(); ObjectNode criteria = JsonNodeFactory.instance.objectNode(); criteria = JsonNodeFactory.instance.objectNode(); ArrayNode arrayNode = criteria.putObject("classCode").putArray("$in"); classCodeSet.stream().forEach(classCode -> arrayNode.add(classCode)); criteria.put("type", "commo"); if(getInfoCounts){ criteria.put("valid","['0','1']"); queryCriteria.setCriteria(criteria); queryCriteria.setOnlyCount(true); List totalInfo = DigitalObjectInfoFacade.query(groupCode, AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteria); controlInfoCounts = totalInfo.size(); criteria.remove("valid"); } //静态信息点 criteria.put("category","STATIC"); if(visible){ criteria.put("valid", "1"); }else{ criteria.put("valid","['0','1']"); } queryCriteria.setCriteria(criteria); List staticInfoCode = DigitalObjectInfoFacade.query(groupCode, AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteria); criteria.remove("category"); //动态信息点 JSONObject category = new JSONObject(); category.put("$ne","STATIC"); criteria.putPOJO("category", category); queryCriteria.setCriteria(criteria); List dynamicInfoCode = DigitalObjectInfoFacade.query(groupCode, AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteria); //4 计算已采集的和需要采集的信息点占比 //return customSqlService.systemInfoPoins() Map hashMap = calculate(dynamicInfoCode, staticInfoCode, admObjList, 1); gatherInfoPoint.put("gatherCustomInfoPointCounts",hashMap.get("customInfoPoint")); gatherInfoPoint.put("gatherDynamicInfoPointCounts",hashMap.get("dynamicInfoPoint")); gatherInfoPoint.put("gatherStaticInfoPointCounts",hashMap.get("staticInfoPoint")); gatherInfoPoint.put("gatherInfoPointCounts", controlInfoCounts); } return gatherInfoPoint; } /** * 处理设备属性文件 -> 设备的信息点 * @param equip * @param attribute */ private void dealTaskFiles(AdmEquipment equip, String attribute, List upTarget){ Map infos = equip.getInfos(); boolean containsKey1 = infos.containsKey(attribute); if (containsKey1) { if (infos.get(attribute) != null && StrUtil.isNotEmpty(infos.get(attribute).toString())){ List list = JSONUtil.toList(infos.get(attribute).toString(), AdmTaskPic.class); list.addAll(upTarget); infos.put(attribute, list); }else { infos.put(attribute, upTarget); } } else { infos.put(attribute, upTarget); } } }