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 59cc986e7..8eff00c7a 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 @@ -1,6 +1,9 @@ package com.stdiet.web.controller.custom; import java.util.List; + +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; @@ -15,8 +18,6 @@ import com.stdiet.common.annotation.Log; import com.stdiet.common.core.controller.BaseController; import com.stdiet.common.core.domain.AjaxResult; import com.stdiet.common.enums.BusinessType; -import com.stdiet.custom.domain.SysFoodHeatStatistics; -import com.stdiet.custom.service.ISysFoodHeatStatisticsService; import com.stdiet.common.utils.poi.ExcelUtil; import com.stdiet.common.core.page.TableDataInfo; @@ -31,17 +32,17 @@ import com.stdiet.common.core.page.TableDataInfo; public class SysFoodHeatStatisticsController extends BaseController { @Autowired - private ISysFoodHeatStatisticsService sysFoodHeatStatisticsService; + private ISysCustomerHeatStatisticsService sysCustomerHeatStatisticsService; /** * 查询外食热量统计列表 */ @PreAuthorize("@ss.hasPermi('custom:foodHeatStatistics:list')") @GetMapping("/list") - public TableDataInfo list(SysFoodHeatStatistics sysFoodHeatStatistics) + public TableDataInfo list(SysCustomerHeatStatistics sysCustomerHeatStatistics) { startPage(); - List list = sysFoodHeatStatisticsService.selectSysFoodHeatStatisticsList(sysFoodHeatStatistics); + List list = sysCustomerHeatStatisticsService.selectSysCustomerHeatStatisticsList(sysCustomerHeatStatistics); return getDataTable(list); } @@ -51,11 +52,11 @@ public class SysFoodHeatStatisticsController extends BaseController @PreAuthorize("@ss.hasPermi('custom:foodHeatStatistics:export')") @Log(title = "外食热量统计", businessType = BusinessType.EXPORT) @GetMapping("/export") - public AjaxResult export(SysFoodHeatStatistics sysFoodHeatStatistics) + public AjaxResult export(SysCustomerHeatStatistics sysCustomerHeatStatistics) { - List list = sysFoodHeatStatisticsService.selectSysFoodHeatStatisticsList(sysFoodHeatStatistics); - ExcelUtil util = new ExcelUtil(SysFoodHeatStatistics.class); - return util.exportExcel(list, "foodHeatStatistics"); + List list = sysCustomerHeatStatisticsService.selectSysCustomerHeatStatisticsList(sysCustomerHeatStatistics); + ExcelUtil util = new ExcelUtil(SysCustomerHeatStatistics.class); + return util.exportExcel(list, "customerHeatstatistics"); } /** @@ -65,7 +66,7 @@ public class SysFoodHeatStatisticsController extends BaseController @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { - return AjaxResult.success(sysFoodHeatStatisticsService.selectSysFoodHeatStatisticsById(id)); + return AjaxResult.success(sysCustomerHeatStatisticsService.selectSysCustomerHeatStatisticsById(id)); } /** @@ -74,9 +75,9 @@ public class SysFoodHeatStatisticsController extends BaseController @PreAuthorize("@ss.hasPermi('custom:foodHeatStatistics:add')") @Log(title = "外食热量统计", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody SysFoodHeatStatistics sysFoodHeatStatistics) + public AjaxResult add(@RequestBody SysCustomerHeatStatistics sysCustomerHeatStatistics) { - return toAjax(sysFoodHeatStatisticsService.insertSysFoodHeatStatistics(sysFoodHeatStatistics)); + return toAjax(sysCustomerHeatStatisticsService.insertSysCustomerHeatStatistics(sysCustomerHeatStatistics)); } /** @@ -85,9 +86,9 @@ public class SysFoodHeatStatisticsController extends BaseController @PreAuthorize("@ss.hasPermi('custom:foodHeatStatistics:edit')") @Log(title = "外食热量统计", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody SysFoodHeatStatistics sysFoodHeatStatistics) + public AjaxResult edit(@RequestBody SysCustomerHeatStatistics sysCustomerHeatStatistics) { - return toAjax(sysFoodHeatStatisticsService.updateSysFoodHeatStatistics(sysFoodHeatStatistics)); + return toAjax(sysCustomerHeatStatisticsService.updateSysCustomerHeatStatistics(sysCustomerHeatStatistics)); } /** @@ -98,6 +99,16 @@ public class SysFoodHeatStatisticsController extends BaseController @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { - return toAjax(sysFoodHeatStatisticsService.deleteSysFoodHeatStatisticsByIds(ids)); + return toAjax(sysCustomerHeatStatisticsService.deleteSysCustomerHeatStatisticsByIds(ids)); + } + + /** + * 修改食材热量并计算 + */ + @Log(title = "修改食材热量并计算", businessType = BusinessType.UPDATE) + @RequestMapping("/addFoodHeatData") + public AjaxResult addFoodHeatData(@RequestBody SysCustomerHeatStatistics sysCustomerHeatStatistics) + { + return toAjax(sysCustomerHeatStatisticsService.calculateCustomerHeat(sysCustomerHeatStatistics)); } } \ 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 new file mode 100644 index 000000000..e9e07cf79 --- /dev/null +++ b/stdiet-common/src/main/java/com/stdiet/common/utils/HealthyUtils.java @@ -0,0 +1,20 @@ +package com.stdiet.common.utils; + +public class HealthyUtils { + + public static final double maxHeatEveryDayLess = 250.0; + + /** + * 计算每天最大摄入量 + * @param age 年龄 + * @param tall 身高 + * @param weight 体重 + * @return + */ + 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; + return Math.round(655+(9.5*weight/2)+(1.8*tall)-(4.7*age) - maxHeatEveryDayLess); + } +} 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 new file mode 100644 index 000000000..003594e16 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysCustomerHeatStatistics.java @@ -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 foodHeatStatisticsList; +} \ No newline at end of file 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 c65e8060b..4865b2317 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 @@ -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; + + } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysCustomerHeatStatisticsMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysCustomerHeatStatisticsMapper.java new file mode 100644 index 000000000..a47ff33eb --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysCustomerHeatStatisticsMapper.java @@ -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 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); +} \ No newline at end of file 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 new file mode 100644 index 000000000..007d85668 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysCustomerHeatStatisticsService.java @@ -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 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); +} \ No newline at end of file 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 new file mode 100644 index 000000000..3d26ebcd4 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHeatStatisticsServiceImpl.java @@ -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 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; + } +} \ 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 d813fa02e..2129b7cda 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 @@ -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 list = new ArrayList<>(); - if(StringUtils.isNotEmpty(foodHeatCalculatorRequest.getIngredientArray())){ - List 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 list = new ArrayList<>(); + if(StringUtils.isNotEmpty(foodHeatCalculatorRequest.getIngredientArray())){ + List 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; } diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysCustomerHeatStatisticsMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysCustomerHeatStatisticsMapper.xml new file mode 100644 index 000000000..671fac2c7 --- /dev/null +++ b/stdiet-custom/src/main/resources/mapper/custom/SysCustomerHeatStatisticsMapper.xml @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + insert into sys_customer_heat_statistics + + customer_id, + edible_date, + max_heat_value, + heat_value, + heat_gap, + create_time, + create_by, + update_time, + update_by, + del_flag, + + + #{customerId}, + #{edibleDate}, + #{maxHeatValue}, + #{heatValue}, + #{heatGap}, + #{createTime}, + #{createBy}, + #{updateTime}, + #{updateBy}, + #{delFlag}, + + + + + update sys_customer_heat_statistics + + customer_id = #{customerId}, + edible_date = #{edibleDate}, + max_heat_value = #{maxHeatValue}, + heat_value = #{heatValue}, + heat_gap = #{heatGap}, + create_time = #{createTime}, + create_by = #{createBy}, + update_time = #{updateTime}, + update_by = #{updateBy}, + del_flag = #{delFlag}, + + where id = #{id} + + + + update sys_customer_heat_statistics set del_flag = 1 where id = #{id} + + + + update sys_customer_heat_statistics set del_flag = 1 where id in + + #{id} + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysFoodHeatStatisticsMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysFoodHeatStatisticsMapper.xml index fcd71fd76..515d1a7d3 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysFoodHeatStatisticsMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysFoodHeatStatisticsMapper.xml @@ -6,15 +6,13 @@ - + - - @@ -25,15 +23,14 @@ - select id, customer_id, ingredient, unit, number, quantity, edible_date, edible_type, heat_value, heat_gap, 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, heat_value, create_time, create_by, update_time, update_by, del_flag from sys_food_heat_statistics