外食计算器优化,营养成分以及热量比例数据计算

This commit is contained in:
xiezhijun 2021-02-22 19:30:33 +08:00
parent b4f70fa741
commit 473ccef008
14 changed files with 477 additions and 65 deletions

View File

@ -2,10 +2,22 @@ package com.stdiet.common.utils;
public class HealthyUtils { public class HealthyUtils {
public static final double maxHeatEveryDayLess = 250.0; public static final long maxHeatEveryDayLess = 250;
//每克蛋白质对应热量千卡
public static final int proteinHeat = 4;
//每克脂肪对应热量千卡
public static final int fatHeat = 9;
//每克碳水对应热量千卡
public static final int carbonWaterHeat = 4;
//营养成分比例
public static final Integer[] nutritionRate = {30, 20, 50};
/** /**
* 计算每天最大摄入量 * 计算减脂每天最大摄入量千卡
* @param age 年龄 * @param age 年龄
* @param tall 身高 * @param tall 身高
* @param weight 体重 * @param weight 体重
@ -15,6 +27,119 @@ public class HealthyUtils {
age = age == null ? 0 : age; age = age == null ? 0 : age;
tall = tall == null ? 0 : tall; tall = tall == null ? 0 : tall;
weight = weight == null ? 0.0 : weight; weight = weight == null ? 0.0 : weight;
return Math.round(655+(9.5*weight/2)+(1.8*tall)-(4.7*age) - maxHeatEveryDayLess); return calculateMetabolizeHeat(age, tall, weight) - maxHeatEveryDayLess;
} }
/**
* 计算基础代谢BMR(千卡
* @param age
* @param tall
* @param weight
* @return
*/
public static Long calculateMetabolizeHeat(Integer age, Integer tall, Double weight){
return Math.round(655+(9.5*weight/2)+(1.8*tall)-(4.7*age));
}
/**
* 计算每公斤体重占比千卡/公斤
* @param metabolizeHeat 基础代谢BMR(千卡
* @param weight 体重
* @return
*/
public static double calculateHeatRateByWeight(long metabolizeHeat, double weight){
return NumberUtils.getNumberByRoundHalfUp(metabolizeHeat/weight*2, 2).doubleValue();
}
/**
* 计算每公斤体重占比目标范围
* @param heatRateByWeight 每公斤体重占比千卡/公斤
* @return
*/
public static double[] calculateHeatTargetRate(double heatRateByWeight){
double[] heatArray = new double[2];
heatArray[0] = heatRateByWeight - 10;
heatArray[1] = heatRateByWeight - 5;
return heatArray;
}
/**
* 计算减脂热量控制范围(千卡
* @param heatTargetRateArray 每公斤体重占比目标范围
* @param fatRateWeight 每公斤体重脂肪占比(/公斤)
* @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);
return heatArray;
}
/**
* 根据蛋白质脂肪碳水质量计算热量
* @param proteinQuality 蛋白质质量
* @param fatQuality 脂肪质量
* @param carbonWaterQuality 碳水质量
* @return
*/
public static int calculateTotalHeatByProteinFatCarbonWater(Integer proteinQuality, Integer fatQuality, Integer carbonWaterQuality){
return calculateHeatByProteinQuality(proteinQuality) + calculateHeatByFatQuality(fatQuality) + calculateHeatByCarbonWaterQuality(carbonWaterQuality);
}
/**
* 根据蛋白质质量计算热量
* @return
*/
public static int calculateHeatByProteinQuality(Integer proteinQuality){
proteinQuality = proteinQuality == null ? 0 : proteinQuality;
return proteinQuality * proteinHeat;
}
/**
* 根据脂肪质量计算热量
* @return
*/
public static int calculateHeatByFatQuality(Integer fatQuality){
fatQuality = fatQuality == null ? 0 : fatQuality;
return fatQuality * fatHeat;
}
/**
* 根据碳水质量计算热量
* @return
*/
public static int calculateHeatByCarbonWaterQuality(Integer carbonWaterQuality){
carbonWaterQuality = carbonWaterQuality == null ? 0 : carbonWaterQuality;
return carbonWaterQuality * carbonWaterHeat;
}
/**
* 根据身高计算标准体重
* @param tall 身高厘米
* @return
*/
public static double calculateStandardWeight(int tall){
return (tall-107.5)*2;
}
/**
* 返回蛋白质脂肪碳水对应热量质量
* @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;
}
} }

View File

@ -0,0 +1,17 @@
package com.stdiet.common.utils;
import java.math.BigDecimal;
public class NumberUtils {
/**
* 对double数字进行四舍五入返回BigDecimal
* @param number 数字
* @param decimalPlaces 保留的小数点位数
* @return
*/
public static BigDecimal getNumberByRoundHalfUp(double number, int decimalPlaces){
return BigDecimal.valueOf(number).setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
}
}

View File

@ -52,6 +52,15 @@ public class SysCustomerHeatStatistics extends BaseEntity
//食材热量 //食材热量
private Integer[] foodHeatList; private Integer[] foodHeatList;
//食材蛋白质质量
private Integer[] proteinQualityList;
//食材脂肪质量
private Integer[] fatQualityList;
//食材碳水质量
private Integer[] carbonWaterQualityList;
//具体食材集合 //具体食材集合
private List<SysFoodHeatStatistics> foodHeatStatisticsList; private List<SysFoodHeatStatistics> foodHeatStatisticsList;
} }

