feat: 老法规系统数据导入v2.0
This commit is contained in:
+1
-1
@@ -60,7 +60,7 @@ public class OldSystemImportDTO {
|
||||
@Excel(name = "TY", width = 15, orderNum = "15")
|
||||
private String ty;
|
||||
|
||||
@Excel(name = "BZZT", width = 15, orderNum = "16", dicCode = "enterprise_standard_state")
|
||||
@Excel(name = "BZZT", width = 15, orderNum = "16")
|
||||
private String bzzt;
|
||||
|
||||
@Excel(name = "BZXZ", width = 15, orderNum = "17")
|
||||
|
||||
+4
-4
@@ -239,10 +239,10 @@ public class LawsEnterpriseController {
|
||||
return Result.OK();
|
||||
}
|
||||
|
||||
@AutoLog(value = "企业法规标准-老法规企标数据库Excel导入")
|
||||
@ApiOperation(value="企业法规标准-老法规企标数据库Excel导入", notes="企业法规标准-老法规企标数据库Excel导入")
|
||||
@PostMapping("/importExcelOldSystem")
|
||||
public Result<?> importExcelOldSystem(@RequestParam("file") MultipartFile file) {
|
||||
@AutoLog(value = "企业法规标准-老法规企标数据库Zip导入")
|
||||
@ApiOperation(value="企业法规标准-老法规企标数据库Zip导入", notes="企业法规标准-老法规企标数据库Zip导入")
|
||||
@PostMapping("/importOldSystemESZip")
|
||||
public Result<?> importOldSystemESZip(@RequestParam("file") MultipartFile file) {
|
||||
enterpriseStandardService.importExcelOldSystem(file);
|
||||
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.service.ILawsEnterpriseStandardService;
|
||||
import com.jero.modules.laws.standard.mapper.LawsEnterpriseStandardMapper;
|
||||
import com.jero.modules.laws.standard.service.ILawsReplacedStandardService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
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.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
@@ -47,6 +56,9 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
@Resource
|
||||
private CommonAPI commonAPI;
|
||||
|
||||
@Resource
|
||||
private ILawsReplacedStandardService lawsReplacedStandardService;
|
||||
|
||||
@Override
|
||||
public LawsEnterpriseStandard queryByStandardNumber(String standardNumber) {
|
||||
if (StringUtils.isBlank(standardNumber)){
|
||||
@@ -61,13 +73,38 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
|
||||
|
||||
@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();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setTitleRows(0);
|
||||
params.setNeedSave(true);
|
||||
// 获取数据
|
||||
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 {
|
||||
// 获取当前时间戳(毫秒)
|
||||
long startTime = System.currentTimeMillis();
|
||||
@@ -80,6 +117,17 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
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());
|
||||
// 获取当前时间戳(毫秒)
|
||||
long endTime = System.currentTimeMillis();
|
||||
@@ -102,10 +150,22 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
es.setEnglishName(dto.getBzywmc());
|
||||
es.setReleaseDate(dto.getFbrq());
|
||||
es.setImplementationDate(dto.getSsrq());
|
||||
es.setStandardState(Integer.parseInt(dto.getBzzt()));
|
||||
es.setSubstituteStandardNumber(dto.getTdbzh());
|
||||
es.setReplacedByStandardNumber(dto.getBtdbzh());
|
||||
|
||||
String standardState = dto.getBzzt();
|
||||
es.setStandardState(standardState.equals("现行有效") ? 8 : 9);
|
||||
//代替被代替特殊逻辑
|
||||
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");
|
||||
esList.add(es);
|
||||
|
||||
Reference in New Issue
Block a user