From ef40ab58f40a6bd3c12cee529a2e94868b91de0c Mon Sep 17 00:00:00 2001 From: lijinyu <3023846734@qq.com> Date: Wed, 26 Jul 2023 16:57:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=AE=A1=E7=90=86=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=8A=9F=E8=83=BD=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ModulexServiceImpl.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/modulex/service/impl/ModulexServiceImpl.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/modulex/service/impl/ModulexServiceImpl.java index ef8335e..0abec86 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/modulex/service/impl/ModulexServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/modulex/service/impl/ModulexServiceImpl.java @@ -371,6 +371,7 @@ public class ModulexServiceImpl extends ServiceImpl impl int numberOfSheets = wb.getNumberOfSheets(); for (int i = 0; i < numberOfSheets; i++) { Sheet sheet = wb.getSheetAt(i); + //获取行数 int physicalNumberOfRows = sheet.getPhysicalNumberOfRows(); for (int j = 2; j < physicalNumberOfRows; j++) { @@ -380,6 +381,14 @@ public class ModulexServiceImpl extends ServiceImpl impl if(row==null){ continue; } + boolean rowEmpty = isRowEmpty(row); + if(rowEmpty){ + message.put("isError", "true"); + message.put("status", "模块管理execl表格不规范有空行存在,请重新上传"); + message.put("closeable","true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("模块管理execl表格不规范有空行存在,请重新上传"); + } //获取单行单元格数 Integer physicalNumberOfCells = null; if (row == null) { @@ -432,7 +441,10 @@ public class ModulexServiceImpl extends ServiceImpl impl int annual = 0; for (int k = 0; k < physicalNumberOfCells; k++) { Cell cell = row.getCell(k); - String value = cell.getStringCellValue(); + String value=""; + if(cell!=null){ + value = cell.getStringCellValue(); + } switch (k){ case 0: modulexVo.setPid(value); @@ -957,9 +969,6 @@ public class ModulexServiceImpl extends ServiceImpl impl } modulexList.add(modulex); } -// for (ModulexTemplate modulexTemplate : modulexTemplates) { -// -// } boolean result = this.saveSingleBatch(modulexList, loginUser, message); if(!result){ message.put("isError", "true"); @@ -1323,7 +1332,18 @@ public class ModulexServiceImpl extends ServiceImpl impl } return pinyinStr; } - - - + /** + * 判断是否有空行 + * @param row + * @return + */ + private boolean isRowEmpty(Row row) { + for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) { + Cell cell = row.getCell(c); + if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { + return false; + } + } + return true; + } }