123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- 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.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 org.apache.commons.lang.StringUtils;
- 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:系统下的设备设施
- * @author:lgy
- * @data:2021/9/3 15:25
- */
- @RestController
- @RequestMapping("/rel/sy-in-eq")
- public class RelationSyEqController {
- @Autowired
- private IAdmRelationService service;
- @Value("${middleware.group.code}")
- private String groupCode;
- /**
- * 创建系统下的设备关系,数据叠加,不会覆盖以前的数据
- * 必填项:EquipID(设备id)、SysID(系统id)
- * @param param
- * @return
- * @throws Exception
- */
- @PostMapping(value = {"/link-sy-eq","/link"})
- public AdmResponse create(@RequestBody JSONObject param) throws Exception {
- //String equipId = param.getString("equipId");
- JSONArray equipIdList = param.getJSONArray("equipIdList");
- String sysID = param.getString("sysId");
- if(StringUtils.isEmpty(sysID) || CollUtil.isEmpty(equipIdList)) {
- return AdmResponse.failure("必填项:EquipIdList(设备id列表)、SysID(系统id)");
- }
- // 创建关系对象
- List<RelationDTO> voList = new ArrayList<>();
- equipIdList.forEach(item->{
- voList.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null, sysID , item.toString()));
- });
- // 组装上下文条件
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- service.doSave(context, voList);
- return AdmResponse.success();
- }
- /**
- * 根据对象删除系统和设备的关系,只针对一个对象
- *必填项:EquipID(设备id)、SysID(系统id)
- * @param param 对象
- * @return 删除的结果信息
- */
- @PostMapping("/unlink")
- public AdmResponse delete(@RequestBody JSONObject param) throws Exception {
- if(CollUtil.isEmpty(param)) {
- return AdmResponse.success();
- }
- // 组装上下文条件
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- // 组装条件
- QueryCriteria criteria = new QueryCriteria();
- String equipId = param.getString("equipId");
- String sysID = param.getString("sysId");
- if(!StrUtil.isAllNotEmpty(equipId,sysID)) {
- return AdmResponse.failure("必填项:EquipID(设备id)、SysID(系统id)");
- }
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- node.put("graphCode", "MechSubset");
- node.put("relCode", "Sy2Eq");
- node.put("objFrom", sysID);
- node.put("objTo", equipId);
- criteria.setCriteria(node);
- service.doDelete(context, criteria);
- return AdmResponse.success();
- }
- /**
- * 创建系统下的设备关系
- *
- * @param syEqList 系统和设备的关系对象
- * @return 创建结果信息
- */
- @PostMapping("/link-eq")
- public AdmResponse createBatchWithDeleteOldsysIdRelation(@RequestBody JSONObject syEqList) throws Exception {
- JSONArray equipIdList = syEqList.getJSONArray("equipIdList");
- String sysId = syEqList.getString("sysId");
- if(StrUtil.isBlank(sysId) || CollUtil.isEmpty(equipIdList)) {
- return AdmResponse.failure("必填项:EquipIdList(设备id列表)、SysID(系统id)");
- }
- InstanceUrlParam context =AdmContextUtil.toDmpContext();
- QueryCriteria queryRequest = new QueryCriteria();
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- node.put("graphCode", "MechSubset");
- node.put("relCode", "Sy2Eq");
- node.put("objFrom", sysId);
- queryRequest.setCriteria(node);
- service.doDelete(context,queryRequest);
- // 创建关系对象
- List<RelationDTO> voList = new ArrayList<>();
- for (int i = 0; i < equipIdList.size(); i++) {
- voList.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null, sysId , equipIdList.getString(i)));
- }
- // 组装上下文条件
- service.doSave(context, voList);
- return AdmResponse.success();
- }
- /**
- * 创建系统下的设备关系
- *
- * @param param 系统和设备的关系对象
- * @return 创建结果信息
- */
- @PostMapping("/link-sy")
- public AdmResponse createDistinctEq(@RequestBody JSONObject param) throws Exception {
- String equipId = param.getString("equipId");
- JSONArray sysIdList = param.getJSONArray("sysIdList");
- if(StringUtils.isEmpty(equipId) || CollUtil.isEmpty(sysIdList)) {
- return AdmResponse.failure("必填项:EquipId(设备id)、sysIdList(系统id列表)");
- }
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- QueryCriteria queryRequest = new QueryCriteria();
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- node.put("graphCode", "MechSubset");
- node.put("relCode", "Sy2Eq");
- node.put("objTo", equipId);
- queryRequest.setCriteria(node);
- service.doDelete(context,queryRequest);
- // 创建关系对象
- List<RelationDTO> voList = new ArrayList<>();
- sysIdList.forEach(item->{
- voList.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null, item.toString() , equipId));
- });
- // 组装上下文条件
- service.doSave(context, voList);
- return AdmResponse.success();
- }
- /**
- * 根据对象删除系统和设备的关系
- *
- * @param entytyList 根据对象删除系统和设备的关系
- * @return 创建结果信息
- */
- public AdmResponse deleteBatch(@RequestBody JSONArray entytyList) {
- if(CollUtil.isEmpty(entytyList)) {
- return AdmResponse.success();
- }
- // 组装上下文条件
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- for (int i = 0; i < entytyList.size(); i++) {
- JSONObject entity = entytyList.getJSONObject(i);
- // 组装条件
- QueryCriteria criteria = new QueryCriteria();
- String equipId = entity.getString("equipId");
- String sysID = entity.getString("sysId");
- if(!StrUtil.isAllNotEmpty(equipId,sysID)) {
- continue;
- }
- ObjectNode node = JsonNodeFactory.instance.objectNode();
- node.put("graphCode", "MechSubset");
- node.put("relCode", "Sy2Eq");
- node.put("objFrom", sysID);
- node.put("objTo", equipId);
- criteria.setCriteria(node);
- service.doDelete(context, criteria);
- }
- return AdmResponse.success();
- }
- }
|