From a18f328b45ecccd402858e0a97b9d240dada01bc Mon Sep 17 00:00:00 2001 From: erdanergou Date: Sat, 29 Apr 2023 11:17:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=93=E5=AD=98=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=97=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExcelDepositoryInfoConverter.java | 26 ++++++++----------- .../service/DepositoryService.java | 1 + .../service/impl/ExcelServiceImpl.java | 21 +++++++++++---- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/dreamchaser/depository_manage/converter/ExcelDepositoryInfoConverter.java b/src/main/java/com/dreamchaser/depository_manage/converter/ExcelDepositoryInfoConverter.java index 045e5e23..62b0d7db 100644 --- a/src/main/java/com/dreamchaser/depository_manage/converter/ExcelDepositoryInfoConverter.java +++ b/src/main/java/com/dreamchaser/depository_manage/converter/ExcelDepositoryInfoConverter.java @@ -23,10 +23,9 @@ import java.util.List; @Component public class ExcelDepositoryInfoConverter implements Converter { + private static ExcelDepositoryInfoConverter excelDepositoryInfoConverter; @Autowired - private DepositoryService depositoryService; - - private static ExcelDepositoryInfoConverter excelDepositoryInfoConverter; + private DepositoryService depositoryService; @Override public Class supportJavaTypeKey() { @@ -40,14 +39,12 @@ public class ExcelDepositoryInfoConverter implements Converter { @Override public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { - List depositoryAll = excelDepositoryInfoConverter.depositoryService.findDepositoryAll(); Integer data = 0; - for (int i = 0; i < depositoryAll.size(); i++) { - if(cellData.getStringValue().equals(depositoryAll.get(i).getCode())){ - data = depositoryAll.get(i).getId(); - } + Depository depository = excelDepositoryInfoConverter.depositoryService.findDepositoryByCode(cellData.getStringValue()); + if (depository != null) { + data = depository.getId(); } - if(data == 0){ + if (data == 0) { throw new RuntimeException("没有该仓库"); } return data; @@ -55,18 +52,17 @@ public class ExcelDepositoryInfoConverter implements Converter { @Override public WriteCellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { - List depositoryAll = excelDepositoryInfoConverter.depositoryService.findDepositoryAll(); + Depository depository = excelDepositoryInfoConverter.depositoryService.findDepositoryById(value); String data = ""; - for (int i = 0; i < depositoryAll.size(); i++) { - if(Integer.compare(value,depositoryAll.get(i).getId()) == 0){ - data = depositoryAll.get(i).getCode(); - } + if(depository != null) { + data = depository.getCode(); } + return new WriteCellData<>(data); } @PostConstruct - public void init(){ + public void init() { excelDepositoryInfoConverter = this; excelDepositoryInfoConverter.depositoryService = this.depositoryService; } diff --git a/src/main/java/com/dreamchaser/depository_manage/service/DepositoryService.java b/src/main/java/com/dreamchaser/depository_manage/service/DepositoryService.java index aab8de0e..63caed21 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/DepositoryService.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/DepositoryService.java @@ -96,6 +96,7 @@ public interface DepositoryService { List findDepositoryAll(); + /** * 根据主键id将仓库状态改为删除 * @param id diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java index 994db7a0..0e68eb88 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java @@ -158,9 +158,11 @@ public class ExcelServiceImpl implements ExcelService { errMsg.addAll(strings); } } - System.out.println(ExcelFileInfoPool.getUserExcelMaterialInfo(userByPort.getNumber()).size()); - - readResult.put("dataList", ExcelFileInfoPool.getUserExcelMaterialInfo(userByPort.getNumber())); + List userExcelMaterialInfo = ExcelFileInfoPool.getUserExcelMaterialInfo(userByPort.getNumber()); + if(userExcelMaterialInfo == null){ + userExcelMaterialInfo = new ArrayList<>(); + } + readResult.put("dataList", userExcelMaterialInfo); // 4.2删除临时文件 boolean deleteFile = FileUtil.deleteFile(new File(filePath)); @@ -269,7 +271,12 @@ public class ExcelServiceImpl implements ExcelService { } } - readResult.put("dataList", ExcelFileInfoPool.getUserExcelMaterialTypeInfo(userByPort.getNumber())); + List userExcelMaterialTypeInfo = ExcelFileInfoPool.getUserExcelMaterialTypeInfo(userByPort.getNumber()); + if(userExcelMaterialTypeInfo == null){ + userExcelMaterialTypeInfo = new ArrayList<>(); + } + + readResult.put("dataList", userExcelMaterialTypeInfo); // 4.2删除临时文件 @@ -382,7 +389,11 @@ public class ExcelServiceImpl implements ExcelService { } - readResult.put("dataList", ExcelFileInfoPool.getUserExcelInventoryInfo(userByPort.getNumber())); + List userExcelInventoryInfo = ExcelFileInfoPool.getUserExcelInventoryInfo(userByPort.getNumber()); + if(userExcelInventoryInfo == null){ + userExcelInventoryInfo = new ArrayList<>(); + } + readResult.put("dataList", userExcelInventoryInfo); // 4.2删除临时文件 boolean deleteFile = FileUtil.deleteFile(new File(filePath));