View File

@ -44,6 +44,18 @@ public class SysFoodHeatStatistics extends BaseEntity
@Excel(name = "类型0早 1中 2晚") @Excel(name = "类型0早 1中 2晚")
private Integer edibleType; private Integer edibleType;
/** 蛋白质质量,克 */
@Excel(name = "蛋白质质量,克")
private Integer proteinQuality;
/** 脂肪质量,克 */
@Excel(name = "脂肪质量,克")
private Integer fatQuality;
/** 碳水质量,克 */
@Excel(name = "碳水质量,克")
private Integer carbonWaterQuality;
/** 热量数值 */ /** 热量数值 */
@Excel(name = "热量数值") @Excel(name = "热量数值")
private Integer heatValue; private Integer heatValue;

View File

@ -0,0 +1,72 @@
package com.stdiet.custom.dto.response;
import lombok.Data;
import java.io.Serializable;
@Data
public class NutritionalCalories implements Serializable {
private static final long serialVersionUID = 1L;
//姓名
public String name;
//实际体重
public double weight;
//实际身高(厘米)
public int tall;
//年龄
public int age;
//标准体重
public double standardWeight;
//超重
public double overWeight;
//活动因子
public double activityFactor;
//基础代谢BMR(千卡
public int metabolizeHeat;
//减脂最大摄入量(千卡
public int maxIntakeHeat;
//不运动总热量(千卡
public int withoutExerciseHeat;
//运动总热量(千卡
public int exerciseHeat;
//每公斤体重占比(千卡/公斤
public double everyWeightHeat;
//目标范围千卡/公斤
public double[] targetEveryWeightHeat;
//减脂热量标准范围千卡/公斤
public double[] standardEveryWeightHeat;
//蛋白质脂肪碳水比例
public Integer[] nutritionalRate;
//蛋白质脂肪碳水对应热量千卡
public Integer[] nutritionalHeat;
//蛋白质脂肪碳水对应质量()
public Integer[] nutritionalQuality;
//每公斤体重对应蛋白质脂肪碳水占比(/公斤)
public double[] weightNutritionalRate;
//蛋白质脂肪碳水已摄入热量千卡
public Integer[] ingestedNutritionalHeat;
//蛋白质脂肪碳水剩余可摄入热量
public Integer[] surplusNutritionalHeat;
}

View File

@ -1,7 +1,10 @@
package com.stdiet.custom.mapper; package com.stdiet.custom.mapper;
import java.util.List; import java.util.List;
import com.stdiet.custom.domain.SysCustomer;
import com.stdiet.custom.domain.SysCustomerHeatStatistics; import com.stdiet.custom.domain.SysCustomerHeatStatistics;
import com.stdiet.custom.dto.response.NutritionalCalories;
/** /**
* 外食热量统计Mapper接口 * 外食热量统计Mapper接口

View File

@ -2,6 +2,7 @@ package com.stdiet.custom.service;
import java.util.List; import java.util.List;
import com.stdiet.custom.domain.SysCustomerHeatStatistics; import com.stdiet.custom.domain.SysCustomerHeatStatistics;
import com.stdiet.custom.dto.response.NutritionalCalories;
/** /**
* 外食热量统计Service接口 * 外食热量统计Service接口
@ -65,4 +66,18 @@ public interface ISysCustomerHeatStatisticsService
* @return * @return
*/ */
public int calculateCustomerHeat(SysCustomerHeatStatistics sysCustomerHeatStatistics); public int calculateCustomerHeat(SysCustomerHeatStatistics sysCustomerHeatStatistics);
/**
* 根据日期查询是否客户热量统计
* @param sysCustomerHeatStatistics
* @return
*/
SysCustomerHeatStatistics getCustomerHeatStatisticsByDate(SysCustomerHeatStatistics sysCustomerHeatStatistics);
/**
* 根据客户热量食材统计ID查询详情
* @param id
* @return
*/
public NutritionalCalories getNutritionalCaloriesByCustomer(Long id);
} }

View File

