diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/coryUtils/ExcelReader.java b/xinnengyuan/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/coryUtils/ExcelReader.java index d9d8689b..509db055 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/coryUtils/ExcelReader.java +++ b/xinnengyuan/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/coryUtils/ExcelReader.java @@ -1,10 +1,7 @@ package org.dromara.common.excel.coryUtils; -import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.web.multipart.MultipartFile; @@ -84,7 +81,7 @@ public class ExcelReader { SheetData sheetData = new SheetData(); sheetData.setSheetName(sheet.getSheetName()); - processSheetData(sheet, sheetData); + processSheetData(workbook,sheet, sheetData); sheetDataList.add(sheetData); } } @@ -114,7 +111,7 @@ public class ExcelReader { sheetData.setSheetName(sheet.getSheetName()); // 处理单个sheet的数据 - processSheetData(sheet, sheetData); + processSheetData(workbook, sheet, sheetData); sheetDataList.add(sheetData); } @@ -129,7 +126,7 @@ public class ExcelReader { /** * 处理单个工作表的数据 */ - private static void processSheetData(org.apache.poi.ss.usermodel.Sheet sheet, SheetData sheetData) { + private static void processSheetData(Workbook workbook, Sheet sheet, SheetData sheetData) { boolean foundChineseStart = false; List> data = new ArrayList<>(); boolean isFirstRow = true; @@ -140,12 +137,12 @@ public class ExcelReader { isFirstRow = false; continue; } - if(hasValidData(row)){ + if(hasValidData(workbook,row)){ List rowData = new ArrayList<>(); // 读取A到E列(索引0到4) for (int cellIndex = 0; cellIndex < 6; cellIndex++) { Cell cell = row.getCell(cellIndex, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); - rowData.add(getCellValue(cell)); + rowData.add(getCellValue(workbook,cell)); } // 检查是否找到中文数字开头的行 @@ -165,11 +162,11 @@ public class ExcelReader { sheetData.setData(data); } - private static boolean hasValidData(Row row) { + private static boolean hasValidData(Workbook workbook,Row row) { // 遍历行中的所有单元格 for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) { Cell cell = row.getCell(cellIndex, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); - String cellValue = getCellValue(cell).trim(); + String cellValue = getCellValue(workbook, cell).trim(); // 只要有一个单元格有非空值,就认为是有效行 if (!cellValue.isEmpty()) { @@ -278,7 +275,7 @@ public class ExcelReader { /** * 获取单元格的值,处理不同数据类型 */ - private static String getCellValue(Cell cell) { + private static String getCellValue(Workbook workbook, Cell cell) { if (cell == null) { return ""; } @@ -293,6 +290,21 @@ public class ExcelReader { return numericValue.substring(0, numericValue.length() - 2); } return numericValue; + case FORMULA: + //这样对于字符串cell.getStringCellValue()方法即可取得其值,如果公式生成的是数值,使用cell.getStringCellValue()方法会抛出IllegalStateException异常,在异常处理中使用cell.getNumericCellValue(); + // 1. 获取公式文本(如 "A1+B1") + String formula = cell.getCellFormula(); + System.out.println("公式文本:" + formula); + + // 2. 创建公式计算器(关键步骤:用于计算公式结果) + FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); + + // 3. 计算公式,返回包含结果类型和值的CellValue对象 + CellValue cellValue = evaluator.evaluate(cell); + + // 4. 根据结果类型提取值 + return getValue( cellValue.getCellType(), cellValue); + case BOOLEAN: return String.valueOf(cell.getBooleanCellValue()); default: @@ -300,6 +312,19 @@ public class ExcelReader { } } + private static String getValue( CellType resultType, CellValue cellValue) { + return switch (resultType) { + case NUMERIC -> String.valueOf(cellValue.getNumberValue()); + case STRING -> String.valueOf(cellValue.getStringValue()); + case BOOLEAN -> String.valueOf(cellValue.getBooleanValue()); + case ERROR -> String.valueOf(cellValue.getErrorValue()); + case BLANK -> String.valueOf(CellType.BLANK); + default -> + // 保留原公式(不处理的类型) + cellValue.getStringValue(); + }; + } + /** * 根据A列的值确定父节点的键 */ diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/domain/vo/DetailsMaterialAndEquipmentApprovalRes.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/domain/vo/DetailsMaterialAndEquipmentApprovalRes.java index 5abdeb61..8c29cbd0 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/domain/vo/DetailsMaterialAndEquipmentApprovalRes.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/domain/vo/DetailsMaterialAndEquipmentApprovalRes.java @@ -20,6 +20,7 @@ public class DetailsMaterialAndEquipmentApprovalRes implements Serializable { * 版本号 */ private String versions; + private String versionsName; /** diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/BusBillofquantitiesVersionsServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/BusBillofquantitiesVersionsServiceImpl.java index d347dc85..b185ef94 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/BusBillofquantitiesVersionsServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/BusBillofquantitiesVersionsServiceImpl.java @@ -226,12 +226,17 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl busBillofquantities = busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper().eq(BusBillofquantities::getProjectId, bo.getProjectId())); Set names = busBillofquantities.stream() .filter(Objects::nonNull) - .map(BusBillofquantities::getName) - .filter(Objects::nonNull) + .map(obj->{ + String name = Optional.ofNullable (obj.getName ()).orElse (""); + String specification = Optional.ofNullable (obj.getSpecification ()).orElse (""); + String remark = Optional.ofNullable (obj.getRemark ()).orElse (""); + return name+"+"+specification+"+"+remark; + }) .collect(Collectors.toSet()); for (BusBillofquantities allMaterial : allMaterials) { - if (names.contains(allMaterial.getName())) { - throw new ServiceException("名称“"+allMaterial.getName()+"”已存在,请修改后重新上传!"); + String biaoqian = allMaterial.getName()+"+"+allMaterial.getSpecification()+"+"+allMaterial.getRemark(); + if (names.contains(biaoqian)) { + throw new ServiceException("名称:“"+allMaterial.getName()+"+”规格:”"+allMaterial.getSpecification()+"“+”备注:“"+allMaterial.getRemark()+"已存在,请修改后重新上传!"); } allMaterial.setProjectId(bo.getProjectId()); } @@ -303,6 +308,7 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl