diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysFoodHeatStatisticsController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysFoodHeatStatisticsController.java index 8eff00c7a..4e9350315 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysFoodHeatStatisticsController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysFoodHeatStatisticsController.java @@ -6,14 +6,7 @@ import com.stdiet.custom.domain.SysCustomerHeatStatistics; import com.stdiet.custom.service.ISysCustomerHeatStatisticsService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.stdiet.common.annotation.Log; import com.stdiet.common.core.controller.BaseController; import com.stdiet.common.core.domain.AjaxResult; @@ -111,4 +104,14 @@ public class SysFoodHeatStatisticsController extends BaseController { return toAjax(sysCustomerHeatStatisticsService.calculateCustomerHeat(sysCustomerHeatStatistics)); } + + /** + * 查看外食热量统计详细信息 + */ + @PreAuthorize("@ss.hasPermi('custom:foodHeatStatistics:query')") + @GetMapping(value = "/getNutritionalCalories") + public AjaxResult getNutritionalCalories(@RequestParam("id") Long id) + { + return AjaxResult.success(sysCustomerHeatStatisticsService.getNutritionalCaloriesByCustomerHeatId(id)); + } } \ No newline at end of file diff --git a/stdiet-common/src/main/java/com/stdiet/common/utils/HealthyUtils.java b/stdiet-common/src/main/java/com/stdiet/common/utils/HealthyUtils.java index baff6a9a5..9f19c3fbe 100644 --- a/stdiet-common/src/main/java/com/stdiet/common/utils/HealthyUtils.java +++ b/stdiet-common/src/main/java/com/stdiet/common/utils/HealthyUtils.java @@ -23,7 +23,7 @@ public class HealthyUtils { * @param weight 体重 * @return */ - public static long calculateMaxHeatEveryDay(Integer age, Integer tall, Double weight){ + public static Long calculateMaxHeatEveryDay(Integer age, Integer tall, Double weight){ age = age == null ? 0 : age; tall = tall == null ? 0 : tall; weight = weight == null ? 0.0 : weight; @@ -47,8 +47,8 @@ public class HealthyUtils { * @param weight 体重(斤) * @return */ - public static double calculateHeatRateByWeight(long metabolizeHeat, double weight){ - return NumberUtils.getNumberByRoundHalfUp(metabolizeHeat/weight*2, 2).doubleValue(); + public static Long calculateHeatRateByWeight(Integer metabolizeHeat, Double weight){ + return Math.round(metabolizeHeat/weight*2); } /** @@ -56,8 +56,8 @@ public class HealthyUtils { * @param heatRateByWeight 每公斤体重占比(千卡/公斤) * @return */ - public static double[] calculateHeatTargetRate(double heatRateByWeight){ - double[] heatArray = new double[2]; + public static Long[] calculateHeatTargetRate(Long heatRateByWeight){ + Long[] heatArray = new Long[2]; heatArray[0] = heatRateByWeight - 10; heatArray[1] = heatRateByWeight - 5; return heatArray; @@ -66,13 +66,13 @@ public class HealthyUtils { /** * 计算减脂热量控制范围(千卡) * @param heatTargetRateArray 每公斤体重占比目标范围 - * @param fatRateWeight 每公斤体重脂肪占比(克/公斤) + * @param weight 体重 * @return */ - public static long[] calculateStandardHeatScopeRate(double[] heatTargetRateArray, double fatRateWeight){ - long[] heatArray = new long[2]; - heatArray[0] = Math.round(heatTargetRateArray[0] * fatRateWeight / 2); - heatArray[1] = Math.round(heatTargetRateArray[1] * fatRateWeight / 2); + public static Long[] calculateStandardHeatScopeRate(Long[] heatTargetRateArray, Double weight){ + Long[] heatArray = new Long[2]; + heatArray[0] = Math.round(heatTargetRateArray[0] * weight / 2); + heatArray[1] = Math.round(heatTargetRateArray[1] * weight / 2); return heatArray; } @@ -121,25 +121,40 @@ public class HealthyUtils { * @return */ public static double calculateStandardWeight(int tall){ - return (tall-107.5)*2; + return NumberUtils.getNumberByRoundHalfUp((tall-107.5)*2, 1).doubleValue(); } /** * 返回蛋白质、脂肪、碳水对应热量、质量 - * @param metabolizeHeat + * @param metabolizeHeat 摄入热量 * @return */ public static Integer[][] calculateNutritionHeatAndQuality(int metabolizeHeat){ Integer[] heatArray = new Integer[3]; Integer[] qualityArray = new Integer[3]; - heatArray[0] = Math.round(nutritionRate[0] * metabolizeHeat /100); - heatArray[1] = Math.round(nutritionRate[1] * metabolizeHeat /100); - heatArray[2] = Math.round(nutritionRate[2] * metabolizeHeat /100); - qualityArray[0] = (int)Math.round(Double.parseDouble(heatArray[0]+"")/proteinHeat); - qualityArray[1] = (int)Math.round(Double.parseDouble(heatArray[1]+"")/fatHeat); - qualityArray[2] = (int)Math.round(Double.parseDouble(heatArray[2]+"")/carbonWaterHeat); - Integer[][] result = {heatArray, qualityArray}; - return result; + heatArray[0] = Math.round(nutritionRate[0] * metabolizeHeat /100); + heatArray[1] = Math.round(nutritionRate[1] * metabolizeHeat /100); + heatArray[2] = Math.round(metabolizeHeat - heatArray[0] - heatArray[1]); + qualityArray[0] = (int)Math.round(Double.parseDouble(heatArray[0]+"")/proteinHeat); + qualityArray[1] = (int)Math.round(Double.parseDouble(heatArray[1]+"")/fatHeat); + qualityArray[2] = (int)Math.round(Double.parseDouble(heatArray[2]+"")/carbonWaterHeat); + Integer[][] result = {heatArray, qualityArray}; + return result; } + /** + * 计算每公斤体重占比(克/公斤) + * @param nutritionQuality 蛋白质、脂肪、碳水对应质量 + * @param weight 体重 + * @return + */ + public static final Double[] calculateNutritionEveryWeight(Integer[] nutritionQuality, double weight){ + Double[] nutritionEveryWeight = new Double[3]; + nutritionEveryWeight[0] = NumberUtils.getNumberByRoundHalfUp(nutritionQuality[0]/weight*2,2).doubleValue(); + nutritionEveryWeight[1] = NumberUtils.getNumberByRoundHalfUp(nutritionQuality[1]/weight*2,2).doubleValue(); + nutritionEveryWeight[2] = NumberUtils.getNumberByRoundHalfUp(nutritionQuality[2]/weight*2, 2).doubleValue(); + return nutritionEveryWeight; + } + + } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysCustomerHeatStatistics.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysCustomerHeatStatistics.java index 1827dfbf6..f91dcd0ae 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysCustomerHeatStatistics.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysCustomerHeatStatistics.java @@ -39,6 +39,18 @@ public class SysCustomerHeatStatistics extends BaseEntity @Excel(name = "当天食材总热量") private Integer heatValue; + /** 当天摄入蛋白质热量 */ + @Excel(name = "当天摄入蛋白质热量") + private Integer proteinHeat; + + /** 当天摄入脂肪热量 */ + @Excel(name = "当天摄入脂肪热量") + private Integer fatHeat; + + /** 当天摄入碳水热量 */ + @Excel(name = "当天摄入碳水热量") + private Integer carbonWaterHeat; + /** 当天热量缺口 */ @Excel(name = "当天热量缺口") private Integer heatGap; diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysFoodHeatStatistics.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysFoodHeatStatistics.java index 973fb208f..28883465a 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysFoodHeatStatistics.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysFoodHeatStatistics.java @@ -56,6 +56,12 @@ public class SysFoodHeatStatistics extends BaseEntity @Excel(name = "碳水质量,克") private Integer carbonWaterQuality; + private Integer proteinHeat; + + private Integer fatHeat; + + private Integer carbonWaterHeat; + /** 热量数值 */ @Excel(name = "热量数值") private Integer heatValue; diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/NutritionalCalories.java b/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/NutritionalCalories.java index 958e4e733..fc23e08bc 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/NutritionalCalories.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/NutritionalCalories.java @@ -13,43 +13,43 @@ public class NutritionalCalories implements Serializable { public String name; //实际体重(斤) - public double weight; + public Double weight; //实际身高(厘米) - public int tall; + public Integer tall; //年龄 - public int age; + public Integer age; //标准体重(斤) - public double standardWeight; + public Double standardWeight; //超重(斤) - public double overWeight; + public Double overWeight; //活动因子 - public double activityFactor; + public Double activityFactor; //基础代谢BMR(千卡) - public int metabolizeHeat; + public Integer metabolizeHeat; //减脂最大摄入量(千卡) - public int maxIntakeHeat; + public Long maxIntakeHeat; //不运动总热量(千卡) - public int withoutExerciseHeat; + public Integer withoutExerciseHeat; //运动总热量(千卡) - public int exerciseHeat; + public Integer exerciseHeat; //每公斤体重占比(千卡/公斤) - public double everyWeightHeat; + public Long everyWeightHeat; //目标范围(千卡/公斤) - public double[] targetEveryWeightHeat; + public Long[] targetEveryWeightHeat; //减脂热量标准范围(千卡/公斤) - public double[] standardEveryWeightHeat; + public Long[] standardEveryWeightHeat; //蛋白质、脂肪、碳水比例 public Integer[] nutritionalRate; @@ -61,7 +61,7 @@ public class NutritionalCalories implements Serializable { public Integer[] nutritionalQuality; //每公斤体重对应蛋白质、脂肪、碳水占比(克/公斤) - public double[] weightNutritionalRate; + public Double[] weightNutritionalRate; //蛋白质、脂肪、碳水已摄入热量(千卡) public Integer[] ingestedNutritionalHeat; diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java index bb6c4aa5b..d1e8b9d9f 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java @@ -4,6 +4,7 @@ import java.util.List; import com.stdiet.custom.domain.SysIngredient; import com.stdiet.custom.domain.SysIngredientNotRec; import com.stdiet.custom.domain.SysIngredientRec; +import org.apache.ibatis.annotations.Param; /** * 食材Mapper接口 @@ -72,4 +73,11 @@ public interface SysIngredientMapper public int deleteIngredentRecByIngredientIds(Long[] id); public int deleteIngredentNotRecByIngredientIds(Long[] id); + + /** + * 根据食材名称查询食材信息 + * @param name + * @return + */ + public SysIngredient selectSysIngredientByName(@Param("name") String name); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/AsyncCommonService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/AsyncCommonService.java new file mode 100644 index 000000000..73e5d95bc --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/AsyncCommonService.java @@ -0,0 +1,9 @@ +package com.stdiet.custom.service; + +public interface AsyncCommonService { + + /** + * 异步更新每个食材对应的蛋白质、脂肪、碳水的质量 + */ + public void updateFoodNutritionalQualityAndHeat(Long customerHeatId); +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysCustomerHeatStatisticsService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysCustomerHeatStatisticsService.java index 207a6b730..70e4c1387 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysCustomerHeatStatisticsService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysCustomerHeatStatisticsService.java @@ -79,5 +79,5 @@ public interface ISysCustomerHeatStatisticsService * @param id * @return */ - public NutritionalCalories getNutritionalCaloriesByCustomer(Long id); + public NutritionalCalories getNutritionalCaloriesByCustomerHeatId(Long id); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysIngredientService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysIngredientService.java index ab63c4ace..0d8f10d61 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysIngredientService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysIngredientService.java @@ -58,4 +58,10 @@ public interface ISysIngredientService * @return 结果 */ public int deleteSysIngredientById(Long id); -} \ No newline at end of file + + /** + * 根据食材名称查询食材信息 + * @param name + * @return + */ + public SysIngredient selectSysIngredientByName(String name);} \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/AsyncCommonServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/AsyncCommonServiceImpl.java new file mode 100644 index 000000000..b4a99b1d1 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/AsyncCommonServiceImpl.java @@ -0,0 +1,102 @@ +package com.stdiet.custom.service.impl; + +import com.stdiet.common.utils.HealthyUtils; +import com.stdiet.common.utils.StringUtils; +import com.stdiet.custom.domain.SysCustomerHeatStatistics; +import com.stdiet.custom.domain.SysFoodHeatStatistics; +import com.stdiet.custom.domain.SysIngredient; +import com.stdiet.custom.mapper.SysCustomerHeatStatisticsMapper; +import com.stdiet.custom.mapper.SysFoodHeatStatisticsMapper; +import com.stdiet.custom.service.AsyncCommonService; +import com.stdiet.custom.service.ISysIngredientService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class AsyncCommonServiceImpl implements AsyncCommonService { + + @Autowired + private ISysIngredientService sysIngredientService; + + @Autowired + private SysCustomerHeatStatisticsMapper sysCustomerHeatStatisticsMapper; + + @Autowired + private SysFoodHeatStatisticsMapper sysFoodHeatStatisticsMapper; + + + /** + * 异步更新每个食材对应的蛋白质、脂肪、碳水的质量 + */ + @Override + @Async + public void updateFoodNutritionalQualityAndHeat(Long customerHeatId){ + SysCustomerHeatStatistics sysCustomerHeatStatistics = sysCustomerHeatStatisticsMapper.selectSysCustomerHeatStatisticsById(customerHeatId); + if(sysCustomerHeatStatistics != null && sysCustomerHeatStatistics.getFoodHeatStatisticsList() != null + && sysCustomerHeatStatistics.getFoodHeatStatisticsList().size() > 0){ + List foodList = sysCustomerHeatStatistics.getFoodHeatStatisticsList(); + //食材是否全部存在食材库,并且存在对应比例 + int totalProteinHeat = 0; + int totalFatHeat = 0; + int totalCarbonWaterHeat = 0; + boolean allExistFlag = true; + for (SysFoodHeatStatistics sysFoodHeatStatistics : foodList) { + //判断食材库中是否存在该食材以及该食材是否存在质量 + if(sysFoodHeatStatistics.getQuantity() == null || StringUtils.isEmpty(sysFoodHeatStatistics.getIngredient())){ + allExistFlag = false; + continue; + } + //如果该食材之前未计算出热量则从食材库中查询并查询计算 + if(sysFoodHeatStatistics.getHeatValue() == null || sysFoodHeatStatistics.getHeatValue().intValue() == 0){ + SysIngredient sysIngredient = sysIngredientService.selectSysIngredientByName(sysFoodHeatStatistics.getIngredient().trim()); + if(sysIngredient == null || sysIngredient.getProteinRatio() == null || sysIngredient.getFatRatio() == null || sysIngredient.getCarbonRatio() == null){ + allExistFlag = false; + continue; + } + Long proteinValue = Math.round(sysFoodHeatStatistics.getQuantity()*sysIngredient.getProteinRatio().doubleValue()/100); + Long fatValue = Math.round(sysFoodHeatStatistics.getQuantity()*sysIngredient.getFatRatio().doubleValue()/100); + Long carbonValue = Math.round(sysFoodHeatStatistics.getQuantity()*sysIngredient.getCarbonRatio().doubleValue()/100); + sysFoodHeatStatistics.setProteinQuality(proteinValue.intValue()); + sysFoodHeatStatistics.setFatQuality(fatValue.intValue()); + sysFoodHeatStatistics.setCarbonWaterQuality(carbonValue.intValue()); + //根据蛋白质、脂肪、碳水计算热量 + sysFoodHeatStatistics.setProteinHeat(HealthyUtils.calculateHeatByProteinQuality(proteinValue.intValue())); + sysFoodHeatStatistics.setFatHeat(HealthyUtils.calculateHeatByFatQuality(fatValue.intValue())); + sysFoodHeatStatistics.setCarbonWaterHeat(HealthyUtils.calculateHeatByCarbonWaterQuality(carbonValue.intValue())); + sysFoodHeatStatistics.setHeatValue(sysFoodHeatStatistics.getProteinHeat()+sysFoodHeatStatistics.getFatHeat()+sysFoodHeatStatistics.getCarbonWaterHeat()); + sysFoodHeatStatisticsMapper.updateSysFoodHeatStatistics(sysFoodHeatStatistics); + }else{ + //根据蛋白质、脂肪、碳水计算热量 + sysFoodHeatStatistics.setProteinHeat(HealthyUtils.calculateHeatByProteinQuality(sysFoodHeatStatistics.getProteinQuality())); + sysFoodHeatStatistics.setFatHeat(HealthyUtils.calculateHeatByFatQuality(sysFoodHeatStatistics.getFatQuality())); + sysFoodHeatStatistics.setCarbonWaterHeat(HealthyUtils.calculateHeatByCarbonWaterQuality(sysFoodHeatStatistics.getCarbonWaterQuality())); + } + totalProteinHeat += sysFoodHeatStatistics.getProteinHeat(); + totalFatHeat += sysFoodHeatStatistics.getFatHeat(); + totalCarbonWaterHeat += sysFoodHeatStatistics.getCarbonWaterHeat(); + } + //是否全部食材都存在于食材库 + if(allExistFlag){ + sysCustomerHeatStatistics.setHeatValue(totalProteinHeat + totalFatHeat + totalCarbonWaterHeat); + sysCustomerHeatStatistics.setProteinHeat(totalProteinHeat); + sysCustomerHeatStatistics.setFatHeat(totalFatHeat); + sysCustomerHeatStatistics.setCarbonWaterHeat(totalCarbonWaterHeat); + sysCustomerHeatStatistics.setHeatGap(sysCustomerHeatStatistics.getMaxHeatValue() - sysCustomerHeatStatistics.getHeatValue()); + sysCustomerHeatStatisticsMapper.updateSysCustomerHeatStatistics(sysCustomerHeatStatistics); + }else{ + //新添加的食材如果不存在食材库,需要将热量数据更新为0,需要重新计算 + if(sysCustomerHeatStatistics.getHeatValue() != null && sysCustomerHeatStatistics.getHeatValue().intValue() > 0){ + sysCustomerHeatStatistics.setHeatValue(0); + sysCustomerHeatStatistics.setProteinHeat(0); + sysCustomerHeatStatistics.setFatHeat(0); + sysCustomerHeatStatistics.setCarbonWaterHeat(0); + sysCustomerHeatStatistics.setHeatGap(sysCustomerHeatStatistics.getMaxHeatValue() - sysCustomerHeatStatistics.getHeatValue()); + sysCustomerHeatStatisticsMapper.updateSysCustomerHeatStatistics(sysCustomerHeatStatistics); + } + } + } + } +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHeatStatisticsServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHeatStatisticsServiceImpl.java index a0428ffec..8df621ba1 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHeatStatisticsServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHeatStatisticsServiceImpl.java @@ -11,6 +11,7 @@ import com.stdiet.custom.dto.response.NutritionalCalories; import com.stdiet.custom.service.ISysCustomerHealthyService; import com.stdiet.custom.service.ISysCustomerPhysicalSignsService; import com.stdiet.custom.service.ISysFoodHeatStatisticsService; +import com.stdiet.custom.utils.NutritionalUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.stdiet.custom.mapper.SysCustomerHeatStatisticsMapper; @@ -134,20 +135,29 @@ public class SysCustomerHeatStatisticsServiceImpl implements ISysCustomerHeatSta Integer[] foodHeat = sysCustomerHeatStatistics.getFoodHeatList(); if(foodHeatId != null && foodHeatId.length > 0){ SysFoodHeatStatistics sysFoodHeatStatistics = new SysFoodHeatStatistics(); - int totalHeatCalue = 0; + int totalProteinHeat = 0; + int totalFatHeat = 0; + int totalCarbonWaterHeat = 0; for (int i = 0; i < foodHeatId.length; i++) { sysFoodHeatStatistics.setId(foodHeatId[i]); sysFoodHeatStatistics.setProteinQuality(sysCustomerHeatStatistics.getProteinQualityList()[i]); sysFoodHeatStatistics.setFatQuality(sysCustomerHeatStatistics.getFatQualityList()[i]); sysFoodHeatStatistics.setCarbonWaterQuality(sysCustomerHeatStatistics.getCarbonWaterQualityList()[i]); //根据蛋白质、脂肪、碳水计算热量 - sysFoodHeatStatistics.setHeatValue(HealthyUtils.calculateTotalHeatByProteinFatCarbonWater(sysCustomerHeatStatistics.getProteinQualityList()[i], - sysCustomerHeatStatistics.getFatQualityList()[i], sysCustomerHeatStatistics.getCarbonWaterQualityList()[i])); + sysFoodHeatStatistics.setProteinHeat(HealthyUtils.calculateHeatByProteinQuality(sysCustomerHeatStatistics.getProteinQualityList()[i])); + sysFoodHeatStatistics.setFatHeat(HealthyUtils.calculateHeatByFatQuality(sysCustomerHeatStatistics.getFatQualityList()[i])); + sysFoodHeatStatistics.setCarbonWaterHeat(HealthyUtils.calculateHeatByCarbonWaterQuality(sysCustomerHeatStatistics.getCarbonWaterQualityList()[i])); + sysFoodHeatStatistics.setHeatValue(sysFoodHeatStatistics.getProteinHeat()+sysFoodHeatStatistics.getFatHeat()+sysFoodHeatStatistics.getCarbonWaterHeat()); sysFoodHeatStatisticsService.updateSysFoodHeatStatistics(sysFoodHeatStatistics); - totalHeatCalue += sysFoodHeatStatistics.getHeatValue(); + totalProteinHeat += sysFoodHeatStatistics.getProteinHeat(); + totalFatHeat += sysFoodHeatStatistics.getFatHeat(); + totalCarbonWaterHeat += sysFoodHeatStatistics.getCarbonWaterHeat(); } - sysCustomerHeatStatistics.setHeatValue(totalHeatCalue); - sysCustomerHeatStatistics.setHeatGap(sysCustomerHeatStatistics.getMaxHeatValue() - totalHeatCalue); + sysCustomerHeatStatistics.setHeatValue(totalProteinHeat + totalFatHeat + totalCarbonWaterHeat); + sysCustomerHeatStatistics.setProteinHeat(totalProteinHeat); + sysCustomerHeatStatistics.setFatHeat(totalFatHeat); + sysCustomerHeatStatistics.setCarbonWaterHeat(totalCarbonWaterHeat); + sysCustomerHeatStatistics.setHeatGap(sysCustomerHeatStatistics.getMaxHeatValue() - sysCustomerHeatStatistics.getHeatValue()); return sysCustomerHeatStatisticsMapper.updateSysCustomerHeatStatistics(sysCustomerHeatStatistics); } return 0; @@ -158,29 +168,24 @@ public class SysCustomerHeatStatisticsServiceImpl implements ISysCustomerHeatSta * @param id * @return */ - public NutritionalCalories getNutritionalCaloriesByCustomer(Long id){ - NutritionalCalories nutritionalCalories = new NutritionalCalories(); + @Override + public NutritionalCalories getNutritionalCaloriesByCustomerHeatId(Long id){ + NutritionalCalories nutritionalCalories = null; SysCustomerHeatStatistics sysCustomerHeatStatistics = sysCustomerHeatStatisticsMapper.selectSysCustomerHeatStatisticsById(id); if(sysCustomerHeatStatistics != null){ SysCustomerHealthy sysCustomerHealthy = getSysCustomerHealthy(sysCustomerHeatStatistics.getCustomerId()); if(sysCustomerHealthy != null){ - nutritionalCalories.setName(sysCustomerHealthy.getName()); - nutritionalCalories.setAge(sysCustomerHealthy.getAge().intValue()); - nutritionalCalories.setTall(sysCustomerHealthy.getTall()); - nutritionalCalories.setWeight(sysCustomerHealthy.getWeight().doubleValue()); - nutritionalCalories.setStandardWeight(HealthyUtils.calculateStandardWeight(nutritionalCalories.getTall())); - double overHeight = nutritionalCalories.getWeight() - nutritionalCalories.getStandardWeight(); - overHeight = overHeight > 0 ? overHeight : 0; - nutritionalCalories.setOverWeight(overHeight); - nutritionalCalories.setMetabolizeHeat(HealthyUtils.calculateMetabolizeHeat(nutritionalCalories.getAge(), nutritionalCalories.getTall(), nutritionalCalories.getWeight()).intValue()); - nutritionalCalories.setMaxIntakeHeat(sysCustomerHeatStatistics.getMaxHeatValue()); - nutritionalCalories.setEveryWeightHeat(HealthyUtils.calculateHeatRateByWeight(nutritionalCalories.getMetabolizeHeat(), nutritionalCalories.getWeight())); - nutritionalCalories.setTargetEveryWeightHeat(HealthyUtils.calculateHeatTargetRate(nutritionalCalories.getEveryWeightHeat())); - //nutritionalCalories.setStandardEveryWeightHeat(HealthyUtils.calculateHeatTargetRate() ); - nutritionalCalories.setNutritionalRate(HealthyUtils.nutritionRate); - Integer[][] nutritionalHeatAndQuality = HealthyUtils.calculateNutritionHeatAndQuality(nutritionalCalories.getMetabolizeHeat()); - nutritionalCalories.setNutritionalHeat(nutritionalHeatAndQuality[0]); - nutritionalCalories.setNutritionalQuality(nutritionalHeatAndQuality[1]); + nutritionalCalories = NutritionalUtils.getNutritionalCaloriesData(sysCustomerHealthy); + Integer[] ingestedNutritionalHeat = new Integer[3]; + ingestedNutritionalHeat[0] = sysCustomerHeatStatistics.getProteinHeat(); + ingestedNutritionalHeat[1] = sysCustomerHeatStatistics.getFatHeat(); + ingestedNutritionalHeat[2] = sysCustomerHeatStatistics.getCarbonWaterHeat(); + nutritionalCalories.setIngestedNutritionalHeat(ingestedNutritionalHeat); + Integer[] surplusNutritionalHeat = new Integer[3]; + surplusNutritionalHeat[0] = nutritionalCalories.getNutritionalHeat()[0] - ingestedNutritionalHeat[0]; + surplusNutritionalHeat[1] = nutritionalCalories.getNutritionalHeat()[1] - ingestedNutritionalHeat[1]; + surplusNutritionalHeat[2] = nutritionalCalories.getNutritionalHeat()[2] - ingestedNutritionalHeat[2]; + nutritionalCalories.setSurplusNutritionalHeat(surplusNutritionalHeat); } } return nutritionalCalories; @@ -207,6 +212,4 @@ public class SysCustomerHeatStatisticsServiceImpl implements ISysCustomerHeatSta } return sysCustomerHealthy; } - - } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysFoodHeatStatisticsServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysFoodHeatStatisticsServiceImpl.java index e727ae8f2..c8c56c467 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysFoodHeatStatisticsServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysFoodHeatStatisticsServiceImpl.java @@ -7,18 +7,14 @@ import com.stdiet.common.utils.DateUtils; import com.stdiet.common.utils.HealthyUtils; import com.stdiet.common.utils.StringUtils; import com.stdiet.common.utils.sign.AesUtils; -import com.stdiet.custom.domain.SysCustomerHealthy; -import com.stdiet.custom.domain.SysCustomerHeatStatistics; -import com.stdiet.custom.domain.SysCustomerPhysicalSigns; +import com.stdiet.custom.domain.*; import com.stdiet.custom.dto.request.FoodHeatCalculatorRequest; -import com.stdiet.custom.service.ISysCustomerHealthyService; -import com.stdiet.custom.service.ISysCustomerHeatStatisticsService; -import com.stdiet.custom.service.ISysCustomerPhysicalSignsService; +import com.stdiet.custom.mapper.SysCustomerHeatStatisticsMapper; +import com.stdiet.custom.service.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import com.stdiet.custom.mapper.SysFoodHeatStatisticsMapper; -import com.stdiet.custom.domain.SysFoodHeatStatistics; -import com.stdiet.custom.service.ISysFoodHeatStatisticsService; import org.springframework.transaction.annotation.Transactional; import javax.xml.crypto.Data; @@ -37,7 +33,7 @@ public class SysFoodHeatStatisticsServiceImpl implements ISysFoodHeatStatisticsS private SysFoodHeatStatisticsMapper sysFoodHeatStatisticsMapper; @Autowired - private ISysCustomerHeatStatisticsService sysCustomerHeatStatisticsService; + private SysCustomerHeatStatisticsMapper sysCustomerHeatStatisticsMapper; @Autowired private ISysCustomerPhysicalSignsService sysCustomerPhysicalSignsService; @@ -45,6 +41,9 @@ public class SysFoodHeatStatisticsServiceImpl implements ISysFoodHeatStatisticsS @Autowired private ISysCustomerHealthyService sysCustomerHealthyService; + @Autowired + private AsyncCommonService asyncCommonService; + /** * 查询外食热量统计 * @@ -154,10 +153,10 @@ public class SysFoodHeatStatisticsServiceImpl implements ISysFoodHeatStatisticsS SysCustomerHeatStatistics sysCustomerHeatStatistics = new SysCustomerHeatStatistics(); sysCustomerHeatStatistics.setCustomerId(Long.parseLong(customerId)); sysCustomerHeatStatistics.setEdibleDate(DateUtils.parseDate(dateKey)); - SysCustomerHeatStatistics customerHeatResult = sysCustomerHeatStatisticsService.getCustomerHeatStatisticsByDate(sysCustomerHeatStatistics); + SysCustomerHeatStatistics customerHeatResult = sysCustomerHeatStatisticsMapper.getCustomerHeatStatisticsByDate(sysCustomerHeatStatistics); if(customerHeatResult == null){ sysCustomerHeatStatistics.setMaxHeatValue(maxHeatValue); - sysCustomerHeatStatisticsService.insertSysCustomerHeatStatistics(sysCustomerHeatStatistics); + sysCustomerHeatStatisticsMapper.insertSysCustomerHeatStatistics(sysCustomerHeatStatistics); }else{ sysCustomerHeatStatistics.setId(customerHeatResult.getId()); } @@ -169,6 +168,8 @@ public class SysFoodHeatStatisticsServiceImpl implements ISysFoodHeatStatisticsS map.put("quantity", map.get("quantity") != null && "".equals(map.get("quantity").toString().trim()) ? null : map.get("quantity")); } row = sysFoodHeatStatisticsMapper.insertFoodHeatBatch(dateFoodMap.get(dateKey)); + //异步查询食材对应蛋白质、脂肪、碳水热量、质量,并更新热量缺口 + asyncCommonService.updateFoodNutritionalQualityAndHeat(sysCustomerHeatStatistics.getId()); } } return row; diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java index eff3414a4..2814d59bd 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java @@ -145,4 +145,14 @@ public class SysIngredientServiceImpl implements ISysIngredientService { sysIngredientMapper.deleteIngredentNotRecByIngredientId(id); return sysIngredientMapper.deleteSysIngredientById(id); } + + /** + * 根据食材名称查询食材信息 + * @param name + * @return + */ + @Override + public SysIngredient selectSysIngredientByName(String name){ + return sysIngredientMapper.selectSysIngredientByName(name); + } } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/utils/NutritionalUtils.java b/stdiet-custom/src/main/java/com/stdiet/custom/utils/NutritionalUtils.java new file mode 100644 index 000000000..e1a89986b --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/utils/NutritionalUtils.java @@ -0,0 +1,38 @@ +package com.stdiet.custom.utils; + +import com.stdiet.common.utils.HealthyUtils; +import com.stdiet.custom.domain.SysCustomerHealthy; +import com.stdiet.custom.dto.response.NutritionalCalories; + +public class NutritionalUtils { + + /** + * 根据客户健康信息获营养热量成分比例 + * @param sysCustomerHealthy + * @return + */ + public static final NutritionalCalories getNutritionalCaloriesData(SysCustomerHealthy sysCustomerHealthy){ + NutritionalCalories nutritionalCalories = new NutritionalCalories(); + if(sysCustomerHealthy != null){ + nutritionalCalories.setName(sysCustomerHealthy.getName()); + nutritionalCalories.setAge(sysCustomerHealthy.getAge().intValue()); + nutritionalCalories.setTall(sysCustomerHealthy.getTall()); + nutritionalCalories.setWeight(sysCustomerHealthy.getWeight().doubleValue()); + nutritionalCalories.setStandardWeight(HealthyUtils.calculateStandardWeight(nutritionalCalories.getTall())); + double overHeight = nutritionalCalories.getWeight() - nutritionalCalories.getStandardWeight(); + overHeight = overHeight > 0 ? overHeight : 0; + nutritionalCalories.setOverWeight(overHeight); + nutritionalCalories.setMetabolizeHeat(HealthyUtils.calculateMetabolizeHeat(nutritionalCalories.getAge(), nutritionalCalories.getTall(), nutritionalCalories.getWeight()).intValue()); + nutritionalCalories.setMaxIntakeHeat(HealthyUtils.calculateMaxHeatEveryDay(sysCustomerHealthy.getAge().intValue(), sysCustomerHealthy.getTall(), sysCustomerHealthy.getWeight().doubleValue())); + nutritionalCalories.setEveryWeightHeat(HealthyUtils.calculateHeatRateByWeight(nutritionalCalories.getMetabolizeHeat(), nutritionalCalories.getWeight())); + nutritionalCalories.setTargetEveryWeightHeat(HealthyUtils.calculateHeatTargetRate(nutritionalCalories.getEveryWeightHeat())); + nutritionalCalories.setStandardEveryWeightHeat(HealthyUtils.calculateStandardHeatScopeRate(nutritionalCalories.getTargetEveryWeightHeat(), nutritionalCalories.getWeight())); + nutritionalCalories.setNutritionalRate(HealthyUtils.nutritionRate); + Integer[][] nutritionalHeatAndQuality = HealthyUtils.calculateNutritionHeatAndQuality(nutritionalCalories.getMaxIntakeHeat().intValue()); + nutritionalCalories.setNutritionalHeat(nutritionalHeatAndQuality[0]); + nutritionalCalories.setNutritionalQuality(nutritionalHeatAndQuality[1]); + nutritionalCalories.setWeightNutritionalRate(HealthyUtils.calculateNutritionEveryWeight(nutritionalHeatAndQuality[1], nutritionalCalories.getWeight())); + } + return nutritionalCalories; + } +} diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysCustomerHeatStatisticsMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysCustomerHeatStatisticsMapper.xml index edb9d6ef8..db3d80fa6 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysCustomerHeatStatisticsMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysCustomerHeatStatisticsMapper.xml @@ -10,6 +10,9 @@ + + + @@ -24,6 +27,9 @@ + + + @@ -36,15 +42,13 @@ - select id, customer_id, edible_date, max_heat_value, heat_value, heat_gap, create_time, create_by, update_time, update_by, del_flag from sys_customer_heat_statistics + select id, customer_id, edible_date, max_heat_value, heat_value, protein_heat,fat_heat,carbon_water_heat,heat_gap, create_time, create_by, update_time, update_by, del_flag from sys_customer_heat_statistics + select id,name,protein_ratio,fat_ratio,carbon_ratio from sys_ingredient + where name = #{name} limit 1 + + \ No newline at end of file diff --git a/stdiet-ui/src/api/custom/foodHeatStatistics.js b/stdiet-ui/src/api/custom/foodHeatStatistics.js index 2b20b5134..315c680b3 100644 --- a/stdiet-ui/src/api/custom/foodHeatStatistics.js +++ b/stdiet-ui/src/api/custom/foodHeatStatistics.js @@ -61,3 +61,14 @@ export function addFoodHeatData(data) { }) } +// 获取热量比例分析详情 +export function getNutritionalCalories(id) { + return request({ + url: '/custom/foodHeatStatistics/getNutritionalCalories', + method: 'get', + params: {"id": id} + }) +} + + + diff --git a/stdiet-ui/src/components/HeatStatisticsDetail/index.vue b/stdiet-ui/src/components/HeatStatisticsDetail/index.vue new file mode 100644 index 000000000..cea41c8dd --- /dev/null +++ b/stdiet-ui/src/components/HeatStatisticsDetail/index.vue @@ -0,0 +1,194 @@ + + + + diff --git a/stdiet-ui/src/components/HeatStatisticsDrawer/index.vue b/stdiet-ui/src/components/HeatStatisticsDrawer/index.vue index e28b1e55c..2f050501e 100644 --- a/stdiet-ui/src/components/HeatStatisticsDrawer/index.vue +++ b/stdiet-ui/src/components/HeatStatisticsDrawer/index.vue @@ -32,13 +32,12 @@