Эх сурвалжийг харах

fix:考务数据导入空行判断及不处理操作

caozixuan 3 жил өмнө
parent
commit
5c395332e1

+ 5 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -648,6 +648,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         if (totalRows > 1 && sheet.getRow(0) != null) {
             totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
         }
+        // 获取sheet的title
         Row head = sheet.getRow(0);
         List<String> headList = new ArrayList<>();
         // 将必填字段匹配excel解析的表头索引
@@ -671,6 +672,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         List<ExaminationImportDto> examinationImportDtoList = new ArrayList<>();
         for (int r = 1; r < totalRows; r++) {
             Row row = sheet.getRow(r);
+            if (ExcelUtil.isRowAllCellEmpty(row,head)){
+                // excel中整行为空,直接跳过
+                continue;
+            }
 
             List<FieldsDto> secondaryFieldList = new ArrayList<>(); // 备选字段
 

+ 22 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/ExcelUtil.java

@@ -7,6 +7,7 @@ import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.util.excel.ExcelCallback;
 import com.qmth.teachcloud.common.util.excel.ExcelError;
 import com.qmth.teachcloud.common.util.excel.ExcelWriter;
+import jodd.util.StringUtil;
 import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellType;
@@ -304,4 +305,25 @@ public class ExcelUtil {
         }
         return excelErrorList;
     }
+
+    /**
+     * 验证excel中某一行是否全部为空
+     * @param row 当前行
+     * @param firstRow 第一行标题行
+     * @return 是否整整一行为空
+     */
+    public static boolean isRowAllCellEmpty(Row row,Row firstRow) {
+        int count = 0;
+        //单元格数量
+        int rowCount = firstRow.getLastCellNum() - firstRow.getFirstCellNum();
+        //判断多少个单元格为空
+        for (int c = 0; c < rowCount; c++) {
+            Cell cell = row.getCell(c);
+            if (cell == null || cell.getCellTypeEnum() == CellType.BLANK || StringUtil.isEmpty((cell+"").trim())){
+                count += 1;
+            }
+        }
+
+        return count == rowCount;
+    }
 }