fix: 修复health/feature/base接口根据customerId查询基础体征配置
问题修复: - 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 <[email protected]>
This commit is contained in:
+19
-4
@@ -56,7 +56,17 @@ public class HealthFeatureController {
|
||||
@GetMapping(value = "/base")
|
||||
public Result<List<Map<String, String>>> getBaseFeatures(@RequestParam("customerId") Long customerId) {
|
||||
try {
|
||||
List<THealthDataConfig> configs = healthDataConfigService.getBaseConfigsByOrgId(customerId);
|
||||
log.info("📈 获取基础健康特征配置 - customerId: {}", customerId);
|
||||
|
||||
// 直接使用customerId查询t_health_data_config表获取基础体征配置
|
||||
List<THealthDataConfig> 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<Map<String, String>> 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<List<Map<String, String>>> getFullFeatures(@RequestParam("customerId") Long customerId) {
|
||||
try {
|
||||
List<THealthDataConfig> configs = healthDataConfigService.getEnabledConfigsByOrgId(customerId);
|
||||
log.info("📈 获取全量健康特征配置 - customerId: {}", customerId);
|
||||
|
||||
// 直接使用customerId查询t_health_data_config表获取所有启用的特征配置
|
||||
List<THealthDataConfig> configs = healthDataConfigService.getEnabledConfigsByCustomerId(customerId);
|
||||
|
||||
log.info("✅ 查询到 {} 个全量特征配置", configs.size());
|
||||
|
||||
List<Map<String, String>> 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("获取健康特征失败");
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -49,6 +49,26 @@ public interface ITHealthDataConfigService extends IService<THealthDataConfig> {
|
||||
*/
|
||||
IPage<THealthDataConfig> listTHealthDataConfigPage(PageQuery pageQuery, THealthDataConfigBO tHealthDataConfigBO);
|
||||
|
||||
/**
|
||||
* 根据 customerId 查询启用的健康数据配置
|
||||
*
|
||||
* @param customerId 客户ID
|
||||
* @return {@link List} 启用的健康数据配置列表
|
||||
* @author jjgao
|
||||
* @CreateTime 2025-01-15
|
||||
*/
|
||||
List<THealthDataConfig> getEnabledConfigsByCustomerId(Long customerId);
|
||||
|
||||
/**
|
||||
* 根据 customerId 查询基础健康数据配置(t_user_health_data主表字段)
|
||||
*
|
||||
* @param customerId 客户ID
|
||||
* @return {@link List} 基础健康数据配置列表
|
||||
* @author jjgao
|
||||
* @CreateTime 2025-01-15
|
||||
*/
|
||||
List<THealthDataConfig> getBaseConfigsByCustomerId(Long customerId);
|
||||
|
||||
/**
|
||||
* 根据 orgId 查询启用的健康数据配置
|
||||
*
|
||||
|
||||
+30
@@ -66,6 +66,36 @@ public class THealthDataConfigServiceImpl extends ServiceImpl<THealthDataConfigM
|
||||
return baseMapper.selectPage(pageQuery.buildPage(), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<THealthDataConfig> getEnabledConfigsByCustomerId(Long customerId) {
|
||||
return list(new LambdaQueryWrapper<THealthDataConfig>()
|
||||
.eq(THealthDataConfig::getIsEnabled, 1)
|
||||
.eq(THealthDataConfig::getCustomerId, customerId)
|
||||
.orderByDesc(THealthDataConfig::getWeight));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<THealthDataConfig> getBaseConfigsByCustomerId(Long customerId) {
|
||||
// 定义t_user_health_data主表的基础体征字段(排除复杂的分表数据)
|
||||
List<String> baseMetrics = Arrays.asList(
|
||||
"heart_rate", // 心率
|
||||
"blood_oxygen", // 血氧
|
||||
"temperature", // 体温
|
||||
"pressure_high", // 收缩压
|
||||
"pressure_low", // 舒张压
|
||||
"step", // 步数
|
||||
"stress", // 压力
|
||||
"calorie", // 卡路里
|
||||
"distance" // 距离
|
||||
);
|
||||
|
||||
return list(new LambdaQueryWrapper<THealthDataConfig>()
|
||||
.eq(THealthDataConfig::getIsEnabled, 1)
|
||||
.eq(THealthDataConfig::getCustomerId, customerId)
|
||||
.in(THealthDataConfig::getDataType, baseMetrics)
|
||||
.orderByDesc(THealthDataConfig::getWeight));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<THealthDataConfig> getEnabledConfigsByOrgId(Long orgId) {
|
||||
// 获取顶级部门ID用于查询配置
|
||||
|
||||
Reference in New Issue
Block a user