@ -1,14 +1,16 @@
package com.stdiet.custom.service.impl; package com.stdiet.custom.service.impl;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import com.stdiet.common.utils.DateUtils; import com.stdiet.common.utils.DateUtils;
import com.stdiet.common.utils.HealthyUtils; import com.stdiet.common.utils.HealthyUtils;
import com.stdiet.custom.domain.SysCustomerHealthy; import com.stdiet.custom.domain.SysCustomerHealthy;
import com.stdiet.custom.domain.SysCustomerPhysicalSigns; import com.stdiet.custom.domain.SysCustomerPhysicalSigns;
import com.stdiet.custom.domain.SysFoodHeatStatistics; import com.stdiet.custom.domain.SysFoodHeatStatistics;
import com.stdiet.custom.mapper.SysFoodHeatStatisticsMapper; import com.stdiet.custom.dto.response.NutritionalCalories;
import com.stdiet.custom.service.ISysCustomerHealthyService; import com.stdiet.custom.service.ISysCustomerHealthyService;
import com.stdiet.custom.service.ISysCustomerPhysicalSignsService; import com.stdiet.custom.service.ISysCustomerPhysicalSignsService;
import com.stdiet.custom.service.ISysFoodHeatStatisticsService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.stdiet.custom.mapper.SysCustomerHeatStatisticsMapper; import com.stdiet.custom.mapper.SysCustomerHeatStatisticsMapper;
@ -30,7 +32,7 @@ public class SysCustomerHeatStatisticsServiceImpl implements ISysCustomerHeatSta
private SysCustomerHeatStatisticsMapper sysCustomerHeatStatisticsMapper; private SysCustomerHeatStatisticsMapper sysCustomerHeatStatisticsMapper;
@Autowired @Autowired
private SysFoodHeatStatisticsMapper sysFoodHeatStatisticsMapper; private ISysFoodHeatStatisticsService sysFoodHeatStatisticsService;
@Autowired @Autowired
private ISysCustomerPhysicalSignsService sysCustomerPhysicalSignsService; private ISysCustomerPhysicalSignsService sysCustomerPhysicalSignsService;
@ -112,6 +114,15 @@ public class SysCustomerHeatStatisticsServiceImpl implements ISysCustomerHeatSta
return sysCustomerHeatStatisticsMapper.deleteSysCustomerHeatStatisticsById(id); return sysCustomerHeatStatisticsMapper.deleteSysCustomerHeatStatisticsById(id);
} }
/**
* 根据日期查询是否客户热量统计
* @param sysCustomerHeatStatistics
* @return
*/
public SysCustomerHeatStatistics getCustomerHeatStatisticsByDate(SysCustomerHeatStatistics sysCustomerHeatStatistics){
return sysCustomerHeatStatisticsMapper.getCustomerHeatStatisticsByDate(sysCustomerHeatStatistics);
}
/** /**
* 更新食材热量并计算当天总热量 * 更新食材热量并计算当天总热量
* @param sysCustomerHeatStatistics * @param sysCustomerHeatStatistics
@ -121,34 +132,81 @@ public class SysCustomerHeatStatisticsServiceImpl implements ISysCustomerHeatSta
public int calculateCustomerHeat(SysCustomerHeatStatistics sysCustomerHeatStatistics){ public int calculateCustomerHeat(SysCustomerHeatStatistics sysCustomerHeatStatistics){
Long[] foodHeatId = sysCustomerHeatStatistics.getFoodHeatIdList(); Long[] foodHeatId = sysCustomerHeatStatistics.getFoodHeatIdList();
Integer[] foodHeat = sysCustomerHeatStatistics.getFoodHeatList(); Integer[] foodHeat = sysCustomerHeatStatistics.getFoodHeatList();
if(foodHeatId != null && foodHeatId.length > 0 && foodHeat != null && foodHeat.length == foodHeatId.length){ if(foodHeatId != null && foodHeatId.length > 0){
SysFoodHeatStatistics sysFoodHeatStatistics = new SysFoodHeatStatistics(); SysFoodHeatStatistics sysFoodHeatStatistics = new SysFoodHeatStatistics();
int totalHeatCalue = 0; int totalHeatCalue = 0;
for (int i = 0; i < foodHeatId.length; i++) { for (int i = 0; i < foodHeatId.length; i++) {
sysFoodHeatStatistics.setId(foodHeatId[i]); sysFoodHeatStatistics.setId(foodHeatId[i]);
sysFoodHeatStatistics.setHeatValue(foodHeat[i]); sysFoodHeatStatistics.setProteinQuality(sysCustomerHeatStatistics.getProteinQualityList()[i]);
sysFoodHeatStatisticsMapper.updateSysFoodHeatStatistics(sysFoodHeatStatistics); sysFoodHeatStatistics.setFatQuality(sysCustomerHeatStatistics.getFatQualityList()[i]);
totalHeatCalue += foodHeat[i]; sysFoodHeatStatistics.setCarbonWaterQuality(sysCustomerHeatStatistics.getCarbonWaterQualityList()[i]);
//根据蛋白质脂肪碳水计算热量
sysFoodHeatStatistics.setHeatValue(HealthyUtils.calculateTotalHeatByProteinFatCarbonWater(sysCustomerHeatStatistics.getProteinQualityList()[i],
sysCustomerHeatStatistics.getFatQualityList()[i], sysCustomerHeatStatistics.getCarbonWaterQualityList()[i]));
sysFoodHeatStatisticsService.updateSysFoodHeatStatistics(sysFoodHeatStatistics);
totalHeatCalue += sysFoodHeatStatistics.getHeatValue();
} }
sysCustomerHeatStatistics.setHeatValue(totalHeatCalue); sysCustomerHeatStatistics.setHeatValue(totalHeatCalue);
Long maxHeatValue = getMaxHeatValue(sysCustomerHeatStatistics.getCustomerId()); sysCustomerHeatStatistics.setHeatGap(sysCustomerHeatStatistics.getMaxHeatValue() - totalHeatCalue);
sysCustomerHeatStatistics.setMaxHeatValue(maxHeatValue.intValue());
sysCustomerHeatStatistics.setHeatGap(maxHeatValue.intValue() - totalHeatCalue);
return sysCustomerHeatStatisticsMapper.updateSysCustomerHeatStatistics(sysCustomerHeatStatistics); return sysCustomerHeatStatisticsMapper.updateSysCustomerHeatStatistics(sysCustomerHeatStatistics);
} }
return 0; return 0;
} }
public long getMaxHeatValue(Long customerId){ /**
* 根据客户热量食材统计ID查询详情
* @param id
* @return
*/
public NutritionalCalories getNutritionalCaloriesByCustomer(Long id){
NutritionalCalories nutritionalCalories = new NutritionalCalories();
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]);
}
}
return nutritionalCalories;
}
/**
* 根据用户ID查询该用户每天最大摄入量
* @param customerId
* @return
*/
private SysCustomerHealthy getSysCustomerHealthy(Long customerId){
SysCustomerHealthy sysCustomerHealthy = sysCustomerHealthyService.selectSysCustomerHealthyByCustomerId(customerId); SysCustomerHealthy sysCustomerHealthy = sysCustomerHealthyService.selectSysCustomerHealthyByCustomerId(customerId);
if(sysCustomerHealthy != null){ if(sysCustomerHealthy != null){
return HealthyUtils.calculateMaxHeatEveryDay(sysCustomerHealthy.getAge().intValue(),sysCustomerHealthy.getTall(),sysCustomerHealthy.getWeight().doubleValue()); return sysCustomerHealthy;
} }
//查询体征信息 //查询体征信息
SysCustomerPhysicalSigns sysCustomerPhysicalSigns = sysCustomerPhysicalSignsService.selectSysCustomerPhysicalSignsByCusId(customerId); SysCustomerPhysicalSigns sysCustomerPhysicalSigns = sysCustomerPhysicalSignsService.selectSysCustomerPhysicalSignsByCusId(customerId);
if(sysCustomerPhysicalSigns != null){ if(sysCustomerPhysicalSigns != null){
return HealthyUtils.calculateMaxHeatEveryDay(sysCustomerPhysicalSigns.getAge().intValue(),sysCustomerPhysicalSigns.getTall(),sysCustomerPhysicalSigns.getWeight().doubleValue()); sysCustomerHealthy = new SysCustomerHealthy();
sysCustomerHealthy.setName(sysCustomerPhysicalSigns.getName());
sysCustomerHealthy.setTall(sysCustomerPhysicalSigns.getTall());
sysCustomerHealthy.setAge(sysCustomerPhysicalSigns.getAge().longValue());
sysCustomerHealthy.setWeight(BigDecimal.valueOf(sysCustomerPhysicalSigns.getWeight()));
} }
return 0; return sysCustomerHealthy;
} }
} }

