|
@@ -20,9 +20,11 @@ import org.dromara.web.domain.bo.NutritionSettingBo;
|
|
|
import org.dromara.web.domain.vo.NutritionSettingVo;
|
|
|
import org.dromara.web.mapper.NutritionSettingMapper;
|
|
|
import org.dromara.web.service.INutritionSettingService;
|
|
|
+import org.dromara.web.service.MetabolicCalculator;
|
|
|
import org.dromara.web.service.NutritionDataUtil;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -169,9 +171,16 @@ public class NutritionSettingServiceImpl implements INutritionSettingService {
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
}
|
|
|
|
|
|
- public Map<String, String> calculateEnergyRequirements(
|
|
|
- String gender, int age, double height, double weight,
|
|
|
- Integer activity, Integer stressType) {
|
|
|
+ public Map<String, String> calculateEnergyRequirements(Integer settingType,
|
|
|
+ String gender, String ageStr, double height, double weight,
|
|
|
+ Integer activity, Integer stressType, BigDecimal burnArea) {
|
|
|
+ Map<String, String> settingTypeMap = Optional.ofNullable(dictDataService.selectMapByType("nutrition_setting_type").getData())
|
|
|
+ .orElseGet(MapUtil::newHashMap)
|
|
|
+ .entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ entry -> entry.getValue().getDictLabel()
|
|
|
+ ));
|
|
|
|
|
|
Map<String, String> activityMap = Optional.ofNullable(dictDataService.selectMapByType("physical_activity").getData())
|
|
|
.orElseGet(MapUtil::newHashMap)
|
|
@@ -191,6 +200,11 @@ public class NutritionSettingServiceImpl implements INutritionSettingService {
|
|
|
));
|
|
|
String activityLevel = null;
|
|
|
String stressLevel = null;
|
|
|
+ Integer age = null;
|
|
|
+ if (null != ageStr) {
|
|
|
+ age = Integer.valueOf(ageStr.substring(0, 2));
|
|
|
+
|
|
|
+ }
|
|
|
if (null != activity) {
|
|
|
activityLevel = activityMap.get(Integer.toString(activity));
|
|
|
}
|
|
@@ -199,67 +213,63 @@ public class NutritionSettingServiceImpl implements INutritionSettingService {
|
|
|
|
|
|
}
|
|
|
|
|
|
- Map<String, String> results = new HashMap<>();
|
|
|
-
|
|
|
- // 1. 计算基础代谢率 (BEE) - 使用毛德倩公式
|
|
|
- double bee;
|
|
|
- if ("男".equals(gender)) {
|
|
|
- bee = 48.5 * weight + 2954.7;
|
|
|
- } else {
|
|
|
- bee = 41.9 * weight + 2869.1;
|
|
|
- }
|
|
|
-
|
|
|
- // 2. 活动系数转换
|
|
|
- double activityFactor = 1.2; // 默认静态
|
|
|
if (null != activityLevel) {
|
|
|
if (activityLevel.contains("低")) {
|
|
|
- activityFactor = 1.375;
|
|
|
+ activityLevel = "低";
|
|
|
} else if (activityLevel.contains("中")) {
|
|
|
- activityFactor = 1.55;
|
|
|
+ activityLevel = "中";
|
|
|
} else if (activityLevel.contains("重")) {
|
|
|
- activityFactor = 1.725;
|
|
|
+ activityLevel = "重";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 3. 应激系数转换
|
|
|
- double stressFactor = 1.0; // 默认基础状态
|
|
|
if (null != stressLevel) {
|
|
|
- if (stressLevel.contains("低度")) {
|
|
|
- stressFactor = 1.1;
|
|
|
- } else if (stressLevel.contains("中度")) {
|
|
|
- stressFactor = 1.2;
|
|
|
+ if (stressLevel.contains("低级")) {
|
|
|
+ stressLevel = "低级";
|
|
|
+ } else if (stressLevel.contains("中级")) {
|
|
|
+ stressLevel = "中级";
|
|
|
} else if (stressLevel.contains("严重")) {
|
|
|
- stressFactor = 1.3;
|
|
|
+ stressLevel = "严重";
|
|
|
} else if (stressLevel.contains("恶性")) {
|
|
|
- stressFactor = 1.4;
|
|
|
+ stressLevel = "恶性肿瘤";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 4. 计算总热量需求 (TDEE)
|
|
|
- double tdeeKcal = bee * activityFactor * stressFactor;
|
|
|
- double tdeeKj = tdeeKcal * 4.184; // 1 kcal = 4.184 kJ
|
|
|
- double kcalPerKg = tdeeKcal / weight;
|
|
|
+ Map<String, String> map = null;
|
|
|
+ if ("BEE".equals(settingTypeMap.get(Integer.toString(settingType)))) {
|
|
|
+ map = MetabolicCalculator.calculateByBEE(gender, age, height, weight, activityLevel, stressLevel);
|
|
|
+ } else if ("DRIS".equals(settingTypeMap.get(Integer.toString(settingType)))) {
|
|
|
+ map = MetabolicCalculator.calculateByDRIS(gender, age, height, weight, activityLevel);
|
|
|
+ } else if ("拇指测法".equals(settingTypeMap.get(Integer.toString(settingType)))) {
|
|
|
+ map = MetabolicCalculator.calculateByThumb(gender, age, height, weight, activityLevel);
|
|
|
+ } else if ("烧伤公式".equals(settingTypeMap.get(Integer.toString(settingType)))) {
|
|
|
+ map = MetabolicCalculator.calculateByBurnFormula(gender, age, height, age, activityLevel, burnArea.doubleValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> results = new HashMap<>();
|
|
|
+
|
|
|
|
|
|
double proteinCaloriePercentage = 20;
|
|
|
double fatCaloriePercentage = 20;
|
|
|
double carbohydrateCaloriePercentage = 50;
|
|
|
|
|
|
// 5. 设置计算结果
|
|
|
- results.put("caloriesKcalPerDay", String.format("%.2f", tdeeKcal));
|
|
|
- results.put("caloriesKjPerDay", String.format("%.2f", tdeeKj));
|
|
|
- results.put("caloriesKcalPerKgDay", String.format("%.2f", kcalPerKg));
|
|
|
+ results.put("caloriesKcalPerDay", map.get("kcal/d"));
|
|
|
+ results.put("caloriesKjPerDay", map.get("kJ/d"));
|
|
|
+ results.put("caloriesKcalPerKgDay", map.get("kcal/kg*d"));
|
|
|
|
|
|
results.put("proteinCaloriePercentage", String.format("%.2f", proteinCaloriePercentage));//蛋白质热量占比
|
|
|
- results.put("proteinGPerKgDay", String.format("%.2f", tdeeKj));
|
|
|
- results.put("proteinGPerDay", String.format("%.2f", kcalPerKg));
|
|
|
+ results.put("proteinGPerKgDay", map.get("kcal/d"));
|
|
|
+ results.put("proteinGPerDay", map.get("kJ/d"));
|
|
|
|
|
|
results.put("fatCaloriePercentage", String.format("%.2f", fatCaloriePercentage));//脂肪热量占比
|
|
|
- results.put("fatGPerKgDay", String.format("%.2f", kcalPerKg));
|
|
|
- results.put("fatGPerDay", String.format("%.2f", tdeeKj));
|
|
|
+ results.put("fatGPerKgDay", map.get("kJ/d"));
|
|
|
+ results.put("fatGPerDay", map.get("kcal/d"));
|
|
|
|
|
|
results.put("carbohydrateCaloriePercentage", String.format("%.2f", carbohydrateCaloriePercentage));//碳水化合物占比
|
|
|
- results.put("carbohydrateGPerKgDay", String.format("%.2f", kcalPerKg));
|
|
|
- results.put("carbohydrateGPerDay", String.format("%.2f", tdeeKj));
|
|
|
+ results.put("carbohydrateGPerKgDay", map.get("kcal/d"));
|
|
|
+ results.put("carbohydrateGPerDay", map.get("kJ/d"));
|
|
|
|
|
|
results.put("calcium", NutritionDataUtil.getValueByAge("钙", null, age));
|
|
|
results.put("potassium", NutritionDataUtil.getValueByAge("钾", null, age));
|
|
@@ -292,7 +302,6 @@ public class NutritionSettingServiceImpl implements INutritionSettingService {
|
|
|
results.put("pantothenicAcid", NutritionDataUtil.getValueByAge("泛酸", null, age));
|
|
|
results.put("dietaryFiber", NutritionDataUtil.getValueByAge("膳食纤维", null, age));
|
|
|
|
|
|
-
|
|
|
return results;
|
|
|
}
|
|
|
}
|