|
@@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
-import com.persagy.adm.diagram.client.RwdClient;
|
|
|
import com.persagy.adm.diagram.core.DataStrategy;
|
|
|
import com.persagy.adm.diagram.core.model.Diagram;
|
|
|
import com.persagy.adm.diagram.core.model.legend.Legend;
|
|
@@ -20,12 +19,13 @@ import com.persagy.adm.diagram.util.ServiceUtil;
|
|
|
import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
import com.persagy.dmp.basic.model.QueryOperator;
|
|
|
import com.persagy.dmp.basic.utils.JsonNodeUtils;
|
|
|
+import com.persagy.dmp.common.constant.ResponseCode;
|
|
|
+import com.persagy.dmp.common.exception.BusinessException;
|
|
|
import com.persagy.dmp.digital.client.DigitalObjectFacade;
|
|
|
import com.persagy.dmp.digital.client.DigitalRelationFacade;
|
|
|
import com.persagy.dmp.digital.entity.ObjectRelation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
-import org.springframework.cloud.client.discovery.DiscoveryClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
@@ -33,11 +33,15 @@ import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-
|
|
|
+/**
|
|
|
+ * 相关接口实现
|
|
|
+ *
|
|
|
+ * @author liyang
|
|
|
+ * @date 2021-12-31
|
|
|
+ */
|
|
|
@Service("dataStrategyImpl")
|
|
|
public class DataStrategyImpl implements DataStrategy {
|
|
|
- @Autowired
|
|
|
- private RwdClient rwdClient;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ModelAdapter modelAdapter;
|
|
|
@Autowired
|
|
@@ -51,16 +55,24 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
@Autowired
|
|
|
private DiagramMapper diagramMapper;
|
|
|
@Autowired
|
|
|
- private DiscoveryClient discoveryClient;
|
|
|
- @Autowired
|
|
|
@Qualifier("customThreadPool")
|
|
|
private ThreadPoolExecutor executor;
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取系统图类型列表
|
|
|
+ *
|
|
|
+ * @return 系统图类型列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<DiagramType> getDiagramTypes() {
|
|
|
return diagramTypeMapper.getDiagramTypes();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取系统图模板列表
|
|
|
+ *
|
|
|
+ * @return 模板列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<DiagramTemplate> getTemplates() {
|
|
|
List<TemplateEntity> templates = templateMapper.getTemplates();
|
|
@@ -71,8 +83,17 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据系统图类型获取系统图模板列表
|
|
|
+ *
|
|
|
+ * @param diagramType 类型
|
|
|
+ * @return 模板列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<DiagramTemplate> getTemplates(String diagramType) {
|
|
|
+ if (StrUtil.isBlank(diagramType)) {
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(), "diagramType不能为空");
|
|
|
+ }
|
|
|
List<TemplateEntity> templates = templateMapper.getTemplatesByType(diagramType);
|
|
|
if (CollectionUtil.isNotEmpty(templates)) {
|
|
|
return templates.stream().map(templateEntity ->
|
|
@@ -81,6 +102,12 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存系统图模板
|
|
|
+ *
|
|
|
+ * @param template 系统图模板信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public DiagramTemplate saveTemplate(DiagramTemplate template) {
|
|
|
TemplateEntity templateEntity = modelAdapter.toTemplateEntity(template);
|
|
@@ -88,22 +115,41 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
return template;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据模板id删除模板
|
|
|
+ *
|
|
|
+ * @param templateId 模板id
|
|
|
+ * @return 是否成功
|
|
|
+ */
|
|
|
@Override
|
|
|
public boolean deleteTemplate(String templateId) {
|
|
|
templateMapper.deleteByTemplateId(templateId);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据模板id获取模板信息
|
|
|
+ *
|
|
|
+ * @param templateId 模板id
|
|
|
+ * @return 系统图模板信息
|
|
|
+ */
|
|
|
@Override
|
|
|
public DiagramTemplate getTemplate(String templateId) {
|
|
|
TemplateEntity templateEntity = templateMapper.selectByTemplateId(templateId);
|
|
|
- //TODO 没有数据返回一个空对象
|
|
|
return templateEntity != null ? modelAdapter.toTemplate(templateEntity) : new DiagramTemplate();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据系统code获取图例
|
|
|
+ *
|
|
|
+ * @param systemCode 所属系统code
|
|
|
+ * @return 图例列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<Legend> getLegends(String systemCode) {
|
|
|
- //TODO 这个systemCode 对应的是bt_system字段?
|
|
|
+ if (StrUtil.isBlank(systemCode)) {
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(), "systemCode不能为空");
|
|
|
+ }
|
|
|
List<LegendEntity> legends = legendMapper.getLegends(systemCode);
|
|
|
if (CollectionUtil.isNotEmpty(legends)) {
|
|
|
return legends.stream().map(legendEntity ->
|
|
@@ -112,6 +158,13 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存图例
|
|
|
+ *
|
|
|
+ * @param legend 图例信息
|
|
|
+ * @param systemCode 所属系统code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public Legend saveLegend(Legend legend, String systemCode) {
|
|
|
legend.setSystem(systemCode);
|
|
@@ -119,24 +172,54 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
return legend;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 删除图例
|
|
|
+ *
|
|
|
+ * @param legendId 图例id
|
|
|
+ * @param systemCode 所属系统code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public boolean deleteLegend(String legendId, String systemCode) {
|
|
|
return legendMapper.deleteLegend(legendId, systemCode);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据图例id、所属系统code 获取图例信息
|
|
|
+ *
|
|
|
+ * @param legendId 图例id
|
|
|
+ * @param systemCode 所属系统code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public Legend getLegend(String legendId, String systemCode) {
|
|
|
LegendEntity legendEntity = legendMapper.getLegend(legendId, systemCode);
|
|
|
- //TODO 没有数据返回一个空对象
|
|
|
return legendEntity == null ? new Legend() : modelAdapter.toLegend(legendEntity);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据设备类型获取图例列表
|
|
|
+ *
|
|
|
+ * @param equipmentType 设备类型
|
|
|
+ * @return 图例列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<Legend> getLegendsForEquipment(String equipmentType) {
|
|
|
+ if (StrUtil.isBlank(equipmentType)) {
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(), "equipmentType不能为空");
|
|
|
+ }
|
|
|
String systemCode = Optional.of(equipmentType).map(s -> s.substring(0, 4)).orElse(StrUtil.EMPTY);
|
|
|
return getLegends(systemCode);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据项目id、系统id、集团code 获取系统图列表
|
|
|
+ *
|
|
|
+ * @param projectId 项目id
|
|
|
+ * @param systemId 系统id
|
|
|
+ * @param groupCode 集团code
|
|
|
+ * @return 系统图列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<Diagram> getDiagrams(String projectId, String systemId, String groupCode) {
|
|
|
List<DiagramEntity> diagrams = diagramMapper.getDiagrams(null, projectId, systemId, groupCode);
|
|
@@ -147,6 +230,15 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据系统图类型、项目id、系统id、集团code 获取系统图列表
|
|
|
+ *
|
|
|
+ * @param diagramType 统图类型
|
|
|
+ * @param projectId 项目id
|
|
|
+ * @param systemId 系统id
|
|
|
+ * @param groupCode 集团code
|
|
|
+ * @return 系统图列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode) {
|
|
|
List<DiagramEntity> diagrams = diagramMapper.getDiagrams(diagramType,
|
|
@@ -158,6 +250,12 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存系统图
|
|
|
+ *
|
|
|
+ * @param diagram 系统图信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public Diagram saveDiagram(Diagram diagram) {
|
|
|
DiagramEntity diagramEntity = modelAdapter.toDiagramEntity(diagram);
|
|
@@ -165,26 +263,46 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
return diagram;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据系统图id删除
|
|
|
+ *
|
|
|
+ * @param diagramId 系统图id
|
|
|
+ * @return 是否成功
|
|
|
+ */
|
|
|
@Override
|
|
|
public boolean deleteDiagram(String diagramId) {
|
|
|
return diagramMapper.deleteByDiagramId(diagramId);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据系统图id获取系统图信息
|
|
|
+ *
|
|
|
+ * @param diagramId 系统图id
|
|
|
+ * @return 系统图信息
|
|
|
+ */
|
|
|
@Override
|
|
|
public Diagram getDiagram(String diagramId) {
|
|
|
DiagramEntity diagramEntity = diagramMapper.getDiagram(diagramId);
|
|
|
- //TODO 没有数据返回一个空对象
|
|
|
return diagramEntity == null ? new Diagram() : modelAdapter.toDiagram(diagramEntity);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据设备类型、项目id、系统id、集团code获取对象列表信息
|
|
|
+ *
|
|
|
+ * @param equipmentTypes 设备类型列表
|
|
|
+ * @param projectId 项目id
|
|
|
+ * @param systemId 系统id
|
|
|
+ * @param groupCode 集团code
|
|
|
+ * @return 节点列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<ObjectNode> loadObjectsByType(List<String> equipmentTypes, String projectId,
|
|
|
String systemId, String groupCode) {
|
|
|
- //TODO 是否需要校验 equipmentTypes 、objectIds
|
|
|
QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "equipment");
|
|
|
- ArrayNode types = criteria.getCriteria().putArray("classCode");
|
|
|
- Optional.ofNullable(equipmentTypes).ifPresent(stringList ->
|
|
|
- stringList.forEach(types::add));
|
|
|
+ if (CollectionUtil.isNotEmpty(equipmentTypes)) {
|
|
|
+ ArrayNode types = criteria.getCriteria().putArray("classCode");
|
|
|
+ equipmentTypes.forEach(types::add);
|
|
|
+ }
|
|
|
|
|
|
if (StrUtil.isNotBlank(systemId)) {
|
|
|
ObjectNode on = JsonNodeFactory.instance.objectNode();
|
|
@@ -196,13 +314,23 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
return DigitalObjectFacade.query(groupCode, projectId, null, null, criteria);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据关系类型列表、节点id列表、项目id、集团code获取对象关系列表
|
|
|
+ *
|
|
|
+ * @param relationTypes 关系类型列表
|
|
|
+ * @param objectIds 节点id列表
|
|
|
+ * @param projectId 项目id
|
|
|
+ * @param groupCode 集团code
|
|
|
+ * @return 关系列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<ObjectNode> loadRelationsByType(List<String[]> relationTypes, List<String> objectIds,
|
|
|
String projectId, String groupCode) {
|
|
|
- //TODO 是否需要校验 relationTypes 、objectIds
|
|
|
+ if (CollectionUtil.isEmpty(objectIds)) {
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(), "objectIds不能为空");
|
|
|
+ }
|
|
|
//查询到的所有关系
|
|
|
List<ObjectRelation> allRelations = queryRelationsByObjIds(projectId, groupCode, objectIds);
|
|
|
- Set<String> collect = allRelations.stream().map(ObjectRelation::getRelCode).collect(Collectors.toSet());
|
|
|
//所有关系类型
|
|
|
Set<String> types = new HashSet<>();
|
|
|
Optional.ofNullable(relationTypes).ifPresent(relations ->
|
|
@@ -246,21 +374,42 @@ public class DataStrategyImpl implements DataStrategy {
|
|
|
return resultList.stream().distinct().filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据对象id列表获取节点列表
|
|
|
+ *
|
|
|
+ * @param objectIds 节点id列表
|
|
|
+ * @param projectId 项目id
|
|
|
+ * @param groupCode 集团code
|
|
|
+ * @return 节点列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<ObjectNode> loadObjectsById(List<String> objectIds, String projectId, String groupCode) {
|
|
|
- //TODO 是否需要校验 objectIds
|
|
|
+ if (CollectionUtil.isEmpty(objectIds)) {
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(), "objectIds不能为空");
|
|
|
+ }
|
|
|
QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "equipment");
|
|
|
ArrayNode arr = criteria.getCriteria().putArray("id");
|
|
|
- Optional.ofNullable(objectIds).ifPresent(ids -> ids.forEach(arr::add));
|
|
|
+ objectIds.forEach(arr::add);
|
|
|
+
|
|
|
return DigitalObjectFacade.query(groupCode, projectId, null, null, criteria);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据关系id列表、项目id、集团code获取关系列表
|
|
|
+ *
|
|
|
+ * @param relationIds 关系id列表
|
|
|
+ * @param projectId 项目id
|
|
|
+ * @param groupCode 集团code
|
|
|
+ * @return 关系列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<ObjectNode> loadRelationsById(List<String> relationIds, String projectId, String groupCode) {
|
|
|
- //TODO 是否需要校验 relationIds
|
|
|
+ if (CollectionUtil.isEmpty(relationIds)) {
|
|
|
+ throw new BusinessException(ResponseCode.A0400.getCode(), "relationIds不能为空");
|
|
|
+ }
|
|
|
QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper);
|
|
|
ArrayNode nodes = criteria.getCriteria().putArray("id");
|
|
|
- Optional.ofNullable(relationIds).ifPresent(ids -> ids.forEach(nodes::add));
|
|
|
+ relationIds.forEach(nodes::add);
|
|
|
|
|
|
List<ObjectRelation> result = DigitalRelationFacade.query(groupCode, projectId, null, null, criteria);
|
|
|
return JsonNodeUtils.toListNode(result, null, null);
|