| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | ); |
| | | //属性英文名称校验(判空、系统中判重、是否关键字、是否合规等) |
| | | 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); |
| | | } |
| | |
| | | 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 + "】在系统中已存在!"}); |
| | | }*/ |
| | | } |
| | | |
| | | /** |
| | |
| | | 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())); |
| | |
| | | /** |
| | | * 导入属性 |
| | | * @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(); |
| | | //查询枚举是否存在,填写了枚举但没填写取值范围,这时候直接使用枚举项值作为默认的range |
| | | //查询属性是否存在,填写了枚举但没填写取值范围,这时候直接使用枚举项值作为默认的range |
| | | if(Func.isNotBlank(osAttributePO.getEnumId()) && Func.isBlank(osAttributePO.getRange())){ |
| | | try { |
| | | OsEnumVO enumVO = enumService.getEnumTypeById(osAttributePO.getEnumId()); |
| | |
| | | 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 (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("属性导入成功!"); |
| | | } |
| | | |
| | | /** |