fix: 标准导入文件格式校验Bug
This commit is contained in:
+2
-6
@@ -172,9 +172,6 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
// 封装查询显示的字段
|
// 封装查询显示的字段
|
||||||
String selectField = getSelectField(fieldList);
|
String selectField = getSelectField(fieldList);
|
||||||
|
|
||||||
// 筛选出查询列表显示的字段(不传id查列表)
|
|
||||||
List<LawsTag> fieldListSelect = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
|
||||||
.equals(lawsTag.getIsShowList().toString())).collect(Collectors.toList());
|
|
||||||
// 筛选出用于查询的字段
|
// 筛选出用于查询的字段
|
||||||
List<LawsTag> fieldListCondition = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
List<LawsTag> fieldListCondition = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||||
.equals(lawsTag.getIsQuery().toString())).collect(Collectors.toList());
|
.equals(lawsTag.getIsQuery().toString())).collect(Collectors.toList());
|
||||||
@@ -1246,7 +1243,6 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
.filter(lawsTag -> !lawsTag.getDbFieldName().equals(FieldCommon.ENTERPRISE_NAME_CODE))
|
.filter(lawsTag -> !lawsTag.getDbFieldName().equals(FieldCommon.ENTERPRISE_NAME_CODE))
|
||||||
.filter(lawsTag -> !lawsTag.getDbFieldName().equals(FieldCommon.STANDARD_CATEGORY_CODE))
|
.filter(lawsTag -> !lawsTag.getDbFieldName().equals(FieldCommon.STANDARD_CATEGORY_CODE))
|
||||||
.filter(lawsTag -> !lawsTag.getDbFieldName().equals(FieldCommon.YEAR_NUMBER))
|
.filter(lawsTag -> !lawsTag.getDbFieldName().equals(FieldCommon.YEAR_NUMBER))
|
||||||
.filter(lawsTag -> !lawsTag.getDbFieldName().equals(FieldCommon.CHECK_LIST))
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1351,7 +1347,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
if (errorMsgsList.size() > 0) {
|
if (errorMsgsList.size() > 0) {
|
||||||
return errorMsgsList;
|
return errorMsgsList;
|
||||||
} else {
|
} else {
|
||||||
// 执行导入功能
|
// 执行新增功能
|
||||||
for (Map<String, Object> map : insertDataList) {
|
for (Map<String, Object> map : insertDataList) {
|
||||||
// 获取操作模块
|
// 获取操作模块
|
||||||
map.put(FieldCommon.MODULE, module);
|
map.put(FieldCommon.MODULE, module);
|
||||||
@@ -1447,7 +1443,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
os.write(buffer, 0, length);
|
os.write(buffer, 0, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileMap.put(relativePath, tempOutputFile); // Use relative path as key
|
fileMap.put(relativePath, tempOutputFile); //使用相对路径作为Key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import com.jero.modules.system.service.ISysDepartService;
|
|||||||
import com.jero.modules.system.service.ISysUserService;
|
import com.jero.modules.system.service.ISysUserService;
|
||||||
import com.jero.modules.tag.entity.LawsTag;
|
import com.jero.modules.tag.entity.LawsTag;
|
||||||
import com.jero.modules.tag.enums.FieldShowTypeEnum;
|
import com.jero.modules.tag.enums.FieldShowTypeEnum;
|
||||||
|
import com.jero.modules.tag.enums.TableNameEnum;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -74,6 +75,40 @@ public class ImportUtil {
|
|||||||
}
|
}
|
||||||
// 单选时间
|
// 单选时间
|
||||||
String cellValue = cell.toString();
|
String cellValue = cell.toString();
|
||||||
|
|
||||||
|
// 企标编号校验
|
||||||
|
if (FieldCommon.STANDARD_NUMBER.equals(tag.getDbFieldName())) {
|
||||||
|
if (TableNameEnum.ENTERPRISE_STANDARDS.getValue().equals(tag.getIsModel())) {
|
||||||
|
// 使用正则表达式进行基础的格式验证
|
||||||
|
if (!cellValue.matches("^[A-Z]{1,2}/[A-Z]{2} [1-9A-HJ-Z]\\d{4}-\\d{4}$")) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列输入的标准编号格式不正确");
|
||||||
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列输入的标准编号格式不正确");
|
||||||
|
}
|
||||||
|
// 拆分成两部分,前半部分和后半部分
|
||||||
|
String[] mainParts = cellValue.split(" ");
|
||||||
|
String firstPart = mainParts[0];
|
||||||
|
String secondPart = mainParts[1];
|
||||||
|
|
||||||
|
// 拆分前半部分获取企业标准代号和企业名称代号
|
||||||
|
String[] firstPartElements = firstPart.split("/");
|
||||||
|
String enterpriseStandardCode = firstPartElements[0];
|
||||||
|
String enterpriseNameCode = firstPartElements[1];
|
||||||
|
|
||||||
|
// 拆分后半部分获取标准类别代号,顺序号和年代号
|
||||||
|
String[] secondPartElements = secondPart.split("-");
|
||||||
|
String categoryAndSequence = secondPartElements[0];
|
||||||
|
String yearCode = secondPartElements[1];
|
||||||
|
|
||||||
|
// 从标准类别代号和顺序号字符串中分离出标准类别代号和顺序号
|
||||||
|
String categoryCode = categoryAndSequence.substring(0, 1);
|
||||||
|
|
||||||
|
// 转成字典值并存入
|
||||||
|
parameterMap.put(FieldCommon.ENTERPRISE_STANDARD_CODE, this.convertDictValue("enterprise_standard_code", enterpriseStandardCode));
|
||||||
|
parameterMap.put(FieldCommon.ENTERPRISE_NAME_CODE, this.convertDictValue("enterprise_name_code", enterpriseNameCode));
|
||||||
|
parameterMap.put(FieldCommon.STANDARD_CATEGORY_CODE, this.convertDictValue("standard_category_code", categoryCode));
|
||||||
|
parameterMap.put(FieldCommon.YEAR_NUMBER, yearCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (FieldShowTypeEnum.SINGLE_DATE_PICKER.getValue().equals(tag.getFieldShowType())) {
|
if (FieldShowTypeEnum.SINGLE_DATE_PICKER.getValue().equals(tag.getFieldShowType())) {
|
||||||
Date date = cell.getDateCellValue();
|
Date date = cell.getDateCellValue();
|
||||||
// 创建一个SimpleDateFormat对象,并指定所需的格式
|
// 创建一个SimpleDateFormat对象,并指定所需的格式
|
||||||
@@ -84,11 +119,13 @@ public class ImportUtil {
|
|||||||
// 字段长度校验
|
// 字段长度校验
|
||||||
if (FieldShowTypeEnum.TEXT_BOX.getValue().equals(tag.getFieldShowType())) {
|
if (FieldShowTypeEnum.TEXT_BOX.getValue().equals(tag.getFieldShowType())) {
|
||||||
if (cellValue.length() > 50) {
|
if (cellValue.length() > 50) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列字段超过50字");
|
||||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列字段超过50字");
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列字段超过50字");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (FieldShowTypeEnum.MULTI_TEXT.getValue().equals(tag.getFieldShowType())) {
|
if (FieldShowTypeEnum.MULTI_TEXT.getValue().equals(tag.getFieldShowType())) {
|
||||||
if (cellValue.length() > 500) {
|
if (cellValue.length() > 500) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列字段超过500字");
|
||||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列字段超过500字");
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列字段超过500字");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,6 +134,7 @@ public class ImportUtil {
|
|||||||
if (FieldShowTypeEnum.DROPDOWN_SINGLE_SELECT.getValue().equals(tag.getFieldShowType()) ||
|
if (FieldShowTypeEnum.DROPDOWN_SINGLE_SELECT.getValue().equals(tag.getFieldShowType()) ||
|
||||||
FieldShowTypeEnum.DROPDOWN_MULTI_SELECT.getValue().equals(tag.getFieldShowType())) {
|
FieldShowTypeEnum.DROPDOWN_MULTI_SELECT.getValue().equals(tag.getFieldShowType())) {
|
||||||
if (!this.dictValid(tag.getDictField(), cellValue)) {
|
if (!this.dictValid(tag.getDictField(), cellValue)) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||||
} else {
|
} else {
|
||||||
// 转为value
|
// 转为value
|
||||||
@@ -106,6 +144,7 @@ public class ImportUtil {
|
|||||||
// 单选组织机构
|
// 单选组织机构
|
||||||
if (FieldShowTypeEnum.SINGLE_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
if (FieldShowTypeEnum.SINGLE_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||||
if (!this.singleOrgValid(cellValue)) {
|
if (!this.singleOrgValid(cellValue)) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
} else {
|
} else {
|
||||||
// 转为id
|
// 转为id
|
||||||
@@ -115,6 +154,7 @@ public class ImportUtil {
|
|||||||
// 单选人员
|
// 单选人员
|
||||||
if (FieldShowTypeEnum.SINGLE_USER_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
if (FieldShowTypeEnum.SINGLE_USER_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||||
if (!this.singleUserValid(cellValue)) {
|
if (!this.singleUserValid(cellValue)) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
} else {
|
} else {
|
||||||
// 转为id
|
// 转为id
|
||||||
@@ -124,6 +164,7 @@ public class ImportUtil {
|
|||||||
// 多选组织机构
|
// 多选组织机构
|
||||||
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||||
if (!this.multiOrgValid(cellValue)) {
|
if (!this.multiOrgValid(cellValue)) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
} else {
|
} else {
|
||||||
// 转为id
|
// 转为id
|
||||||
@@ -133,6 +174,7 @@ public class ImportUtil {
|
|||||||
// 零部件
|
// 零部件
|
||||||
if (tag.getDbFieldName().equals("part_name") && StrUtil.isNotBlank(cellValue)) {
|
if (tag.getDbFieldName().equals("part_name") && StrUtil.isNotBlank(cellValue)) {
|
||||||
if (!this.partValid(cellValue)) {
|
if (!this.partValid(cellValue)) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
} else {
|
} else {
|
||||||
// 转为id
|
// 转为id
|
||||||
@@ -142,6 +184,7 @@ public class ImportUtil {
|
|||||||
// 多选组织机构
|
// 多选组织机构
|
||||||
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||||
if (!this.multiOrgValid(cellValue)) {
|
if (!this.multiOrgValid(cellValue)) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
} else {
|
} else {
|
||||||
// 转为id
|
// 转为id
|
||||||
@@ -151,6 +194,7 @@ public class ImportUtil {
|
|||||||
// 体系
|
// 体系
|
||||||
if (FieldCommon.STANDARD_SYSTEM.equals(tag.getDbFieldName())) {
|
if (FieldCommon.STANDARD_SYSTEM.equals(tag.getDbFieldName())) {
|
||||||
if (!this.standardSystemValid(cellValue)) {
|
if (!this.standardSystemValid(cellValue)) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
} else {
|
} else {
|
||||||
// 转为id
|
// 转为id
|
||||||
@@ -160,6 +204,7 @@ public class ImportUtil {
|
|||||||
// 文件
|
// 文件
|
||||||
if (FieldShowTypeEnum.FILE_UPLOAD.getValue().equals(tag.getFieldShowType())) {
|
if (FieldShowTypeEnum.FILE_UPLOAD.getValue().equals(tag.getFieldShowType())) {
|
||||||
if (!this.fileValid(cellValue, fileMap)) {
|
if (!this.fileValid(cellValue, fileMap)) {
|
||||||
|
log.error("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
} else {
|
} else {
|
||||||
// 转为id
|
// 转为id
|
||||||
@@ -362,10 +407,10 @@ public class ImportUtil {
|
|||||||
if (file == null) {
|
if (file == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (path.endsWith(".pdf")
|
if (!(path.endsWith(".pdf")
|
||||||
|| path.endsWith(".doc") || path.endsWith(".docx")
|
|| path.endsWith(".doc") || path.endsWith(".docx")
|
||||||
|| path.endsWith(".xls") || path.endsWith(".xlsx")
|
|| path.endsWith(".xls") || path.endsWith(".xlsx")
|
||||||
|| path.endsWith(".png") || path.endsWith(".jpg")) {
|
|| path.endsWith(".png") || path.endsWith(".jpg"))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user