123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package com.persagy.proxy.adm.controller;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.collection.CollectionUtil;
- 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.proxy.adm.constant.AdmCommonConstant;
- import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
- import com.persagy.proxy.adm.model.AdmFloor;
- import com.persagy.proxy.adm.model.AdmRelationAddRequest;
- 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.common.entity.InstanceUrlParam;
- import com.persagy.proxy.common.entity.RelationDTO;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.util.CollectionUtils;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import javax.ws.rs.QueryParam;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * @author zhangwencheng
- * 系统服务于业务空间
- */
- @Slf4j
- @RestController
- @RequestMapping("/rel/sy-for-sp-base")
- public class RelationSyForSpController {
- @Autowired
- private IAdmRelationService service;
- @Value("${middleware.group.code}")
- private String groupCode;
- /**
- * 创建系统服务于业务空间关系
- *
- * @param rSyForSpBase
- * @param projectId
- * @return
- * @throws Exception
- */
- @PostMapping("/link")
- public AdmResponse create(@RequestBody SyForSpBase rSyForSpBase, @RequestParam("projectId") String projectId) throws Exception {
- log.info("创建系统服务于业务空间关系create方法开始参数projectId为{}", projectId);
- //系统Id
- String sysID = rSyForSpBase.getSysId();
- //业务空间Id
- String spaceId = rSyForSpBase.getSpaceId();
- if (StrUtil.isBlank(sysID) || StrUtil.isBlank(spaceId)) {
- return AdmResponse.failure("必填项:sysID(系统id)、SpaceId(业务空间id)");
- }
- AdmRelationTypeEnum sy2spFor = AdmRelationTypeEnum.SY2SP_FOR;
- String graphCode = sy2spFor.getGraphCode();
- String relCode = sy2spFor.getRelCode();
- List<RelationDTO> voList = new ArrayList<>();
- RelationDTO relation = new RelationDTO(null, graphCode, relCode, rSyForSpBase.getObjectType(), sysID, spaceId);
- voList.add(relation);
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- service.doSave(context, voList);
- log.info("创建系统服务于业务空间关系create方法结束");
- return AdmResponse.success();
- }
- /**
- * 系统服务于业务空间关系,系统一对多
- *
- * @return
- * @throws Exception
- */
- @PostMapping("/link-sp")
- public AdmResponse createSp(@RequestBody SyForSpBaseList syForSpBaseList, @RequestParam("projectId") String projectId) throws Exception {
- log.info("创建系统空间关系createSp开始");
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- List<String> spaceIdList = syForSpBaseList.getSpaceIdList();
- String sysId = syForSpBaseList.getSysId();
- List<RelationDTO> voList = new ArrayList<>();
- AdmRelationTypeEnum sy2spFor = AdmRelationTypeEnum.SY2SP_FOR;
- String graphCode = sy2spFor.getGraphCode();
- String relCode = sy2spFor.getRelCode();
- //校验输入参数
- if (CollectionUtils.isEmpty(spaceIdList) || StringUtils.isEmpty(sysId)) {
- return AdmResponse.failure("必填项:SpaceIdList(业务空间id列表)、SysID(系统id)");
- }
- for (String spaceId : spaceIdList) {
- RelationDTO relation = new RelationDTO(null, graphCode, relCode, "", sysId, spaceId);
- voList.add(relation);
- }
- service.doSave(context, voList);
- log.info("创建系统空间关系createSp结束");
- return AdmResponse.success();
- }
- /**
- * 服务于业务空间的系统,业务空间一对多
- *
- * @param spForSyBaseList
- * @param projectId
- * @return
- * @throws Exception
- */
- @PostMapping("/link-sy")
- public AdmResponse createSy(@RequestBody SpForSyBaseList spForSyBaseList, @RequestParam("projectId") String projectId) throws Exception {
- log.info("创建系统空间关系业务空间一对多link-sy开始");
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- List<String> sysIdList = spForSyBaseList.getSysIdList();
- String spaceId = spForSyBaseList.getSpaceId();
- List<RelationDTO> voList = new ArrayList<>();
- if (CollectionUtils.isEmpty(sysIdList) || StringUtils.isEmpty(spaceId)) {
- return AdmResponse.failure("必填项:spaceId业务空间id,SysIDList(系统id列表))");
- }
- AdmRelationTypeEnum sy2spFor = AdmRelationTypeEnum.SY2SP_FOR;
- String graphCode = sy2spFor.getGraphCode();
- String relCode = sy2spFor.getRelCode();
- for (String sysId: sysIdList) {
- RelationDTO relation = new RelationDTO(null, graphCode, relCode, "", sysId, spaceId);
- voList.add(relation);
- }
- service.doSave(context, voList);
- log.info("创建系统空间关系业务空间一对多link-sy结束");
- return AdmResponse.success();
- }
- /**
- * 根据对象删除系统服务于业务空间关系,只针对一个对象
- * @param syForSpBase
- * @param projectId
- * @return
- * @throws Exception
- */
- @PostMapping("/unlink")
- public AdmResponse delete(@RequestBody SyForSpBase syForSpBase, @RequestParam("projectId") String projectId) throws Exception {
- log.info("创建系统服务于业务空间关系create方法开始参数projectId为{}", projectId);
- //系统Id
- String sysID = syForSpBase.getSysId();
- //业务空间Id
- String spaceId = syForSpBase.getSpaceId();
- if (StrUtil.isBlank(sysID) || StrUtil.isBlank(spaceId)) {
- return AdmResponse.failure("必填项:sysID(系统id)、SpaceId(业务空间id)");
- }
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- QueryCriteria criteria = new QueryCriteria();
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- AdmRelationTypeEnum sy2spFor = AdmRelationTypeEnum.SY2SP_FOR;
- String graphCode = sy2spFor.getGraphCode();
- String relCode = sy2spFor.getRelCode();
- node.put("graphCode", graphCode);
- node.put("relCode", relCode);
- // node.put("relValue", syForSpBase.getObjectType());
- node.put("objFrom", sysID);
- node.put("objTo", spaceId);
- criteria.setCriteria(node);
- service.doDelete(context, criteria);
- log.info("创建系统服务于业务空间关系create方法结束");
- return AdmResponse.success();
- }
- }
|