package com.vci.web.service.impl; import com.vci.client.omd.linktype.util.Tool; import com.vci.client.omd.provider.BtmProvider; import com.vci.client.omd.provider.LinkTypeProvider; import com.vci.corba.common.PLException; import com.vci.corba.omd.atm.AttributeDef; import com.vci.corba.omd.btm.BTMServicePrx; import com.vci.corba.omd.btm.BizType; import com.vci.corba.omd.etm.EnumItem; import com.vci.corba.omd.etm.EnumType; import com.vci.corba.omd.lcm.Bound; import com.vci.corba.omd.lcm.LifeCycle; import com.vci.corba.omd.lcm.TransitionVO; import com.vci.corba.omd.lcm.TransitionVOEvent; import com.vci.corba.omd.ltm.LinkType; import com.vci.corba.omd.stm.StatePool; import com.vci.starter.poi.bo.WriteExcelData; import com.vci.starter.poi.bo.WriteExcelOption; import com.vci.starter.poi.util.ExcelUtil; import com.vci.starter.web.annotation.VciBtmType; import com.vci.starter.web.constant.FrameWorkLcStatusConstant; import com.vci.starter.web.enumpck.VciFieldTypeEnum; import com.vci.starter.web.exception.VciBaseException; import com.vci.starter.web.util.BeanUtil; import com.vci.starter.web.util.LocalFileUtil; import com.vci.starter.web.util.VciBaseUtil; import com.vci.starter.web.util.VciDateUtil; import com.vci.starter.word.bo.WordMergeStartTableDataBO; import com.vci.starter.word.util.WordUtil; import com.vci.web.dto.*; import com.vci.web.pageModel.*; import com.vci.web.properties.OsDDLExportWordFieldProperties; import com.vci.web.service.*; import com.vci.web.util.Func; 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 java.io.File; import java.io.FileNotFoundException; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import static com.vci.client.omd.attribpool.ui.VTDataTypePanel.*; /** * 对象建模等相关的内容导入 * @author weidy * @date 2021/8/13 */ @Service public class WebBtmIOServiceImpl implements WebBtmIOServiceI { /** * 平台的调用客户端 */ @Autowired private PlatformClientUtil platformClientUtil; /** * 生命周期的服务 */ @Autowired private OsLifeCycleServiceI lifeCycleService; /** * 状态的服务 */ @Autowired private OsStatusServiceI statusService; /** * 属性的服务 */ @Autowired private OsAttributeServiceI attrService; /** * 枚举的服务 */ @Autowired private OsEnumServiceI enumService; /** * 业务类型的服务 */ @Autowired private OsBtmServiceI btmService; /** * 链接服务 */ @Autowired private OsLinkTypeServiceI linkTypeService; /** * 日志 */ private Logger logger = LoggerFactory.getLogger(getClass()); /** * 获取消息的前缀 * @return 消息前缀 */ private String getMsgPrefix(){ return getClass().getPackage().getName(); } /** * 业务类型 */ private Map allLink = new ConcurrentHashMap(); /** * word里的字段域配置 */ @Autowired private OsDDLExportWordFieldProperties wordFieldProperties; /** * 导入业务类型和链接类型,包含属性,枚举,状态,生命周期,版本规则等全套内容 * * @param importBtmTypeDTO 需要导入的业务类型,链接类型等内容 * @throws VciBaseException */ @Override public void importBtmTypes(OsBtmTypeExportDTO importBtmTypeDTO) throws VciBaseException { VciBaseUtil.alertNotNull(importBtmTypeDTO, "要导入的业务类型等相关数据"); String msgPrefix = getMsgPrefix(); if(logger.isInfoEnabled()){ logger.info("{}在{}调用了" + msgPrefix + ".importBtmTypes", WebUtil.getCurrentUserId(), VciDateUtil.getNow()); } if(logger.isDebugEnabled()){ logger.debug(importBtmTypeDTO.toString()); } //因为ORACLE在DDL的时候就会提交一次事务,如果交给spring执行的话。可能抛出事务回滚异常 //要调整的数据库表的内容 try { if (CollectionUtils.isEmpty(importBtmTypeDTO.getAttributeDTOList()) && CollectionUtils.isEmpty(importBtmTypeDTO.getStatusDTOList()) && CollectionUtils.isEmpty(importBtmTypeDTO.getEnumDTOList()) && CollectionUtils.isEmpty(importBtmTypeDTO.getLifeCycleDTOList()) && CollectionUtils.isEmpty(importBtmTypeDTO.getRevisionRuleDTOList()) && CollectionUtils.isEmpty(importBtmTypeDTO.getBtmTypeDTOList()) && CollectionUtils.isEmpty(importBtmTypeDTO.getLinkTypeDTOList())) { logger.info("要导入的业务类型等相关数据为空"); return ; } //先处理基础的,比如,状态,版本规则,枚举,枚举项 //然后处理生命周期,业务类型,链接类型 Collection statusDTOList = importBtmTypeDTO.getStatusDTOList(); if (!CollectionUtils.isEmpty(statusDTOList)) { //说明有新的状态 //我们需要先去查询已经存在的状态 importStatus(statusDTOList); } //规则使用对象没办法声明出来 Collection lifeCycleDTOList = importBtmTypeDTO.getLifeCycleDTOList(); if (!CollectionUtils.isEmpty(lifeCycleDTOList)) { //说明有生命周期状态 importLifeCycles(lifeCycleDTOList); } Collection attributeDTOList = importBtmTypeDTO.getAttributeDTOList(); if (!CollectionUtils.isEmpty(attributeDTOList)) { //说明有属性需要导入 importAttributes(attributeDTOList); } //因为老平台的地方的业务类型上面不需要枚举的主键,所以先处理枚举 Collection enumDTOList = importBtmTypeDTO.getEnumDTOList(); if (!CollectionUtils.isEmpty(enumDTOList)) { //说明有枚举需要导入 importEnums(enumDTOList); } Collection btmTypeDTOList = importBtmTypeDTO.getBtmTypeDTOList(); if (!CollectionUtils.isEmpty(btmTypeDTOList)) { //说明有业务类型需要导入 importBtmType(btmTypeDTOList); } Collection linkTypeDTOList = importBtmTypeDTO.getLinkTypeDTOList(); if(!CollectionUtils.isEmpty(linkTypeDTOList)){ importLinkType(linkTypeDTOList); } }catch (Throwable e){ if(logger.isErrorEnabled()){ logger.error("导入业务类型相关数据错误",e); } throw new VciBaseException(e.getMessage(),new String[0],e); } } /** * 导入状态 * @param statusDTOList 要导入的状态的数据传输对象列表 * @throws VciBaseException 查询或者执行出错的时候会抛出异常 */ private void importStatus( Collection statusDTOList) throws VciBaseException{ //要导入的状态的所有英文名称 List statusIdList = new ArrayList(); Iterator iterator = statusDTOList.iterator(); while(iterator.hasNext()){ statusIdList.add(iterator.next().getId().toLowerCase()); } Set existStatusIdList = statusService.selectAllStatusMap().keySet(); Set statusNameSet = statusService.selectAllStatusMap().values().stream().map(OsStatusVO::getName).collect(Collectors.toSet()); //这个地方的状态不是小写的,但是平台又区分小写 List existStatusLowIdList = existStatusIdList.stream().map(s->s.toLowerCase(Locale.ROOT).trim()).collect(Collectors.toList()); //不存在状态对象(意思需要添加) List unExistStatusDTOList = new ArrayList(); for(OsStatusDTO statusDTO: statusDTOList){ String statusId = statusDTO.getId().toLowerCase().trim(); StatePool statePool = null; if(!existStatusLowIdList.contains(statusId)){ statusDTO.setOid(VciBaseUtil.getPk()); statePool = statusService.statusDTO2DO(statusDTO); unExistStatusDTOList.add(statePool); logger.info("要添加的状态{}",statusId); //要看名字是不是也重复了 if(statusNameSet.contains(statusDTO.getName())){ throw new VciBaseException("平台要求状态池的中文标签不能重复,平台中已经存在了中文标签为{0}的状态,但是英文名称确不是{1}",new String[]{statusDTO.getName(),statusDTO.getId()}); } }else{ //名称都不改 } } //执行添加 if(!CollectionUtils.isEmpty(unExistStatusDTOList)){ statusService.batchAddStatus(unExistStatusDTOList); } statusService.clearCache();; statusService.selectAllStatus(); } /** * 导入生命周期 * @param lifeCycleDTOList 要导入的生命周期数据传输对象列表 * @throws VciBaseException 查询或者保存出错的时候,会抛出异常 */ private void importLifeCycles(Collection lifeCycleDTOList) throws VciBaseException{ Set existLifeCycleIds = lifeCycleService.selectAllLifeCycleMap().keySet(); //生命周期的名称没有转为小写,但是平台又区分大小写 List existLifeCycleLowIds = existLifeCycleIds.stream().map(s->s.toLowerCase(Locale.ROOT)).collect(Collectors.toList()); Map allLifeCycleMap = lifeCycleService.selectAllLifeCycleMap(); Map allLifeCycleLowMap = new HashMap<>(); allLifeCycleMap.forEach((id,lifeCycleVO)->{ allLifeCycleLowMap.put(id.toLowerCase(Locale.ROOT),lifeCycleVO); }); //不存在的生命周期对象 List unExistLifeCycleList = new ArrayList(); List editLifeCycleList = new ArrayList(); String userId = WebUtil.getCurrentUserId(); long now = VciDateUtil.getNowTime(); //循环分析需要添加还是修改 for(OsLifeCycleDTO lifeCycleDTO : lifeCycleDTOList){ String lifeCycleId = lifeCycleDTO.getId().toLowerCase().trim(); LifeCycle lifeCyle = null; boolean edit = false; if(!existLifeCycleLowIds.contains(lifeCycleId)) { lifeCyle = new LifeCycle(); lifeCyle.oid = ""; lifeCyle.id = ""; lifeCyle.creator = userId; lifeCyle.createTime = now; lifeCyle.ts = VciDateUtil.getNowString(VciDateUtil.DateTimeMillFormat); lifeCyle.name = lifeCycleDTO.getId(); }else { lifeCyle = lifeCycleService.lifeCycleVO2DO( allLifeCycleLowMap.get(lifeCycleId)); edit = true; } lifeCyle.tag = lifeCycleDTO.getName(); lifeCyle.description = lifeCycleDTO.getDescription() == null?"":lifeCycleDTO.getDescription(); lifeCyle.startState = lifeCycleDTO.getStartStatus() == null?"":lifeCycleDTO.getStartStatus(); lifeCyle.modifier = userId; lifeCyle.modifyTime = now; //找区域 List lineDTOList = lifeCycleDTO.getLineDTOList(); if(CollectionUtils.isEmpty(lineDTOList)){ //如果是只有空的时候,说明可能只有一个状态 lifeCyle.bounds = new Bound[0]; lifeCyle.routes = new TransitionVO[0]; }else{ //先查询所有的状态 List hasStatusList = new ArrayList(); for(int i = 0 ; i < lineDTOList.size() ; i++){ OsLifeCycleLineDTO lineDTO = lineDTOList.get(i); if(!hasStatusList.contains(lineDTO.getSourceLifeStatus())){ hasStatusList.add(lineDTO.getSourceLifeStatus()); } if(!hasStatusList.contains(lineDTO.getTargetLifeStatus())){ hasStatusList.add(lineDTO.getTargetLifeStatus()); } } //我们每个状态的宽度100,高度50,然后是连接的间距100. //起始状态的左边间距为20,顶部间距为100 List boundList = new ArrayList(); int w = 1 ; for(int i = 0 ; i < hasStatusList.size() ; i++){ String status = hasStatusList.get(i); Bound bound = new Bound(); bound.id=""; bound.name = status; bound.cellw = "75.0"; bound.cellh = "50.0"; bound.cellx = String.valueOf(80+100*w); bound.celly = String.valueOf(100 + 80*w); w++; boundList.add(bound); } lifeCyle.bounds = boundList.toArray(new Bound[0]); //找关系 List lineList = new ArrayList(); for(int i = 0 ; i < lineDTOList.size() ; i++) { OsLifeCycleLineDTO lineDTO = lineDTOList.get(i); TransitionVO line = new TransitionVO(); line.id = ""; line.source = lineDTO.getSourceLifeStatus(); line.destination = lineDTO.getTargetLifeStatus(); if(StringUtils.isNotBlank(lineDTO.getName())) { line.connect = lineDTO.getName(); }else{ line.connect = "line" + i; } List eventDTOList = lineDTO.getEventDTOList(); if(!CollectionUtils.isEmpty(eventDTOList)){ List eventList = new ArrayList(); for(String event:eventDTOList){ if(StringUtils.isNotBlank(event)) { String id = event.contains(".") ? event.substring(event.lastIndexOf(".") + 1) : event; TransitionVOEvent eventVO = new TransitionVOEvent(); eventVO.id = id; eventVO.name = event; eventList.add(eventVO); } } line.transitionVOEvents = eventList.toArray(new TransitionVOEvent[0]); }else{ line.transitionVOEvents = new TransitionVOEvent[0]; } lineList.add(line); } lifeCyle.routes = lineList.toArray(new TransitionVO[0]); } if(edit){ editLifeCycleList.add(lifeCyle); }else{ unExistLifeCycleList.add(lifeCyle); } } //执行添加 if(!CollectionUtils.isEmpty(unExistLifeCycleList)){ lifeCycleService.batchAddLifeCycle(unExistLifeCycleList); } if(!CollectionUtils.isEmpty(editLifeCycleList)){ lifeCycleService.batchEditLifeCycle(editLifeCycleList); } lifeCycleService.clearCache(); lifeCycleService.selectAllLifeCycle(); } /** * 导入属性 * @param attributeDTOList 要导入的属性的数据显示对象 */ private void importAttributes(Collection attributeDTOList) throws VciBaseException { Set existAttributeList = attrService.selectAllAttributeMap().keySet(); Map allAttributeMap = attrService.selectAllAttributeMap(); List unExistAttrList = new ArrayList(); List editAttrList = new ArrayList(); String userId = WebUtil.getCurrentUserId(); long now = VciDateUtil.getNowTime(); //循环分析需要添加还是修改 for (OsAttributeDTO attributeDTO : attributeDTOList) { String attrId = attributeDTO.getId().toLowerCase().trim(); AttributeDef attribItem = null; boolean edit = false; if (!existAttributeList.contains(attrId)) { attribItem = new AttributeDef(); attribItem.oid = ""; attribItem.ts = VciDateUtil.getNowString(VciDateUtil.DateTimeMillFormat); attribItem.creator = userId; attribItem.createTime = now; }else { OsAttributeVO attributeVO = allAttributeMap.get(attrId); attribItem =new AttributeDef(); attribItem.oid = attributeVO.getOid(); attribItem.ts = VciDateUtil.date2Str(attributeVO.getTs(),VciDateUtil.DateTimeMillFormat); attribItem.creator = attributeVO.getCreator(); attribItem.createTime = VciDateUtil.getTime(attributeVO.getCreateTime()); edit = true; } attribItem.modifier = userId; attribItem.modifyTime = now; attribItem.name = attributeDTO.getId().toLowerCase(); attribItem.label = attributeDTO.getName(); attribItem.description = attributeDTO.getDescription() == null ? "" : attributeDTO.getDescription(); attribItem.vtDataType = attributeDTO.getAttributeDataType() == null ? VciFieldTypeEnum.VTString.name() : attributeDTO.getAttributeDataType(); attribItem.defValue = attributeDTO.getDefaultValue() == null?"":attributeDTO.getDefaultValue(); attribItem.rage = attributeDTO.getRange() == null ? "" : attributeDTO.getRange(); //other需要自行处理 StringBuffer sb = new StringBuffer(); sb.append(ALLOWNULL).append(" = ").append(attributeDTO.isNullableFlag() ? "yes" : "no").append(";"); VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.valueOf(attributeDTO.getAttributeDataType()); String[] otherInfos = attribItem.other.split(";"); int length = 0; if(otherInfos!=null&& otherInfos.length > 0){ for(String s : otherInfos){ if(s.contains(LENGTH+" =") || s.contains(LENGTH+"=")){ length = VciBaseUtil.getInt(s.split("=")[1]); break; } } } switch (fieldTypeEnum) { case VTDouble: sb.append(ACCURACY).append(" = ").append(attributeDTO.getPrecisionLength()).append(";"); if(edit){ sb.append(LENGTH).append(" = ").append(length > attributeDTO.getAttrLength()?length:attributeDTO.getAttrLength()).append(";"); }else { sb.append(LENGTH).append(" = ").append(attributeDTO.getAttrLength()).append(";"); } break; case VTInteger: if (StringUtils.isNotBlank(attributeDTO.getEnumId())) { sb.append(ENUMNAME).append(" = ").append(attributeDTO.getEnumId()).append(";"); } break; case VTString: if (StringUtils.isNotBlank(attributeDTO.getBtmTypeId())) { //参照 sb.append(BTM).append(" = ").append(attributeDTO.getBtmTypeId()).append(";"); //链接类型暂时不支持 } if(edit){ sb.append(LENGTH).append(" = ").append(length > attributeDTO.getAttrLength()?length:attributeDTO.getAttrLength()).append(";"); }else { sb.append(LENGTH).append(" = ").append(attributeDTO.getAttrLength()).append(";"); } if (StringUtils.isNotBlank(attributeDTO.getEnumId())) { sb.append(ENUMNAME).append(" = ").append(attributeDTO.getEnumId()).append(";"); } break; default: //不需要处理 break; } attribItem.other = sb.toString(); if (attribItem.other.endsWith(";")) { attribItem.other = attribItem.other.substring(0, attribItem.other.length() - 1); } if(edit){ editAttrList.add(attribItem); }else { unExistAttrList.add(attribItem); } } if (!CollectionUtils.isEmpty(unExistAttrList)) { attrService.batchAddAttribute(unExistAttrList); } if(!CollectionUtils.isEmpty(editAttrList)){ attrService.batchEditAttribute(editAttrList); } //刷新属性,因为后面需要 attrService.clearCache(); attrService.selectAllAttribute(); } /** * 导入枚举 * @param enumDTOList 要导入的枚举的数据传输对象列表 * @throws VciBaseException 查询或执行出错的时候会抛出异常 */ private void importEnums(Collection enumDTOList) throws VciBaseException{ Set existEnumIdList = enumService.selectAllEnumMap().keySet(); Map allEnumMap = enumService.selectAllEnumMap(); List unExistEnumList = new ArrayList(); List editEnumList = new ArrayList(); String userId = WebUtil.getCurrentUserId(); String now = VciDateUtil.getNowString(VciDateUtil.DateTimeFormat); Long nowLong = System.currentTimeMillis(); for(OsEnumDTO enumDTO : enumDTOList){ String enumId = enumDTO.getId().toLowerCase().trim(); if(!existEnumIdList.contains(enumId)){ EnumType enumItem = new EnumType(); enumItem.oid = ""; enumItem.ts = now; enumItem.creator = userId; // enumItem.createTime = now; enumItem.createTime = nowLong; enumItem.modifier = userId; // enumItem.modifyTime = now; enumItem.modifyTime = nowLong; enumItem.name = enumDTO.getId(); enumItem.label = enumDTO.getName(); enumItem.type = "int".equalsIgnoreCase(enumDTO.getEnumValueDataType())?"Integer":"String"; enumItem.length = enumDTO.getLength(); List childList = new ArrayList(); Map itemMaps = enumDTO.getItemMaps(); if(CollectionUtils.isEmpty(itemMaps)){ throw new VciBaseException("枚举{0}没有选项",new String[]{enumItem.name}); } for(String key : itemMaps.keySet()){ String value = itemMaps.get(key); EnumItem enumChild = new EnumItem(); enumChild.name = value; enumChild.value = key; enumChild.description = ""; childList.add(enumChild); } enumItem.items = childList.toArray(new EnumItem[0]); unExistEnumList.add(enumItem); }else{ //修改内容 EnumType enumItem = new EnumType(); OsEnumVO enumVO = allEnumMap.get(enumId); enumItem.oid = enumVO.getOid(); // enumItem.createTime = VciDateUtil.date2Str(enumVO.getCreateTime(),VciDateUtil.DateTimeFormat); enumItem.createTime = Func.toLong(enumVO.getCreateTime()); enumItem.creator = enumVO.getCreator(); enumItem.modifier = userId; // enumItem.modifyTime = now; enumItem.modifyTime = nowLong; enumItem.name = enumVO.getId(); enumItem.ts = VciDateUtil.date2Str(enumVO.getTs(),VciDateUtil.DateTimeMillFormat); enumItem.label = enumDTO.getName(); enumItem.type = "int".equalsIgnoreCase(enumDTO.getEnumValueDataType())?"Integer":"String"; enumItem.length = enumDTO.getLength(); List childList = new ArrayList(); Map itemMaps = enumDTO.getItemMaps(); if(CollectionUtils.isEmpty(itemMaps)){ throw new VciBaseException("枚举{0}没有选项",new String[]{enumItem.name}); } for(String key : itemMaps.keySet()){ String value = itemMaps.get(key); EnumItem enumChild = new EnumItem(); enumChild.name = value; enumChild.value = key; enumChild.description = ""; childList.add(enumChild); } enumItem.items = childList.toArray(new EnumItem[0]); editEnumList.add(enumItem); } } //执行添加 if(!CollectionUtils.isEmpty(unExistEnumList)){ enumService.batchAddEnum(unExistEnumList); } //执行修改 if(!CollectionUtils.isEmpty(editEnumList)){ enumService.batchEditEnum(editEnumList); } enumService.clearCache(); enumService.selectAllEnum(); } /** * 执行导入业务类型 * @param btmTypeDTOList 需要导入的业务类型的数据传输对象列表 */ private void importBtmType(Collection btmTypeDTOList) { //查询已经存在的业务类型 Map allBtmMap = btmService.selectAllBtmMap(); Set exitBtmList = allBtmMap.keySet(); List unExistBtmList = new ArrayList(); List editBtmList = new ArrayList(); String userId = WebUtil.getCurrentUserId(); long now = VciDateUtil.getNowTime(); for (OsBtmTypeDTO btmTypeDTO : btmTypeDTOList) { String btmId = btmTypeDTO.getId().toLowerCase().trim(); if (!exitBtmList.contains(btmId)) { //老平台的内容中,实际不关心关联的数据是否真实存在,所以直接添加就行 BizType btmItem = new BizType(); btmItem.oid = ""; btmItem.ts = now; btmItem.creator = userId; btmItem.createTime = now; btmItem.modifier = userId; btmItem.modifyTime = now; btmItem.name = btmTypeDTO.getId().toLowerCase(); wrapperBtmItem(btmItem,btmTypeDTO); unExistBtmList.add(btmItem); } else { BizType btmItem = new BizType(); OsBtmTypeVO btmTypeVO = allBtmMap.get(btmId); btmItem.name = btmTypeDTO.getId().toLowerCase(); btmItem.oid = btmTypeVO.getOid(); btmItem.creator = btmTypeVO.getCreator(); btmItem.createTime = VciDateUtil.getTime(btmTypeVO.getCreateTime()); //修改 btmItem.modifier = userId; btmItem.modifyTime = now; btmItem.ts = VciDateUtil.getTime(btmTypeVO.getTs()); wrapperBtmItem(btmItem,btmTypeDTO); editBtmList.add(btmItem); } if(logger.isInfoEnabled()){ logger.info("业务类型[{}],对应的类路径是{}",btmId,btmTypeDTO.getClassFullName()); } } batchAddBtm(unExistBtmList); batchEditBtm(editBtmList); } /** * 批量添加业务类型 * @param btmItems 业务类型的对象 */ @Override public void batchAddBtm(Collection btmItems){ if(!CollectionUtils.isEmpty(btmItems)){ Map attributeMap = attrService.selectAllAttributeMap(); for(BizType btmItem : btmItems){ try{ BTMServicePrx btmService = platformClientUtil.getBtmService(); btmService.addBizType(btmItem); //执行完成了需要创建表 //获取的时候不一定刷新了缓存,这样就获取不到信息 String btmTableName = BtmProvider.getInstance().getBTTableName(btmItem.name); String sql = "create Table " + btmTableName + "(" + "\n\tOID VARCHAR2(36) not null,\n\tREVISIONOID VARCHAR2(36),\n\tNAMEOID VARCHAR2(36),\n\tBtmName VARCHAR2(36),\n\tISLastR CHAR(1),\n\tISFirstR CHAR(1),\n\tISLastV CHAR(1),\n\tISFirstV CHAR(1),\n\tCreator VARCHAR2(36),\n\tCreateTime TIMESTAMP,\n\tLastModifier VARCHAR2(36),\n\tLastModifyTime TIMESTAMP,\n\tRevisionRule VARCHAR2(36),\n\tVersionRule VARCHAR2(36),\n\tRevisionSeq NUMBER,\n\tRevisionValue VARCHAR2(10),\n\tVersionSeq NUMBER,\n\tVersionValue VARCHAR2(10),\n\tLCTID VARCHAR2(36),\n\tLCStatus VARCHAR2(36),\n\tTS TIMESTAMP,\n\tID VARCHAR2(36),\n\tNAME VARCHAR2(128),\n\tDESCRIPTION VARCHAR2(255),\n\tOWNER VARCHAR2(36),\n\tCHECKINBY VARCHAR2(36),\n\tCHECKINTIME TIMESTAMP,\n\tCHECKOUTBY VARCHAR2(36),\n\tCHECKOUTTIME TIMESTAMP,\n\tCOPYFROMVERSION VARCHAR2(36),\n\t"; String[] apNameArray = btmItem.apNameArray; if(apNameArray!=null && apNameArray.length>0){ for(String attrId : apNameArray){ OsAttributeVO attrVO = attributeMap.get(attrId.toLowerCase().trim()); if(attrVO!=null) { String abSql = Tool.getInstance().getAbSql(attrService.attributeVO2DO(attrVO)); sql = sql + abSql; }else{ logger.info("业务类型{}里的属性{}没找到",btmTableName,attrId.toLowerCase().trim()); } } } String alterSql = BtmProvider.getInstance().getAddPKSql(btmItem.name); sql = sql.substring(0, sql.lastIndexOf(",")); sql = sql + "\n)"; //TODO 暂时不清楚用何种方式创建表,此处先注释掉 // DDLToolClient.getService().executeUpdateOracle(sql); // DDLToolClient.getService().executeUpdateOracle(alterSql); }catch (PLException vciError){ throw WebUtil.getVciBaseException(vciError); } } } } /** * 批量添加业务类型 * @param btmItems 业务类型的对象 */ @Override public void batchEditBtm(Collection btmItems){ Map btmTypeVOMap = btmService.selectAllBtmMap(); if(!CollectionUtils.isEmpty(btmItems)){ for(BizType btmItem : btmItems){ String btmId = btmItem.name; List addAttrList = new ArrayList(); //修改这里判断不了,是靠属性整体调整的 List deleteAttrList = new ArrayList(); Set newAttrSet = new HashSet(); Collections.addAll(newAttrSet,btmItem.apNameArray); //拿到以前的 OsBtmTypeVO oldItem = btmTypeVOMap.get(btmId); Set oldAttrSet = new HashSet(); Collections.addAll(oldAttrSet,oldItem.getAttributes().stream().map(OsBtmTypeAttributeVO::getId).collect(Collectors.toList()).toArray(new String[0])); for(String attr:newAttrSet){ if(!oldAttrSet.contains(attr)){ addAttrList.add(attr); } } for(String attr:oldAttrSet){ if(!newAttrSet.contains(attr)){ deleteAttrList.add(attr); } } try{ platformClientUtil.getBtmService().updateBizType(btmItem); }catch (PLException vciError){ throw WebUtil.getVciBaseException(vciError); } addAttrToDB(addAttrList,btmId,false); removeAttrToDB(deleteAttrList,btmId,false); } } } /** * 导出业务类型的信息到Word中 * * @param btmTypeIdCollection 业务类型的编号集合 * @return word的全路径 */ @Override public String exportBtmTypesToWord(Collection btmTypeIdCollection) { if(CollectionUtils.isEmpty(btmTypeIdCollection)){ btmTypeIdCollection = btmService.selectAllBtmMap().keySet(); } List btmTypeVOList = btmService.listBtmByIds(btmTypeIdCollection); List linkTypeVOList = linkTypeService.listLinkTypeIds(btmTypeIdCollection); if(CollectionUtils.isEmpty(btmTypeVOList) && CollectionUtils.isEmpty(linkTypeVOList)){ throw new VciBaseException("要导出的业务类型或者链接类型都不存在"); } WordMergeStartTableDataBO tableDataBO = new WordMergeStartTableDataBO(); tableDataBO.setTableName(wordFieldProperties.getTableName()); List> dataList = new ArrayList<>(); if(!CollectionUtils.isEmpty(btmTypeVOList)){ btmTypeVOList.stream().forEach( s -> { //保持顺序 Map tableData = new HashMap<>(); tableData.put(wordFieldProperties.getTitle(),(s.getName()==null?"":s.getName()) + " " + s.getId()); //字段 List> columnDataList = new ArrayList<>(); List attributes = s.getAttributes(); String tableAreaDesc = ""; if(CollectionUtils.isEmpty(attributes)){ attributes = new ArrayList<>(); } //加三个默认的属性 OsBtmTypeAttributeVO idAttrVO = new OsBtmTypeAttributeVO(); idAttrVO.setId("id"); idAttrVO.setName("编号"); idAttrVO.setAttrDataType(VciFieldTypeEnum.VTString.name()); idAttrVO.setAttributeLength(50); idAttrVO.setNullableFlag(true); attributes.add(idAttrVO); OsBtmTypeAttributeVO nameAttrVO = new OsBtmTypeAttributeVO(); nameAttrVO.setId("name"); nameAttrVO.setName("名称"); nameAttrVO.setAttrDataType(VciFieldTypeEnum.VTString.name()); nameAttrVO.setAttributeLength(50); nameAttrVO.setNullableFlag(true); attributes.add(nameAttrVO); OsBtmTypeAttributeVO descAttrVO = new OsBtmTypeAttributeVO(); descAttrVO.setId("description"); descAttrVO.setName("描述"); descAttrVO.setAttrDataType(VciFieldTypeEnum.VTString.name()); descAttrVO.setAttributeLength(150); descAttrVO.setNullableFlag(true); attributes.add(descAttrVO); if(!CollectionUtils.isEmpty(attributes)){ Map indexMap = new HashMap<>(); indexMap.put("index",1); attributes.stream().forEach( t -> { int index = indexMap.get("index"); Map columnData = attributeToWordMap(t,index); indexMap.put("index",index+1); columnDataList.add(columnData); }); //看是否有枚举 String enumString = joinEnumInfoFromAttribute(attributes); if(StringUtils.isNotBlank(enumString)) { tableAreaDesc += enumString; } } tableData.put(wordFieldProperties.getColumnTableName(),columnDataList); if(StringUtils.isNotBlank(s.getLifeCycleId()) && !FrameWorkLcStatusConstant.EMTYPE_LIFE_CYCLE.equalsIgnoreCase(s.getLifeCycleId())){ List statusVOList = lifeCycleService.listStatusById(s.getLifeCycleId()); if(!CollectionUtils.isEmpty(statusVOList)){ tableAreaDesc += "生命周期:[" + statusVOList.stream().map(OsStatusVO::getName).collect(Collectors.joining(",")) + "]"; } } tableData.put(wordFieldProperties.getAreaDesc(),tableAreaDesc); dataList.add(tableData); }); } if(!CollectionUtils.isEmpty(linkTypeVOList)){ linkTypeVOList.stream().forEach( s -> { //保持顺序 Map tableData = new HashMap<>(); tableData.put(wordFieldProperties.getTitle(),(s.getName()==null?"":s.getName()) + " " + s.getId()); //字段 List> columnDataList = new ArrayList<>(); List linkAttributes = s.getAttributes(); List attributes = new ArrayList<>(); linkAttributes.stream().forEach(t -> { OsBtmTypeAttributeVO attributeVO = new OsBtmTypeAttributeVO(); BeanUtil.convert(t,attributeVO); attributeVO.setPkBtmType(t.getPkLinkType()); attributes.add(attributeVO); }); String tableAreaDesc = ""; if(!CollectionUtils.isEmpty(attributes)){ Map indexMap = new HashMap<>(); indexMap.put("index",1); attributes.stream().forEach( t -> { int index = indexMap.get("index"); Map columnData = attributeToWordMap(t,index); indexMap.put("index",index+1); columnDataList.add(columnData); }); //看是否有枚举 String enumString = joinEnumInfoFromAttribute(attributes); if(StringUtils.isNotBlank(enumString)) { tableAreaDesc += enumString ; } } if(StringUtils.isNotBlank(s.getFromBtmTypeName()) ){ tableAreaDesc += "From端业务类型:" + s.getFromBtmTypeName() + "\n"; } if(StringUtils.isNotBlank(s.getToBtmTypeName()) ){ tableAreaDesc += "To端业务类型:" + s.getToBtmTypeName() + "\n"; } tableData.put(wordFieldProperties.getColumnTableName(),columnDataList); tableData.put(wordFieldProperties.getAreaDesc(),tableAreaDesc); dataList.add(tableData); }); } tableDataBO.setTableDataList(dataList); //写入到文件 return writeDataToWord(tableDataBO); } /** * 导出业务类型的信息到Excel中 * * @param btmTypeIdCollection 业务类型的编号集合 * @return excel的全路径 */ @Override public String exportBtmTypesToExcel(Collection btmTypeIdCollection) { if(CollectionUtils.isEmpty(btmTypeIdCollection)){ btmTypeIdCollection = btmService.selectAllBtmMap().keySet(); } List btmTypeVOList = btmService.listBtmByIds(btmTypeIdCollection); List linkTypeVOList = linkTypeService.listLinkTypeIds(btmTypeIdCollection); if(CollectionUtils.isEmpty(btmTypeVOList) && CollectionUtils.isEmpty(linkTypeVOList)){ throw new VciBaseException("要导出的业务类型或者链接类型都不存在"); } List rowDataList = new ArrayList<>(); final int[] index = {0}; if(!CollectionUtils.isEmpty(btmTypeVOList)) { btmTypeVOList.stream().forEach(btmTypeVO -> { String btmId = btmTypeVO.getId(); List attributeVOS = btmService.listAttributeByBtmId(btmId); //先是名称 int rowIndex = index[0]; WriteExcelData idED = new WriteExcelData(rowIndex, 0, btmId); idED.setMerged(true); if (attributeVOS.size() > 0) { idED.setRowTo(rowIndex + attributeVOS.size() - 1 + 3); } rowDataList.add(idED); WriteExcelData nameED = new WriteExcelData(rowIndex, 1, btmTypeVO.getName()); nameED.setMerged(true); if (attributeVOS.size() > 0) { nameED.setRowTo(rowIndex + attributeVOS.size() - 1 + 3); } rowDataList.add(nameED); rowDataList.add(new WriteExcelData(rowIndex, 2, "id")); rowDataList.add(new WriteExcelData(rowIndex, 3, "编号")); rowDataList.add(new WriteExcelData(rowIndex, 4, "字符串")); rowDataList.add(new WriteExcelData(rowIndex, 5, "是")); rowDataList.add(new WriteExcelData(rowIndex, 6, "50")); rowIndex++; rowDataList.add(new WriteExcelData(rowIndex, 2, "name")); rowDataList.add(new WriteExcelData(rowIndex, 3, "名称")); rowDataList.add(new WriteExcelData(rowIndex, 4, "字符串")); rowDataList.add(new WriteExcelData(rowIndex, 5, "是")); rowDataList.add(new WriteExcelData(rowIndex, 6, "50")); rowIndex++; rowDataList.add(new WriteExcelData(rowIndex, 2, "description")); rowDataList.add(new WriteExcelData(rowIndex, 3, "描述")); rowDataList.add(new WriteExcelData(rowIndex, 4, "字符串")); rowDataList.add(new WriteExcelData(rowIndex, 5, "是")); rowDataList.add(new WriteExcelData(rowIndex, 6, "150")); //处理属性 rowIndex++; for (int i = 0; i < attributeVOS.size(); i++) { OsBtmTypeAttributeVO attributeVO = attributeVOS.get(i); //先是属性的英文名称 rowDataList.add(new WriteExcelData(rowIndex, 2, attributeVO.getId())); //然后属性的中文名称 rowDataList.add(new WriteExcelData(rowIndex, 3, attributeVO.getName())); //属性的类型 rowDataList.add(new WriteExcelData(rowIndex, 4, VciFieldTypeEnum.getTextByValue(attributeVO.getAttrDataType()))); //是否可以为空 rowDataList.add(new WriteExcelData(rowIndex, 5, attributeVO.isNullableFlag() ? "是" : "否")); //属性长度 String length = attributeVO.getAttributeLength()==null?"":attributeVO.getAttributeLength() + "" ; if (attributeVO.getPrecisionLength() != null) { length = length + "(" + attributeVO.getPrecisionLength() + "," + attributeVO.getScaleLength() == null ? "2" : (attributeVO.getScaleLength() + "") + ")" ; } rowDataList.add(new WriteExcelData(rowIndex, 6, length)); //备注 rowDataList.add(new WriteExcelData(rowIndex, 7, attributeVO.getDescription() == null ? "" : attributeVO.getDescription())); rowIndex++; } index[0] = rowIndex; }); } if(!CollectionUtils.isEmpty(linkTypeVOList)){ linkTypeVOList.stream().forEach(linkTypeVO->{ String linkTypeId = linkTypeVO.getId(); List attributeVOS = linkTypeService.listAttributeByLinkId(linkTypeId); //先是名称 int rowIndex = index[0]; WriteExcelData idED = new WriteExcelData(rowIndex, 0, linkTypeId); idED.setMerged(true); if (attributeVOS.size() > 0) { idED.setRowTo(rowIndex + attributeVOS.size() - 1); } rowDataList.add(idED); WriteExcelData nameED = new WriteExcelData(rowIndex, 1, linkTypeVO.getName()); nameED.setMerged(true); if (attributeVOS.size() > 0) { nameED.setRowTo(rowIndex + attributeVOS.size() - 1); } rowDataList.add(nameED); //处理属性 for (int i = 0; i < attributeVOS.size(); i++) { OsLinkTypeAttributeVO attributeVO = attributeVOS.get(i); //先是属性的英文名称 rowDataList.add(new WriteExcelData(rowIndex, 2, attributeVO.getId())); //然后属性的中文名称 rowDataList.add(new WriteExcelData(rowIndex, 3, attributeVO.getName())); //属性的类型 rowDataList.add(new WriteExcelData(rowIndex, 4, VciFieldTypeEnum.getTextByValue(attributeVO.getAttrDataType()))); //是否可以为空 rowDataList.add(new WriteExcelData(rowIndex, 5, attributeVO.isNullableFlag() ? "是" : "否")); //属性长度 String length = attributeVO.getAttributeLength() + "" ; if (attributeVO.getPrecisionLength() != null) { length = length + "(" + attributeVO.getPrecisionLength() + "," + attributeVO.getScaleLength() == null ? "2" : (attributeVO.getScaleLength() + "") + ")" ; } rowDataList.add(new WriteExcelData(rowIndex, 6, length)); //备注 rowDataList.add(new WriteExcelData(rowIndex, 7, attributeVO.getDescription() == null ? "" : attributeVO.getDescription())); rowIndex++; } if(attributeVOS.size()==0){ rowIndex ++; } index[0] = rowIndex ; }); } String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + "数据库表信息.xls"; File excelFile = new File(excelFileName); try { excelFile.createNewFile(); }catch (Throwable e){ String msg = "在创建excel文件的时候出现了错误"; if(logger.isErrorEnabled()){ logger.error(msg,e); } throw new VciBaseException(msg+",{0}",new String[]{excelFileName},e); } String excelTemplateFileName = "/excelTemplate/dataBaseExport.xls"; if(this.getClass().getResource(excelTemplateFileName) == null){ throw new VciBaseException("请联系管理员,系统中缺少{0}这个模板文件",new String[]{excelTemplateFileName}); } try { ExcelUtil.copyFileFromJar(excelTemplateFileName,excelFile); //这个方法会关闭文件流 }catch (Throwable e){ String msg = "从模板文件拷贝到目标文件出现了错误"; if(logger.isErrorEnabled()){ logger.error(msg,e); } throw new VciBaseException(msg+",{0}",new String[]{excelFileName},e); } try{ WriteExcelOption excelOption = new WriteExcelOption(); excelOption.addSheetDataList("数据库表",rowDataList); ExcelUtil.writeDataToFile(excelFile,excelOption); }catch (Throwable e){ String msg = "把数据写入到excel文件中出现错误"; if(logger.isErrorEnabled()){ logger.error(msg,e); } throw new VciBaseException(msg+",{0}",new String[]{excelFileName},e); } //最后返回excel文件名称 return excelFileName; } /** * 拷贝数据到word模板中 * @param tableDataBO 要写入的数据 * @return word 文件路径 */ public String writeDataToWord(WordMergeStartTableDataBO tableDataBO){ String tempFolder = LocalFileUtil.getDefaultTempFolder(); //拷贝文件 String wordFileName = tempFolder + File.separator + "数据库逻辑设计.doc"; File wordFile = new File(wordFileName); try { wordFile.createNewFile(); }catch (Throwable e){ String msg = "在创建word文件的时候出现了错误"; if(logger.isErrorEnabled()){ logger.error(msg,e); } throw new VciBaseException(msg+",{0}",new String[]{wordFileName},e); } String wordTemplateFileName = "/wordTemplate/dataBaseExport.doc"; if(this.getClass().getResource(wordTemplateFileName) == null){ throw new VciBaseException("请联系管理员,系统中缺少{0}这个模板文件",new String[]{wordTemplateFileName}); } try { LocalFileUtil.copyFileInJar(wordTemplateFileName,wordFileName); //这个方法会关闭文件流 }catch (Throwable e){ String msg = "从模板文件拷贝到目标文件出现了错误"; if(logger.isErrorEnabled()){ logger.error(msg,e); } throw new VciBaseException(msg+",{0}",new String[]{wordFileName},e); } //写入word文件 List tableDataBOList = new ArrayList<>(); tableDataBOList.add(tableDataBO); try { WordUtil.setTableDataToWord(wordFile, tableDataBOList); }catch (FileNotFoundException e){ String msg = "读取word文件的时候出现了错误"; if(logger.isErrorEnabled()){ logger.error(msg,e); } throw new VciBaseException(msg + ",{0}",new String[]{wordFileName},e); }catch (VciBaseException e){ throw e; }catch (Throwable e){ throw new VciBaseException("写入数据到word中出现",new String[0],e); } return wordFileName; } /** * 将属性对象拷贝到word数据对象中 * @param btmTypeAttributeVO 属性对象 * @param index 索引 * @return 数据映射,key 是word里的域字段,value是对应的值 */ private Map attributeToWordMap(OsBtmTypeAttributeVO btmTypeAttributeVO,int index){ Map columnData = new HashMap<>(); if(StringUtils.isNotBlank(wordFieldProperties.getColumnIndex())) { columnData.put(wordFieldProperties.getColumnIndex(), index); } columnData.put(wordFieldProperties.getColumnId(),btmTypeAttributeVO.getId().toLowerCase()); columnData.put(wordFieldProperties.getColumnName(),btmTypeAttributeVO.getName()); String attrDataType = btmTypeAttributeVO.getAttrDataType(); String columnType = VciFieldTypeEnum.getTextByValue(attrDataType); if(StringUtils.isBlank(columnType)){ columnType = "字符串"; } columnData.put(wordFieldProperties.getColumnType(),columnType); String area = "长度" + (btmTypeAttributeVO.getAttributeLength() ==null?" ":btmTypeAttributeVO.getAttributeLength()) + ((VciFieldTypeEnum.VTDouble.name().equalsIgnoreCase(attrDataType) && btmTypeAttributeVO.getPrecisionLength() != null && btmTypeAttributeVO.getScaleLength() !=null)?("(" + btmTypeAttributeVO.getPrecisionLength() + "," + btmTypeAttributeVO.getScaleLength() + ")"):""); if(VciFieldTypeEnum.VTDate.name().equalsIgnoreCase(attrDataType) || VciFieldTypeEnum.VTDateTime.name().equalsIgnoreCase(attrDataType) || VciFieldTypeEnum.VTTime.name().equalsIgnoreCase(attrDataType) || VciFieldTypeEnum.VTClob.name().equalsIgnoreCase(attrDataType)){ area = ""; } if(btmTypeAttributeVO.isEnumFlag()){ area = "枚举:" + enumService.getNameById(btmTypeAttributeVO.getEnumId()); } if(btmTypeAttributeVO.isReferFlag()){ area = "参照:" + btmService.getNameById(btmTypeAttributeVO.getReferBtmTypeId()) + "(" + btmTypeAttributeVO.getReferBtmTypeId() + ")"; } if(!btmTypeAttributeVO.isNullableFlag()){ if(StringUtils.isNotBlank(area)){ area += ","; } area += "非空"; } columnData.put(wordFieldProperties.getColumnArea(),area); columnData.put(wordFieldProperties.getColumnDesc(),""); return columnData; } /** * 从属性中获取枚举的信息 * @param attributes 属性对象 * @return 不存在枚举的属性的时候会返回空 */ private String joinEnumInfoFromAttribute(List attributes){ List hasEnumAttributeVOList = attributes.stream().filter( t -> t.isEnumFlag() ).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(hasEnumAttributeVOList)){ List enumIdList = hasEnumAttributeVOList.stream().map(OsBtmTypeAttributeVO::getEnumId).collect(Collectors.toList()); List enumVOList = enumService.listEnumByIdCollection(enumIdList); return enumVOList.stream().map(t->{ return t.getName() + "(" + t.getId() + "):[" + t.getItemMaps().values().stream().collect(Collectors.joining(",")) + "]"; }).collect(Collectors.joining("\n")) + "\n"; } return ""; } /** * 添加属性到oracle * @param addedAbList 添加的属性 * @param btmType 业务类型 */ private void addAttrToDB(Collection addedAbList,String btmType,boolean linkType){ if (!CollectionUtils.isEmpty(addedAbList)) { String tableName = linkType? LinkTypeProvider.getInstance().getLTTableName(btmType):BtmProvider.getInstance().getBTTableName(btmType); String addSql = "alter table " + tableName + " add("; Map attributeMap = attrService.selectAllAttributeMap(); for (String abName : addedAbList) { AttributeDef abItem = attrService.attributeVO2DO(attributeMap.get(abName)); addSql = addSql + Tool.getInstance().getAbSql(abItem); } addSql = VciBaseUtil.removeComma(addSql.replace("\n\t","")); addSql = addSql + ")"; //TODO 不清楚具体使用什么方法,暂时注释,但不要删除 // DDLToolClient.getService().batchExecuteUpdateOracle(new String[]{addSql}); } } /** * 移除属性 * @param removeAbList 要移除的属性列表 * @param btmType 业务类型的内容 */ private void removeAttrToDB(Collection removeAbList,String btmType,boolean linkType){ if (!CollectionUtils.isEmpty(removeAbList)) { String tableName = linkType?LinkTypeProvider.getInstance().getLTTableName(btmType):BtmProvider.getInstance().getBTTableName(btmType); String removeSql = "alter table " + tableName + " drop("; for (String abName : removeAbList) { removeSql = removeSql + abName + ","; } removeSql = VciBaseUtil.removeComma(removeSql.replace("\n\t","")); removeSql = removeSql + ")"; //TODO 不清楚具体使用什么方法,暂时注释,但不要删除 // DDLToolClient.getService().batchExecuteUpdateOracle(new String[]{removeSql}); } } /** * 封装业务类型 * @param btmItem 业务类型的对象 * @param btmTypeDTO 业务类型的数据传输对象 */ private void wrapperBtmItem(BizType btmItem ,OsBtmTypeDTO btmTypeDTO){ btmItem.label = btmTypeDTO.getName(); btmItem.description = btmTypeDTO.getDescription() == null ? "" : btmTypeDTO.getDescription(); btmItem.isAbstract = false; btmItem.fName = ""; btmItem.implClass = ""; btmItem.shape = ""; btmItem.lifeCycle = btmTypeDTO.getLifeCycleId() == null ? "" : btmTypeDTO.getLifeCycleId(); btmItem.lifeCycles = new String[0]; btmItem.imageName = ""; if (StringUtils.isBlank(btmTypeDTO.getRevisionRuleId())) { btmItem.revLevel = 0; } else { btmItem.revLevel = (StringUtils.isNotBlank(btmTypeDTO.getVersionRule()) && VciBtmType.VciBtmTypeVersionRule.NONE.getValue().equalsIgnoreCase(btmTypeDTO.getVersionRule())) ? (short) 1 : (short)2; } btmItem.revInput = btmTypeDTO.isInputRevisionFlag(); btmItem.revRuleName = btmTypeDTO.getRevisionRuleId()==null?"":btmTypeDTO.getRevisionRuleId(); btmItem.delimiter = ""; if (VciBtmType.VciBtmTypeVersionRule.INTSTART0.getValue().equalsIgnoreCase(btmTypeDTO.getVersionRule())) { btmItem.verRuleName = 2; } else if (VciBtmType.VciBtmTypeVersionRule.LETTER.getValue().equalsIgnoreCase(btmTypeDTO.getVersionRule())) { btmItem.verRuleName = 1; } else { btmItem.verRuleName = 0; } //包含的属性的数组 List attributesDTOList = btmTypeDTO.getAttributesDTOList(); List attrIdList = new ArrayList(); if (!CollectionUtils.isEmpty(attributesDTOList)) { for (OsBtmTypeLinkAttributesDTO attr : attributesDTOList) { attrIdList.add(attr.getId().toLowerCase()); } } btmItem.apNameArray = attrIdList.toArray(new String[0]); } /** * 导入链接类型 * @param linkTypeDTOS 链接类型的数据传输对象 */ private void importLinkType(Collection linkTypeDTOS){ Map allLinkMap = linkTypeService.selectAllLinkMap(); Set existLinkIdList = allLinkMap.keySet(); List addLinkTypeList = new ArrayList(); List editLinkTypeList = new ArrayList(); String userId = WebUtil.getCurrentUserId(); long now = VciDateUtil.getNowTime(); for(OsLinkTypeDTO linkTypeDTO : linkTypeDTOS){ String linkId = linkTypeDTO.getId().toLowerCase().trim(); LinkType linkType = null; boolean editFlag = false; if(!existLinkIdList.contains(linkId)) { linkType = new LinkType(); linkType.oid = ""; linkType.creator = userId; linkType.createTime = now; linkType.ts = now; }else { linkType = new LinkType(); OsLinkTypeVO linkTypeVO = allLinkMap.get(linkId); linkType.oid = linkTypeVO.getOid(); linkType.creator = linkTypeVO.getCreator(); linkType.createTime = VciDateUtil.getTime(linkTypeVO.getCreateTime()); linkType.ts = VciDateUtil.getTime(linkTypeVO.getTs()); editFlag = true; } linkType.modifier = userId; linkType.modifyTime = now; linkType.id = ""; linkType.name = linkId; linkType.tag = linkTypeDTO.getName(); linkType.description = linkTypeDTO.getDescription() == null ?"":linkTypeDTO.getDescription(); linkType.implClass = ""; linkType.shape = ""; linkType.btmItemsFrom = linkTypeDTO.getFromBtmType().split(","); linkType.btmItemsTo = linkTypeDTO.getToBtmType().split(","); linkType.primitivesFrom = linkType.btmItemsFrom[0]; linkType.primitivesTo = linkType.btmItemsTo[0]; linkType.relationFrom = "N:N"; linkType.relationTo = "N:N"; linkType.relation = "N:N"; List attrList = new ArrayList(); List attributesDTOList = linkTypeDTO.getAttributesDTOList(); if(!CollectionUtils.isEmpty(attributesDTOList)){ for(OsBtmTypeLinkAttributesDTO attr:attributesDTOList){ attrList.add(attr.getId().toLowerCase()); } } linkType.attributes = attrList.toArray(new String[0]); if(editFlag){ editLinkTypeList.add(linkType); }else{ addLinkTypeList.add(linkType); } } batchAddLink(addLinkTypeList); batchEditLink(editLinkTypeList); linkTypeService.clearCache(); linkTypeService.selectAllLink(); } /** * 批量添加链接类型 * @param linkTypes 链接类型的对象 */ public void batchAddLink(Collection linkTypes){ if(!CollectionUtils.isEmpty(linkTypes)){ Map attributeMap = attrService.selectAllAttributeMap(); for(LinkType linkType : linkTypes){ try{ platformClientUtil.getLinkTypeService().addLinkType(linkType); String tableName = LinkTypeProvider.getInstance().getLTTableName(linkType.name); String sql = "create table " + tableName + "(" + "\n\tOID VARCHAR2(36) not null,\n\tCreator VARCHAR2(36),\n\tCreateTime TIMESTAMP,\n\tLastModifier VARCHAR2(36),\n\tLastModifyTime TIMESTAMP,\n\tTS TIMESTAMP,\n\t"; String[] apNameArray = linkType.attributes; if(apNameArray!=null && apNameArray.length>0){ for(String attrId : apNameArray){ OsAttributeVO attrVO = attributeMap.get(attrId.toLowerCase().trim()); String abSql = Tool.getInstance().getAbSql(attrService.attributeVO2DO(attrVO)); sql = sql + abSql; } } sql = sql.substring(0, sql.lastIndexOf(",")); sql = sql + "\n)"; //TODO 不清楚具体使用什么方法,暂时注释,但不要删除 // DDLToolClient.getService().executeUpdateOracle(sql); // DDLToolClient.getService().executeUpdateOracle(LinkTypeProvider.getInstance().getAddPKSql(linkType.name)); }catch (PLException vciError){ throw WebUtil.getVciBaseException(vciError); } } } } /** * 批量修改链接类型 * @param linkTypes 链接类型的对象 */ public void batchEditLink(Collection linkTypes){ Map linkTypeVOMap = linkTypeService.selectAllLinkMap(); if(!CollectionUtils.isEmpty(linkTypes)){ for(LinkType linkType : linkTypes){ try{ platformClientUtil.getLinkTypeService().modifyLinkType(linkType); String linkTypeId = linkType.name.toLowerCase(Locale.ROOT); List addAttrList = new ArrayList(); //修改这里判断不了,是靠属性整体调整的 List deleteAttrList = new ArrayList(); Set newAttrSet = new HashSet(); Collections.addAll(newAttrSet,linkType.attributes); OsLinkTypeVO oldItem = linkTypeVOMap.get(linkType.name.toLowerCase(Locale.ROOT)); Set oldAttrSet = new HashSet(); Collections.addAll(oldAttrSet,oldItem.getAttributes().stream().map(OsLinkTypeAttributeVO::getId).collect(Collectors.toList()).toArray(new String[0])); for(String attr:newAttrSet){ if(!oldAttrSet.contains(attr)){ addAttrList.add(attr); } } for(String attr:oldAttrSet){ if(!newAttrSet.contains(attr)){ deleteAttrList.add(attr); } } addAttrToDB(addAttrList,linkTypeId,true); removeAttrToDB(deleteAttrList,linkTypeId,true); }catch (PLException vciError){ throw WebUtil.getVciBaseException(vciError); } } } } }