فهرست منبع

[BL_2018110014]导入错误模板进行识别

guq 7 سال پیش
والد
کامیت
14bbe21363

+ 1 - 0
applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/exception/BizExceptionCode.java

@@ -39,6 +39,7 @@ public enum BizExceptionCode implements BaseExceptionCode {
     BIZ_NULLCALLER(79315, "该单据的定义不存在"),
     BIZ_REPORT_NOCALLER(79316, "报表配置不存在"),
     BIZ_REPORT_NOTCORRECT(79317, "导入数据无效"),
+    BIZ_IMPORT_ERROREXCEL(79318, "请导入对应的单据数据"),
 
     NO_OPRATIONDATA(79400,"无可操作单据"),
     NULL_DATA(23232,"无数据"),

+ 4 - 3
applications/commons/commons-server/src/main/java/com/usoftchina/saas/commons/controller/ExcelController.java

@@ -55,6 +55,7 @@ public class ExcelController {
         } else {
             excelService.clearBefore(caller);
             String ft = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
+            String fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."));
             is = file.getInputStream();
             if (ft.equals("xlsx")) {
                 wb = new XSSFWorkbook(is);
@@ -64,12 +65,12 @@ public class ExcelController {
                 return Result.error(new String("{error: 'excel文件的格式不太规范,导入失败<hr>可以尝试将文件另存为.xls文件,或将数据选择性粘贴到excel模板,然后导入'}".getBytes("utf-8"),
                         "iso8859-1"));
             }
-            keyvalue = excelService.parseTemplet(wb, caller);
+            keyvalue = excelService.parseTemplet(wb, caller, fileName);
         }
         return Result.success(keyvalue);
     }
 
-    @RequestMapping(value = "/test")
+   /* @RequestMapping(value = "/test")
     public Result ParseTemplet(String caller) throws IOException {
         InputStream is = null;
         Workbook wb = null;
@@ -78,6 +79,6 @@ public class ExcelController {
         wb = new XSSFWorkbook(is);
         excelService.parseTemplet(wb, caller);
         return Result.success();
-    }
+    }*/
 
 }

+ 1 - 2
applications/commons/commons-server/src/main/java/com/usoftchina/saas/commons/service/ExcelService.java

@@ -1,7 +1,6 @@
 package com.usoftchina.saas.commons.service;
 
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 
 import java.util.Map;
 
@@ -10,5 +9,5 @@ public interface ExcelService {
 
     void clearBefore(String caller);
 
-    Integer parseTemplet(Workbook wb, String caller);
+    Integer parseTemplet(Workbook wb, String caller, String title);
 }

+ 7 - 2
applications/commons/commons-server/src/main/java/com/usoftchina/saas/commons/service/impl/ExcelServiceImpl.java

@@ -78,7 +78,7 @@ public class ExcelServiceImpl implements ExcelService{
 
     @Override
     @Transactional
-    public Integer parseTemplet(Workbook wb, String caller) {
+    public Integer parseTemplet(Workbook wb, String caller, String fileName) {
         if (wb == null || StringUtils.isEmpty(caller)) {
             throw new BizException(BizExceptionCode.NULL_DATA);
         }
@@ -96,6 +96,11 @@ public class ExcelServiceImpl implements ExcelService{
         if (StringUtils.isEmpty(cols)) {
             throw new BizException(12135, "没有查询到对应的excel配置");
         }
+        //验证标题是否正确
+        String title = dataTemplet.getDt_title();
+        if (StringUtils.isEmpty(fileName) || fileName.indexOf(title) < 0) {
+            throw new BizException(BizExceptionCode.BIZ_IMPORT_ERROREXCEL);
+        }
         //前端列表信息
         List<TempletSet> templetSets = JSONArray.parseArray(cols, TempletSet.class);
         Map<String, List<TempletSet>> columns = CollectionUtils.groupBy(templetSets, TempletSet::getPosition);
@@ -222,7 +227,7 @@ public class ExcelServiceImpl implements ExcelService{
                        for (TempletSet set : detail) {
                            //取excel值
                            value = data.get(set.getDescription());
-                           if ("true".equals(set.getNecessary()) && value.equals("")) {
+                           if ("true".equals(set.getNecessary()) && StringUtils.isEmpty(value)) {
                                detailData = null;
                                //err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
                                break;