View File

@ -1,17 +1,19 @@
package com.stdiet.custom.service.impl; package com.stdiet.custom.service.impl;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.stdiet.common.utils.DateUtils; import com.stdiet.common.utils.DateUtils;
import com.stdiet.common.utils.HealthyUtils;
import com.stdiet.common.utils.StringUtils; import com.stdiet.common.utils.StringUtils;
import com.stdiet.common.utils.sign.AesUtils; import com.stdiet.common.utils.sign.AesUtils;
import com.stdiet.custom.domain.SysCustomerHealthy;
import com.stdiet.custom.domain.SysCustomerHeatStatistics; import com.stdiet.custom.domain.SysCustomerHeatStatistics;
import com.stdiet.custom.domain.SysCustomerPhysicalSigns;
import com.stdiet.custom.dto.request.FoodHeatCalculatorRequest; import com.stdiet.custom.dto.request.FoodHeatCalculatorRequest;
import com.stdiet.custom.mapper.SysCustomerHeatStatisticsMapper; import com.stdiet.custom.service.ISysCustomerHealthyService;
import com.stdiet.custom.service.ISysCustomerHeatStatisticsService;
import com.stdiet.custom.service.ISysCustomerPhysicalSignsService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.stdiet.custom.mapper.SysFoodHeatStatisticsMapper; import com.stdiet.custom.mapper.SysFoodHeatStatisticsMapper;
@ -19,6 +21,8 @@ import com.stdiet.custom.domain.SysFoodHeatStatistics;
import com.stdiet.custom.service.ISysFoodHeatStatisticsService; import com.stdiet.custom.service.ISysFoodHeatStatisticsService;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.xml.crypto.Data;
/** /**
* 外食热量统计Service业务层处理 * 外食热量统计Service业务层处理
* *
@ -33,7 +37,13 @@ public class SysFoodHeatStatisticsServiceImpl implements ISysFoodHeatStatisticsS
private SysFoodHeatStatisticsMapper sysFoodHeatStatisticsMapper; private SysFoodHeatStatisticsMapper sysFoodHeatStatisticsMapper;
@Autowired @Autowired
private SysCustomerHeatStatisticsMapper sysCustomerHeatStatisticsMapper; private ISysCustomerHeatStatisticsService sysCustomerHeatStatisticsService;
@Autowired
private ISysCustomerPhysicalSignsService sysCustomerPhysicalSignsService;
@Autowired
private ISysCustomerHealthyService sysCustomerHealthyService;
/** /**
* 查询外食热量统计 * 查询外食热量统计
@ -118,29 +128,67 @@ public class SysFoodHeatStatisticsServiceImpl implements ISysFoodHeatStatisticsS
public int addMuchFoodHeat(FoodHeatCalculatorRequest foodHeatCalculatorRequest){ public int addMuchFoodHeat(FoodHeatCalculatorRequest foodHeatCalculatorRequest){
//客户ID解密 //客户ID解密
String customerId = StringUtils.isNotEmpty(foodHeatCalculatorRequest.getCustomerEncId()) ? AesUtils.decrypt(foodHeatCalculatorRequest.getCustomerEncId(), null) : ""; String customerId = StringUtils.isNotEmpty(foodHeatCalculatorRequest.getCustomerEncId()) ? AesUtils.decrypt(foodHeatCalculatorRequest.getCustomerEncId(), null) : "";
if(StringUtils.isEmpty(customerId)){ if(StringUtils.isEmpty(customerId) || StringUtils.isEmpty(foodHeatCalculatorRequest.getIngredientArray())){
return 0; return 0;
} }
//先判断该日期下是否已存在 List<HashMap> foodHeatList = JSON.parseArray(foodHeatCalculatorRequest.getIngredientArray(), HashMap.class);
SysCustomerHeatStatistics sysCustomerHeatStatistics = new SysCustomerHeatStatistics(); if(foodHeatList == null || foodHeatList.size() == 0){
sysCustomerHeatStatistics.setCustomerId(Long.parseLong(customerId)); return 0;
sysCustomerHeatStatistics.setEdibleDate(new Date());
SysCustomerHeatStatistics customerHeatResult = sysCustomerHeatStatisticsMapper.getCustomerHeatStatisticsByDate(sysCustomerHeatStatistics);
if(customerHeatResult == null){
sysCustomerHeatStatisticsMapper.insertSysCustomerHeatStatistics(sysCustomerHeatStatistics);
}else{
sysCustomerHeatStatistics.setId(customerHeatResult.getId());
} }
if(sysCustomerHeatStatistics.getId() != null){ Map<String, List<HashMap>> dateFoodMap = new HashMap<>();
List<SysFoodHeatStatistics> list = new ArrayList<>(); //根据日期分类
if(StringUtils.isNotEmpty(foodHeatCalculatorRequest.getIngredientArray())){ for(HashMap map : foodHeatList){
List<HashMap> foodHeatList = JSON.parseArray(foodHeatCalculatorRequest.getIngredientArray(), HashMap.class); String edibleDate = map.get("edibleDate").toString();
for(HashMap map : foodHeatList){ if(dateFoodMap.containsKey(edibleDate)){
map.put("customerHeatId", sysCustomerHeatStatistics.getId()); dateFoodMap.get(edibleDate).add(map);
} }else{
return sysFoodHeatStatisticsMapper.insertFoodHeatBatch(foodHeatList); List<HashMap> list = new ArrayList<>();
list.add(map);
dateFoodMap.put(edibleDate, list);
} }
} }
return 0; int row = 0;
int maxHeatValue = getMaxHeatValue(Long.parseLong(customerId)).intValue();
for (String dateKey : dateFoodMap.keySet()) {
//先判断该日期下是否已存在
SysCustomerHeatStatistics sysCustomerHeatStatistics = new SysCustomerHeatStatistics();
sysCustomerHeatStatistics.setCustomerId(Long.parseLong(customerId));
sysCustomerHeatStatistics.setEdibleDate(DateUtils.parseDate(dateKey));
SysCustomerHeatStatistics customerHeatResult = sysCustomerHeatStatisticsService.getCustomerHeatStatisticsByDate(sysCustomerHeatStatistics);
if(customerHeatResult == null){
sysCustomerHeatStatistics.setMaxHeatValue(maxHeatValue);
sysCustomerHeatStatisticsService.insertSysCustomerHeatStatistics(sysCustomerHeatStatistics);
}else{
sysCustomerHeatStatistics.setId(customerHeatResult.getId());
}
if(sysCustomerHeatStatistics.getId() != null){
for(HashMap map : dateFoodMap.get(dateKey)){
map.put("customerHeatId", sysCustomerHeatStatistics.getId());
map.put("number", map.get("number") != null && "".equals(map.get("number").toString().trim()) ? null : map.get("number"));
map.put("unit", map.get("unit") != null && "".equals(map.get("unit").toString().trim()) ? null : map.get("unit"));
map.put("quantity", map.get("quantity") != null && "".equals(map.get("quantity").toString().trim()) ? null : map.get("quantity"));
}
row = sysFoodHeatStatisticsMapper.insertFoodHeatBatch(dateFoodMap.get(dateKey));
}
}
return row;
}
/**
* 根据用户ID查询该用户每天最大摄入量
* @param customerId
* @return
*/
private Long getMaxHeatValue(Long customerId){
SysCustomerHealthy sysCustomerHealthy = sysCustomerHealthyService.selectSysCustomerHealthyByCustomerId(customerId);
if(sysCustomerHealthy != null){
return HealthyUtils.calculateMaxHeatEveryDay(sysCustomerHealthy.getAge().intValue(),sysCustomerHealthy.getTall(),sysCustomerHealthy.getWeight().doubleValue());
}
//查询体征信息
SysCustomerPhysicalSigns sysCustomerPhysicalSigns = sysCustomerPhysicalSignsService.selectSysCustomerPhysicalSignsByCusId(customerId);
if(sysCustomerPhysicalSigns != null){
return HealthyUtils.calculateMaxHeatEveryDay(sysCustomerPhysicalSigns.getAge().intValue(),sysCustomerPhysicalSigns.getTall(),sysCustomerPhysicalSigns.getWeight().doubleValue());
}
return 0L;
} }
} }

