diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/healthmachine/controller/HealthMachineController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/healthmachine/controller/HealthMachineController.java index 3053df9..e853673 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/healthmachine/controller/HealthMachineController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/healthmachine/controller/HealthMachineController.java @@ -3,12 +3,14 @@ package com.bonus.canteen.core.healthmachine.controller; import com.alibaba.fastjson.JSON; import com.bonus.canteen.core.healthmachine.bean.*; import com.bonus.canteen.core.healthmachine.mapper.HealthMachineMapper; +import com.bonus.canteen.core.kitchen.utils.BodyMeasurementStatusCalculator; import com.bonus.common.core.utils.encryption.Sm4Utils; import com.bonus.common.core.web.controller.BaseController; import com.bonus.common.houqin.utils.SM4EncryptUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -30,6 +32,9 @@ public class HealthMachineController extends BaseController { private HealthMachineMapper healthMachineMapper; private static final String MINUS_ONE = "-1"; + @Autowired + private BodyMeasurementStatusCalculator statusCalculator; + @ApiOperation("检查人员是否存在并获取人员信息") @GetMapping({"/getPhoneUser/restful"}) public String checkUserIsExist(@Valid UserDTO dto) { @@ -61,6 +66,9 @@ public class HealthMachineController extends BaseController { } dto.setPhone(user.getPhone()); dto.setUserCode(user.getUserCode()); + // 计算所有状态指标 + statusCalculator.calculateAllStatus(dto); + healthMachineMapper.addPhysicalExaminationData(dto); }catch (Exception e){ return JSON.toJSONString(BodyResponse.fail("上传数据失败",500,"上传数据失败")); diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/BodyMeasurementStatusCalculator.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/BodyMeasurementStatusCalculator.java new file mode 100644 index 0000000..63bdb82 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/BodyMeasurementStatusCalculator.java @@ -0,0 +1,430 @@ +package com.bonus.canteen.core.kitchen.utils; + +import com.bonus.canteen.core.healthmachine.bean.BodyMeasurement; +import org.springframework.stereotype.Component; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 体检数据状态计算工具类 + */ +@Component +public class BodyMeasurementStatusCalculator { + + /** + * 计算所有状态并设置到体检数据对象中 + * @param measurement 体检数据对象 + */ + public void calculateAllStatus(BodyMeasurement measurement) { + if (measurement == null) { + return; + } + + String sex = measurement.getSex(); + boolean isMale = "男".equals(sex) || "male".equalsIgnoreCase(sex) || "man".equals(sex); + + // 1. 身高状态 + measurement.setHeightStatus(calculateHeightStatus(measurement.getHeight())); + + // 2. 体重状态 + measurement.setWeightStatus(calculateWeightStatus( + measurement.getWeight(), + measurement.getHeight(), + isMale + )); + + // 3. BMI状态 + measurement.setBmiStatus(calculateBmiStatus(measurement.getBmi())); + + // 4. 体脂率状态 + measurement.setBodyFatStatus(calculateBodyFatStatus( + measurement.getBodyFat(), + isMale + )); + + // 5. 内脏脂肪指数状态 + measurement.setFatLevelStatus(calculateFatLevelStatus(measurement.getFatLevel())); + + // 6. 体水分状态 + measurement.setWaterContentStatus(calculateWaterContentStatus( + measurement.getWaterContent(), + isMale + )); + + // 7. 肌肉率状态 + measurement.setMuscleStatus(calculateMuscleStatus( + measurement.getMuscle(), + measurement.getHeight(), + measurement.getWeight(), + isMale + )); + + // 8. 蛋白质状态 + measurement.setProteinStatus(calculateProteinStatus( + measurement.getProtein(), + isMale + )); + + // 9. 细胞外液状态 + measurement.setExtwaterStatus(calculateExtwaterStatus(measurement.getExtwater())); + + // 10. 骨量状态 + measurement.setBoneMassStatus(calculateBoneMassStatus( + measurement.getBoneMass(), + measurement.getWeight(), + isMale + )); + + // 11. 基础代谢状态 + measurement.setMetabolismStatus(calculateMetabolismStatus( + measurement.getMetabolism(), + measurement.getWeight(), + measurement.getAge(), + isMale + )); + + // 12. 健康建议 + measurement.setHealthSuggestion(generateHealthSuggestion(measurement)); + } + + /** + * 1. 身高状态计算 + */ + private String calculateHeightStatus(double height) { + // 根据需求,身高一律显示正常 + return "正常"; + } + + /** + * 2. 体重状态计算 + */ + private String calculateWeightStatus(int weight, double height, boolean isMale) { + // 计算标准体重 + double standardWeight = calculateStandardWeight(height, isMale); + + if (weight <= 0.8 * standardWeight) { + return "过低"; + } else if (weight > 0.8 * standardWeight && weight <= 0.9 * standardWeight) { + return "偏低"; + } else if (weight >= 0.9 * standardWeight && weight <= 1.1 * standardWeight) { + return "正常"; + } else if (weight > 1.1 * standardWeight && weight <= 1.2 * standardWeight) { + return "偏高"; + } else { + return "过高"; + } + } + + /** + * 计算标准体重 + */ + private double calculateStandardWeight(double height, boolean isMale) { + if (isMale) { + // 男性:sw = (身高 − 80) × 0.7 + return (height - 80) * 0.7; + } else { + // 女性:sw = ((身高 × 1.37) − 110) × 0.45 + return ((height * 1.37) - 110) * 0.45; + } + } + + /** + * 3. BMI状态计算 + */ + private String calculateBmiStatus(double bmi) { + if (bmi < 18.5) { + return "偏低"; + } else if (bmi >= 18.5 && bmi <= 25) { + return "标准"; + } else { + return "偏高"; + } + } + + /** + * 4. 体脂率状态计算 + */ + private String calculateBodyFatStatus(double bodyFat, boolean isMale) { + if (isMale) { + if (bodyFat < 11) { + return "偏低"; + } else if (bodyFat >= 11 && bodyFat <= 21) { + return "标准"; + } else if (bodyFat > 21 && bodyFat <= 26) { + return "偏高"; + } else { + return "过高"; + } + } else { + if (bodyFat < 21) { + return "偏低"; + } else if (bodyFat >= 21 && bodyFat <= 31) { + return "标准"; + } else if (bodyFat > 31 && bodyFat <= 36) { + return "偏高"; + } else { + return "过高"; + } + } + } + + /** + * 5. 内脏脂肪指数状态计算 + */ + private String calculateFatLevelStatus(int fatLevel) { + if (fatLevel <= 9) { + return "标准"; + } else if (fatLevel > 9 && fatLevel <= 14) { + return "偏高"; + } else { + return "过高"; + } + } + + /** + * 6. 体水分状态计算 + */ + private String calculateWaterContentStatus(double waterContent, boolean isMale) { + if (isMale) { + if (waterContent < 55) { + return "偏低"; + } else if (waterContent >= 55 && waterContent <= 65) { + return "标准"; + } else { + return "过高"; + } + } else { + if (waterContent < 45) { + return "偏低"; + } else if (waterContent >= 45 && waterContent <= 60) { + return "标准"; + } else { + return "过高"; + } + } + } + + /** + * 7. 肌肉率状态计算 + */ + private String calculateMuscleStatus(double muscleRate, double height, int weight, boolean isMale) { + // 计算肌肉量:体重 × (肌肉率 / 100) + double muscleMass = weight * (muscleRate / 100); + + if (isMale) { + if (height < 160) { + if (muscleMass < 38.5) { + return "偏低"; + } else if (muscleMass >= 38.5 && muscleMass < 46.5) { + return "正常"; + } else { + return "过高"; + } + } else if (height >= 160 && height <= 170) { + if (muscleMass < 44.0) { + return "偏低"; + } else if (muscleMass >= 44.0 && muscleMass < 52.4) { + return "正常"; + } else { + return "过高"; + } + } else { // height > 170 + if (muscleMass < 49.4) { + return "偏低"; + } else if (muscleMass >= 49.4 && muscleMass < 59.4) { + return "正常"; + } else { + return "过高"; + } + } + } else { + if (height < 150) { + if (muscleMass < 29.1) { + return "偏低"; + } else if (muscleMass >= 29.1 && muscleMass < 34.7) { + return "正常"; + } else { + return "过高"; + } + } else if (height >= 150 && height <= 160) { + if (muscleMass < 32.9) { + return "偏低"; + } else if (muscleMass >= 32.9 && muscleMass < 37.5) { + return "正常"; + } else { + return "过高"; + } + } else { // height > 160 + if (muscleMass < 36.5) { + return "偏低"; + } else if (muscleMass >= 36.5 && muscleMass < 42.5) { + return "正常"; + } else { + return "过高"; + } + } + } + } + + /** + * 8. 蛋白质状态计算 + */ + private String calculateProteinStatus(double protein, boolean isMale) { + if (isMale) { + return protein < 16 ? "偏低" : "标准"; + } else { + return protein < 14 ? "偏低" : "标准"; + } + } + + /** + * 9. 细胞外液状态计算 + */ + private String calculateExtwaterStatus(double extwater) { + if (extwater >= 0 && extwater < 13) { + return "过低"; + } else if (extwater >= 13 && extwater < 15) { + return "偏低"; + } else if (extwater >= 15 && extwater <= 100) { + return "正常"; + } else { + return "异常"; + } + } + + /** + * 10. 骨量状态计算 + */ + private String calculateBoneMassStatus(double boneMass, int weight, boolean isMale) { + if (isMale) { + if (weight <= 60) { + if (boneMass < 2.3) { + return "偏低"; + } else if (boneMass >= 2.3 && boneMass <= 2.7) { + return "标准"; + } else { + return "偏高"; + } + } else if (weight > 60 && weight <= 75) { + if (boneMass < 2.7) { + return "偏低"; + } else if (boneMass >= 2.7 && boneMass <= 3.1) { + return "标准"; + } else { + return "偏高"; + } + } else { // weight > 75 + if (boneMass < 3.0) { + return "偏低"; + } else if (boneMass >= 3.0 && boneMass <= 3.4) { + return "标准"; + } else { + return "偏高"; + } + } + } else { + if (weight <= 45) { + if (boneMass < 1.6) { + return "偏低"; + } else if (boneMass >= 1.6 && boneMass <= 2.0) { + return "标准"; + } else { + return "偏高"; + } + } else if (weight > 45 && weight <= 60) { + if (boneMass < 2.0) { + return "偏低"; + } else if (boneMass >= 2.0 && boneMass <= 2.4) { + return "标准"; + } else { + return "偏高"; + } + } else { // weight > 60 + if (boneMass < 2.3) { + return "偏低"; + } else if (boneMass >= 2.3 && boneMass <= 2.7) { + return "标准"; + } else { + return "偏高"; + } + } + } + } + + /** + * 11. 基础代谢状态计算 + */ + private String calculateMetabolismStatus(int metabolism, int weight, int age, boolean isMale) { + if (age >= 50) { + // 计算单位代谢 + double unitMetabolism = (double) metabolism / weight; + + if (isMale) { + return unitMetabolism > 21 ? "正常" : "偏低"; + } else { + return unitMetabolism > 20 ? "正常" : "偏低"; + } + } else { + // 对于年龄小于50的情况,可以根据实际需求调整 + // 这里假设都是正常,实际应用中可能需要更详细的标准 + return "正常"; + } + } + + /** + * 生成健康建议 + */ + private String generateHealthSuggestion(BodyMeasurement measurement) { + List suggestions = new ArrayList<>(); + + // 根据各项指标状态给出建议 + if ("过高".equals(measurement.getWeightStatus()) || "偏高".equals(measurement.getWeightStatus())) { + suggestions.add("建议控制饮食,适当增加运动以减轻体重"); + } else if ("过低".equals(measurement.getWeightStatus()) || "偏低".equals(measurement.getWeightStatus())) { + suggestions.add("建议增加营养摄入,适当进行力量训练增加肌肉"); + } + + if ("偏高".equals(measurement.getBmiStatus())) { + suggestions.add("BMI偏高,建议控制体重"); + } else if ("偏低".equals(measurement.getBmiStatus())) { + suggestions.add("BMI偏低,建议增加体重"); + } + + if ("过高".equals(measurement.getBodyFatStatus()) || "偏高".equals(measurement.getBodyFatStatus())) { + suggestions.add("体脂率偏高,建议进行有氧运动和饮食控制"); + } else if ("偏低".equals(measurement.getBodyFatStatus())) { + suggestions.add("体脂率偏低,建议适当增加健康脂肪摄入"); + } + + if ("过高".equals(measurement.getFatLevelStatus()) || "偏高".equals(measurement.getFatLevelStatus())) { + suggestions.add("内脏脂肪偏高,需特别注意饮食和运动"); + } + + if ("偏低".equals(measurement.getWaterContentStatus())) { + suggestions.add("体水分偏低,建议每天饮用充足的水"); + } + + if ("偏低".equals(measurement.getMuscleStatus())) { + suggestions.add("肌肉率偏低,建议增加力量训练"); + } + + if ("偏低".equals(measurement.getProteinStatus())) { + suggestions.add("蛋白质偏低,建议增加优质蛋白质摄入"); + } + + if ("偏低".equals(measurement.getBoneMassStatus())) { + suggestions.add("骨量偏低,建议补充钙质和维生素D,适当进行负重运动"); + } + + // 如果所有指标都正常 + if (suggestions.isEmpty()) { + suggestions.add("各项指标基本正常,建议保持健康生活方式,定期体检"); + } + // 限制建议长度,避免过长 + return suggestions.stream() + .distinct() + .limit(3) + .collect(Collectors.joining("\n")); + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/domain/PhysicalExaminationVO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/domain/PhysicalExaminationVO.java index f5783bd..0cfa0d5 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/domain/PhysicalExaminationVO.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/domain/PhysicalExaminationVO.java @@ -54,4 +54,18 @@ public class PhysicalExaminationVO { private String subPlace; private String createTime; -} \ No newline at end of file + + private String heightStatus; + private String weightStatus; + private String bmiStatus; + private String bodyFatStatus; + private String waterContentStatus; + private String fatLevelStatus; + private String muscleStatus; + private String proteinStatus; + private String extwaterStatus; + private String boneMassStatus; + private String metabolismStatus; + + private String healthSuggestion; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/healthmachine/HealthMachineMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/healthmachine/HealthMachineMapper.xml index 22c5c0e..72152cb 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/healthmachine/HealthMachineMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/healthmachine/HealthMachineMapper.xml @@ -16,10 +16,25 @@ - insert into kitchen_staff_physical_examination(staff_id, device_id, sex, age, height, weight, bmi, bodyFat, muscle, boneMass, - waterContent, extwater, protein, metabolism, fatLevel, bodyAge,phone) - values (#{dto.userId},#{dto.machineId},#{dto.sex},#{dto.age},#{dto.height},#{dto.weight},#{dto.bmi},#{dto.bodyFat},#{dto.muscle},#{dto.boneMass},#{dto.waterContent},#{dto.extwater},#{dto.protein} - ,#{dto.metabolism},#{dto.fatLevel},#{dto.bodyAge},#{dto.phone}) + insert into kitchen_staff_physical_examination( + staff_id, device_id, sex, age, height, weight, + bmi, bodyFat, muscle, boneMass, waterContent, + extwater, protein, metabolism, fatLevel, bodyAge, + phone, + heightStatus, weightStatus, bmiStatus, bodyFatStatus, + waterContentStatus, fatLevelStatus, muscleStatus, proteinStatus, + extwaterStatus, boneMassStatus, metabolismStatus, healthSuggestion + ) values ( + #{dto.userId}, #{dto.machineId}, #{dto.sex}, #{dto.age}, + #{dto.height}, #{dto.weight}, #{dto.bmi}, #{dto.bodyFat}, + #{dto.muscle}, #{dto.boneMass}, #{dto.waterContent}, + #{dto.extwater}, #{dto.protein}, #{dto.metabolism}, + #{dto.fatLevel}, #{dto.bodyAge}, #{dto.phone}, + #{dto.heightStatus}, #{dto.weightStatus}, #{dto.bmiStatus}, + #{dto.bodyFatStatus}, #{dto.waterContentStatus}, #{dto.fatLevelStatus}, + #{dto.muscleStatus}, #{dto.proteinStatus}, #{dto.extwaterStatus}, + #{dto.boneMassStatus}, #{dto.metabolismStatus}, #{dto.healthSuggestion} + )