|
|
@@ -2987,37 +2987,39 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
try (InputStream inputStream = file.getInputStream()) {
|
|
|
// 立即处理文件流
|
|
|
Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
- Sheet sheet = workbook.getSheetAt(0);
|
|
|
- // 处理Excel数据...
|
|
|
- unmergeCells(sheet);
|
|
|
List<ImportTreeDto> list = new ArrayList<>();
|
|
|
- for (int i = 2; i <= sheet.getLastRowNum(); i++) {
|
|
|
- Row row = sheet.getRow(i);
|
|
|
- if (row == null) continue;
|
|
|
-// if(StringUtils.isEmpty(getCellValue(row.getCell(1)))){
|
|
|
-// throw new ServerException("单位工程类型名称不能为空");
|
|
|
-// }
|
|
|
-// if(StringUtils.isEmpty(getCellValue(row.getCell(3)))){
|
|
|
-// throw new ServerException("单位工程名称不能为空");
|
|
|
-// }
|
|
|
-// if(StringUtils.isEmpty(getCellValue(row.getCell(5)))){
|
|
|
-// throw new ServerException("分部工程名称不能为空");
|
|
|
-// }
|
|
|
- // 获取每一列的值
|
|
|
- String unitCode = getCellValue(row.getCell(0)); // A列:单位工程编号
|
|
|
- String unitName = getCellValue(row.getCell(1)); // B列:单位工程名称
|
|
|
- String subUnitCode = getCellValue(row.getCell(2)); // C列:子单位工程编号
|
|
|
- String subUnitName = getCellValue(row.getCell(3)); // D列:子单位工程名称
|
|
|
- String divisionCode = getCellValue(row.getCell(4)); // E列:分部工程编号
|
|
|
- String divisionName = getCellValue(row.getCell(5)); // F列:分部工程名称
|
|
|
- String subDivisionCode = getCellValue(row.getCell(6)); // G列:子分部工程编号
|
|
|
- String subDivisionName = getCellValue(row.getCell(7)); // H列:子分部工程名称
|
|
|
- String itemCode = getCellValue(row.getCell(8)); // I列:分项工程编号
|
|
|
- String itemName = getCellValue(row.getCell(9)); // J列:分项工程名称
|
|
|
- String subItemCode = getCellValue(row.getCell(10));// K列:子分项工程编号
|
|
|
- String subItemName = getCellValue(row.getCell(11)); // L列:子分项工程名称
|
|
|
- ImportTreeDto dto = new ImportTreeDto(unitName, unitCode, 1, StringUtils.isEmpty(unitName), subUnitName, subUnitCode, 18, StringUtils.isEmpty(subUnitName), divisionName, divisionCode, 2, StringUtils.isEmpty(divisionName), subDivisionName, subDivisionCode, 3, StringUtils.isEmpty(subDivisionName), itemName, itemCode, 4, StringUtils.isEmpty(itemName), subItemName, subItemCode, 5, StringUtils.isEmpty(subItemName));
|
|
|
- list.add(dto);
|
|
|
+ // 遍历所有工作表
|
|
|
+ for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(sheetIndex);
|
|
|
+ // 处理Excel数据...
|
|
|
+ unmergeCells(sheet);
|
|
|
+ for (int i = 2; i <= sheet.getLastRowNum(); i++) {
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ if (row == null) continue;
|
|
|
+ // 获取每一列的值
|
|
|
+ String unitCode = getCellValue(row.getCell(0)); // A列:单位工程编号
|
|
|
+ String unitName = getCellValue(row.getCell(1)); // B列:单位工程名称
|
|
|
+ String subUnitCode = getCellValue(row.getCell(2)); // C列:子单位工程编号
|
|
|
+ String subUnitName = getCellValue(row.getCell(3)); // D列:子单位工程名称
|
|
|
+ String divisionCode = getCellValue(row.getCell(4)); // E列:分部工程编号
|
|
|
+ String divisionName = getCellValue(row.getCell(5)); // F列:分部工程名称
|
|
|
+ String subDivisionCode = getCellValue(row.getCell(6)); // G列:子分部工程编号
|
|
|
+ String subDivisionName = getCellValue(row.getCell(7)); // H列:子分部工程名称
|
|
|
+ String itemCode = getCellValue(row.getCell(8)); // I列:分项工程编号
|
|
|
+ String itemName = getCellValue(row.getCell(9)); // J列:分项工程名称
|
|
|
+ String subItemCode = getCellValue(row.getCell(10));// K列:子分项工程编号
|
|
|
+ String subItemName = getCellValue(row.getCell(11)); // L列:子分项工程名称
|
|
|
+
|
|
|
+ ImportTreeDto dto = new ImportTreeDto(
|
|
|
+ unitName, unitCode, 1, StringUtils.isEmpty(unitName),
|
|
|
+ subUnitName, subUnitCode, 18, StringUtils.isEmpty(subUnitName),
|
|
|
+ divisionName, divisionCode, 2, StringUtils.isEmpty(divisionName),
|
|
|
+ subDivisionName, subDivisionCode, 3, StringUtils.isEmpty(subDivisionName),
|
|
|
+ itemName, itemCode, 4, StringUtils.isEmpty(itemName),
|
|
|
+ subItemName, subItemCode, 5, StringUtils.isEmpty(subItemName)
|
|
|
+ );
|
|
|
+ list.add(dto);
|
|
|
+ }
|
|
|
}
|
|
|
if (list.isEmpty()) {
|
|
|
throw new ServiceException("导入模版为空,请先填写数据");
|