Merge branch 'develop_3' into 'develop_master'
匹配文件id和文件路径 See merge request LiuChao/foton-slrs-system-rest!232
This commit is contained in:
@@ -42,18 +42,18 @@ public class Analysis {
|
|||||||
//获取表1的标准号
|
//获取表1的标准号
|
||||||
String value = row.getCell(1).toString();
|
String value = row.getCell(1).toString();
|
||||||
Cell sortCell = row.createCell(11);
|
Cell sortCell = row.createCell(11);
|
||||||
Cell sortNumber = row.createCell(12);
|
Cell numberCell = row.createCell(12);
|
||||||
Cell sortYear = row.createCell(13);
|
Cell yearCell = row.createCell(13);
|
||||||
|
|
||||||
sortCell.setCellType(CellType.STRING);
|
sortCell.setCellType(CellType.STRING);
|
||||||
sortNumber.setCellType(CellType.STRING);
|
numberCell.setCellType(CellType.STRING);
|
||||||
sortYear.setCellType(CellType.STRING);
|
yearCell.setCellType(CellType.STRING);
|
||||||
|
|
||||||
List<String> collect = sortSet.stream()
|
List<String> collect = sortSet.stream()
|
||||||
.filter(item ->{
|
.filter(item ->{
|
||||||
int length = item.length();
|
int length = item.length();
|
||||||
if (value.length()>length){
|
if (value.length()>length){
|
||||||
return value.substring(0, length).contains(item.trim());
|
return value.substring(0, length).contains(item);
|
||||||
}else return false;
|
}else return false;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -68,8 +68,8 @@ public class Analysis {
|
|||||||
// pattern.matcher(standId).matches()
|
// pattern.matcher(standId).matches()
|
||||||
if (value.length()>=length+5){
|
if (value.length()>=length+5){
|
||||||
sortCell.setCellValue(collect.get(0));
|
sortCell.setCellValue(collect.get(0));
|
||||||
sortNumber.setCellValue(value.substring(length,value.length()-5));
|
numberCell.setCellValue(value.substring(length,value.length()-5));
|
||||||
sortYear.setCellValue(value.substring(value.length()-4));
|
yearCell.setCellValue(value.substring(value.length()-4));
|
||||||
}
|
}
|
||||||
}else if (collect.size()>1){
|
}else if (collect.size()>1){
|
||||||
String maxLenSort="";
|
String maxLenSort="";
|
||||||
@@ -86,16 +86,16 @@ public class Analysis {
|
|||||||
|
|
||||||
|
|
||||||
sortCell.setCellValue(maxLenSort);
|
sortCell.setCellValue(maxLenSort);
|
||||||
sortNumber.setCellValue(value.substring(length,value.length()-5));
|
numberCell.setCellValue(value.substring(length,value.length()-5));
|
||||||
sortYear.setCellValue(value.substring(value.length()-4));
|
yearCell.setCellValue(value.substring(value.length()-4));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.info("-");
|
logger.info("-");
|
||||||
|
|
||||||
sortCell.setCellValue("-");
|
sortCell.setCellValue("-");
|
||||||
sortNumber.setCellValue("-");
|
numberCell.setCellValue("-");
|
||||||
sortYear.setCellValue("-");
|
yearCell.setCellValue("-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package com.adc.da.slrs.ImportExcelDatas.comment;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.CellType;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class PathMatcher {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PathMatcher.class);
|
||||||
|
|
||||||
|
public void run(MultipartFile target,MultipartFile attach) throws IOException {
|
||||||
|
|
||||||
|
InputStream inputStream = target.getInputStream();
|
||||||
|
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||||
|
|
||||||
|
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
HashMap<String, String> fileMap = getFileMap(attach);
|
||||||
|
|
||||||
|
|
||||||
|
for (Row row : sheet) {
|
||||||
|
|
||||||
|
String latter = row.getCell(1).getStringCellValue().trim();//标准号
|
||||||
|
String fileId="";
|
||||||
|
if (row.getCell(10)!=null){
|
||||||
|
fileId = row.getCell(10).getStringCellValue().trim();//文档id
|
||||||
|
}else {
|
||||||
|
logger.info("+");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(fileId)
|
||||||
|
.append(latter);
|
||||||
|
if (fileMap.containsKey(builder.toString())){
|
||||||
|
Cell cell = row.createCell(9);
|
||||||
|
cell.setCellType(CellType.STRING);
|
||||||
|
cell.setCellValue(fileMap.get(builder.toString()));
|
||||||
|
logger.info("*");
|
||||||
|
}else {
|
||||||
|
logger.info("-");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\匹配带入文件路径-国内库.xlsx");
|
||||||
|
FileOutputStream os = new FileOutputStream(file);
|
||||||
|
workbook.write(os);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private HashMap<String,String> getFileMap(MultipartFile excel) throws IOException {
|
||||||
|
|
||||||
|
InputStream inputStream = excel.getInputStream();
|
||||||
|
|
||||||
|
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||||
|
|
||||||
|
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
HashMap<String, String> resultMap = new HashMap<>();
|
||||||
|
for (Row row : sheet) {
|
||||||
|
|
||||||
|
String value = row.getCell(0).getStringCellValue();
|
||||||
|
|
||||||
|
String[] strArray = value.split(",");
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(strArray[1].trim()) //文档id
|
||||||
|
.append(strArray[2].trim()); //标准号
|
||||||
|
|
||||||
|
|
||||||
|
String path = strArray[3];
|
||||||
|
|
||||||
|
resultMap.put(builder.toString(),path);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
package com.adc.da.slrs.ImportExcelDatas.comment;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.CellType;
|
||||||
|
import org.apache.poi.ss.usermodel.DateUtil;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.apache.poi.ss.usermodel.CellType.NUMERIC;
|
||||||
|
|
||||||
|
public class StandMatcher {
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(StandMatcher.class);
|
||||||
|
|
||||||
|
|
||||||
|
public void run(MultipartFile target,MultipartFile attach) throws IOException {
|
||||||
|
InputStream inputStream = target.getInputStream();
|
||||||
|
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||||
|
|
||||||
|
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
Map<String, String> matchSet = getMatchSet(attach);
|
||||||
|
|
||||||
|
for (Row row : sheet) {
|
||||||
|
|
||||||
|
String letter =convertCellValueToString(row.getCell(1));//标准号
|
||||||
|
|
||||||
|
String publish = convertCellValueToString(row.getCell(3));//发布日期
|
||||||
|
|
||||||
|
String impl= convertCellValueToString(row.getCell(4));//实施日期
|
||||||
|
|
||||||
|
String state = convertCellValueToString(row.getCell(2));//状态
|
||||||
|
|
||||||
|
String replace= convertCellValueToString(row.getCell(5));//代替标准号
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
StringBuilder strBuilder = new StringBuilder();
|
||||||
|
strBuilder.append(letter)
|
||||||
|
.append(publish)
|
||||||
|
.append(impl)
|
||||||
|
.append(state)
|
||||||
|
.append(replace);
|
||||||
|
String str = strBuilder.toString();
|
||||||
|
|
||||||
|
if (matchSet.containsKey(str)){
|
||||||
|
Cell cell = row.createCell(10); //再第10列存放文件id
|
||||||
|
cell.setCellType(CellType.STRING);
|
||||||
|
cell.setCellValue(matchSet.get(str));
|
||||||
|
logger.info("*");
|
||||||
|
}else {
|
||||||
|
logger.info("-");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
File result = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\匹配带入文件id-国内库.xlsx");
|
||||||
|
FileOutputStream os = new FileOutputStream(result);
|
||||||
|
workbook.write(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private Map<String,String> getMatchSet(MultipartFile excel) throws IOException {
|
||||||
|
InputStream inputStream = excel.getInputStream();
|
||||||
|
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||||
|
|
||||||
|
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
Map<String,String> resultSet = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
for (Row row : sheet) {
|
||||||
|
|
||||||
|
String letter =convertCellValueToString(row.getCell(0));//标准号
|
||||||
|
|
||||||
|
String publish = convertCellValueToString(row.getCell(3));//发布日期
|
||||||
|
|
||||||
|
String impl= convertCellValueToString(row.getCell(4));//实施日期
|
||||||
|
|
||||||
|
String state = convertCellValueToString(row.getCell(5));//状态
|
||||||
|
|
||||||
|
String replace= convertCellValueToString(row.getCell(6));//代替标准号
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
StringBuilder strBuilder = new StringBuilder();
|
||||||
|
strBuilder.append(letter)
|
||||||
|
.append(publish)
|
||||||
|
.append(impl)
|
||||||
|
.append(state)
|
||||||
|
.append(replace);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (row.getCell(7).getCellType()== NUMERIC){
|
||||||
|
String s = row.getCell(7).toString();
|
||||||
|
String fileId =s.substring(0,s.length()-2);//文件id
|
||||||
|
resultSet.put(strBuilder.toString(),fileId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return resultSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将单元格内容转化为字符串
|
||||||
|
*/
|
||||||
|
private static String convertCellValueToString(Cell cell) {
|
||||||
|
if (null == cell) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String returnValue = "";
|
||||||
|
switch (cell.getCellType()) {
|
||||||
|
case STRING: //字符串
|
||||||
|
returnValue = cell.getStringCellValue().trim();
|
||||||
|
break;
|
||||||
|
case NUMERIC: //数字
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (DateUtil.isCellDateFormatted(cell)) {
|
||||||
|
Date tempValue = cell.getDateCellValue();
|
||||||
|
SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
returnValue = simpleFormat.format(tempValue);
|
||||||
|
}else {
|
||||||
|
returnValue = String.valueOf(cell.getNumericCellValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
returnValue=cell.toString().trim();
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
case BOOLEAN: //布尔
|
||||||
|
boolean booleanCellValue = cell.getBooleanCellValue();
|
||||||
|
returnValue = Boolean.toString(booleanCellValue).trim();
|
||||||
|
break;
|
||||||
|
case BLANK: //空值
|
||||||
|
break;
|
||||||
|
case FORMULA: //公式
|
||||||
|
cell.getCellFormula();
|
||||||
|
break;
|
||||||
|
case ERROR: //故障
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 判断是否为整数,是返回true,否则返回false.
|
||||||
|
*/
|
||||||
|
public static boolean isIntegerForDouble(Double num) {
|
||||||
|
double eqs = 1e-10; //精度范围
|
||||||
|
return num - Math.floor(num) < eqs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+26
-10
@@ -2,10 +2,7 @@ package com.adc.da.slrs.ImportExcelDatas.controller;
|
|||||||
|
|
||||||
import com.adc.da.base.web.BaseController;
|
import com.adc.da.base.web.BaseController;
|
||||||
import com.adc.da.common.ReadExcel;
|
import com.adc.da.common.ReadExcel;
|
||||||
import com.adc.da.slrs.ImportExcelDatas.comment.Analysis;
|
import com.adc.da.slrs.ImportExcelDatas.comment.*;
|
||||||
import com.adc.da.slrs.ImportExcelDatas.comment.Contrast;
|
|
||||||
import com.adc.da.slrs.ImportExcelDatas.comment.ExclErrorOut;
|
|
||||||
import com.adc.da.slrs.ImportExcelDatas.comment.ExclExport;
|
|
||||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||||
import com.adc.da.slrs.ImportExcelDatas.service.ImportExcelService;
|
import com.adc.da.slrs.ImportExcelDatas.service.ImportExcelService;
|
||||||
import com.adc.da.util.exception.AdcDaBaseException;
|
import com.adc.da.util.exception.AdcDaBaseException;
|
||||||
@@ -90,7 +87,7 @@ public class ImportExcelController extends BaseController<ImportDto> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation("从excl分解")
|
@ApiOperation("从excl分解出标准号")
|
||||||
@PostMapping("/analysisExcl")
|
@PostMapping("/analysisExcl")
|
||||||
public void analysisExcl(MultipartFile exclFile,MultipartFile standSort, HttpServletResponse response, HttpServletRequest request) throws IOException {
|
public void analysisExcl(MultipartFile exclFile,MultipartFile standSort, HttpServletResponse response, HttpServletRequest request) throws IOException {
|
||||||
/**
|
/**
|
||||||
@@ -139,20 +136,39 @@ public class ImportExcelController extends BaseController<ImportDto> {
|
|||||||
return importExcelService.isExist(exclFile);
|
return importExcelService.isExist(exclFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("对比")
|
@ApiOperation("对比两个excel表中的标准名称")
|
||||||
@PostMapping("/contrast")
|
@PostMapping("/contrast")
|
||||||
public void contrast(MultipartFile all,MultipartFile excel) throws IOException {
|
public void contrast(MultipartFile targetExcel,MultipartFile excel) throws IOException {
|
||||||
Contrast contrast = new Contrast();
|
Contrast contrast = new Contrast();
|
||||||
contrast.run(all,excel);
|
contrast.run(targetExcel,excel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation("根据标准从excl中分解出标准号,类别,年份")
|
@ApiOperation("根据标准从excl中分解出标准号,类别,年份")
|
||||||
@PostMapping("/analysis")
|
@PostMapping("/analysis")
|
||||||
public void analysis(MultipartFile exclFile,MultipartFile standSort) throws IOException {
|
public void analysis(MultipartFile targetExcel,MultipartFile attachExcel) throws IOException {
|
||||||
Analysis analysis = new Analysis();
|
Analysis analysis = new Analysis();
|
||||||
analysis.setSortColumn(1);
|
analysis.setSortColumn(1);
|
||||||
analysis.run(exclFile,standSort);
|
analysis.run(targetExcel,attachExcel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("匹配文件id")
|
||||||
|
@PostMapping("/matching")
|
||||||
|
public void matching(MultipartFile targetExcel,MultipartFile attachExcel) throws IOException {
|
||||||
|
StandMatcher standMatcher = new StandMatcher();
|
||||||
|
standMatcher.run(targetExcel, attachExcel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("根据文件id和标准匹配文件路径")
|
||||||
|
@PostMapping("/matchingPath")
|
||||||
|
public void matchingPath(MultipartFile targetExcel,MultipartFile attachExcel) throws IOException {
|
||||||
|
|
||||||
|
PathMatcher pathMatcher = new PathMatcher();
|
||||||
|
pathMatcher.run(targetExcel,attachExcel);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user