|
@@ -1,25 +1,33 @@
|
|
|
package com.fs.his.service.impl;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
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.utils.StringUtils;
|
|
|
import com.fs.his.config.HealthIndicatorConfig;
|
|
|
-import lombok.val;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import com.fs.his.mapper.FsUserHealthDataMapper;
|
|
|
import com.fs.his.domain.FsUserHealthData;
|
|
|
+import com.fs.his.domain.FsUserHealthProfile;
|
|
|
+import com.fs.his.domain.FsUserInfo;
|
|
|
+import com.fs.his.enums.HealthDataLevelEnum;
|
|
|
+import com.fs.his.enums.HealthDataTypeEnum;
|
|
|
+import com.fs.his.mapper.FsUserHealthDataMapper;
|
|
|
import com.fs.his.service.IFsUserHealthDataService;
|
|
|
+import com.fs.his.service.IFsUserHealthProfileService;
|
|
|
+import com.fs.his.service.IFsUserInfoService;
|
|
|
+import com.fs.system.domain.SysConfig;
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 用户身体检测数据Service业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author fs
|
|
|
* @date 2025-08-27
|
|
|
*/
|
|
@@ -30,117 +38,119 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
- private static final String HEALTH_INDICATOR_KEY = "his.healthIndexConfig:";
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsUserInfoService fsUserInfoService;
|
|
|
+ @Autowired
|
|
|
+ private IFsUserHealthProfileService fsUserHealthProfileService;
|
|
|
+
|
|
|
+ private static final String HEALTH_INDICATOR_KEY = "his.healthIndexConfig";
|
|
|
+
|
|
|
/**
|
|
|
* 查询用户身体检测数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 用户身体检测数据主键
|
|
|
* @return 用户身体检测数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public FsUserHealthData selectFsUserHealthDataById(String id)
|
|
|
- {
|
|
|
+ public FsUserHealthData selectFsUserHealthDataById(String id) {
|
|
|
return baseMapper.selectFsUserHealthDataById(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询用户身体检测数据列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param fsUserHealthData 用户身体检测数据
|
|
|
* @return 用户身体检测数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<FsUserHealthData> selectFsUserHealthDataList(FsUserHealthData fsUserHealthData)
|
|
|
- {
|
|
|
+ public List<FsUserHealthData> selectFsUserHealthDataList(FsUserHealthData fsUserHealthData) {
|
|
|
return baseMapper.selectFsUserHealthDataList(fsUserHealthData);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增用户身体检测数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param fsUserHealthData 用户身体检测数据
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertFsUserHealthData(FsUserHealthData fsUserHealthData)
|
|
|
- {
|
|
|
+ public int insertFsUserHealthData(FsUserHealthData fsUserHealthData) {
|
|
|
return baseMapper.insertFsUserHealthData(fsUserHealthData);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改用户身体检测数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param fsUserHealthData 用户身体检测数据
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateFsUserHealthData(FsUserHealthData fsUserHealthData)
|
|
|
- {
|
|
|
+ public int updateFsUserHealthData(FsUserHealthData fsUserHealthData) {
|
|
|
return baseMapper.updateFsUserHealthData(fsUserHealthData);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除用户身体检测数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param ids 需要删除的用户身体检测数据主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteFsUserHealthDataByIds(String[] ids)
|
|
|
- {
|
|
|
+ public int deleteFsUserHealthDataByIds(String[] ids) {
|
|
|
return baseMapper.deleteFsUserHealthDataByIds(ids);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除用户身体检测数据信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 用户身体检测数据主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteFsUserHealthDataById(String id)
|
|
|
- {
|
|
|
+ public int deleteFsUserHealthDataById(String id) {
|
|
|
return baseMapper.deleteFsUserHealthDataById(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Description: 解析健康指标
|
|
|
- * @Param: []
|
|
|
- * @Return: java.util.Map<java.lang.String,java.lang.Object>
|
|
|
+ * @Param: []
|
|
|
+ * @Return: java.util.Map<java.lang.String, java.lang.Object>
|
|
|
* @Author xgb
|
|
|
* @Date 2025/8/28 9:10
|
|
|
*/
|
|
|
- @Override
|
|
|
- public HealthIndicatorConfig parseHealthIndicator() {
|
|
|
+ private HealthIndicatorConfig parseHealthIndicator() {
|
|
|
+ String configKey = Constants.SYS_CONFIG_KEY + HEALTH_INDICATOR_KEY;
|
|
|
String str = redisCache.getCacheObject(Constants.SYS_CONFIG_KEY + HEALTH_INDICATOR_KEY);
|
|
|
// str JSON串转 map
|
|
|
- if(StringUtils.isEmpty(str)){
|
|
|
- throw new RuntimeException("健康指标配置不存在,请联系管理人员");
|
|
|
+ if (StringUtils.isEmpty(str)) {
|
|
|
+ // 查询sys_config表配置
|
|
|
+ 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("健康指标配置不存在,请联系管理人员");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 解析健康指标JSON 放入HealthIndicatorConfig
|
|
|
return HealthIndicatorConfig.fromJson(str);
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- // 解析健康指标JSON 放入map对象
|
|
|
- String str="{\"bloodGlucose\":{\"fasting\":{\"normal\":\"3.9~6.1\"},\"post1Hour\":{\"normal\":\"<11.1\"},\"post2Hour\":{\"normal\":\"<7.8\"},\"severity\":[{\"level\":\"normal\",\"range\":\"<6.1\",\"description\":\"\"},{\"level\":\"mild\",\"range\":\"6.1~7.0\",\"description\":\"\"},{\"level\":\"severe\",\"range\":\"≥7.0\",\"description\":\"\"}]},\"bloodPressure\":{\"protection\":{\"systolic\":\"\",\"diastolic\":\"\"},\"severity\":[{\"level\":\"normal\",\"type\":\"systolic\",\"range\":\"<120\",\"description\":\"\"},{\"level\":\"mild\",\"type\":\"systolic\",\"range\":\"120~139\",\"description\":\"\"},{\"level\":\"severe\",\"type\":\"systolic\",\"range\":\"≥140\",\"description\":\"\"},{\"level\":\"normal\",\"type\":\"diastolic\",\"range\":\"<80\",\"description\":\"\"},{\"level\":\"mild\",\"type\":\"diastolic\",\"range\":\"80~89\",\"description\":\"\"},{\"level\":\"severe\",\"type\":\"diastolic\",\"range\":\"≥90\",\"description\":\"\"}]},\"uricAcid\":{\"activeGender\":\"male\",\"male\":[{\"level\":\"normal\",\"range\":\"<420\",\"description\":\"\"},{\"level\":\"poor\",\"range\":\"420~480\",\"description\":\"\"},{\"level\":\"highRisk\",\"range\":\">480\",\"description\":\"\"}],\"female\":[{\"level\":\"normal\",\"range\":\"<360\",\"description\":\"\"},{\"level\":\"poor\",\"range\":\"360~420\",\"description\":\"\"},{\"level\":\"highRisk\",\"range\":\">420\",\"description\":\"\"}]},\"bmi\":{\"severity\":[{\"level\":\"normal\",\"range\":\"18.5~23.9\",\"description\":\"\"},{\"level\":\"mild\",\"range\":\"<18.5\",\"description\":\"\"},{\"level\":\"severe\",\"range\":\"≥24.0\",\"description\":\"\"}]}}";
|
|
|
-
|
|
|
- HealthIndicatorConfig config = HealthIndicatorConfig.fromJson(str);
|
|
|
- System.out.println(getHealthIndicatorValue(config, "bloodGlucose", "fasting", "normal"));
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取健康指标值
|
|
|
- * @param config 健康指标配置对象
|
|
|
- * @param type 指标类型 (bloodGlucose 血糖, bloodPressure 血压, uricAcid 血酸(分男女), bmi 胖瘦)
|
|
|
- * @param key 指标键值 (bloodGlucose使用(fasting 正常, post1Hour 饭后一小时, post2Hour 饭后两小时 )血酸(male 男性 female 女性) severity 等)
|
|
|
- * @param level 指标级别 (normal 正常, mild 轻微, severe 严重 等)
|
|
|
+ *
|
|
|
+ * @param config 健康指标配置对象
|
|
|
+ * @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 static String getHealthIndicatorValue(HealthIndicatorConfig config, String type, String key, String level, String subType) {
|
|
|
+ private String getHealthIndicatorValue(HealthIndicatorConfig config, String type, String key, String level, String subType) {
|
|
|
if (config == null) {
|
|
|
throw new RuntimeException("健康指标配置不存在,请联系管理人员");
|
|
|
}
|
|
@@ -188,10 +198,8 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
|
|
|
case "uricAcid":
|
|
|
Map<String, Object> uricAcid = config.getUricAcid();
|
|
|
- if ("severity".equals(key)) {
|
|
|
- // 根据性别获取尿酸范围
|
|
|
- String activeGender = (String) uricAcid.get("activeGender");
|
|
|
- List<Map<String, Object>> genderList = (List<Map<String, Object>>) uricAcid.get(activeGender);
|
|
|
+ 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) {
|
|
|
if (level.equals(severity.get("level"))) {
|
|
@@ -199,17 +207,10 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- // 直接根据指定性别获取尿酸范围
|
|
|
- if (subType != null && ("male".equals(subType) || "female".equals(subType))) {
|
|
|
- List<Map<String, Object>> genderList = (List<Map<String, Object>>) uricAcid.get(subType);
|
|
|
- if (genderList != null) {
|
|
|
- for (Map<String, Object> severity : genderList) {
|
|
|
- if (level.equals(severity.get("level"))) {
|
|
|
- return (String) severity.get("range");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ } else{
|
|
|
+ Map<String, Object> keyMap = (Map<String, Object>) uricAcid.get(key);
|
|
|
+ if (keyMap != null) {
|
|
|
+ return (String) keyMap.get(level);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -239,17 +240,277 @@ public class FsUserHealthDataServiceImpl extends ServiceImpl<FsUserHealthDataMap
|
|
|
|
|
|
/**
|
|
|
* 获取健康指标值 (重载方法,用于不需要subType的场景)
|
|
|
+ *
|
|
|
* @param config 健康指标配置对象
|
|
|
- * @param type 指标类型
|
|
|
- * @param key 指标键值
|
|
|
- * @param level 指标级别
|
|
|
+ * @param type 指标类型
|
|
|
+ * @param key 指标键值
|
|
|
+ * @param level 指标级别
|
|
|
* @return 指标值
|
|
|
*/
|
|
|
- private static String getHealthIndicatorValue(HealthIndicatorConfig config, String type, String key, String level) {
|
|
|
+ private String getHealthIndicatorValue(HealthIndicatorConfig config, String type, String key, String level) {
|
|
|
return getHealthIndicatorValue(config, type, key, level, null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Description: 获取健康指标级别 根据测量值判断指标级别
|
|
|
+ * @Param: [fsUserHealthData]
|
|
|
+ * @Return: int 0 表示正常,1 表示轻度,2 表示重度 3 异常数据(不在测量值范围内)
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2025/8/28 17:19
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int getHealthIndicatorLevel(FsUserHealthData fsUserHealthData) {
|
|
|
+ HealthIndicatorConfig config = parseHealthIndicator();
|
|
|
+
|
|
|
+ HealthDataTypeEnum dataType = HealthDataTypeEnum.getEnumByKey(fsUserHealthData.getMeasurementType());
|
|
|
+ if (dataType == null) {
|
|
|
+ throw new RuntimeException("不支持的健康指标类型: " + fsUserHealthData.getMeasurementType());
|
|
|
+ }
|
|
|
|
|
|
+ // 定义健康级别的优先级顺序和对应常量
|
|
|
+ String[] levels = {HealthIndicatorConfig.NORMAL, HealthIndicatorConfig.MILD, HealthIndicatorConfig.SEVERE};
|
|
|
+ int[] levelValues = {0, 1, 2};
|
|
|
+
|
|
|
+ BigDecimal userValue = fsUserHealthData.getValue1();
|
|
|
+
|
|
|
+ // 根据不同的测量类型处理
|
|
|
+ switch (dataType) {
|
|
|
+ case GLUCOSE: // 血糖
|
|
|
+ case BMI: // BMI指标(胖瘦)
|
|
|
+ // 遍历各个健康级别,检查用户数据是否符合该级别范围
|
|
|
+ for (int i = 0; i < levels.length; i++) {
|
|
|
+ String rule = getHealthIndicatorValue(config, dataType.getType(), HealthIndicatorConfig.SEVERITY, levels[i]);
|
|
|
+ if (isContain(rule, userValue)) {
|
|
|
+ return levelValues[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果没有匹配的级别,则返回异常数据
|
|
|
+ return HealthDataLevelEnum.EXCEPTION.getValue();
|
|
|
+ case BLOOD_PRESSURE: // 血压
|
|
|
+ // 血压判断 从严重,轻微,正常顺序判断 只要收缩压和舒张压其中一个符合该级别范围,则返回该级别
|
|
|
+ // 获取血压的子类型
|
|
|
+ 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];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果没有匹配的级别,则返回异常数据
|
|
|
+ return HealthDataLevelEnum.EXCEPTION.getValue();
|
|
|
+ // 可以继续添加其他类型,如血压、尿酸等
|
|
|
+ case URIC_ACID:
|
|
|
+ // 判断性别 0-男 1-女
|
|
|
+ String sex = fsUserHealthData.getSex();
|
|
|
+ String key;
|
|
|
+
|
|
|
+ if ("0".equals(sex)) { // 男
|
|
|
+ key = HealthIndicatorConfig.MALE;
|
|
|
+ } else if ("1".equals(sex)) { // 女
|
|
|
+ key = HealthIndicatorConfig.FEMALE;
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("不支持的性别类型: " + sex);
|
|
|
+ }
|
|
|
+ for (int i = 0; i < levels.length; i++) {
|
|
|
+ String rule = getHealthIndicatorValue(config, dataType.getType(), key, levels[i]);
|
|
|
+ if (isContain(rule, userValue)) {
|
|
|
+ return levelValues[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ // 如果没有匹配的级别,则返回异常数据
|
|
|
+ return HealthDataLevelEnum.EXCEPTION.getValue();
|
|
|
+ default:
|
|
|
+ throw new RuntimeException("未实现的健康指标类型处理: " + dataType.getType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 根据身高体重计算BMI
|
|
|
+ * @Param: height 身高cm weight 体重kg
|
|
|
+ * @Return: BMI值
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2025/8/29 11:00
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BigDecimal calculateBMI(BigDecimal height, BigDecimal weight) {
|
|
|
+ if (height == null || weight == null) {
|
|
|
+ throw new IllegalArgumentException("身高和体重不能为空");
|
|
|
+ }
|
|
|
|
|
|
+ if (height.compareTo(BigDecimal.ZERO) <= 0 || weight.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw new IllegalArgumentException("身高和体重必须大于0");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将身高从厘米转换为米 (除以100)
|
|
|
+ BigDecimal heightInMeter = height.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ // 计算BMI: 体重(kg) / 身高²(m²)
|
|
|
+ return weight.divide(heightInMeter.multiply(heightInMeter), 1, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 初始化健康档案时登记初始化用户健康数据
|
|
|
+ * @Param: fsUserHealthProfile
|
|
|
+ * @Return:
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2025/8/29 13:37
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void initHealthData(FsUserHealthProfile fsUserHealthProfile) {
|
|
|
+ // 查询档案信息获取登记时间
|
|
|
+ fsUserHealthProfile = fsUserHealthProfileService.selectFsUserHealthProfileByUserId(fsUserHealthProfile.getUserId());
|
|
|
+ if(fsUserHealthProfile==null){
|
|
|
+ throw new RuntimeException("用户健康档案不存在");
|
|
|
+ }
|
|
|
+ // 第一次登记档案的时候 若存在身高体重 BMI 则进行BMI等级判断
|
|
|
+ FsUserHealthData fsUserHealthData=new FsUserHealthData();
|
|
|
+ fsUserHealthData.setUserId(fsUserHealthProfile.getUserId());
|
|
|
+ fsUserHealthData.setMeasurementDate(fsUserHealthProfile.getCreatedTime());
|
|
|
+ fsUserHealthData.setMeasurementTime(fsUserHealthProfile.getCreatedTime());
|
|
|
+ // 若存在身高体重 则登记BMI测量值
|
|
|
+ if(fsUserHealthProfile.getHeight()!=null && fsUserHealthProfile.getWeight()!=null){
|
|
|
+ // 计算BMI值
|
|
|
+ BigDecimal bmi=calculateBMI(fsUserHealthProfile.getHeight(),fsUserHealthProfile.getWeight());
|
|
|
+ // 计算BMI等级
|
|
|
+ /** 测量类型(0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI) */
|
|
|
+ fsUserHealthData.setMeasurementType(HealthDataTypeEnum.BMI.getValue());
|
|
|
+ fsUserHealthData.setValue1(bmi);
|
|
|
+ int healthIndicatorLevel = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
+ fsUserHealthData.setValue1(fsUserHealthProfile.getHeight());
|
|
|
+ fsUserHealthData.setValue2(fsUserHealthProfile.getWeight());
|
|
|
+ fsUserHealthData.setLevel(healthIndicatorLevel);
|
|
|
+
|
|
|
+ if (insertFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
+ throw new RuntimeException("BMI数据登记失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 若存在腰围
|
|
|
+ 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("腰围数据登记失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 若存在臀围
|
|
|
+ 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("臀围数据登记失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 若存在血压
|
|
|
+ if(fsUserHealthProfile.getSystolicPressure()!=null && fsUserHealthProfile.getDiastolicPressure()!=null){
|
|
|
+
|
|
|
+ /** 测量类型(0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI) */
|
|
|
+ fsUserHealthData.setMeasurementType(HealthDataTypeEnum.BLOOD_PRESSURE.getValue());
|
|
|
+ fsUserHealthData.setValue1(fsUserHealthProfile.getSystolicPressure());
|
|
|
+ fsUserHealthData.setValue2(fsUserHealthProfile.getDiastolicPressure());
|
|
|
+ int healthIndicatorLevel = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
+ fsUserHealthData.setLevel(healthIndicatorLevel);
|
|
|
+ if (insertFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
+ throw new RuntimeException("血压数据登记失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 若存在血糖
|
|
|
+ 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("血糖数据登记失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 若存在尿酸
|
|
|
+ if(fsUserHealthProfile.getHyperuricemiaValue()!=null){
|
|
|
+ // 查询用户信息获取 性别
|
|
|
+ FsUserInfo fsUserInfo=fsUserInfoService.selectFsUserInfoById(fsUserHealthProfile.getUserId());
|
|
|
+ if(fsUserInfo== null|| StringUtils.isEmpty(fsUserInfo.getSex())){
|
|
|
+ throw new RuntimeException("无法获取用户性别,请完善用户信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 测量类型(0-腰围,1-臀围,2-血糖,3-血压,4-尿酸 5-BMI) */
|
|
|
+ fsUserHealthData.setMeasurementType(HealthDataTypeEnum.URIC_ACID.getValue());
|
|
|
+ fsUserHealthData.setValue1(fsUserHealthProfile.getHyperuricemiaValue());
|
|
|
+ fsUserHealthData.setSex(fsUserInfo.getSex());
|
|
|
+ int healthIndicatorLevel = getHealthIndicatorLevel(fsUserHealthData);
|
|
|
+ fsUserHealthData.setLevel(healthIndicatorLevel);
|
|
|
+ if (insertFsUserHealthData(fsUserHealthData) <= 0) {
|
|
|
+ throw new RuntimeException("尿酸数据登记失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断value1是否在value规则范围内
|
|
|
+ *
|
|
|
+ * @param value 规则字符串,如 "0~100"、"<100"、"≤100"、">100"、"≥100"
|
|
|
+ * @param value1 实际测量值
|
|
|
+ * @return 是否在范围内
|
|
|
+ */
|
|
|
+ private static Boolean isContain(String value, BigDecimal value1) {
|
|
|
+ if (value == null || value1 == null) {
|
|
|
+ throw new RuntimeException("参数不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理范围值 "0~100"
|
|
|
+ if (value.contains("~")) {
|
|
|
+ String[] parts = value.split("~");
|
|
|
+ if (parts.length != 2) {
|
|
|
+ throw new RuntimeException("无效的范围值格式: " + value);
|
|
|
+ }
|
|
|
+ BigDecimal lower = new BigDecimal(parts[0]);
|
|
|
+ BigDecimal upper = new BigDecimal(parts[1]);
|
|
|
+ return value1.compareTo(lower) >= 0 && value1.compareTo(upper) <= 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理小于 "<100"
|
|
|
+ if (value.startsWith("<")) {
|
|
|
+ BigDecimal threshold = new BigDecimal(value.substring(1));
|
|
|
+ return value1.compareTo(threshold) < 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理小于等于 "≤100"
|
|
|
+ if (value.startsWith("≤")) {
|
|
|
+ BigDecimal threshold = new BigDecimal(value.substring(1));
|
|
|
+ return value1.compareTo(threshold) <= 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理大于 ">100"
|
|
|
+ if (value.startsWith(">")) {
|
|
|
+ BigDecimal threshold = new BigDecimal(value.substring(1));
|
|
|
+ return value1.compareTo(threshold) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理大于等于 "≥100"
|
|
|
+ if (value.startsWith("≥")) {
|
|
|
+ BigDecimal threshold = new BigDecimal(value.substring(2));
|
|
|
+ return value1.compareTo(threshold) >= 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 尝试直接转换为数字进行比较
|
|
|
+ try {
|
|
|
+ BigDecimal threshold = new BigDecimal(value);
|
|
|
+ return value1.compareTo(threshold) == 0;
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new RuntimeException("不支持的指标值规则: " + value + ";请联系管理员处理");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|