From 138dead9b8a35d843a74a799e2cfbe1b12b51189 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期五, 20 六月 2025 17:46:38 +0800 Subject: [PATCH] Merge branch 'master' of http://118.89.139.230:10101/r/powerIntelligenceSystem --- src/main/java/com/whyc/service/DeviceSpareService.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 52 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/whyc/service/DeviceSpareService.java b/src/main/java/com/whyc/service/DeviceSpareService.java index 5dd1598..72a0fea 100644 --- a/src/main/java/com/whyc/service/DeviceSpareService.java +++ b/src/main/java/com/whyc/service/DeviceSpareService.java @@ -12,6 +12,7 @@ import com.whyc.util.CommonUtil; import com.whyc.util.ThreadLocalUtil; import org.apache.commons.lang.StringUtils; +import org.apache.poi.ss.usermodel.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,6 +21,7 @@ import javax.annotation.Resource; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -160,7 +162,7 @@ return new Response<List<DeviceSpare>>().set(1,deviceSpares); } - public void add(List<DeviceSpare> spareList) { + public void addBatch(List<DeviceSpare> spareList) { mapper.insertBatchSomeColumn(spareList); } @@ -187,4 +189,53 @@ } } + + public void outBound(List<DeviceSpare> spareList) { + mapper.outBound(spareList); + } + + public Response addByExcel(MultipartFile file) throws IOException { + //灏嗘枃浠舵祦杞寲涓簑orkbook + Workbook book = WorkbookFactory.create(file.getInputStream()); + Sheet sheet = book.getSheetAt(0); + //鑾峰彇鏈�鍚庝竴琛� + int lastRowIndex = sheet.getLastRowNum(); + List<DeviceSpare> spareList = new ArrayList<>(); + for (int i = 1; i <= lastRowIndex; i++) { + DeviceSpare spare = new DeviceSpare(); + Row row = sheet.getRow(i); + //瀵规瘡琛岀殑鍓�7鍒楄繘琛岄潪绌烘牎楠� + for (int j = 0; j < 7; j++) { + Cell cell = row.getCell(j); + //闈炲浘鐗囧垪杩涜闈炵┖鏍¢獙.涓嶅悎瑙勬棤娉曚笂浼� + if (cell == null || cell.getCellType() == CellType.BLANK) { + return new Response().set(1, false, "绗�" + (i + 1) + "琛岀" + (j + 1) + "鍒楁暟鎹负绌�"); + } + } + //鑾峰彇鍒楃殑鍊� + String name = row.getCell(0).getStringCellValue(); + String model = row.getCell(1).getStringCellValue(); + String version = row.getCell(2).getStringCellValue(); + int quantity = (int) row.getCell(3).getNumericCellValue(); + String brand = row.getCell(4).getStringCellValue(); + String type = row.getCell(5).getStringCellValue(); + String supplier = row.getCell(6).getStringCellValue(); + spare.setName(name); + spare.setModel(model); + spare.setVersion(version); + spare.setQuantity(quantity); + spare.setBrand(brand); + spare.setType(type); + spare.setSupplier(supplier); + + spareList.add(spare); + //绗竷鍒椾负鍥剧墖 TODO 寰呭鐞� + /*Cell cell = row.getCell(7); + CellType cellType = cell.getCellType(); + System.out.println("-");*/ + } + addBatch(spareList); + + return null; + } } -- Gitblit v1.9.1