123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712 |
- package com.persagy.proxy.object.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.collection.CollectionUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.json.JSONUtil;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.metadata.OrderItem;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.fasterxml.jackson.databind.node.ArrayNode;
- import com.fasterxml.jackson.databind.node.JsonNodeFactory;
- import com.fasterxml.jackson.databind.node.ObjectNode;
- import com.google.common.collect.Sets;
- import com.persagy.dmp.basic.model.QueryCriteria;
- import com.persagy.dmp.common.context.AppContext;
- import com.persagy.dmp.common.helper.SpringHelper;
- import com.persagy.dmp.common.model.response.CommonResult;
- import com.persagy.dmp.define.entity.ObjectTypeDefine;
- import com.persagy.dmp.digital.client.DigitalObjectFacade;
- 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.GraphCodeEnum;
- import com.persagy.proxy.adm.constant.RelCodeEnum;
- import com.persagy.proxy.adm.request.AdmDCSQueryRequest;
- import com.persagy.proxy.adm.request.AdmQueryCriteria;
- import com.persagy.proxy.adm.request.AdmResponse;
- import com.persagy.proxy.adm.service.IAdmRelationService;
- import com.persagy.proxy.adm.service.impl.AbstractAdmBaseServiceImpl;
- import com.persagy.proxy.adm.utils.AdmContextUtil;
- import com.persagy.proxy.adm.utils.AdmEntityTransferUtil;
- import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
- import com.persagy.proxy.common.client.DmpRwdClient;
- import com.persagy.proxy.common.entity.DmpResult;
- import com.persagy.proxy.common.entity.InstanceUrlParam;
- import com.persagy.proxy.common.entity.RelationDTO;
- import com.persagy.proxy.object.model.AdmEquipment;
- import com.persagy.proxy.object.model.AdmSpace;
- import com.persagy.proxy.object.model.AdmSystem;
- import com.persagy.proxy.object.service.IAdmEquipmentService;
- import com.persagy.proxy.object.service.IAdmSpaceService;
- import com.persagy.proxy.object.service.IAdmSystemService;
- import com.persagy.proxy.report.service.IRelationReportService;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.servlet.http.HttpServletRequest;
- import java.util.*;
- import java.util.stream.Collectors;
- @Slf4j
- @Service
- public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> implements IAdmSpaceService {
- @Autowired
- private DmpRwdClient rwdClient;
- @Autowired
- private ObjectMapper objectMapper;
- @Autowired
- private IAdmRelationService relationService;
- @Autowired
- private IAdmEquipmentService equipmentService;
- @Autowired
- private IAdmSystemService systemService;
- @Autowired
- private IRelationReportService relationReportService;
- @Override
- public AdmResponse doQuery(InstanceUrlParam context, AdmQueryCriteria request, Class<AdmSpace> clazz) {
- AdmResponse response = super.doQuery(context, request, clazz);
-
- ensureSpecialValues(context, (List<AdmSpace>) response.getContent());
- return response;
- }
- @Override
- public List<AdmSpace> doInsertExt(InstanceUrlParam context, Class<AdmSpace> clazz, List<AdmSpace> voList) {
- Map<String, List<AdmSpace>> spaceMapByFlId = voList.stream().filter(admSpace -> StringUtils.isNotEmpty(admSpace.getFloorId())).collect(Collectors.groupingBy(AdmSpace::getFloorId));
-
- if(CollUtil.isNotEmpty(spaceMapByFlId)){
- List<ObjectNode> floors = queryFloorsByFloorIds(context, spaceMapByFlId.keySet());
- if(CollUtil.isNotEmpty(floors)){
-
-
- voList = processHeight(spaceMapByFlId, floors);
- }
- }
-
- List<AdmSpace> vosR = doInsert(context, clazz, voList);
-
- processRelations(vosR);
-
-
-
- return vosR;
- }
- @Override
- public AdmResponse doQueryType(InstanceUrlParam context, AdmDCSQueryRequest request) {
-
- ObjectNode criteriaEq = JsonNodeFactory.instance.objectNode();
- criteriaEq.put("parentCode", "space");
- DmpResult<JSONArray> resultDef = queryDefineType(context, criteriaEq);
- List<JSONObject> defineList = null;
- if(resultDef.getResult().equals(DmpResult.SUCCESS)){
- defineList = JSONUtil.toList(resultDef.getData().toString(), JSONObject.class);
-
-
- assembleDefineTypes(context, defineList, request.getFloorId());
-
- AdmResponse response = AdmResponse.success(defineList, request);
- Long total = resultDef.getCount() == null ? null : resultDef.getCount().longValue();
- response.setTotal(total);
- return response;
- }else{
- return null;
- }
- }
- @Override
- public AdmResponse doQuerySpaces(InstanceUrlParam context, AdmDCSQueryRequest request) {
- request.setName(AdmSpace.OBJ_TYPE);
- String classCodeFilter = "";
- if(StrUtil.isNotEmpty(request.getZoneType())){
- classCodeFilter = " classCode = '"+request.getZoneType()+"'";
- }else{
- classCodeFilter = " classCode in ['"+ String.join("', '",request.getZoneTypeList()) + "']";
- }
- String filters = request.getFilters();
- if(StrUtil.isBlank(filters)){
- request.setFilters(classCodeFilter);
- }else{
- request.setFilters(filters+"; "+classCodeFilter);
- }
- AdmResponse response = null;
- if(StrUtil.isNotEmpty(request.getBuildingId()) && StrUtil.isNotEmpty(request.getFloorId()) && !request.getFloorId().equals("isnull")){
-
- request.setFilters(request.getFilters()+" ; buildingId = '"+request.getBuildingId()+"' ; floorId='"+request.getFloorId()+"' ;");
-
- }else if(StrUtil.isNotEmpty(request.getBuildingId()) && StrUtil.isNotEmpty(request.getFloorId()) && request.getFloorId().equals("isnull")){
-
- request.setFilters(request.getFilters()+" ; buildingId = '"+request.getBuildingId()+"' ; floorId isnull");
-
- }else if(StrUtil.isNotEmpty(request.getBuildingId()) && StrUtil.isEmpty(request.getFloorId()) && !request.getBuildingId().equals("isnull")){
-
-
- request.setFilters(request.getFilters()+" ; buildingId = '"+request.getBuildingId()+"' ; ");
- }else if(StrUtil.isNotEmpty(request.getBuildingId()) && StrUtil.isEmpty(request.getFloorId()) && request.getBuildingId().equals("isnull")){
-
-
-
- request.setFilters(request.getFilters()+" ; buildingId isnull");
- }else if(StrUtil.isEmpty(request.getBuildingId()) && StrUtil.isEmpty(request.getFloorId())){
- }
- response = this.query(request);
- return response;
- }
- @Override
- public void ensureSpecialValues(InstanceUrlParam context, List<AdmSpace> vos) {
- if(CollUtil.isEmpty(vos)) {
- return;
- }
-
- List<AdmEquipment> equipmentList = new ArrayList<>();
- for(AdmSpace vo:vos) {
-
- if(CollUtil.isEmpty(vo.getEquipment()) && CollUtil.isEmpty(vo.getEquipmentFor())) {
- continue;
- }
- if(CollUtil.isNotEmpty(vo.getEquipment())) {
- equipmentList.addAll(vo.getEquipment());
- }
- if(CollUtil.isNotEmpty(vo.getEquipmentFor())) {
- equipmentList.addAll(vo.getEquipmentFor());
- }
- }
-
- equipmentService.ensureSpecialValues(context, equipmentList);
-
- List<AdmSystem> admSystemList = new ArrayList<>();
- for(AdmSpace vo:vos) {
-
- if(CollUtil.isEmpty(vo.getGeneralSystem())) {
- continue;
- }
- admSystemList.addAll(vo.getGeneralSystem());
- }
-
- systemService.ensureSpecialValues(context, admSystemList);
- }
- @Override
- public List<AdmSpace> querySpaceInShaft(InstanceUrlParam context, String shaftId, String spaceType) {
- AdmQueryCriteria request = new AdmQueryCriteria();
- request.setName(AdmSpace.OBJ_TYPE);
- request.resetRelationCond(false, "ArchSubset", "Sh2Sp", spaceType, shaftId, true);
- AdmResponse rs = query(request);
- return (List<AdmSpace>) rs.getContent();
- }
- @Override
- public List<AdmSpace> querySpaceInBuilding(InstanceUrlParam context, String buildingId, String spaceType) {
- AdmQueryCriteria request = new AdmQueryCriteria();
- request.setName(AdmSpace.OBJ_TYPE);
- request.resetRelationCond(false, "ArchSubset", "Bd2Sp", spaceType, buildingId, true);
- AdmResponse rs = query(request);
- return (List<AdmSpace>) rs.getContent();
- }
- @Override
- public Map<String, List<String>> querySpaceMapInFloors(InstanceUrlParam context, List<String> floorIds, String spaceType) {
- QueryCriteria queryRequest = new QueryCriteria();
- ObjectNode criteriaRel = JsonNodeFactory.instance.objectNode();
- criteriaRel.put("graphCode", "ArchSubset");
- criteriaRel.put("relCode", "Fl2Sp");
- criteriaRel.put("relValue", spaceType);
- ArrayNode objNode = criteriaRel.putArray("objFrom");
- floorIds.forEach(floorId -> objNode.add(floorId));
- queryRequest.setCriteria(criteriaRel);
- List<ObjectRelation> relations = relationService.queryByCondition(context, queryRequest);
- if(CollUtil.isEmpty(relations)) {
- return null;
- }
- return relations.stream().collect(Collectors.groupingBy(ObjectRelation::getObjFrom,
- Collectors.mapping(ObjectRelation::getObjTo, Collectors.toList())));
- }
- @Override
- public Map<String, Set<String>> queryTrafficSpaceMap(InstanceUrlParam context, Iterable<String> spaceIds, String spaceType) {
- Map<String, Set<String>> result = new HashMap<>();
- loadTrafficSpace(context, spaceIds, spaceType, true, result);
- loadTrafficSpace(context, spaceIds, spaceType, false, result);
- return result;
- }
-
- @Override
- public Set<String> queryMultiBuildingOrFloorSpaceIds(HttpServletRequest request) {
- String groupCode = AppContext.getContext().getGroupCode();
- String projectId = AppContext.getContext().getProjectId();
-
- CommonResult<List<ObjectRelation>> floorCountByObjIds = DigitalObjectSimpleFacade
- .queryRelationCountByObjIds(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID,
- getMultiBuildingOrFloorQueryWrapper(request,RelCodeEnum.Fl2Sp.name()));
- List<ObjectRelation> floorSpaceData = floorCountByObjIds.getData();
-
- CommonResult<List<ObjectRelation>> buildingCountByObjIds = DigitalObjectSimpleFacade
- .queryRelationCountByObjIds(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID,
- getMultiBuildingOrFloorQueryWrapper(request, RelCodeEnum.Bd2Sp.name()));
- List<ObjectRelation> buildingSpaceData = buildingCountByObjIds.getData();
- Set<String> spaceIds = CollUtil.newHashSet(CollUtil.isNotEmpty(floorSpaceData), floorSpaceData
- .stream().filter(objectRelation -> objectRelation.getCount()>1)
- .map(ObjectRelation::getObjTo).collect(Collectors.toSet()));
- spaceIds.addAll(CollUtil.newHashSet(CollUtil.isNotEmpty(buildingSpaceData),
- buildingSpaceData.stream().filter(objectRelation -> objectRelation.getCount()>1)
- .map(ObjectRelation::getObjTo).collect(Collectors.toSet())));
- return spaceIds;
- }
-
- @Override
- public AdmResponse queryMultiBuildingOrFloorSpaces(HttpServletRequest request) {
-
- Set<String> spaceIds = queryMultiBuildingOrFloorSpaceIds(request);
- AdmQueryCriteria spaceCriteria = new AdmQueryCriteria();
- String filters = " id in ['"+ String.join("', '", spaceIds) +"'] ";
- spaceCriteria.setFilters(filters);
- AdmQueryCriteria floorCriteria = new AdmQueryCriteria();
- floorCriteria.setName("floorList");
- AdmQueryCriteria buildingCriteria = new AdmQueryCriteria();
- buildingCriteria.setName("building");
- floorCriteria.setCascade(CollUtil.newArrayList(buildingCriteria));
- spaceCriteria.setCascade(CollUtil.newArrayList(floorCriteria));
- return super.doQuery(AdmContextUtil.toDmpContext(), spaceCriteria, AdmSpace.class);
- }
-
- @Override
- public AdmResponse query(AdmQueryCriteria request) {
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- AdmResponse response = super.doQuery(context, request, AdmSpace.class);
-
- ensureSpecialValues(context, (List<AdmSpace>) response.getContent());
- return response;
- }
-
- private AdmResponse query(AdmDCSQueryRequest request) {
- String orders = request.getOrders();
- List<OrderItem> orderItem = AdmQueryCriteriaHelper.toOrderItem(orders);
- Set<String> classCodes = StrUtil.isBlank(request.getZoneType()) ? request.getZoneTypeList() : Sets.newHashSet(request.getZoneType());
-
- QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request);
- ObjectNode criteria = queryCriteria.getCriteria();
- List<ObjectNode> queryObjects = this.relationReportService.queryObjects(criteria, AppContext.getContext().getGroupCode(), AppContext.getContext().getProjectId(),
- null, classCodes, Sets.newHashSet("space"), orderItem);
-
- List<AdmSpace> admVOs = AdmEntityTransferUtil.toAdmMultiEntity(queryObjects, request.getProjection(), AdmSpace.class);
-
- processCascade(AdmContextUtil.toDmpContext(), admVOs, request.getName(), request.getCascade());
-
- AdmResponse response = AdmResponse.success(admVOs);
- if(CollectionUtil.isEmpty(queryObjects)){
- response.setTotal(0L);
- response.setCount(0L);
- }else {
- response.setTotal((long) queryObjects.size());
- }
- response.setPageNumber(request.getPageNumber() == null ? 50 : request.getPageNumber());
- response.setPageSize(request.getPageSize() == null ? 1 : request.getPageSize());
-
- ensureSpecialValues(AdmContextUtil.toDmpContext(), admVOs);
- return response;
- }
-
-
- @Override
- protected void processDmpCriteria(QueryCriteria dmpRequest) {
- ObjectNode criteria = dmpRequest.getCriteria();
- if (null==criteria){
- return;
- }
-
- ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
- if (criteria.has("floorId")){
-
- if(!criteria.get("floorId").toString().contains("$null")) {
- ObjectNode relationTo = objectMapper.createObjectNode();
- relationTo.put("graphCode", GraphCodeEnum.ArchSubset.name());
- relationTo.put("relCode", RelCodeEnum.Fl2Sp.name());
- relationTo.set("objFrom", criteria.get("floorId"));
- criteria.set("relationTo", relationTo);
- criteria.remove("floorId");
- if (criteria.has("buildingId"))
- criteria.remove("buildingId");
- return;
- }
- }
- if (criteria.has("buildingId")){
-
- ObjectNode relationTo = objectMapper.createObjectNode();
- relationTo.put("graphCode", GraphCodeEnum.ArchSubset.name());
- relationTo.put("relCode", RelCodeEnum.Bd2Sp.name());
- if(!criteria.get("buildingId").toString().contains("$null")) {
- relationTo.set("objFrom",criteria.get("buildingId"));
- }else{
- relationTo.put("$bindFlag", false);
- }
- criteria.set("relationTo",relationTo);
- criteria.remove("buildingId");
- }
- }
-
- private ObjectNode getMultiBuildingOrFloorQueryWrapper(HttpServletRequest request,String relCode) {
- ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
- ObjectNode objectNode = objectMapper.createObjectNode();
- if (StrUtil.isNotBlank(AppContext.getContext().getProjectId())){
- objectNode.putPOJO("projectIds", Sets.newHashSet(AppContext.getContext().getProjectId()));
- }
- objectNode.putPOJO("graphCodes", Sets.newHashSet(GraphCodeEnum.ArchSubset.name()));
- objectNode.putPOJO("relCodes", Sets.newHashSet(relCode));
- objectNode.putPOJO("groups", Sets.newHashSet("objTo"));
- return objectNode;
- }
-
- private void loadTrafficSpace(InstanceUrlParam context, Iterable<String> spaceIds, String spaceType, boolean isFrom, Map<String, Set<String>> result) {
-
- QueryCriteria queryRequest = new QueryCriteria();
- ObjectNode criteriaRel = JsonNodeFactory.instance.objectNode();
- criteriaRel.put("graphCode", "TrafficNetwork");
- criteriaRel.put("relValue", spaceType);
- ArrayNode objNode = criteriaRel.putArray(isFrom?"objFrom":"objTo");
- spaceIds.forEach(spaceId -> objNode.add(spaceId));
- queryRequest.setCriteria(criteriaRel);
- List<ObjectRelation> relations = relationService.queryByCondition(context, queryRequest);
- if(CollUtil.isEmpty(relations)) {
- return;
- }
-
- for(ObjectRelation relation:relations) {
- String key = isFrom ? relation.getObjFrom() : relation.getObjTo();
- String value = isFrom ? relation.getObjTo() : relation.getObjFrom();
- Set<String> valueList = result.get(key);
- if(CollUtil.isEmpty(valueList)) {
- valueList = new HashSet<>();
- result.put(key, valueList);
- }
- valueList.add(value);
- }
- }
-
- @Override
- public List<JSONObject> doQuerySpaceTypes(InstanceUrlParam context) {
-
- Map<String, String> codeNameMap = queryProjectDefineType(context);
- if(CollUtil.isNotEmpty(codeNameMap)){
-
- JSONArray demObjs = queryAndDealObjs(context, codeNameMap.keySet());
- if(CollUtil.isNotEmpty(demObjs)){
- List<AdmSpace> spaceList = JSONArray.parseArray(JSONUtil.toJsonStr(demObjs), AdmSpace.class);
- Set<String> classCodes = spaceList.stream().map(space -> space.getClassCode()).collect(Collectors.toSet());
- if(CollUtil.isNotEmpty(classCodes)){
- codeNameMap.keySet().removeIf(code -> !classCodes.contains(code));
- }
- }
- }
- if(CollUtil.isNotEmpty(codeNameMap)){
- List<JSONObject> list = new ArrayList<>(codeNameMap.size());
- codeNameMap.keySet().stream().forEach(code ->{
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("name",codeNameMap.get(code));
- jsonObject.put("code",code);
- list.add(jsonObject);
- });
- return list;
- }else{
- return null;
- }
- }
- private List<ObjectNode> queryObject(InstanceUrlParam context, QueryCriteria criteriaObject){
- JSONObject paraPe = null;
- String groupCode = AppContext.getContext().getGroupCode();
- String projectId = AppContext.getContext().getProjectId();
- List<ObjectNode> query = DigitalObjectFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, criteriaObject);
- return query;
- }
-
- private DmpResult<JSONArray> queryObj(InstanceUrlParam context, QueryCriteria criteriaObject){
- JSONObject paraPe = null;
- try {
- String paraStr = objectMapper.writeValueAsString(criteriaObject);
- paraPe = JSONObject.parseObject(paraStr);
- } catch (JsonProcessingException e) {
- throw new RuntimeException("转换查询条件出错:" + e.getMessage());
- }
- return rwdClient.queryObject(context, paraPe);
- }
- private QueryCriteria ensureQueryCommParm(QueryCriteria dmpRequest, InstanceUrlParam context, Collection<String> classCodes, String objType){
- ObjectNode criteriaEq = null;
- if(JSONUtil.isNull(dmpRequest.getCriteria())){
- criteriaEq = JsonNodeFactory.instance.objectNode();
- }else{
- criteriaEq = dmpRequest.getCriteria();
- }
- if(CollUtil.isNotEmpty(classCodes)){
- ArrayNode array = criteriaEq.putObject("classCode").putArray("$in");
- classCodes.forEach(code -> array.add(code));
- }
- criteriaEq.put("objType", objType);
- dmpRequest.setCriteria(criteriaEq);
- return dmpRequest;
- }
- private JSONArray queryAndDealObjs(InstanceUrlParam context, Set<String> codes){
- QueryCriteria criteriaObject = ensureQueryCommParm(new QueryCriteria(), context, codes,AdmSpace.OBJ_TYPE);
- criteriaObject.setSize(50L);
- DmpResult<JSONArray> dmpResult = queryObj(context, criteriaObject);
- if(CollUtil.isEmpty(dmpResult.getData())){
- return null;
- }
- JSONArray demObjs = dmpResult.getData();
- if(dmpResult.getCount() > criteriaObject.getSize()){
- for(int page = 2; page < dmpResult.getCount()/criteriaObject.getSize()+1; page++){
- criteriaObject.setPage(page*1L);
- demObjs.addAll(queryObj(context, criteriaObject).getData());
- }
- }
- return demObjs;
- }
- private Map<String, String> queryProjectDefineType(InstanceUrlParam context){
- Map<String, String> codeNameMap = null;
- ObjectNode criteriaEq = JsonNodeFactory.instance.objectNode();
- criteriaEq.put("projectId", context.getProjectId());
- criteriaEq.put("objType", AdmSpace.OBJ_TYPE);
- DmpResult<JSONArray> resultDef = queryDefineType(context, criteriaEq);
- if(resultDef.getResult().equals(DmpResult.SUCCESS) && CollUtil.isNotEmpty(resultDef.getData())){
- List<ObjectTypeDefine> defineList = JSONUtil.toList(resultDef.getData().toString(), ObjectTypeDefine.class);
- codeNameMap = defineList.stream().collect(Collectors.toMap(ObjectTypeDefine::getCode, ObjectTypeDefine::getName, (k1,k2)->k1));
- }
- return codeNameMap;
- }
-
- private List<ObjectNode> queryFloorsByFloorIds(InstanceUrlParam context, Collection<String> floolIds){
- QueryCriteria queryCriteria = ensureQueryCommParm(new QueryCriteria(),context, CollUtil.newArrayList("floor"),"floor");
- ObjectNode criteriaPe = queryCriteria.getCriteria();
- if(CollUtil.isNotEmpty(floolIds)){
- ArrayNode array = criteriaPe.putObject("id").putArray("$in");
- floolIds.forEach(floorId -> array.add(floorId));
- }
- JSONObject height = new JSONObject();
- height.put("$gt", 0f);
- criteriaPe.putPOJO("height", height);
- queryCriteria.setCriteria(criteriaPe);
- queryCriteria.setWithoutCount(true);
- return queryObject(context, queryCriteria);
- }
-
- private List<AdmSpace> processHeight(Map<String, List<AdmSpace>> spaceMapByFlId, List<ObjectNode> floorList){
- List<AdmSpace> resultList = new ArrayList<>();
- floorList.forEach(node -> {
- try {
- if (!node.has("id")
- || !node.get("id").isTextual()){
- return;
- }
- List<AdmSpace> spaces = spaceMapByFlId.get(node.get("id").asText());
- if (CollUtil.isEmpty(spaces)){
- return;
- }
- if(node.has("height")){
- String height = node.get("height").asText();
- if (StrUtil.isNotBlank(height)) {
- for (AdmSpace admSpace : spaces) {
- admSpace.setHeight(Float.parseFloat(height));
- resultList.add(admSpace);
- }
- }
- }
- } catch (Exception e) {}
- });
- return resultList;
- }
-
- private void processRelations(List<AdmSpace> vosR){
- if(CollUtil.isNotEmpty(vosR)) {
- List<RelationDTO> relationDTOS = new ArrayList<>(vosR.size());
- vosR.forEach(admSpace -> {
- if (StrUtil.isNotEmpty(admSpace.getBuildingId())) {
- relationDTOS.add(new RelationDTO("GtArchSubset001", "ArchSubset", "Bd2Sp", admSpace.getClassCode(), admSpace.getBuildingId(), admSpace.getId()));
- }
- if (StrUtil.isNotEmpty(admSpace.getFloorId())) {
- relationDTOS.add(new RelationDTO("GtArchSubset001", "ArchSubset", "Fl2Sp", admSpace.getClassCode(), admSpace.getFloorId(), admSpace.getId()));
- }
- });
- if (CollUtil.isNotEmpty(relationDTOS)) {
- relationService.doSave(AdmContextUtil.toDmpContext(), relationDTOS);
- }
- }
- }
-
- private void assembleDefineTypes(InstanceUrlParam context, List<JSONObject> defineList, String floorId){
- boolean needCount = true;
- defineList.stream().forEach(defineType -> {
-
- int count = needCount ? countSpace(context, defineType.getString("code"), floorId) : 0;
-
- assembleDefineObj(defineType, count, context.getProjectId());
- });
- }
-
- private void assembleDefineObj(JSONObject defineType, int count, String projectId){
- defineType.put("count", count);
- defineType.put("projectId", projectId);
- defineType.remove("aliasName");
- defineType.remove("aliasCode");
- defineType.remove("valid");
- defineType.remove("objType");
- defineType.remove("groupCode");
- defineType.remove("parentCode");
- defineType.remove("id");
- }
- private void addRelationTo(QueryCriteria rwdQueryCriteria, String objFrom, String relCode){
- ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
- relationTO.put("relCode", relCode);
- relationTO.put("graphCode", "ArchSubset");
- relationTO.put("objFrom", objFrom);
- ObjectNode criteria = rwdQueryCriteria.getCriteria();
- criteria.putPOJO("relationTo", relationTO);
- rwdQueryCriteria.setCriteria(criteria);
- }
-
- private int countSpace(InstanceUrlParam context, String classCode, String objFrom){
- QueryCriteria queryCriteria = ensureQueryCommParm(new QueryCriteria(), context, CollUtil.newArrayList(classCode),"space");
- addRelationTo(queryCriteria, objFrom,"Fl2Sp");
- queryCriteria.setOnlyCount(true);
- DmpResult<JSONArray> dmpResult = queryObj(context, queryCriteria);
- return dmpResult.getCount();
- }
- private DmpResult<JSONArray> queryDefineType(InstanceUrlParam context, ObjectNode criteriaEq){
- QueryCriteria criteriaObject = new QueryCriteria();
- criteriaObject.setCriteria(criteriaEq);
- JSONObject paraPe = null;
- try {
- String paraStr = objectMapper.writeValueAsString(criteriaObject);
- paraPe = JSONObject.parseObject(paraStr);
- } catch (JsonProcessingException e) {
- throw new RuntimeException("查询公共定义的空间类型,转换查询条件出错:" + e.getMessage());
- }
- return rwdClient.queryDefClass(context, paraPe);
- }
- }
|