| | |
| | | package com.vci.web.service.impl; |
| | | |
| | | import com.vci.client.common.datatype.VTDouble; |
| | | import com.vci.client.common.datatype.VTInteger; |
| | | import com.vci.client.common.datatype.VTLong; |
| | | import com.vci.client.common.datatype.VTString; |
| | | import com.vci.client.mw.ClientSessionUtility; |
| | | import com.vci.corba.common.PLException; |
| | | import com.vci.corba.omd.atm.AttributeDef; |
| | | import com.vci.dto.OsAttributeDTO; |
| | | import com.vci.omd.dataType.VTDataType; |
| | | import com.vci.pagemodel.OsEnumItemVO; |
| | | import com.vci.pagemodel.OsEnumVO; |
| | | import com.vci.pagemodel.OsUsedAttributeVO; |
| | | 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.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.DataGrid; |
| | | import com.vci.starter.web.util.VciBaseUtil; |
| | | import com.vci.starter.web.util.VciDateUtil; |
| | | import com.vci.starter.web.util.*; |
| | | import com.vci.model.OsAttributeDO; |
| | | import com.vci.pagemodel.OsAttributeVO; |
| | | import com.vci.web.properties.UsedNames; |
| | | import com.vci.web.service.OsAttributeServiceI; |
| | | import com.vci.web.service.OsBaseServiceI; |
| | | import com.vci.web.service.OsLinkTypeServiceI; |
| | | 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.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.swing.*; |
| | | import java.awt.*; |
| | | import java.io.File; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | //import static com.vci.client.omd.attribpool.ui.VTDataTypePanel.*; |
| | |
| | | @Autowired(required = false) |
| | | @Lazy |
| | | private OsAttributeServiceI self; |
| | | |
| | | /** |
| | | * 属性名称最大长度 |
| | | */ |
| | | private Integer NAME_MAX_LENGTH = 28; |
| | | |
| | | /** |
| | | * 系统中变量配置文件中配置的key |
| | | */ |
| | | private final String SYSUSEDNAMES = "sysUsedNames"; |
| | | |
| | | /** |
| | | * 数据库中关键字配置文件中配置的key |
| | | */ |
| | | private final String DATABASEUSEDNAMES = "dataBaseUsedNames"; |
| | | |
| | | /** |
| | | * 链接类型服务 |
| | | */ |
| | | @Autowired(required = false) |
| | | @Lazy |
| | | private OsLinkTypeServiceI osLinkTypeServiceI; |
| | | |
| | | /** |
| | | * 业务类型服务 |
| | | */ |
| | | @Autowired(required = false) |
| | | @Lazy |
| | | private OsBtmServiceImpl osBtmService; |
| | | |
| | | /** |
| | | * 默认的属性 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据多个属性名称查询属性 |
| | | * @param attrNames |
| | | * @return |
| | | */ |
| | | @Override |
| | | 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],1,1); |
| | | if(Func.isNotEmpty(attributeDefs)){ |
| | | Arrays.stream(attributeDefs).forEach(attributeDef -> { |
| | | osAttributeVOS.add(attributeDO2VO(attributeDef)); |
| | | }); |
| | | } |
| | | } |
| | | return osAttributeVOS; |
| | | } |
| | | |
| | | /** |
| | | * 属性的数据对象转换为显示对象 |
| | | * |
| | | * @param attribItems 数据对象 |
| | |
| | | attributeVO.setAttributeDataTypeText(VciFieldTypeEnum.getTextByValue(attribItem.vtDataType)); |
| | | attributeVO.setDefaultValue(attribItem.defValue); |
| | | attributeVO.setRange(attribItem.rage); |
| | | attributeVO.setOther(attribItem.other); |
| | | //处理参照相关属性 |
| | | if(StringUtils.isNotBlank(attribItem.other)) { |
| | | if (isReferAttr(attribItem.other)) { |
| | | //说明这个的确是参照字段 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 添加单条属性 |
| | | * @param osAttributeDTO |
| | | * @return true成功,false失败 |
| | | */ |
| | | @Override |
| | | public boolean addAttribute(OsAttributeDTO osAttributeDTO) throws PLException { |
| | | //判空 |
| | | VciBaseUtil.alertNotNull( |
| | | osAttributeDTO,"创建的属性对象", |
| | | osAttributeDTO.getId(),"属性名称", |
| | | osAttributeDTO.getAttributeDataType(),"属性类型" |
| | | ); |
| | | //属性英文名称校验(判空、系统中判重、是否关键字、是否合规等) |
| | | checkName(osAttributeDTO.getId()); |
| | | //检查默认值与属性类型是否匹配 |
| | | checkDefValue(osAttributeDTO); |
| | | //dto对象转换为存储所需对象 |
| | | AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO); |
| | | return platformClientUtil.getAttributeService().addAttributeDef(attributeDef); |
| | | } |
| | | |
| | | /** |
| | | * 修改单条属性 |
| | | * @param osAttributeDTO |
| | | * @return true成功,false失败 |
| | | */ |
| | | @Override |
| | | public boolean updateAttribute(OsAttributeDTO osAttributeDTO) throws PLException { |
| | | //判空 |
| | | VciBaseUtil.alertNotNull( |
| | | osAttributeDTO,"修改的属性对象", |
| | | osAttributeDTO.getId(),"属性名称", |
| | | osAttributeDTO.getTs(),"事务TS", |
| | | osAttributeDTO.getAttributeDataType(),"属性类型" |
| | | ); |
| | | |
| | | //名称不允许修改所以不用查重 |
| | | //但是需要检查属性是否存在 |
| | | OsAttributeVO osAttributeVO = getByAttributeNames(new String[]{osAttributeDTO.getId()}).get(0); |
| | | if(Func.isEmpty(osAttributeVO) || Func.isBlank(osAttributeVO.getOid())){ |
| | | throw new PLException("500",new String[]{"属性在系统中不存在,请刷新后重试!"}); |
| | | } |
| | | //检查默认值与属性类型是否匹配 |
| | | checkDefValue(osAttributeDTO); |
| | | boolean compatible = isCompatible(osAttributeVO,osAttributeDTO); |
| | | boolean hasInstance = hasInstance(osAttributeDTO.getName()); |
| | | //产生数据, 并且不兼容 |
| | | if(hasInstance && !compatible){ |
| | | throw new PLException("500",new String[]{"无效变更, 不兼容已产生的数据!"}); |
| | | } |
| | | String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); |
| | | osAttributeDTO.setLastModifier(userId); |
| | | osAttributeDTO.setCreator(osAttributeVO.getCreator()); |
| | | osAttributeDTO.setCreateTime(osAttributeVO.getCreateTime()); |
| | | osAttributeDTO.setLastModifyTime(new Date()); |
| | | |
| | | try { |
| | | AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO); |
| | | boolean mdSuccess = platformClientUtil.getAttributeService().modifyAttributeDef(attributeDef); |
| | | if(!mdSuccess){ |
| | | return false; |
| | | } |
| | | |
| | | //属性修改成功,修改业务类型, 链接类型中该属性字段 |
| | | boolean alterApBoolean = this.alterAp(attributeDef.name); |
| | | if(!alterApBoolean){ |
| | | logger.error("属性修改完成,但在调整业务类型或链接类型中对应属性名的属性时出现错误!"); |
| | | throw new PLException("500",new String[]{"属性修改完成,但在调整业务类型或链接类型中对应属性名的属性时出现错误!"}); |
| | | } |
| | | return true; |
| | | } catch (PLException e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * DTO对象转实际存储所需的AttributeDef对象 |
| | | * @param osAttributeDTO |
| | | * @return |
| | | */ |
| | | private AttributeDef osAttributeDTO2AttributeDef(OsAttributeDTO osAttributeDTO) { |
| | | AttributeDef attributeDef = new AttributeDef(); |
| | | attributeDef.name = osAttributeDTO.getId().toLowerCase().replaceAll(" ", ""); |
| | | attributeDef.label = osAttributeDTO.getName(); |
| | | attributeDef.description = osAttributeDTO.getDescription(); |
| | | attributeDef.vtDataType = (String)osAttributeDTO.getAttributeDataType(); |
| | | attributeDef.defValue = Func.isBlank(osAttributeDTO.getDefaultValue()) ? "" : osAttributeDTO.getDefaultValue(); |
| | | attributeDef.rage = Func.isBlank(osAttributeDTO.getRange()) ? "" : osAttributeDTO.getRange(); |
| | | attributeDef.creator = Func.isBlank(osAttributeDTO.getCreator()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getCreator(); |
| | | attributeDef.ts = Func.format((Func.isNotEmpty(osAttributeDTO.getTs()) ? osAttributeDTO.getTs():new Date()),VciDateUtil.DateTimeMillFormat); |
| | | attributeDef.createTime = Func.isEmpty(osAttributeDTO.getCreateTime()) ? System.currentTimeMillis():osAttributeDTO.getCreateTime().getTime(); |
| | | attributeDef.modifier = Func.isBlank(osAttributeDTO.getLastModifier()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getLastModifier(); |
| | | attributeDef.modifyTime = System.currentTimeMillis(); |
| | | //other需要自行处理 |
| | | StringBuffer sb = new StringBuffer(); |
| | | sb.append(ALLOWNULL).append(" = ").append(osAttributeDTO.isNullableFlag() ? "yes" : "no").append(";"); |
| | | VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.valueOf(osAttributeDTO.getAttributeDataType()); |
| | | String[] otherInfos = attributeDef.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: |
| | | if(osAttributeDTO.getAttrLength() == null){ |
| | | osAttributeDTO.setAttrLength(20); |
| | | } |
| | | if(osAttributeDTO.getPrecisionLength() == null){ |
| | | osAttributeDTO.setPrecisionLength(2); |
| | | } |
| | | sb.append(ACCURACY).append(" = ").append(osAttributeDTO.getPrecisionLength()).append(";"); |
| | | sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";"); |
| | | |
| | | break; |
| | | case VTInteger: |
| | | if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) { |
| | | sb.append(ENUMNAME).append(" = ").append(osAttributeDTO.getEnumId()).append(";"); |
| | | } |
| | | break; |
| | | case VTString: |
| | | if (StringUtils.isNotBlank(osAttributeDTO.getBtmTypeId())) { |
| | | //参照 |
| | | sb.append(BTM).append(" = ").append(osAttributeDTO.getBtmTypeId()).append(";"); |
| | | //链接类型暂时不支持 |
| | | } |
| | | sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";"); |
| | | if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) { |
| | | sb.append(ENUMNAME).append(" = ").append(osAttributeDTO.getEnumId()).append(";"); |
| | | } |
| | | break; |
| | | default: |
| | | //不需要处理 |
| | | break; |
| | | } |
| | | attributeDef.other = sb.toString(); |
| | | if (attributeDef.other.endsWith(";")) { |
| | | attributeDef.other = attributeDef.other.substring(0, attributeDef.other.length() - 1); |
| | | } |
| | | return attributeDef; |
| | | } |
| | | |
| | | /** |
| | | * 修改属性时, 判断当前输入的属性是否能兼容之前的属性 |
| | | * @param osAttributeVO 数据库中存储的 |
| | | * @param osAttributeDTO 修改后的内容 |
| | | * @return |
| | | */ |
| | | private boolean isCompatible(OsAttributeVO osAttributeVO/*数据库中存储的*/,OsAttributeDTO osAttributeDTO/*修改后的内容*/){ |
| | | String dataType = osAttributeVO.getAttributeDataType(); |
| | | //String other = osAttributeVO.getOther(); |
| | | //String newOther = abItem.other == null ? "" : abItem.other; |
| | | String newType = osAttributeDTO.getAttributeDataType(); |
| | | if(newType.equals(VTDataType.VTSTRING)){ |
| | | if(dataType.equals(VTDataType.VTINTEGER) || dataType.equals(VTDataType.VTLONG)){ |
| | | return true; |
| | | } |
| | | if(dataType.equals(VTDataType.VTSTRING)){ |
| | | int length = osAttributeVO.getAttrLength();//Integer.valueOf(getOtherValueByType(other, "length")); |
| | | int newLen = osAttributeDTO.getAttrLength();//Integer.valueOf(getOtherValueByType(newOther, "length")); |
| | | if(length <= newLen){ |
| | | return true; |
| | | }else{ |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(newType.equals(dataType)){ |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 判断该属性是否已经在业务类型中, 或者链接类型中产生了数据 |
| | | * @param abName |
| | | * @return |
| | | */ |
| | | private boolean hasInstance(String abName) throws PLException { |
| | | return osBtmService.hasInstance(abName) && osLinkTypeServiceI.hasInstance(abName); |
| | | } |
| | | |
| | | /** |
| | | * 检查属性名称是否符合规范 |
| | | * @param attributeName |
| | | * @return 没有返回值,存在问题直接抛出错误 |
| | | */ |
| | | private void checkName(String attributeName) throws PLException { |
| | | if(attributeName.equals("")){ |
| | | throw new PLException("500",new String[]{"注意,属性名不能为空!"}); |
| | | } |
| | | |
| | | if(!attributeName.matches("[a-z A-Z]*")){ |
| | | throw new PLException("500",new String[]{"注意:属性名只能为英文字母!"+ NAME_MAX_LENGTH}); |
| | | } |
| | | |
| | | int length = attributeName.length(); |
| | | if(length > NAME_MAX_LENGTH){ |
| | | throw new PLException("500",new String[]{"属性名过长,属性名长度不能超过!"+ NAME_MAX_LENGTH}); |
| | | } |
| | | |
| | | String abName = attributeName.toLowerCase(); |
| | | //检查属性名是否是为系统基础属性,如createTime,ts,oid等 |
| | | if(usedBySystem(abName)){ |
| | | throw new PLException("500",new String[]{"属性名无效,原因:属性名已被系统属性使用!"}); |
| | | } |
| | | //检查属性名是否是关键字 |
| | | if(usedByDataBase(abName)){ |
| | | throw new PLException("500",new String[]{"属性名无效,原因:属性名是数据库关键字!"}); |
| | | } |
| | | //检查属性名是否已存在与系统中 |
| | | if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){ |
| | | throw new PLException("500",new String[]{"属性名称在系统中已存在!"}); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检查默认值与属性类型是否匹配 |
| | | * @param osAttributeDTO |
| | | * @return |
| | | */ |
| | | private void checkDefValue(OsAttributeDTO osAttributeDTO) throws PLException { |
| | | String defValue = osAttributeDTO.getDefaultValue(); |
| | | String vtType = osAttributeDTO.getAttributeDataType(); |
| | | String rages = osAttributeDTO.getRange(); |
| | | if(defValue != null && !defValue.equals("")){ |
| | | if(vtType.equals(VTDataType.VTSTRING)){ |
| | | try{ |
| | | String.valueOf(defValue); |
| | | }catch(Exception e){ |
| | | throw new PLException("500",new String[]{"请输入String类型的默认值!"}); |
| | | } |
| | | if(rages == null || rages.equals("")){ |
| | | return; |
| | | } |
| | | VTString obj = new VTString(String.valueOf(defValue)); |
| | | boolean flag = obj.checkRageValueByRage(rages); |
| | | if(!flag){ |
| | | throw new PLException("500",new String[]{"默认值与值域冲突!"}); |
| | | } |
| | | }else if(vtType.equals(VTDataType.VTINTEGER)){ |
| | | try{ |
| | | Integer.valueOf(defValue); |
| | | }catch(Exception e){ |
| | | throw new PLException("500",new String[]{"请输入Integer类型的默认值!"}); |
| | | } |
| | | if(rages == null || rages.equals("")){ |
| | | return; |
| | | } |
| | | |
| | | VTInteger obj = new VTInteger(Integer.valueOf(defValue)); |
| | | boolean flag = obj.checkRageValueByRage(rages); |
| | | if(!flag){ |
| | | throw new PLException("500",new String[]{"默认值与值域冲突!"}); |
| | | } |
| | | }else if(vtType.equals(VTDataType.VTLONG)){ |
| | | try{ |
| | | Long.valueOf(defValue); |
| | | }catch(Exception e){ |
| | | throw new PLException("500",new String[]{"请输入Long类型的默认值!"}); |
| | | } |
| | | if(rages == null || rages.equals("")){ |
| | | return; |
| | | } |
| | | |
| | | VTLong obj = new VTLong(Long.valueOf(defValue)); |
| | | boolean flag = obj.checkRageValueByRage(rages); |
| | | if(!flag){ |
| | | throw new PLException("500",new String[]{"默认值与值域冲突!"}); |
| | | } |
| | | }else if(vtType.equals(VTDataType.VTDOUBLE)){ |
| | | try{ |
| | | Double.valueOf(defValue); |
| | | }catch(Exception e){ |
| | | throw new PLException("500",new String[]{"请输入Double类型的默认值!"}); |
| | | } |
| | | if(rages == null || rages.equals("")){ |
| | | return; |
| | | } |
| | | VTDouble obj = new VTDouble(Double.valueOf(defValue)); |
| | | boolean flag = obj.checkRageValueByRage(rages); |
| | | if(!flag){ |
| | | throw new PLException("500",new String[]{"默认值与值域冲突!"}); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检查该属性名是否被系统属性使用 |
| | | * @param abName |
| | | * @return |
| | | */ |
| | | private boolean usedBySystem(String abName) { |
| | | boolean flag = false; |
| | | String[] names = UsedNames.getProperty(SYSUSEDNAMES).toUpperCase().split(","); |
| | | List<String> nameList = Arrays.asList(names); |
| | | if(nameList.contains(abName.toUpperCase())){ |
| | | flag = true; |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 检查该属性名是否属于数据库关键字 |
| | | * @param abName |
| | | * @return |
| | | */ |
| | | private boolean usedByDataBase(String abName){ |
| | | boolean flag = false; |
| | | String[] names = UsedNames.getProperty(DATABASEUSEDNAMES).toUpperCase().split(","); |
| | | List<String> nameList = Arrays.asList(names); |
| | | if(nameList.contains(abName.toUpperCase())){ |
| | | flag = true; |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 删除属性 |
| | | * @param osAttributeDTOS |
| | | * @return true成功,false失败 |
| | | */ |
| | | @Override |
| | | public boolean deleteAttributes(List<OsAttributeDTO> osAttributeDTOS) throws PLException { |
| | | VciBaseUtil.alertNotNull(osAttributeDTOS,"待删除的属性列表"); |
| | | //平台的deleteEnumTypes方法必传三个参数,oid、name和ts |
| | | List<AttributeDef> attributeDefs = new ArrayList<>(); |
| | | for(OsAttributeDTO osAttributeDTO : osAttributeDTOS){ |
| | | //oid和ts判空 |
| | | String oid = osAttributeDTO.getOid(); |
| | | //name主要用来对缓存数据删除 |
| | | String name = osAttributeDTO.getName(); |
| | | Date ts = osAttributeDTO.getTs(); |
| | | 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 + "】,已被引用!"}); |
| | | } |
| | | AttributeDef attributeDef = new AttributeDef(); |
| | | attributeDef.oid = oid; |
| | | attributeDef.name = name; |
| | | attributeDef.ts = Func.format(ts,VciDateUtil.DateTimeMillFormat); |
| | | attributeDefs.add(attributeDef); |
| | | } |
| | | if(Func.isEmpty(attributeDefs)){ |
| | | return false; |
| | | } |
| | | return platformClientUtil.getAttributeService().deleteAttributeDefs(attributeDefs.toArray(new AttributeDef[attributeDefs.size()])); |
| | | } |
| | | |
| | | /** |
| | | * 查看属性的使用范围 |
| | | * @param attributeName |
| | | * @return key:属性 ,value使用该属性的业务类型 |
| | | */ |
| | | @Override |
| | | public List<Map<String, String>> getUsedAttributeList(String attributeName) throws PLException { |
| | | if(Func.isBlank(attributeName)){ |
| | | throw new PLException("500",new String[]{"请选择要查询应用范围的属性!"}); |
| | | } |
| | | String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(attributeName); |
| | | if(Func.isEmpty(btNames)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | List<Map<String,String>> btmNameMapList = new ArrayList<>(); |
| | | Arrays.stream(btNames).forEach(btName->{ |
| | | Map<String, String> itemMap = new HashMap<>(); |
| | | itemMap.put("attributeName",attributeName); |
| | | itemMap.put("source",btName); |
| | | btmNameMapList.add(itemMap); |
| | | }); |
| | | return btmNameMapList; |
| | | } |
| | | |
| | | /** |
| | | * 导出选中的属性 |
| | | * @param exportFileName 导出的文件名 |
| | | * @param attrNames 需要导出的属性名称 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String exportAttributes(String exportFileName, String attrNames) 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("属性名", "标签", "描述", |
| | | "属性类型", "允许为空", "默认值", "使用的枚举英文名称(枚举名)", |
| | | "使用的枚举中文名称(标签)", "参照的业务类型编号", "参照的业务类型名称", |
| | | "属性长度", "小数精度位数","小数刻度位数","取值范围","创建时间") |
| | | ); |
| | | |
| | | //写excel |
| | | String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls"; |
| | | try { |
| | | new File(excelPath).createNewFile(); |
| | | } catch (Throwable e) { |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e); |
| | | } |
| | | //设置列 |
| | | List<WriteExcelData> excelDataList = new ArrayList<>(); |
| | | //设置列头 |
| | | for (int index = 0; index < columns.size(); index++) { |
| | | excelDataList.add(new WriteExcelData(0,index, columns.get(index))); |
| | | } |
| | | //按照属性名查询属性,然后处理属性导出 |
| | | List<String> enumNameList = Func.toStrList(attrNames); |
| | | List<OsAttributeVO> osAttributeVOS = this.listAttrByIds(enumNameList); |
| | | if(Func.isEmpty(osAttributeVOS)){ |
| | | excelDataList.add(new WriteExcelData(1,1, "根据属性名称未查询到属性信息,请刷新后尝试重新导出!")); |
| | | }else{ |
| | | //先按照属性类型排序,不同属性类型导出的数据乱的效果 |
| | | osAttributeVOS.sort(Comparator.comparing(OsAttributeVO::getAttributeDataType)); |
| | | for (int i = 0; i < osAttributeVOS.size(); i++) { |
| | | OsAttributeVO osAttributeVO = osAttributeVOS.get(i); |
| | | 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()))); |
| | | 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.getPrecisionLength())); |
| | | excelDataList.add(new WriteExcelData(i+1,12, osAttributeVO.getScaleLength())); |
| | | excelDataList.add(new WriteExcelData(i+1,13, osAttributeVO.getRange())); |
| | | excelDataList.add(new WriteExcelData(i+1,14, osAttributeVO.getCreateTime())); |
| | | } |
| | | } |
| | | WriteExcelOption excelOption = new WriteExcelOption(excelDataList); |
| | | ExcelUtil.writeDataToFile(excelPath, excelOption); |
| | | return excelPath; |
| | | } |
| | | |
| | | /** |
| | | * 是否默认的属性 |
| | | * |
| | | * @param attr 属性编号 |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 是否为枚举的属性 |
| | | * @param other 配置的内容 |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 清除缓存 |
| | | */ |
| | |
| | | public void clearCache() { |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 调用修改业务类型和连接类型中对应属性名的属性 |
| | | * @param apName |
| | | * @return |
| | | * @throws PLException |
| | | */ |
| | | private boolean alterAp(String apName) throws PLException { |
| | | return osBtmService.alterAp(apName) && osLinkTypeServiceI.alterAp(apName); |
| | | } |
| | | |
| | | } |