package com.vci.web.service.impl;
|
|
import com.vci.corba.common.PLException;
|
import com.vci.corba.omd.btm.BizType;
|
import com.vci.pagemodel.*;
|
import com.vci.starter.web.annotation.log.VciUnLog;
|
import com.vci.starter.web.enumpck.BooleanEnum;
|
import com.vci.starter.web.exception.VciBaseException;
|
import com.vci.starter.web.pagemodel.DataGrid;
|
import com.vci.starter.web.pagemodel.PageHelper;
|
import com.vci.starter.web.util.BeanUtil;
|
import com.vci.starter.web.util.VciBaseUtil;
|
import com.vci.starter.web.util.VciDateUtil;
|
import com.vci.web.service.*;
|
import com.vci.web.util.ConcurrentDateFormat;
|
import com.vci.web.util.Func;
|
import com.vci.web.util.PlatformClientUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 业务类型服务
|
* @author weidy
|
* @date 2021-2-15
|
*/
|
@Service
|
public class OsBtmServiceImpl implements OsBtmServiceI {
|
|
/**
|
* 日志
|
*/
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
/**
|
* 平台的调用工具类
|
*/
|
@Autowired
|
private PlatformClientUtil platformClientUtil;
|
|
/**
|
* 属性的服务
|
*/
|
@Autowired
|
private OsAttributeServiceI attributeService;
|
|
/**
|
* 枚举的服务
|
*/
|
@Autowired
|
private OsEnumServiceI enumService;
|
|
/**
|
* 业务数据操作服务
|
*/
|
@Autowired
|
private WebBoServiceI boService;
|
|
/**
|
* 链接类型的服务
|
*/
|
@Autowired(required = false)
|
@Lazy
|
private OsLinkTypeServiceI linkTypeService;
|
|
/**
|
* 加载自身
|
*/
|
@Autowired(required = false)
|
@Lazy
|
private OsBtmServiceI self;
|
|
/**
|
* 查询所有的业务类型
|
*
|
* @return 业务类型对象
|
*/
|
@Override
|
@VciUnLog
|
public List<OsBtmTypeVO> selectAllBtm() {
|
try {
|
return btmDO2VOs(Arrays.stream(platformClientUtil.getBtmService().getBizTypes("")).collect(Collectors.toList()));
|
} catch (PLException e) {
|
throw new RuntimeException(e);
|
}
|
}
|
|
/**
|
* 查询所有的业务类型映射
|
*
|
* @return key 是业务的英文名称的小写
|
*/
|
@Override
|
@VciUnLog
|
public Map<String, OsBtmTypeVO> selectAllBtmMap() {
|
return Optional.ofNullable(self.selectAllBtm()).orElseGet(()->new ArrayList<OsBtmTypeVO>()).stream().collect(Collectors.toMap(s->s.getId().toLowerCase(), t->t,(o1,o2)->o1));
|
}
|
|
/**
|
* 数据对象转换为显示对象
|
*
|
* @param btmItems 数据对象
|
* @return 显示对象
|
*/
|
@Override
|
public List<OsBtmTypeVO> btmDO2VOs(Collection<BizType> btmItems) {
|
List<OsBtmTypeVO> VOS = new ArrayList<>();
|
Optional.ofNullable(btmItems).orElseGet(()->new ArrayList<>()).stream().forEach(btmItem -> {
|
OsBtmTypeVO vo = btmDO2VO(btmItem);
|
VOS.add(vo);
|
});
|
return VOS;
|
}
|
|
/**
|
* 数据对象转换为显示对象
|
*
|
* @param btmItem 数据对象
|
* @return 显示对象
|
*/
|
@Override
|
public OsBtmTypeVO btmDO2VO(BizType btmItem) {
|
OsBtmTypeVO vo = new OsBtmTypeVO();
|
if(btmItem !=null){
|
vo.setOid(btmItem.oid);
|
vo.setCreator(btmItem.creator);
|
vo.setLastModifier(btmItem.modifier);
|
try {
|
// btmItem.createTime拿到的是时间戳,但是这儿要的是例如2017-12-27 09:32:20.034这样的格式,所以不调用这个方法,改调用其他方法
|
//vo.setCreateTime(VciDateUtil.str2Date(String.valueOf(btmItem.createTime),VciDateUtil.DateTimeFormat));
|
vo.setCreateTime(Func.parse(btmItem.createTime, ConcurrentDateFormat.of(VciDateUtil.DateTimeFormat)));
|
vo.setLastModifyTime( Func.parse(btmItem.modifyTime, ConcurrentDateFormat.of(VciDateUtil.DateTimeFormat)));
|
vo.setTs(Func.parse(btmItem.ts, ConcurrentDateFormat.of(VciDateUtil.DateTimeFormat)));
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
vo.setDescription(btmItem.description);
|
vo.setId(btmItem.name);
|
vo.setName(btmItem.label);
|
vo.setLifeCycleId(btmItem.lifeCycle);
|
vo.setAbstractFlag(btmItem.isAbstract);
|
vo.setImplClass(btmItem.implClass);
|
vo.setShape(btmItem.shape);
|
vo.setRevisionRuleId(btmItem.revRuleName);
|
vo.setTableName(VciBaseUtil.getTableName(vo.getId()));
|
vo.setInputRevisionFlag(btmItem.revInput);
|
if(StringUtils.isNotBlank(vo.getRevisionRuleId()) || vo.isInputRevisionFlag()){
|
vo.setRevisionFlag(true);
|
}
|
vo.setVersionRule(String.valueOf(btmItem.verRuleName));
|
vo.setSubLifeCycleId(Arrays.stream(btmItem.lifeCycles).collect(Collectors.joining(",")));
|
List<OsAttributeVO> attributeVOS = attributeService.listAttrByIds(Arrays.stream(btmItem.apNameArray).collect(Collectors.toList()));
|
List<OsBtmTypeAttributeVO> btmTypeAttributeVOS = new ArrayList<>();
|
Optional.ofNullable(attributeVOS).orElseGet(()->new ArrayList<>()).stream().forEach(attributeVO->{
|
OsBtmTypeAttributeVO btmTypeAttributeVO = new OsBtmTypeAttributeVO();
|
BeanUtil.convert(attributeVO,btmTypeAttributeVO);
|
btmTypeAttributeVO.setPkBtmType(vo.getOid());
|
btmTypeAttributeVO.setBtmTypeId(vo.getId());
|
btmTypeAttributeVO.setAttrDataType(attributeVO.getAttributeDataType());
|
btmTypeAttributeVO.setAttributeLength(attributeVO.getAttrLength());
|
btmTypeAttributeVO.setDefaultValue(attributeVO.getDefaultValue());
|
if("secretgrade".equalsIgnoreCase(attributeVO.getId())){
|
vo.setSecretFlag(true);
|
}
|
if(StringUtils.isNotBlank(attributeVO.getBtmTypeId())){
|
btmTypeAttributeVO.setReferFlag(true);
|
btmTypeAttributeVO.setReferBtmTypeId(attributeVO.getBtmTypeId());
|
}
|
if(StringUtils.isNotBlank(attributeVO.getEnumId())){
|
btmTypeAttributeVO.setEnumFlag(true);
|
btmTypeAttributeVO.setEnumItemMap(enumService.getEnumValueMap(btmTypeAttributeVO.getEnumId()));
|
}
|
btmTypeAttributeVOS.add(btmTypeAttributeVO);
|
});
|
vo.setAttributes(btmTypeAttributeVOS);
|
}
|
return vo;
|
}
|
|
/**
|
* 使用编号获取业务类型
|
*
|
* @param btmIds 编号
|
* @return 业务类型
|
*/
|
@Override
|
public List<OsBtmTypeVO> listBtmByIds(Collection<String> btmIds) {
|
if(CollectionUtils.isEmpty(btmIds)){
|
return null;
|
}
|
Map<String, OsBtmTypeVO> btmTypeVOMap = self.selectAllBtmMap();
|
List<OsBtmTypeVO> btmTypeVOS = new ArrayList<>();
|
btmIds.stream().forEach(id->{
|
if(btmTypeVOMap.containsKey(id.toLowerCase())){
|
btmTypeVOS.add(btmTypeVOMap.get(id.toLowerCase()));
|
}
|
});
|
return btmTypeVOS;
|
}
|
|
/**
|
* 使用编号获取业务类型
|
*
|
* @param id 编号
|
* @return 业务类型
|
*/
|
@Override
|
public OsBtmTypeVO getBtmById(String id) {
|
if(StringUtils.isBlank(id)){
|
return null;
|
}
|
return self.selectAllBtmMap().getOrDefault(id.toLowerCase(),null);
|
}
|
|
/**
|
* 获取业务类型的在哪个属性中使用
|
*
|
* @param btmName 业务类型
|
* @return 引用的信息
|
*/
|
@Override
|
public List<OsUsedAttributeVO> listBtmUsedInfo(String btmName) {
|
return listBtmUsedInfo(btmName,false);
|
}
|
|
/**
|
* 获取业务类型的在哪个属性中使用
|
*
|
* @param btmId 业务类型
|
* @param hasLink 是否包含链接类型中
|
* @return 引用的信息
|
*/
|
@Override
|
public List<OsUsedAttributeVO> listBtmUsedInfo(String btmId, boolean hasLink){
|
VciBaseUtil.alertNotNull(btmId,"业务类型的名称");
|
List<OsAttributeVO> allReferThisBtmAttributes = Optional.ofNullable(attributeService.selectAllAttribute()).orElseGet(()->new ArrayList<>()).stream().filter(s->btmId.equalsIgnoreCase(s.getBtmTypeId())).collect(Collectors.toList());
|
if(CollectionUtils.isEmpty(allReferThisBtmAttributes)){
|
return null;
|
}
|
//根据这些属性,找它使用的业务类型
|
List<OsUsedAttributeVO> usedInfos= new ArrayList<>();
|
List<OsBtmTypeVO> btmTypeVOMap = self.selectAllBtmMap().values().stream().collect(Collectors.toList());
|
List<OsLinkTypeVO> linkTypeVOS = linkTypeService.selectAllLinkMap().values().stream().collect(Collectors.toList());
|
allReferThisBtmAttributes.stream().forEach(attribute->{
|
//其他的业务类型包含了这个属性的
|
List<OsBtmTypeVO> usedBtms = btmTypeVOMap.stream().filter(btmTypeVO -> !CollectionUtils.isEmpty(btmTypeVO.getAttributes()) && btmTypeVO.getAttributes().stream().anyMatch(s -> attribute.getId().equalsIgnoreCase(s.getId()))).collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(usedBtms)){
|
usedBtms.stream().forEach(btm->{
|
btm.getAttributes().stream().filter(s->attribute.getId().equalsIgnoreCase(s.getId())).forEach(attrInBtm->{
|
OsUsedAttributeVO usedAttributeVO = new OsUsedAttributeVO();
|
usedAttributeVO.setId(attrInBtm.getId());
|
usedAttributeVO.setName(attrInBtm.getName());
|
usedAttributeVO.setPkBtmType(btm.getId());
|
usedAttributeVO.setBusinessType(BooleanEnum.TRUE.getValue());
|
usedInfos.add(usedAttributeVO);
|
});
|
});
|
}
|
if(hasLink){
|
List<OsLinkTypeVO> usedLinks = linkTypeVOS.stream().filter(linkTypeVO -> !CollectionUtils.isEmpty(linkTypeVO.getAttributes()) &&linkTypeVO.getAttributes().stream().anyMatch(s->attribute.getId().equalsIgnoreCase(s.getId())) ).collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(usedLinks)){
|
usedLinks.stream().forEach(link->{
|
link.getAttributes().stream().filter(s->attribute.getId().equalsIgnoreCase(s.getId())).forEach(attrInBtm->{
|
OsUsedAttributeVO usedAttributeVO = new OsUsedAttributeVO();
|
usedAttributeVO.setId(attrInBtm.getId());
|
usedAttributeVO.setName(attrInBtm.getName());
|
usedAttributeVO.setPkBtmType(link.getId());
|
usedAttributeVO.setBusinessType(BooleanEnum.FASLE.getValue());
|
usedInfos.add(usedAttributeVO);
|
});
|
});
|
}
|
}
|
});
|
return usedInfos;
|
}
|
|
/**
|
* 根据业务类型获取包含的属性--不包含基础属性
|
*
|
* @param btmId 业务类型的编号
|
* @return 属性的内容
|
*/
|
@Override
|
public List<OsBtmTypeAttributeVO> listAttributeByBtmId(String btmId) {
|
VciBaseUtil.alertNotNull(btmId,"业务类型的编号");
|
OsBtmTypeVO btmTypeVO = getBtmById(btmId);
|
List<OsBtmTypeAttributeVO> attributes = btmTypeVO.getAttributes();
|
if(attributes == null){
|
attributes = new ArrayList<>();
|
}
|
return attributes.stream().sorted(((o1, o2) -> o1.getId().toLowerCase(Locale.ROOT).compareTo(o2.getId().toLowerCase(Locale.ROOT)))).collect(Collectors.toList());
|
}
|
|
/**
|
* 根据业务类型获取包含的属性--包含基础属性
|
*
|
* @param btmId 业务类型的编号
|
* @return 属性的内容
|
*/
|
@Override
|
public List<OsBtmTypeAttributeVO> listAttributeByBtmIdHasDefault(String btmId) {
|
List<OsBtmTypeAttributeVO> attrVOs = listAttributeByBtmId(btmId);
|
if(attrVOs == null){
|
attrVOs = new ArrayList<>();
|
}
|
if(!CollectionUtils.isEmpty(attributeService.getDefaultAttributeVOs())) {
|
List<OsBtmTypeAttributeVO> finalAttrVOs = attrVOs;
|
attributeService.getDefaultAttributeVOs().stream().forEach(attr->{
|
OsBtmTypeAttributeVO attributeVO = new OsBtmTypeAttributeVO();
|
BeanUtil.convert(attr, attributeVO);
|
attributeVO.setAttrDataType(attr.getAttributeDataType());
|
attributeVO.setAttributeLength(attr.getAttrLength());
|
attributeVO.setReferBtmTypeId(attr.getBtmTypeId());
|
attributeVO.setReferBtmTypeName(attr.getBtmTypeName());
|
finalAttrVOs.add(attributeVO);
|
});
|
attrVOs = finalAttrVOs;
|
}
|
return attrVOs;
|
}
|
|
/**
|
* 清除缓存
|
*/
|
@Override
|
public void clearCache() {
|
|
}
|
|
/**
|
* 参照业务类型
|
*
|
* @param conditionMap 查询条件
|
* @param pageHelper 分页的对象
|
* @return 业务类型的信息
|
*/
|
@Override
|
public DataGrid<OsBtmTypeVO> referDataGrid(Map<String, String> conditionMap, PageHelper pageHelper) {
|
DataGrid<OsBtmTypeVO> dataGrid = queryObjectServiceInfoBySql(conditionMap, pageHelper, "plbtmtype",OsBtmTypeVO.class,((data, obj) -> {
|
obj.setTableName(VciBaseUtil.getTableName(obj.getId()));
|
}));
|
return dataGrid;
|
}
|
|
/**
|
* 使用主键查询
|
*
|
* @param oid 主键
|
* @return 业务类型
|
*/
|
@Override
|
public OsBtmTypeVO selectByOid(String oid) {
|
List<OsBtmTypeVO> btmTypeVOS = self.selectAllBtmMap().values().stream().collect(Collectors.toList());
|
return Optional.ofNullable(btmTypeVOS).orElseGet(()->new ArrayList<>()).stream().filter(s->s.getOid().equalsIgnoreCase(oid)).findFirst().orElseGet(()->null);
|
}
|
|
/**
|
* 使用编号获取枚举的名称
|
*
|
* @param id 枚举的英文
|
* @return 枚举的名称
|
*/
|
@Override
|
public String getNameById(String id) {
|
OsBtmTypeVO btmTypeVO = getBtmById(id);
|
if(btmTypeVO == null){
|
throw new VciBaseException("业务类型[{0}]在系统里不存在",new String[]{id});
|
}
|
return btmTypeVO.getName();
|
}
|
|
/**
|
* 根据业务类型和链接类型生成ER图
|
*
|
* @param btmId 业务类型主键
|
*/
|
@Override
|
public OsERVO createERDiagram(String btmId) {
|
VciBaseUtil.alertNotNull(btmId, "业务类型编号");
|
OsBtmTypeVO btmTypeVO = getBtmById(btmId);
|
List<OsERNodeVO> nodeVOList = new ArrayList<>();
|
List<OsERRelationVO> relationVOList = new ArrayList<>();
|
//看当前这个业务类型,参照了其他的哪些业务类型 .我们不显示引用当前业务类型的业务类型
|
splicingBtmType2Json(nodeVOList, relationVOList, btmTypeVO,true);
|
loadAllLinkTypeByBtmType(nodeVOList, relationVOList, btmTypeVO);
|
OsERVO osERVO = new OsERVO();
|
osERVO.setTabViewList(nodeVOList);
|
osERVO.setTabRelViewList(relationVOList);
|
return osERVO;
|
}
|
|
/**
|
* 获取使用这个业务类型的E-R图
|
*
|
* @param btmId 业务类型编号
|
* @return 执行结果
|
*/
|
@Override
|
public OsERVO createERUsed(String btmId) {
|
VciBaseUtil.alertNotNull(btmId, "业务类型编号");
|
OsBtmTypeVO btmTypeVO = getBtmById(btmId);
|
//获取使用当前类型的属性
|
List<OsUsedAttributeVO> usedAttributeVOS = listBtmUsedInfo(btmTypeVO.getId());
|
List<OsERNodeVO> nodeVOList = new ArrayList<>();
|
List<OsERRelationVO> relationVOList = new ArrayList<>();
|
splicingBtmType2Json(nodeVOList, relationVOList, btmTypeVO,false);
|
if(!CollectionUtils.isEmpty(usedAttributeVOS)){
|
usedAttributeVOS.stream().forEach(usedAttr->{
|
//业务类型和链接类型都有可能
|
if(BooleanEnum.TRUE.getValue().equalsIgnoreCase(usedAttr.getBusinessType())){
|
//业务类型
|
OsBtmTypeVO linkBtmVO = self.selectAllBtmMap().get(usedAttr.getPkBtmType().toLowerCase(Locale.ROOT));
|
splicingBtmType2Json(nodeVOList, relationVOList, linkBtmVO,false);
|
OsERRelationVO relationVO = new OsERRelationVO();
|
relationVO.setTo(btmTypeVO.getId() + " " + btmTypeVO.getName());
|
relationVO.setFrom(linkBtmVO.getId() + " " + linkBtmVO.getName());
|
relationVO.setToText("引用");
|
relationVOList.add(relationVO);
|
}else{
|
//是链接类型
|
OsLinkTypeVO linkTypeVO = linkTypeService.selectAllLinkMap().get(usedAttr.getPkBtmType().toLowerCase(Locale.ROOT));
|
List<OsLinkTypeVO> linkTypeVOList = new ArrayList<>();
|
linkTypeVOList.add(linkTypeVO);
|
splicingLinkType2Json(nodeVOList, relationVOList,linkTypeVOList,btmTypeVO,true);
|
}
|
});
|
}
|
OsERVO ervo = new OsERVO();
|
ervo.setTabViewList(nodeVOList);
|
ervo.setTabRelViewList(relationVOList);
|
return ervo;
|
}
|
|
/**
|
* 将业务类型拼接json
|
*
|
* @param nodeVOList 对象节点的信息
|
* @param relationVOList 关系的信息
|
* @param btmTypeVO 业务类型显示对象
|
* @param hasRefer 包含参照
|
*/
|
private void splicingBtmType2Json(List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList, OsBtmTypeVO btmTypeVO,boolean hasRefer) {
|
OsERNodeVO nodeVO = new OsERNodeVO();
|
nodeVO.setKey(btmTypeVO.getId() + " " + btmTypeVO.getName());
|
List<OsERNodePropertyVO> itemList = new ArrayList<>();
|
btmTypeVO.getAttributes().forEach(attribute -> {
|
OsERNodePropertyVO nodePropertyVO = new OsERNodePropertyVO();
|
nodePropertyVO.setName(attribute.getId() + " " + attribute.getName());
|
nodePropertyVO.setKey("oid".equals(attribute.getId().toLowerCase()));
|
if(StringUtils.isNotBlank(attribute.getReferBtmTypeId())){
|
//参照的属性,设置为黄色
|
nodePropertyVO.setColor("#FEDD32FF");
|
}else{
|
nodePropertyVO.setColor("#000");
|
}
|
itemList.add(nodePropertyVO);
|
//判断参照
|
if(hasRefer) {
|
selectReferenceBtmType(attribute, btmTypeVO, nodeVOList, relationVOList);
|
}
|
});
|
nodeVO.setItems(itemList);
|
nodeVOList.add(nodeVO);
|
}
|
|
/**
|
* 判断业务类型的属性是不是参照类型,并将参照添加到ER图中
|
*
|
* @param attribute 业务类型属性
|
* @param nodeVOList 节点信息
|
* @param btmTypeVO 业务类型
|
* @param relationVOList 关系信息
|
*/
|
private void selectReferenceBtmType(OsBtmTypeAttributeVO attribute, OsBtmTypeVO btmTypeVO,
|
List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList) {
|
if (StringUtils.isNotBlank(attribute.getReferBtmTypeId())) {
|
//是参照类型的
|
OsBtmTypeVO referenceBtmType = getBtmById(attribute.getReferBtmTypeId());
|
List<OsBtmTypeAttributeVO> referenceBtmAttributes = referenceBtmType.getAttributes();
|
//向表json中添加
|
OsERNodeVO nodeVO = new OsERNodeVO();
|
nodeVO.setKey(referenceBtmType.getId() + " " + referenceBtmType.getName());
|
|
List<OsERNodePropertyVO> items = new ArrayList<>();
|
if(referenceBtmType.getId().equalsIgnoreCase(btmTypeVO.getId())){
|
//参照自己的内容
|
OsERRelationVO relationVO = new OsERRelationVO();
|
relationVO.setTo(referenceBtmType.getId() + " " + referenceBtmType.getName());
|
relationVO.setFrom(btmTypeVO.getId() + " " + btmTypeVO.getName());
|
relationVO.setToText("自参照");
|
relationVOList.add(relationVO);
|
}else {
|
referenceBtmAttributes.forEach(attr -> {
|
OsERNodePropertyVO nodePropertyVO = new OsERNodePropertyVO();
|
nodePropertyVO.setName(attr.getId() + " " + attr.getName());
|
nodePropertyVO.setKey("oid".equals(attr.getId().toLowerCase()));
|
nodePropertyVO.setColor("#000");
|
items.add(nodePropertyVO);
|
});
|
nodeVO.setItems(items);
|
nodeVOList.add(nodeVO);
|
//关系
|
OsERRelationVO relationVO = new OsERRelationVO();
|
relationVO.setTo(referenceBtmType.getId() + " " + referenceBtmType.getName());
|
relationVO.setFrom(btmTypeVO.getId() + " " + btmTypeVO.getName());
|
relationVO.setToText("参照");
|
relationVOList.add(relationVO);
|
}
|
}
|
}
|
|
/**
|
* 加载业务类型所关联的链接类型
|
*
|
* @param nodeVOList 节点信息
|
* @param relationVOList 关系的信息
|
* @param btmTypeVO 业务类型
|
*/
|
private void loadAllLinkTypeByBtmType(List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList, OsBtmTypeVO btmTypeVO) {
|
Map<String, OsLinkTypeVO> linkTypeVOMap = linkTypeService.selectAllLinkMap();
|
Collection<OsLinkTypeVO> linkTypeVOS = linkTypeVOMap.values();
|
Set<OsLinkTypeVO> fromLinkTypeVOList = linkTypeVOS.stream().filter(link ->
|
Arrays.stream(link.getFromBtmType().split(",")).anyMatch(s->s.equalsIgnoreCase(btmTypeVO.getId()))
|
).collect(Collectors.toSet());
|
Set<OsLinkTypeVO> toLinkTypeList = linkTypeVOS.stream().filter(link ->
|
Arrays.stream(link.getToBtmType().split(",")).anyMatch(s->s.equalsIgnoreCase(btmTypeVO.getId()))).collect(Collectors.toSet());
|
List<OsLinkTypeVO> linkTypeVOList = new ArrayList<>();
|
linkTypeVOList.addAll(fromLinkTypeVOList);
|
linkTypeVOList.addAll(toLinkTypeList);
|
if (!CollectionUtils.isEmpty(linkTypeVOList)) {
|
splicingLinkType2Json(nodeVOList, relationVOList,linkTypeVOList,btmTypeVO,false);
|
}
|
|
}
|
|
/**
|
* 将链接类型拼接成json
|
*
|
* @param nodeVOList 节点信息
|
* @param relationVOList 关系信息
|
* @param linkTypeVOs 链接类型
|
* @param btmTypeVO 业务类型的显示对象
|
* @param used 是否为被使用
|
*/
|
private void splicingLinkType2Json(List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList,
|
List<OsLinkTypeVO> linkTypeVOs,OsBtmTypeVO btmTypeVO,boolean used) {
|
linkTypeVOs.forEach(link -> {
|
List<OsLinkTypeAttributeVO> attributeList = link.getAttributes();
|
OsERNodeVO nodeVO= new OsERNodeVO();
|
nodeVO.setKey(link.getId() + " " + link.getName());
|
List<OsERNodePropertyVO> items = new ArrayList<>();
|
attributeList.forEach(attr -> {
|
OsERNodePropertyVO nodePropertyVO = new OsERNodePropertyVO();
|
nodePropertyVO.setName(attr.getId() + " " + attr.getName());
|
nodePropertyVO.setKey("oid".equals(attr.getId().toLowerCase()));
|
if(StringUtils.isNotBlank(attr.getReferBtmTypeId())) {
|
nodePropertyVO.setColor("#FEDD32FF");
|
}else {
|
nodePropertyVO.setColor("#1c446f");
|
}
|
items.add(nodePropertyVO);
|
//判断参照
|
if(!used) {
|
selectReferenceLinkType(attr, link, nodeVOList, relationVOList);
|
}
|
});
|
nodeVO.setItems(items);
|
//链接类型和业务类型加关系
|
OsERRelationVO relationVO = new OsERRelationVO();
|
relationVO.setFrom(link.getId() + " " + link.getName());
|
relationVO.setTo(btmTypeVO.getId() + " " + btmTypeVO.getName());
|
|
nodeVOList.add(nodeVO);
|
|
if(used){
|
relationVO.setText("被引用");
|
}
|
//如果当前的from端,那么就显示to端的
|
//如果当前的是to端的,那么就显示from端的内容
|
if(Arrays.stream(link.getFromBtmType().split(",")).anyMatch(s->s.equalsIgnoreCase(btmTypeVO.getId()))){
|
//这个是from端
|
if(!used) {
|
relationVO.setToText("from端");
|
}
|
//找这个链接类型的to端的业务类型
|
link.getToBtmTypeVOS().stream().forEach(toBtm->{
|
splicingBtmType2JsonForLink(nodeVOList,relationVOList,link,toBtm,true);
|
});
|
}else{
|
if(!used) {
|
relationVO.setToText("to端");
|
}
|
link.getFromBtmTypeVOS().stream().forEach(fromBtm->{
|
splicingBtmType2JsonForLink(nodeVOList,relationVOList,link,fromBtm,false);
|
});
|
}
|
relationVOList.add(relationVO);
|
});
|
}
|
|
/**
|
* 链接类型关键的业务类型
|
* @param nodeVOList 对象列表
|
* @param relationVOList 关联关系列表
|
* @param link 链接类型
|
* @param btmTypeVO 业务类型
|
* @param to 是否为to端
|
*/
|
private void splicingBtmType2JsonForLink(List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList, OsLinkTypeVO link, OsBtmTypeVO btmTypeVO, boolean to) {
|
OsERNodeVO nodeVO = new OsERNodeVO();
|
nodeVO.setKey(btmTypeVO.getId() + " " + btmTypeVO.getName());
|
List<OsERNodePropertyVO> itemList = new ArrayList<>();
|
btmTypeVO.getAttributes().forEach(attribute -> {
|
OsERNodePropertyVO items = new OsERNodePropertyVO();
|
items.setName(attribute.getId() + " " + attribute.getName());
|
items.setKey("oid".equals(attribute.getId().toLowerCase()));
|
items.setColor("#000");
|
itemList.add(items);
|
//不加参照判断了
|
});
|
nodeVO.setItems(itemList);
|
OsERRelationVO relationVO = new OsERRelationVO();
|
relationVO.setFrom(link.getId() + " " + link.getName());
|
relationVO.setTo(btmTypeVO.getId() + " " + btmTypeVO.getName());
|
relationVO.setToText(to?"to端":"from端");
|
relationVOList.add(relationVO);
|
nodeVOList.add(nodeVO);
|
}
|
|
/**
|
* 判断链接类型的属性是不是参照类型,并将参照添加到ER图中
|
*
|
* @param attr 链接类型的属性
|
* @param linkTypeVO 链接类型的内容
|
* @param nodeVOList 节点对象
|
* @param relationVOList 关系对象
|
*/
|
private void selectReferenceLinkType(OsLinkTypeAttributeVO attr, OsLinkTypeVO linkTypeVO,List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList) {
|
if (StringUtils.isNotBlank(attr.getReferBtmTypeId())) {
|
//是参照类型的
|
OsBtmTypeVO referenceBtmType = getBtmById(attr.getReferBtmTypeId());
|
List<OsBtmTypeAttributeVO> attributeList = referenceBtmType.getAttributes();
|
//向表json中添加
|
OsERNodeVO nodeVO = new OsERNodeVO();
|
nodeVO.setKey(referenceBtmType.getId() + " " + referenceBtmType.getName());
|
List<OsERNodePropertyVO> items = new ArrayList<>();
|
attributeList.forEach(attribute -> {
|
OsERNodePropertyVO item = new OsERNodePropertyVO();
|
item.setName(attribute.getId() + " " + attribute.getName());
|
item.setKey("oid".equals(attribute.getId().toLowerCase()));
|
item.setColor("#000");
|
items.add(item);
|
});
|
nodeVO.setItems(items);
|
nodeVOList.add(nodeVO);
|
//向关系json中添加
|
OsERRelationVO relationVO = new OsERRelationVO();
|
relationVO.setTo(referenceBtmType.getId() + " " + referenceBtmType.getName());
|
relationVO.setFrom(linkTypeVO.getId() + " " + linkTypeVO.getName());
|
relationVO.setToText("参照");
|
relationVOList.add(relationVO);
|
}
|
}
|
|
}
|