View File

@ -124,7 +124,10 @@
<result property="number" column="number" /> <result property="number" column="number" />
<result property="quantity" column="quantity" /> <result property="quantity" column="quantity" />
<result property="edibleType" column="edible_type" /> <result property="edibleType" column="edible_type" />
<result property="proteinQuality" column="protein_quality" />
<result property="heatValue" column="heat_value" /> <result property="heatValue" column="heat_value" />
<result property="fatQuality" column="fat_quality" />
<result property="carbonWaterQuality" column="carbon_water_quality" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
@ -135,7 +138,7 @@
</resultMap> </resultMap>
<select id="selectSysFoodHeatStatisticsList" parameterType="Long" resultMap="SysFoodHeatStatisticsResult"> <select id="selectSysFoodHeatStatisticsList" parameterType="Long" resultMap="SysFoodHeatStatisticsResult">
select sfhs.id, sfhs.customer_heat_id, sfhs.ingredient, sfhs.unit, sfhs.number, sfhs.quantity, sfhs.edible_type, sfhs.heat_value,cusUnit.dict_label as unitName select sfhs.id, sfhs.customer_heat_id, sfhs.ingredient, sfhs.unit, sfhs.number, sfhs.quantity, sfhs.edible_type, sfhs.protein_quality, sfhs.fat_quality, sfhs.carbon_water_quality,sfhs.heat_value,cusUnit.dict_label as unitName
from sys_food_heat_statistics as sfhs from sys_food_heat_statistics as sfhs
LEFT JOIN (SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'cus_cus_unit') AS cusUnit ON cusUnit.dict_value = sfhs.unit LEFT JOIN (SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'cus_cus_unit') AS cusUnit ON cusUnit.dict_value = sfhs.unit
where sfhs.del_flag = 0 and customer_heat_id = #{id} where sfhs.del_flag = 0 and customer_heat_id = #{id}

