diff --git a/health-watch/health-watch-biz/src/main/java/com/renkang/watch/async/AsyncImportService.java b/health-watch/health-watch-biz/src/main/java/com/renkang/watch/async/AsyncImportService.java index 41a3ce4..ea8e061 100644 --- a/health-watch/health-watch-biz/src/main/java/com/renkang/watch/async/AsyncImportService.java +++ b/health-watch/health-watch-biz/src/main/java/com/renkang/watch/async/AsyncImportService.java @@ -336,8 +336,9 @@ public class AsyncImportService { updatedWatchDevice.setBindDate(watchDevice.getBindDate()==null?new Date():watchDevice.getBindDate()); updatedWatchDevice.setUpdateDate(new Date()); updatedWatchDevice.setUpdateBy(sysUser.getId()); - updatedWatchDevice.setDeptId(device.getDeptId()); - updatedWatchDevice.setOrgCode(device.getOrgCode()); + // 这里修改成以用户的部门为准,更新手表的所属部门 + updatedWatchDevice.setDeptId(sysCache.getDepartIdByOrgCode(user.getOrgCode())); + updatedWatchDevice.setOrgCode(user.getOrgCode()); updateList.add(updatedWatchDevice); } info1.setHandleMsg(index + "/" + count); 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 691dd78..c4094a4 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 @@ -440,7 +440,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()); } @@ -2089,8 +2184,8 @@ public class DeptStatisticDataServiceImpl extends ServiceImpl 6){ + orgCode = orgCode.substring(0, 6); + } + watchDevice.setOrgCode(orgCode); + watchDevice.setDeptId(sysCache.getDepartIdByOrgCode(orgCode)); bindUserToDevice(watchDevice, dto); if (StrUtil.isNotBlank(dto.getBindUserId())) { // 初始化开关数据 @@ -488,6 +495,13 @@ public class WatchDeviceServiceImpl extends ServiceImpl filterMap = new HashMap(1);