From 3f3fcda8628bb52f2c1dd99c64787a7b10425fd1 Mon Sep 17 00:00:00 2001 From: xiezhijun <15270898033@163.com> Date: Sat, 20 Feb 2021 19:38:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=96=E9=A3=9F=E8=AE=A1=E7=AE=97=E5=99=A8?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SysFoodHeatStatisticsController.java | 41 +++-- .../com/stdiet/common/utils/HealthyUtils.java | 20 +++ .../domain/SysCustomerHeatStatistics.java | 57 +++++++ .../custom/domain/SysFoodHeatStatistics.java | 19 +-- .../SysCustomerHeatStatisticsMapper.java | 68 ++++++++ .../ISysCustomerHeatStatisticsService.java | 68 ++++++++ .../SysCustomerHeatStatisticsServiceImpl.java | 154 ++++++++++++++++++ .../SysFoodHeatStatisticsServiceImpl.java | 34 +++- .../SysCustomerHeatStatisticsMapper.xml | 144 ++++++++++++++++ .../custom/SysFoodHeatStatisticsMapper.xml | 25 +-- .../src/api/custom/foodHeatStatistics.js | 10 ++ .../HeatStatisticsCalculate/index.vue | 117 +++++++++++++ .../components/HeatStatisticsDrawer/index.vue | 27 ++- .../src/views/custom/fanStatistics/index.vue | 1 + .../foodHeatStatistics/investigate/index.vue | 145 +++++++++++------ 15 files changed, 822 insertions(+), 108 deletions(-) create mode 100644 stdiet-common/src/main/java/com/stdiet/common/utils/HealthyUtils.java create mode 100644 stdiet-custom/src/main/java/com/stdiet/custom/domain/SysCustomerHeatStatistics.java create mode 100644 stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysCustomerHeatStatisticsMapper.java create mode 100644 stdiet-custom/src/main/java/com/stdiet/custom/service/ISysCustomerHeatStatisticsService.java create mode 100644 stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHeatStatisticsServiceImpl.java create mode 100644 stdiet-custom/src/main/resources/mapper/custom/SysCustomerHeatStatisticsMapper.xml create mode 100644 stdiet-ui/src/components/HeatStatisticsCalculate/index.vue 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<SysFoodHeatStatistics> list = sysFoodHeatStatisticsService.selectSysFoodHeatStatisticsList(sysFoodHeatStatistics); + List<SysCustomerHeatStatistics> 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<SysFoodHeatStatistics> list = sysFoodHeatStatisticsService.selectSysFoodHeatStatisticsList(sysFoodHeatStatistics); - ExcelUtil<SysFoodHeatStatistics> util = new ExcelUtil<SysFoodHeatStatistics>(SysFoodHeatStatistics.class); - return util.exportExcel(list, "foodHeatStatistics"); + List<SysCustomerHeatStatistics> list = sysCustomerHeatStatisticsService.selectSysCustomerHeatStatisticsList(sysCustomerHeatStatistics); + ExcelUtil<SysCustomerHeatStatistics> util = new ExcelUtil<SysCustomerHeatStatistics>(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<SysFoodHeatStatistics> 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<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); +} \ 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<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); +} \ 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<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; + } +} \ 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<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; } 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 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.stdiet.custom.mapper.SysCustomerHeatStatisticsMapper"> + + <resultMap type="SysCustomerHeatStatistics" id="SysCustomerHeatStatisticsResult"> + <result property="id" column="id" /> + <result property="customerId" column="customer_id" /> + <result property="edibleDate" column="edible_date" /> + <result property="maxHeatValue" column="max_heat_value" /> + <result property="heatValue" column="heat_value" /> + <result property="heatGap" column="heat_gap" /> + <result property="createTime" column="create_time" /> + <result property="createBy" column="create_by" /> + <result property="updateTime" column="update_time" /> + <result property="updateBy" column="update_by" /> + <result property="delFlag" column="del_flag" /> + </resultMap> + + <resultMap type="SysCustomerHeatStatistics" id="SysCustomerHeatStatisticsResultExtended"> + <result property="id" column="id" /> + <result property="customerId" column="customer_id" /> + <result property="edibleDate" column="edible_date" /> + <result property="maxHeatValue" column="max_heat_value" /> + <result property="heatValue" column="heat_value" /> + <result property="heatGap" column="heat_gap" /> + <result property="createTime" column="create_time" /> + <result property="createBy" column="create_by" /> + <result property="updateTime" column="update_time" /> + <result property="updateBy" column="update_by" /> + <result property="delFlag" column="del_flag" /> + + <!-- column是传的参数, select是调用的查询 --> + <association property="foodHeatStatisticsList" column="id" select="selectSysFoodHeatStatisticsList"/> + </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 + </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 + </select> + + <select id="selectSysCustomerHeatStatisticsById" parameterType="Long" resultMap="SysCustomerHeatStatisticsResultExtended"> + <include refid="selectSysCustomerHeatStatisticsVo"/> + where id = #{id} and del_flag = 0 + </select> + + <insert id="insertSysCustomerHeatStatistics" parameterType="SysCustomerHeatStatistics" useGeneratedKeys="true" keyProperty="id"> + insert into sys_customer_heat_statistics + <trim prefix="(" suffix=")" suffixOverrides=","> + <if test="customerId != null">customer_id,</if> + <if test="edibleDate != null">edible_date,</if> + <if test="maxHeatValue != null">max_heat_value,</if> + <if test="heatValue != null">heat_value,</if> + <if test="heatGap != null">heat_gap,</if> + <if test="createTime != null">create_time,</if> + <if test="createBy != null">create_by,</if> + <if test="updateTime != null">update_time,</if> + <if test="updateBy != null">update_by,</if> + <if test="delFlag != null">del_flag,</if> + </trim> + <trim prefix="values (" suffix=")" suffixOverrides=","> + <if test="customerId != null">#{customerId},</if> + <if test="edibleDate != null">#{edibleDate},</if> + <if test="maxHeatValue != null">#{maxHeatValue},</if> + <if test="heatValue != null">#{heatValue},</if> + <if test="heatGap != null">#{heatGap},</if> + <if test="createTime != null">#{createTime},</if> + <if test="createBy != null">#{createBy},</if> + <if test="updateTime != null">#{updateTime},</if> + <if test="updateBy != null">#{updateBy},</if> + <if test="delFlag != null">#{delFlag},</if> + </trim> + </insert> + + <update id="updateSysCustomerHeatStatistics" parameterType="SysCustomerHeatStatistics"> + update sys_customer_heat_statistics + <trim prefix="SET" suffixOverrides=","> + <if test="customerId != null">customer_id = #{customerId},</if> + <if test="edibleDate != null">edible_date = #{edibleDate},</if> + <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="createTime != null">create_time = #{createTime},</if> + <if test="createBy != null">create_by = #{createBy},</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> + </trim> + where id = #{id} + </update> + + <update id="deleteSysCustomerHeatStatisticsById" parameterType="Long"> + update sys_customer_heat_statistics set del_flag = 1 where id = #{id} + </update> + + <update id="deleteSysCustomerHeatStatisticsByIds" parameterType="String"> + update sys_customer_heat_statistics set del_flag = 1 where id in + <foreach item="id" collection="array" open="(" separator="," close=")"> + #{id} + </foreach> + </update> + + <!-- 根据日期、客户ID查询是否存在热量统计 --> + <select id="getCustomerHeatStatisticsByDate" parameterType="SysCustomerHeatStatistics" resultMap="SysCustomerHeatStatisticsResult"> + select id from sys_customer_heat_statistics where del_flag = 0 and customer_id = #{customerId} + <if test="edibleDate != null">and date_format(edible_date,'%y%m%d') = date_format(#{edibleDate},'%y%m%d')</if> + limit 1 + </select> + + + <resultMap type="SysFoodHeatStatistics" id="SysFoodHeatStatisticsResult"> + <result property="id" column="id" /> + <result property="customerHeatId" column="customer_heat_id" /> + <result property="ingredient" column="ingredient" /> + <result property="unit" column="unit" /> + <result property="number" column="number" /> + <result property="quantity" column="quantity" /> + <result property="edibleType" column="edible_type" /> + <result property="heatValue" column="heat_value" /> + <result property="createTime" column="create_time" /> + <result property="createBy" column="create_by" /> + <result property="updateTime" column="update_time" /> + <result property="updateBy" column="update_by" /> + <result property="delFlag" column="del_flag" /> + + <result property="unitName" column="unitName"></result> + </resultMap> + + <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 + 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 + where sfhs.del_flag = 0 and customer_heat_id = #{id} + </select> + +</mapper> \ 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 @@ <resultMap type="SysFoodHeatStatistics" id="SysFoodHeatStatisticsResult"> <result property="id" column="id" /> - <result property="customerId" column="customer_id" /> + <result property="customerHeatId" column="customer_heat_id" /> <result property="ingredient" column="ingredient" /> <result property="unit" column="unit" /> <result property="number" column="number" /> <result property="quantity" column="quantity" /> - <result property="edibleDate" column="edible_date" /> <result property="edibleType" column="edible_type" /> <result property="heatValue" column="heat_value" /> - <result property="heatGap" column="heat_gap" /> <result property="createTime" column="create_time" /> <result property="createBy" column="create_by" /> <result property="updateTime" column="update_time" /> @@ -25,15 +23,14 @@ </resultMap> <sql id="selectSysFoodHeatStatisticsVo"> - 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 </sql> <select id="selectSysFoodHeatStatisticsList" parameterType="SysFoodHeatStatistics" resultMap="SysFoodHeatStatisticsResult"> - select sfhs.id, sfhs.customer_id, sfhs.ingredient, sfhs.unit, sfhs.number, sfhs.quantity, sfhs.edible_date, sfhs.edible_type, sfhs.heat_value, sfhs.heat_gap,cusUnit.dict_label as unitName + 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 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 where sfhs.del_flag = 0 - <if test="customerId != null "> and sfhs.customer_id = #{customerId}</if> </select> <select id="selectSysFoodHeatStatisticsById" parameterType="Long" resultMap="SysFoodHeatStatisticsResult"> @@ -44,15 +41,13 @@ <insert id="insertSysFoodHeatStatistics" parameterType="SysFoodHeatStatistics" useGeneratedKeys="true" keyProperty="id"> insert into sys_food_heat_statistics <trim prefix="(" suffix=")" suffixOverrides=","> - <if test="customerId != null">customer_id,</if> + <if test="customerHeatId != null">customer_heat_id,</if> <if test="ingredient != null">ingredient,</if> <if test="unit != null">unit,</if> <if test="number != null">number,</if> <if test="quantity != null">quantity,</if> - <if test="edibleDate != null">edible_date,</if> <if test="edibleType != null">edible_type,</if> <if test="heatValue != null">heat_value,</if> - <if test="heatGap != null">heat_gap,</if> <if test="createTime != null">create_time,</if> <if test="createBy != null">create_by,</if> <if test="updateTime != null">update_time,</if> @@ -60,15 +55,13 @@ <if test="delFlag != null">del_flag,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> - <if test="customerId != null">#{customerId},</if> + <if test="customerHeatId != null">#{customerHeatId},</if> <if test="ingredient != null">#{ingredient},</if> <if test="unit != null">#{unit},</if> <if test="number != null">#{number},</if> <if test="quantity != null">#{quantity},</if> - <if test="edibleDate != null">#{edibleDate},</if> <if test="edibleType != null">#{edibleType},</if> <if test="heatValue != null">#{heatValue},</if> - <if test="heatGap != null">#{heatGap},</if> <if test="createTime != null">#{createTime},</if> <if test="createBy != null">#{createBy},</if> <if test="updateTime != null">#{updateTime},</if> @@ -80,15 +73,13 @@ <update id="updateSysFoodHeatStatistics" parameterType="SysFoodHeatStatistics"> update sys_food_heat_statistics <trim prefix="SET" suffixOverrides=","> - <if test="customerId != null">customer_id = #{customerId},</if> + <if test="customerHeatId != null">customer_heat_id = #{customerHeatId},</if> <if test="ingredient != null">ingredient = #{ingredient},</if> <if test="unit != null">unit = #{unit},</if> <if test="number != null">number = #{number},</if> <if test="quantity != null">quantity = #{quantity},</if> - <if test="edibleDate != null">edible_date = #{edibleDate},</if> <if test="edibleType != null">edible_type = #{edibleType},</if> <if test="heatValue != null">heat_value = #{heatValue},</if> - <if test="heatGap != null">heat_gap = #{heatGap},</if> <if test="createTime != null">create_time = #{createTime},</if> <if test="createBy != null">create_by = #{createBy},</if> <if test="updateTime != null">update_time = #{updateTime},</if> @@ -110,9 +101,9 @@ </update> <insert id="insertFoodHeatBatch" parameterType="java.util.List"> - insert into sys_food_heat_statistics(customer_id,ingredient,unit,number,quantity) values + insert into sys_food_heat_statistics(customer_heat_id,ingredient,unit,number,quantity) values <foreach collection ="list" item="food" index= "index" separator =","> - (#{food.customerId}, #{food.ingredient},#{food.unit},#{food.number},#{food.quantity}) + (#{food.customerHeatId}, #{food.ingredient},#{food.unit},#{food.number},#{food.quantity}) </foreach > </insert> diff --git a/stdiet-ui/src/api/custom/foodHeatStatistics.js b/stdiet-ui/src/api/custom/foodHeatStatistics.js index 81e1bb5f7..2b20b5134 100644 --- a/stdiet-ui/src/api/custom/foodHeatStatistics.js +++ b/stdiet-ui/src/api/custom/foodHeatStatistics.js @@ -51,3 +51,13 @@ export function exportFoodHeatStatistics(query) { params: query }) } + +// 新增外食热量统计 +export function addFoodHeatData(data) { + return request({ + url: '/custom/foodHeatStatistics/addFoodHeatData', + method: 'post', + data: data + }) +} + diff --git a/stdiet-ui/src/components/HeatStatisticsCalculate/index.vue b/stdiet-ui/src/components/HeatStatisticsCalculate/index.vue new file mode 100644 index 000000000..ce2147a34 --- /dev/null +++ b/stdiet-ui/src/components/HeatStatisticsCalculate/index.vue @@ -0,0 +1,117 @@ +<template> + <!-- 计算食材热量对话框 --> + <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body> + <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"> + <div> + <span>食材名称:</span><el-input style="width:30%" 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:15%" type="number" placeholder="" v-model="item.heatValue"/><span>千卡</span> + </div> + </el-form-item> + </el-form> + <div slot="footer" class="dialog-footer"> + <el-button type="primary" @click="submitForm">确 定</el-button> + <el-button @click="cancel">取 消</el-button> + </div> + </el-dialog> +</template> +<script> + + import { getFoodHeatStatistics,addFoodHeatData } from "@/api/custom/foodHeatStatistics"; + import {getOptions} from "@/api/custom/order"; + + export default { + name: "index", + components: { + + }, + props: {}, + data() { + return { + // 弹出层标题 + title: "", + // 是否显示弹出层 + open: false, + callback: undefined, + // 表单参数 + form: {}, + // 表单校验 + rules: { + projectId:[ + {required: true, message: "请选择调理项目", trigger: "blur"} + ] + }, + heatData: null, + foodHeatList: [] + }; + }, + created() { + + }, + methods: { + showDialog(data, callback) { + this.callback = callback; + this.reset(data); + this.title = "计算"+`「${data.edibleDate}」食材热量`; + this.open = true; + this.getFoodHeatList(data.id); + }, + getFoodHeatList(id){ + getFoodHeatStatistics(id).then((response) => { + //let contractDetail = response.data; + this.heatData = response.data; + this.foodHeatList = response.data.foodHeatStatisticsList != null ? response.data.foodHeatStatisticsList : []; + }); + }, + getNumberString(foodData){ + let numberString = ""; + if(foodData.number){ + numberString += foodData.number + foodData.unitName; + } + if(foodData.quantity){ + numberString += (numberString != "" ? "/" : "" ) + foodData.quantity + "克"; + } + return numberString; + }, + // 表单重置 + reset(obj) { + this.heatData = null; + this.foodHeatList = []; + this.resetForm("form"); + }, + // 取消按钮 + cancel() { + this.open = false; + }, + /** 提交按钮 */ + submitForm() { + if(this.foodHeatList.length == 0){ + return; + } + let obj = {}; + obj.foodHeatIdList = []; + obj.foodHeatList = []; + obj.id = this.heatData.id; + obj.customerId = this.heatData.customerId; + this.foodHeatList.forEach((item,index) => { + obj.foodHeatIdList.push(item.id); + if(!/^[1-9]\d*$/.test(item.heatValue)){ + obj.foodHeatList.push(0); + }else{ + obj.foodHeatList.push(item.heatValue); + } + }); + console.log(obj.foodHeatIdList.length); + addFoodHeatData(obj).then(response => { + if (response.code === 200) { + this.msgSuccess("提交成功"); + this.open = false; + this.callback && this.callback(); + } + }); + } + } + }; +</script> diff --git a/stdiet-ui/src/components/HeatStatisticsDrawer/index.vue b/stdiet-ui/src/components/HeatStatisticsDrawer/index.vue index 72cb90f7e..708777aae 100644 --- a/stdiet-ui/src/components/HeatStatisticsDrawer/index.vue +++ b/stdiet-ui/src/components/HeatStatisticsDrawer/index.vue @@ -19,16 +19,16 @@ <span>{{ parseTime(scope.row.edibleDate, '{y}-{m}-{d}') }}</span> </template> </el-table-column> - <el-table-column label="食材" align="center" prop="ingredient" /> - <el-table-column label="通俗质量" align="center" prop="unitName"> + <!-- <el-table-column label="食材" align="center" prop="ingredient" /> + <el-table-column label="通俗计量" align="center" prop="unitName"> <template slot-scope="scope"> - {{ scope.row.number + "" + scope.row.unitName }} + {{ scope.row.number ? (scope.row.number + "" + (scope.row.unitName != null ? scope.row.unitName : "")) : "" }} </template> </el-table-column> - <el-table-column label="质量(克)" align="center" prop="quantity" /> + <el-table-column label="质量(克)" align="center" prop="quantity" />--> - <!--<el-table-column label="类型,0早 1中 2晚" align="center" prop="edibleType" />--> - <el-table-column label="热量数值" align="center" prop="heatValue" /> + <el-table-column label="最大摄入量" align="center" prop="maxHeatValue" /> + <el-table-column label="食材热量" align="center" prop="heatValue" /> <el-table-column label="热量缺口" align="center" prop="heatGap" /> <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <template slot-scope="scope"> @@ -39,6 +39,12 @@ @click="handleUpdate(scope.row)" v-hasPermi="['custom:foodHeatStatistics:edit']" >修改</el-button>--> + <el-button + size="mini" + type="text" + icon="el-icon-edit" + @click="handleCalculate(scope.row)" + >计算</el-button> <el-button size="mini" type="text" @@ -58,6 +64,8 @@ @pagination="fetchHeatList" /> + <heatStatisticsCalculate ref="heatStatisticsCalculateRef"></heatStatisticsCalculate> + </div> </el-drawer> </div> @@ -65,9 +73,11 @@ <script> import { listFoodHeatStatistics, getFoodHeatStatistics, delFoodHeatStatistics, addFoodHeatStatistics, updateFoodHeatStatistics, exportFoodHeatStatistics } from "@/api/custom/foodHeatStatistics"; import Clipboard from 'clipboard'; + import HeatStatisticsCalculate from "@/components/HeatStatisticsCalculate"; export default { name: "HeatStatisticsDrawer", components: { + 'heatStatisticsCalculate':HeatStatisticsCalculate }, data() { return { @@ -137,6 +147,11 @@ export default { message: '拷贝成功', type: 'success' }); + }, + handleCalculate(data){ + this.$refs.heatStatisticsCalculateRef.showDialog(data,() => { + this.fetchHeatList(); + }); } }, }; diff --git a/stdiet-ui/src/views/custom/fanStatistics/index.vue b/stdiet-ui/src/views/custom/fanStatistics/index.vue index 8ccdc490c..24961af14 100644 --- a/stdiet-ui/src/views/custom/fanStatistics/index.vue +++ b/stdiet-ui/src/views/custom/fanStatistics/index.vue @@ -370,6 +370,7 @@ if (response.code === 200) { this.msgSuccess("新增成功"); this.open = false; + this.reset(); this.getList(); } }); diff --git a/stdiet-ui/src/views/custom/foodHeatStatistics/investigate/index.vue b/stdiet-ui/src/views/custom/foodHeatStatistics/investigate/index.vue index cdc24c59e..78f2f96bb 100644 --- a/stdiet-ui/src/views/custom/foodHeatStatistics/investigate/index.vue +++ b/stdiet-ui/src/views/custom/foodHeatStatistics/investigate/index.vue @@ -13,51 +13,52 @@ <h3>个人信息</h3> <!--<div><span>{{form.name}}</span></div>--> </div> - <el-form-item label="真实姓名" prop="name"> - <el-input v-model="customer.name" :readonly="true" placeholder="请输入真实姓名" maxlength="20"/> + <el-form-item :label="'姓名:'+customer.name" prop="name"> + <!--<el-input v-model="customer.name" :readonly="true" placeholder="请输入真实姓名" maxlength="20"/>--> + </el-form-item> + <el-form-item :label="'手机号:'+customer.phone" prop="phone" style="margin-top: -15px"> + <!--<el-input v-model="customer.name" :readonly="true" placeholder="请输入真实姓名" maxlength="20"/>--> </el-form-item> <div> - <h3>食材记录</h3> - <!--<div><span>{{form.name}}</span></div>--> + <h3>外食计算</h3> </div> - <el-form-item label="已添加的食材" prop="name"> - <el-tag style="margin-left: 5px" - v-for="tag in ingredientTagArray" - :key="tag" - closable - :disable-transitions="false" - @close="handleClose(tag)" - > - {{tag}} - </el-tag> - <!--<el-tag class="el-icon-plus" style="margin-left: 5px"> - 添加 - </el-tag>--> - </el-form-item> - <div> - <el-form-item label="食材名称" prop="ingredient"> - <el-input v-model="form.ingredient" placeholder="请输入食材名称" maxlength="50"/> + <el-row> + <el-button v-for="(item,index) in modular" type="primary" plain @click="modularChange(index)">{{item}}</el-button> + </el-row> + <div style="margin-top: 40px"> + <h3>{{currentTitle}}</h3> + </div> + <div v-show="currentShow == 0"> + <el-form-item label="已添加的食材" prop="name"> + <el-tag style="margin-left: 5px" v-for="tag in ingredientTagArray" :key="tag" closable :disable-transitions="false" @close="handleClose(tag)"> + {{tag}} + </el-tag> </el-form-item> - <el-form-item label="通俗计量" prop="numberUnit"> - <el-input-number v-model="form.number" controls-position="right" :controls="false" style="width: 48%" placeholder="请输入食材数量" :step="1" :max="100"></el-input-number> - <el-select v-model="form.unit" placeholder="请选择单位" style="margin-left:5px;width: 50%" filterable clearable> - <el-option - v-for="dict in cusUnitOptions" - :key="dict.dictValue" - :label="dict.dictLabel" - :value="parseInt(dict.dictValue)" - /> - </el-select> - </el-form-item> - <el-form-item label="重量(克)" prop="quantity"> - <el-input type="number" v-model="form.quantity" placeholder="请输入食材重量(整数)" maxlength="10"/> + <div> + <el-form-item label="食材名称" prop="ingredient"> + <el-input v-model="form.ingredient" placeholder="请输入食材名称" maxlength="20"/> + </el-form-item> + <el-form-item label="通俗计量" prop="numberUnit"> + <el-input v-model="form.number" style="width: 48%" placeholder="请输入食材数量" maxlength="10"/> + <el-select v-model="form.unit" placeholder="请选择单位" style="margin-left:5px;width: 50%" filterable clearable> + <el-option + v-for="dict in cusUnitOptions" + :key="dict.dictValue" + :label="dict.dictLabel" + :value="parseInt(dict.dictValue)" + /> + </el-select> + </el-form-item> + <el-form-item label="重量(克)" prop="quantity"> + <el-input v-model="form.quantity" placeholder="请输入食材重量(整数)" maxlength="10"/> + </el-form-item> + </div> + <el-form-item style="text-align: center; margin: 40px auto" > + <el-button type="primary" @click="continueAdd()" >继续添加</el-button> + <el-button type="success" @click="submit()" >提交数据</el-button> </el-form-item> + </div> - </div> - <el-form-item style="text-align: center; margin: 40px auto" > - <el-button type="primary" @click="continueAdd()" >继续添加</el-button> - <el-button type="success" @click="submit()" >提交数据</el-button> - </el-form-item> </el-form> </section> </template> @@ -67,7 +68,21 @@ export default { name: "index", data() { + const checkNumberUnit = (rule, value, callback) => { + if (this.form.number) { + if(!/^[1-9]\d*$/.test(value)){ + return callback(new Error("通俗计量的数量格式错误")); + } + if(!this.form.unit){ + return callback(new Error("请选择通俗计量单位")); + } + } + callback(); + }; return { + modular:["食材提交"], + currentShow: -1, + currentTitle: "", logo, timer: null, customerExistFlag: false, @@ -79,12 +94,15 @@ }, form: { ingredient: null, - number: 0, + number: null, unit: null, quantity: null, }, rules: { - ingredient: [{ required: true, trigger: "blur", message: "请输入食材名称" }] + ingredient: [{ required: true, trigger: "blur", message: "请输入食材名称" }], + /*numberUnit: [ + { required: false, trigger: "blur", validator: checkNumberUnit } + ],*/ }, ingredientTagArray:[ @@ -100,6 +118,15 @@ }, methods: { + modularChange(index){ + if(index != this.currentShow){ + this.currentShow = index; + this.currentTitle = this.modular[index]; + }else{ + this.currentShow = -1; + this.currentTitle = ""; + } + }, //根据用户ID获取用户基本信息(手机号、姓名) getCustomerBase(id){ if(id == null || id == undefined){ @@ -120,7 +147,7 @@ continueAdd(){ this.$refs.form.validate((valid) => { if (valid) { - if(this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){ + if(this.verify() && this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){ this.ingredientArray.push(this.form); this.ingredientTagArray.push(this.form.ingredient); this.reset(); @@ -130,26 +157,48 @@ } }); }, + verify(){ + if(this.form.number != null && this.form.number != ""){ + if(!/^[1-9]\d*$/.test(this.form.number+"")){ + this.$message({message: "通俗计量的数量格式错误", type: "warning"}); + return false; + } + if(this.form.unit == null || this.form.unit == ""){ + this.$message({message: "请选择通俗计量单位", type: "warning"}); + return false; + } + } + if(this.form.quantity != null && this.form.quantity != "" && !/^[1-9]\d*$/.test(this.form.quantity)){ + this.$message({message: "重量格式错误", type: "warning"}); + return false; + } + if((this.form.number == null || this.form.number == "") && (this.form.quantity == null || this.form.quantity == "")){ + this.$message({message: "通俗计量和重量不能都为空", type: "warning"}); + return false; + } + return true; + }, reset(){ this.form = { ingredient: null, - number: 0, + number: null, unit: null, quantity: null } }, + againSumbit(){ + this.submitFlag = false; + }, submit(){ if (this.submitFlag) { this.$message({ - message: "请勿重复提交,1分钟后重试", + message: "请勿频繁提交,1分钟后重试", type: "warning", }); return; } - this.timer = setTimeout(function(){ - this.submitFlag = false; - },1000*60); - if(this.form.ingredient && this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){ + this.timer = setTimeout(this.againSumbit,1000*60); + if(this.form.ingredient && this.verify() && this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){ this.ingredientArray.push(this.form); this.ingredientTagArray.push(this.form.ingredient); this.reset();