123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- package com.persagy.proxy.adm.controller;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.fasterxml.jackson.databind.node.JsonNodeFactory;
- import com.fasterxml.jackson.databind.node.ObjectNode;
- import com.persagy.dmp.basic.model.QueryCriteria;
- import com.persagy.dmp.digital.entity.ObjectRelation;
- import com.persagy.proxy.adm.constant.AdmCommonConstant;
- import com.persagy.proxy.adm.request.AdmResponse;
- import com.persagy.proxy.adm.service.IAdmRelationService;
- import com.persagy.proxy.common.client.DmpRwdClient;
- import com.persagy.proxy.common.entity.InstanceUrlParam;
- import com.persagy.proxy.common.entity.RelationDTO;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.*;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * @description:026、关系-系统服务于建筑
- * @author:lgy
- * @data:2021/9/24 20:29
- */
- @RestController
- @RequestMapping("/rel/sy-for-bd")
- public class RelationSyForBdController {
- @Autowired
- private IAdmRelationService service;
- @Autowired
- DmpRwdClient rwdClient;
- @Value("${middleware.group.code}")
- private String groupCode;
- /**
- * 默认图类型
- */
- public static String DEFAULT_GRAPH_CODE = "MechForArch";
- /**
- * 默认边类型
- */
- public static String DEFAULT_REL_CODE = "Sy2Bd";
- /**
- * 创建系统服务于建筑关系
- * @param param
- * @return
- * @throws Exception
- */
- @PostMapping(value = {"/link"})
- public AdmResponse create(@RequestParam("projectId") String projectId,
- @RequestBody JSONObject param) throws Exception {
- String sysId = param.getString("sysId");
- String buildingId = param.getString("buildingId");
- if(!StrUtil.isAllNotEmpty(buildingId,sysId)) {
- return AdmResponse.failure("必填项:SysId(系统id)、BuildingId(建筑id)");
- }
- // 创建关系对象
- List<RelationDTO> voList = new ArrayList<>();
- voList.add(new RelationDTO(null, DEFAULT_GRAPH_CODE, DEFAULT_REL_CODE, null, sysId , buildingId));
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- service.doSave(context, voList);
- return AdmResponse.success();
- }
- /**
- * 根据对象删除关系
- * 根据对象删除系统服务于建筑的关系,只针对一个对象
- * @param param 对象
- * @return 删除的结果信息
- */
- @PostMapping("/unlink")
- public AdmResponse delete(@RequestParam String projectId,
- @RequestBody JSONObject param) throws Exception {
- if(CollUtil.isEmpty(param)) {
- return AdmResponse.success();
- }
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- // 组装条件
- QueryCriteria criteria = new QueryCriteria();
- String sysId = param.getString("sysId");
- String buildingId = param.getString("buildingId");
- if(!StrUtil.isAllNotEmpty(buildingId,sysId)) {
- return AdmResponse.failure("必填项:SysId(系统id)、BuildingId(建筑id)");
- }
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- node.put("graphCode", DEFAULT_GRAPH_CODE);
- node.put("relCode", DEFAULT_REL_CODE);
- node.put("objFrom", sysId);
- node.put("objTo",buildingId);
- criteria.setCriteria(node);
- service.doDelete(context, criteria);
- return AdmResponse.success();
- }
- /**
- * 创建系统服务于建筑关系
- * 系统服务于建筑,系统一对多
- * @param param
- * @return 创建的结果信息
- */
- @PostMapping("/link-shsps")
- public AdmResponse createBd(@RequestParam("projectId") String projectId,
- @RequestBody JSONObject param) throws Exception {
- String sysId = param.getString("sysId");
- JSONArray buildingIdList = param.getJSONArray("buildingIdList");
- if(StrUtil.isBlank(sysId) || CollUtil.isEmpty(buildingIdList)) {
- return AdmResponse.failure("必填项:BuildingIdList(建筑id列表)、SysId(系统id),测方法会覆盖以前的记录");
- }
- // 创建关系对象.先删除,后添加
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- QueryCriteria queryRequestTmp = new QueryCriteria();
- ObjectNode nodeTmp = JsonNodeFactory.instance.objectNode();
- nodeTmp.put("graphCode", DEFAULT_GRAPH_CODE);
- nodeTmp.put("relCode", DEFAULT_REL_CODE);
- nodeTmp.put("objFrom", sysId);
- queryRequestTmp.setCriteria(nodeTmp);
- //关系之前的关系,并且删除
- List<ObjectRelation> objectRelations = service.queryByCondition(context, queryRequestTmp);
- for (ObjectRelation objectRelation : objectRelations) {
- QueryCriteria queryRequest = new QueryCriteria();
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- node.put("graphCode", objectRelation.getGraphCode());
- node.put("relCode", objectRelation.getRelCode());
- node.put("relValue", objectRelation.getRelValue());
- node.put("objFrom", objectRelation.getObjFrom());
- node.put("objTo", objectRelation.getObjTo());
- queryRequest.setCriteria(node);
- service.doDelete(context, queryRequest);
- }
- List<RelationDTO> voList = new ArrayList<>();
- for(int i = 0;i < buildingIdList.size();i++) {
- String buildingId = buildingIdList.getString(i);
- if(StrUtil.isBlank(buildingId)) {
- continue;
- }
- voList.add(new RelationDTO(null, DEFAULT_GRAPH_CODE, DEFAULT_REL_CODE, null, sysId, buildingId));
- }
- // 组装上下文条件
- service.doSave(context, voList);
- return AdmResponse.success();
- }
- /**
- * 服务于建筑的系统,建筑一对多
- * @param param
- * @return 创建的结果信息
- */
- @PostMapping("/link-sy")
- public AdmResponse createSy(@RequestParam("projectId") String projectId,
- @RequestBody JSONObject param) throws Exception {
- String buildingId = param.getString("buildingId");
- JSONArray sysIdList = param.getJSONArray("sysIdList");
- if(StrUtil.isBlank(buildingId) || CollUtil.isEmpty(sysIdList)) {
- return AdmResponse.failure("必填项:sysIdList(系统id列表)、BuildingId(建筑id),测方法会覆盖以前的记录");
- }
- // 创建关系对象.先删除,后添加
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- QueryCriteria queryRequestTmp = new QueryCriteria();
- ObjectNode nodeTmp = JsonNodeFactory.instance.objectNode();
- nodeTmp.put("graphCode", DEFAULT_GRAPH_CODE);
- nodeTmp.put("relCode", DEFAULT_REL_CODE);
- nodeTmp.put("objTo", buildingId);
- queryRequestTmp.setCriteria(nodeTmp);
- //关系之前的关系,并且删除
- List<ObjectRelation> objectRelations = service.queryByCondition(context, queryRequestTmp);
- for (ObjectRelation objectRelation : objectRelations) {
- QueryCriteria queryRequest = new QueryCriteria();
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- node.put("graphCode", objectRelation.getGraphCode());
- node.put("relCode", objectRelation.getRelCode());
- node.put("relValue", objectRelation.getRelValue());
- node.put("objFrom", objectRelation.getObjFrom());
- node.put("objTo", objectRelation.getObjTo());
- queryRequest.setCriteria(node);
- service.doDelete(context, queryRequest);
- }
- List<RelationDTO> voList = new ArrayList<>();
- for(int i = 0;i < sysIdList.size();i++) {
- String sysId = sysIdList.getString(i);
- if(StrUtil.isBlank(sysId)) {
- continue;
- }
- voList.add(new RelationDTO(null, DEFAULT_GRAPH_CODE, DEFAULT_REL_CODE, null, sysId, buildingId));
- }
- // 组装上下文条件
- service.doSave(context, voList);
- return AdmResponse.success();
- }
- }
|