From 8b08b989dd6fdf0bd2a67758e39b867050cb8506 Mon Sep 17 00:00:00 2001 From: Euni4U <958079825@qq.com> Date: Tue, 22 Apr 2025 11:47:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96EXCEL=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InspectPatientController.java | 7 +- .../inspectpatient/InspectPatientService.java | 10 ++- .../InspectPatientServiceImpl.java | 71 +++++++++++++++++++ 3 files changed, 82 insertions(+), 6 deletions(-) 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 5748e25..b03b213 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 @@ -1626,11 +1626,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 2e625d6..dafce84 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 @@ -102,6 +102,14 @@ public interface InspectPatientService { */ PageResult getPatientPage(InspectPatientPageReqVO pageReqVO); + /** + * 获取患者信息用于Excel导出 + * + * @param pageReqVO 分页查询 + * @return 包含导出所需字段的患者信息列表 + */ + List getPatientForExcel(InspectPatientPageReqVO pageReqVO); + //根据条码获取患者信息 InspectPatientDO getPatientOfMedicalSn(String medicalSn); //验证身份证号是否存在 @@ -149,6 +157,4 @@ public interface InspectPatientService { * @return 患者补充信息列表 */ List getPatientSupplementsByDates(List dates); - - } \ No newline at end of file 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 ea60166..ef96df5 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 @@ -800,4 +800,75 @@ public class InspectPatientServiceImpl implements InspectPatientService { }) .collect(Collectors.toList()); } + + @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