fix: 标准文件层级问题

This commit is contained in:
2023-11-07 17:25:28 +08:00
parent 8bfc98c1ed
commit bd4c00a43b
3 changed files with 66 additions and 8 deletions
@@ -1428,10 +1428,19 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
}
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + File.separator + file.getOriginalFilename()));
// 解压缩
FileUnZip.unZipFiles(path + File.separator + file.getOriginalFilename(), String.valueOf(path));
String zipEntryName = FileUnZip.unZipFiles(path + File.separator + file.getOriginalFilename(), String.valueOf(path));
//判断压缩包下是否只有一个文件夹
File fileTemp = new File(path.toUri());
int length = fileTemp.listFiles().length;
if (length > 2) {
FileUnZip.deleteDir(saveDirectory);
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.FOLDER_ONLY_ONE));
}
List<File> fileList = new ArrayList<>();
for (File file1 : Objects.requireNonNull(saveDirectory.listFiles())) {
File fileNew = new File(zipEntryName);
for (File file1 : Objects.requireNonNull(fileNew.listFiles())) {
if (file1.getName().contains(".xls") || file1.getName().contains(".xlsx")) {
fileList.add(file1);
}
@@ -1443,7 +1452,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
FileUnZip.deleteDir(saveDirectory);
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.IMPORT_TEMPLATE_ERROR));
}
List<File> excelfilelist = FileUnZip.readImpExcelFile(saveDirectory.getPath());
List<File> excelfilelist = FileUnZip.readImpExcelFile(fileNew.getPath());
System.gc();
if (excelfilelist.size() != 1) {
FileUnZip.deleteDir(saveDirectory);
@@ -1474,7 +1483,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
// 数据内容格式校验
Map<String, File> fileMap = new HashMap<>();
// 遍历saveDirectory下的所有文件
populateFileMap(saveDirectory, saveDirectory, fileMap);
populateFileMap(fileNew, fileNew, fileMap);
try (Workbook workbook = new XSSFWorkbook(Files.newInputStream(excelfilelist.get(0).toPath()))) {
// 检测是否是空Excel
@@ -92,6 +92,8 @@ public class ImportUtil {
String standardNumber = "";
String standardClass = "";
String yearNumber = "";
Date publishDate = null;
Date implementationDate = null;
StringBuilder errMsg = new StringBuilder("" + line + "");
Map<String, Object> parameterMap = new HashMap<>();
boolean standardValidFlag = false;
@@ -379,9 +381,16 @@ public class ImportUtil {
}
// 单选时间
if (FieldShowTypeEnum.SINGLE_DATE_PICKER.getValue().equals(tag.getFieldShowType())) {
if (!this.multiDateValid(cellValue)) {
if (!this.singleDateValid(cellValue)) {
log.error("" + row + "" + tag.getDbFieldTxt() + "填写错误 ");
errMsg.append("").append(row).append("").append(tag.getDbFieldTxt()).append("填写错误 ");
} else {
if (tag.getDbFieldName().equals("publish_date")) {
publishDate = this.convertDate(cellValue);
}
if (tag.getDbFieldName().equals("implementation_date")) {
implementationDate = this.convertDate(cellValue);
}
}
}
// 多选时间
@@ -421,6 +430,16 @@ public class ImportUtil {
}
}
}
// 判断实施日期是否大于发布日期15天
if (publishDate != null && implementationDate != null) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(implementationDate);
calendar.add(Calendar.DAY_OF_MONTH, 15);
if (publishDate.before(calendar.getTime())) {
log.error("" + line + "行的实施日期必须大于发布日期15天 ");
errMsg.append("").append(line).append("行的实施日期必须大于发布日期15天 ");
}
}
if (errMsg.toString().contains("") || errMsg.toString().contains("重复") || errMsg.toString().contains("已存在")) {
errMsgList.add(errMsg.toString());
} else {
@@ -430,6 +449,20 @@ public class ImportUtil {
return errMsgList;
}
private Date convertDate(String cellValue) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 设置lenient为false,使得日期解析更为严格
sdf.setLenient(false);
try {
// 使用parse方法而不是format方法
return sdf.parse(cellValue.trim());
} catch (ParseException e) {
// 这里捕获的应该是ParseException
log.error("日期转换错误: {}", e.getMessage());
return null;
}
}
private Object convertInspectContentFile(String cellValue, Map<String, File> fileMap) {
List<LinkedHashMap<String, String>> checkList = new ArrayList<>();
String filePath = Arrays.asList(cellValue.split(",")).get(0);
@@ -458,6 +491,22 @@ public class ImportUtil {
return checkList;
}
// 单选日期校验
private boolean singleDateValid(String cellValue) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 设置lenient为false,使得日期解析更为严格
sdf.setLenient(false);
try {
// 使用parse方法而不是format方法
sdf.parse(cellValue.trim()); // 这里还添加了trim()以去除可能的空白字符
return true;
} catch (ParseException e) {
// 这里捕获的应该是ParseException
log.error("日期转换错误: {}", e.getMessage());
return false;
}
}
private boolean multiDateValid(String cellValue) {
String[] dates = cellValue.split(",");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@@ -26,9 +26,9 @@ public enum FieldShowTypeEnum {
// 体系
TREE_STRUCTURE_MULTI_SELECT("树形结构(多选)","12","请填写选项中包含的文本,多填以英文逗号隔开"),
YEAR_SELECT("年份选择","14","请填写选项中包含的文本"),
// 零部件
TREE_STRUCTURE_SINGLE_SELECT("树形结构(单选)","15","请填写选项中包含的文本"),
TREE_POP_UP("树形弹框","16","请填写选项中包含的文本,多填以逗号隔开"),
// 零部件
TREE_POP_UP("树形弹框","16","请填写选项中包含的文本"),
;
@@ -56,7 +56,7 @@ public enum FieldShowTypeEnum {
case "试行周期":
return "请填写1-24个月";
case "动力类型":
return "请填写选项中包含的文本,多填以逗号隔开";
return "请填写选项中包含的文本,多填以英文逗号隔开";
}
String value = tag.getFieldShowType();
for (FieldShowTypeEnum fieldShowTypeEnum : values()) {