Commit 16c886b1 authored by xiachenqi's avatar xiachenqi

港澳台购车比对

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