feat: 老法规文件导入逻辑
This commit is contained in:
@@ -179,5 +179,6 @@ public class FieldCommon {
|
|||||||
public static final String TRY_FLAG = "try_flag";
|
public static final String TRY_FLAG = "try_flag";
|
||||||
public static final String RELEASE_DATE = "release_date";
|
public static final String RELEASE_DATE = "release_date";
|
||||||
public static final String TRIAL_PERIOD = "trial_period";
|
public static final String TRIAL_PERIOD = "trial_period";
|
||||||
|
// 关联文件
|
||||||
|
public static final String ASSOCIATED_FILE = "associated_file";
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -98,4 +98,13 @@ public class OldSystemController {
|
|||||||
enterpriseStandardService.filterChineseStandardNo(file, response);
|
enterpriseStandardService.filterChineseStandardNo(file, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/importFileRelationExcel")
|
||||||
|
@AutoLog(value = "老法规系统-导入文件附件等关联关系")
|
||||||
|
@ApiOperation(value="老法规系统-导入文件附件等关联关系", notes="老法规系统-导入文件附件等关联关系", produces = "application/octet-stream")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
public void importFileRelationExcel(@RequestParam("file") MultipartFile file,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
enterpriseStandardService.importFileRelationExcel(file, response);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -56,9 +56,16 @@ public interface ILawsEnterpriseStandardService extends IService<LawsEnterpriseS
|
|||||||
void importOldESAuthDeptExcel(MultipartFile file, HttpServletResponse response);
|
void importOldESAuthDeptExcel(MultipartFile file, HttpServletResponse response);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g
|
* 过滤中文标准号
|
||||||
* @param file
|
* @param file
|
||||||
* @param response
|
* @param response
|
||||||
*/
|
*/
|
||||||
void filterChineseStandardNo(MultipartFile file, HttpServletResponse response) throws IOException;
|
void filterChineseStandardNo(MultipartFile file, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入文件关系Excel
|
||||||
|
* @param file
|
||||||
|
* @param response
|
||||||
|
*/
|
||||||
|
void importFileRelationExcel(MultipartFile file, HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
|||||||
+131
-5
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.jero.common.api.CommonAPI;
|
import com.jero.common.api.CommonAPI;
|
||||||
import com.jero.common.api.vo.ResultCommon;
|
import com.jero.common.api.vo.ResultCommon;
|
||||||
import com.jero.common.constant.CommonConstant;
|
import com.jero.common.constant.CommonConstant;
|
||||||
|
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||||
import com.jero.common.exception.JeroBootException;
|
import com.jero.common.exception.JeroBootException;
|
||||||
import com.jero.common.system.vo.SysDictItemCore;
|
import com.jero.common.system.vo.SysDictItemCore;
|
||||||
import com.jero.common.util.MessageUtils;
|
import com.jero.common.util.MessageUtils;
|
||||||
@@ -207,6 +208,11 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
o.getBzfl().contains("国外")).collect(Collectors.toList());
|
o.getBzfl().contains("国外")).collect(Collectors.toList());
|
||||||
log.info("外标相关数据条数:{}", fbDatalist.size());
|
log.info("外标相关数据条数:{}", fbDatalist.size());
|
||||||
|
|
||||||
|
// 过滤字段 根据标准号字段去重
|
||||||
|
fbDatalist = fbDatalist.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()
|
||||||
|
-> new TreeSet<>(Comparator.comparing(OldSystemImportDTO::getBzh))), ArrayList::new));
|
||||||
|
log.info("根据标准号去重后的外标相关数据条数:{}", fbDatalist.size());
|
||||||
|
|
||||||
// 找到所有人 并且用 姓名加工号做key
|
// 找到所有人 并且用 姓名加工号做key
|
||||||
Map<String, SysUser> allUserMap = sysUserService.list().stream().collect(Collectors.toMap(o -> o.getRealname() + o.getUsername(), o -> o));
|
Map<String, SysUser> allUserMap = sysUserService.list().stream().collect(Collectors.toMap(o -> o.getRealname() + o.getUsername(), o -> o));
|
||||||
|
|
||||||
@@ -691,6 +697,114 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void importFileRelationExcel(MultipartFile file, HttpServletResponse response) {
|
||||||
|
List<OldSystemImportDTO> errImportList = new ArrayList<>();
|
||||||
|
|
||||||
|
// 验证文件是否为压缩格式
|
||||||
|
if (!Objects.requireNonNull(file.getOriginalFilename()).contains("xls")) {
|
||||||
|
throw new JeroBootException("文件格式不正确,请上传Excel。");
|
||||||
|
}
|
||||||
|
ImportParams params = new ImportParams();
|
||||||
|
params.setTitleRows(0);
|
||||||
|
params.setNeedSave(true);
|
||||||
|
// 获取数据
|
||||||
|
List<OldSystemImportDTO> allDatalist = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取当前时间戳(毫秒)
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
@Cleanup
|
||||||
|
InputStream inputStream = file.getInputStream();
|
||||||
|
allDatalist = ExcelImportUtil.importExcel(inputStream, OldSystemImportDTO.class, params);
|
||||||
|
// 删除空行
|
||||||
|
allDatalist.removeIf(OldSystemImportDTO::isEmptyRow);
|
||||||
|
log.info("获取数据成功,数据条数:{}", allDatalist.size());
|
||||||
|
// 获取当前时间戳(毫秒)
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
// 计算执行时间(毫秒)
|
||||||
|
long executionTime = endTime - startTime;
|
||||||
|
log.info("数据转换执行时间:" + executionTime + " 毫秒");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("导入失败;{}", e.getMessage());
|
||||||
|
}
|
||||||
|
if (allDatalist == null) {
|
||||||
|
throw new JeroBootException("导入失败,数据为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询所有企标
|
||||||
|
LambdaQueryWrapper<LawsEnterpriseStandard> esWrapper = new LambdaQueryWrapper<>();
|
||||||
|
esWrapper.eq(LawsEnterpriseStandard::getDelFlag, YesOrNoEnum.NO.getValue());
|
||||||
|
List<LawsEnterpriseStandard> esList = this.list(esWrapper);
|
||||||
|
// 查询所有外标
|
||||||
|
LambdaQueryWrapper<LawsOverseasStandard> fbWrapper = new LambdaQueryWrapper<>();
|
||||||
|
fbWrapper.eq(LawsOverseasStandard::getDelFlag, YesOrNoEnum.NO.getValue());
|
||||||
|
List<LawsOverseasStandard> fbList = overseasStandardService.list(fbWrapper);
|
||||||
|
// 查询所有国标
|
||||||
|
LambdaQueryWrapper<LawsDomesticStandard> gbWrapper = new LambdaQueryWrapper<>();
|
||||||
|
gbWrapper.eq(LawsDomesticStandard::getDelFlag, YesOrNoEnum.NO.getValue());
|
||||||
|
List<LawsDomesticStandard> gbList = domesticStandardService.list(gbWrapper);
|
||||||
|
|
||||||
|
Map<String, String> standardMap = esList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getStandardNumber, LawsEnterpriseStandard::getId));
|
||||||
|
standardMap.putAll(fbList.stream().collect(Collectors.toMap(LawsOverseasStandard::getStandardNumber, LawsOverseasStandard::getId)));
|
||||||
|
standardMap.putAll(gbList.stream().collect(Collectors.toMap(LawsDomesticStandard::getStandardNumber, LawsDomesticStandard::getId)));
|
||||||
|
// 文件关联
|
||||||
|
List<OSSFile> ossFileList = new ArrayList<>();
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
// 转换数据
|
||||||
|
for (OldSystemImportDTO dto : allDatalist) {
|
||||||
|
try {
|
||||||
|
// 将标准号中的括号删除
|
||||||
|
String standardFileType = StandardSplitUtils.getStandardFileTypeByBZH(dto.getBzh());
|
||||||
|
String standardNo = StandardSplitUtils.extractStandardNumber(dto.getBzh());
|
||||||
|
String standardId = null;
|
||||||
|
for (String s : standardMap.keySet()) {
|
||||||
|
if (s.contains(standardNo)) {
|
||||||
|
standardId = standardMap.get(s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(standardId)) {
|
||||||
|
throw new JeroBootException("未找到该标准,标准编号:" + dto.getBzh());
|
||||||
|
}
|
||||||
|
// 根据文件路径获取文件Id
|
||||||
|
String originPath = dto.getSclj();
|
||||||
|
if (StrUtil.isNotBlank(originPath)) {
|
||||||
|
String filePath = this.getFilePath(originPath);
|
||||||
|
if (MinioUtil.doesObjectExist(filePath)) {
|
||||||
|
// 存入关系表
|
||||||
|
OSSFile ossFile = new OSSFile();
|
||||||
|
ossFile.setUrl(filePath);
|
||||||
|
ossFile.setStandardNo(standardNo);
|
||||||
|
ossFile.setFileName(FileUtil.getName(filePath));
|
||||||
|
ossFile.setStandardFileType(standardFileType);
|
||||||
|
ossFile.setStandardId(standardId);
|
||||||
|
ossFileList.add(ossFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("导入转换外标数据时发生错误:{}", e.getMessage());
|
||||||
|
log.error("错误数据:{}", dto.toString());
|
||||||
|
dto.setErrorInfo(e.getMessage());
|
||||||
|
errImportList.add(dto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (OSSFile ossfile : ossFileList) {
|
||||||
|
// 保存文件关联
|
||||||
|
ossFileService.save(ossfile);
|
||||||
|
}
|
||||||
|
log.info("文件关系覆盖导入完成");
|
||||||
|
// 获取当前时间戳(毫秒)
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
// 计算执行时间(毫秒)
|
||||||
|
long executionTime = endTime - startTime;
|
||||||
|
log.info("代码执行时间:" + executionTime + " 毫秒");
|
||||||
|
if (!errImportList.isEmpty()) {
|
||||||
|
this.exportWithExcel(response, errImportList, "OldSystemStandardErrorData.xls");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean containsChinese(String text) {
|
public boolean containsChinese(String text) {
|
||||||
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
|
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
|
||||||
Matcher matcher = pattern.matcher(text);
|
Matcher matcher = pattern.matcher(text);
|
||||||
@@ -724,6 +838,11 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
o.getBzfl().contains("行业标准")).collect(Collectors.toList());
|
o.getBzfl().contains("行业标准")).collect(Collectors.toList());
|
||||||
log.info("国标相关数据条数:{}", gbDatalist.size());
|
log.info("国标相关数据条数:{}", gbDatalist.size());
|
||||||
|
|
||||||
|
// 过滤字段 根据标准号字段去重
|
||||||
|
gbDatalist = gbDatalist.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()
|
||||||
|
-> new TreeSet<>(Comparator.comparing(OldSystemImportDTO::getBzh))), ArrayList::new));
|
||||||
|
log.info("根据标准号去重后的国标相关数据条数:{}", gbDatalist.size());
|
||||||
|
|
||||||
// 找到所有人 并且用 姓名加工号做key
|
// 找到所有人 并且用 姓名加工号做key
|
||||||
Map<String, SysUser> allUserMap = sysUserService.list().stream().collect(Collectors.toMap(o -> o.getRealname() + o.getUsername(), o -> o));
|
Map<String, SysUser> allUserMap = sysUserService.list().stream().collect(Collectors.toMap(o -> o.getRealname() + o.getUsername(), o -> o));
|
||||||
|
|
||||||
@@ -954,6 +1073,12 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void oldSysESImport(List<OldSystemImportDTO> esDatalist, List<OldSystemImportDTO> errImportList) {
|
private void oldSysESImport(List<OldSystemImportDTO> esDatalist, List<OldSystemImportDTO> errImportList) {
|
||||||
|
log.info("企标相关数据条数:{}", esDatalist.size());
|
||||||
|
// 过滤字段 根据标准号字段去重
|
||||||
|
esDatalist = esDatalist.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()
|
||||||
|
-> new TreeSet<>(Comparator.comparing(OldSystemImportDTO::getBzh))), ArrayList::new));
|
||||||
|
log.info("根据标准号去重后的企标相关数据条数:{}", esDatalist.size());
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
// 转换数据
|
// 转换数据
|
||||||
List<LawsEnterpriseStandard> esList = new ArrayList<>();
|
List<LawsEnterpriseStandard> esList = new ArrayList<>();
|
||||||
@@ -969,11 +1094,12 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
es.setStandardName(dto.getBzmc());
|
es.setStandardName(dto.getBzmc());
|
||||||
es.setStandardEnglishName(dto.getBzywmc());
|
es.setStandardEnglishName(dto.getBzywmc());
|
||||||
|
|
||||||
String fbrq = dto.getFbrq().trim();
|
// 发布日期和实施日期入库之前需要校验 为空或者不符合规则的不入库
|
||||||
String ssrq = dto.getSsrq().trim();
|
String fbrq = dto.getFbrq();
|
||||||
|
String ssrq = dto.getSsrq();
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||||
if (StrUtil.isNotBlank(fbrq)) {
|
if (StrUtil.isNotBlank(fbrq)) {
|
||||||
Date newDate = sdf.parse(fbrq);
|
Date newDate = sdf.parse(fbrq.trim());
|
||||||
if (newDate != null) {
|
if (newDate != null) {
|
||||||
es.setReleaseDate(newDate);
|
es.setReleaseDate(newDate);
|
||||||
} else {
|
} else {
|
||||||
@@ -981,7 +1107,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotBlank(ssrq)) {
|
if (StrUtil.isNotBlank(ssrq)) {
|
||||||
Date newDate = sdf.parse(ssrq);
|
Date newDate = sdf.parse(ssrq.trim());
|
||||||
if (newDate != null) {
|
if (newDate != null) {
|
||||||
es.setImplementationDate(newDate);
|
es.setImplementationDate(newDate);
|
||||||
} else {
|
} else {
|
||||||
@@ -989,7 +1115,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String standardState = dto.getBzzt();
|
String standardState = dto.getBzzt();
|
||||||
es.setStandardState(standardState.equals("现行有效") ? "8" : "9");
|
es.setStandardState(standardState.equals("现行有效") ? "6" : "7");
|
||||||
es.setGradeClassification(null);
|
es.setGradeClassification(null);
|
||||||
// 代替被代替特殊逻辑
|
// 代替被代替特殊逻辑
|
||||||
es.setSubstituteStandardNumber(dto.getTdbzh());
|
es.setSubstituteStandardNumber(dto.getTdbzh());
|
||||||
|
|||||||
+51
@@ -110,7 +110,58 @@ public class StandardSplitUtils {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取字符串中的中文
|
||||||
|
public static String extractChineseText(String input) {
|
||||||
|
// 使用正则表达式匹配中文字符
|
||||||
|
Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]+");
|
||||||
|
Matcher matcher = pattern.matcher(input);
|
||||||
|
|
||||||
|
// 用于存储提取的中文字符
|
||||||
|
StringBuilder chineseText = new StringBuilder();
|
||||||
|
|
||||||
|
// 遍历匹配结果并将中文字符追加到chineseText中
|
||||||
|
while (matcher.find()) {
|
||||||
|
chineseText.append(matcher.group());
|
||||||
|
}
|
||||||
|
|
||||||
|
return chineseText.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据标准号获取文件类型
|
||||||
|
public static String getStandardFileTypeByBZH(String bzh) {
|
||||||
|
String fileType = extractChineseText(bzh);
|
||||||
|
switch (fileType) {
|
||||||
|
case "附件":
|
||||||
|
return FieldCommon.ASSOCIATED_FILE;
|
||||||
|
case "发布稿":
|
||||||
|
return FieldCommon.FILE_PUBLISH_OF_ORIGINAL;
|
||||||
|
case "修改单":
|
||||||
|
return FieldCommon.FILE_MODIFICATION_LIST;
|
||||||
|
case "报批稿":
|
||||||
|
return FieldCommon.FILE_DRAFT_FOR_REVIEW;
|
||||||
|
case "草案":
|
||||||
|
return FieldCommon.FILE_DRAFT;
|
||||||
|
}
|
||||||
|
throw new RuntimeException("标准号" + bzh + "文件类型获取失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从带有文件名的字符串中提取标准号
|
||||||
|
public static String extractStandardNumber(String bzh) {
|
||||||
|
// 使用正则表达式匹配标准号部分
|
||||||
|
Pattern pattern = Pattern.compile("[A-Z0-9\\s-]+");
|
||||||
|
Matcher matcher = pattern.matcher(bzh);
|
||||||
|
|
||||||
|
// 用于存储提取的标准号部分
|
||||||
|
StringBuilder standardNumber = new StringBuilder();
|
||||||
|
|
||||||
|
// 遍历匹配结果并将标准号部分追加到standardNumber中
|
||||||
|
if (matcher.find()) {
|
||||||
|
standardNumber.append(matcher.group().trim());
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(standardNumber.toString())) {
|
||||||
|
// 如果没有匹配项,返回空字符串
|
||||||
|
throw new RuntimeException("标准号" + bzh + "获取标准号失败");
|
||||||
|
}
|
||||||
|
return standardNumber.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user