View File

@ -12,7 +12,10 @@
<result property="number" column="number" /> <result property="number" column="number" />
<result property="quantity" column="quantity" /> <result property="quantity" column="quantity" />
<result property="edibleType" column="edible_type" /> <result property="edibleType" column="edible_type" />
<result property="proteinQuality" column="protein_quality" />
<result property="heatValue" column="heat_value" /> <result property="heatValue" column="heat_value" />
<result property="fatQuality" column="fat_quality" />
<result property="carbonWaterQuality" column="carbon_water_quality" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
@ -23,11 +26,11 @@
</resultMap> </resultMap>
<sql id="selectSysFoodHeatStatisticsVo"> <sql id="selectSysFoodHeatStatisticsVo">
select id, customer_heat_id, ingredient, unit, number, quantity, edible_type, heat_value, create_time, create_by, update_time, update_by, del_flag from sys_food_heat_statistics select id, customer_heat_id, ingredient, unit, number, quantity, edible_type, protein_quality, heat_value, fat_quality, carbon_water_quality,create_time, create_by, update_time, update_by, del_flag from sys_food_heat_statistics
</sql> </sql>
<select id="selectSysFoodHeatStatisticsList" parameterType="SysFoodHeatStatistics" resultMap="SysFoodHeatStatisticsResult"> <select id="selectSysFoodHeatStatisticsList" parameterType="SysFoodHeatStatistics" resultMap="SysFoodHeatStatisticsResult">
select sfhs.id, sfhs.customer_heat_id, sfhs.ingredient, sfhs.unit, sfhs.number, sfhs.quantity, sfhs.edible_type, sfhs.heat_value,cusUnit.dict_label as unitName select sfhs.id, sfhs.customer_heat_id, sfhs.ingredient, sfhs.unit, sfhs.number, sfhs.quantity, sfhs.edible_type, sfhs.protein_quality, sfhs.fat_quality, sfhs.carbon_water_quality,sfhs.heat_value,cusUnit.dict_label as unitName
from sys_food_heat_statistics as sfhs from sys_food_heat_statistics as sfhs
LEFT JOIN (SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'cus_cus_unit') AS cusUnit ON cusUnit.dict_value = sfhs.unit LEFT JOIN (SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'cus_cus_unit') AS cusUnit ON cusUnit.dict_value = sfhs.unit
where sfhs.del_flag = 0 where sfhs.del_flag = 0
@ -47,7 +50,10 @@
<if test="number != null">number,</if> <if test="number != null">number,</if>
<if test="quantity != null">quantity,</if> <if test="quantity != null">quantity,</if>
<if test="edibleType != null">edible_type,</if> <if test="edibleType != null">edible_type,</if>
<if test="proteinQuality != null">protein_quality,</if>
<if test="heatValue != null">heat_value,</if> <if test="heatValue != null">heat_value,</if>
<if test="fatQuality != null">fat_quality,</if>
<if test="carbonWaterQuality != null">carbon_water_quality,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
<if test="createBy != null">create_by,</if> <if test="createBy != null">create_by,</if>
<if test="updateTime != null">update_time,</if> <if test="updateTime != null">update_time,</if>
@ -61,7 +67,10 @@
<if test="number != null">#{number},</if> <if test="number != null">#{number},</if>
<if test="quantity != null">#{quantity},</if> <if test="quantity != null">#{quantity},</if>
<if test="edibleType != null">#{edibleType},</if> <if test="edibleType != null">#{edibleType},</if>
<if test="proteinQuality != null">#{proteinQuality},</if>
<if test="heatValue != null">#{heatValue},</if> <if test="heatValue != null">#{heatValue},</if>
<if test="fatQuality != null">#{fatQuality},</if>
<if test="carbonWaterQuality != null">#{carbonWaterQuality},</if>
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
<if test="createBy != null">#{createBy},</if> <if test="createBy != null">#{createBy},</if>
<if test="updateTime != null">#{updateTime},</if> <if test="updateTime != null">#{updateTime},</if>
@ -79,7 +88,10 @@
<if test="number != null">number = #{number},</if> <if test="number != null">number = #{number},</if>
<if test="quantity != null">quantity = #{quantity},</if> <if test="quantity != null">quantity = #{quantity},</if>
<if test="edibleType != null">edible_type = #{edibleType},</if> <if test="edibleType != null">edible_type = #{edibleType},</if>
<if test="proteinQuality != null">protein_quality = #{proteinQuality},</if>
<if test="heatValue != null">heat_value = #{heatValue},</if> <if test="heatValue != null">heat_value = #{heatValue},</if>
<if test="fatQuality != null">fat_quality = #{fatQuality},</if>
<if test="carbonWaterQuality != null">carbon_water_quality = #{carbonWaterQuality},</if>
<if test="createTime != null">create_time = #{createTime},</if> <if test="createTime != null">create_time = #{createTime},</if>
<if test="createBy != null">create_by = #{createBy},</if> <if test="createBy != null">create_by = #{createBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if> <if test="updateTime != null">update_time = #{updateTime},</if>

