liusheng
2024-11-01 5d1d54e83546ba9fc85c69b32287883d04f4a475
smartor/src/main/java/com/smartor/service/impl/PatArchiveImportServiceImpl.java
@@ -6,10 +6,7 @@
import com.smartor.mapper.PatArchiveImportMapper;
import com.smartor.service.IPatArchiveImportService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.poi.ss.usermodel.Cell;
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;
@@ -21,6 +18,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
/**
 * Excel导入患者档案Service业务层处理
@@ -117,42 +115,59 @@
                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))) {
                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()));
                }