diff --git a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java index b323a0128..5932546de 100644 --- a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java +++ b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java @@ -536,36 +536,35 @@ public class PatientexamlistController { @GetMapping("/getECGStatistics") @Operation(summary = "获取心电图统计数据") - @PreAuthorize("@ss.hasPermission('tblist:patientexamlist:query')") - public CommonResult getECGStatistics(@RequestParam("orgId") String orgId) { + public CommonResult getECGStatistics() { ECGStatisticsRespVO statistics = new ECGStatisticsRespVO(); - - // 构建基础查询条件 + AdminUserDO user = userService.getUser(getLoginUserId()); + String orgId = user.getOrgId(); + + // 使用一个查询获取所有统计数据 QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("deviceType", "ECG") - .eq("orgId", orgId); - - // 获取总数 - int totalCount = patientexamlistMapper.selectCount(queryWrapper).intValue(); - statistics.setTotalCount(totalCount); - - // 获取已分析数量(reviewDate不为空) - QueryWrapper analyzedWrapper = new QueryWrapper<>(); - analyzedWrapper.eq("deviceType", "ECG") - .eq("orgId", orgId) - .isNotNull("reviewDate"); - int analyzedCount = patientexamlistMapper.selectCount(analyzedWrapper).intValue(); - statistics.setAnalyzedCount(analyzedCount); - - // 获取未分析数量 - statistics.setUnanalyzedCount(totalCount - analyzedCount); + queryWrapper.select( + "COUNT(*) as totalCount", + "SUM(CASE WHEN reviewDate IS NOT NULL THEN 1 ELSE 0 END) as analyzedCount", + "SUM(CASE WHEN reviewDate IS NULL THEN 1 ELSE 0 END) as unanalyzedCount", + "SUM(CASE WHEN applicationDate IS NOT NULL THEN 1 ELSE 0 END) as appliedCount", + "SUM(CASE WHEN warning = '1' THEN 1 ELSE 0 END) as criticalCount" + ) + .eq("deviceType", "ECG") + .eq("orgId", orgId); + + Map counts = patientexamlistMapper.selectMaps(queryWrapper).get(0); + statistics.setTotalCount(((Number) counts.get("totalCount")).intValue()); + statistics.setAnalyzedCount(((Number) counts.get("analyzedCount")).intValue()); + statistics.setUnanalyzedCount(((Number) counts.get("unanalyzedCount")).intValue()); + statistics.setAppliedCount(((Number) counts.get("appliedCount")).intValue()); + statistics.setCriticalCount(((Number) counts.get("criticalCount")).intValue()); + // 获取阳性数量 int positiveCount = 0; - // 1. 获取所有阳性关键词配置 List> positivestatisticsDict = positivestatisticsMapper.selectList_usable(orgId); if (positivestatisticsDict != null && !positivestatisticsDict.isEmpty()) { - // 2. 收集所有关键词 List allKeywords = new ArrayList<>(); for (Map dict : positivestatisticsDict) { if (dict.get("keyWord") != null && dict.get("keyWord").toString().trim().length() > 0) { @@ -574,35 +573,17 @@ public class PatientexamlistController { } } - // 3. 一次性查询所有符合任意关键词的记录 if (!allKeywords.isEmpty()) { positiveCount = ecganalysisparasMapper.selectList_positive( - orgId, // 机构ID - null, // 不限制开始时间 - null, // 不限制结束时间 + orgId, + null, + null, allKeywords.toArray(new String[0]) ).size(); } } - statistics.setPositiveCount(positiveCount); - // 获取上级申请数量(applicationDate不为空) - QueryWrapper appliedWrapper = new QueryWrapper<>(); - appliedWrapper.eq("deviceType", "ECG") - .eq("orgId", orgId) - .isNotNull("applicationDate"); - int appliedCount = patientexamlistMapper.selectCount(appliedWrapper).intValue(); - statistics.setAppliedCount(appliedCount); - - // 获取危急值数量(warning = 1) - QueryWrapper criticalWrapper = new QueryWrapper<>(); - criticalWrapper.eq("deviceType", "ECG") - .eq("orgId", orgId) - .eq("warning", "1"); - int criticalCount = patientexamlistMapper.selectCount(criticalWrapper).intValue(); - statistics.setCriticalCount(criticalCount); - return success(statistics); }