View File

@ -1,13 +1,18 @@
<template> <template>
<!-- 计算食材热量对话框 --> <!-- 计算食材热量对话框 -->
<el-dialog :title="title" :visible.sync="open" width="750px" append-to-body> <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
<el-form ref="form" :model="form" label-position="top" :rules="rules" label-width="100px"> <el-form ref="form" :model="form" label-position="top" :rules="rules" label-width="100px">
<el-form-item v-for="(item,index) in foodHeatList" label="" class="margin-left"> <el-form-item v-for="(item,index) in foodHeatList" label="" class="margin-left">
<div> <div>
<span>食材名称</span><el-input style="width:30%" placeholder="" :readonly="true" :value="item.ingredient"/> <span>食材名称</span><el-input style="width:20%" placeholder="" :readonly="true" :value="item.ingredient"/>
<span style="margin-left: 10px">份量</span><el-input style="width:25%" placeholder="" :readonly="true" :value="getNumberString(item)"/> <span style="margin-left: 10px">份量</span><el-input style="width:20%" placeholder="" :readonly="true" :value="getNumberString(item)"/>
<span style="margin-left: 10px">热量</span><el-input style="width:15%" type="number" placeholder="" v-model="item.heatValue"/><span>千卡</span> <!--<span style="margin-left: 10px">热量</span><el-input style="width:15%" type="number" placeholder="" v-model="item.heatValue"/><span>千卡</span>-->
<span style="margin-left: 10px">蛋白质/脂肪/碳水</span>
<el-input style="width:10%" placeholder="" v-model="item.proteinQuality"/>
<el-input style="width:10%;margin-left: 5px" placeholder="" v-model="item.fatQuality"/>
<el-input style="width:10%;margin-left: 5px" placeholder="" v-model="item.carbonWaterQuality"/>
<span style="margin-left: 5px"></span>
</div> </div>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -29,6 +34,7 @@
}, },
props: {}, props: {},
data() { data() {
return { return {
// //
title: "", title: "",
@ -62,7 +68,7 @@
getFoodHeatStatistics(id).then((response) => { getFoodHeatStatistics(id).then((response) => {
//let contractDetail = response.data; //let contractDetail = response.data;
this.heatData = response.data; this.heatData = response.data;
this.foodHeatList = response.data.foodHeatStatisticsList != null ? response.data.foodHeatStatisticsList : []; this.foodHeatList = response.data.foodHeatStatisticsList != null ? response.data.foodHeatStatisticsList : [];
}); });
}, },
getNumberString(foodData){ getNumberString(foodData){
@ -87,23 +93,34 @@
}, },
/** 提交按钮 */ /** 提交按钮 */
submitForm() { submitForm() {
var reg = /^([1-9]\d*|[0]{1,1})$/;
if(this.foodHeatList.length == 0){ if(this.foodHeatList.length == 0){
return; return;
} }
let obj = {}; let obj = {};
obj.foodHeatIdList = [];
obj.foodHeatList = [];
obj.id = this.heatData.id; obj.id = this.heatData.id;
obj.customerId = this.heatData.customerId; obj.customerId = this.heatData.customerId;
obj.maxHeatValue = this.heatData.maxHeatValue;
obj.foodHeatIdList = [];
obj.proteinQualityList = [];
obj.fatQualityList = [];
obj.carbonWaterQualityList = [];
let verifyFlag = true;
this.foodHeatList.forEach((item,index) => { this.foodHeatList.forEach((item,index) => {
obj.foodHeatIdList.push(item.id); obj.foodHeatIdList.push(item.id);
if(!/^[1-9]\d*$/.test(item.heatValue)){ if(!reg.test(item.proteinQuality) || !reg.test(item.fatQuality) || !reg.test(item.carbonWaterQuality)){
obj.foodHeatList.push(0); verifyFlag = false;
}else{ }else{
obj.foodHeatList.push(item.heatValue); obj.proteinQualityList.push(item.proteinQuality);
obj.fatQualityList.push(item.fatQuality);
obj.carbonWaterQualityList.push(item.carbonWaterQuality);
} }
}); });
console.log(obj.foodHeatIdList.length); if(!verifyFlag){
this.$message({message: "填写的数值格式错误", type: "warning"});
return;
}
//console.log(obj.foodHeatIdList.length);
addFoodHeatData(obj).then(response => { addFoodHeatData(obj).then(response => {
if (response.code === 200) { if (response.code === 200) {
this.msgSuccess("提交成功"); this.msgSuccess("提交成功");

View File

@ -27,7 +27,7 @@
</el-table-column> </el-table-column>
<el-table-column label="质量(克)" align="center" prop="quantity" />--> <el-table-column label="质量(克)" align="center" prop="quantity" />-->
<el-table-column label="最大摄入量" align="center" prop="maxHeatValue" /> <el-table-column label="摄入量" align="center" prop="maxHeatValue" />
<el-table-column label="食材热量" align="center" prop="heatValue" /> <el-table-column label="食材热量" align="center" prop="heatValue" />
<el-table-column label="热量缺口" align="center" prop="heatGap" /> <el-table-column label="热量缺口" align="center" prop="heatGap" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">

View File

@ -35,6 +35,16 @@
</el-tag> </el-tag>
</el-form-item> </el-form-item>
<div> <div>
<el-form-item label="日期" prop="edibleDate">
<el-date-picker
v-model="form.edibleDate"
type="date"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"
:picker-options="pickerOptions"
placeholder="选择日期">
</el-date-picker>
</el-form-item>
<el-form-item label="食材名称" prop="ingredient"> <el-form-item label="食材名称" prop="ingredient">
<el-input v-model="form.ingredient" placeholder="请输入食材名称" maxlength="20"/> <el-input v-model="form.ingredient" placeholder="请输入食材名称" maxlength="20"/>
</el-form-item> </el-form-item>
@ -64,6 +74,8 @@
</template> </template>
<script> <script>
import { getDictData,getCustomerBaseMessage,addFoodHeatStatistics } from "@/api/custom/customerInvestigation"; import { getDictData,getCustomerBaseMessage,addFoodHeatStatistics } from "@/api/custom/customerInvestigation";
import dayjs from "dayjs";
const nowDate = dayjs().format("YYYY-MM-DD");
const logo = require("@/assets/logo/st_logo.png"); const logo = require("@/assets/logo/st_logo.png");
export default { export default {
name: "index", name: "index",
@ -93,6 +105,7 @@
phone: null phone: null
}, },
form: { form: {
edibleDate: nowDate,
ingredient: null, ingredient: null,
number: null, number: null,
unit: null, unit: null,
@ -100,9 +113,7 @@
}, },
rules: { rules: {
ingredient: [{ required: true, trigger: "blur", message: "请输入食材名称" }], ingredient: [{ required: true, trigger: "blur", message: "请输入食材名称" }],
/*numberUnit: [ edibleDate: [{ required: true, trigger: "blur", message: "请选择日期" }]
{ required: false, trigger: "blur", validator: checkNumberUnit }
],*/
}, },
ingredientTagArray:[ ingredientTagArray:[
@ -111,7 +122,12 @@
], ],
// //
cusUnitOptions:[] cusUnitOptions:[],
pickerOptions: {
disabledDate(time) {
return time.getTime() > Date.now();
},
},
}; };
}, },
components: { components: {
@ -158,8 +174,9 @@
}); });
}, },
verify(){ verify(){
var reg = /^([1-9]\d*|[0]{1,1})$/;
if(this.form.number != null && this.form.number != ""){ if(this.form.number != null && this.form.number != ""){
if(!/^[1-9]\d*$/.test(this.form.number+"")){ if(!reg.test(this.form.number+"")){
this.$message({message: "通俗计量的数量格式错误", type: "warning"}); this.$message({message: "通俗计量的数量格式错误", type: "warning"});
return false; return false;
} }
@ -168,7 +185,7 @@
return false; return false;
} }
} }
if(this.form.quantity != null && this.form.quantity != "" && !/^[1-9]\d*$/.test(this.form.quantity)){ if(this.form.quantity != null && this.form.quantity != "" && !reg.test(this.form.quantity)){
this.$message({message: "重量格式错误", type: "warning"}); this.$message({message: "重量格式错误", type: "warning"});
return false; return false;
} }
@ -180,6 +197,7 @@
}, },
reset(){ reset(){
this.form = { this.form = {
edibleDate: nowDate,
ingredient: null, ingredient: null,
number: null, number: null,
unit: null, unit: null,
@ -192,13 +210,15 @@
submit(){ submit(){
if (this.submitFlag) { if (this.submitFlag) {
this.$message({ this.$message({
message: "请勿频繁提交,1分钟后重试", message: "请勿频繁提交,分钟后重试",
type: "warning", type: "warning",
}); });
return; return;
} }
this.timer = setTimeout(this.againSumbit,1000*60); if(this.form.ingredient && this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){
if(this.form.ingredient && this.verify() && this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){ if(!this.verify()){
return;
}
this.ingredientArray.push(this.form); this.ingredientArray.push(this.form);
this.ingredientTagArray.push(this.form.ingredient); this.ingredientTagArray.push(this.form.ingredient);
this.reset(); this.reset();
@ -207,6 +227,7 @@
this.$message({message: "还未添加食材数据,无法提交", type: "warning"}); this.$message({message: "还未添加食材数据,无法提交", type: "warning"});
return; return;
} }
this.timer = setTimeout(this.againSumbit,1000*60);
let submitObject = {}; let submitObject = {};
submitObject.ingredientArray = JSON.stringify(this.ingredientArray); submitObject.ingredientArray = JSON.stringify(this.ingredientArray);
submitObject.customerEncId = this.customer.customerEncId; submitObject.customerEncId = this.customer.customerEncId;