feat: 三标通用导入(常规字段导入)
This commit is contained in:
+5
-4
@@ -4,9 +4,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.jero.modules.laws.common.vo.ManyStandardSelectionBox;
|
import com.jero.modules.laws.common.vo.ManyStandardSelectionBox;
|
||||||
import com.jero.modules.laws.common.vo.ManyStandardSelectionBoxVO;
|
import com.jero.modules.laws.common.vo.ManyStandardSelectionBoxVO;
|
||||||
import com.jero.modules.tag.entity.LawsTag;
|
import com.jero.modules.tag.entity.LawsTag;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -144,8 +145,8 @@ public interface ILawsCommonService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入
|
* 导入
|
||||||
* @param request
|
* @param file
|
||||||
* @param tableName
|
* @param module
|
||||||
*/
|
*/
|
||||||
void importExcelWithData(HttpServletRequest request, String tableName);
|
List<String> importExcelWithData(MultipartFile file, String module);
|
||||||
}
|
}
|
||||||
|
|||||||
+417
-11
@@ -10,9 +10,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.jero.common.constant.enums.LanguageEnum;
|
import com.jero.common.constant.enums.LanguageEnum;
|
||||||
import com.jero.common.constant.enums.YesOrNoEnum;
|
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||||
import com.jero.common.exception.JeroBootException;
|
import com.jero.common.exception.JeroBootException;
|
||||||
|
import com.jero.common.system.api.ISysBaseAPI;
|
||||||
|
import com.jero.common.system.vo.DictModel;
|
||||||
import com.jero.common.system.vo.LoginUser;
|
import com.jero.common.system.vo.LoginUser;
|
||||||
import com.jero.common.util.MessageUtils;
|
import com.jero.common.util.MessageUtils;
|
||||||
import com.jero.common.util.MinioUtil;
|
|
||||||
import com.jero.modules.laws.common.constant.FieldCommon;
|
import com.jero.modules.laws.common.constant.FieldCommon;
|
||||||
import com.jero.modules.laws.common.constant.ResultCommon;
|
import com.jero.modules.laws.common.constant.ResultCommon;
|
||||||
import com.jero.modules.laws.common.mapper.LawsCommonMapper;
|
import com.jero.modules.laws.common.mapper.LawsCommonMapper;
|
||||||
@@ -43,6 +44,7 @@ import com.jero.modules.tag.enums.LawsFieldTypeEnum;
|
|||||||
import com.jero.modules.tag.service.ILawsAreaService;
|
import com.jero.modules.tag.service.ILawsAreaService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
@@ -52,18 +54,23 @@ import org.apache.shiro.SecurityUtils;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,6 +111,13 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
private EnterpriseStandardInspectContentService esInspectContentService;
|
private EnterpriseStandardInspectContentService esInspectContentService;
|
||||||
@Resource
|
@Resource
|
||||||
private EnterpriseStandardUtil esUtil;
|
private EnterpriseStandardUtil esUtil;
|
||||||
|
@Resource
|
||||||
|
private ISysBaseAPI sysBaseAPI;
|
||||||
|
@Resource
|
||||||
|
private ISysDictItemService dictItemService;
|
||||||
|
// 自我注入
|
||||||
|
@Autowired
|
||||||
|
private ILawsCommonService commonService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: liao
|
* @Author: liao
|
||||||
@@ -477,15 +491,16 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
String module = (String) parameterMap.get(FieldCommon.MODULE);
|
String module = (String) parameterMap.get(FieldCommon.MODULE);
|
||||||
|
|
||||||
// 企标需要自动拼装标准号
|
// 企标需要自动拼装标准号
|
||||||
if (module.equals(TableNameEnum.ENTERPRISE_STANDARDS.getValue())) {
|
if (module.equals(TableNameEnum.ENTERPRISE_STANDARDS.getValue()) &&
|
||||||
|
StrUtil.isBlank(parameterMap.get(FieldCommon.STANDARD_NUMBER).toString())) {
|
||||||
// 生成企标编号
|
// 生成企标编号
|
||||||
String standardNumber = esUtil.generateStandardNumber(parameterMap);
|
String standardNumber = esUtil.generateStandardNumber(parameterMap);
|
||||||
parameterMap.put(FieldCommon.STANDARD_NUMBER, standardNumber);
|
parameterMap.put(FieldCommon.STANDARD_NUMBER, standardNumber);
|
||||||
}
|
}
|
||||||
// 提前处理企标的稽查内容,否则后面转换会报错
|
// 提前处理企标的稽查内容,否则后面转换会报错
|
||||||
List<LinkedHashMap> checkList = (List<LinkedHashMap>) parameterMap.get(FieldCommon.CHECK_LIST);
|
// List<LinkedHashMap> checkList = (List<LinkedHashMap>) parameterMap.get(FieldCommon.CHECK_LIST);
|
||||||
List<EnterpriseStandardInspectContent> inspectContents = this.convertList(checkList);
|
// List<EnterpriseStandardInspectContent> inspectContents = this.convertList(checkList);
|
||||||
parameterMap.put(FieldCommon.CHECK_LIST, null);
|
// parameterMap.put(FieldCommon.CHECK_LIST, null);
|
||||||
// 法规编号不能为空
|
// 法规编号不能为空
|
||||||
String standardNumber = (String) parameterMap.get(FieldCommon.STANDARD_NUMBER);
|
String standardNumber = (String) parameterMap.get(FieldCommon.STANDARD_NUMBER);
|
||||||
if (StringUtils.isBlank(standardNumber)) {
|
if (StringUtils.isBlank(standardNumber)) {
|
||||||
@@ -551,9 +566,9 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
lawsNodeRelationService.addRelation(standardSystem, standardNumber, id);
|
lawsNodeRelationService.addRelation(standardSystem, standardNumber, id);
|
||||||
|
|
||||||
// 执行企标独有的逻辑
|
// 执行企标独有的逻辑
|
||||||
if (module.equals(TableNameEnum.ENTERPRISE_STANDARDS.getValue())) {
|
// if (module.equals(TableNameEnum.ENTERPRISE_STANDARDS.getValue())) {
|
||||||
this.esInspectContentSaveOrUpdate(inspectContents, id, standardNumber);
|
// this.esInspectContentSaveOrUpdate(inspectContents, id, standardNumber);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return MessageUtils.getMessage(ResultCommon.OK);
|
return MessageUtils.getMessage(ResultCommon.OK);
|
||||||
}
|
}
|
||||||
@@ -1206,6 +1221,17 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||||
.equals(lawsTag.getIsShowFormCreate().toString())).collect(Collectors.toList());
|
.equals(lawsTag.getIsShowFormCreate().toString())).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 去除企标导入逻辑不需要显示的字段
|
||||||
|
if (TableNameEnum.ENTERPRISE_STANDARDS.getTableName().equals(tableName)) {
|
||||||
|
fieldList = fieldList.stream()
|
||||||
|
.filter(lawsTag -> !lawsTag.getDbFieldName().equals(FieldCommon.ENTERPRISE_STANDARD_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.YEAR_NUMBER))
|
||||||
|
.filter(lawsTag -> !lawsTag.getDbFieldName().equals(FieldCommon.CHECK_LIST))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
// 创建一个Excel工作簿
|
// 创建一个Excel工作簿
|
||||||
Workbook workbook = new XSSFWorkbook();
|
Workbook workbook = new XSSFWorkbook();
|
||||||
|
|
||||||
@@ -1297,9 +1323,389 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importExcelWithData(HttpServletRequest request, String tableName) {
|
public List<String> importExcelWithData(MultipartFile file, String module) {
|
||||||
//TODO 该死的导入
|
try {
|
||||||
|
List<Map<String, Object>> insertDataList = new ArrayList<>();
|
||||||
|
String tableName = TableNameEnum.getTableName(module);
|
||||||
|
List<String> errorMsgsList = this.validDataFormat(insertDataList, file, tableName);
|
||||||
|
// 判断如果校验有问题则返回校验错误信息,没问题则将数据转化为导入方法所需参数
|
||||||
|
if (errorMsgsList.size() > 0) {
|
||||||
|
return errorMsgsList;
|
||||||
|
} else {
|
||||||
|
// 执行导入功能
|
||||||
|
for (Map<String, Object> map : insertDataList) {
|
||||||
|
// 获取操作模块
|
||||||
|
map.put(FieldCommon.MODULE, module);
|
||||||
|
commonService.commonAdd(map);
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("数据导入异常,请检查", e);
|
||||||
|
throw new JeroBootException("数据导入异常,请检查");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验导入数据有效性
|
||||||
|
* @param insertDataList
|
||||||
|
* @param file
|
||||||
|
* @param tableName
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private List<String> validDataFormat(List<Map<String, Object>> insertDataList, MultipartFile file, String tableName) throws IOException {
|
||||||
|
List<String> errMsgList = new ArrayList<>();
|
||||||
|
|
||||||
|
// 判断上传的是不是压缩包
|
||||||
|
if (!Objects.requireNonNull(file.getOriginalFilename()).endsWith(".zip")) {
|
||||||
|
throw new JeroBootException("数据导入失败,请上传zip压缩包");
|
||||||
|
}
|
||||||
|
|
||||||
|
Path tempDirWithPrefix = Files.createTempDirectory("temp");
|
||||||
|
File tempFile = new File(tempDirWithPrefix.toFile(), Objects.requireNonNull(file.getOriginalFilename()));
|
||||||
|
file.transferTo(tempFile);
|
||||||
|
|
||||||
|
int folderCount = 0;
|
||||||
|
int excelCount = 0;
|
||||||
|
ZipEntry targetExcelEntry = null;
|
||||||
|
Charset correctCharset = null;
|
||||||
|
|
||||||
|
// 尝试不同的编码来找到正确的字符集
|
||||||
|
String[] charsetsToBeTested = {"GB2312", "GBK", "UTF-8", "UTF-16"};
|
||||||
|
for (String charset : charsetsToBeTested) {
|
||||||
|
try (ZipFile zipFile = new ZipFile(tempFile, Charset.forName(charset))) {
|
||||||
|
if (zipFile.size() > 0) {
|
||||||
|
correctCharset = Charset.forName(charset);
|
||||||
|
log.info("【标准带文件导入】尝试使用{}编码打开压缩包成功", charset);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
log.error("【标准带文件导入】尝试使用{}编码打开压缩包失败", charset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (correctCharset == null) {
|
||||||
|
errMsgList.add("无法确定压缩包的字符编码");
|
||||||
|
return errMsgList;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (ZipFile zipFile = new ZipFile(tempFile, correctCharset)) {
|
||||||
|
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||||
|
|
||||||
|
// 文件数量校验
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
ZipEntry entry = entries.nextElement();
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
folderCount++;
|
||||||
|
}
|
||||||
|
if (folderCount > 1) {
|
||||||
|
errMsgList.add("压缩包根目录下仅能存在一个文件夹");
|
||||||
|
return errMsgList;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entry.isDirectory() && entry.getName().endsWith(".xlsx")) {
|
||||||
|
excelCount++;
|
||||||
|
targetExcelEntry = entry;
|
||||||
|
}
|
||||||
|
if (excelCount > 1) {
|
||||||
|
errMsgList.add("压缩包根目录下仅能存在一个 excel 为导入数据");
|
||||||
|
return errMsgList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据内容格式校验
|
||||||
|
if (targetExcelEntry != null) {
|
||||||
|
try (Workbook workbook = new XSSFWorkbook(zipFile.getInputStream(targetExcelEntry))) {
|
||||||
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
// 获取标题行中文 转换为LawsTag对象
|
||||||
|
Row hearderRow = sheet.getRow(0);
|
||||||
|
|
||||||
|
// 获取全部字段
|
||||||
|
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||||
|
// 筛选表单显示的字段
|
||||||
|
|
||||||
|
// 找到所有标题Map
|
||||||
|
Map<String, LawsTag> headerMap = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||||
|
.equals(lawsTag.getIsShowForm().toString())).collect(Collectors.toMap(
|
||||||
|
LawsTag::getDbFieldTxt, lawsTag -> lawsTag
|
||||||
|
));
|
||||||
|
// 按照实际顺序创建headerList
|
||||||
|
List<LawsTag> headerList = new ArrayList<>();
|
||||||
|
for (Cell cell : hearderRow) {
|
||||||
|
headerList.add(headerMap.get(cell.toString().replace("*", "")));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从数据行开始遍历
|
||||||
|
for (int i = 3; i < sheet.getPhysicalNumberOfRows(); i++) {
|
||||||
|
Map<String, Object> parameterMap = new HashMap<>();
|
||||||
|
for (int j = 0; j < sheet.getRow(i).getPhysicalNumberOfCells(); j++) {
|
||||||
|
boolean errorFlag = false;
|
||||||
|
// 获取当前单元格
|
||||||
|
Cell cell = sheet.getRow(i).getCell(j);
|
||||||
|
|
||||||
|
// 获取当前单元格内容对应的字段
|
||||||
|
LawsTag tag = headerList.get(j);
|
||||||
|
|
||||||
|
// 按照标签要求的格式验证
|
||||||
|
// 必填验证
|
||||||
|
if (YesOrNoEnum.YES.getValue().equals(tag.getFieldMustInput())) {
|
||||||
|
if (!this.mustInputValid(cell)) {
|
||||||
|
errMsgList.add("第" + (i) + "行第" + (j + 1) + "列为必填");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 获取当前单元格内容
|
||||||
|
if (cell == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 单选时间
|
||||||
|
String cellValue = cell.toString();
|
||||||
|
if (FieldShowTypeEnum.SINGLE_DATE_PICKER.getValue().equals(tag.getFieldShowType())) {
|
||||||
|
Date date = cell.getDateCellValue();
|
||||||
|
// 创建一个SimpleDateFormat对象,并指定所需的格式
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
// 使用SimpleDateFormat对象的format方法将Date对象转换为字符串
|
||||||
|
cellValue = sdf.format(date);
|
||||||
|
}
|
||||||
|
// TODO 多选时间
|
||||||
|
|
||||||
|
// 字段长度校验
|
||||||
|
if (FieldShowTypeEnum.TEXT_BOX.getValue().equals(tag.getFieldShowType())) {
|
||||||
|
if (cellValue.length() > 50) {
|
||||||
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列字段超过50字");
|
||||||
|
errorFlag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (FieldShowTypeEnum.MULTI_TEXT.getValue().equals(tag.getFieldShowType())) {
|
||||||
|
if (cellValue.length() > 500) {
|
||||||
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列字段超过500字");
|
||||||
|
errorFlag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下拉单选
|
||||||
|
if (FieldShowTypeEnum.DROPDOWN_SINGLE_SELECT.getValue().equals(tag.getFieldShowType()) ||
|
||||||
|
FieldShowTypeEnum.DROPDOWN_MULTI_SELECT.getValue().equals(tag.getFieldShowType())) {
|
||||||
|
if (!this.dictValid(tag.getDictField(), cellValue)) {
|
||||||
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||||
|
errorFlag = true;
|
||||||
|
} else {
|
||||||
|
// 转为value
|
||||||
|
cellValue = this.convertDictValue(tag.getDictField(), cellValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 单选组织机构
|
||||||
|
if (FieldShowTypeEnum.SINGLE_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||||
|
if (!this.singleOrgValid(cellValue)) {
|
||||||
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
|
errorFlag = true;
|
||||||
|
} else {
|
||||||
|
// 转为id
|
||||||
|
cellValue = this.convertSingleOrgId(cellValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 单选人员
|
||||||
|
if (FieldShowTypeEnum.SINGLE_USER_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||||
|
if (!this.singleUserValid(cellValue)) {
|
||||||
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
|
errorFlag = true;
|
||||||
|
} else {
|
||||||
|
// 转为id
|
||||||
|
cellValue = this.convertSingleUserId(cellValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 多选组织机构
|
||||||
|
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||||
|
if (!this.multiOrgValid(cellValue)) {
|
||||||
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
|
errorFlag = true;
|
||||||
|
} else {
|
||||||
|
// 转为id
|
||||||
|
cellValue = this.convertMultiOrgId(cellValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 零部件
|
||||||
|
if (tag.getDbFieldName().equals("part_name") && StrUtil.isNotBlank(cellValue)) {
|
||||||
|
if (!this.partValid(cellValue)) {
|
||||||
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
|
errorFlag = true;
|
||||||
|
} else {
|
||||||
|
// 转为id
|
||||||
|
cellValue = this.convertPartId(cellValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 多选组织机构
|
||||||
|
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||||
|
if (!this.multiOrgValid(cellValue)) {
|
||||||
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
|
errorFlag = true;
|
||||||
|
} else {
|
||||||
|
// 转为id
|
||||||
|
cellValue = this.convertMultiOrgId(cellValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 体系
|
||||||
|
if (FieldCommon.STANDARD_SYSTEM.equals(tag.getDbFieldName())) {
|
||||||
|
if (!this.standardSystemValid(cellValue)) {
|
||||||
|
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||||
|
errorFlag = true;
|
||||||
|
} else {
|
||||||
|
// 转为id
|
||||||
|
cellValue = this.convertStandardSystem(cellValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!errorFlag) {
|
||||||
|
// 如果数据通过了校验则将数据按照格式加入Map
|
||||||
|
// 如果是企标稽查内容,则需要将整个Excel文档序列化成JSON 然后走新增逻辑
|
||||||
|
parameterMap.put(tag.getDbFieldName(), cellValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
insertDataList.add(parameterMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errMsgList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String convertStandardSystem(String cellValue) {
|
||||||
|
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||||
|
LambdaQueryWrapper<LawsTreeNode> treeNodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
treeNodeLambdaQueryWrapper.in(LawsTreeNode::getNodeName, valueList);
|
||||||
|
List<LawsTreeNode> treeNodeList = lawsTreeNodeService.list(treeNodeLambdaQueryWrapper);
|
||||||
|
Map<String, String> systemMap = treeNodeList.stream().collect(Collectors.toMap(LawsTreeNode::getNodeName, LawsTreeNode::getId));
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (String value : valueList) {
|
||||||
|
result.append(systemMap.get(value)).append(",");
|
||||||
|
}
|
||||||
|
// 去除掉最后的逗号
|
||||||
|
return result.substring(0, result.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String convertSingleUserId(String cellValue) {
|
||||||
|
LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sysUserLambdaQueryWrapper.eq(SysUser::getNameWorkNo, cellValue);
|
||||||
|
return sysUserService.getOne(sysUserLambdaQueryWrapper).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String convertPartId(String cellValue) {
|
||||||
|
String[] valueList = cellValue.split(",");
|
||||||
|
Map<String, DictModel> sexDictModelMap =
|
||||||
|
sysBaseAPI.getDictItems("Part Name").stream()
|
||||||
|
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (String value : valueList) {
|
||||||
|
result.append(sexDictModelMap.get(value).getValue()).append(",");
|
||||||
|
}
|
||||||
|
// 去除掉最后的逗号
|
||||||
|
return result.substring(0, result.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String convertMultiOrgId(String cellValue) {
|
||||||
|
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||||
|
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sysDepartLambdaQueryWrapper.in(SysDepart::getDepartName, valueList);
|
||||||
|
List<SysDepart> deptList = sysDepartService.list(sysDepartLambdaQueryWrapper);
|
||||||
|
Map<String, String> deptMap = deptList.stream().collect(Collectors.toMap(SysDepart::getDepartName, SysDepart::getId));
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (String value : valueList) {
|
||||||
|
result.append(deptMap.get(value)).append(",");
|
||||||
|
}
|
||||||
|
// 去除掉最后的逗号
|
||||||
|
return result.substring(0, result.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String convertSingleOrgId(String cellValue) {
|
||||||
|
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sysDepartLambdaQueryWrapper.eq(SysDepart::getDepartName, cellValue);
|
||||||
|
return sysDepartService.getOne(sysDepartLambdaQueryWrapper).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String convertDictValue(String dictCode, String cellValue) {
|
||||||
|
String[] valueList = cellValue.split(",");
|
||||||
|
Map<String, DictModel> sexDictModelMap =
|
||||||
|
sysBaseAPI.getDictItems(dictCode).stream()
|
||||||
|
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (String value : valueList) {
|
||||||
|
result.append(sexDictModelMap.get(value).getValue()).append(",");
|
||||||
|
}
|
||||||
|
// 去除掉最后的逗号
|
||||||
|
return result.substring(0, result.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 必填校验
|
||||||
|
private boolean mustInputValid(Cell cell) {
|
||||||
|
if (cell == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String cellValue = cell.toString();
|
||||||
|
return StrUtil.isNotBlank(cellValue);
|
||||||
|
}
|
||||||
|
// 字典验证(判断填写的是否是选项中的一个)
|
||||||
|
private boolean dictValid(String dictCode, String cellValue) {
|
||||||
|
String[] valueList = cellValue.split(",");
|
||||||
|
Map<String, DictModel> sexDictModelMap =
|
||||||
|
sysBaseAPI.getDictItems(dictCode).stream()
|
||||||
|
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||||
|
|
||||||
|
for (String value : valueList) {
|
||||||
|
if (sexDictModelMap.get(value) == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 单选组织机构
|
||||||
|
private boolean singleOrgValid(String cellValue) {
|
||||||
|
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sysDepartLambdaQueryWrapper.eq(SysDepart::getDepartName, cellValue);
|
||||||
|
return Objects.nonNull(sysDepartService.getOne(sysDepartLambdaQueryWrapper));
|
||||||
|
}
|
||||||
|
// 单选人员
|
||||||
|
private boolean singleUserValid(String cellValue) {
|
||||||
|
LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sysUserLambdaQueryWrapper.eq(SysUser::getNameWorkNo, cellValue);
|
||||||
|
return Objects.nonNull(sysUserService.getOne(sysUserLambdaQueryWrapper));
|
||||||
|
}
|
||||||
|
// 多选组织机构
|
||||||
|
private boolean multiOrgValid(String cellValue) {
|
||||||
|
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||||
|
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sysDepartLambdaQueryWrapper.in(SysDepart::getDepartName, valueList);
|
||||||
|
List<SysDepart> list = sysDepartService.list(sysDepartLambdaQueryWrapper);
|
||||||
|
return valueList.size() == list.size();
|
||||||
|
}
|
||||||
|
// 零部件
|
||||||
|
private boolean partValid(String cellValue) {
|
||||||
|
String[] valueList = cellValue.split(",");
|
||||||
|
List<DictModel> educationDictModelList = sysBaseAPI.getDictItems("Part Name");
|
||||||
|
Map<String, DictModel> sexDictModelMap = educationDictModelList.stream()
|
||||||
|
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||||
|
for (String value : valueList) {
|
||||||
|
if (sexDictModelMap.get(value) == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private boolean standardSystemValid(String cellValue) {
|
||||||
|
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||||
|
LambdaQueryWrapper<LawsTreeNode> treeNodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
treeNodeLambdaQueryWrapper.in(LawsTreeNode::getNodeName, valueList);
|
||||||
|
List<LawsTreeNode> treeNodeList = lawsTreeNodeService.list(treeNodeLambdaQueryWrapper);
|
||||||
|
Map<String, String> systemMap = treeNodeList.stream().collect(Collectors.toMap(LawsTreeNode::getNodeName, LawsTreeNode::getId));
|
||||||
|
for (String value : valueList) {
|
||||||
|
if (systemMap.get(value) == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+5
-3
@@ -22,8 +22,10 @@ import com.jero.modules.tag.entity.LawsTag;
|
|||||||
import com.jero.modules.tag.enums.TableNameEnum;
|
import com.jero.modules.tag.enums.TableNameEnum;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -217,8 +219,8 @@ public class LawsEnterpriseController {
|
|||||||
|
|
||||||
@AutoLog(value = "企业法规标准-导入")
|
@AutoLog(value = "企业法规标准-导入")
|
||||||
@ApiOperation(value="企业法规标准-导入", notes="企业法规标准-导入")
|
@ApiOperation(value="企业法规标准-导入", notes="企业法规标准-导入")
|
||||||
@GetMapping("/importExcelWithData")
|
@PostMapping("/importExcelWithData")
|
||||||
public void importExcelWithData(HttpServletRequest request) {
|
public Result<?> importExcelWithData(@RequestParam("file") MultipartFile file) {
|
||||||
lawsCommonService.importExcelWithData(request, TableNameEnum.ENTERPRISE_STANDARDS.getTableName());
|
return Result.OK(lawsCommonService.importExcelWithData(file, TableNameEnum.ENTERPRISE_STANDARDS.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,17 +11,19 @@ public enum FieldShowTypeEnum {
|
|||||||
SINGLE_DATE_PICKER("单日期选择","1","请填写选项中包含的文本"),
|
SINGLE_DATE_PICKER("单日期选择","1","请填写选项中包含的文本"),
|
||||||
SINGLE_USER_DIALOG("单选用户弹框","2","请填写选项中包含的文本"),
|
SINGLE_USER_DIALOG("单选用户弹框","2","请填写选项中包含的文本"),
|
||||||
SINGLE_ORGANIZATION_DIALOG("单选组织机构弹框","3","请填写选项中包含的文本"),
|
SINGLE_ORGANIZATION_DIALOG("单选组织机构弹框","3","请填写选项中包含的文本"),
|
||||||
MULTI_DATE_PICKER("多日期选择","4","4"),
|
MULTI_DATE_PICKER("多日期选择","4","请填写一个至多个日期,多填以中文逗号隔开"),
|
||||||
MULTI_TEXT("多行文本","5","文本输入"),
|
MULTI_TEXT("多行文本","5","文本输入"),
|
||||||
MULTI_STANDARD_DIALOG("多选标准弹框","6","请填写选项中包含的文本,多填以逗号隔开"),
|
MULTI_STANDARD_DIALOG("多选标准弹框","6","请填写选项中包含的文本,多填以中文逗号隔开"),
|
||||||
MULTI_ORGANIZATION_DIALOG("多选组织机构弹框","7","请填写选项中包含的文本,多填以逗号隔开"),
|
MULTI_ORGANIZATION_DIALOG("多选组织机构弹框","7","请填写选项中包含的文本,多填以中文逗号隔开"),
|
||||||
FILE_UPLOAD("上传文件","8","文件属性,请输入:标准号/文件名称.文件格式"),
|
FILE_UPLOAD("上传文件","8","文件属性,请输入:标准号/文件名称.文件格式"),
|
||||||
TEXT_BOX("文本框","9","文本输入"),
|
TEXT_BOX("文本框","9","文本输入"),
|
||||||
DROPDOWN_SINGLE_SELECT("下拉单选","10","4"),
|
DROPDOWN_SINGLE_SELECT("下拉单选","10","请填写选项中包含的文本"),
|
||||||
DROPDOWN_MULTI_SELECT("下拉多选","11","请填写选项中包含的文本,多填以逗号隔开"),
|
DROPDOWN_MULTI_SELECT("下拉多选","11","请填写选项中包含的文本,多填以中文逗号隔开"),
|
||||||
TREE_STRUCTURE_MULTI_SELECT("条款拆分","12","请填写选项中包含的文本,多填以逗号隔开"),
|
// 体系
|
||||||
|
TREE_STRUCTURE_MULTI_SELECT("条款拆分","12","请填写选项中包含的文本,多填以中文逗号隔开"),
|
||||||
LINK_INPUT_BOX("输入框(链接)","13","请填写选项中包含的文本"),
|
LINK_INPUT_BOX("输入框(链接)","13","请填写选项中包含的文本"),
|
||||||
YEAR_SELECT("条款拆分","14","请填写选项中包含的文本"),
|
YEAR_SELECT("条款拆分","14","请填写选项中包含的文本"),
|
||||||
|
// 零部件
|
||||||
TREE_STRUCTURE_SINGLE_SELECT("树形结构(单选)","15","请填写选项中包含的文本")
|
TREE_STRUCTURE_SINGLE_SELECT("树形结构(单选)","15","请填写选项中包含的文本")
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user