!22 修复重复数据问题

Merge pull request !22 from 德仔/develop
This commit is contained in:
德仔 2020-12-18 16:02:18 +08:00 committed by Gitee
commit 2aca886ac2
14 changed files with 1328 additions and 4 deletions

View File

@ -810,3 +810,60 @@ create table sys_wx_user_log (
remark varchar(500) default null comment '备注', remark varchar(500) default null comment '备注',
primary key (id) primary key (id)
) engine=innodb comment = '微信用户记录'; ) 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 = '体征';

View File

@ -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<SysIngredient> 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<SysIngredient> list = sysIngredientService.selectSysIngredientList(sysIngredient);
ExcelUtil<SysIngredient> util = new ExcelUtil<SysIngredient>(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));
}
}

View File

@ -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();
}
}

View File

@ -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 +
'}';
}
}

View File

@ -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 +
'}';
}
}

View File

@ -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<SysIngredient> 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<SysIngredientRec> ingredientRecList);
public int batchIngredientNotRec(List<SysIngredientNotRec> ingredientNotRecList);
public int deleteIngredentRecByIngredientId(Long recId);
public int deleteIngredentNotRecByIngredientId(Long notRecId);
}

View File

@ -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<SysIngredient> 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);
}

View File

@ -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<SysIngredient> 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<SysIngredientRec> list = new ArrayList<SysIngredientRec>();
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<SysIngredientNotRec> list = new ArrayList<SysIngredientNotRec>();
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);
}
}

View File

