From 115407026fc0962498414721bbfb13ef783f829a Mon Sep 17 00:00:00 2001 From: lianlonggang Date: Thu, 30 Apr 2026 14:13:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(device):=20=E8=A7=A3=E5=86=B3=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=AF=BC=E5=85=A5=E5=92=8C=E7=BB=91=E5=AE=9A=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E7=9A=84=E9=83=A8=E9=97=A8=E6=9D=83=E9=99=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除设备导入时的部门必填验证,允许为空时默认归入新疆油田公司(A01) - 移除设备绑定时的跨单位限制检查 - 在设备绑定时根据员工信息更新手表的单位信息 - 修复部门统计数据查询中的层级展示逻辑 - 优化部门统计服务中的注释文档和代码结构 - 添加设备表更新操作中单位编码和部门ID的条件设置 --- .../controller/WatchDeviceController.java | 4 +- .../impl/DeptStatisticDataServiceImpl.java | 103 +++++++++++++++++- .../service/impl/WatchDeviceServiceImpl.java | 24 +++- 3 files changed, 121 insertions(+), 10 deletions(-) diff --git a/health-watch/health-watch-biz/src/main/java/com/renkang/watch/controller/WatchDeviceController.java b/health-watch/health-watch-biz/src/main/java/com/renkang/watch/controller/WatchDeviceController.java index 5ada030..a521656 100644 --- a/health-watch/health-watch-biz/src/main/java/com/renkang/watch/controller/WatchDeviceController.java +++ b/health-watch/health-watch-biz/src/main/java/com/renkang/watch/controller/WatchDeviceController.java @@ -439,7 +439,9 @@ public class WatchDeviceController extends JeecgController getDeptData(DepartStatsFilter filter) { return getDeptData(filter, true).pagedData(); } + /** + * 查询部门统计数据的核心实现 + *

+ * 执行流程: + * 1. 权限校验,补全过滤条件 + * 2. 查询各部门设备总数 Map 和绑定/佩戴数 Map + * 3. 根据过滤条件确定最终需要展示的部门列表 + * 4. 查询各部门异常预警数量 + * 5. 按需分页,将部门列表转换为统计 DTO + *

+ * + * @param filter 查询过滤条件 + * @param paged 是否需要分页,true=分页查询,false=全量查询(用于导出等场景) + * @return 包含统计数据和中间结果的传输对象 + */ private DepartStatTransfer getDeptData(DepartStatsFilter filter, boolean paged) { authCheck(filter); DepartStatTransfer transfer = new DepartStatTransfer() @@ -639,12 +660,29 @@ public class DeptStatisticDataServiceImpl extends ServiceImpl + * orgCode 编码规则:3位一层,如 A01=一级,A01A01=二级,A01A01A01=三级 + * 区分三种视图: + * - 一级部门(orgCode 长度为 3):展示自身信息,叶子名称置为 "-",取自身设备总数 + * - 二级部门(orgCode 长度为 6):同一级,展示自身信息,叶子名称置为 "-",取自身设备总数 + * - 三级部门(orgCode 长度为 9):展示所属上级名称 + 自身名称,绑定/佩戴数取自身数据 + * 当 allSecond=true(全量视图)时,绑定/佩戴数始终取各部门自身数据 + *

+ * + * @param depart 部门实体 + * @param transfer 包含所有统计中间数据的传输对象 + * @return 填充完毕的部门统计 DTO + */ private DeptStatData transferData(SysDepart depart, DepartStatTransfer transfer) { DeptStatData deptStatData = new DeptStatData(); String orgCode = null != depart ? depart.getOrgCode() : null; boolean allSecond = StrUtil.isEmpty(transfer.filter().getOrgCode()); + boolean isFirst = StrUtil.isNotEmpty(orgCode) && orgCode.length() == 3; boolean isSecond = StrUtil.isNotEmpty(orgCode) && orgCode.length() == 6; - if (isSecond) { + if (isFirst || isSecond) { + // 一级/二级部门行:展示自身信息,叶子名称占位 deptStatData.setOrgCode(orgCode); deptStatData.setOrgCodeLeaf(orgCode); deptStatData.setOrgCodeName(depart.getDepartName()); @@ -655,6 +693,7 @@ public class DeptStatisticDataServiceImpl extends ServiceImpl + * assignedDeviceNums = 已绑定设备数 + * assignedUserNums = 已佩戴人数 + * undistributedUserNums = 已绑定但未佩戴数(bindCount - wearCount) + *

+ */ private void fillWatchNums(DeptStatData deptStatData, DepartDeviceNum departDeviceNum) { deptStatData.setAssignedDeviceNums(Optional.ofNullable(departDeviceNum.getBindCount()).orElse(0)); deptStatData.setAssignedUserNums(Optional.ofNullable(departDeviceNum.getWearCount()).orElse(0)); deptStatData.setUndistributedUserNums(deptStatData.getAssignedDeviceNums() - deptStatData.getAssignedUserNums()); } + /** + * 填充各健康指标的预警数量 + *

+ * 从 abnormalCountMap 中按事件类型取值: + * stress → 压力预警数 + * heart_rate → 心率预警数 + * spo2 → 血氧预警数 + * temperature_anomalies → 体温预警数 + *

+ */ private void fillWarningNums(DeptStatData deptStatData, Map abnormalCountMap) { deptStatData.setStressNums(Optional.ofNullable(abnormalCountMap.get("stress")).map(AbnormalCount::getWarningCount).orElse(0)); deptStatData.setHeartRateNums(Optional.ofNullable(abnormalCountMap.get("heart_rate")).map(AbnormalCount::getWarningCount).orElse(0)); @@ -722,6 +779,10 @@ public class DeptStatisticDataServiceImpl extends ServiceImpl getDepartDeviceNumMap(DepartStatsFilter filter) { if (StrUtil.isNotEmpty(filter.getOrgCodeLeaf())) { return Collections.emptyMap(); @@ -732,6 +793,9 @@ public class DeptStatisticDataServiceImpl extends ServiceImpl getDepartBindAndWearNumMap(DepartStatsFilter filter) { return watchStatisticsMapper.deviceBindAndWearNums(filter) .stream() @@ -739,6 +803,10 @@ public class DeptStatisticDataServiceImpl extends ServiceImpl> getDepartAbnormalCountMap(DepartStatsFilter filter) { return watchStatisticsMapper.abnormalWarningCount(filter) .stream() @@ -746,6 +814,12 @@ public class DeptStatisticDataServiceImpl extends ServiceImpl + * 仅在"指定了二级部门但未指定三级部门"时有效,其他情况返回 null + *

+ */ private DepartDeviceNum getSecondDepartBindAndWearNum(DepartStatsFilter filter, Map departBindAndWearNumMap) { if (StrUtil.isNotEmpty(filter.getOrgCodeLeaf()) || StrUtil.isEmpty(filter.getOrgCode())) { @@ -764,6 +838,13 @@ public class DeptStatisticDataServiceImpl extends ServiceImpl + * 仅在"指定了二级部门但未指定三级部门"时有效,其他情况返回 null + * 合并时按 eventType 累加 warningCount + *

+ */ private Map getSecondDepartAbnormalCount(DepartStatsFilter filter, Map> departAbnormalCountMap) { if (StrUtil.isNotEmpty(filter.getOrgCodeLeaf()) || StrUtil.isEmpty(filter.getOrgCode())) { @@ -778,6 +859,14 @@ public class DeptStatisticDataServiceImpl extends ServiceImpl + *
  • 指定三级部门(orgCodeLeaf 不为空):仅返回该三级部门(无绑定数据则返回空)
  • + *
  • 指定二级部门(orgCode 不为空):返回该部门本身 + 其下有绑定数据的子部门,按层级(orgCode 长度)升序后再按排序字段排序
  • + *
  • 全量(orgCode 为空):返回所有有设备数据的部门,同样按层级升序后再按排序字段排序,确保一级部门排在最前
  • + * + */ private List getFinalDeparts(DepartStatsFilter filter, Map departDeviceNumMap, Map departBindAndWearNumMap) { @@ -804,7 +893,10 @@ public class DeptStatisticDataServiceImpl extends ServiceImplcomparingInt(sysDepart -> sysDepart.getOrgCode().length()) + .thenComparing(this::departComparator) + ) .collect(Collectors.toList()); } } @@ -825,6 +917,9 @@ public class DeptStatisticDataServiceImpl extends ServiceImpl getPagedDeparts(List sysDeparts, DepartStatsFilter filter) { return getSubList(sysDeparts, filter.getPageNo(), filter.getPageSize()); } diff --git a/health-watch/health-watch-biz/src/main/java/com/renkang/watch/service/impl/WatchDeviceServiceImpl.java b/health-watch/health-watch-biz/src/main/java/com/renkang/watch/service/impl/WatchDeviceServiceImpl.java index 498b224..acfdc4f 100644 --- a/health-watch/health-watch-biz/src/main/java/com/renkang/watch/service/impl/WatchDeviceServiceImpl.java +++ b/health-watch/health-watch-biz/src/main/java/com/renkang/watch/service/impl/WatchDeviceServiceImpl.java @@ -301,11 +301,11 @@ public class WatchDeviceServiceImpl extends ServiceImpl 6){ + orgCode = orgCode.substring(0, 6); + } + watchDevice.setOrgCode(orgCode); + watchDevice.setDeptId(sysCache.getDepartIdByOrgCode(orgCode)); bindUserToDevice(watchDevice, dto); if (StrUtil.isNotBlank(dto.getBindUserId())) { // 初始化开关数据 @@ -491,6 +498,13 @@ public class WatchDeviceServiceImpl extends ServiceImpl