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));