feat: 老法规外标导入逻辑
This commit is contained in:
@@ -24,6 +24,8 @@ import javax.annotation.Resource;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -350,4 +352,11 @@ public class ExcelUtils {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 判断是否有中文字符
|
||||
public static boolean containsChinese(String text) {
|
||||
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
return matcher.find();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-5
@@ -1,5 +1,6 @@
|
||||
package com.jero.modules.laws.enterprise.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Data;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
@@ -51,11 +52,11 @@ public class OldSystemImportDTO {
|
||||
@Excel(name = "ZTC", width = 15, orderNum = "12")
|
||||
private String ztc;
|
||||
|
||||
@Excel(name = "FBRQ", width = 15, orderNum = "13", format = "yyyyMMdd")
|
||||
private Date fbrq;
|
||||
@Excel(name = "FBRQ", width = 15, orderNum = "13")
|
||||
private String fbrq;
|
||||
|
||||
@Excel(name = "SSRQ", width = 15, orderNum = "14", format = "yyyyMMdd")
|
||||
private Date ssrq;
|
||||
@Excel(name = "SSRQ", width = 15, orderNum = "14")
|
||||
private String ssrq;
|
||||
|
||||
@Excel(name = "TY", width = 15, orderNum = "15")
|
||||
private String ty;
|
||||
@@ -168,12 +169,16 @@ public class OldSystemImportDTO {
|
||||
@Excel(name = "BZCOUNTRY", width = 15, orderNum = "51")
|
||||
private String bzcountry;
|
||||
|
||||
@Excel(name = "错误信息", width = 35, orderNum = "52")
|
||||
@TableField(exist = false)
|
||||
private String errorInfo;
|
||||
|
||||
/**
|
||||
* 判断是否是空行
|
||||
* @return 如果所有字段都为null或空字符串,返回true,否则返回false
|
||||
*/
|
||||
public boolean isEmptyRow() {
|
||||
return id == null && bzh == null && status == null && cybzh == null
|
||||
return id == null && status == null && cybzh == null
|
||||
&& bzmc == null && bzywmc == null && bzfl == null && bzyytype == null
|
||||
&& bzdjtype == null && bzlbtype == null && bzlcgj == null && bzsydw == null
|
||||
&& ztc == null && fbrq == null && ssrq == null && ty == null
|
||||
|
||||
+13
-3
@@ -23,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
@ApiSupport(order = 10101)
|
||||
@Api(tags="老法规系统")
|
||||
@@ -52,11 +53,11 @@ public class OldSystemController {
|
||||
private ILawsEnterpriseStandardService enterpriseStandardService;
|
||||
|
||||
@PostMapping("/importOldSystemExcel")
|
||||
@AutoLog(value = "老法规系统-老法规企标国标数据导入")
|
||||
@ApiOperation(value="老法规系统-老法规企标国标数据导入", notes="老法规系统-老法规企标国标数据导入", produces = "application/octet-stream")
|
||||
@AutoLog(value = "老法规系统-老法规企标国标外标数据导入")
|
||||
@ApiOperation(value="老法规系统-老法规企标国标外标数据导入", notes="老法规系统-老法规企标国标外标数据导入", produces = "application/octet-stream")
|
||||
@ApiOperationSupport(order = 2)
|
||||
public void importOldSystemESZip(@RequestParam("file") MultipartFile file,
|
||||
@ApiParam(value = "0不导入 1导入企标 2导入国标 3一起导入", required = true)
|
||||
@ApiParam(value = "0不导入 1导入企标 2导入国标 3外标", required = true)
|
||||
@RequestParam("type") String type,
|
||||
HttpServletResponse response) {
|
||||
enterpriseStandardService.importExcelOldSystem(file, type, response);
|
||||
@@ -88,4 +89,13 @@ public class OldSystemController {
|
||||
enterpriseStandardService.importOldESAuthDeptExcel(file, response);
|
||||
}
|
||||
|
||||
@PostMapping("/filterChineseStandardNo")
|
||||
@AutoLog(value = "老法规系统-过滤带中文的标准号")
|
||||
@ApiOperation(value="老法规系统-过滤带中文的标准号", notes="老法规系统-过滤带中文的标准号", produces = "application/octet-stream")
|
||||
@ApiOperationSupport(order = 6)
|
||||
public void filterChineseStandardNo(@RequestParam("file") MultipartFile file,
|
||||
HttpServletResponse response) throws IOException {
|
||||
enterpriseStandardService.filterChineseStandardNo(file, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jero.modules.laws.oldSystem.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -42,6 +43,7 @@ public class ESAuthDept {
|
||||
|
||||
@Excel(name = "错误信息", width = 35)
|
||||
@ApiModelProperty(value = "错误信息")
|
||||
@TableField(exist = false)
|
||||
private String errorInfo;
|
||||
|
||||
public boolean isEmptyRow() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jero.modules.laws.oldSystem.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -43,6 +44,7 @@ public class ESAuthUser {
|
||||
|
||||
@Excel(name = "错误信息", width = 35, orderNum = "7")
|
||||
@ApiModelProperty(value = "错误信息")
|
||||
@TableField(exist = false)
|
||||
private String errorInfo;
|
||||
|
||||
public boolean isEmptyRow() {
|
||||
|
||||
+1
@@ -80,6 +80,7 @@ public class OldSystemDepartRelation implements Serializable {
|
||||
*/
|
||||
@Excel(name = "错误信息", width = 35)
|
||||
@ApiModelProperty(value = "错误信息")
|
||||
@TableField(exist = false)
|
||||
private String errorInfo;
|
||||
|
||||
@TableField(exist = false)
|
||||
|
||||
+3
@@ -181,4 +181,7 @@ public class LawsOverseasStandard implements Serializable {
|
||||
@Excel(name = "草案", width = 15)
|
||||
@ApiModelProperty(value = "草案")
|
||||
private java.lang.String draft;
|
||||
/**标准号*/
|
||||
@ApiModelProperty(value = "标准号")
|
||||
private java.lang.String standardNumberTemp;
|
||||
}
|
||||
|
||||
+8
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
@@ -53,4 +54,11 @@ public interface ILawsEnterpriseStandardService extends IService<LawsEnterpriseS
|
||||
* @return
|
||||
*/
|
||||
void importOldESAuthDeptExcel(MultipartFile file, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* g
|
||||
* @param file
|
||||
* @param response
|
||||
*/
|
||||
void filterChineseStandardNo(MultipartFile file, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
|
||||
+408
-108
@@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.api.CommonAPI;
|
||||
import com.jero.common.api.vo.ResultCommon;
|
||||
@@ -30,10 +31,13 @@ import com.jero.modules.laws.oldSystem.entity.OldSystemDepartRelation;
|
||||
import com.jero.modules.laws.oldSystem.service.OldSystemDepartRelationService;
|
||||
import com.jero.modules.laws.standard.entity.LawsDomesticStandard;
|
||||
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
|
||||
import com.jero.modules.laws.standard.entity.LawsOverseasStandard;
|
||||
import com.jero.modules.laws.standard.service.ILawsDomesticStandardService;
|
||||
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
|
||||
import com.jero.modules.laws.standard.mapper.LawsEnterpriseStandardMapper;
|
||||
import com.jero.modules.laws.standard.service.ILawsOverseasStandardService;
|
||||
import com.jero.modules.laws.standard.service.ILawsReplacedStandardService;
|
||||
import com.jero.modules.laws.standard.util.StandardSplitUtils;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.modules.system.entity.SysDepart;
|
||||
@@ -42,10 +46,13 @@ import com.jero.modules.system.service.ISysDepartService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import io.minio.errors.MinioException;
|
||||
import lombok.Cleanup;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
@@ -61,6 +68,8 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -117,10 +126,13 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
|
||||
@Resource
|
||||
private ISysDepartService sysDepartService;
|
||||
|
||||
|
||||
@Resource
|
||||
private OldSystemDepartRelationService oldSystemDepartRelationService;
|
||||
|
||||
@Resource
|
||||
private ILawsOverseasStandardService overseasStandardService;
|
||||
|
||||
@Override
|
||||
public LawsEnterpriseStandard queryByStandardNumber(String standardNumber) {
|
||||
if (StringUtils.isBlank(standardNumber)) {
|
||||
@@ -146,9 +158,6 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
params.setNeedSave(true);
|
||||
// 获取数据
|
||||
List<OldSystemImportDTO> allDatalist = null;
|
||||
List<OldSystemImportDTO> esDatalist = new ArrayList<>();
|
||||
List<OldSystemImportDTO> gbDatalist = new ArrayList<>();
|
||||
List<OldSystemImportDTO> fbDatalist = new ArrayList<>();
|
||||
|
||||
try {
|
||||
// 获取当前时间戳(毫秒)
|
||||
@@ -157,27 +166,8 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
InputStream inputStream = file.getInputStream();
|
||||
allDatalist = ExcelImportUtil.importExcel(inputStream, OldSystemImportDTO.class, params);
|
||||
// 删除空行
|
||||
for (int i = 0; i < allDatalist.size(); i++) {
|
||||
OldSystemImportDTO oldSystemImportDTO = allDatalist.get(i);
|
||||
if (oldSystemImportDTO.isEmptyRow()) {
|
||||
allDatalist.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
// 区分数据
|
||||
for (OldSystemImportDTO oldSystemImportDTO : allDatalist) {
|
||||
if (oldSystemImportDTO.getBzfl().startsWith("企业标准")) {
|
||||
esDatalist.add(oldSystemImportDTO);
|
||||
} else if (oldSystemImportDTO.getBzfl().startsWith("国家标准")) {
|
||||
gbDatalist.add(oldSystemImportDTO);
|
||||
} else {
|
||||
fbDatalist.add(oldSystemImportDTO);
|
||||
}
|
||||
}
|
||||
allDatalist.removeIf(OldSystemImportDTO::isEmptyRow);
|
||||
log.info("获取数据成功,数据条数:{}", allDatalist.size());
|
||||
log.info("获取数据成功,企标数据条数:{}", esDatalist.size());
|
||||
log.info("获取数据成功,国标数据条数:{}", gbDatalist.size());
|
||||
log.info("获取数据成功,其他数据条数:{}", fbDatalist.size());
|
||||
// 获取当前时间戳(毫秒)
|
||||
long endTime = System.currentTimeMillis();
|
||||
// 计算执行时间(毫秒)
|
||||
@@ -186,47 +176,222 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
} catch (Exception e) {
|
||||
log.error("导入失败;{}", e.getMessage());
|
||||
}
|
||||
if (allDatalist == null) {
|
||||
throw new JeroBootException("导入失败,数据为空");
|
||||
}
|
||||
// 导入企标
|
||||
switch (type) {
|
||||
case "0":
|
||||
break;
|
||||
case "1":
|
||||
// 判断是否需要跳过
|
||||
if (esDatalist.isEmpty()) {
|
||||
log.info("企标数据为空,跳过导入");
|
||||
} else {
|
||||
this.oldSysESImport(esDatalist, errImportList);
|
||||
}
|
||||
// 导入企标
|
||||
this.oldSysESImport(allDatalist, errImportList);
|
||||
break;
|
||||
case "2":
|
||||
// 导入国标
|
||||
// 判断是否需要跳过
|
||||
if (gbDatalist.isEmpty()) {
|
||||
log.info("国标数据为空,跳过导入");
|
||||
} else {
|
||||
this.oldSysGBImport(gbDatalist, errImportList);
|
||||
}
|
||||
this.oldSysGBImport(allDatalist, errImportList);
|
||||
break;
|
||||
case "3":
|
||||
// 判断是否需要跳过
|
||||
if (esDatalist.isEmpty()) {
|
||||
log.info("企标数据为空,跳过导入");
|
||||
} else {
|
||||
this.oldSysESImport(esDatalist, errImportList);
|
||||
}
|
||||
// 导入国标
|
||||
// 判断是否需要跳过
|
||||
if (gbDatalist.isEmpty()) {
|
||||
log.info("国标数据为空,跳过导入");
|
||||
} else {
|
||||
this.oldSysGBImport(gbDatalist, errImportList);
|
||||
}
|
||||
// 导入外标
|
||||
this.oldSysFBImport(allDatalist, errImportList);
|
||||
|
||||
}
|
||||
if (!errImportList.isEmpty()) {
|
||||
this.exportWithExcel(response, errImportList, "OldSystemStandardErrorData.xls");
|
||||
}
|
||||
}
|
||||
|
||||
private void oldSysFBImport(List<OldSystemImportDTO> allDatalist, List<OldSystemImportDTO> errImportList) {
|
||||
List<OldSystemImportDTO> fbDatalist = allDatalist.stream().filter(o -> o.getBzfl().contains("ISO") ||
|
||||
o.getBzfl().contains("引进") ||
|
||||
o.getBzfl().contains("国外")).collect(Collectors.toList());
|
||||
log.info("外标相关数据条数:{}", fbDatalist.size());
|
||||
|
||||
// 找到所有人 并且用 姓名加工号做key
|
||||
Map<String, SysUser> allUserMap = sysUserService.list().stream().collect(Collectors.toMap(o -> o.getRealname() + o.getUsername(), o -> o));
|
||||
|
||||
// 现所有部门
|
||||
List<SysDepart> curDepartList = departService.list();
|
||||
Map<String, List<SysDepart>> curDeptMap = curDepartList.stream().collect(Collectors.groupingBy(SysDepart::getDepartName));
|
||||
|
||||
// 部门关系列表
|
||||
List<OldSystemDepartRelation> list = oldDeptService.list();
|
||||
list = list.stream().filter(o -> StrUtil.isNotBlank(o.getOldOrgName())).collect(Collectors.toList());
|
||||
Map<String, List<OldSystemDepartRelation>> oldDeptMap = list.stream().collect(Collectors.groupingBy(OldSystemDepartRelation::getOldOrgName));
|
||||
|
||||
// 文件关联
|
||||
List<OSSFile> ossFileList = new ArrayList<>();
|
||||
long startTime = System.currentTimeMillis();
|
||||
// 转换数据
|
||||
List<LawsOverseasStandard> fbList = new ArrayList<>();
|
||||
for (OldSystemImportDTO dto : fbDatalist) {
|
||||
try {
|
||||
LawsOverseasStandard fb = new LawsOverseasStandard();
|
||||
|
||||
// 先将标准号中的中文横杠替换为英文横杠
|
||||
String newBzh = dto.getBzh().replace("—", "-");
|
||||
fb.setStandardNumber(newBzh);
|
||||
String cybzh = dto.getCybzh();
|
||||
// 采用标准号为空跳过拆分
|
||||
if (StrUtil.isNotBlank(cybzh)){
|
||||
// 执行拆分
|
||||
Map<String, String> map = StandardSplitUtils.simpleSplitStandardNumber(newBzh, cybzh);
|
||||
fb.setStandardClass(map.get(FieldCommon.STANDARD_CLASS));
|
||||
fb.setStandardNumberTemp(map.get(FieldCommon.STANDARD_NUMBER_TEMP));
|
||||
fb.setYearNumber(map.get(FieldCommon.YEAR_NUMBER));
|
||||
}
|
||||
|
||||
fb.setStandardName(dto.getBzmc());
|
||||
fb.setStandardEnglishName(dto.getBzywmc());
|
||||
|
||||
// 发布日期和实施日期入库之前需要校验 为空或者不符合规则的不入库
|
||||
String fbrq = dto.getFbrq();
|
||||
String ssrq = dto.getSsrq();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
if (StrUtil.isNotBlank(fbrq)) {
|
||||
Date newDate = sdf.parse(fbrq.trim());
|
||||
if (newDate != null) {
|
||||
fb.setReleaseDate(newDate);
|
||||
} else {
|
||||
throw new JeroBootException("发布日期格式不正确,标准编号:" + dto.getBzh());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(ssrq)) {
|
||||
Date newDate = sdf.parse(ssrq.trim());
|
||||
if (newDate != null) {
|
||||
fb.setImplementationDate(newDate);
|
||||
} else {
|
||||
throw new JeroBootException("实施日期格式不正确,标准编号:" + dto.getBzh());
|
||||
}
|
||||
}
|
||||
|
||||
String standardState = dto.getBzzt();
|
||||
fb.setStandardState(standardState.equals("现行有效") ? "6" : "7");
|
||||
// 代替被代替特殊逻辑
|
||||
fb.setSubstituteStandardNumber(dto.getTdbzh());
|
||||
fb.setReplacedByStandardNumber(dto.getBtdbzh());
|
||||
|
||||
// 责任部门暂不导入
|
||||
// String zrbm = dto.getZrbm();
|
||||
// if (oldDeptMap.get(zrbm) != null && oldDeptMap.get(zrbm).get(0) != null) {
|
||||
// String curOrgName = oldDeptMap.get(zrbm).get(0).getCurOrgName();
|
||||
// if (StrUtil.isNotBlank(curOrgName)) {
|
||||
// List<SysDepart> departList = curDeptMap.get(curOrgName);
|
||||
// if (departList.size() != 0) {
|
||||
// gb.setResponsibleDepartment(departList.get(0).getId());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
String zrr = dto.getZrr();
|
||||
String zrrid = dto.getZrrid();
|
||||
if (StrUtil.isNotBlank(zrr) && StrUtil.isNotBlank(zrrid)) {
|
||||
SysUser sysUser = allUserMap.get(zrr + zrrid);
|
||||
if (sysUser != null) {
|
||||
fb.setResponsibleDepartmentUser(sysUser.getId());
|
||||
} else {
|
||||
throw new JeroBootException("未找到责任人,姓名:" + zrr + ",工号:" + zrrid + ",标准编号:" + 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(dto.getBzh());
|
||||
// ossFile.setFileName(FileUtil.getName(filePath));
|
||||
// ossFile.setStandardFileType("publish_of_original");
|
||||
// ossFileList.add(ossFile);
|
||||
// }
|
||||
// }
|
||||
fbList.add(fb);
|
||||
} catch (Exception e) {
|
||||
log.error("导入转换外标数据时发生错误:{}", e.getMessage());
|
||||
log.error("错误数据:{}", dto.toString());
|
||||
dto.setErrorInfo(e.getMessage());
|
||||
errImportList.add(dto);
|
||||
}
|
||||
}
|
||||
// 保存数据
|
||||
// 1. 首先获取所有现有的国标标准号
|
||||
List<LawsOverseasStandard> existingEntities = overseasStandardService.list();
|
||||
|
||||
// 2. 创建一个Map,用于快速查找是否存在相同的标准号
|
||||
Map<String, LawsOverseasStandard> standardNumberToEntityMap = new HashMap<>();
|
||||
for (LawsOverseasStandard existingEntity : existingEntities) {
|
||||
standardNumberToEntityMap.put(existingEntity.getStandardNumber(), existingEntity);
|
||||
}
|
||||
|
||||
// 3. 将文件关系列表转为Map,用于快速查找
|
||||
// Map<String, List<OSSFile>> standardNumberToFileMap = ossFileList.stream().collect(Collectors.groupingBy(OSSFile::getStandardNo));
|
||||
|
||||
// 4. 遍历待保存或更新的列表,设置ID
|
||||
StringBuilder oldIds = new StringBuilder();
|
||||
StringBuilder newIds = new StringBuilder();
|
||||
for (LawsOverseasStandard entity : fbList) {
|
||||
LawsOverseasStandard existingEntity = standardNumberToEntityMap.get(entity.getStandardNumber());
|
||||
if (existingEntity != null) {
|
||||
// 如果存在,则执行更新操作
|
||||
// 删除替代
|
||||
lawsReplacedStandardService.removeRelation(existingEntity.getStandardNumber(), 1);
|
||||
// 删除文件关联
|
||||
LambdaUpdateWrapper<OSSFile> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.eq(OSSFile::getStandardId, existingEntity.getId());
|
||||
ossFileService.remove(wrapper);
|
||||
// 拼接老id
|
||||
oldIds.append(existingEntity.getId()).append(",");
|
||||
|
||||
entity.setId(existingEntity.getId());
|
||||
}
|
||||
String tdbzh = entity.getSubstituteStandardNumber();
|
||||
String btdbzh = entity.getReplacedByStandardNumber();
|
||||
// 代替标准号
|
||||
if (StringUtils.isNotBlank(tdbzh)) {
|
||||
lawsReplacedStandardService.addRelation(btdbzh, tdbzh, 1);
|
||||
}
|
||||
// 被代替标准号
|
||||
if (StringUtils.isNotBlank(btdbzh)) {
|
||||
List<String> replaceCodeList = Arrays.asList(btdbzh.split(";"));
|
||||
replaceCodeList.forEach(replaceCode -> {
|
||||
lawsReplacedStandardService.addRelation(replaceCode, btdbzh, 1);
|
||||
});
|
||||
}
|
||||
entity.setSubstituteStandardNumber(null);
|
||||
entity.setReplacedByStandardNumber(null);
|
||||
// 构建updateWrapper 将其余字段全部设为null
|
||||
|
||||
overseasStandardService.saveOrUpdate(entity);
|
||||
|
||||
String standardId = entity.getId();
|
||||
// 保存文件关联
|
||||
// List<OSSFile> ossFiles = standardNumberToFileMap.get(entity.getStandardNumber());
|
||||
// if (ossFiles != null && !ossFiles.isEmpty()) {
|
||||
// OSSFile ossFile = ossFiles.get(0);
|
||||
// ossFile.setStandardId(standardId);
|
||||
// ossFileService.save(ossFile);
|
||||
// }
|
||||
}
|
||||
log.info("老法规外标覆盖导入完成");
|
||||
// 获取当前时间戳(毫秒)
|
||||
long endTime = System.currentTimeMillis();
|
||||
// 计算执行时间(毫秒)
|
||||
long executionTime = endTime - startTime;
|
||||
log.info("代码执行时间:" + executionTime + " 毫秒");
|
||||
// es中删除数据
|
||||
// if (oldIds.length() > 0) {
|
||||
// oldIds = new StringBuilder(oldIds.substring(0, oldIds.length() - 1));
|
||||
// lawsHomeSearchService.updateEsData(LawsHomeSearchCommon.LAWS_OVERSEAS_STANDARD, oldIds.toString(), LawsHomeSearchCommon.LAWS_ES_DELETE);
|
||||
// }
|
||||
// // 同步es数据库
|
||||
// if (newIds.length() > 0) {
|
||||
// newIds = new StringBuilder(newIds.substring(0, newIds.length() - 1));
|
||||
// lawsHomeSearchService.updateEsData(LawsHomeSearchCommon.LAWS_OVERSEAS_STANDARD, newIds.toString(), LawsHomeSearchCommon.LAWS_ES_ADD);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importOldESAuthAllExcel(MultipartFile file, HttpServletResponse response) {
|
||||
List<ESAuthAll> errImportList = new ArrayList<>();
|
||||
@@ -247,13 +412,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
InputStream inputStream = file.getInputStream();
|
||||
datalist = ExcelImportUtil.importExcel(inputStream, ESAuthAll.class, params);
|
||||
// 删除空行
|
||||
for (int i = 0; i < datalist.size(); i++) {
|
||||
ESAuthAll data = datalist.get(i);
|
||||
if (data.isEmptyRow()) {
|
||||
datalist.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
datalist.removeIf(ESAuthAll::isEmptyRow);
|
||||
// 只取用企标数据
|
||||
// 区分数据
|
||||
log.info("获取数据成功,总数据条数:{}", datalist.size());
|
||||
@@ -318,13 +477,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
InputStream inputStream = file.getInputStream();
|
||||
datalist = ExcelImportUtil.importExcel(inputStream, ESAuthUser.class, params);
|
||||
// 删除空行
|
||||
for (int i = 0; i < datalist.size(); i++) {
|
||||
ESAuthUser data = datalist.get(i);
|
||||
if (data.isEmptyRow()) {
|
||||
datalist.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
datalist.removeIf(ESAuthUser::isEmptyRow);
|
||||
// 只取用企标数据
|
||||
// 区分数据
|
||||
log.info("获取数据成功,总数据条数:{}", datalist.size());
|
||||
@@ -416,13 +569,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
InputStream inputStream = file.getInputStream();
|
||||
datalist = ExcelImportUtil.importExcel(inputStream, ESAuthDept.class, params);
|
||||
// 删除空行
|
||||
for (int i = 0; i < datalist.size(); i++) {
|
||||
ESAuthDept data = datalist.get(i);
|
||||
if (data.isEmptyRow()) {
|
||||
datalist.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
datalist.removeIf(ESAuthDept::isEmptyRow);
|
||||
// 区分数据
|
||||
log.info("获取数据成功,总数据条数:{}", datalist.size());
|
||||
// 删选标准分类不为空且是企标的数据
|
||||
@@ -439,7 +586,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
LambdaQueryWrapper<LawsEnterpriseStandard> esWrapper = new LambdaQueryWrapper<>();
|
||||
List<LawsEnterpriseStandard> esList = this.list(esWrapper.isNotNull(LawsEnterpriseStandard::getOldSystemId));
|
||||
Map<String, LawsEnterpriseStandard> esMap = esList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getOldSystemId, o -> o));
|
||||
|
||||
|
||||
// 获取所有有关联的新部门
|
||||
LambdaQueryWrapper<SysDepart> sysDeptWrapper = new LambdaQueryWrapper<>();
|
||||
sysDeptWrapper.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
|
||||
@@ -485,6 +632,71 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
log.info("企标部门权限导入结束");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void filterChineseStandardNo(MultipartFile file, HttpServletResponse response) throws IOException {
|
||||
List<OldSystemImportDTO> chineseStandardNo = 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> datalist = new ArrayList<>();
|
||||
List<OldSystemImportDTO> emptyData = new ArrayList<>();
|
||||
List<OldSystemImportDTO> chineseData = new ArrayList<>();
|
||||
try {
|
||||
// 获取当前时间戳(毫秒)
|
||||
long startTime = System.currentTimeMillis();
|
||||
params.setSheetNum(1);
|
||||
try (InputStream newInputStream = file.getInputStream()) {
|
||||
datalist = ExcelImportUtil.importExcel(newInputStream, OldSystemImportDTO.class, params);
|
||||
}
|
||||
|
||||
// 空行数据
|
||||
emptyData = datalist.stream().filter(OldSystemImportDTO::isEmptyRow).collect(Collectors.toList());
|
||||
// 删除空行之后的数据
|
||||
datalist.removeIf(OldSystemImportDTO::isEmptyRow);
|
||||
|
||||
datalist = datalist.stream().filter(data -> !this.containsChinese(data.getBzh())).collect(Collectors.toList());
|
||||
// 剔除不导入的数据 国家标准/GJB国家军用标准
|
||||
// datalist = datalist.stream().filter(data -> !data.getBzfl().equals("国家标准/GJB国家军用标准")).collect(Collectors.toList());
|
||||
// // 删除政策 文件 之后的数据
|
||||
// datalist = datalist.stream().filter(data -> !this.containsChinese(data.getBzh())).collect(Collectors.toList());
|
||||
//// // 只取用国标数据
|
||||
//// datalist = datalist.stream().filter(data -> data.getBzfl().startsWith("国家标准")).collect(Collectors.toList());
|
||||
//// // 只取用外标数据
|
||||
// datalist = datalist.stream().filter(data -> data.getBzfl().contains("国外") || data.getBzfl().contains("ISO"))
|
||||
// .collect(Collectors.toList());
|
||||
|
||||
|
||||
// 区分数据
|
||||
log.info("获取数据成功,总数据条数:{}", datalist.size());
|
||||
// 删选标准分类不为空且是企标的数据
|
||||
|
||||
log.info("企标相关数据条数:{}", datalist.size());
|
||||
// 获取当前时间戳(毫秒)
|
||||
long endTime = System.currentTimeMillis();
|
||||
// 计算执行时间(毫秒)
|
||||
long executionTime = endTime - startTime;
|
||||
log.info("数据转换执行时间:" + executionTime + " 毫秒");
|
||||
} catch (Exception e) {
|
||||
log.error("导入失败;{}", e.getMessage());
|
||||
}
|
||||
this.exportWithExcel(response, datalist, "needImportAllData.xls");
|
||||
if (false) {
|
||||
this.exportWithExcel(response, chineseStandardNo, "ChineseStandardNo.xls");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsChinese(String text) {
|
||||
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
return matcher.find();
|
||||
}
|
||||
|
||||
public <T> void exportWithExcel(HttpServletResponse response, List<T> dtoList, String fileName) {
|
||||
try {
|
||||
// 设置导出参数
|
||||
@@ -504,8 +716,12 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
}
|
||||
}
|
||||
|
||||
private void oldSysGBImport(List<OldSystemImportDTO> allDatalist, List<OldSystemImportDTO> errImportList) {
|
||||
List<OldSystemImportDTO> gbDatalist = allDatalist.stream().filter(o -> o.getBzfl().contains("国家") ||
|
||||
o.getBzfl().contains("地方") ||
|
||||
o.getBzfl().contains("行业")).collect(Collectors.toList());
|
||||
log.info("国标相关数据条数:{}", gbDatalist.size());
|
||||
|
||||
private void oldSysGBImport(List<OldSystemImportDTO> gbDatalist, List<OldSystemImportDTO> errImportList) {
|
||||
// 找到所有人 并且用 姓名加工号做key
|
||||
Map<String, SysUser> allUserMap = sysUserService.list().stream().collect(Collectors.toMap(o -> o.getRealname() + o.getUsername(), o -> o));
|
||||
|
||||
@@ -526,27 +742,40 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
for (OldSystemImportDTO dto : gbDatalist) {
|
||||
try {
|
||||
LawsDomesticStandard gb = new LawsDomesticStandard();
|
||||
gb.setId(dto.getId());
|
||||
gb.setStandardNumber(dto.getBzh());
|
||||
|
||||
String[] parts = dto.getBzh().split("[-\\s]"); // 使用空格或破折号作为分隔符
|
||||
if (parts.length < 3) {
|
||||
parts = dto.getBzh().split("[—\\s]"); // 使用空格或破折号作为分隔符
|
||||
}
|
||||
// 标准类别
|
||||
gb.setStandardClass(parts[0]);
|
||||
// 标准号
|
||||
gb.setStandardNumberTemp(parts[1]);
|
||||
// 年代号
|
||||
gb.setYearNumber(parts[2]);
|
||||
// 先将标准号中的中文横杠替换为英文横杠
|
||||
String newBzh = dto.getBzh().replace("—", "-");
|
||||
gb.setStandardNumber(newBzh);
|
||||
// 执行拆分
|
||||
Map<String, String> map = StandardSplitUtils.splitDomesticStandardNumber(newBzh);
|
||||
gb.setStandardClass(map.get(FieldCommon.STANDARD_CLASS));
|
||||
gb.setStandardNumberTemp(map.get(FieldCommon.STANDARD_NUMBER_TEMP));
|
||||
gb.setYearNumber(map.get(FieldCommon.YEAR_NUMBER));
|
||||
|
||||
gb.setStandardName(dto.getBzmc());
|
||||
|
||||
gb.setStandardEnglishName(dto.getBzywmc());
|
||||
|
||||
// 发布日期和实施日期入库之前需要校验 为空或者不符合规则的不入库
|
||||
gb.setReleaseDate(dto.getFbrq());
|
||||
gb.setImplementationDate(dto.getSsrq());
|
||||
String fbrq = dto.getFbrq();
|
||||
String ssrq = dto.getSsrq();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
if (StrUtil.isNotBlank(fbrq)) {
|
||||
Date newDate = sdf.parse(fbrq.trim());
|
||||
if (newDate != null) {
|
||||
gb.setReleaseDate(newDate);
|
||||
} else {
|
||||
throw new JeroBootException("发布日期格式不正确,标准编号:" + dto.getBzh());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(ssrq)) {
|
||||
Date newDate = sdf.parse(ssrq.trim());
|
||||
if (newDate != null) {
|
||||
gb.setImplementationDate(newDate);
|
||||
} else {
|
||||
throw new JeroBootException("实施日期格式不正确,标准编号:" + dto.getBzh());
|
||||
}
|
||||
}
|
||||
|
||||
String standardState = dto.getBzzt();
|
||||
gb.setStandardState(standardState.equals("现行有效") ? "6" : "7");
|
||||
@@ -554,20 +783,26 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
gb.setSubstituteStandardNumber(dto.getTdbzh());
|
||||
gb.setReplacedByStandardNumber(dto.getBtdbzh());
|
||||
|
||||
String zrbm = dto.getZrbm();
|
||||
if (oldDeptMap.get(zrbm) != null && oldDeptMap.get(zrbm).get(0) != null) {
|
||||
String curOrgName = oldDeptMap.get(zrbm).get(0).getCurOrgName();
|
||||
if (StrUtil.isNotBlank(curOrgName)) {
|
||||
List<SysDepart> departList = curDeptMap.get(curOrgName);
|
||||
if (departList.size() != 0) {
|
||||
gb.setResponsibleDepartment(departList.get(0).getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 责任部门暂不导入
|
||||
// String zrbm = dto.getZrbm();
|
||||
// if (oldDeptMap.get(zrbm) != null && oldDeptMap.get(zrbm).get(0) != null) {
|
||||
// String curOrgName = oldDeptMap.get(zrbm).get(0).getCurOrgName();
|
||||
// if (StrUtil.isNotBlank(curOrgName)) {
|
||||
// List<SysDepart> departList = curDeptMap.get(curOrgName);
|
||||
// if (departList.size() != 0) {
|
||||
// gb.setResponsibleDepartment(departList.get(0).getId());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
String zrr = dto.getZrr();
|
||||
String zrrid = dto.getZrrid();
|
||||
if (StrUtil.isNotBlank(zrr) && StrUtil.isNotBlank(zrrid)) {
|
||||
gb.setResponsibleDepartmentUser(allUserMap.get(zrr + zrrid).getId());
|
||||
SysUser sysUser = allUserMap.get(zrr + zrrid);
|
||||
if (sysUser != null) {
|
||||
gb.setResponsibleDepartmentUser(sysUser.getId());
|
||||
} else {
|
||||
throw new JeroBootException("未找到责任人,姓名:" + zrr + ",工号:" + zrrid + ",标准编号:" + dto.getBzh());
|
||||
}
|
||||
}
|
||||
|
||||
// 根据文件路径获取文件Id
|
||||
@@ -584,15 +819,17 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
// ossFileList.add(ossFile);
|
||||
// }
|
||||
// }
|
||||
gb.setIsAsmsImport("0");
|
||||
gbList.add(gb);
|
||||
} catch (Exception e) {
|
||||
log.error("导入转换国标数据时发生错误:{}", e.getMessage());
|
||||
log.error("错误数据:{}", dto.toString());
|
||||
dto.setErrorInfo(e.getMessage());
|
||||
errImportList.add(dto);
|
||||
}
|
||||
}
|
||||
// 保存数据
|
||||
// 1. 首先获取所有现有的企标标准号
|
||||
// 1. 首先获取所有现有的国标标准号
|
||||
List<LawsDomesticStandard> existingEntities = domesticStandardService.list();
|
||||
|
||||
// 2. 创建一个Map,用于快速查找是否存在相同的标准号
|
||||
@@ -637,13 +874,24 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
}
|
||||
entity.setSubstituteStandardNumber(null);
|
||||
entity.setReplacedByStandardNumber(null);
|
||||
domesticStandardService.saveOrUpdate(entity);
|
||||
// 构建updateWrapper 将其余字段全部设为null
|
||||
if (existingEntity != null) {
|
||||
// 如果存在,则执行更新操作
|
||||
entity.setIsAsmsImport("0");
|
||||
UpdateWrapper<LawsDomesticStandard> updateWrapper = this.getDomesticUpdateWrapper(entity);
|
||||
domesticStandardService.update(entity, updateWrapper);
|
||||
} else {
|
||||
// 如果不存在,则执行保存操作
|
||||
domesticStandardService.save(entity);
|
||||
}
|
||||
String standardId = entity.getId();
|
||||
// 保存文件关联 //TODO 处理空指针
|
||||
// OSSFile ossFile = standardNumberToFileMap.get(entity.getStandardNumber()).get(0);
|
||||
// ossFile.setStandardId(standardId);
|
||||
// ossFileService.save(ossFile);
|
||||
// entity.setId(standardId);
|
||||
// 保存文件关联
|
||||
// List<OSSFile> ossFiles = standardNumberToFileMap.get(entity.getStandardNumber());
|
||||
// if (ossFiles != null && !ossFiles.isEmpty()) {
|
||||
// OSSFile ossFile = ossFiles.get(0);
|
||||
// ossFile.setStandardId(standardId);
|
||||
// ossFileService.save(ossFile);
|
||||
// }
|
||||
}
|
||||
log.info("老法规国标覆盖导入完成");
|
||||
// 获取当前时间戳(毫秒)
|
||||
@@ -663,6 +911,43 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
// }
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private UpdateWrapper<LawsDomesticStandard> getDomesticUpdateWrapper(LawsDomesticStandard entity) {
|
||||
// 遍历是实体类的所有字段,如果有值则不拼接update语句,如果没有值则拼接语句
|
||||
UpdateWrapper<LawsDomesticStandard> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", entity.getId());
|
||||
Field[] fields = entity.getClass().getDeclaredFields();
|
||||
// 创建一个不做处理的数组
|
||||
List<String> ignoreFields = Arrays.asList("id",
|
||||
"serialVersionUID", "delFlag",
|
||||
"createBy", "createTime", "updateBy", "updateTime", "orgCode");
|
||||
for (Field field : fields) {
|
||||
if (!ignoreFields.contains(field.getName())) {
|
||||
field.setAccessible(true);
|
||||
String dbColumnName = convertFieldNameToDbColumnName(field.getName());
|
||||
if (field.get(entity) == null) {
|
||||
updateWrapper.set(dbColumnName, null);
|
||||
} else {
|
||||
updateWrapper.set(dbColumnName, field.get(entity));
|
||||
}
|
||||
}
|
||||
}
|
||||
return updateWrapper;
|
||||
}
|
||||
|
||||
// 定义一个方法来执行字段名转换
|
||||
private String convertFieldNameToDbColumnName(String fieldName) {
|
||||
StringBuilder dbColumnName = new StringBuilder();
|
||||
for (char c : fieldName.toCharArray()) {
|
||||
if (Character.isUpperCase(c)) {
|
||||
dbColumnName.append("_").append(Character.toLowerCase(c));
|
||||
} else {
|
||||
dbColumnName.append(c);
|
||||
}
|
||||
}
|
||||
return dbColumnName.toString();
|
||||
}
|
||||
|
||||
private void oldSysESImport(List<OldSystemImportDTO> esDatalist, List<OldSystemImportDTO> errImportList) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
// 转换数据
|
||||
@@ -679,10 +964,25 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
es.setStandardName(dto.getBzmc());
|
||||
es.setStandardEnglishName(dto.getBzywmc());
|
||||
|
||||
// 发布日期和实施日期入库之前需要校验 为空或者不符合规则的不入库
|
||||
es.setReleaseDate(dto.getFbrq());
|
||||
es.setImplementationDate(dto.getSsrq());
|
||||
|
||||
String fbrq = dto.getFbrq().trim();
|
||||
String ssrq = dto.getSsrq().trim();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
if (StrUtil.isNotBlank(fbrq)) {
|
||||
Date newDate = sdf.parse(fbrq);
|
||||
if (newDate != null) {
|
||||
es.setReleaseDate(newDate);
|
||||
} else {
|
||||
throw new JeroBootException("发布日期格式不正确,标准编号:" + dto.getBzh());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(ssrq)) {
|
||||
Date newDate = sdf.parse(ssrq);
|
||||
if (newDate != null) {
|
||||
es.setImplementationDate(newDate);
|
||||
} else {
|
||||
throw new JeroBootException("实施日期格式不正确,标准编号:" + dto.getBzh());
|
||||
}
|
||||
}
|
||||
String standardState = dto.getBzzt();
|
||||
es.setStandardState(standardState.equals("现行有效") ? "8" : "9");
|
||||
es.setGradeClassification(null);
|
||||
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package com.jero.modules.laws.standard.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.jero.modules.laws.common.constant.FieldCommon;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author: Mzaxd
|
||||
* @Date: 2023/12/1 9:05
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class StandardSplitUtils {
|
||||
|
||||
// 国家标准拆分
|
||||
public static Map<String, String> splitDomesticStandardNumber(String standardNumber) {
|
||||
// 定义多个正则表达式来匹配不同的标准号格式
|
||||
String[] regexPatterns = {
|
||||
"^([A-Za-z0-9/]+) (\\d+(?:\\.\\d+)?)-(\\d+)$"
|
||||
};
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
boolean isMatched = false;
|
||||
for (String regex : regexPatterns) {
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(standardNumber);
|
||||
if (matcher.find()) {
|
||||
String dsCode = matcher.group(1).trim();
|
||||
String sequenceNumber = matcher.group(2).trim();
|
||||
String yearNum = matcher.group(3).trim();
|
||||
|
||||
map.put(FieldCommon.STANDARD_CLASS, dsCode);
|
||||
map.put(FieldCommon.STANDARD_NUMBER_TEMP, sequenceNumber);
|
||||
map.put(FieldCommon.YEAR_NUMBER, yearNum);
|
||||
isMatched = true;
|
||||
break; // 匹配成功,跳出循环
|
||||
}
|
||||
}
|
||||
if (!isMatched) {
|
||||
log.error("国标标准号" + standardNumber + "拆分失败");
|
||||
throw new RuntimeException("国标标准号" + standardNumber + "拆分失败");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// 标准简单拆分
|
||||
public static Map<String, String> simpleSplitStandardNumber(String bzh, String cybzh) {
|
||||
// 将bzh根据空格分成两部分
|
||||
String[] cybzhArr = cybzh.split(" ");
|
||||
String sCode = cybzhArr[0].trim();
|
||||
String sequenceNumber = cybzhArr[1].trim();
|
||||
String yearNum = null;
|
||||
if (!bzh.equals(cybzh)) {
|
||||
yearNum = bzh.replaceAll(cybzh, "").replaceFirst("-", "").trim();
|
||||
// 如果类别和顺序号不为空则返回成功, 否则抛异常
|
||||
if (StrUtil.isBlank(yearNum)) {
|
||||
log.error("标准号" + bzh + "拆分失败,标准号和采用标准号不一致,但年代号为空");
|
||||
throw new RuntimeException("标准号" + bzh + "拆分失败,标准号和采用标准号不一致,但年代号为空");
|
||||
}
|
||||
}
|
||||
|
||||
// 如果类别和顺序号不为空则返回成功, 否则抛异常
|
||||
if (StrUtil.isBlank(sCode) || StrUtil.isBlank(sequenceNumber)) {
|
||||
log.error("标准号" + bzh + "拆分失败");
|
||||
throw new RuntimeException("标准号" + bzh + "拆分失败");
|
||||
}
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(FieldCommon.STANDARD_CLASS, sCode);
|
||||
map.put(FieldCommon.STANDARD_NUMBER_TEMP, sequenceNumber);
|
||||
map.put(FieldCommon.YEAR_NUMBER, yearNum);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
// 海外标准拆分
|
||||
public static Map<String, String> splitOverseaStandardNumber(String standardNumber) {
|
||||
// 定义多个正则表达式来匹配不同的标准号格式
|
||||
String[] regexPatterns = {
|
||||
"^([A-Za-z0-9/]+) (\\d+(?:\\.\\d+)?)-(\\d+)$"
|
||||
};
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
boolean isMatched = false;
|
||||
for (String regex : regexPatterns) {
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(standardNumber);
|
||||
if (matcher.find()) {
|
||||
String dsCode = matcher.group(1).trim();
|
||||
String sequenceNumber = matcher.group(2).trim();
|
||||
String yearNum = matcher.group(3).trim();
|
||||
|
||||
map.put(FieldCommon.STANDARD_CLASS, dsCode);
|
||||
map.put(FieldCommon.STANDARD_NUMBER_TEMP, sequenceNumber);
|
||||
map.put(FieldCommon.YEAR_NUMBER, yearNum);
|
||||
isMatched = true;
|
||||
break; // 匹配成功,跳出循环
|
||||
}
|
||||
}
|
||||
if (!isMatched) {
|
||||
log.error("海外标准号" + standardNumber + "拆分失败");
|
||||
throw new RuntimeException("海外标准号" + standardNumber + "拆分失败");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user