diff --git a/sql/ry_20200920.sql b/sql/ry_20200920.sql index 2b958dbca..8d6275017 100644 --- a/sql/ry_20200920.sql +++ b/sql/ry_20200920.sql @@ -809,4 +809,61 @@ create table sys_wx_user_log ( update_time datetime comment '更新时间', remark varchar(500) default null comment '备注', primary key (id) -) engine=innodb comment = '微信用户记录'; \ No newline at end of file +) engine=innodb comment = '微信用户记录'; + + +-- ---------------------------- +-- 24、食材 +-- ---------------------------- +drop table if exists sys_ingredient; +create table sys_ingredient( + id BIGINT(20) not null auto_increment comment 'id', + name varchar(20) comment '食材名称', + type varchar(20) comment '食材类别', + rec_estimation tinyint comment '推荐分量估算', + rec_est_unit bigint(20) comment '推荐分量估算单位id', + rec_portion tinyint comment '推荐分量', + protein_ratio decimal(10,3) comment '蛋白质比例', + fat_ratio decimal(10,3) comment '脂肪比例', + carbon_ratio decimal(10,3) comment '碳水比例', + remark varchar(500) comment '备注', + area varchar(20) comment '地域', + not_rec varchar(500) comment '忌口', + recommend varchar(500) comment '推荐', + create_by varchar(64) default '' comment '创建者', + create_time datetime comment '创建时间', + update_by varchar(64) default '' comment '更新者', + update_time datetime comment '更新时间', + primary key (id) +) engine=innodb comment = '食材'; + +drop table if exists sys_dishes; +create table sys_dishes( + id BIGINT(20) not null auto_increment comment 'id', + name varchar(20) comment '菜品名称', + type varchar(20) comment '菜品类型', + not_rec varchar(500) comment '忌口', + recommend varchar(500) comment '推荐', + methods text comment '做法', + create_by varchar(64) default '' comment '创建者', + create_time datetime comment '创建时间', + update_by varchar(64) default '' comment '更新者', + update_time datetime comment '更新时间', + primary key (id) +) engine=innodb comment = '菜品'; + +drop table if exists sys_dishes_ingredient; +create table sys_dishes_ingredient( + id BIGINT(20) not null auto_increment comment 'id', + dishes_id varchar(20) comment '菜品id', + ingredient_id varchar(20) comment '食材id', + ing_weight decimal(10,2) comment '食材重量', + primary key (id) +) engine=innodb comment = '菜品食材'; + +drop table if exists sys_physical_signs; +create table sys_physical_signs( + id BIGINT(20) not null auto_increment comment 'id', + name varchar(20) comment '体征名称', + primary key (id) +) engine=innodb comment = '体征'; \ No newline at end of file diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysIngredientController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysIngredientController.java new file mode 100644 index 000000000..f293a54b8 --- /dev/null +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysIngredientController.java @@ -0,0 +1,103 @@ +package com.stdiet.web.controller.custom; + +import java.util.List; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +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.SysIngredient; +import com.stdiet.custom.service.ISysIngredientService; +import com.stdiet.common.utils.poi.ExcelUtil; +import com.stdiet.common.core.page.TableDataInfo; + +/** + * 食材Controller + * + * @author wonder + * @date 2020-12-15 + */ +@RestController +@RequestMapping("/custom/ingredient") +public class SysIngredientController extends BaseController +{ + @Autowired + private ISysIngredientService sysIngredientService; + + /** + * 查询食材列表 + */ + @PreAuthorize("@ss.hasPermi('custom:ingredient:list')") + @GetMapping("/list") + public TableDataInfo list(SysIngredient sysIngredient) + { + startPage(); + List list = sysIngredientService.selectSysIngredientList(sysIngredient); + return getDataTable(list); + } + + /** + * 导出食材列表 + */ + @PreAuthorize("@ss.hasPermi('custom:ingredient:export')") + @Log(title = "食材", businessType = BusinessType.EXPORT) + @GetMapping("/export") + public AjaxResult export(SysIngredient sysIngredient) + { + List list = sysIngredientService.selectSysIngredientList(sysIngredient); + ExcelUtil util = new ExcelUtil(SysIngredient.class); + return util.exportExcel(list, "ingredient"); + } + + /** + * 获取食材详细信息 + */ + @PreAuthorize("@ss.hasPermi('custom:ingredient:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return AjaxResult.success(sysIngredientService.selectSysIngredientById(id)); + } + + /** + * 新增食材 + */ + @PreAuthorize("@ss.hasPermi('custom:ingredient:add')") + @Log(title = "食材", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody SysIngredient sysIngredient) + { + return toAjax(sysIngredientService.insertSysIngredient(sysIngredient)); + } + + /** + * 修改食材 + */ + @PreAuthorize("@ss.hasPermi('custom:ingredient:edit')") + @Log(title = "食材", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody SysIngredient sysIngredient) + { + return toAjax(sysIngredientService.updateSysIngredient(sysIngredient)); + } + + /** + * 删除食材 + */ + @PreAuthorize("@ss.hasPermi('custom:ingredient:remove')") + @Log(title = "食材", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(sysIngredientService.deleteSysIngredientByIds(ids)); + } +} \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredient.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredient.java new file mode 100644 index 000000000..26c48fc85 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredient.java @@ -0,0 +1,217 @@ +package com.stdiet.custom.domain; + +import java.math.BigDecimal; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.stdiet.common.annotation.Excel; +import com.stdiet.common.core.domain.BaseEntity; + +/** + * 食材对象 sys_ingredient + * + * @author wonder + * @date 2020-12-15 + */ +public class SysIngredient extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** id */ + private Long id; + + /** 食材名称 */ + @Excel(name = "食材名称") + private String name; + + /** 食材类别 */ + @Excel(name = "食材类别") + private String type; + + /** 推荐分量估算 */ + @Excel(name = "推荐分量估算") + private Long recEstimation; + + /** 推荐分量估算单位id */ + @Excel(name = "推荐分量估算单位id") + private Long recEstUnit; + + /** 推荐分量 */ + @Excel(name = "推荐分量") + private Long recPortion; + + /** 蛋白质比例 */ + @Excel(name = "蛋白质比例") + private BigDecimal proteinRatio; + + /** 脂肪比例 */ + @Excel(name = "脂肪比例") + private BigDecimal fatRatio; + + /** 碳水比例 */ + @Excel(name = "碳水比例") + private BigDecimal carbonRatio; + + /** 地域 */ + @Excel(name = "地域") + private String area; + + /** 忌口 */ + @Excel(name = "忌口") + private String notRec; + + /** 推荐 */ + @Excel(name = "推荐") + private String recommend; + + private Long[] recIds; + + private Long[] notRecIds; + + public Long[] getRecIds() { + return recIds; + } + + public Long[] getNotRecIds() { + return notRecIds; + } + + public void setNotRecIds(Long[] notRecIds) { + this.notRecIds = notRecIds; + } + + public void setRedIds(Long[] recIds) { + this.recIds = recIds; + } + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + public void setType(String type) + { + this.type = type; + } + + public String getType() + { + return type; + } + public void setRecEstimation(Long recEstimation) + { + this.recEstimation = recEstimation; + } + + public Long getRecEstimation() + { + return recEstimation; + } + public void setRecEstUnit(Long recEstUnit) + { + this.recEstUnit = recEstUnit; + } + + public Long getRecEstUnit() + { + return recEstUnit; + } + public void setRecPortion(Long recPortion) + { + this.recPortion = recPortion; + } + + public Long getRecPortion() + { + return recPortion; + } + public void setProteinRatio(BigDecimal proteinRatio) + { + this.proteinRatio = proteinRatio; + } + + public BigDecimal getProteinRatio() + { + return proteinRatio; + } + public void setFatRatio(BigDecimal fatRatio) + { + this.fatRatio = fatRatio; + } + + public BigDecimal getFatRatio() + { + return fatRatio; + } + public void setCarbonRatio(BigDecimal carbonRatio) + { + this.carbonRatio = carbonRatio; + } + + public BigDecimal getCarbonRatio() + { + return carbonRatio; + } + public void setArea(String area) + { + this.area = area; + } + + public String getArea() + { + return area; + } + public void setNotRec(String notRec) + { + this.notRec = notRec; + } + + public String getNotRec() + { + return notRec; + } + public void setRecommend(String recommend) + { + this.recommend = recommend; + } + + public String getRecommend() + { + return recommend; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("name", getName()) + .append("type", getType()) + .append("recEstimation", getRecEstimation()) + .append("recEstUnit", getRecEstUnit()) + .append("recPortion", getRecPortion()) + .append("proteinRatio", getProteinRatio()) + .append("fatRatio", getFatRatio()) + .append("carbonRatio", getCarbonRatio()) + .append("remark", getRemark()) + .append("area", getArea()) + .append("notRec", getNotRec()) + .append("recommend", getRecommend()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .toString(); + } +} \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientNotRec.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientNotRec.java new file mode 100644 index 000000000..059347528 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientNotRec.java @@ -0,0 +1,30 @@ +package com.stdiet.custom.domain; + +public class SysIngredientNotRec { + private Long ingredientId; + private Long notRecommandId; + + public Long getIngredientId() { + return ingredientId; + } + + public void setIngredientId(Long ingredientId) { + this.ingredientId = ingredientId; + } + + public Long getRecommandId() { + return notRecommandId; + } + + public void setRecommandId(Long recommandId) { + this.notRecommandId = recommandId; + } + + @Override + public String toString() { + return "SysIngredientRec{" + + "ingredientId=" + ingredientId + + ", notRecommandId=" + notRecommandId + + '}'; + } +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientRec.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientRec.java new file mode 100644 index 000000000..c1cb0ec09 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientRec.java @@ -0,0 +1,30 @@ +package com.stdiet.custom.domain; + +public class SysIngredientRec { + private Long ingredientId; + private Long recommandId; + + public Long getIngredientId() { + return ingredientId; + } + + public void setIngredientId(Long ingredientId) { + this.ingredientId = ingredientId; + } + + public Long getRecommandId() { + return recommandId; + } + + public void setRecommandId(Long recommandId) { + this.recommandId = recommandId; + } + + @Override + public String toString() { + return "SysIngredientRec{" + + "ingredientId=" + ingredientId + + ", recommandId=" + recommandId + + '}'; + } +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java new file mode 100644 index 000000000..8c8c527f8 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java @@ -0,0 +1,71 @@ +package com.stdiet.custom.mapper; + +import java.util.List; +import com.stdiet.custom.domain.SysIngredient; +import com.stdiet.custom.domain.SysIngredientNotRec; +import com.stdiet.custom.domain.SysIngredientRec; + +/** + * 食材Mapper接口 + * + * @author wonder + * @date 2020-12-15 + */ +public interface SysIngredientMapper +{ + /** + * 查询食材 + * + * @param id 食材ID + * @return 食材 + */ + public SysIngredient selectSysIngredientById(Long id); + + /** + * 查询食材列表 + * + * @param sysIngredient 食材 + * @return 食材集合 + */ + public List selectSysIngredientList(SysIngredient sysIngredient); + + /** + * 新增食材 + * + * @param sysIngredient 食材 + * @return 结果 + */ + public int insertSysIngredient(SysIngredient sysIngredient); + + /** + * 修改食材 + * + * @param sysIngredient 食材 + * @return 结果 + */ + public int updateSysIngredient(SysIngredient sysIngredient); + + /** + * 删除食材 + * + * @param id 食材ID + * @return 结果 + */ + public int deleteSysIngredientById(Long id); + + /** + * 批量删除食材 + * + * @param ids 需要删除的数据ID + * @return 结果 + */ + public int deleteSysIngredientByIds(Long[] ids); + + public int batchIngredientRec(List ingredientRecList); + + public int batchIngredientNotRec(List ingredientNotRecList); + + public int deleteIngredentRecByIngredientId(Long recId); + + public int deleteIngredentNotRecByIngredientId(Long notRecId); +} \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysIngredientService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysIngredientService.java new file mode 100644 index 000000000..ab63c4ace --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysIngredientService.java @@ -0,0 +1,61 @@ +package com.stdiet.custom.service; + +import java.util.List; +import com.stdiet.custom.domain.SysIngredient; + +/** + * 食材Service接口 + * + * @author wonder + * @date 2020-12-15 + */ +public interface ISysIngredientService +{ + /** + * 查询食材 + * + * @param id 食材ID + * @return 食材 + */ + public SysIngredient selectSysIngredientById(Long id); + + /** + * 查询食材列表 + * + * @param sysIngredient 食材 + * @return 食材集合 + */ + public List selectSysIngredientList(SysIngredient sysIngredient); + + /** + * 新增食材 + * + * @param sysIngredient 食材 + * @return 结果 + */ + public int insertSysIngredient(SysIngredient sysIngredient); + + /** + * 修改食材 + * + * @param sysIngredient 食材 + * @return 结果 + */ + public int updateSysIngredient(SysIngredient sysIngredient); + + /** + * 批量删除食材 + * + * @param ids 需要删除的食材ID + * @return 结果 + */ + public int deleteSysIngredientByIds(Long[] ids); + + /** + * 删除食材信息 + * + * @param id 食材ID + * @return 结果 + */ + public int deleteSysIngredientById(Long id); +} \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java new file mode 100644 index 000000000..1838b4128 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java @@ -0,0 +1,146 @@ +package com.stdiet.custom.service.impl; + +import com.stdiet.common.utils.DateUtils; +import com.stdiet.common.utils.StringUtils; +import com.stdiet.custom.domain.SysIngredient; +import com.stdiet.custom.domain.SysIngredientNotRec; +import com.stdiet.custom.domain.SysIngredientRec; +import com.stdiet.custom.mapper.SysIngredientMapper; +import com.stdiet.custom.service.ISysIngredientService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +/** + * 食材Service业务层处理 + * + * @author wonder + * @date 2020-12-15 + */ +@Service +public class SysIngredientServiceImpl implements ISysIngredientService { + @Autowired + private SysIngredientMapper sysIngredientMapper; + + /** + * 查询食材 + * + * @param id 食材ID + * @return 食材 + */ + @Override + public SysIngredient selectSysIngredientById(Long id) { + return sysIngredientMapper.selectSysIngredientById(id); + } + + /** + * 查询食材列表 + * + * @param sysIngredient 食材 + * @return 食材 + */ + @Override + public List selectSysIngredientList(SysIngredient sysIngredient) { + return sysIngredientMapper.selectSysIngredientList(sysIngredient); + } + + /** + * 新增食材 + * + * @param sysIngredient 食材 + * @return 结果 + */ + @Override + public int insertSysIngredient(SysIngredient sysIngredient) { + sysIngredient.setCreateTime(DateUtils.getNowDate()); + int rows = sysIngredientMapper.insertSysIngredient(sysIngredient); + // + insertRecommand(sysIngredient); + // + insertNotRecommand(sysIngredient); + return rows; + } + + /** + * 新增推荐标签 + * @param ingredient + */ + public void insertRecommand(SysIngredient ingredient) { + Long[] recIds = ingredient.getRecIds(); + if(StringUtils.isNotNull(recIds)) { + List list = new ArrayList(); + for(Long recId: recIds) { + SysIngredientRec rec = new SysIngredientRec(); + rec.setIngredientId(ingredient.getId()); + rec.setRecommandId(recId); + list.add(rec); + } + if(list.size() > 0) { + sysIngredientMapper.batchIngredientRec(list); + } + } + } + + /** + * 新增不推荐标签 + * @param ingredient + */ + public void insertNotRecommand(SysIngredient ingredient) { + Long[] notRecIds = ingredient.getNotRecIds(); + if(StringUtils.isNotNull(notRecIds)) { + List list = new ArrayList(); + for(Long recId: notRecIds) { + SysIngredientNotRec notRec = new SysIngredientNotRec(); + notRec.setIngredientId(ingredient.getId()); + notRec.setRecommandId(recId); + list.add(notRec); + } + if(list.size() > 0) { + sysIngredientMapper.batchIngredientNotRec(list); + } + } + } + + /** + * 修改食材 + * + * @param sysIngredient 食材 + * @return 结果 + */ + @Override + public int updateSysIngredient(SysIngredient sysIngredient) { + sysIngredient.setUpdateTime(DateUtils.getNowDate()); + Long ingredientId = sysIngredient.getId(); + sysIngredientMapper.deleteIngredentNotRecByIngredientId(ingredientId); + insertNotRecommand(sysIngredient); + sysIngredientMapper.deleteIngredentRecByIngredientId(ingredientId); + insertRecommand(sysIngredient); + return sysIngredientMapper.updateSysIngredient(sysIngredient); + } + + /** + * 批量删除食材 + * + * @param ids 需要删除的食材ID + * @return 结果 + */ + @Override + public int deleteSysIngredientByIds(Long[] ids) { + return sysIngredientMapper.deleteSysIngredientByIds(ids); + } + + /** + * 删除食材信息 + * + * @param id 食材ID + * @return 结果 + */ + @Override + public int deleteSysIngredientById(Long id) { + sysIngredientMapper.deleteIngredentRecByIngredientId(id); + sysIngredientMapper.deleteIngredentNotRecByIngredientId(id); + return sysIngredientMapper.deleteSysIngredientById(id); + } +} \ No newline at end of file diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysIngredientMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysIngredientMapper.xml new file mode 100644 index 000000000..c0a372b9c --- /dev/null +++ b/stdiet-custom/src/main/resources/mapper/custom/SysIngredientMapper.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + select id, name, type, protein_ratio, fat_ratio, carbon_ratio, area, remark, create_by, create_time, update_by, update_time from sys_ingredient + + + + + + + + insert into sys_ingredient + + name, + type, + protein_ratio, + fat_ratio, + carbon_ratio, + area, + remark, + create_by, + create_time, + update_by, + update_time, + + + #{name}, + #{type}, + #{proteinRatio}, + #{fatRatio}, + #{carbonRatio}, + #{area}, + #{remark}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + insert into sys_ingredient_rec(ingredient_id, rec_id) values + + (#{item.ingredientId},#{item.recommandId}) + + + + + insert into sys_ingredient_not_rec(ingredient_id, not_rec_id) values + + (#{item.ingredientId},#{item.notRecommandId}) + + + + + delete from sys_ingredient_rec where ingredient_id=#{ingredientId} + + + + delete from sys_ingredient_not_rec where ingredient_id=#{ingredientId} + + + + update sys_ingredient + + name = #{name}, + type = #{type}, + protein_ratio = #{proteinRatio}, + fat_ratio = #{fatRatio}, + carbon_ratio = #{carbonRatio}, + area = #{area}, + remark = #{remark}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where id = #{id} + + + + delete from sys_ingredient where id = #{id} + + + + delete from sys_ingredient where id in + + #{id} + + + + \ No newline at end of file diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml index 49665dcea..cb72bfb52 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml @@ -36,7 +36,7 @@