| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- package com.persagy.proxy.adm.controller;
- import cn.hutool.core.util.StrUtil;
- import com.fasterxml.jackson.databind.node.JsonNodeFactory;
- import com.fasterxml.jackson.databind.node.ObjectNode;
- import com.persagy.dmp.basic.model.QueryCriteria;
- import com.persagy.proxy.adm.constant.AdmCommonConstant;
- import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
- import com.persagy.proxy.adm.model.relation.*;
- import com.persagy.proxy.adm.request.AdmResponse;
- import com.persagy.proxy.adm.service.IAdmRelationService;
- import com.persagy.proxy.adm.utils.AdmContextUtil;
- import com.persagy.proxy.common.entity.InstanceUrlParam;
- import com.persagy.proxy.common.entity.RelationDTO;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.util.CollectionUtils;
- import org.springframework.web.bind.annotation.*;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * @author zhangwencheng
- * 系统所在建筑
- */
- @Slf4j
- @RestController
- @RequestMapping("/rel/sy-in-bd")
- public class RelationSyInBdController {
- @Autowired
- private IAdmRelationService service;
- @Value("${middleware.group.code}")
- private String groupCode;
- /**
- * 系统所在建筑
- *
- * @param syInBd
- * @param projectId
- * @return
- * @throws Exception
- */
- @PostMapping("/link")
- public AdmResponse create(@RequestBody SyInBd syInBd) throws Exception {
- log.info("创建系统所在建筑关系create方法开始参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
- //系统Id
- String sysID = syInBd.getSysId();
- //建筑Id
- String buildingId = syInBd.getBuildingId();
- if (StrUtil.isBlank(sysID) || StrUtil.isBlank(buildingId)) {
- return AdmResponse.failure("必填项:SysId(系统id)、BuildingId(建筑id)");
- }
- List<RelationDTO> voList = new ArrayList<>();
- AdmRelationTypeEnum sy2bdMechinarch = AdmRelationTypeEnum.SY2BD_MECHINARCH;
- String graphCode = sy2bdMechinarch.getGraphCode();
- String relCode = sy2bdMechinarch.getRelCode();
- RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysID, buildingId);
- voList.add(relation);
- // 组装上下文条件
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- service.doSave(context, voList);
- log.info("创建系统所在建筑create方法结束");
- return AdmResponse.success();
- }
- // /**
- // * 系统和楼层的关系对象
- // *
- // * @param syInFlList
- // * @param projectId
- // * @return
- // * @throws Exception
- // */
- // @PostMapping("/link-fl")
- // public AdmResponse createSy(@RequestBody SyInFlList syInFlList, @RequestParam("projectId") String projectId) throws Exception {
- // log.info("创建系统所在建筑关系create方法开始参数projectId为{}", projectId);
- // //系统Id
- // String sysID = syInFlList.getSysId();
- // //楼层
- // List<String> floors = syInFlList.getFloorIdList();
- // if (StringUtils.isBlank(sysID) || CollectionUtils.isEmpty(floors)) {
- // return AdmResponse.failure("必填项:SysId(系统id)、floorIdList(楼层)");
- // }
- // List<RelationDTO> voList = new ArrayList<>();
- // for (String floorId : floors) {
- // //todo graphCode
- // RelationDTO relation = new RelationDTO(null, "MechInArch", "Eq2Sp", null, sysID, floorId);
- // voList.add(relation);
- // }
- // // 组装上下文条件
- // InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- // service.doSave(context, voList);
- // log.info("创建系统服务于业务空间关系create方法结束");
- // return AdmResponse.success();
- // }
- /**
- * 创建系统所在建筑关系
- * @param syInFlList
- * @param projectId
- * @return
- * @throws Exception
- */
- @PostMapping("/link-bd")
- public AdmResponse createBd(@RequestBody SyInBdList syInFlList) throws Exception {
- log.info("创建系统所在建筑关系createBD方法开始参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
- //系统Id
- String sysID = syInFlList.getSysId();
- //楼层
- List<String> builds = syInFlList.getBuildingIdList();
- if (StringUtils.isBlank(sysID) || CollectionUtils.isEmpty(builds)) {
- return AdmResponse.failure("必填项:SysId(系统id)、buildingIdList(建筑Id)");
- }
- List<RelationDTO> voList = new ArrayList<>();
- AdmRelationTypeEnum sy2bdMechinarch = AdmRelationTypeEnum.SY2BD_MECHINARCH;
- String graphCode = sy2bdMechinarch.getGraphCode();
- String relCode = sy2bdMechinarch.getRelCode();
- for (String buildId : builds) {
- RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysID, buildId);
- voList.add(relation);
- }
- // 组装上下文条件
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- service.doSave(context, voList);
- log.info("创建系统所在建筑关系createBD方法结束");
- return AdmResponse.success();
- }
- /**
- * 创建系统所在建筑关系 同上
- * @param syInFlList
- * @param projectId
- * @return
- * @throws Exception
- */
- @PostMapping("/link-bd-sy")
- public AdmResponse createSyBd(@RequestBody SyInBdList syInFlList) throws Exception {
- log.info("创建系统所在建筑关系createSyBd方法开始参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
- //系统Id
- String sysID = syInFlList.getSysId();
- //楼层
- List<String> builds = syInFlList.getBuildingIdList();
- if (StringUtils.isBlank(sysID) || CollectionUtils.isEmpty(builds)) {
- return AdmResponse.failure("必填项:SysId(系统id)、buildingIdList(建筑Id)");
- }
- List<RelationDTO> voList = new ArrayList<>();
- AdmRelationTypeEnum sy2bdMechinarch = AdmRelationTypeEnum.SY2BD_MECHINARCH;
- String graphCode = sy2bdMechinarch.getGraphCode();
- String relCode = sy2bdMechinarch.getRelCode();
- for (String buildId : builds) {
- RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysID, buildId);
- voList.add(relation);
- }
- // 组装上下文条件
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- service.doSave(context, voList);
- log.info("创建系统所在建筑关系createSyBd方法结束");
- return AdmResponse.success();
- }
- /**
- * 创建所在建筑的系统关系
- * @param bdInSyList
- * @param projectId
- * @return
- * @throws Exception
- */
- @PostMapping("/link-sy")
- public AdmResponse createSyBd(@RequestBody BdInSyList bdInSyList) throws Exception {
- log.info("创建系统所在建筑关系createSyBd方法开始参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
- //建筑Id
- String buildingId = bdInSyList.getBuildingId();
- //系统
- List<String> sysIdList = bdInSyList.getSysIdList();
- if (StringUtils.isBlank(buildingId) || CollectionUtils.isEmpty(sysIdList)) {
- return AdmResponse.failure("必填项:buildingId(建筑id)、sysIdList(系统Id)");
- }
- List<RelationDTO> voList = new ArrayList<>();
- AdmRelationTypeEnum sy2bdMechinarch = AdmRelationTypeEnum.SY2BD_MECHINARCH;
- String graphCode = sy2bdMechinarch.getGraphCode();
- String relCode = sy2bdMechinarch.getRelCode();
- for (String sysId : sysIdList) {
- RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysId, buildingId);
- voList.add(relation);
- }
- // 组装上下文条件
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- service.doSave(context, voList);
- log.info("创建系统所在建筑关系createSyBd方法结束");
- return AdmResponse.success();
- }
- /**
- * 系统所在建筑
- *
- * @param syInBd
- * @param projectId
- * @return
- * @throws Exception
- */
- @PostMapping("/unlink")
- public AdmResponse delete(@RequestBody SyInBd syInBd) throws Exception {
- log.info("创建系统所在建筑关系delete方法开始参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
- //系统Id
- String sysID = syInBd.getSysId();
- //建筑Id
- String buildingId = syInBd.getBuildingId();
- if (StrUtil.isBlank(sysID) || StrUtil.isBlank(buildingId)) {
- return AdmResponse.failure("必填项:SysId(系统id)、BuildingId(建筑id)");
- }
- QueryCriteria criteria = new QueryCriteria();
- // RelationDTO relation = new RelationDTO(null, "MechInArch", "Eq2Sp", null, sysID, buildingId);
- AdmRelationTypeEnum sy2bdMechinarch = AdmRelationTypeEnum.SY2BD_MECHINARCH;
- String graphCode = sy2bdMechinarch.getGraphCode();
- String relCode = sy2bdMechinarch.getRelCode();
- // 组装上下文条件
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- node.put("graphCode", graphCode);
- node.put("relCode", relCode);
- // node.put("relValue", );
- node.put("objFrom", sysID);
- node.put("objTo", buildingId);
- criteria.setCriteria(node);
- // 组装上下文条件
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- service.doDelete(context,criteria);
- log.info("创建系统服务于业务空间关系delete方法结束");
- return AdmResponse.success();
- }
- }
|