Commit 16c886b1 authored by xiachenqi's avatar xiachenqi

港澳台购车比对

parent 6c1ac7a0
......@@ -23,3 +23,4 @@
/nbdist/
/.nb-gradle/
/build/
/logs/
package com.yxproject.start.api;
import com.yxproject.start.service.impl.ExtensionServiceImpl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
......@@ -33,25 +30,22 @@ public class ExtensionApi {
* 解析港澳台购车人信息,判断是否办理过港澳台居住证
*/
@PostMapping(value = "analysisGAT", consumes = MediaType.MULTIPART_FORM_DATA)
public ResponseEntity<byte[]> analysisGAT(@RequestPart("file") MultipartFile file) {
public String analysisGAT(@RequestPart("file") MultipartFile file) {
// 检查文件是否为空
if (file.isEmpty()) {
throw new RuntimeException("No file uploaded");
}
// 获取文件名
String fileName = file.getOriginalFilename();
if (!fileName.endsWith("xls") && !fileName.endsWith("xlsx")) {
if (fileName != null && !fileName.endsWith("xls") && !fileName.endsWith("xlsx")) {
throw new RuntimeException("Only .xls or .xlsx files are supported");
}
Thread thread = new Thread(() -> {
extensionService.analysisGAT(file);
});
// 处理文件并生成新的Excel
byte[] newExcelData = extensionService.analysisGAT(file);
// 设置响应头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(org.springframework.http.MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", "processed_" + fileName);
return new ResponseEntity<>(newExcelData, headers, HttpStatus.OK);
thread.start();
// extensionService.analysisGAT(file);
return "ok";
}
}
......@@ -802,7 +802,10 @@ public class PersonPostApi {
cell = row.createCell(7);
cell.setCellValue(map.get("RECIPIENT_PHONE").toString());
cell = row.createCell(8);
cell.setCellValue(map.get("NATURE_OF_THE_INFORMATION").toString());
Object NATURE_OF_THE_INFORMATION = map.get("NATURE_OF_THE_INFORMATION");
if (NATURE_OF_THE_INFORMATION != null) {
cell.setCellValue(map.get("NATURE_OF_THE_INFORMATION").toString());
}
cell = row.createCell(9);
cell.setCellValue(map.get("NAME").toString());
cell = row.createCell(10);
......
......@@ -11,7 +11,6 @@ import java.util.List;
@NoArgsConstructor
public class ExtensionGatAnalysisResultDto {
private boolean result;
private String result;
private String message;
private List<ExtensionGatDto> extensionGatRecords;
}
......@@ -20,23 +20,11 @@ public interface ExtensionMapper {
"FROM\n" +
" PRODYD_DBA.PROD_CARD_T@PRODYD_LINK\n" +
"WHERE\n" +
" PROD_CARD_T.CARD_NO = #{cardNo}\n" +
" PROD_CARD_T.CARD_NO = '${cardNo}'\n" +
"ORDER BY\n" +
" PROD_CARD_T.SIGN_TIMES DESC")
List<ExtensionGatDto> getProdGatCardList(@Param("cardNo") String cardNo);
@Select("SELECT\n" +
" HIS_CARD_T.NAME,\n" +
" HIS_CARD_T.BIRTHDAY,\n" +
" HIS_CARD_T.ID_NO,\n" +
" HIS_CARD_T.BEGIN_DATE,\n" +
" HIS_CARD_T.EXPIRE_DATE,\n" +
" HIS_CARD_T.SIGN_TIMES\n" +
"FROM\n" +
" HISYD_DBA.HIS_CARD_T@HISYD_LINK\n" +
"WHERE\n" +
" HIS_CARD_T.CARD_NO = #{cardNo}\n" +
"ORDER BY\n" +
" HIS_CARD_T.SIGN_TIMES DESC")
@Select("SELECT HIS_CARD_T.NAME, HIS_CARD_T.BIRTHDAY, HIS_CARD_T.ID_NO, HIS_CARD_T.BEGIN_DATE, HIS_CARD_T.EXPIRE_DATE, HIS_CARD_T.SIGN_TIMES FROM HISYD_DBA.HIS_CARD_T@HISYD_LINK WHERE HIS_CARD_T.CARD_NO = '${cardNo}' ORDER BY HIS_CARD_T.SIGN_TIMES DESC")
List<ExtensionGatDto> getHisGatCardList(@Param("cardNo") String cardNo);
}
......@@ -7,9 +7,8 @@ import org.apache.poi.ss.usermodel.*;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
......@@ -33,23 +32,24 @@ public class ExtensionServiceImpl {
*
* @param file 文件
*/
public byte[] analysisGAT(MultipartFile file) {
public void analysisGAT(MultipartFile file) {
try (InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream)) {
Sheet hkSheet = workbook.getSheetAt(0);
Sheet twSheet = workbook.getSheetAt(1);
// Sheet twSheet = workbook.getSheetAt(1);
// 分析和更新Sheet
// analysisSheet(hkSheet);
analysisSheet(twSheet);
// 将更新后的工作簿保存到字节数组
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
workbook.write(outputStream);
return outputStream.toByteArray();
analysisSheet(hkSheet);
// analysisSheet(twSheet);
String fileName = file.getOriginalFilename();
File excelFile = new File("./" + "(已比对)" + fileName);
try (OutputStream outputStream = Files.newOutputStream(excelFile.toPath())) {
workbook.write(outputStream);
outputStream.flush();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("比对完成");
}
/**
......@@ -57,12 +57,9 @@ public class ExtensionServiceImpl {
*
* @param sheet 工作表
*/
public Sheet analysisSheet(Sheet sheet) {
public void analysisSheet(Sheet sheet) {
for (Row row : sheet) {
if (row.getRowNum() == 10) {
break;
}
ExtensionGatAnalysisResultDto resultDto = new ExtensionGatAnalysisResultDto(false, "", null);
ExtensionGatAnalysisResultDto resultDto = new ExtensionGatAnalysisResultDto("没有记录", "");
if (row.getRowNum() == 0) continue;
String name = "";
Cell cell = row.getCell(4);
......@@ -76,39 +73,37 @@ public class ExtensionServiceImpl {
}
String card_no = row.getCell(9).getStringCellValue();
List<ExtensionGatDto> prodRecords = extensionMapper.getProdGatCardList(card_no);
System.out.println("cardNO:" + card_no);
List<ExtensionGatDto> hisRecords = extensionMapper.getHisGatCardList(card_no);
List<ExtensionGatDto> combinedRecords = new ArrayList<>();
combinedRecords.addAll(prodRecords);
combinedRecords.addAll(hisRecords);
for (ExtensionGatDto prodRecord : combinedRecords) {
System.out.println(prodRecord);
}
System.out.println("rowNum: " + row.getRowNum() + "|| name: " + name + " || birthday: " + birthday + " || card_no: " + card_no + " || recordCount: " + combinedRecords.size());
if (!combinedRecords.isEmpty()) {
resultDto.setResult(true);
resultDto.setResult("比对成功");
for (ExtensionGatDto record : combinedRecords) {
if (!name.isEmpty()) {
if (!record.getName().equals(name)) {
String message = resultDto.getMessage();
resultDto.setMessage(message + "姓名不一致 ");
resultDto.setResult("数据异常");
resultDto.setMessage(message + "与第" +record.getSignTimes() + "次办理姓名不一致 ");
}
}
if (!birthday.isEmpty()) {
if (!record.getBirthday().equals(birthday)) {
String message = resultDto.getMessage();
resultDto.setMessage(message + "出生日期不一致 ");
resultDto.setResult("数据异常");
resultDto.setMessage(message + "与第" +record.getSignTimes() + "出生日期不一致 ");
}
}
}
resultDto.setExtensionGatRecords(combinedRecords);
}
String resultStr = resultDto.isResult() ? "已匹配" : "未找到";
row.createCell(11, CellType.STRING).setCellValue(resultStr);
row.createCell(11, CellType.STRING).setCellValue(resultDto.getResult());
row.createCell(12, CellType.STRING).setCellValue(resultDto.getMessage());
int indexStart = 13;
if (resultDto.getExtensionGatRecords() != null && !resultDto.getExtensionGatRecords().isEmpty()) {
for (ExtensionGatDto dto : resultDto.getExtensionGatRecords()) {
if (!combinedRecords.isEmpty()) {
for (ExtensionGatDto dto : combinedRecords) {
row.createCell(indexStart++, CellType.STRING).setCellValue(dto.getName());
row.createCell(indexStart++, CellType.STRING).setCellValue(dto.getIdNo());
row.createCell(indexStart++, CellType.STRING).setCellValue(dto.getBirthday());
row.createCell(indexStart++, CellType.STRING).setCellValue(dto.getBeginDate());
row.createCell(indexStart++, CellType.STRING).setCellValue(dto.getExpireDate());
......@@ -120,10 +115,10 @@ public class ExtensionServiceImpl {
row.createCell(11, CellType.STRING).setCellValue("比对结果");
row.createCell(12, CellType.STRING).setCellValue("备注");
row.createCell(13, CellType.STRING).setCellValue("证件姓名");
row.createCell(14, CellType.STRING).setCellValue("证件出生日期");
row.createCell(15, CellType.STRING).setCellValue("证件起始日期");
row.createCell(16, CellType.STRING).setCellValue("证件截止日期");
row.createCell(17, CellType.STRING).setCellValue("办理次数");
return sheet;
row.createCell(14, CellType.STRING).setCellValue("证件号码");
row.createCell(15, CellType.STRING).setCellValue("证件出生日期");
row.createCell(16, CellType.STRING).setCellValue("证件起始日期");
row.createCell(17, CellType.STRING).setCellValue("证件截止日期");
row.createCell(18, CellType.STRING).setCellValue("办理次数");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment