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.util.BeanUtilForVCI;
|
import com.vci.starter.web.util.Lcm.ConcurrentDateFormat;
|
import com.vci.starter.web.util.Lcm.Func;
|
import com.vci.starter.web.util.VciBaseUtil;
|
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.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:32
|
*/
|
@Service
|
public class WebBtmServiceImpl implements WebBtmServiceI {
|
|
/**
|
* 日志
|
*/
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
/**
|
* 平台的调用工具类
|
*/
|
@Resource
|
private PlatformClientUtil platformClientUtil;
|
|
/**
|
* 枚举的服务
|
*/
|
@Resource
|
private WebEnumServiceI enumService;
|
|
/**
|
* 链接类型的服务
|
*/
|
@Resource
|
private WebLinkTypeServiceI linkTypeService;
|
|
/**
|
* 属性的服务
|
*/
|
@Resource
|
private WebAttributeServiceI attributeService;
|
|
/**
|
* 使用编号获取业务类型
|
*
|
* @param id 编号
|
* @return 业务类型
|
*/
|
@Override
|
public OsBtmTypeVO getBtmById(String id) throws PLException {
|
if (StringUtils.isBlank(id)) {
|
return null;
|
}
|
BizType bizType = platformClientUtil.getBtmService().getBizTypeByName(id);
|
return btmDO2VO(bizType,null);
|
}
|
|
/**
|
* 数据对象转换为显示对象
|
*
|
* @param btmItem 数据对象
|
* @return 显示对象
|
*/
|
@Override
|
public OsBtmTypeVO btmDO2VO(BizType btmItem, Map<String, OsAttributeVO> attributeVOMap) {
|
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.DateTimeMillFormat)));
|
} 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.setRevLevel(btmItem.revLevel);
|
vo.setRevisionRuleId(btmItem.revRuleName);
|
vo.setTableName(VciBaseUtil.getTableName(vo.getId()));
|
vo.setInputRevisionFlag(btmItem.revInput);
|
vo.setDelimiter(btmItem.delimiter);
|
vo.setfName(btmItem.fName);
|
vo.setVersionRule(String.valueOf(btmItem.verRuleName));
|
if (StringUtils.isNotBlank(vo.getRevisionRuleId()) || vo.isInputRevisionFlag()) {
|
vo.setRevisionFlag(true);
|
}
|
vo.setLifeCycleIds(Arrays.stream(btmItem.lifeCycles).collect(Collectors.joining(",")));
|
vo.setApNameArray(btmItem.apNameArray);
|
List<OsAttributeVO> attributeVOS = attributeService.listAttrByIds(Arrays.stream(btmItem.apNameArray).collect(Collectors.toList()),attributeVOMap);
|
List<OsBtmTypeAttributeVO> btmTypeAttributeVOS = new ArrayList<>();
|
Optional.ofNullable(attributeVOS).orElseGet(() -> new ArrayList<>()).stream().forEach(attributeVO -> {
|
OsBtmTypeAttributeVO btmTypeAttributeVO = new OsBtmTypeAttributeVO();
|
BeanUtilForVCI.convert(attributeVO, btmTypeAttributeVO);
|
btmTypeAttributeVO.setPkBtmType(vo.getOid());
|
btmTypeAttributeVO.setBtmTypeId(vo.getId());
|
btmTypeAttributeVO.setAttributeDataType(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 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 = 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;
|
}
|
|
/**
|
* 查询所有的业务类型映射
|
*
|
* @return key 是业务的英文名称的小写
|
*/
|
@Override
|
@VciUnLog
|
public Map<String, OsBtmTypeVO> selectAllBtmMap() {
|
return Optional.ofNullable(selectAllBtm()).orElseGet(() -> new ArrayList<OsBtmTypeVO>()).stream().collect(Collectors.toMap(s -> s.getId().toLowerCase(), t -> t, (o1, o2) -> o1));
|
}
|
|
/**
|
* 查询所有的业务类型映射
|
*
|
* @return key 是业务的英文名称的小写
|
*/
|
@Override
|
@VciUnLog
|
public Map<String, OsBtmTypeVO> selectAllBtmMap(Map<String, OsAttributeVO> attributeVOMap) {
|
return Optional.ofNullable(selectAllBtm(attributeVOMap)).orElseGet(() -> new ArrayList<OsBtmTypeVO>()).stream().collect(Collectors.toMap(s -> s.getId().toLowerCase(), t -> t, (o1, o2) -> o1));
|
}
|
|
/**
|
* 查询所有的业务类型
|
*
|
* @return 业务类型对象
|
*/
|
@Override
|
@VciUnLog
|
public List<OsBtmTypeVO> selectAllBtm() {
|
try {
|
return btmDO2VOs(Arrays.stream(platformClientUtil.getBtmService().getBizTypes("")).collect(Collectors.toList()),null);
|
} catch (PLException e) {
|
throw new RuntimeException(e);
|
}
|
}
|
|
/**
|
* 查询所有的业务类型
|
*
|
* @return 业务类型对象
|
*/
|
@Override
|
@VciUnLog
|
public List<OsBtmTypeVO> selectAllBtm(Map<String, OsAttributeVO> attributeVOMap) {
|
try {
|
return btmDO2VOs(Arrays.stream(platformClientUtil.getBtmService().getBizTypes("")).collect(Collectors.toList()),attributeVOMap);
|
} catch (PLException e) {
|
throw new RuntimeException(e);
|
}
|
}
|
|
/**
|
* 数据对象转换为显示对象
|
*
|
* @param btmItems 数据对象
|
* @return 显示对象
|
*/
|
@Override
|
public List<OsBtmTypeVO> btmDO2VOs(Collection<BizType> btmItems,Map<String, OsAttributeVO> attributeVOMap) {
|
List<OsBtmTypeVO> VOS = new ArrayList<>();
|
Optional.ofNullable(btmItems).orElseGet(() -> new ArrayList<>()).parallelStream().forEach(btmItem -> {
|
OsBtmTypeVO vo = btmDO2VO(btmItem,attributeVOMap);
|
VOS.add(vo);
|
});
|
return VOS;
|
}
|
|
/**
|
* 使用编号获取业务类型
|
*
|
* @param btmIds 编号
|
* @return 业务类型
|
*/
|
@Override
|
public List<OsBtmTypeVO> listBtmByIds(Collection<String> btmIds) {
|
if (CollectionUtils.isEmpty(btmIds)) {
|
return null;
|
}
|
BtmDataFetcher btmDataFetcher = new BtmDataFetcher();
|
List<OsBtmTypeVO> btmTypeVOS = new ArrayList<>();
|
btmIds.stream().forEach(id -> {
|
OsBtmTypeVO btmType = btmDataFetcher.getBtmType(id);
|
btmTypeVOS.add(btmType);
|
});
|
return btmTypeVOS;
|
}
|
|
private class BtmDataFetcher {
|
|
//业务类型
|
private Map<String, BizType> btmTypeVOMap = new HashMap<String, BizType>();
|
|
public BtmDataFetcher() {
|
initBtmDataFetcher();
|
}
|
|
private void initBtmDataFetcher(){
|
try {
|
BizType[] bizTypes = platformClientUtil.getBtmService().getBizTypes("");
|
//List<OsBtmTypeVO> osBtmTypeVOS = btmDO2VOs(Arrays.asList(bizTypes), null);
|
if(Func.isNotEmpty(bizTypes)){
|
btmTypeVOMap = Arrays.stream(bizTypes).collect(Collectors.toMap(btm -> btm.name, btm -> btm));
|
}
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 获取业务类型
|
* @param id
|
* @return
|
*/
|
public OsBtmTypeVO getBtmType(String id) {
|
BizType bizType = btmTypeVOMap.get(id);
|
if(Func.isEmpty(bizType)){
|
return null;
|
}
|
//获取的时候才赚VO对象,这样避免一次性全部Btm转VO太慢的问题
|
return btmDO2VO(bizType,null);
|
}
|
}
|
|
/**
|
* 根据业务类型获取包含的属性--不包含基础属性
|
*
|
* @param btmId 业务类型的编号
|
* @return 属性的内容
|
*/
|
@Override
|
public List<OsBtmTypeAttributeVO> listAttributeByBtmId(String btmId) {
|
VciBaseUtil.alertNotNull(btmId, "业务类型的编号");
|
BizType[] bizTypes = new BizType[0];
|
try {
|
bizTypes = platformClientUtil.getBtmService().getBizTypes(btmId);
|
} catch (PLException e) {
|
throw WebUtil.getVciBaseException(e);
|
}
|
if (Func.isEmpty(bizTypes)) {
|
return new ArrayList<>();
|
}
|
BizType bizType = bizTypes[0];
|
OsBtmTypeVO btmTypeVO = btmDO2VO(bizType,null);
|
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());
|
}
|
}
|