虚拟清单导入--表头验证

This commit is contained in:
zhn
2022-06-10 16:02:55 +08:00
parent bc072cc262
commit ba71b20da8
@@ -1047,6 +1047,22 @@ public class DummyInventoryInfoEOServiceImpl extends ServiceImpl<DummyInventoryI
headerSb.append(key + ","); headerSb.append(key + ",");
} }
} else if(i > 2){ } else if(i > 2){
// 校验头部是否符合模板
String substring = headerSb.toString();
if (substring.endsWith(",") || substring.endsWith(",")){
substring = headerSb.substring(0, headerSb.length() - 1);
}
String excelHeader = substring.toString();
if (!title.equals(excelHeader)) {
workbook.close();
//删除原上传文件
FileUnZip.deleteDir(saveDirectory);
if(CutEnum.CN.getValue().equals(dummyInventoryInfoEO.getCut())){
throw new JeroBootException("读取失败,请严格按照模板文件导入数据");
}else{
throw new JeroBootException("The data fails to be read. Import data strictly according to the template file");
}
}
List<String> headList = Arrays.asList(headerSb.toString().split(",")); List<String> headList = Arrays.asList(headerSb.toString().split(","));
String field =""; String field ="";
if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType() && HSSFDateUtil.isCellDateFormatted(cell)) { if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType() && HSSFDateUtil.isCellDateFormatted(cell)) {
@@ -1092,23 +1108,22 @@ public class DummyInventoryInfoEOServiceImpl extends ServiceImpl<DummyInventoryI
} }
} }
// 校验头部是否符合模板 // 校验头部是否符合模板
String substring = headerSb.toString(); // String substring = headerSb.toString();
if (substring.endsWith(",") || substring.endsWith(",")){ // if (substring.endsWith(",") || substring.endsWith(",")){
substring = headerSb.substring(0, headerSb.length() - 1); // substring = headerSb.substring(0, headerSb.length() - 1);
} // }
// String excelHeader = substring.toString();
String excelHeader = substring.toString(); // if (!title.equals(excelHeader)) {
if (!title.equals(excelHeader)) { // workbook.close();
workbook.close(); // //删除原上传文件
//删除原上传文件 // FileUnZip.deleteDir(saveDirectory);
FileUnZip.deleteDir(saveDirectory); // if(CutEnum.CN.getValue().equals(dummyInventoryInfoEO.getCut())){
if(CutEnum.CN.getValue().equals(dummyInventoryInfoEO.getCut())){ // throw new JeroBootException("读取失败,请严格按照模板文件导入数据");
throw new JeroBootException("读取失败,请严格按照模板文件导入数据"); // }else{
}else{ // throw new JeroBootException("The data fails to be read. Import data strictly according to the template file");
throw new JeroBootException("The data fails to be read. Import data strictly according to the template file"); // }
} //
// }
}
} }
} }
workbook.close(); workbook.close();