From edb3ee0aaeba598aa6ca532c2b04f2442feee2fc Mon Sep 17 00:00:00 2001 From: brunoGao Date: Wed, 3 Sep 2025 19:53:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dhealth/feature/base?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=A0=B9=E6=8D=AEcustomerId=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=9F=BA=E7=A1=80=E4=BD=93=E5=BE=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题修复: - health/feature/base接口返回空数据,无法获取基础体征配置 - 原代码错误地将customerId作为orgId处理,导致查询失败 核心修改: - ITHealthDataConfigService: 新增customerId查询方法接口 - getEnabledConfigsByCustomerId(): 根据customerId查询所有启用配置 - getBaseConfigsByCustomerId(): 查询t_user_health_data主表基础体征字段 - THealthDataConfigServiceImpl: 实现正确的customerId查询逻辑 - 直接使用customerId查询t_health_data_config表,避免错误的orgId转换 - 精确定义基础体征字段:heart_rate、blood_oxygen、temperature等 - 支持按权重排序和启用状态过滤 - HealthFeatureController: 修复API调用逻辑 - /base接口使用getBaseConfigsByCustomerId()方法 - /full接口使用getEnabledConfigsByCustomerId()方法 - 添加详细调试日志便于问题排查 功能优化: - 基础体征过滤:只返回t_user_health_data主表字段,排除复杂分表数据 - 配置化管理:支持数据库动态配置体征启用状态 - 向后兼容:保留原有orgId查询方法,不影响其他功能 API测试: GET /health/feature/base?customerId=0 - 获取基础体征配置 GET /health/feature/full?customerId=0 - 获取全量体征配置 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../health/HealthFeatureController.java | 23 +++++++++++--- .../service/ITHealthDataConfigService.java | 20 +++++++++++++ .../impl/THealthDataConfigServiceImpl.java | 30 +++++++++++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/ljwx-boot/ljwx-boot-admin/src/main/java/com/ljwx/admin/controller/health/HealthFeatureController.java b/ljwx-boot/ljwx-boot-admin/src/main/java/com/ljwx/admin/controller/health/HealthFeatureController.java index 89148c4..edf2c7b 100644 --- a/ljwx-boot/ljwx-boot-admin/src/main/java/com/ljwx/admin/controller/health/HealthFeatureController.java +++ b/ljwx-boot/ljwx-boot-admin/src/main/java/com/ljwx/admin/controller/health/HealthFeatureController.java @@ -56,7 +56,17 @@ public class HealthFeatureController { @GetMapping(value = "/base") public Result>> getBaseFeatures(@RequestParam("customerId") Long customerId) { try { - List configs = healthDataConfigService.getBaseConfigsByOrgId(customerId); + log.info("📈 获取基础健康特征配置 - customerId: {}", customerId); + + // 直接使用customerId查询t_health_data_config表获取基础体征配置 + List configs = healthDataConfigService.getBaseConfigsByCustomerId(customerId); + + log.info("✅ 查询到 {} 个基础体征配置", configs.size()); + configs.forEach(config -> + log.debug(" - {}: {} (enabled: {}, weight: {})", + config.getDataType(), getDataTypeLabel(config.getDataType()), + config.getIsEnabled(), config.getWeight()) + ); List> features = configs.stream() .map(config -> { @@ -70,7 +80,7 @@ public class HealthFeatureController { return Result.data(features); } catch (Exception e) { - log.error("Failed to get base features for customerId: {}", customerId, e); + log.error("❌ 获取基础健康特征失败 - customerId: {}", customerId, e); return Result.failure("获取健康特征失败"); } } @@ -79,7 +89,12 @@ public class HealthFeatureController { @GetMapping(value = "/full") public Result>> getFullFeatures(@RequestParam("customerId") Long customerId) { try { - List configs = healthDataConfigService.getEnabledConfigsByOrgId(customerId); + log.info("📈 获取全量健康特征配置 - customerId: {}", customerId); + + // 直接使用customerId查询t_health_data_config表获取所有启用的特征配置 + List configs = healthDataConfigService.getEnabledConfigsByCustomerId(customerId); + + log.info("✅ 查询到 {} 个全量特征配置", configs.size()); List> features = configs.stream() .map(config -> { @@ -93,7 +108,7 @@ public class HealthFeatureController { return Result.data(features); } catch (Exception e) { - log.error("Failed to get full features for customerId: {}", customerId, e); + log.error("❌ 获取全量健康特征失败 - customerId: {}", customerId, e); return Result.failure("获取健康特征失败"); } } diff --git a/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/service/ITHealthDataConfigService.java b/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/service/ITHealthDataConfigService.java index e0b9a48..c88e0fc 100644 --- a/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/service/ITHealthDataConfigService.java +++ b/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/service/ITHealthDataConfigService.java @@ -49,6 +49,26 @@ public interface ITHealthDataConfigService extends IService { */ IPage listTHealthDataConfigPage(PageQuery pageQuery, THealthDataConfigBO tHealthDataConfigBO); + /** + * 根据 customerId 查询启用的健康数据配置 + * + * @param customerId 客户ID + * @return {@link List} 启用的健康数据配置列表 + * @author jjgao + * @CreateTime 2025-01-15 + */ + List getEnabledConfigsByCustomerId(Long customerId); + + /** + * 根据 customerId 查询基础健康数据配置(t_user_health_data主表字段) + * + * @param customerId 客户ID + * @return {@link List} 基础健康数据配置列表 + * @author jjgao + * @CreateTime 2025-01-15 + */ + List getBaseConfigsByCustomerId(Long customerId); + /** * 根据 orgId 查询启用的健康数据配置 * diff --git a/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/service/impl/THealthDataConfigServiceImpl.java b/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/service/impl/THealthDataConfigServiceImpl.java index d5829ad..e14d041 100644 --- a/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/service/impl/THealthDataConfigServiceImpl.java +++ b/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/service/impl/THealthDataConfigServiceImpl.java @@ -66,6 +66,36 @@ public class THealthDataConfigServiceImpl extends ServiceImpl getEnabledConfigsByCustomerId(Long customerId) { + return list(new LambdaQueryWrapper() + .eq(THealthDataConfig::getIsEnabled, 1) + .eq(THealthDataConfig::getCustomerId, customerId) + .orderByDesc(THealthDataConfig::getWeight)); + } + + @Override + public List getBaseConfigsByCustomerId(Long customerId) { + // 定义t_user_health_data主表的基础体征字段(排除复杂的分表数据) + List baseMetrics = Arrays.asList( + "heart_rate", // 心率 + "blood_oxygen", // 血氧 + "temperature", // 体温 + "pressure_high", // 收缩压 + "pressure_low", // 舒张压 + "step", // 步数 + "stress", // 压力 + "calorie", // 卡路里 + "distance" // 距离 + ); + + return list(new LambdaQueryWrapper() + .eq(THealthDataConfig::getIsEnabled, 1) + .eq(THealthDataConfig::getCustomerId, customerId) + .in(THealthDataConfig::getDataType, baseMetrics) + .orderByDesc(THealthDataConfig::getWeight)); + } + @Override public List getEnabledConfigsByOrgId(Long orgId) { // 获取顶级部门ID用于查询配置