标准excl导入 已知标准类别

This commit is contained in:
zhaokaiyao@91isoft.com
2021-11-03 13:53:27 +08:00
parent 60bd72ce14
commit 89f5d35050
5 changed files with 132 additions and 15 deletions
@@ -23,6 +23,7 @@ public class ExclExport extends ExclErrorOut {
for (Map.Entry<String, List<ImportDto>> entry : dataMap.entrySet()) {
List<ImportDto> datas = entry.getValue();
Sheet sheet = workbook.createSheet(entry.getKey());
sheet.setDefaultColumnWidth(25);
super.createHeader(workbook,sheet,header);
super.createDatas(workbook,sheet,datas);
@@ -52,13 +52,15 @@ public class ImportExcelController extends BaseController<ImportDto> {
/**
* 导入系统
*/
List<ImportDto> errorList = importExcelService.storageExclData(mapMap);
// List<ImportDto> errorList = importExcelService.storageExclData(mapMap);
// mapMap.put("导入后的信息",errorList);
// List<ImportDto> guonei= mapMap.get("GNBZ");
// List<ImportDto> haiwai = mapMap.get("HWBZ");
// List<ImportDto> qibiao = mapMap.get("QYBZ");
/**
* 生成错误表格
*/
@@ -94,4 +96,47 @@ public class ImportExcelController extends BaseController<ImportDto> {
}
@ApiOperation("从excl中导入标准信息")
@PostMapping("/analysisExcl")
public void analysisExcl(MultipartFile exclFile,MultipartFile standSort, HttpServletResponse response, HttpServletRequest request) throws IOException {
/**
* 分解数据
*/
String headStr="标准号,标准类别,内容,标准名称,英文名称,发布时间,实施时间,标准状态,代替标准号,//,//";
Map<String, List<ImportDto>> stringListMap = importExcelService.analysisExcl(exclFile,standSort);
/**
* 生成错误表格
*/
OutputStream os = null;
Workbook workbook = null;
try {
String exportName="错误表格";
response.setHeader("Content-Disposition",
"attachment; filename=" + ReadExcel.encodeFileName(exportName+".xlsx",request));
response.setContentType("application/force-download");
//导出数据
// workbook = exclErrorOut.exportDatas(guonei,headStr);
ExclExport exclExport = new ExclExport();
workbook = exclExport.exportData(stringListMap, headStr);
os = response.getOutputStream();
workbook.write(os);
os.flush();
} catch (IOException e) {
throw new AdcDaBaseException("下载文件失败,请重试");
} finally {
IOUtils.closeQuietly(os);
if (workbook != null) {
workbook.close();
}
}
}
}
@@ -8,6 +8,10 @@ public class ImportDto extends BaseEntity {
// 标准号
private String standId;
//标准类别
private String standSort;
//
private String standIdExcludeSort;
// 标准名称
private String standName;
// 英文名称
@@ -14,4 +14,5 @@ public interface ImportExcelService extends IService<ImportDto> {
public List<ImportDto> storageExclData(Map<String, List<ImportDto>> importListMap);
public Map<String,List<ImportDto>> analysisExcl(MultipartFile exclFile,MultipartFile standSort);
}
@@ -31,6 +31,7 @@ import java.io.InputStream;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Service
public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDto> implements ImportExcelService {
@@ -51,9 +52,10 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
// private SarBussionessStandServiceImpl sarBussionessStandService;
/**
* 标准类别
*/
private final static String GN = "GB,GB/T,QC/T,GJB,JB,JT,HG,YV,SY,SH,GA,HJ,QB,JG,NB,JC,YS/T,FZ/T,TB/T,JJG,SJ/T,T/TBPS" +
",NB/T,CJ/T,YS/T,SJ/T,BB/T,SN/T,SB/T,MH/T,DB11,SZDB/Z,HKG,T/ZSA,CSAE,T/CAS,T/CADA,T/CHTS,T/ITS,T/BJQC";
private final static String QB = "Q/QCBFC,Q/FT,Q/FL,Q/QCFLC,Q/BQB,Q/SGT," +
@@ -205,23 +207,34 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
//赋值方法
private ImportDto getImportDto(String[] as) {
ImportDto importDto = new ImportDto();
if (as.length == 8) {
String content = as[0];
int length = as.length;
if (length>6){
for (String s : sortList) {
int sortLength = s.length();//标准类别长度
if (s.equals(content.substring(0,sortLength ))){
importDto.setStandSort(s);
importDto.setStandIdExcludeSort(content.substring(sortLength));
}
}
importDto.setStandId(null != as[0] ? as[0].trim() : "");
importDto.setStandName(null != as[1] ? as[1].trim() : "");
importDto.setStandNameEN(null != as[2] ? as[2].trim() : "");
importDto.setPublishTime(null != as[3] ? as[3].trim() : "");
importDto.setImplementedTime(null != as[4] ? as[4].trim() : "");
importDto.setStandStatus(null != as[5] ? as[5].trim() : "");
importDto.setReplaceId(null != as[6] ? as[6].trim() : "");
} else if (as.length == 7) {
importDto.setStandId(null != as[0] ? as[0].trim() : "");
importDto.setStandName(null != as[1] ? as[1].trim() : "");
importDto.setStandNameEN(null != as[2] ? as[2].trim() : "");
importDto.setPublishTime(null != as[3] ? as[3].trim() : "");
importDto.setImplementedTime(null != as[4] ? as[4].trim() : "");
importDto.setStandStatus(null != as[5] ? as[5].trim() : "");
importDto.setReplaceId("");
if (length==7){
importDto.setReplaceId("");
}else if (length==8){
importDto.setReplaceId(null != as[6] ? as[6].trim() : "");
}
}
return importDto;
}
@@ -241,7 +254,6 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
for (int j = 0; j <= lastNum; j++) {
HSSFRow row = sheet.getRow(j);
if (null != row) {
System.out.println("正在读取第"+j+"行...");
strings.add(row.getCell(0).getStringCellValue());
}
}
@@ -532,6 +544,60 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
return error;
}
private List<String> sortList=new LinkedList<>();
@Override
public Map<String,List<ImportDto>> analysisExcl(MultipartFile exclFile,MultipartFile standSort) {
//TODO analy
if (exclFile == null || exclFile.getSize() == 0) {
log.error("文件上传错误,重新上传");
}
String filename = exclFile.getOriginalFilename();
String standSortName=standSort.getOriginalFilename();
List<String> datas = new ArrayList<>();
if (filename.endsWith(".xls")) {
datas = isXls(exclFile);
} else {
datas = isXlsx(exclFile);
}
if (standSortName.endsWith(".xls")){
sortList = isXls(standSort);
}else {
sortList = isXlsx(standSort);
}
HashMap<String, List<ImportDto>> result = new HashMap<>();
LinkedList<ImportDto> exportList = new LinkedList<>();
HashSet<String> distinct = new HashSet<>();
datas.forEach(data->{
System.out.print("#");
String[] row = data.split("\\,");
if (row.length>7){
if ((!"".equals(row[0].trim()) || !"".equals(row[1].trim()))&&distinct.add(row[0].trim()+row[1].trim())){
ImportDto importDto = getImportDto(row);
if(importDto.getStandId()!=null&&importDto.getStandName()!=null){
exportList.add(importDto);
}
}
}
});
result.put("标准数据all_new",exportList);
return result;
}
/**
* 整理为标准信息实体