package com.vci.web.service.impl;
|
|
import com.vci.corba.common.PLException;
|
import com.vci.corba.omd.ltm.LinkType;
|
import com.vci.pagemodel.OsAttributeVO;
|
import com.vci.pagemodel.OsBtmTypeVO;
|
import com.vci.pagemodel.OsLinkTypeAttributeVO;
|
import com.vci.pagemodel.OsLinkTypeVO;
|
import com.vci.starter.web.annotation.log.VciUnLog;
|
import com.vci.starter.web.util.BeanUtilForVCI;
|
import com.vci.starter.web.util.VciDateUtil;
|
import com.vci.web.service.WebAttributeServiceI;
|
import com.vci.web.service.WebBtmServiceI;
|
import com.vci.web.service.WebEnumServiceI;
|
import com.vci.web.service.WebLinkTypeServiceI;
|
import com.vci.web.util.PlatformClientUtil;
|
import com.vci.web.util.WebUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* @Description 链接类型服务
|
* @Author dangsn
|
* @Date 2024/11/28 11:42
|
*/
|
@Service
|
public class WebLinkTypeServiceImpl implements WebLinkTypeServiceI {
|
|
/**
|
* 日志
|
*/
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
/**
|
* 平台的调用工具类
|
*/
|
@Resource
|
private PlatformClientUtil platformClientUtil;
|
|
/**
|
* 业务类型服务
|
*/
|
@Resource
|
private WebBtmServiceI btmService;
|
|
/**
|
* 枚举的服务
|
*/
|
@Resource
|
private WebEnumServiceI enumService;
|
|
/**
|
* 属性的服务
|
*/
|
@Resource
|
private WebAttributeServiceI attributeService;
|
|
/**
|
* 查询所有的链接类型
|
*
|
* @return 链接类型对象
|
*/
|
@Override
|
@VciUnLog
|
public List<OsLinkTypeVO> selectAllLink() {
|
try {
|
return linkTypeDO2VOs(Arrays.stream(platformClientUtil.getLinkTypeService().getLinkTypes()).collect(Collectors.toList()));
|
} catch (PLException vciError) {
|
throw WebUtil.getVciBaseException(vciError);
|
}
|
}
|
|
/**
|
* 查询所有的业务类型映射
|
*
|
* @return key 是业务的英文名称的小写
|
*/
|
@Override
|
@VciUnLog
|
public Map<String, OsLinkTypeVO> selectAllLinkMap() {
|
return Optional.ofNullable(selectAllLink()).orElseGet(()->new ArrayList<>()).stream().collect(Collectors.toMap(s->s.getId().toLowerCase(), t->t,(o1, o2)->o1));
|
}
|
|
/**
|
* 数据对象转换为显示对象
|
*
|
* @param linkTypes 数据对象
|
* @return 显示对象
|
*/
|
@Override
|
public List<OsLinkTypeVO> linkTypeDO2VOs(Collection<LinkType> linkTypes) {
|
List<OsLinkTypeVO> VOS = new ArrayList<>();
|
Optional.ofNullable(linkTypes).orElseGet(()->new ArrayList<>()).stream().forEach(linkType -> {
|
OsLinkTypeVO vo = linkTypeDO2VO(linkType);
|
VOS.add(vo);
|
});
|
return VOS;
|
}
|
|
/**
|
* 数据对象转换为显示对象
|
*
|
* @param linkType 数据对象
|
* @return 显示对象
|
*/
|
@Override
|
public OsLinkTypeVO linkTypeDO2VO(LinkType linkType) {
|
OsLinkTypeVO vo = new OsLinkTypeVO();
|
if(linkType !=null){
|
vo.setOid(linkType.oid);
|
vo.setCreator(linkType.creator);
|
vo.setLastModifier(linkType.modifier);
|
try {
|
vo.setCreateTime(VciDateUtil.long2Date(linkType.createTime));
|
vo.setLastModifyTime(VciDateUtil.long2Date(linkType.modifyTime));
|
vo.setTs(VciDateUtil.long2Date(linkType.ts));
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
vo.setDescription(linkType.description);
|
vo.setId(linkType.name);
|
vo.setName(linkType.label);
|
vo.setFromBtmTypeVOS(btmService.listBtmByIds(Arrays.stream(linkType.btmItemsFrom).collect(Collectors.toSet())));
|
if(!CollectionUtils.isEmpty(vo.getFromBtmTypeVOS())){
|
vo.setFromBtmType(Arrays.stream(linkType.btmItemsFrom).collect(Collectors.joining(",")));
|
vo.setFromBtmTypeName(vo.getFromBtmTypeVOS().stream().map(OsBtmTypeVO::getName).collect(Collectors.joining(",")));
|
}
|
vo.setToBtmTypeVOS(btmService.listBtmByIds(Arrays.stream(linkType.btmItemsTo).collect(Collectors.toSet())));
|
if(!CollectionUtils.isEmpty(vo.getToBtmTypeVOS())){
|
vo.setToBtmType(Arrays.stream(linkType.btmItemsTo).collect(Collectors.joining(",")));
|
vo.setToBtmTypeName(vo.getToBtmTypeVOS().stream().map(OsBtmTypeVO::getName).collect(Collectors.joining(",")));
|
}
|
vo.setImplClass(linkType.implClass);
|
vo.setShape(linkType.shape);
|
List<OsAttributeVO> attributeVOS = attributeService.listAttrByIds(Arrays.stream(linkType.attributes).collect(Collectors.toList()));
|
List<OsLinkTypeAttributeVO> linkTypeAttributeVOS = new ArrayList<>();
|
Optional.ofNullable(attributeVOS).orElseGet(()->new ArrayList<>()).stream().forEach(attributeVO->{
|
OsLinkTypeAttributeVO linkTypeAttributeVO = new OsLinkTypeAttributeVO();
|
BeanUtilForVCI.convert(attributeVO,linkTypeAttributeVO);
|
linkTypeAttributeVO.setPkLinkType(vo.getOid());
|
if(StringUtils.isNotBlank(attributeVO.getBtmTypeId())){
|
linkTypeAttributeVO.setReferFlag(true);
|
linkTypeAttributeVO.setReferBtmTypeId(attributeVO.getBtmTypeId());
|
}
|
if(StringUtils.isNotBlank(attributeVO.getEnumId())){
|
linkTypeAttributeVO.setEnumFlag(true);
|
linkTypeAttributeVO.setEnumItemMap(enumService.getEnumValueMap(linkTypeAttributeVO.getEnumId()));
|
}
|
linkTypeAttributeVOS.add(linkTypeAttributeVO);
|
});
|
vo.setAttributes(linkTypeAttributeVOS);
|
}
|
return vo;
|
}
|
}
|