feat: 老法规系统数据导入v2.0
This commit is contained in:
+1
-1
@@ -60,7 +60,7 @@ public class OldSystemImportDTO {
|
|||||||
@Excel(name = "TY", width = 15, orderNum = "15")
|
@Excel(name = "TY", width = 15, orderNum = "15")
|
||||||
private String ty;
|
private String ty;
|
||||||
|
|
||||||
@Excel(name = "BZZT", width = 15, orderNum = "16", dicCode = "enterprise_standard_state")
|
@Excel(name = "BZZT", width = 15, orderNum = "16")
|
||||||
private String bzzt;
|
private String bzzt;
|
||||||
|
|
||||||
@Excel(name = "BZXZ", width = 15, orderNum = "17")
|
@Excel(name = "BZXZ", width = 15, orderNum = "17")
|
||||||
|
|||||||
+4
-4
@@ -239,10 +239,10 @@ public class LawsEnterpriseController {
|
|||||||
return Result.OK();
|
return Result.OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AutoLog(value = "企业法规标准-老法规企标数据库Excel导入")
|
@AutoLog(value = "企业法规标准-老法规企标数据库Zip导入")
|
||||||
@ApiOperation(value="企业法规标准-老法规企标数据库Excel导入", notes="企业法规标准-老法规企标数据库Excel导入")
|
@ApiOperation(value="企业法规标准-老法规企标数据库Zip导入", notes="企业法规标准-老法规企标数据库Zip导入")
|
||||||
@PostMapping("/importExcelOldSystem")
|
@PostMapping("/importOldSystemESZip")
|
||||||
public Result<?> importExcelOldSystem(@RequestParam("file") MultipartFile file) {
|
public Result<?> importOldSystemESZip(@RequestParam("file") MultipartFile file) {
|
||||||
enterpriseStandardService.importExcelOldSystem(file);
|
enterpriseStandardService.importExcelOldSystem(file);
|
||||||
return Result.OK("导入成功");
|
return Result.OK("导入成功");
|
||||||
}
|
}
|
||||||
|
|||||||
+67
-7
@@ -15,17 +15,26 @@ import com.jero.modules.laws.enterprise.util.EnterpriseStandardUtil;
|
|||||||
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
|
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
|
||||||
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
|
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
|
||||||
import com.jero.modules.laws.standard.mapper.LawsEnterpriseStandardMapper;
|
import com.jero.modules.laws.standard.mapper.LawsEnterpriseStandardMapper;
|
||||||
|
import com.jero.modules.laws.standard.service.ILawsReplacedStandardService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.compress.utils.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ThinkBook
|
* @author ThinkBook
|
||||||
@@ -47,6 +56,9 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
@Resource
|
@Resource
|
||||||
private CommonAPI commonAPI;
|
private CommonAPI commonAPI;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ILawsReplacedStandardService lawsReplacedStandardService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LawsEnterpriseStandard queryByStandardNumber(String standardNumber) {
|
public LawsEnterpriseStandard queryByStandardNumber(String standardNumber) {
|
||||||
if (StringUtils.isBlank(standardNumber)){
|
if (StringUtils.isBlank(standardNumber)){
|
||||||
@@ -61,13 +73,38 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importExcelOldSystem(MultipartFile file) {
|
public void importExcelOldSystem(MultipartFile zipFile) {
|
||||||
|
// 验证文件是否为压缩格式
|
||||||
|
if (!Objects.requireNonNull(zipFile.getContentType()).contains("zip")) {
|
||||||
|
throw new JeroBootException("文件格式不正确,请上传zip格式的压缩包。");
|
||||||
|
}
|
||||||
ImportParams params = new ImportParams();
|
ImportParams params = new ImportParams();
|
||||||
params.setTitleRows(2);
|
params.setTitleRows(0);
|
||||||
params.setHeadRows(1);
|
|
||||||
params.setNeedSave(true);
|
params.setNeedSave(true);
|
||||||
// 获取数据
|
// 获取数据
|
||||||
List<OldSystemImportDTO> list = null;
|
List<OldSystemImportDTO> list = null;
|
||||||
|
// 解压缩文件,查找Excel文件
|
||||||
|
MultipartFile file = null;
|
||||||
|
try (ZipInputStream zis = new ZipInputStream(zipFile.getInputStream())) {
|
||||||
|
ZipEntry zipEntry;
|
||||||
|
while ((zipEntry = zis.getNextEntry()) != null) {
|
||||||
|
if (zipEntry.getName().endsWith(".xls") || zipEntry.getName().endsWith(".xlsx")) {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
IOUtils.copy(zis, baos);
|
||||||
|
byte[] excelData = baos.toByteArray();
|
||||||
|
file = new MockMultipartFile(zipEntry.getName(), zipEntry.getName(), "application/vnd.ms-excel", excelData);
|
||||||
|
zis.closeEntry();
|
||||||
|
break; // 一旦找到Excel文件,就可以跳出循环
|
||||||
|
}
|
||||||
|
zis.closeEntry();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JeroBootException("处理压缩文件时发生错误:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file == null) {
|
||||||
|
throw new JeroBootException("压缩包中未发现Excel文件。");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// 获取当前时间戳(毫秒)
|
// 获取当前时间戳(毫秒)
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
@@ -80,6 +117,17 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 删除国标
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
OldSystemImportDTO oldSystemImportDTO = list.get(i);
|
||||||
|
if (oldSystemImportDTO.getBzfl().startsWith("国家标准")
|
||||||
|
|| oldSystemImportDTO.getBzh().startsWith("GB")
|
||||||
|
|| oldSystemImportDTO.getBzh().startsWith("海外标准")
|
||||||
|
|| oldSystemImportDTO.getBzh().startsWith("FB")) {
|
||||||
|
list.remove(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
log.info("获取数据成功,数据条数:{}", list.size());
|
log.info("获取数据成功,数据条数:{}", list.size());
|
||||||
// 获取当前时间戳(毫秒)
|
// 获取当前时间戳(毫秒)
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
@@ -102,10 +150,22 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
es.setEnglishName(dto.getBzywmc());
|
es.setEnglishName(dto.getBzywmc());
|
||||||
es.setReleaseDate(dto.getFbrq());
|
es.setReleaseDate(dto.getFbrq());
|
||||||
es.setImplementationDate(dto.getSsrq());
|
es.setImplementationDate(dto.getSsrq());
|
||||||
es.setStandardState(Integer.parseInt(dto.getBzzt()));
|
String standardState = dto.getBzzt();
|
||||||
es.setSubstituteStandardNumber(dto.getTdbzh());
|
es.setStandardState(standardState.equals("现行有效") ? 8 : 9);
|
||||||
es.setReplacedByStandardNumber(dto.getBtdbzh());
|
//代替被代替特殊逻辑
|
||||||
|
String tdbzh = dto.getTdbzh();
|
||||||
|
String btdbzh = dto.getBtdbzh();
|
||||||
|
// 代替标准号
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
// 等级分类默认值
|
// 等级分类默认值
|
||||||
es.setGradeClassification("1");
|
es.setGradeClassification("1");
|
||||||
esList.add(es);
|
esList.add(es);
|
||||||
|
|||||||
Reference in New Issue
Block a user