外食计算器功能优化修改
This commit is contained in:
@ -0,0 +1,57 @@
|
||||
package com.stdiet.custom.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.stdiet.common.annotation.Excel;
|
||||
import com.stdiet.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 外食热量统计对象 sys_customer_heat_statistics
|
||||
*
|
||||
* @author xzj
|
||||
* @date 2021-02-20
|
||||
*/
|
||||
@Data
|
||||
public class SysCustomerHeatStatistics extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** $column.columnComment */
|
||||
private Long id;
|
||||
|
||||
/** 客户ID */
|
||||
@Excel(name = "客户ID")
|
||||
private Long customerId;
|
||||
|
||||
/** 日期 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date edibleDate;
|
||||
|
||||
/** 最大可摄入量 */
|
||||
@Excel(name = "最大可摄入量")
|
||||
private Integer maxHeatValue;
|
||||
|
||||
/** 当天食材总热量 */
|
||||
@Excel(name = "当天食材总热量")
|
||||
private Integer heatValue;
|
||||
|
||||
/** 当天热量缺口 */
|
||||
@Excel(name = "当天热量缺口")
|
||||
private Integer heatGap;
|
||||
|
||||
/** 删除标识 0未删除 1已删除 */
|
||||
private Integer delFlag;
|
||||
|
||||
//食材热量ID
|
||||
private Long[] foodHeatIdList;
|
||||
|
||||
//食材热量
|
||||
private Integer[] foodHeatList;
|
||||
|
||||
//具体食材集合
|
||||
private List<SysFoodHeatStatistics> foodHeatStatisticsList;
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
package com.stdiet.custom.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.stdiet.common.annotation.Excel;
|
||||
import com.stdiet.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
@ -20,9 +18,9 @@ public class SysFoodHeatStatistics extends BaseEntity
|
||||
/** $column.columnComment */
|
||||
private Long id;
|
||||
|
||||
/** 客户ID */
|
||||
@Excel(name = "客户ID")
|
||||
private Long customerId;
|
||||
/** 客户热量统计ID */
|
||||
@Excel(name = "客户热量统计ID")
|
||||
private Long customerHeatId;
|
||||
|
||||
/** 食材 */
|
||||
@Excel(name = "食材")
|
||||
@ -42,11 +40,6 @@ public class SysFoodHeatStatistics extends BaseEntity
|
||||
@Excel(name = "具体质量,单位:克")
|
||||
private Integer quantity;
|
||||
|
||||
/** 食用日期 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "食用日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date edibleDate;
|
||||
|
||||
/** 类型,0早 1中 2晚 */
|
||||
@Excel(name = "类型,0早 1中 2晚")
|
||||
private Integer edibleType;
|
||||
@ -55,11 +48,9 @@ public class SysFoodHeatStatistics extends BaseEntity
|
||||
@Excel(name = "热量数值")
|
||||
private Integer heatValue;
|
||||
|
||||
/** 热量缺口 */
|
||||
@Excel(name = "热量缺口")
|
||||
private Integer heatGap;
|
||||
|
||||
/** 删除标识 0未删除 1已删除 */
|
||||
private Integer delFlag;
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.stdiet.custom.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.stdiet.custom.domain.SysCustomerHeatStatistics;
|
||||
|
||||
/**
|
||||
* 外食热量统计Mapper接口
|
||||
*
|
||||
* @author xzj
|
||||
* @date 2021-02-20
|
||||
*/
|
||||
public interface SysCustomerHeatStatisticsMapper
|
||||
{
|
||||
/**
|
||||
* 查询外食热量统计
|
||||
*
|
||||
* @param id 外食热量统计ID
|
||||
* @return 外食热量统计
|
||||
*/
|
||||
public SysCustomerHeatStatistics selectSysCustomerHeatStatisticsById(Long id);
|
||||
|
||||
/**
|
||||
* 查询外食热量统计列表
|
||||
*
|
||||
* @param sysCustomerHeatStatistics 外食热量统计
|
||||
* @return 外食热量统计集合
|
||||
*/
|
||||
public List<SysCustomerHeatStatistics> selectSysCustomerHeatStatisticsList(SysCustomerHeatStatistics sysCustomerHeatStatistics);
|
||||
|
||||
/**
|
||||
* 新增外食热量统计
|
||||
*
|
||||
* @param sysCustomerHeatStatistics 外食热量统计
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertSysCustomerHeatStatistics(SysCustomerHeatStatistics sysCustomerHeatStatistics);
|
||||
|
||||
/**
|
||||
* 修改外食热量统计
|
||||
*
|
||||
* @param sysCustomerHeatStatistics 外食热量统计
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateSysCustomerHeatStatistics(SysCustomerHeatStatistics sysCustomerHeatStatistics);
|
||||
|
||||
/**
|
||||
* 删除外食热量统计
|
||||
*
|
||||
* @param id 外食热量统计ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysCustomerHeatStatisticsById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除外食热量统计
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysCustomerHeatStatisticsByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 根据客户ID、日期查询客户热量统计数据
|
||||
* @param sysCustomerHeatStatistics
|
||||
* @return
|
||||
*/
|
||||
public SysCustomerHeatStatistics getCustomerHeatStatisticsByDate(SysCustomerHeatStatistics sysCustomerHeatStatistics);
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.stdiet.custom.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.stdiet.custom.domain.SysCustomerHeatStatistics;
|
||||
|
||||
/**
|
||||
* 外食热量统计Service接口
|
||||
*
|
||||
* @author xzj
|
||||
* @date 2021-02-20
|
||||
*/
|
||||
public interface ISysCustomerHeatStatisticsService
|
||||
{
|
||||
/**
|
||||
* 查询外食热量统计
|
||||
*
|
||||
* @param id 外食热量统计ID
|
||||
* @return 外食热量统计
|
||||
*/
|
||||
public SysCustomerHeatStatistics selectSysCustomerHeatStatisticsById(Long id);
|
||||
|
||||
/**
|
||||
* 查询外食热量统计列表
|
||||
*
|
||||
* @param sysCustomerHeatStatistics 外食热量统计
|
||||
* @return 外食热量统计集合
|
||||
*/
|
||||
public List<SysCustomerHeatStatistics> selectSysCustomerHeatStatisticsList(SysCustomerHeatStatistics sysCustomerHeatStatistics);
|
||||
|
||||
/**
|
||||
* 新增外食热量统计
|
||||
*
|
||||
* @param sysCustomerHeatStatistics 外食热量统计
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertSysCustomerHeatStatistics(SysCustomerHeatStatistics sysCustomerHeatStatistics);
|
||||
|
||||
/**
|
||||
* 修改外食热量统计
|
||||
*
|
||||
* @param sysCustomerHeatStatistics 外食热量统计
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateSysCustomerHeatStatistics(SysCustomerHeatStatistics sysCustomerHeatStatistics);
|
||||
|
||||
/**
|
||||
* 批量删除外食热量统计
|
||||
*
|
||||
* @param ids 需要删除的外食热量统计ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysCustomerHeatStatisticsByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除外食热量统计信息
|
||||
*
|
||||
* @param id 外食热量统计ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysCustomerHeatStatisticsById(Long id);
|
||||
|
||||
/**
|
||||
* 更新食材热量并计算当天总热量
|
||||
* @param sysCustomerHeatStatistics
|
||||
* @return
|
||||
*/
|
||||
public int calculateCustomerHeat(SysCustomerHeatStatistics sysCustomerHeatStatistics);
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
package com.stdiet.custom.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.stdiet.common.utils.DateUtils;
|
||||
import com.stdiet.common.utils.HealthyUtils;
|
||||
import com.stdiet.custom.domain.SysCustomerHealthy;
|
||||
import com.stdiet.custom.domain.SysCustomerPhysicalSigns;
|
||||
import com.stdiet.custom.domain.SysFoodHeatStatistics;
|
||||
import com.stdiet.custom.mapper.SysFoodHeatStatisticsMapper;
|
||||
import com.stdiet.custom.service.ISysCustomerHealthyService;
|
||||
import com.stdiet.custom.service.ISysCustomerPhysicalSignsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.stdiet.custom.mapper.SysCustomerHeatStatisticsMapper;
|
||||
import com.stdiet.custom.domain.SysCustomerHeatStatistics;
|
||||
import com.stdiet.custom.service.ISysCustomerHeatStatisticsService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 外食热量统计Service业务层处理
|
||||
*
|
||||
* @author xzj
|
||||
* @date 2021-02-20
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class SysCustomerHeatStatisticsServiceImpl implements ISysCustomerHeatStatisticsService
|
||||
{
|
||||
@Autowired
|
||||
private SysCustomerHeatStatisticsMapper sysCustomerHeatStatisticsMapper;
|
||||
|
||||
@Autowired
|
||||
private SysFoodHeatStatisticsMapper sysFoodHeatStatisticsMapper;
|
||||
|
||||
@Autowired
|
||||
private ISysCustomerPhysicalSignsService sysCustomerPhysicalSignsService;
|
||||
|
||||
@Autowired
|
||||
private ISysCustomerHealthyService sysCustomerHealthyService;
|
||||
|
||||
/**
|
||||
* 查询外食热量统计
|
||||
*
|
||||
* @param id 外食热量统计ID
|
||||
* @return 外食热量统计
|
||||
*/
|
||||
@Override
|
||||
public SysCustomerHeatStatistics selectSysCustomerHeatStatisticsById(Long id)
|
||||
{
|
||||
return sysCustomerHeatStatisticsMapper.selectSysCustomerHeatStatisticsById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询外食热量统计列表
|
||||
*
|
||||
* @param sysCustomerHeatStatistics 外食热量统计
|
||||
* @return 外食热量统计
|
||||
*/
|
||||
@Override
|
||||
public List<SysCustomerHeatStatistics> selectSysCustomerHeatStatisticsList(SysCustomerHeatStatistics sysCustomerHeatStatistics)
|
||||
{
|
||||
return sysCustomerHeatStatisticsMapper.selectSysCustomerHeatStatisticsList(sysCustomerHeatStatistics);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增外食热量统计
|
||||
*
|
||||
* @param sysCustomerHeatStatistics 外食热量统计
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertSysCustomerHeatStatistics(SysCustomerHeatStatistics sysCustomerHeatStatistics)
|
||||
{
|
||||
sysCustomerHeatStatistics.setCreateTime(DateUtils.getNowDate());
|
||||
return sysCustomerHeatStatisticsMapper.insertSysCustomerHeatStatistics(sysCustomerHeatStatistics);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改外食热量统计
|
||||
*
|
||||
* @param sysCustomerHeatStatistics 外食热量统计
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateSysCustomerHeatStatistics(SysCustomerHeatStatistics sysCustomerHeatStatistics)
|
||||
{
|
||||
sysCustomerHeatStatistics.setUpdateTime(DateUtils.getNowDate());
|
||||
return sysCustomerHeatStatisticsMapper.updateSysCustomerHeatStatistics(sysCustomerHeatStatistics);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除外食热量统计
|
||||
*
|
||||
* @param ids 需要删除的外食热量统计ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSysCustomerHeatStatisticsByIds(Long[] ids)
|
||||
{
|
||||
return sysCustomerHeatStatisticsMapper.deleteSysCustomerHeatStatisticsByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除外食热量统计信息
|
||||
*
|
||||
* @param id 外食热量统计ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSysCustomerHeatStatisticsById(Long id)
|
||||
{
|
||||
return sysCustomerHeatStatisticsMapper.deleteSysCustomerHeatStatisticsById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新食材热量并计算当天总热量
|
||||
* @param sysCustomerHeatStatistics
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int calculateCustomerHeat(SysCustomerHeatStatistics sysCustomerHeatStatistics){
|
||||
Long[] foodHeatId = sysCustomerHeatStatistics.getFoodHeatIdList();
|
||||
Integer[] foodHeat = sysCustomerHeatStatistics.getFoodHeatList();
|
||||
if(foodHeatId != null && foodHeatId.length > 0 && foodHeat != null && foodHeat.length == foodHeatId.length){
|
||||
SysFoodHeatStatistics sysFoodHeatStatistics = new SysFoodHeatStatistics();
|
||||
int totalHeatCalue = 0;
|
||||
for (int i = 0; i < foodHeatId.length; i++) {
|
||||
sysFoodHeatStatistics.setId(foodHeatId[i]);
|
||||
sysFoodHeatStatistics.setHeatValue(foodHeat[i]);
|
||||
sysFoodHeatStatisticsMapper.updateSysFoodHeatStatistics(sysFoodHeatStatistics);
|
||||
totalHeatCalue += foodHeat[i];
|
||||
}
|
||||
sysCustomerHeatStatistics.setHeatValue(totalHeatCalue);
|
||||
Long maxHeatValue = getMaxHeatValue(sysCustomerHeatStatistics.getCustomerId());
|
||||
sysCustomerHeatStatistics.setMaxHeatValue(maxHeatValue.intValue());
|
||||
sysCustomerHeatStatistics.setHeatGap(maxHeatValue.intValue() - totalHeatCalue);
|
||||
return sysCustomerHeatStatisticsMapper.updateSysCustomerHeatStatistics(sysCustomerHeatStatistics);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public 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 0;
|
||||
}
|
||||
}
|
@ -1,21 +1,23 @@
|
||||
package com.stdiet.custom.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.stdiet.common.utils.DateUtils;
|
||||
import com.stdiet.common.utils.StringUtils;
|
||||
import com.stdiet.common.utils.sign.AesUtils;
|
||||
import com.stdiet.custom.domain.SysCustomerHeatStatistics;
|
||||
import com.stdiet.custom.dto.request.FoodHeatCalculatorRequest;
|
||||
import com.stdiet.custom.mapper.SysCustomerHeatStatisticsMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 外食热量统计Service业务层处理
|
||||
@ -24,11 +26,15 @@ import com.stdiet.custom.service.ISysFoodHeatStatisticsService;
|
||||
* @date 2021-02-19
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class SysFoodHeatStatisticsServiceImpl implements ISysFoodHeatStatisticsService
|
||||
{
|
||||
@Autowired
|
||||
private SysFoodHeatStatisticsMapper sysFoodHeatStatisticsMapper;
|
||||
|
||||
@Autowired
|
||||
private SysCustomerHeatStatisticsMapper sysCustomerHeatStatisticsMapper;
|
||||
|
||||
/**
|
||||
* 查询外食热量统计
|
||||
*
|
||||
@ -115,13 +121,25 @@ public class SysFoodHeatStatisticsServiceImpl implements ISysFoodHeatStatisticsS
|
||||
if(StringUtils.isEmpty(customerId)){
|
||||
return 0;
|
||||
}
|
||||
List<SysFoodHeatStatistics> list = new ArrayList<>();
|
||||
if(StringUtils.isNotEmpty(foodHeatCalculatorRequest.getIngredientArray())){
|
||||
List<HashMap> foodHeatList = JSON.parseArray(foodHeatCalculatorRequest.getIngredientArray(), HashMap.class);
|
||||
for(HashMap map : foodHeatList){
|
||||
map.put("customerId", customerId);
|
||||
//先判断该日期下是否已存在
|
||||
SysCustomerHeatStatistics sysCustomerHeatStatistics = new SysCustomerHeatStatistics();
|
||||
sysCustomerHeatStatistics.setCustomerId(Long.parseLong(customerId));
|
||||
sysCustomerHeatStatistics.setEdibleDate(new Date());
|
||||
SysCustomerHeatStatistics customerHeatResult = sysCustomerHeatStatisticsMapper.getCustomerHeatStatisticsByDate(sysCustomerHeatStatistics);
|
||||
if(customerHeatResult == null){
|
||||
sysCustomerHeatStatisticsMapper.insertSysCustomerHeatStatistics(sysCustomerHeatStatistics);
|
||||
}else{
|
||||
sysCustomerHeatStatistics.setId(customerHeatResult.getId());
|
||||
}
|
||||
if(sysCustomerHeatStatistics.getId() != null){
|
||||
List<SysFoodHeatStatistics> list = new ArrayList<>();
|
||||
if(StringUtils.isNotEmpty(foodHeatCalculatorRequest.getIngredientArray())){
|
||||
List<HashMap> foodHeatList = JSON.parseArray(foodHeatCalculatorRequest.getIngredientArray(), HashMap.class);
|
||||
for(HashMap map : foodHeatList){
|
||||
map.put("customerHeatId", sysCustomerHeatStatistics.getId());
|
||||
}
|
||||
return sysFoodHeatStatisticsMapper.insertFoodHeatBatch(foodHeatList);
|
||||
}
|
||||
return sysFoodHeatStatisticsMapper.insertFoodHeatBatch(foodHeatList);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user