123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- package com.persagy.proxy.adm.controller;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.json.JSONUtil;
- import com.alibaba.fastjson.JSONObject;
- 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.basic.utils.JsonNodeUtils;
- 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.simple.client.DigitalObjectSimpleFacade;
- import com.persagy.proxy.adm.model.*;
- 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.IAdmBuildingService;
- import com.persagy.proxy.adm.service.IAdmRelationService;
- import com.persagy.proxy.adm.service.IAdmShaftService;
- import com.persagy.proxy.adm.utils.AdmContextUtil;
- import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
- import com.persagy.proxy.adm.utils.ObjectNameUtil;
- import com.persagy.proxy.common.entity.RelationDTO;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import javax.ws.rs.QueryParam;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * Adm 竖井 API
- * @author lvxy
- * @date 2021/8/16
- */
- @RestController
- @RequestMapping("/object/shaft")
- public class AdmShaftController {
- @Autowired
- private IAdmShaftService service;
- @Autowired
- private IAdmRelationService relationService;
- @Autowired
- private IAdmBuildingService buildingService;
- /**
- * 统计
- *
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/count")
- public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
- request.setName("shaft");
- request.setOnlyCount(true);
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmShaft.class);
- }
- /**
- * 创建
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/create")
- public AdmResponse create(@RequestBody AdmCreateRequest<AdmShaft> createRequest, @QueryParam("projectId") String projectId) throws Exception {
- List<AdmShaft> vos = CollUtil.newArrayList(createRequest.getContent());
- vos.stream().forEach(admShaft -> {
- if (StrUtil.isEmpty(admShaft.getName())) {
- admShaft.setName(ObjectNameUtil.objectName("竖井-"));
- }
- });
- vos = service.doInsert(AdmContextUtil.toDmpContext(), AdmShaft.class, vos);
- //TODO 创建竖井和建筑的关系
- /*if (!entity.buildingList.isNullOrEmpty()){
- for (building in entity.buildingList!!) {
- try {
- val rShInBd = RShInBd()
- rShInBd.buildingId = building.id
- rShInBd.shaftId = entity.id
- rShInBd.projectId = entity.projectId
- rShInBd.type = "bd2sh"
- val insert = rShInBdService.insert(rShInBd)
- if (insert) {
- try {
- *//** 发送消息 *//*
- RService.rabbitMqService.sendRel(Opt.projectId!!, "sh2bd","11",rShInBd.buildingId!!,rShInBd.shaftId!!)
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }
- }*/
- return AdmResponse.success(vos);
- }
- /**
- * 根据ID删除
- * @param vos
- * @return
- * @throws Exception
- */
- @PostMapping("/delete")
- public AdmResponse delete( @RequestBody List<AdmShaft> vos) throws Exception {
- service.doDelete(AdmContextUtil.toDmpContext(), vos);
- return AdmResponse.success();
- }
- /**
- * 更新
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/update")
- public AdmResponse update(@RequestBody AdmCreateRequest<AdmShaft> createRequest, @QueryParam("projectId") String projectId) throws Exception {
- List<AdmShaft> vos = CollUtil.newArrayList(createRequest.getContent());
- vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmShaft.class, vos);
- return AdmResponse.success(vos);
- }
- /**
- * 查询
- *
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/query")
- public AdmResponse query(@RequestBody AdmQueryCriteria request) throws Exception {
- request.setName(AdmShaft.OBJ_TYPE);
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmShaft.class);
- }
- /**
- * 查询竖井信息-包含统计信息
- * 此方法可能会弃用
- *
- * 暂不实现
- *
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/query-with-count")
- public AdmResponse queryWithCount(@RequestBody AdmQueryCriteria request) throws Exception {
- request.setName("shaft");
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmShaft.class);
- }
- /**
- * 查询关联元空间
- * 可能移至关系
- *
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/relate-space")
- public AdmResponse queryRelateSp(@RequestBody JSONObject request) throws Exception {
- //Sh2Sp
- // 先取消后重新建立
- if(JSONUtil.isNull(request)){
- return AdmResponse.failure("参数为空");
- }
- String shaftId = request.getString("shaftId");
- String spaceId = request.getString("spaceId");
- // 组装条件
- QueryCriteria criteria = new QueryCriteria();
- if(!StrUtil.isAllNotEmpty(shaftId,spaceId)) {
- return AdmResponse.failure("必填项:shaftId(竖井id)、spaceId(空间id)");
- }
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- node.put("graphCode", "ArchSubset");
- node.put("relCode", "Sh2Sp");
- node.put("objFrom", shaftId);
- criteria.setCriteria(node);
- relationService.doDelete(AdmContextUtil.toDmpContext(), criteria);
- List<String> spaceIds = Arrays.asList(spaceId.split(","));
- Set<String> existsIds = spaceExists(spaceIds);
- List<String> failureList = null;
- if(CollUtil.isNotEmpty(existsIds)){
- failureList = spaceIds.stream().filter(isId -> !existsIds.contains(isId)).collect(Collectors.toList());
- List<RelationDTO> relationDTOS = new ArrayList<>();
- existsIds.stream().forEach(spId -> {
- RelationDTO relationDTO = new RelationDTO();
- relationDTO.setGraphCode("ArchSubset");
- relationDTO.setObjFrom(shaftId);
- relationDTO.setRelCode("Sh2Sp");
- relationDTO.setObjTo(spId);
- relationDTOS.add(relationDTO);
- });
- List<ObjectNode> nodeList = JsonNodeUtils.toListNode(relationDTOS, null, null);
- DigitalRelationFacade.create(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(),AdmContextUtil.toDmpContext().getAppId(), null, nodeList);
- }else{
- failureList = spaceIds;
- }
- if(CollUtil.isNotEmpty(failureList))
- return AdmResponse.failure("元空间 " +failureList.stream().collect(Collectors.joining(","))+ " 不存在");
- else
- return AdmResponse.success();
- }
- /**
- * 查询项目下已有的竖井类型
- * 此方法可能会弃用
- * {
- * "id":"shaftFuncType",
- * "name":"竖井功能"
- * }
- *
- * @return
- * @throws Exception
- */
- @PostMapping("/query-shaft-functype")
- public AdmResponse queryShFuncType() throws Exception {
- String projectId = AdmContextUtil.toDmpContext().getProjectId();
- if(StrUtil.isNotEmpty(projectId)){
- AdmResponse admResponse = AdmResponse.success();
- //查询参数请求查询的类型是否存在
- AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
- StringBuilder filters = new StringBuilder(" code = '");
- filters.append("shaftFuncType").append("';");
- filters.append(" classCode ='").append("shaft").append(" '");
- admQueryCriteria.setFilters(filters.toString());
- QueryCriteria dmpRequest = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteria);
- List<ObjectInfoDefine> defineList = DigitalObjectInfoFacade.query(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmContextUtil.toDmpContext().getAppId(),null,dmpRequest);
- //是否有该类型的竖井信息
- if(CollUtil.isNotEmpty(defineList)){
- //查询中台项目实际使用该信息点的竖井
- RequestData requestData = new RequestData();
- requestData.setObjType(AdmShaft.OBJ_TYPE);
- requestData.setGroups(Arrays.asList("shaftFuncType"));
- List<Map<String, Object>> listInfos = DigitalObjectSimpleFacade.queryObjectCountByObjInfos(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getAppId(),null, requestData);
- if(CollUtil.isNotEmpty(listInfos)){
- ArrayNode datasource = defineList.get(0).getDataSource();
- List<HashMap> datasourceList = JSONUtil.toList(datasource.toString(), HashMap.class);
- Map<String, String> datasourceMap = new HashMap<>(datasourceList.size());
- for (HashMap map : datasourceList){
- datasourceMap.put(map.get("code").toString(),map.get("name").toString());
- }
- Map<String, Object> datasourceMapUsed = new HashMap<>(datasourceMap.size());
- listInfos.stream().forEach(map -> {
- if(!datasourceMapUsed.containsKey(map.get("shaftFuncType")) || datasourceMap.containsKey(map.get("shaftFuncType"))){
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("id", map.get("shaftFuncType").toString());
- jsonObject.put("name", datasourceMap.get(map.get("shaftFuncType").toString()));
- datasourceMapUsed.put(map.get("shaftFuncType").toString(),jsonObject);
- }
- });
- if(CollUtil.isNotEmpty(datasourceMapUsed)){
- admResponse = AdmResponse.success(Arrays.asList(datasourceMapUsed.values()));
- }
- }
- }
- return admResponse;
- }else{
- return AdmResponse.failure("项目Id为空");
- }
- }
- /**
- * 查询和当前竖井有关联的业务空间
- * shaftId 为竖井id
- *
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/shaft-zoneSpaceBaseTable")
- public AdmResponse queryZoneSp(@RequestParam String shaftId,
- @RequestBody AdmQueryCriteria request) throws Exception {
- // 组装条件
- QueryCriteria queryCriteria = new QueryCriteria();
- if(!StrUtil.isAllNotEmpty(shaftId,AdmContextUtil.toDmpContext().getProjectId())) {
- return AdmResponse.failure("必填项:shaftId(竖井id)、projectId(项目id)");
- }
- ObjectNode criteria = JsonNodeFactory.instance.objectNode();
- ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
- relationTO.put("relCode", "Sh2Sp");
- relationTO.put("objFrom", shaftId);
- criteria.putPOJO("relationTo", relationTO);
- criteria.put("objType", AdmSpace.OBJ_TYPE);
- queryCriteria.setCriteria(relationTO);
- List<ObjectNode> spaceList = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmContextUtil.toDmpContext().getAppId(), null, queryCriteria);
- if(CollUtil.isNotEmpty(spaceList)){
- List<AdmSpace> vos = JSONUtil.toList(spaceList.toString(), AdmSpace.class);
- return AdmResponse.success(spaceList);
- }else{
- return AdmResponse.success();
- }
- }
- /**
- * 查询和当前竖井有关联的业务空间所在建筑及楼层信息
- * shaftId 为竖井id
- *
- * @return
- * @throws Exception
- */
- @PostMapping("/shaft-zoneSpaceBaseTable-building")
- public AdmResponse queryZoneSpBd( @RequestParam String shaftId,
- @RequestParam String objectType) throws Exception {
- if(!StrUtil.isAllNotEmpty(shaftId,AdmContextUtil.toDmpContext().getProjectId())) {
- return AdmResponse.failure("必填项:shaftId(竖井id)、projectId(项目id)");
- }
- // 组装条件 查询竖井下的空间
- AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
- admQueryCriteria.setName(AdmSpace.OBJ_TYPE);
- if(StrUtil.isNotEmpty(objectType)){
- admQueryCriteria.setFilters(" classCode = '"+objectType+"'");
- }
- //转化为中台的查询条件
- QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteria);
- ObjectNode criteria = JsonNodeFactory.instance.objectNode();
- ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
- relationTO.put("relCode", "Sh2Sp");
- relationTO.put("objFrom", shaftId);
- criteria.putPOJO("relationTo", relationTO);
- criteria.put("objType", AdmSpace.OBJ_TYPE);
- queryCriteria.setCriteria(criteria);
- List<ObjectNode> spaceList = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmContextUtil.toDmpContext().getAppId(), null, queryCriteria);
- if(CollUtil.isNotEmpty(spaceList)){
- AdmQueryCriteria queryCriteriaBd = new AdmQueryCriteria();
- queryCriteriaBd.setName(AdmBuilding.OBJ_TYPE);
- queryCriteriaBd.setProjection(Arrays.asList("id","name","localName","floor"));
- //建筑级联楼层
- List<AdmQueryCriteria> cascade = new ArrayList<>(1);
- AdmQueryCriteria cascadeFloor = new AdmQueryCriteria();
- cascadeFloor.setName(AdmFloor.OBJ_TYPE);
- cascadeFloor.setProjection(Arrays.asList("id","name","localName"));
- cascade.add(cascadeFloor);
- cascadeFloor.setOrders("floorSequenceId desc");
- queryCriteriaBd.setCascade(cascade);
- List<AdmSpace> vos = JSONUtil.toList(spaceList.toString(), AdmSpace.class);
- Map<String, AdmSpace> admSpaceMap = CollUtil.fieldValueMap(vos, "buildingId");
- StringBuilder filter = new StringBuilder(" id in ['");
- admSpaceMap.keySet().stream().forEach(spaceId -> filter.append(spaceId).append("','"));
- String filters = StrUtil.sub(filter.toString(), 0,-2)+"]";
- queryCriteriaBd.setFilters(filters);
- AdmResponse response = buildingService.doQuery(AdmContextUtil.toDmpContext(), queryCriteriaBd, AdmBuilding.class);
- return response;
- }else{
- return AdmResponse.success();
- }
- }
- /**
- * 查询和当前竖井没有关联的业务空间
- * shaftId 为竖井id
- *
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/un-shaft-zoneSpaceBaseTable")
- public AdmResponse queryUnZoneSp( @RequestParam String shaftId,
- @RequestBody AdmQueryCriteria request) throws Exception {
- // 组装条件
- QueryCriteria queryCriteria = new QueryCriteria();
- if(!StrUtil.isAllNotEmpty(shaftId,AdmContextUtil.toDmpContext().getProjectId())) {
- return AdmResponse.failure("必填项:shaftId(竖井id)、projectId(项目id)");
- }
- ObjectNode criteria = JsonNodeFactory.instance.objectNode();
- ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
- ArrayNode arrayNode = relationTO.putObject("objFrom").putArray("$notcontains");
- arrayNode.add(shaftId);
- relationTO.put("relCode", "Sh2Sp");
- criteria.putPOJO("relationTo", relationTO);
- criteria.put("objType", "space");
- queryCriteria.setCriteria(relationTO);
- List<ObjectNode> spaceList = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmContextUtil.toDmpContext().getAppId(), null, queryCriteria);
- if(CollUtil.isNotEmpty(spaceList)){
- List<AdmSpace> vos = JSONUtil.toList(spaceList.toString(), AdmSpace.class);
- return AdmResponse.success(spaceList);
- }else{
- return AdmResponse.success();
- }
- }
- /**
- * 元空间是否存在
- *
- * @param spaceIds failureList
- * @return 是否存在
- */
- private Set<String> spaceExists(List<String> spaceIds) {
- QueryCriteria queryCriteria = new QueryCriteria();
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- ArrayNode arrayNode = node.putObject("id").putArray("$in");
- spaceIds.stream().forEach(spaceId -> arrayNode.add(spaceId));
- node.put("objType","ispace");
- queryCriteria.setCriteria(node);
- List<ObjectNode> ispaces = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmContextUtil.toDmpContext().getAppId(),AdmContextUtil.toDmpContext().getAppId(),queryCriteria);
- if(CollUtil.isNotEmpty(ispaces)){
- List<AdmISpace> iSpaceList = JSONUtil.toList(JSONUtil.parseArray(ispaces.toString()), AdmISpace.class);
- Map<String, AdmISpace> admISpaceMap = CollUtil.fieldValueMap(iSpaceList, BaseEntity.PROP_ID);
- return admISpaceMap.keySet();
- }else{
- return null;
- }
- }
- }
|