Merge branch 'master' of gitee.com:darlk/ShengTangManage into develop
This commit is contained in:
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.stdiet.custom.service;
|
||||
|
||||
public interface AsyncCommonService {
|
||||
|
||||
/**
|
||||
* 异步更新每个食材对应的蛋白质、脂肪、碳水的质量
|
||||
*/
|
||||
public void updateFoodNutritionalQualityAndHeat(Long customerHeatId);
|
||||
}
|
@ -79,5 +79,5 @@ public interface ISysCustomerHeatStatisticsService
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public NutritionalCalories getNutritionalCaloriesByCustomer(Long id);
|
||||
public NutritionalCalories getNutritionalCaloriesByCustomerHeatId(Long id);
|
||||
}
|
@ -58,4 +58,10 @@ public interface ISysIngredientService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysIngredientById(Long id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据食材名称查询食材信息
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public SysIngredient selectSysIngredientByName(String name);}
|
@ -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<SysFoodHeatStatistics> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -10,6 +10,9 @@
|
||||
<result property="edibleDate" column="edible_date" />
|
||||
<result property="maxHeatValue" column="max_heat_value" />
|
||||
<result property="heatValue" column="heat_value" />
|
||||
<result property="proteinHeat" column="protein_heat" />
|
||||
<result property="fatHeat" column="fat_heat" />
|
||||
<result property="carbonWaterHeat" column="carbon_water_heat" />
|
||||
<result property="heatGap" column="heat_gap" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
@ -24,6 +27,9 @@
|
||||
<result property="edibleDate" column="edible_date" />
|
||||
<result property="maxHeatValue" column="max_heat_value" />
|
||||
<result property="heatValue" column="heat_value" />
|
||||
<result property="proteinHeat" column="protein_heat" />
|
||||
<result property="fatHeat" column="fat_heat" />
|
||||
<result property="carbonWaterHeat" column="carbon_water_heat" />
|
||||
<result property="heatGap" column="heat_gap" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
@ -36,15 +42,13 @@
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysCustomerHeatStatisticsVo">
|
||||
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
|
||||
</sql>
|
||||
|
||||
<select id="selectSysCustomerHeatStatisticsList" parameterType="SysCustomerHeatStatistics" resultMap="SysCustomerHeatStatisticsResult">
|
||||
<include refid="selectSysCustomerHeatStatisticsVo"/>
|
||||
<where>
|
||||
<if test="customerId != null "> and customer_id = #{customerId}</if>
|
||||
</where>
|
||||
order by id desc
|
||||
<include refid="selectSysCustomerHeatStatisticsVo"/> where del_flag = 0
|
||||
<if test="customerId != null "> and customer_id = #{customerId}</if>
|
||||
order by edible_date desc
|
||||
</select>
|
||||
|
||||
<select id="selectSysCustomerHeatStatisticsById" parameterType="Long" resultMap="SysCustomerHeatStatisticsResultExtended">
|
||||
@ -60,8 +64,11 @@
|
||||
<if test="maxHeatValue != null">max_heat_value,</if>
|
||||
<if test="heatValue != null">heat_value,</if>
|
||||
<if test="heatGap != null">heat_gap,</if>
|
||||
<if test="proteinHeat != null">protein_heat,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="fatHeat != null">fat_heat,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="carbonWaterHeat != null">carbon_water_heat,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="delFlag != null">del_flag,</if>
|
||||
@ -72,8 +79,11 @@
|
||||
<if test="maxHeatValue != null">#{maxHeatValue},</if>
|
||||
<if test="heatValue != null">#{heatValue},</if>
|
||||
<if test="heatGap != null">#{heatGap},</if>
|
||||
<if test="proteinHeat != null">#{proteinHeat},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="fatHeat != null">#{fatHeat},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="carbonWaterHeat != null">#{carbonWaterHeat},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="delFlag != null">#{delFlag},</if>
|
||||
@ -88,8 +98,11 @@
|
||||
<if test="maxHeatValue != null">max_heat_value = #{maxHeatValue},</if>
|
||||
<if test="heatValue != null">heat_value = #{heatValue},</if>
|
||||
<if test="heatGap != null">heat_gap = #{heatGap},</if>
|
||||
<if test="proteinHeat != null">protein_heat = #{proteinHeat},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="fatHeat != null">fat_heat = #{fatHeat},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="carbonWaterHeat != null">carbon_water_heat = #{carbonWaterHeat},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="delFlag != null">del_flag = #{delFlag},</if>
|
||||
|
@ -207,4 +207,10 @@
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 根据食材名称查询食材 -->
|
||||
<select id="selectSysIngredientByName" parameterType="String" resultMap="SysIngredientResult">
|
||||
select id,name,protein_ratio,fat_ratio,carbon_ratio from sys_ingredient
|
||||
where name = #{name} limit 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user