diff --git a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java index 1ee63bd..fef03ae 100644 --- a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java +++ b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java @@ -1628,11 +1628,10 @@ public class InspectPatientController { @ApiAccessLog(operateType = EXPORT) public void exportPatientExcel(@Valid InspectPatientPageReqVO pageReqVO, HttpServletResponse response) throws IOException { - pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = patientService.getPatientPage(pageReqVO).getList(); + // 直接获取需要的字段数据,优化查询性能 + List list = patientService.getPatientForExcel(pageReqVO); // 导出 Excel - ExcelUtils.write(response, "患者信息.xls", "数据", InspectPatientExcelVO.class, - BeanUtils.toBean(list, InspectPatientExcelVO.class)); + ExcelUtils.write(response, "患者信息.xls", "数据", InspectPatientExcelVO.class, list); } @GetMapping("/createPatientInspectDataReport") diff --git a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/service/inspectpatient/InspectPatientService.java b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/service/inspectpatient/InspectPatientService.java index b35c354..dbe6c56 100644 --- a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/service/inspectpatient/InspectPatientService.java +++ b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/service/inspectpatient/InspectPatientService.java @@ -103,6 +103,14 @@ public interface InspectPatientService { */ PageResult getPatientPage(InspectPatientPageReqVO pageReqVO); + /** + * 获取患者信息用于Excel导出 + * + * @param pageReqVO 分页查询 + * @return 包含导出所需字段的患者信息列表 + */ + List getPatientForExcel(InspectPatientPageReqVO pageReqVO); + //根据条码获取患者信息 InspectPatientDO getPatientOfMedicalSn(String medicalSn); //验证身份证号是否存在 diff --git a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/service/inspectpatient/InspectPatientServiceImpl.java b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/service/inspectpatient/InspectPatientServiceImpl.java index 9b623d6..9f4f45c 100644 --- a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/service/inspectpatient/InspectPatientServiceImpl.java +++ b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/service/inspectpatient/InspectPatientServiceImpl.java @@ -942,4 +942,75 @@ public class InspectPatientServiceImpl implements InspectPatientService { e.printStackTrace(); } } + + @Override + public List getPatientForExcel(InspectPatientPageReqVO pageReqVO) { + // 构建查询条件,只查询Excel导出需要的字段 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.select( + InspectPatientDO::getMedicalSn, + InspectPatientDO::getPName, + InspectPatientDO::getGender, + InspectPatientDO::getCardId, + InspectPatientDO::getPhoneNum, + InspectPatientDO::getDomicileaddress, + InspectPatientDO::getIsprint + ); + + // 添加筛选条件 + if (pageReqVO.getMedicalSn() != null) { + queryWrapper.eq(InspectPatientDO::getMedicalSn, pageReqVO.getMedicalSn()); + } + // 检查大写字段,如果为空则尝试通过getter方法获取小写字段 + String patientName = null; + // 使用反射尝试获取pname字段(如果存在) + try { + if (pageReqVO.getPName() != null) { + patientName = pageReqVO.getPName(); + } else { + java.lang.reflect.Method method = pageReqVO.getClass().getMethod("getPname"); + if (method != null) { + Object result = method.invoke(pageReqVO); + if (result != null) { + patientName = result.toString(); + } + } + } + } catch (Exception e) { + // 忽略反射异常 + } + + if (patientName != null && !patientName.isEmpty()) { + queryWrapper.like(InspectPatientDO::getPName, patientName); + } + if (pageReqVO.getGender() != null) { + queryWrapper.eq(InspectPatientDO::getGender, pageReqVO.getGender()); + } + if (pageReqVO.getCardId() != null) { + queryWrapper.eq(InspectPatientDO::getCardId, pageReqVO.getCardId()); + } + if (pageReqVO.getPhoneNum() != null) { + queryWrapper.eq(InspectPatientDO::getPhoneNum, pageReqVO.getPhoneNum()); + } + if (pageReqVO.getStatus() != null) { + queryWrapper.eq(InspectPatientDO::getStatus, pageReqVO.getStatus()); + } + if (pageReqVO.getIsprint() != null) { + queryWrapper.eq(InspectPatientDO::getIsprint, pageReqVO.getIsprint()); + } + if (pageReqVO.getPrintTimeRange() != null && pageReqVO.getPrintTimeRange().length > 1) { + queryWrapper.between(InspectPatientDO::getPrinttime, + pageReqVO.getPrintTimeRange()[0], + pageReqVO.getPrintTimeRange()[1]); + } + + // 按ID降序排序 + queryWrapper.orderByDesc(InspectPatientDO::getId); + + // 查询数据 + List patientList = patientMapper.selectList(queryWrapper); + + // 转换为Excel VO对象 + return BeanUtils.toBean(patientList, InspectPatientExcelVO.class); + } } \ No newline at end of file