@ -0,0 +1,121 @@
<?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.SysIngredientMapper">
<resultMap type="SysIngredient" id="SysIngredientResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="type" column="type" />
<result property="proteinRatio" column="protein_ratio" />
<result property="fatRatio" column="fat_ratio" />
<result property="carbonRatio" column="carbon_ratio" />
<result property="area" column="area" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectSysIngredientVo">
select id, name, type, protein_ratio, fat_ratio, carbon_ratio, area, remark, create_by, create_time, update_by, update_time from sys_ingredient
</sql>
<select id="selectSysIngredientList" parameterType="SysIngredient" resultMap="SysIngredientResult">
<include refid="selectSysIngredientVo"/>
<where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="area != null and area != ''"> and area = #{area}</if>
</where>
</select>
<select id="selectSysIngredientById" parameterType="Long" resultMap="SysIngredientResult">
<include refid="selectSysIngredientVo"/>
where id = #{id}
</select>
<insert id="insertSysIngredient" parameterType="SysIngredient" useGeneratedKeys="true" keyProperty="id">
insert into sys_ingredient
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">name,</if>
<if test="type != null">type,</if>
<if test="proteinRatio != null">protein_ratio,</if>
<if test="fatRatio != null">fat_ratio,</if>
<if test="carbonRatio != null">carbon_ratio,</if>
<if test="area != null">area,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if>
<if test="type != null">#{type},</if>
<if test="proteinRatio != null">#{proteinRatio},</if>
<if test="fatRatio != null">#{fatRatio},</if>
<if test="carbonRatio != null">#{carbonRatio},</if>
<if test="area != null">#{area},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<insert id="batchIngredientRec" >
insert into sys_ingredient_rec(ingredient_id, rec_id) values
<foreach collection="list" separator="," item="item" index="index">
(#{item.ingredientId},#{item.recommandId})
</foreach>
</insert>
<insert id="batchIngredientNotRec" >
insert into sys_ingredient_not_rec(ingredient_id, not_rec_id) values
<foreach collection="list" separator="," item="item" index="index">
(#{item.ingredientId},#{item.notRecommandId})
</foreach>
</insert>
<delete id="deleteIngredentRecByIngredientId" parameterType="Long">
delete from sys_ingredient_rec where ingredient_id=#{ingredientId}
</delete>
<delete id="deleteIngredentNotRecByIngredientId" parameterType="Long">
delete from sys_ingredient_not_rec where ingredient_id=#{ingredientId}
</delete>
<update id="updateSysIngredient" parameterType="SysIngredient">
update sys_ingredient
<trim prefix="SET" suffixOverrides=",">
<if test="name != null">name = #{name},</if>
<if test="type != null">type = #{type},</if>
<if test="proteinRatio != null">protein_ratio = #{proteinRatio},</if>
<if test="fatRatio != null">fat_ratio = #{fatRatio},</if>
<if test="carbonRatio != null">carbon_ratio = #{carbonRatio},</if>
<if test="area != null">area = #{area},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteSysIngredientById" parameterType="Long">
delete from sys_ingredient where id = #{id}
</delete>
<delete id="deleteSysIngredientByIds" parameterType="String">
delete from sys_ingredient where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -36,7 +36,7 @@
</select> </select>
<select id="selectSysWxUserInfoListNot" parameterType="SysWxUserInfo" resultMap="SysWxUserInfoResult"> <select id="selectSysWxUserInfoListNot" parameterType="SysWxUserInfo" resultMap="SysWxUserInfoResult">
select user.openid, user.nick_name, user.appid, user.phone, user.avatar_url, user.sex, user.update_time from sys_wx_user_info user select distinct user.openid, user.nick_name, user.appid, user.phone, user.avatar_url, user.sex, user.update_time from sys_wx_user_info user
right join sys_order right join sys_order
on user.phone = sys_order.phone on user.phone = sys_order.phone
<where> <where>

View File

@ -0,0 +1,53 @@
import request from '@/utils/request'
// 查询食材列表
export function listIngredient(query) {
return request({
url: '/custom/ingredient/list',
method: 'get',
params: query
})
}
// 查询食材详细
export function getIngredient(id) {
return request({
url: '/custom/ingredient/' + id,
method: 'get'
})
}
// 新增食材
export function addIngredient(data) {
return request({
url: '/custom/ingredient',
method: 'post',
data: data
})
}
// 修改食材
export function updateIngredient(data) {
return request({
url: '/custom/ingredient',
method: 'put',
data: data
})
}
// 删除食材
export function delIngredient(id) {
return request({
url: '/custom/ingredient/' + id,
method: 'delete'
})
}
// 导出食材
export function exportIngredient(query) {
return request({
url: '/custom/ingredient/export',
method: 'get',
params: query
})
}

View File

@ -1,7 +1,7 @@
<template> <template>
<el-breadcrumb class="app-breadcrumb" separator="/"> <el-breadcrumb class="app-breadcrumb" separator="/">
<transition-group name="breadcrumb"> <transition-group name="breadcrumb">
<el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path"> <el-breadcrumb-item v-for="(item,index) in levelList" :key="item.key">
<span v-if="item.redirect==='noRedirect'||index==levelList.length-1" class="no-redirect">{{ item.meta.title }}</span> <span v-if="item.redirect==='noRedirect'||index==levelList.length-1" class="no-redirect">{{ item.meta.title }}</span>
<a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a> <a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a>
</el-breadcrumb-item> </el-breadcrumb-item>
@ -40,7 +40,10 @@ export default {
matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched) matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched)
} }
this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false) this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false).map(obj => ({
...obj,
key: Math.floor(Math.random() * 1000)
}))
}, },
isDashboard(route) { isDashboard(route) {
const name = route && route.name const name = route && route.name

View File

@ -0,0 +1,430 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="食材名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入食材名称"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="食材类别" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择食材类别" clearable size="small">
<el-option
v-for="dict in typeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
<el-form-item label="地域" prop="area">
<el-select v-model="queryParams.area" placeholder="请选择地域" clearable size="small">
<el-option
v-for="dict in areaOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['custom:ingredient:add']"
>新增
</el-button>
</el-col>
<!-- <el-col :span="1.5">-->
<!-- <el-button-->
<!-- type="success"-->
<!-- icon="el-icon-edit"-->
<!-- size="mini"-->
<!-- :disabled="single"-->
<!-- @click="handleUpdate"-->
<!-- v-hasPermi="['custom:ingredient:edit']"-->
<!-- >修改-->
<!-- </el-button>-->
<!-- </el-col>-->
<!-- <el-col :span="1.5">-->
<!-- <el-button-->
<!-- type="danger"-->
<!-- icon="el-icon-delete"-->
<!-- size="mini"-->
<!-- :disabled="multiple"-->
<!-- @click="handleDelete"-->
<!-- v-hasPermi="['custom:ingredient:remove']"-->
<!-- >删除-->
<!-- </el-button>-->
<!-- </el-col>-->
<el-col :span="1.5">
<el-button
type="warning"
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['custom:ingredient:export']"
>导出
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="ingredientList" @selection-change="handleSelectionChange">
<!-- <el-table-column type="selection" width="55" align="center" />-->
<!-- <el-table-column label="id" align="center" prop="id" />-->
<el-table-column label="食材名称" align="center" prop="name"/>
<el-table-column label="食材类别" align="center" prop="type" :formatter="typeFormat"/>
<el-table-column label="蛋白质比例(100g)" align="center" prop="proteinRatio"/>
<el-table-column label="脂肪比例(100g)" align="center" prop="fatRatio"/>
<el-table-column label="碳水比例(100g)" align="center" prop="carbonRatio"/>
<el-table-column label="地域" align="center" prop="area" :formatter="areaFormat"/>
<el-table-column label="忌口人群" align="center" prop="notRecIds" :formatter="notRecFormat"/>
<el-table-column label="推荐人群" align="center" prop="recIds" :formatter="recommendFormat"/>
<el-table-column label="备注" align="center" prop="remark"/>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['custom:ingredient:edit']"
>修改
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['custom:ingredient:remove']"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改食材对话框 -->
<el-dialog :title="title" :visible.sync="open" width="620px" append-to-body>
<el-row :gutter="15">
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-col :span="12">
<el-form-item label="食材名称" prop="name" label-width="90px">
<el-input v-model="form.name" placeholder="请输入食材名称"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="蛋白质比例" prop="proteinRatio" label-width="90px">
<el-input v-model="form.proteinRatio" placeholder="请输入蛋白质比例" style="width: 150px"/>
/100g
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="脂肪比例" prop="fatRatio" label-width="90px">
<el-input v-model="form.fatRatio" placeholder="请输入脂肪比例" style="width: 150px"/>
/100g
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="碳水比例" prop="carbonRatio" label-width="90px">
<el-input v-model="form.carbonRatio" placeholder="请输入碳水比例" style="width: 150px"/>
/100g
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="食材类别" prop="type" label-width="90px">
<el-select v-model="form.type" placeholder="请选择食材类别">
<el-option
v-for="dict in typeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="地域" prop="area" label-width="90px">
<el-select v-model="form.area" placeholder="请选择地域">
<el-option
v-for="dict in areaOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="忌口人群" label-width="90px">
<el-checkbox-group v-model="form.notRecIds">
<el-checkbox
v-for="dict in notRecOptions"
:key="dict.dictValue"
:label="dict.dictValue">
{{dict.dictLabel}}
</el-checkbox>
</el-checkbox-group>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="推荐人群" label-width="90px">
<el-checkbox-group v-model="form.recIds">
<el-checkbox
v-for="dict in recommendOptions"
:key="dict.dictValue"
:label="dict.dictValue">
{{dict.dictLabel}}
</el-checkbox>
</el-checkbox-group>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="备注" prop="remark" label-width="90px">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
</el-form-item>
</el-col>
</el-form>
</el-row>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
addIngredient,
delIngredient,
exportIngredient,
getIngredient,
listIngredient,
updateIngredient
} from "@/api/custom/ingredient";
export default {
name: "Ingredient",
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
ingredientList: [],
//
title: "",
//
open: false,
//
typeOptions: [],
//
areaOptions: [],
//
notRecOptions: [],
//
recommendOptions: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
name: null,
type: null,
area: null,
notRecIds: null,
recIds: null,
},
//
form: {},
//
rules: {}
};
},
created() {
this.getList();
this.getDicts("cus_ing_type").then(response => {
this.typeOptions = response.data;
});
this.getDicts("cus_area").then(response => {
this.areaOptions = response.data;
});
this.getDicts("cus_not_rec_group").then(response => {
this.notRecOptions = response.data;
});
this.getDicts("cus_rec_group").then(response => {
this.recommendOptions = response.data;
});
},
methods: {
/** 查询食材列表 */
getList() {
this.loading = true;
listIngredient(this.queryParams).then(response => {
this.ingredientList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
typeFormat(row, column) {
return this.selectDictLabel(this.typeOptions, row.type);
},
//
areaFormat(row, column) {
return this.selectDictLabel(this.areaOptions, row.area);
},
//
notRecFormat(row, column) {
return this.selectDictLabels(this.notRecOptions, row.notRecIds.join(','));
},
//
recommendFormat(row, column) {
return this.selectDictLabels(this.recommendOptions, row.recIds.join(','));
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: null,
name: null,
type: null,
proteinRatio: null,
fatRatio: null,
carbonRatio: null,
area: null,
notRecIds: [],
recIds: [],
remark: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加食材";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getIngredient(id).then(response => {
this.form = response.data;
// this.form.notRecIds = this.form.notRecIds.split(",");
// this.form.recIds = this.form.recIds.split(",");
this.open = true;
this.title = "修改食材";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
// this.form.notRecIds = this.form.notRecIds.join(",");
// this.form.recIds = this.form.recIds.join(",");
if (this.form.id != null) {
updateIngredient(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
}
});
} else {
addIngredient(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
}
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除食材编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function () {
return delIngredient(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(function () {
});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有食材数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function () {
return exportIngredient(queryParams);
}).then(response => {
this.download(response.msg);
}).catch(function () {
});
}
}
};
</script>

View File

@ -524,6 +524,8 @@
// //
open: false, open: false,
// //
totalAmount: 0,
//
review: 'no', review: 'no',
// //
daterange: [beginTime, endTime], daterange: [beginTime, endTime],