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 645379b..c7d9443 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 @@ -1907,19 +1907,9 @@ public class InspectPatientController { @Operation(summary = "根据日期获取卫生院体检统计") public CommonResult> getWorkload(@RequestParam("dates") @DateTimeFormat(pattern = "yyyy-MM-dd") List dates, @RequestParam(value = "examhosname", required = false) String examhosname) { - // 获取指定日期范围内的所有患者补充信息 - List supplements = patientService.getPatientSupplementsByDates(dates); + // 获取指定日期范围内的所有患者补充信息,如果有医院名称则在数据库层面直接过滤 + List supplements = patientService.getPatientSupplementsByDatesAndHospital(dates, examhosname); - // 医院名称过滤: - // - 若examhosname为null、"null"字符串或空字符串,则不过滤,保留所有记录 - // - 若examhosname有有效值,则只保留匹配该医院名称的记录 - if (examhosname != null && !examhosname.isEmpty() && !"null".equals(examhosname)) { - supplements = supplements.stream() - .filter(s -> examhosname.equals(s.getOrgname())) - .collect(Collectors.toList()); - } - // 否则保持原有supplements不变 - // 使用Map来存储统计结果,key为卫生院名称+行政村名称 Map statisticsMap = new HashMap<>(); 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 bb2f815..e35b931 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 @@ -163,6 +163,15 @@ public interface InspectPatientService { * @return 患者补充信息列表 */ List getPatientSupplementsByDates(List dates); + + /** + * 根据日期列表和医院名称获取患者补充信息 + * + * @param dates 日期列表 + * @param examhosname 医院名称(可选) + * @return 患者补充信息列表 + */ + List getPatientSupplementsByDatesAndHospital(List dates, String examhosname); void exportStatistics(List dates, HttpServletResponse response); 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 1d6eb12..9c4d591 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 @@ -22,7 +22,6 @@ import freemarker.template.Configuration; import freemarker.template.Template; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.rendering.PDFRenderer; -import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.xwpf.usermodel.*; import org.jodconverter.DocumentConverter; import org.jodconverter.LocalConverter; @@ -817,21 +816,50 @@ public class InspectPatientServiceImpl implements InspectPatientService { return Collections.emptyList(); } - // 使用批量转换,避免循环中多次创建对象 - return patients.stream() - .map(patient -> { - PatientSupplementVO vo = new PatientSupplementVO(); - vo.setMedicalSn(patient.getMedicalSn()); - vo.setOrgname(patient.getOrgname()); - vo.setDistrictname(patient.getDistrictname()); - vo.setOldmanflag(patient.getOldmanflag()); - vo.setHtnflag(patient.getHtnflag()); - vo.setDiaflag(patient.getDiaflag()); - vo.setSmiflag(patient.getSmiflag()); - vo.setPulflag(patient.getPulflag()); - return vo; - }) - .collect(Collectors.toList()); + // 转换为 PatientSupplementVO 对象 + return BeanUtils.toBean(patients, PatientSupplementVO.class); + } + + @Override + public List getPatientSupplementsByDatesAndHospital(List dates, String examhosname) { + if (dates == null || dates.isEmpty() || dates.size() < 2) { + return Collections.emptyList(); + } + + // 获取起始日期和结束日期 + LocalDate startDate = dates.get(0); + LocalDate endDate = dates.get(1); + + // 构建查询条件,只查询必要的字段 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper + .select( + InspectPatientDO::getMedicalSn, + InspectPatientDO::getOrgname, + InspectPatientDO::getDistrictname, + InspectPatientDO::getOldmanflag, + InspectPatientDO::getHtnflag, + InspectPatientDO::getDiaflag, + InspectPatientDO::getSmiflag, + InspectPatientDO::getPulflag + ) + .eq(InspectPatientDO::getIsprint, 1) + .between(InspectPatientDO::getPrinttime, startDate.atStartOfDay(), endDate.atTime(23, 59, 59)); + + // 如果医院名称有效,添加筛选条件 + if (examhosname != null && !examhosname.isEmpty() && !"null".equals(examhosname)) { + queryWrapper.eq(InspectPatientDO::getExamhosname, examhosname); + } + + // 查询患者信息 + List patients = patientMapper.selectList(queryWrapper); + + if (patients == null || patients.isEmpty()) { + return Collections.emptyList(); + } + + // 转换为 PatientSupplementVO 对象 + return BeanUtils.toBean(patients, PatientSupplementVO.class); } /** @@ -869,6 +897,9 @@ public class InspectPatientServiceImpl implements InspectPatientService { // 使用Map来存储统计结果,key为卫生院名称+行政村名称 Map statisticsMap = new HashMap<>(); + + // 使用Set来记录已经统计过的患者ID,避免重复统计 + Set countedPatients = new HashSet<>(); // 遍历所有补充信息进行统计 for (PatientSupplementVO supplement : supplements) { @@ -885,8 +916,17 @@ public class InspectPatientServiceImpl implements InspectPatientService { vo.setSum(0); return vo; }); + + // 获取患者体检编号 + String patientId = supplement.getMedicalSn(); + + // 统计各项数量,但每个人只统计一次 + if (!countedPatients.contains(patientId)) { + countedPatients.add(patientId); + statistics.setSum(statistics.getSum() + 1); // 总数加1 + } - // 统计各项数量 + // 统计具体指标 if ("1".equals(supplement.getOldmanflag())) { statistics.setOldmanflag(statistics.getOldmanflag() + 1); } @@ -902,11 +942,6 @@ public class InspectPatientServiceImpl implements InspectPatientService { if ("1".equals(supplement.getPulflag())) { statistics.setPulflag(statistics.getPulflag() + 1); } - - // 计算总数 - statistics.setSum(statistics.getOldmanflag() + statistics.getHtnflag() + - statistics.getDiaflag() + statistics.getSmiflag() + - statistics.getPulflag()); } // excel数据