|
@@ -2,8 +2,8 @@ package com.fs.his.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.common.constant.Constants;
|
|
|
-import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.his.config.HealthIndicatorConfig;
|
|
|
import com.fs.his.domain.FsUserHealthData;
|
|
@@ -48,16 +48,6 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
|
|
|
private static final String HEALTH_INDICATOR_KEY = "his.healthIndexConfig";
|
|
|
|
|
|
- /**
|
|
|
- * 查询用户身体检测数据
|
|
|
- *
|
|
|
- * @param id 用户身体检测数据主键
|
|
|
- * @return 用户身体检测数据
|
|
|
- */
|
|
|
- @Override
|
|
|
- public FsUserHealthData selectFsUserHealthDataById(String id) {
|
|
|
- return baseMapper.selectFsUserHealthDataById(id);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 查询用户身体检测数据列表
|
|
@@ -70,6 +60,19 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
return baseMapper.selectFsUserHealthDataList(fsUserHealthData);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Description: 查询用户身体检测数据列表 获取数量
|
|
|
+ * @Param:
|
|
|
+ * @Return:
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2025/9/1 14:58
|
|
|
+ */
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int selectFsUserHealthDataListCount(FsUserHealthData fsUserHealthData) {
|
|
|
+ return baseMapper.selectFsUserHealthDataListCount(fsUserHealthData);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增用户身体检测数据
|
|
|
*
|
|
@@ -93,27 +96,131 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 批量删除用户身体检测数据
|
|
|
+ * 删除用户身体检测数据信息
|
|
|
*
|
|
|
- * @param ids 需要删除的用户身体检测数据主键
|
|
|
+ * @param id 用户身体检测数据主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteFsUserHealthDataByIds(String[] ids) {
|
|
|
- return baseMapper.deleteFsUserHealthDataByIds(ids);
|
|
|
+ public int deleteFsUserHealthDataById(Long id) {
|
|
|
+ return baseMapper.deleteFsUserHealthDataById(id);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 删除用户身体检测数据信息
|
|
|
- *
|
|
|
- * @param id 用户身体检测数据主键
|
|
|
- * @return 结果
|
|
|
+ * @Description: 查询用户身体检测最新数据
|
|
|
+ * @Param:
|
|
|
+ * @Return:
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2025/8/29 17:48
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteFsUserHealthDataById(String id) {
|
|
|
- return baseMapper.deleteFsUserHealthDataById(id);
|
|
|
+ public FsUserHealthData selectFsUserHealthDataByUserId(FsUserHealthData fsUserHealthData) {
|
|
|
+
|
|
|
+ return baseMapper.selectFsUserHealthDataByUserId(fsUserHealthData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 查询用户身体检测数据详情
|
|
|
+ * @Param:
|
|
|
+ * @Return:
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2025/8/29 17:48
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public FsUserHealthData selectFsUserHealthDataById(Long Id) {
|
|
|
+ return baseMapper.selectFsUserHealthDataById(Id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 更新用户身体检测数据
|
|
|
+ * @Param: fsUserHealthData
|
|
|
+ * @Return:
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2025/9/1 10:50
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateFsUserHealthDataAndLevel(FsUserHealthData fsUserHealthData) {
|
|
|
+ // 优化后的代码
|
|
|
+ int type = fsUserHealthData.getMeasurementType();
|
|
|
+ boolean hasValue1 = fsUserHealthData.getValue1() != null;
|
|
|
+ boolean hasValue2 = fsUserHealthData.getValue2() != null;
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case 3: // 血压
|
|
|
+ case 5: // BMI
|
|
|
+ // 参数校验: 血压和BMI的Value1和Value2必须同时有值或同时没值
|
|
|
+ if (hasValue1 != hasValue2) {
|
|
|
+ throw new ServiceException("血压和BMI必须同时有值或同时没值");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hasValue1 && hasValue2) {
|
|
|
+ if (type == 3) { // 血压
|
|
|
+ // 计算测量值对应等级
|
|
|
+ int level = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
+ fsUserHealthData.setLevel(level);
|
|
|
+ } else { // BMI
|
|
|
+ // 保存原始value1
|
|
|
+ BigDecimal originalValue1 = fsUserHealthData.getValue1();
|
|
|
+ // 计算BMI
|
|
|
+ BigDecimal bmi = calculateBMI(fsUserHealthData.getValue1(), fsUserHealthData.getValue2());
|
|
|
+ fsUserHealthData.setValue1(bmi);
|
|
|
+ // 计算测量值对应等级
|
|
|
+ int level = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
+ fsUserHealthData.setLevel(level);
|
|
|
+ // 恢复原始value1
|
|
|
+ fsUserHealthData.setValue1(originalValue1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 更新用户身体检测数据信息
|
|
|
+ if (updateFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
+ throw new ServiceException("用户身体检测数据修改失败");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0: // 腰围
|
|
|
+ case 1: // 臀围
|
|
|
+ // 更新用户身体检测数据信息
|
|
|
+ if (updateFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
+ throw new ServiceException("用户身体检测数据修改失败");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 2: // 血糖
|
|
|
+ // 计算测量值对应等级
|
|
|
+ int level = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
+ fsUserHealthData.setLevel(level);
|
|
|
+ // 更新用户身体检测数据信息
|
|
|
+ if (updateFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
+ throw new ServiceException("用户身体检测数据修改失败");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 4: // 尿酸
|
|
|
+ // 根据userId查询用户信息
|
|
|
+ FsUserInfo user = fsUserInfoService.selectFsUserInfoById(fsUserHealthData.getUserId());
|
|
|
+ if (StringUtils.isEmpty(user.getSex()) || "2".equals(user.getSex())) {
|
|
|
+ throw new ServiceException("尿酸判断需要性别信息,请完善用户性别信息");
|
|
|
+ }
|
|
|
+ fsUserHealthData.setSex(user.getSex());
|
|
|
+ // 计算测量值对应等级
|
|
|
+ int uricLevel = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
+ fsUserHealthData.setLevel(uricLevel);
|
|
|
+ // 更新用户身体检测数据信息
|
|
|
+ if (updateFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
+ throw new ServiceException("用户身体检测数据修改失败");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ throw new ServiceException("不支持的测量类型");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 解析健康指标
|
|
|
* @Param: []
|
|
@@ -127,12 +234,12 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
// str JSON串转 map
|
|
|
if (StringUtils.isEmpty(str)) {
|
|
|
// 查询sys_config表配置
|
|
|
- SysConfig config=configService.selectConfigByConfigKey(HEALTH_INDICATOR_KEY);
|
|
|
+ SysConfig config = configService.selectConfigByConfigKey(HEALTH_INDICATOR_KEY);
|
|
|
if (config != null && StringUtils.isNotEmpty(config.getConfigValue())) {
|
|
|
redisCache.setCacheObject(configKey, config.getConfigValue());
|
|
|
return HealthIndicatorConfig.fromJson(config.getConfigValue());
|
|
|
- }else {
|
|
|
- throw new RuntimeException("健康指标配置不存在,请联系管理人员");
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("健康指标配置不存在,请联系管理人员");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -144,15 +251,15 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
* 获取健康指标值
|
|
|
*
|
|
|
* @param config 健康指标配置对象
|
|
|
- * @param type 指标类型 (bloodGlucose 血糖, bloodPressure 血压, uricAcid 血酸(分男女), bmi 胖瘦)
|
|
|
- * @param key 指标键值 (bloodGlucose使用(fasting 正常, post1Hour 饭后一小时, post2Hour 饭后两小时 )血酸(male 男性 female 女性) severity 等)
|
|
|
+ * @param type 指标类型 (bloodGlucose 血糖, bloodPressure 血压, uricAcid 尿酸(分男女), bmi 胖瘦)
|
|
|
+ * @param key 指标键值 (bloodGlucose使用(fasting 正常, post1Hour 饭后一小时, post2Hour 饭后两小时 )尿酸(male 男性 female 女性) severity 等)
|
|
|
* @param level 指标级别 (normal 正常, mild 轻微, severe 严重 等)
|
|
|
* @param subType 子类型 (bloodPressure时使用,systolic 收缩压, diastolic 舒张压)
|
|
|
* @return 指标值
|
|
|
*/
|
|
|
private String getHealthIndicatorValue(HealthIndicatorConfig config, String type, String key, String level, String subType) {
|
|
|
if (config == null) {
|
|
|
- throw new RuntimeException("健康指标配置不存在,请联系管理人员");
|
|
|
+ throw new ServiceException("健康指标配置不存在,请联系管理人员");
|
|
|
}
|
|
|
|
|
|
try {
|
|
@@ -198,7 +305,7 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
|
|
|
case "uricAcid":
|
|
|
Map<String, Object> uricAcid = config.getUricAcid();
|
|
|
- if("male".equals(key)||"female".equals(key)){
|
|
|
+ if ("male".equals(key) || "female".equals(key)) {
|
|
|
List<Map<String, Object>> genderList = (List<Map<String, Object>>) uricAcid.get(key);
|
|
|
if (genderList != null) {
|
|
|
for (Map<String, Object> severity : genderList) {
|
|
@@ -207,7 +314,7 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } else{
|
|
|
+ } else {
|
|
|
Map<String, Object> keyMap = (Map<String, Object>) uricAcid.get(key);
|
|
|
if (keyMap != null) {
|
|
|
return (String) keyMap.get(level);
|
|
@@ -229,10 +336,10 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
- throw new RuntimeException("不支持的健康指标类型: " + type);
|
|
|
+ throw new ServiceException("不支持的健康指标类型: " + type);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- throw new RuntimeException("获取健康指标值失败: " + e.getMessage());
|
|
|
+ throw new ServiceException("获取健康指标值失败: " + e.getMessage());
|
|
|
}
|
|
|
|
|
|
return null;
|
|
@@ -264,7 +371,7 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
|
|
|
HealthDataTypeEnum dataType = HealthDataTypeEnum.getEnumByKey(fsUserHealthData.getMeasurementType());
|
|
|
if (dataType == null) {
|
|
|
- throw new RuntimeException("不支持的健康指标类型: " + fsUserHealthData.getMeasurementType());
|
|
|
+ throw new ServiceException("不支持的健康指标类型: " + fsUserHealthData.getMeasurementType());
|
|
|
}
|
|
|
|
|
|
// 定义健康级别的优先级顺序和对应常量
|
|
@@ -292,11 +399,16 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
String[] subTypes = {HealthIndicatorConfig.SYSTOLIC, HealthIndicatorConfig.DIASTOLIC};
|
|
|
// 遍历各个健康级别,检查用户数据是否符合该级别范围
|
|
|
for (int i = 2; i >= 0; i--) {
|
|
|
- for (String subType : subTypes) {
|
|
|
- String rule = getHealthIndicatorValue(config, dataType.getType(), HealthIndicatorConfig.SEVERITY, levels[i], subType);
|
|
|
- if (isContain(rule, userValue)) {
|
|
|
- return levelValues[i];
|
|
|
- }
|
|
|
+ // 判断收缩压
|
|
|
+ String rule = getHealthIndicatorValue(config, dataType.getType(), HealthIndicatorConfig.SEVERITY, levels[i], subTypes[0]);
|
|
|
+ if (isContain(rule, userValue)) {
|
|
|
+ return levelValues[i];
|
|
|
+ }
|
|
|
+ // 判断舒张压
|
|
|
+ BigDecimal userValue2 = fsUserHealthData.getValue2();
|
|
|
+ rule = getHealthIndicatorValue(config, dataType.getType(), HealthIndicatorConfig.SEVERITY, levels[i], subTypes[1]);
|
|
|
+ if (isContain(rule, userValue2)) {
|
|
|
+ return levelValues[i];
|
|
|
}
|
|
|
}
|
|
|
// 如果没有匹配的级别,则返回异常数据
|
|
@@ -312,7 +424,7 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
} else if ("1".equals(sex)) { // 女
|
|
|
key = HealthIndicatorConfig.FEMALE;
|
|
|
} else {
|
|
|
- throw new RuntimeException("不支持的性别类型: " + sex);
|
|
|
+ throw new ServiceException("不支持的性别类型: " + sex);
|
|
|
}
|
|
|
for (int i = 0; i < levels.length; i++) {
|
|
|
String rule = getHealthIndicatorValue(config, dataType.getType(), key, levels[i]);
|
|
@@ -324,7 +436,7 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
// 如果没有匹配的级别,则返回异常数据
|
|
|
return HealthDataLevelEnum.EXCEPTION.getValue();
|
|
|
default:
|
|
|
- throw new RuntimeException("未实现的健康指标类型处理: " + dataType.getType());
|
|
|
+ throw new ServiceException("未实现的健康指标类型处理: " + dataType.getType());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -354,7 +466,7 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
|
|
|
/**
|
|
|
* @Description: 初始化健康档案时登记初始化用户健康数据
|
|
|
- * @Param: fsUserHealthProfile
|
|
|
+ * @Param: fsUserHealthProfile
|
|
|
* @Return:
|
|
|
* @Author xgb
|
|
|
* @Date 2025/8/29 13:37
|
|
@@ -363,18 +475,18 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
public void initHealthData(FsUserHealthProfile fsUserHealthProfile) {
|
|
|
// 查询档案信息获取登记时间
|
|
|
fsUserHealthProfile = fsUserHealthProfileService.selectFsUserHealthProfileByUserId(fsUserHealthProfile.getUserId());
|
|
|
- if(fsUserHealthProfile==null){
|
|
|
- throw new RuntimeException("用户健康档案不存在");
|
|
|
+ if (fsUserHealthProfile == null) {
|
|
|
+ throw new ServiceException("用户健康档案不存在");
|
|
|
}
|
|
|
// 第一次登记档案的时候 若存在身高体重 BMI 则进行BMI等级判断
|
|
|
- FsUserHealthData fsUserHealthData=new FsUserHealthData();
|
|
|
+ FsUserHealthData fsUserHealthData = new FsUserHealthData();
|
|
|
fsUserHealthData.setUserId(fsUserHealthProfile.getUserId());
|
|
|
fsUserHealthData.setMeasurementDate(fsUserHealthProfile.getCreatedTime());
|
|
|
fsUserHealthData.setMeasurementTime(fsUserHealthProfile.getCreatedTime());
|
|
|
// 若存在身高体重 则登记BMI测量值
|
|
|
- if(fsUserHealthProfile.getHeight()!=null && fsUserHealthProfile.getWeight()!=null){
|
|
|
+ if (fsUserHealthProfile.getHeight() != null && fsUserHealthProfile.getWeight() != null) {
|
|
|
// 计算BMI值
|
|
|
- BigDecimal bmi=calculateBMI(fsUserHealthProfile.getHeight(),fsUserHealthProfile.getWeight());
|
|
|
+ BigDecimal bmi = calculateBMI(fsUserHealthProfile.getHeight(), fsUserHealthProfile.getWeight());
|
|
|
// 计算BMI等级
|
|
|
/** 测量类型(0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI) */
|
|
|
fsUserHealthData.setMeasurementType(HealthDataTypeEnum.BMI.getValue());
|
|
@@ -385,33 +497,33 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
fsUserHealthData.setLevel(healthIndicatorLevel);
|
|
|
|
|
|
if (insertFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
- throw new RuntimeException("BMI数据登记失败");
|
|
|
+ throw new ServiceException("BMI数据登记失败");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 若存在腰围
|
|
|
- if(fsUserHealthProfile.getWaistCircumference()!=null){
|
|
|
+ if (fsUserHealthProfile.getWaistCircumference() != null) {
|
|
|
/** 测量类型(0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI) */
|
|
|
fsUserHealthData.setMeasurementType(HealthDataTypeEnum.WAIST.getValue());
|
|
|
fsUserHealthData.setValue1(fsUserHealthProfile.getWaistCircumference());
|
|
|
if (insertFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
- throw new RuntimeException("腰围数据登记失败");
|
|
|
+ throw new ServiceException("腰围数据登记失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 若存在臀围
|
|
|
- if(fsUserHealthProfile.getHipCircumference()!=null){
|
|
|
+ if (fsUserHealthProfile.getHipCircumference() != null) {
|
|
|
/** 测量类型(0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI) */
|
|
|
fsUserHealthData.setMeasurementType(HealthDataTypeEnum.HIP.getValue());
|
|
|
fsUserHealthData.setValue1(fsUserHealthProfile.getHipCircumference());
|
|
|
if (insertFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
- throw new RuntimeException("臀围数据登记失败");
|
|
|
+ throw new ServiceException("臀围数据登记失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 若存在血压
|
|
|
- if(fsUserHealthProfile.getSystolicPressure()!=null && fsUserHealthProfile.getDiastolicPressure()!=null){
|
|
|
+ if (fsUserHealthProfile.getSystolicPressure() != null && fsUserHealthProfile.getDiastolicPressure() != null) {
|
|
|
|
|
|
/** 测量类型(0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI) */
|
|
|
fsUserHealthData.setMeasurementType(HealthDataTypeEnum.BLOOD_PRESSURE.getValue());
|
|
@@ -420,28 +532,28 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
int healthIndicatorLevel = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
fsUserHealthData.setLevel(healthIndicatorLevel);
|
|
|
if (insertFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
- throw new RuntimeException("血压数据登记失败");
|
|
|
+ throw new ServiceException("血压数据登记失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 若存在血糖
|
|
|
- if(fsUserHealthProfile.getHyperglycemiaValue()!=null){
|
|
|
+ if (fsUserHealthProfile.getHyperglycemiaValue() != null) {
|
|
|
/** 测量类型(0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI) */
|
|
|
fsUserHealthData.setMeasurementType(HealthDataTypeEnum.GLUCOSE.getValue());
|
|
|
fsUserHealthData.setValue1(fsUserHealthProfile.getHyperglycemiaValue());
|
|
|
int healthIndicatorLevel = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
fsUserHealthData.setLevel(healthIndicatorLevel);
|
|
|
if (insertFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
- throw new RuntimeException("血糖数据登记失败");
|
|
|
+ throw new ServiceException("血糖数据登记失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 若存在尿酸
|
|
|
- if(fsUserHealthProfile.getHyperuricemiaValue()!=null){
|
|
|
+ if (fsUserHealthProfile.getHyperuricemiaValue() != null) {
|
|
|
// 查询用户信息获取 性别
|
|
|
- FsUserInfo fsUserInfo=fsUserInfoService.selectFsUserInfoById(fsUserHealthProfile.getUserId());
|
|
|
- if(fsUserInfo== null|| StringUtils.isEmpty(fsUserInfo.getSex())){
|
|
|
- throw new RuntimeException("无法获取用户性别,请完善用户信息");
|
|
|
+ FsUserInfo fsUserInfo = fsUserInfoService.selectFsUserInfoById(fsUserHealthProfile.getUserId());
|
|
|
+ if (fsUserInfo == null || StringUtils.isEmpty(fsUserInfo.getSex())) {
|
|
|
+ throw new ServiceException("无法获取用户性别,请完善用户信息");
|
|
|
}
|
|
|
|
|
|
/** 测量类型(0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI) */
|
|
@@ -451,11 +563,59 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
int healthIndicatorLevel = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
fsUserHealthData.setLevel(healthIndicatorLevel);
|
|
|
if (insertFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
- throw new RuntimeException("尿酸数据登记失败");
|
|
|
+ throw new ServiceException("尿酸数据登记失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 新增健康各类型数据 0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI
|
|
|
+ * @Param: fsUserHealthData
|
|
|
+ * @Return:
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2025/8/29 16:06
|
|
|
+ */
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addHealthData(FsUserHealthData fsUserHealthData) {
|
|
|
+ int type = fsUserHealthData.getMeasurementType();
|
|
|
+ // 0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI
|
|
|
+ if (type == 4) { // 尿酸查询等级信息时需要性别信息
|
|
|
+ // 根据userId 查询用户信息
|
|
|
+ FsUserInfo user = fsUserInfoService.selectFsUserInfoById(fsUserHealthData.getUserId());
|
|
|
+ if (StringUtils.isEmpty(user.getSex()) || "2".equals(user.getSex())) {
|
|
|
+ throw new ServiceException("尿酸判断需要性别信息,请完善用户性别信息");
|
|
|
}
|
|
|
+ fsUserHealthData.setSex(user.getSex());
|
|
|
+ }
|
|
|
+ // 2-血糖,3-血压,4-尿酸 5-BMI 判断等级
|
|
|
+ if (type == 2 || type == 3 || type == 4) {
|
|
|
+ // 计算测量值对应等级
|
|
|
+ int level = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
+ fsUserHealthData.setLevel(level);
|
|
|
+ } else if (type == 5) {// BMI 需要用身高体重先计算出BMI
|
|
|
+ // 计算BMI
|
|
|
+ BigDecimal value1 = fsUserHealthData.getValue1();
|
|
|
+ fsUserHealthData.setValue1(calculateBMI(fsUserHealthData.getValue1(), fsUserHealthData.getValue2()));
|
|
|
+ // 计算测量值对应等级
|
|
|
+ int level = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
+ fsUserHealthData.setLevel(level);
|
|
|
+ fsUserHealthData.setValue1(value1);
|
|
|
+ }else if (type == 0 || type == 1) {
|
|
|
+ // 获取性别信息
|
|
|
+ FsUserInfo user = fsUserInfoService.selectFsUserInfoById(fsUserHealthData.getUserId());
|
|
|
+ if (user == null || StringUtils.isEmpty(user.getSex())) {
|
|
|
+ throw new ServiceException("无法获取用户性别,请完善用户信息");
|
|
|
+ }
|
|
|
+ fsUserHealthData.setSex(user.getSex());
|
|
|
+ }
|
|
|
+ // 登记检测数据信息
|
|
|
+ if (insertFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
+ throw new ServiceException("新增用户身体检测数据失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 判断value1是否在value规则范围内
|
|
|
*
|
|
@@ -465,14 +625,14 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
*/
|
|
|
private static Boolean isContain(String value, BigDecimal value1) {
|
|
|
if (value == null || value1 == null) {
|
|
|
- throw new RuntimeException("参数不能为空");
|
|
|
+ throw new ServiceException("参数不能为空");
|
|
|
}
|
|
|
|
|
|
// 处理范围值 "0~100"
|
|
|
if (value.contains("~")) {
|
|
|
String[] parts = value.split("~");
|
|
|
if (parts.length != 2) {
|
|
|
- throw new RuntimeException("无效的范围值格式: " + value);
|
|
|
+ throw new ServiceException("无效的范围值格式: " + value);
|
|
|
}
|
|
|
BigDecimal lower = new BigDecimal(parts[0]);
|
|
|
BigDecimal upper = new BigDecimal(parts[1]);
|
|
@@ -499,7 +659,7 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
|
|
|
// 处理大于等于 "≥100"
|
|
|
if (value.startsWith("≥")) {
|
|
|
- BigDecimal threshold = new BigDecimal(value.substring(2));
|
|
|
+ BigDecimal threshold = new BigDecimal(value.substring(1));
|
|
|
return value1.compareTo(threshold) >= 0;
|
|
|
}
|
|
|
|
|
@@ -508,7 +668,7 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
BigDecimal threshold = new BigDecimal(value);
|
|
|
return value1.compareTo(threshold) == 0;
|
|
|
} catch (NumberFormatException e) {
|
|
|
- throw new RuntimeException("不支持的指标值规则: " + value + ";请联系管理员处理");
|
|
|
+ throw new ServiceException("不支持的指标值规则: " + value + ";请联系管理员处理");
|
|
|
}
|
|
|
|
|
|
}
|