对比excel和数据库中的数据
This commit is contained in:
+1
-1
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ExclErrorOut {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BussStandExportUtil.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExclErrorOut.class);
|
||||
|
||||
public static Workbook exportDatas (List<ImportDto> datas,String header) {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.comment;
|
||||
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
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.stereotype.Component;
|
||||
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.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class ExclExport extends ExclErrorOut {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExclErrorOut.class);
|
||||
|
||||
/**
|
||||
* 导出多个sheet页的excl
|
||||
@@ -34,4 +46,71 @@ public class ExclExport extends ExclErrorOut {
|
||||
|
||||
return workbook;
|
||||
}
|
||||
|
||||
/**
|
||||
* 比对表格中的数据是否在数据库表中
|
||||
* @param sourceFile
|
||||
* @return
|
||||
*/
|
||||
public void contrast(MultipartFile sourceFile, HashSet<List<String>> set) throws IOException {
|
||||
|
||||
|
||||
InputStream inputStream = sourceFile.getInputStream();
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||
|
||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
|
||||
|
||||
// HashMap<String, String> map = new HashMap<>();
|
||||
int lastNum = sheet.getLastRowNum();
|
||||
for (int i = 0; i < lastNum; i++) {
|
||||
|
||||
XSSFRow row = sheet.getRow(i);
|
||||
|
||||
|
||||
if (row.getCell(1)!=null){
|
||||
// String value = row.getCell(1).toString();
|
||||
|
||||
// map.put(value,String.valueOf(i));
|
||||
String value = row.getCell(1).toString();
|
||||
Cell cell = row.createCell(11);
|
||||
Set<List<String>> collect = set.stream()
|
||||
.filter(item ->
|
||||
value.contains(item.get(0).trim())
|
||||
|| value.contains(item.get(1).trim())
|
||||
|| value.contains(item.get(2).trim())
|
||||
)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
|
||||
if (!collect.isEmpty()){
|
||||
logger.info("*");
|
||||
cell.setCellType(CellType.STRING);
|
||||
cell.setCellValue("1");
|
||||
}else {
|
||||
logger.info("-");
|
||||
cell.setCellType(CellType.STRING);
|
||||
cell.setCellValue("0");
|
||||
}
|
||||
}
|
||||
|
||||
// map.strea
|
||||
// List<User> filterList=map.stre()
|
||||
// .filter(user -> serviceCodes.contains(user.getOrgId()))
|
||||
// .collect(Collectors.toList());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
File file = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\ouhuo.xlsx");
|
||||
FileOutputStream os = new FileOutputStream(file);
|
||||
workbook.write(os);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+7
@@ -139,4 +139,11 @@ public class ImportExcelController extends BaseController<ImportDto> {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ApiOperation("从excl中导入标准信息")
|
||||
@PostMapping("/isExist")
|
||||
public String isExist(MultipartFile exclFile){
|
||||
return importExcelService.isExist(exclFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -15,4 +15,7 @@ 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);
|
||||
|
||||
|
||||
public String isExist(MultipartFile exclFile);
|
||||
}
|
||||
|
||||
+32
@@ -2,6 +2,7 @@ package com.adc.da.slrs.ImportExcelDatas.service.impl;
|
||||
|
||||
import com.adc.da.att.service.IAttFileEOService;
|
||||
import com.adc.da.att.vo.AttFileVo;
|
||||
import com.adc.da.slrs.ImportExcelDatas.comment.ExclExport;
|
||||
import com.adc.da.slrs.ImportExcelDatas.dao.ImportExcelDao;
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import com.adc.da.slrs.ImportExcelDatas.service.ImportExcelService;
|
||||
@@ -598,6 +599,37 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String isExist(MultipartFile exclFile) {
|
||||
ExclExport exclExport = new ExclExport();
|
||||
QueryWrapper<SarStandardsInfo> standWrapper = new QueryWrapper<>();
|
||||
standWrapper.select("STAND_NAME,STAND_SORT,STAND_YEAR");
|
||||
List<Map<String, Object>> maps = sarStandardsInfoService.listMaps(standWrapper);
|
||||
|
||||
QueryWrapper<SarBussionessStand> bussionessWrapper = new QueryWrapper<>();
|
||||
bussionessWrapper.select("STAND_NAME,STAND_SORT,STAND_YEAR");
|
||||
List<Map<String, Object>> maps1 = sarBussionessStandService.listMaps(bussionessWrapper);
|
||||
|
||||
HashSet<List<String>> nameSet = new HashSet<>();
|
||||
maps.addAll(maps1);
|
||||
maps.forEach(item->{
|
||||
List<String> strings = new LinkedList<>();
|
||||
strings.add(item.get("STAND_NAME").toString().trim());
|
||||
strings.add(item.get("STAND_SORT").toString().trim());
|
||||
strings.add(item.get("STAND_YEAR").toString().trim());
|
||||
|
||||
nameSet.add(strings);
|
||||
});
|
||||
|
||||
try {
|
||||
exclExport.contrast(exclFile,nameSet);
|
||||
return "success";
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return "failed";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 整理为标准信息实体
|
||||
|
||||
Reference in New Issue
Block a user