From 37b79cfd8e5ecdc6f9f09750583f998183c338fb Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期四, 07 十一月 2024 10:55:27 +0800
Subject: [PATCH] 代码提交
---
smartor/src/main/java/com/smartor/service/impl/PatArchiveImportServiceImpl.java | 60 +++++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 43 insertions(+), 17 deletions(-)
diff --git a/smartor/src/main/java/com/smartor/service/impl/PatArchiveImportServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/PatArchiveImportServiceImpl.java
index c5ea8c6..1a3a169 100644
--- a/smartor/src/main/java/com/smartor/service/impl/PatArchiveImportServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/PatArchiveImportServiceImpl.java
@@ -6,19 +6,19 @@
import com.smartor.mapper.PatArchiveImportMapper;
import com.smartor.service.IPatArchiveImportService;
import org.apache.commons.lang3.ObjectUtils;
-import org.apache.poi.ss.usermodel.Row;
-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.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
+import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.regex.Pattern;
/**
* Excel瀵煎叆鎮h�呮。妗圫ervice涓氬姟灞傚鐞�
@@ -103,55 +103,81 @@
public List<PatArchiveImport> importPatInfo(MultipartFile multipartFile) {
//鐢ㄤ簬杩斿洖
List<PatArchiveImport> patArchiveImports = new ArrayList<>();
+
+ //鍘婚噸
+ List<String> qc = new ArrayList<>();
try {
Workbook workbook = new XSSFWorkbook(multipartFile.getInputStream());
Sheet sheet = workbook.getSheetAt(0);
- for (int i = sheet.getFirstRowNum() + 1; i < sheet.getLastRowNum(); i++) {
+ for (int i = sheet.getFirstRowNum() + 1; i <= sheet.getLastRowNum(); i++) {
//瀵煎叆鎮h�呭璞�
PatArchiveImport patArchiveImport = new PatArchiveImport();
Row row = sheet.getRow(i);
//濡傛灉琛屼负绌猴紝杩涜涓嬩竴娆″惊鐜�
- if (ObjectUtils.isEmpty(row.getCell(0)) && ObjectUtils.isEmpty(row.getCell(1)) && ObjectUtils.isEmpty(row.getCell(2))) {
+ if (ObjectUtils.isEmpty(row.getCell(0)) && StringUtils.isNotEmpty(row.getCell(0) + "") && ObjectUtils.isEmpty(row.getCell(1)) && StringUtils.isNotEmpty(row.getCell(1) + "") && ObjectUtils.isEmpty(row.getCell(2)) && StringUtils.isNotEmpty(row.getCell(2) + "")) {
continue;
}
//鍒ゆ柇鏁版嵁鏄惁鏈夐棶棰�
- if (ObjectUtils.isNotEmpty(row.getCell(0).toString())) {
+ if (ObjectUtils.isNotEmpty(row.getCell(0)) && StringUtils.isNotEmpty(row.getCell(0) + "")) {
patArchiveImport.setName(row.getCell(0).toString());
+ } else {
+ continue;
}
- if (ObjectUtils.isNotEmpty(row.getCell(1))) {
- patArchiveImport.setIdcardno(row.getCell(1).toString());
+ if (ObjectUtils.isNotEmpty(row.getCell(1)) && StringUtils.isNotEmpty(row.getCell(1) + "")) {
+ Cell cell = row.getCell(1);
+ if (row.getCell(1).toString().contains("X") || row.getCell(1).toString().contains("x")) {
+ patArchiveImport.setIdcardno(row.getCell(1).toString());
+ } else {
+ Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
+ boolean matches = pattern.matcher(row.getCell(1).toString()).matches();
+ if (matches) {
+ patArchiveImport.setIdcardno(row.getCell(1).toString());
+ } else {
+ double numericCellValue = cell.getNumericCellValue();
+ DecimalFormat decimalFormat = new DecimalFormat("#");
+ String formattedValue = decimalFormat.format(numericCellValue);
+ patArchiveImport.setIdcardno(formattedValue);
+ }
+ }
+
+ boolean contains = qc.contains(row.getCell(1).toString());
+ if (contains) continue;
}
- if (ObjectUtils.isNotEmpty(row.getCell(2))) {
- patArchiveImport.setTelcode(row.getCell(2).toString());
+ if (ObjectUtils.isNotEmpty(row.getCell(2)) && StringUtils.isNotEmpty(row.getCell(2) + "")) {
+ Cell cell = row.getCell(2);
+ double numericCellValue = cell.getNumericCellValue();
+ DecimalFormat decimalFormat = new DecimalFormat("#");
+ String formattedValue = decimalFormat.format(numericCellValue);
+ patArchiveImport.setTelcode(formattedValue);
}
- if (ObjectUtils.isNotEmpty(row.getCell(3))) {
+ if (ObjectUtils.isNotEmpty(row.getCell(3)) && StringUtils.isNotEmpty(row.getCell(3) + "")) {
patArchiveImport.setBatchName(row.getCell(3).toString());
}
- if (ObjectUtils.isNotEmpty(row.getCell(4))) {
+ if (ObjectUtils.isNotEmpty(row.getCell(4)) && StringUtils.isNotEmpty(row.getCell(4) + "")) {
patArchiveImport.setPatientno(row.getCell(4).toString());
}
- if (ObjectUtils.isNotEmpty(row.getCell(5))) {
+ if (ObjectUtils.isNotEmpty(row.getCell(5)) && StringUtils.isNotEmpty(row.getCell(5) + "")) {
patArchiveImport.setPattype(row.getCell(5).toString());
}
- if (ObjectUtils.isNotEmpty(row.getCell(6))) {
+ if (ObjectUtils.isNotEmpty(row.getCell(6)) && StringUtils.isNotEmpty(row.getCell(6) + "")) {
patArchiveImport.setSex(Long.valueOf(row.getCell(6).toString()));
}
- if (ObjectUtils.isNotEmpty(row.getCell(7))) {
+ if (ObjectUtils.isNotEmpty(row.getCell(7)) && StringUtils.isNotEmpty(row.getCell(7) + "")) {
patArchiveImport.setAge(Long.valueOf(row.getCell(7).toString()));
}
-
- patArchiveImports.add(patArchiveImport);
patArchiveImport.setCreateTime(new Date());
patArchiveImport.setUpdateTime(new Date());
//鎵归噺鍙凤紙褰撳墠鏃堕棿锛�
patArchiveImport.setBatchNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
insertPatArchiveImport(patArchiveImport);
+
+ patArchiveImports.add(patArchiveImport);
}
} catch (Exception e) {
--
Gitblit v1.9.3