| | |
| | | import com.vci.client.common.datatype.VTLong; |
| | | import com.vci.client.common.datatype.VTString; |
| | | import com.vci.client.mw.ClientSessionUtility; |
| | | import com.vci.common.utility.ObjectUtility; |
| | | import com.vci.corba.common.PLException; |
| | | import com.vci.corba.omd.atm.AttributeDef; |
| | | import com.vci.corba.omd.ltm.LinkType; |
| | | import com.vci.corba.omd.vrm.VersionRule; |
| | | import com.vci.dto.OsAttributeDTO; |
| | | import com.vci.dto.OsEnumDTO; |
| | | import com.vci.dto.OsEnumItemDTO; |
| | | import com.vci.omd.dataType.VTDataType; |
| | | import com.vci.pagemodel.OsEnumItemVO; |
| | | import com.vci.pagemodel.OsEnumVO; |
| | | import com.vci.pagemodel.OsUsedAttributeVO; |
| | | import com.vci.omd.objects.OtherInfo; |
| | | import com.vci.pagemodel.*; |
| | | import com.vci.po.OsAttributePO; |
| | | import com.vci.po.OsEnumPO; |
| | | import com.vci.starter.poi.bo.ReadExcelOption; |
| | |
| | | import com.vci.starter.web.annotation.log.VciUnLog; |
| | | import com.vci.starter.web.enumpck.VciFieldTypeEnum; |
| | | import com.vci.starter.web.exception.VciBaseException; |
| | | import com.vci.starter.web.pagemodel.BaseQueryObject; |
| | | import com.vci.starter.web.pagemodel.BaseResult; |
| | | import com.vci.starter.web.pagemodel.DataGrid; |
| | | import com.vci.starter.web.pagemodel.*; |
| | | import com.vci.starter.web.util.*; |
| | | import com.vci.model.OsAttributeDO; |
| | | import com.vci.pagemodel.OsAttributeVO; |
| | | import com.vci.web.enumpck.ItemTypeEnum; |
| | | import com.vci.web.enumpck.PortalVITypeFlag; |
| | | import com.vci.web.properties.UsedNames; |
| | | import com.vci.web.service.OsAttributeServiceI; |
| | | import com.vci.web.service.OsBaseServiceI; |
| | | import com.vci.web.service.OsEnumServiceI; |
| | | import com.vci.web.service.OsLinkTypeServiceI; |
| | | import com.vci.web.util.Func; |
| | | import com.vci.web.util.PlatformClientUtil; |
| | |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | //import static com.vci.client.omd.attribpool.ui.VTDataTypePanel.*; |
| | | import static com.vci.omd.constants.AttributeConstants.*; |
| | |
| | | private OsBtmServiceImpl osBtmService; |
| | | |
| | | /** |
| | | * 枚举的服务 |
| | | */ |
| | | @Autowired |
| | | @Lazy |
| | | private OsEnumServiceI enumService; |
| | | |
| | | /** |
| | | * 必填列 |
| | | */ |
| | | private List<Integer> ColumnNameisRed = new ArrayList<Integer>(); |
| | |
| | | * 默认属性的映射,key是小写 |
| | | */ |
| | | private static Map<String,OsAttributeVO> defaultAttributeVOMap = new HashMap<>(); |
| | | |
| | | @Override |
| | | public List<Tree> getTreeAttributesByBtmName(TreeQueryObject treeQueryObject) { |
| | | List<Tree> rootTreeList=new ArrayList<>(); |
| | | |
| | | Map<String, String> conditionMap = treeQueryObject.getConditionMap(); |
| | | if (conditionMap == null) { |
| | | conditionMap = new HashMap<>(); |
| | | } |
| | | String typeName = StringUtils.isBlank(conditionMap.get("typeName")) ? "" : conditionMap.get("typeName"); |
| | | if (StringUtils.isBlank(typeName)) { |
| | | VciBaseUtil.alertNotNull(typeName,"业务类型名称"); |
| | | } |
| | | try { |
| | | String typeFlag=StringUtils.isBlank(conditionMap.get("typeFlag"))?"":conditionMap.get("typeFlag"); |
| | | PortalVITypeFlag portalVITypeFlag= PortalVITypeFlag.getByName(typeFlag); |
| | | Short viTypeFlag=-1; |
| | | if(portalVITypeFlag!=null){ |
| | | viTypeFlag=portalVITypeFlag.getIntVal(); |
| | | } |
| | | boolean isDefault =Boolean.parseBoolean(conditionMap.get("isDefault")); |
| | | Tree tree = new Tree("root", "【" + typeName + "】属性信息", "root"); |
| | | tree.setLevel(0); |
| | | rootTreeList.add(tree); |
| | | getChildTree(rootTreeList,typeName, viTypeFlag,isDefault); |
| | | }catch (Throwable e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return rootTreeList; |
| | | } |
| | | |
| | | /** |
| | | * 构造属性树节点 |
| | | * @param parentTreeList |
| | | * @param refTypeName |
| | | * @param refFlag |
| | | * @param isDefault |
| | | * @throws Exception |
| | | */ |
| | | private void getChildTree(List<Tree> parentTreeList,String refTypeName,int refFlag,boolean isDefault) throws Exception { |
| | | for (Tree pTree : parentTreeList) { |
| | | if (pTree.getLevel()>= 3) { |
| | | continue; |
| | | } |
| | | Object o= pTree.getData(); |
| | | String pName=pTree.getText(); |
| | | boolean isOsAttributeVO=false; |
| | | if(o instanceof OsAttributeVO){ |
| | | isOsAttributeVO=true; |
| | | OsAttributeVO osAttributeVO=(OsAttributeVO)o; |
| | | String other = osAttributeVO.getOther(); |
| | | OtherInfo otherInfo = OtherInfo.getOtherInfoByText(other); |
| | | refFlag = otherInfo.getRefFlag(); |
| | | refTypeName = otherInfo.getRefTypeName(); |
| | | } |
| | | List<OsAttributeVO> childOsAttributeVOList=new ArrayList<>(); |
| | | if (refFlag != -1) { |
| | | // pName: 为参照属性名加上路径 |
| | | childOsAttributeVOList=getOsAttributeVOSByBtName(refTypeName,refFlag,isDefault); |
| | | if(!CollectionUtils.isEmpty(childOsAttributeVOList)) { |
| | | List<Tree> childTreeList= new ArrayList<>(); |
| | | boolean finalIsOsAttributeVO = isOsAttributeVO; |
| | | childOsAttributeVOList.stream().forEach(childOsAttributeVO->{ |
| | | Tree childTree = new Tree(childOsAttributeVO.getOid(), childOsAttributeVO.getId(), childOsAttributeVO); |
| | | childTree.setOid(childOsAttributeVO.getOid()); |
| | | childTree.setParentName(pTree.getText()); |
| | | childTree.setParentId(pTree.getOid()); |
| | | childTree.setLevel(pTree.getLevel()+1); |
| | | childTree.setLeaf(true); |
| | | if(finalIsOsAttributeVO) { |
| | | childTree.setText(pName + "." + childOsAttributeVO.getId()); |
| | | }else{ |
| | | childTree.setText(childOsAttributeVO.getId()); |
| | | } |
| | | if (childTree.getLevel()>= 3) { |
| | | childTree.setLeaf(true); |
| | | } |
| | | childTreeList.add(childTree); |
| | | }); |
| | | if(childTreeList.size()>0){ |
| | | pTree.setChildren(childTreeList); |
| | | pTree.setExpanded(false); |
| | | getChildTree(childTreeList,refTypeName,refFlag,isDefault); |
| | | }else{ |
| | | pTree.setLeaf(true); |
| | | pTree.setExpanded(true); |
| | | } |
| | | |
| | | } |
| | | }else{ |
| | | pTree.setExpanded(true); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取默认的属性 |
| | |
| | | public List<OsAttributeVO> getByAttributeNames(String[] attrNames) throws PLException { |
| | | VciBaseUtil.alertNotNull(attrNames,"属性名"); |
| | | List<OsAttributeVO> osAttributeVOS = new ArrayList<>(); |
| | | for (int i = 0; i < attrNames.length; i++) { |
| | | AttributeDef[] attributeDefs = platformClientUtil.getAttributeService().getAttributeDefs(attrNames[i].toLowerCase(Locale.ROOT),1,1); |
| | | if(Func.isNotEmpty(attributeDefs)){ |
| | | Arrays.stream(attributeDefs).forEach(attributeDef -> { |
| | | osAttributeVOS.add(attributeDO2VO(attributeDef)); |
| | | }); |
| | | } |
| | | } |
| | | AttributeDef[] attributeDefs = platformClientUtil.getAttributeService().getAttributeDefsByNames(attrNames); |
| | | Arrays.stream(attributeDefs).forEach(attr->{ |
| | | osAttributeVOS.add(attributeDO2VO(attr)); |
| | | }); |
| | | return osAttributeVOS; |
| | | } |
| | | |
| | |
| | | attributeVO.setLastModifyTime(new Date(attribItem.modifyTime)); |
| | | attributeVO.setTs(VciDateUtil.str2Date(attribItem.ts,VciDateUtil.DateTimeMillFormat)); |
| | | }catch (Throwable e){ |
| | | |
| | | e.printStackTrace(); |
| | | String errorLog = "属性DO转VO时出错,原因:"+VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(errorLog); |
| | | throw new VciBaseException(errorLog); |
| | | } |
| | | attributeVO.setLastModifier(attribItem.modifier); |
| | | attributeVO.setName(attribItem.label); |
| | | attributeVO.setDescription(attribItem.description); |
| | | attributeVO.setAttributeDataType(attribItem.vtDataType); |
| | | attributeVO.setAttributeDataTypeText(VciFieldTypeEnum.getTextByValue(attribItem.vtDataType)); |
| | | //获取UI属性类型 |
| | | attributeVO.setAttributeUIType(ItemTypeEnum.convertAttributeTypeTOUITypeTextByValue(attribItem.vtDataType,false)); |
| | | //获取UI属性类型文本 |
| | | attributeVO.setAttributeUITypeText(ItemTypeEnum.convertAttributeTypeTOUITypeTextByValue(attribItem.vtDataType,true)); |
| | | attributeVO.setDefaultValue(attribItem.defValue); |
| | | if(Func.isNotBlank(attribItem.rage)){ |
| | | attributeVO.setRange(attribItem.rage.replace("<","<")); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 使用属性编号获取对象--批量 |
| | | * |
| | | * @param attrCodes 属性的英文名称 |
| | | * @param attributeVOMap 属性对象 |
| | | * @return 属性的显示对象 |
| | | */ |
| | | @Override |
| | | public List<OsAttributeVO> listAttrByIds(Collection<String> attrCodes,Map<String, OsAttributeVO> attributeVOMap) { |
| | | if(CollectionUtils.isEmpty(attrCodes)){ |
| | | return null; |
| | | } |
| | | if(attributeVOMap == null){ |
| | | attributeVOMap = self.selectAllAttributeMap(); |
| | | } |
| | | List<OsAttributeVO> attributeVOS = new ArrayList<>(); |
| | | Map<String, OsAttributeVO> finalAttributeVOMap = attributeVOMap; |
| | | attrCodes.stream().forEach(attrCode->{ |
| | | OsAttributeVO attributeVO = finalAttributeVOMap.getOrDefault(attrCode.toLowerCase(),null); |
| | | if(attributeVO!=null){ |
| | | attributeVOS.add(attributeVO); |
| | | } |
| | | }); |
| | | return attributeVOS; |
| | | } |
| | | |
| | | /** |
| | | * 批量添加属性 |
| | | * |
| | | * @param attribItemList 属性的列表 |
| | |
| | | ); |
| | | //属性英文名称校验(判空、系统中判重、是否关键字、是否合规等) |
| | | checkName(osAttributeDTO.getId()); |
| | | //检查属性名是否已存在与系统中 |
| | | if(platformClientUtil.getAttributeService().checkRowIsExists(osAttributeDTO.getId())){ |
| | | throw new PLException("500",new String[]{"属性名称【" + osAttributeDTO.getId() + "】在系统中已存在!"}); |
| | | } |
| | | //检查默认值与属性类型是否匹配 |
| | | checkDefValue(osAttributeDTO); |
| | | //dto对象转换为存储所需对象 |
| | | osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); |
| | | //osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); |
| | | AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO); |
| | | return platformClientUtil.getAttributeService().addAttributeDef(attributeDef); |
| | | } |
| | |
| | | //检查默认值与属性类型是否匹配 |
| | | checkDefValue(osAttributeDTO); |
| | | boolean compatible = isCompatible(osAttributeVO,osAttributeDTO); |
| | | boolean hasInstance = hasInstance(osAttributeDTO.getName()); |
| | | //产生数据, 并且不兼容 |
| | | if(hasInstance && !compatible){ |
| | | //boolean hasInstance = hasInstance(osAttributeDTO.getId()); //不判断是否产生数据只要被引用就需要进一步判断类型是否兼容 |
| | | boolean checkAttrIsUse = this.checkAttrIsUse(osAttributeDTO.getId()); |
| | | //TODO:按照以前操作配置文档中的逻辑应该是:不论是否产生数据只要被引用就需要要判断类型是否兼容(如VTString不能转为VTIntger或VTLong) |
| | | if(checkAttrIsUse/*hasInstance*/ && !compatible){ |
| | | throw new PLException("500",new String[]{"无效变更, 不兼容已产生的数据!"}); |
| | | } |
| | | String userId = "developer";//WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); |
| | | String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); |
| | | osAttributeDTO.setLastModifier(userId); |
| | | osAttributeDTO.setCreator(osAttributeVO.getCreator()); |
| | | osAttributeDTO.setCreateTime(osAttributeVO.getCreateTime()); |
| | |
| | | attributeDef.rage = osAttributeDTO.getRange().replace("<","<"); |
| | | } |
| | | attributeDef.ts = Func.format((Func.isNotEmpty(osAttributeDTO.getTs()) ? osAttributeDTO.getTs():new Date()),VciDateUtil.DateTimeMillFormat); |
| | | attributeDef.creator = "developer";//Func.isBlank(osAttributeDTO.getCreator()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getCreator(); |
| | | attributeDef.creator = Func.isBlank(osAttributeDTO.getCreator()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getCreator(); |
| | | attributeDef.createTime = Func.isEmpty(osAttributeDTO.getCreateTime()) ? System.currentTimeMillis():osAttributeDTO.getCreateTime().getTime(); |
| | | attributeDef.modifier = "developer";//Func.isBlank(osAttributeDTO.getLastModifier()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getLastModifier(); |
| | | attributeDef.modifier = Func.isBlank(osAttributeDTO.getLastModifier()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getLastModifier(); |
| | | attributeDef.modifyTime = System.currentTimeMillis(); |
| | | //other需要自行处理 |
| | | StringBuffer sb = new StringBuffer(); |
| | |
| | | if(StringUtils.isNotBlank(osAttributeDTO.getLinkTypeName())){ |
| | | //参照链接类型 |
| | | sb.append(LINKTYPENAME).append(" = ").append(osAttributeDTO.getLinkTypeName()).append(";"); |
| | | sb.append(VERSION).append(" = ").append(osAttributeDTO.getVersion()).append(";"); |
| | | } |
| | | sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";"); |
| | | if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查看属性是否被引用 |
| | | * @param abName |
| | | * @return false未被引用 true被引用 |
| | | */ |
| | | private boolean checkAttrIsUse(String abName) throws PLException { |
| | | if(Func.isBlank(abName)){ |
| | | return false; |
| | | } |
| | | String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(abName); |
| | | if(Func.isNotEmpty(btNames)){ |
| | | return true; |
| | | } |
| | | String[] ltNames = platformClientUtil.getLinkTypeService().getLTNamesByAPName(abName); |
| | | if(Func.isNotEmpty(ltNames)){ |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 检查属性名称是否符合规范 |
| | | * @param attributeName |
| | | * @return 没有返回值,存在问题直接抛出错误 |
| | |
| | | throw new PLException("500",new String[]{"属性名无效,原因:属性名是数据库关键字!"}); |
| | | } |
| | | //检查属性名是否已存在与系统中 |
| | | if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){ |
| | | throw new PLException("500",new String[]{"属性名称在系统中已存在!"}); |
| | | } |
| | | /*if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){ |
| | | throw new PLException("500",new String[]{"属性名称【" + abName + "】在系统中已存在!"}); |
| | | }*/ |
| | | } |
| | | |
| | | /** |
| | |
| | | if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){ |
| | | throw new PLException("500",new String[]{"待删除的属性列表中主键【oid】、调整时间【ts】、属性名【name】不能为空!"}); |
| | | } |
| | | //判断枚举是否有被引用 |
| | | //判断属性是否有被引用 |
| | | List<Map<String, String>> usedAttrList = this.getUsedAttributeList(name); |
| | | if(Func.isNotEmpty(usedAttrList)){ |
| | | throw new PLException("500",new String[]{"删除的属性中,属性名称为:【" + name + "】,已被引用!"}); |
| | |
| | | throw new PLException("500",new String[]{"请选择要查询应用范围的属性!"}); |
| | | } |
| | | String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(attributeName); |
| | | if(Func.isEmpty(btNames)){ |
| | | String[] ltNames = platformClientUtil.getLinkTypeService().getLTNamesByAPName(attributeName); |
| | | String[] mergedArray = Stream.concat(Stream.of(btNames), Stream.of(ltNames)).toArray(String[]::new); |
| | | |
| | | if(Func.isEmpty(mergedArray)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | List<Map<String,String>> btmNameMapList = new ArrayList<>(); |
| | | Arrays.stream(btNames).forEach(btName->{ |
| | | Arrays.stream(mergedArray).forEach(btName->{ |
| | | Map<String, String> itemMap = new HashMap<>(); |
| | | itemMap.put("attributeName",attributeName); |
| | | itemMap.put("source",btName); |
| | |
| | | * 导出选中的属性 |
| | | * @param exportFileName 导出的文件名 |
| | | * @param attrNames 需要导出的属性名称 |
| | | * @param flag 控制导出的列名是否和导入模板一致 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String exportAttributes(String exportFileName, String attrNames) throws PLException { |
| | | public String exportAttributes(String exportFileName, String attrNames,boolean flag/*控制导出的列名是否和导入模板一致*/) throws PLException { |
| | | if(Func.isBlank(attrNames)){ |
| | | throw new PLException("500",new String[]{"请勾选要导出的属性!"}); |
| | | } |
| | | //界面没传名称,使用默认导出名称 |
| | | exportFileName = Func.isBlank(exportFileName) ? "属性池中属性导出_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName; |
| | | //设置列名 |
| | | List<String> columns = new ArrayList<>( |
| | | Arrays.asList("属性名", "标签", "描述", |
| | | "属性类型", "允许为空", "默认值", "使用的枚举英文名称(枚举名)", |
| | | "使用的枚举中文名称(标签)", "参照的业务类型编号", "参照的业务类型名称", |
| | | "参照的链接类型名称","版本版次","属性长度", "小数精度位数","小数刻度位数","取值范围","创建时间") |
| | | ); |
| | | List<String> columns = this.getCloumns(flag); |
| | | |
| | | //写excel |
| | | String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls"; |
| | |
| | | excelDataList.add(new WriteExcelData(0,index, columns.get(index))); |
| | | } |
| | | //按照属性名查询属性,然后处理属性导出 |
| | | List<String> enumNameList = Func.toStrList(attrNames); |
| | | List<OsAttributeVO> osAttributeVOS = this.listAttrByIds(enumNameList); |
| | | List<String> attrameList = Func.toStrList(attrNames); |
| | | List<OsAttributeVO> osAttributeVOS = this.listAttrByIds(attrameList); |
| | | if(Func.isEmpty(osAttributeVOS)){ |
| | | excelDataList.add(new WriteExcelData(1,1, "根据属性名称未查询到属性信息,请刷新后尝试重新导出!")); |
| | | }else{ |
| | |
| | | excelDataList.add(new WriteExcelData(i+1,0, osAttributeVO.getId())); |
| | | excelDataList.add(new WriteExcelData(i+1,1, osAttributeVO.getName())); |
| | | excelDataList.add(new WriteExcelData(i+1,2, osAttributeVO.getDescription())); |
| | | excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataTypeText()+"("+osAttributeVO.getAttributeDataType()+")")); |
| | | if(flag){ |
| | | excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataType())); |
| | | }else{ |
| | | excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataType()+"("+osAttributeVO.getAttributeDataTypeText()+")")); |
| | | } |
| | | excelDataList.add(new WriteExcelData(i+1,4, osAttributeVO.isNullableFlag())); |
| | | excelDataList.add(new WriteExcelData(i+1,5, osAttributeVO.getDefaultValue())); |
| | | excelDataList.add(new WriteExcelData(i+1,6, osAttributeVO.getEnumId())); |
| | | excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getEnumName())); |
| | | excelDataList.add(new WriteExcelData(i+1,8, osAttributeVO.getBtmTypeId())); |
| | | excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getBtmTypeName())); |
| | | excelDataList.add(new WriteExcelData(i+1,10, osAttributeVO.getAttrLength())); |
| | | excelDataList.add(new WriteExcelData(i+1,11, osAttributeVO.getLinkTypeName())); |
| | | excelDataList.add(new WriteExcelData(i+1,12, osAttributeVO.getVersion())); |
| | | excelDataList.add(new WriteExcelData(i+1,13, osAttributeVO.getPrecisionLength())); |
| | | excelDataList.add(new WriteExcelData(i+1,14, osAttributeVO.getScaleLength())); |
| | | excelDataList.add(new WriteExcelData(i+1,15, osAttributeVO.getRange())); |
| | | excelDataList.add(new WriteExcelData(i+1,16, osAttributeVO.getCreateTime())); |
| | | //excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getEnumName())); |
| | | excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getBtmTypeId())); |
| | | //excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getBtmTypeName())); |
| | | excelDataList.add(new WriteExcelData(i+1,8, osAttributeVO.getAttrLength())); |
| | | excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getLinkTypeName())); |
| | | excelDataList.add(new WriteExcelData(i+1,10, osAttributeVO.getVersion())); |
| | | excelDataList.add(new WriteExcelData(i+1,11, osAttributeVO.getPrecisionLength())); |
| | | excelDataList.add(new WriteExcelData(i+1,12, osAttributeVO.getScaleLength())); |
| | | excelDataList.add(new WriteExcelData(i+1,13, osAttributeVO.getRange())); |
| | | if(!flag){ |
| | | excelDataList.add(new WriteExcelData(i+1,14, Func.format(osAttributeVO.getCreateTime(),"yyyy年MM月dd日 hh:mm:ss"))); |
| | | } |
| | | } |
| | | } |
| | | WriteExcelOption excelOption = new WriteExcelOption(excelDataList); |
| | | ExcelUtil.writeDataToFile(excelPath, excelOption); |
| | | return excelPath; |
| | | } |
| | | |
| | | /** |
| | | * 获取导出或导入模板的列名 |
| | | * @param flag 是否获取导入模板列名 |
| | | * @return |
| | | */ |
| | | private List<String> getCloumns(boolean flag){ |
| | | if(flag){ |
| | | return new ArrayList<>( |
| | | Arrays.asList("属性名", "标签", "描述", |
| | | "属性类型(参照新增界面的属性类型如VTString)", "允许为空(是/否)", "默认值", "使用的枚举英文名称" |
| | | , "参照的业务类型编号","参照的链接类型编号","版本版次","属性长度", "小数精度位数","小数刻度位数" |
| | | ,"取值范围" |
| | | ) |
| | | ); |
| | | } |
| | | return new ArrayList<>( |
| | | Arrays.asList("属性名", "标签", "描述", |
| | | "属性类型", "允许为空", "默认值", "使用的枚举英文名称(枚举名)", |
| | | "参照的业务类型编号", "参照的链接类型编号","版本版次","属性长度", |
| | | "小数精度位数","小数刻度位数","取值范围","创建时间") |
| | | ); |
| | | } |
| | | |
| | | /** |
| | |
| | | //界面没传名称,使用默认导出名称 |
| | | exportFileName = Func.isBlank(exportFileName) ? "属性池导入模板_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName; |
| | | //设置列名 |
| | | List<String> columns = new ArrayList<>( |
| | | Arrays.asList("属性名", "标签", "描述", |
| | | "属性类型", "允许为空(是/否)", "默认值", "使用的枚举英文名称", "参照的业务类型编号", |
| | | "参照的链接类型编号","版本版次","属性长度", "小数精度位数","小数刻度位数","取值范围") |
| | | ); |
| | | List<String> columns = this.getCloumns(true); |
| | | //设置必填列 |
| | | ColumnNameisRed.clear(); |
| | | ColumnNameisRed.add(0); |
| | |
| | | /** |
| | | * 导入属性 |
| | | * @param file |
| | | * @param isContinue 系统中出现重复是否跳过报错继续执行 |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public BaseResult importAttributes(File file) throws Exception{ |
| | | public BaseResult importAttributes(File file, boolean isContinue) throws Exception{ |
| | | VciBaseUtil.alertNotNull(file,"excel文件"); |
| | | if(!file.exists()){ |
| | | throw new VciBaseException("导入的excel文件不存在,{0}",new String[]{file.getPath()}); |
| | |
| | | List<OsAttributeDTO> dtoList = new ArrayList<>(); |
| | | //当前excel中是否重复用的判重Map:(key:判重属性,value:行号) |
| | | Map<String, String> excelReapeat = new HashMap<>(); |
| | | //判断必填属性是否为空,用户是否已存在,以及部门是否填错等校验逻辑 |
| | | poList.stream().forEach(osAttributePO -> { |
| | | for (int i = 0; i < poList.size(); i++) { |
| | | OsAttributePO osAttributePO = poList.get(i); |
| | | if(Func.isBlank(osAttributePO.getId())){//属性名判空 |
| | | throw new VciBaseException("第【"+osAttributePO.getRowIndex()+"】行,enumnameerror"); |
| | | throw new VciBaseException("第【"+osAttributePO.getRowIndex()+"】行,attrnameerror"); |
| | | }else if(Func.isBlank(osAttributePO.getAttributeDataType())){ |
| | | throw new VciBaseException("第【"+osAttributePO.getRowIndex()+"】行,typeerror"); |
| | | }else if(excelReapeat.containsKey(osAttributePO.getId())){//属性名表格中判重 |
| | | throw new VciBaseException("第【"+excelReapeat.get(osAttributePO.getId())+"】行和第【"+osAttributePO.getRowIndex()+"】行数据,属性名重复"); |
| | | }else { |
| | | try { |
| | | if(platformClientUtil.getAttributeService().checkRowIsExists(osAttributePO.getId())){ |
| | | throw new PLException("500",new String[]{"属性名称【" + osAttributePO.getId() + "】在系统中已存在!"}); |
| | | } |
| | | } catch (PLException e) { |
| | | e.printStackTrace(); |
| | | String errorMsg = "与系统中属性名查重时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(errorMsg); |
| | | //是否跳过当期重复数据 |
| | | if(isContinue){ |
| | | continue; |
| | | } |
| | | throw new VciBaseException(errorMsg); |
| | | } |
| | | } |
| | | //属性名校验 |
| | | try { |
| | |
| | | //属性名excel中判重处理 |
| | | excelReapeat.put(osAttributePO.getId(),osAttributePO.getRowIndex()); |
| | | OsAttributeDTO osAttributeDTO = new OsAttributeDTO(); |
| | | osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); |
| | | //查询属性是否存在,填写了枚举但没填写取值范围,这时候直接使用枚举项值作为默认的range |
| | | if(Func.isNotBlank(osAttributePO.getEnumId()) && Func.isBlank(osAttributePO.getRange())){ |
| | | try { |
| | | OsEnumVO enumVO = enumService.getEnumTypeById(osAttributePO.getEnumId()); |
| | | if(Func.isEmpty(enumVO)){ |
| | | throw new VciBaseException("第【" + osAttributePO.getRowIndex() + "】行数据,通过枚举名称【" + osAttributePO.getEnumId() |
| | | + "】未获取到枚举信息!"); |
| | | } |
| | | String itemValues = enumVO.getItemMaps().values().stream().collect(Collectors.joining(";")); |
| | | osAttributeDTO.setRange(itemValues); |
| | | } catch (PLException e) { |
| | | e.printStackTrace(); |
| | | throw new VciBaseException("枚举查询失败,原因:"+e.getMessage()); |
| | | } |
| | | osAttributeDTO.setBtmTypeId(osAttributePO.getEnumId()); |
| | | } |
| | | osAttributeDTO.setOid(ObjectUtility.getNewObjectID36()); |
| | | osAttributeDTO.setId(osAttributePO.getId()); |
| | | osAttributeDTO.setName(osAttributePO.getName()); |
| | | osAttributeDTO.setDescription(osAttributePO.getDescription()); |
| | |
| | | checkDefValue(osAttributeDTO); |
| | | } catch (PLException e) { |
| | | e.printStackTrace(); |
| | | throw new VciBaseException(e.getMessage()); |
| | | throw new VciBaseException(VciBaseUtil.getExceptionMessage(e)); |
| | | } |
| | | dtoList.add(osAttributeDTO); |
| | | }); |
| | | } |
| | | //执行保存操作 |
| | | dtoList.stream().forEach(dto->{ |
| | | try { |
| | |
| | | } |
| | | } catch (PLException e) { |
| | | e.printStackTrace(); |
| | | throw new VciBaseException("执行保存时出现错误,错误属性对象名为:【" + dto.getId() + "】,原因:"+e.getMessage()); |
| | | throw new VciBaseException("执行保存时出现错误,错误属性对象名为:【" + dto.getId() + "】,原因:"+VciBaseUtil.getExceptionMessage(e)); |
| | | } |
| | | }); |
| | | }catch (Exception e){ |
| | | if(logger.isErrorEnabled()){ |
| | | logger.error("读取excel内容时或保存用户信息时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e)); |
| | | logger.error("读取excel内容时或保存属性时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e)); |
| | | } |
| | | e.printStackTrace(); |
| | | return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e); |
| | | } |
| | | return BaseResult.success("枚举导入成功!"); |
| | | return BaseResult.success("属性导入成功!"); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据业务类型获取属性信息 |
| | | * @param btName 业务类型/链接类型 |
| | | * @param typeFlag 0:业务类型,1:链接类型 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<OsAttributeVO> getOsAttributeVOSByBtName(String btName, int typeFlag,boolean isDefault) throws Exception{ |
| | | VciBaseUtil.alertNotNull(btName,"参数不允许为空",typeFlag,"参数不允许为空"); |
| | | List<OsAttributeVO> attributeVOS=new ArrayList<>(); |
| | | |
| | | try { |
| | | List<AttributeDef> attributeDefList=new ArrayList<>(); |
| | | if(typeFlag==0){ |
| | | AttributeDef [] attributeDefs= platformClientUtil.getBtmService().getAttributeDefs(btName); |
| | | if(attributeDefs!=null){ |
| | | attributeDefList.addAll(Arrays.stream(attributeDefs).collect(Collectors.toList())); |
| | | } |
| | | if(isDefault){ |
| | | AttributeDef [] sysAttributeDefs=platformClientUtil.getBtmService().getSysAttributeDefs(); |
| | | if(sysAttributeDefs!=null){ |
| | | attributeDefList.addAll(Arrays.stream(sysAttributeDefs).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | }else{ |
| | | AttributeDef [] attributeDefs=platformClientUtil.getLinkTypeService().getAttributes(btName); |
| | | if(attributeDefs!=null){ |
| | | attributeDefList.addAll(Arrays.stream(attributeDefs).collect(Collectors.toList())); |
| | | } |
| | | if(isDefault){ |
| | | AttributeDef[] sysAbItems = platformClientUtil.getLinkTypeService().getSysAttributeDefs(); |
| | | if(sysAbItems!=null){ |
| | | attributeDefList.addAll(Arrays.stream(sysAbItems).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | } |
| | | attributeVOS=attributeDO2VOs(attributeDefList); |
| | | }catch (PLException e){ |
| | | throw new Exception("根据业务类型获取属性异常"+e.getMessage()); |
| | | } |
| | | |
| | | return attributeVOS; |
| | | } |
| | | |
| | | /** |
| | | * 是否为参照属性 |
| | | * @param other 配置的其他 |
| | | * @return true 是参照 |