新增食材管理
This commit is contained in:
@ -63,7 +63,27 @@ public class SysIngredient extends BaseEntity
|
||||
@Excel(name = "推荐")
|
||||
private String recommend;
|
||||
|
||||
public void setId(Long id)
|
||||
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;
|
||||
}
|
||||
@ -153,21 +173,21 @@ public class SysIngredient extends BaseEntity
|
||||
{
|
||||
return area;
|
||||
}
|
||||
public void setNotRec(String notRec)
|
||||
public void setNotRec(String notRec)
|
||||
{
|
||||
this.notRec = notRec;
|
||||
}
|
||||
|
||||
public String getNotRec()
|
||||
public String getNotRec()
|
||||
{
|
||||
return notRec;
|
||||
}
|
||||
public void setRecommend(String recommend)
|
||||
public void setRecommend(String recommend)
|
||||
{
|
||||
this.recommend = recommend;
|
||||
}
|
||||
|
||||
public String getRecommend()
|
||||
public String getRecommend()
|
||||
{
|
||||
return recommend;
|
||||
}
|
||||
|
@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@ 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接口
|
||||
@ -58,4 +60,12 @@ public interface SysIngredientMapper
|
||||
* @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);
|
||||
}
|
@ -1,96 +1,146 @@
|
||||
package com.stdiet.custom.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
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 com.stdiet.custom.mapper.SysIngredientMapper;
|
||||
import com.stdiet.custom.domain.SysIngredient;
|
||||
import com.stdiet.custom.service.ISysIngredientService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 食材Service业务层处理
|
||||
*
|
||||
*
|
||||
* @author wonder
|
||||
* @date 2020-12-15
|
||||
*/
|
||||
@Service
|
||||
public class SysIngredientServiceImpl implements ISysIngredientService
|
||||
{
|
||||
public class SysIngredientServiceImpl implements ISysIngredientService {
|
||||
@Autowired
|
||||
private SysIngredientMapper sysIngredientMapper;
|
||||
|
||||
/**
|
||||
* 查询食材
|
||||
*
|
||||
*
|
||||
* @param id 食材ID
|
||||
* @return 食材
|
||||
*/
|
||||
@Override
|
||||
public SysIngredient selectSysIngredientById(Long id)
|
||||
{
|
||||
public SysIngredient selectSysIngredientById(Long id) {
|
||||
return sysIngredientMapper.selectSysIngredientById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询食材列表
|
||||
*
|
||||
*
|
||||
* @param sysIngredient 食材
|
||||
* @return 食材
|
||||
*/
|
||||
@Override
|
||||
public List<SysIngredient> selectSysIngredientList(SysIngredient sysIngredient)
|
||||
{
|
||||
public List<SysIngredient> selectSysIngredientList(SysIngredient sysIngredient) {
|
||||
return sysIngredientMapper.selectSysIngredientList(sysIngredient);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增食材
|
||||
*
|
||||
*
|
||||
* @param sysIngredient 食材
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertSysIngredient(SysIngredient sysIngredient)
|
||||
{
|
||||
public int insertSysIngredient(SysIngredient sysIngredient) {
|
||||
sysIngredient.setCreateTime(DateUtils.getNowDate());
|
||||
return sysIngredientMapper.insertSysIngredient(sysIngredient);
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
public int deleteSysIngredientByIds(Long[] ids) {
|
||||
return sysIngredientMapper.deleteSysIngredientByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除食材信息
|
||||
*
|
||||
*
|
||||
* @param id 食材ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSysIngredientById(Long id)
|
||||
{
|
||||
public int deleteSysIngredientById(Long id) {
|
||||
sysIngredientMapper.deleteIngredentRecByIngredientId(id);
|
||||
sysIngredientMapper.deleteIngredentNotRecByIngredientId(id);
|
||||
return sysIngredientMapper.deleteSysIngredientById(id);
|
||||
}
|
||||
}
|
@ -8,16 +8,11 @@
|
||||
<result property="id" column="id" />
|
||||
<result property="name" column="name" />
|
||||
<result property="type" column="type" />
|
||||
<result property="recEstimation" column="rec_estimation" />
|
||||
<result property="recEstUnit" column="rec_est_unit" />
|
||||
<result property="recPortion" column="rec_portion" />
|
||||
<result property="proteinRatio" column="protein_ratio" />
|
||||
<result property="fatRatio" column="fat_ratio" />
|
||||
<result property="carbonRatio" column="carbon_ratio" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="area" column="area" />
|
||||
<result property="notRec" column="not_rec" />
|
||||
<result property="recommend" column="recommend" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
@ -25,7 +20,7 @@
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysIngredientVo">
|
||||
select id, name, type, rec_estimation, rec_est_unit, rec_portion, protein_ratio, fat_ratio, carbon_ratio, remark, area, not_rec, recommend, create_by, create_time, update_by, update_time from sys_ingredient
|
||||
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">
|
||||
@ -34,8 +29,6 @@
|
||||
<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>
|
||||
<if test="notRec != null and notRec != ''"> and not_rec like concat('%', #{notRec}, '%')</if>
|
||||
<if test="recommend != null and recommend != ''"> and recommend like concat('%', #{recommend}, '%')</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
@ -49,16 +42,11 @@
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null">name,</if>
|
||||
<if test="type != null">type,</if>
|
||||
<if test="recEstimation != null">rec_estimation,</if>
|
||||
<if test="recEstUnit != null">rec_est_unit,</if>
|
||||
<if test="recPortion != null">rec_portion,</if>
|
||||
<if test="proteinRatio != null">protein_ratio,</if>
|
||||
<if test="fatRatio != null">fat_ratio,</if>
|
||||
<if test="carbonRatio != null">carbon_ratio,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="area != null">area,</if>
|
||||
<if test="notRec != null">not_rec,</if>
|
||||
<if test="recommend != null">recommend,</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>
|
||||
@ -67,16 +55,11 @@
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="type != null">#{type},</if>
|
||||
<if test="recEstimation != null">#{recEstimation},</if>
|
||||
<if test="recEstUnit != null">#{recEstUnit},</if>
|
||||
<if test="recPortion != null">#{recPortion},</if>
|
||||
<if test="proteinRatio != null">#{proteinRatio},</if>
|
||||
<if test="fatRatio != null">#{fatRatio},</if>
|
||||
<if test="carbonRatio != null">#{carbonRatio},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="area != null">#{area},</if>
|
||||
<if test="notRec != null">#{notRec},</if>
|
||||
<if test="recommend != null">#{recommend},</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>
|
||||
@ -84,21 +67,38 @@
|
||||
</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="recEstimation != null">rec_estimation = #{recEstimation},</if>
|
||||
<if test="recEstUnit != null">rec_est_unit = #{recEstUnit},</if>
|
||||
<if test="recPortion != null">rec_portion = #{recPortion},</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="remark != null">remark = #{remark},</if>
|
||||
<if test="area != null">area = #{area},</if>
|
||||
<if test="notRec != null">not_rec = #{notRec},</if>
|
||||
<if test="recommend != null">recommend = #{recommend},</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>
|
||||
|
Reference in New Issue
Block a user