浏览代码

问题修正

gaodm 4 年之前
父节点
当前提交
36022cc79c
共有 1 个文件被更改,包括 11 次插入2 次删除
  1. 11 2
      cdssman-service/src/main/java/com/diagbot/util/ExcelUtils.java

+ 11 - 2
cdssman-service/src/main/java/com/diagbot/util/ExcelUtils.java

@@ -7,6 +7,7 @@ import cn.afterturn.easypoi.excel.entity.ExportParams;
 import cn.afterturn.easypoi.excel.entity.ImportParams;
 import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
 import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
+import cn.afterturn.easypoi.exception.excel.ExcelImportException;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
 import org.apache.commons.lang3.StringUtils;
@@ -38,7 +39,7 @@ public class ExcelUtils {
     }
 
     public static void exportExcelDynamicCol(List<ExcelExportEntity> entityList, Collection<?> dataSet, String title, String sheetName, String fileName,
-                                    HttpServletResponse response) {
+                                             HttpServletResponse response) {
         ExportParams exportParams = new ExportParams(title, sheetName);
         dynamicColExport(entityList, dataSet, fileName, response, exportParams);
     }
@@ -72,7 +73,7 @@ public class ExcelUtils {
 
     private static void dynamicColExport(List<ExcelExportEntity> entityList, Collection<?> dataSet, String fileName, HttpServletResponse response,
                                          ExportParams exportParams) {
-        Workbook workbook = ExcelExportUtil.exportExcel(exportParams,entityList,dataSet);
+        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entityList, dataSet);
         if (workbook != null) {
             ;
         }
@@ -148,9 +149,13 @@ public class ExcelUtils {
             list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params);
         } catch (NoSuchElementException e) {
             // throw new NormalException("模板不能为空");
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "模板不能为空");
+        } catch (ExcelImportException e) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "校验失败,请使用模板进行数据导入");
         } catch (Exception e) {
             e.printStackTrace();
             // throw new NormalException(e.getMessage());
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "导入Excel异常");
         }
         return list;
     }
@@ -168,9 +173,13 @@ public class ExcelUtils {
             list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);
         } catch (NoSuchElementException e) {
             // throw new NormalException("excel文件不能为空");
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "excel文件不能为空");
+        } catch (ExcelImportException e) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "校验失败,请使用模板进行数据导入");
         } catch (Exception e) {
             // throw new NormalException(e.getMessage());
             System.out.println(e.getMessage());
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "导入Excel异常");
         }
         return list;
     }