Merge branch 'master' of https://gitee.com/darlk/ShengTangManage into xzj
This commit is contained in:
		| @@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringStyle; | ||||
| import com.stdiet.common.annotation.Excel; | ||||
| import com.stdiet.common.core.domain.BaseEntity; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 菜品对象 sys_dishes | ||||
|  *  | ||||
| @@ -30,6 +32,8 @@ public class SysDishes extends BaseEntity | ||||
|     @Excel(name = "做法") | ||||
|     private String methods; | ||||
|  | ||||
|     private List<SysDishesIngredient> igdList; | ||||
|  | ||||
|     public void setId(Long id)  | ||||
|     { | ||||
|         this.id = id; | ||||
| @@ -67,6 +71,14 @@ public class SysDishes extends BaseEntity | ||||
|         return methods; | ||||
|     } | ||||
|  | ||||
|     public void setIgdList(List<SysDishesIngredient> ingredientList) { | ||||
|         this.igdList = ingredientList; | ||||
|     } | ||||
|  | ||||
|     public List<SysDishesIngredient> getIgdList() { | ||||
|         return igdList; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | ||||
|   | ||||
| @@ -0,0 +1,76 @@ | ||||
| package com.stdiet.custom.domain; | ||||
|  | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
|  | ||||
| /** | ||||
|  * 菜品对象 sys_dishes | ||||
|  * | ||||
|  * @author wonder | ||||
|  * @date 2020-12-28 | ||||
|  */ | ||||
| public class SysDishesIngredient extends SysIngredient { | ||||
|  | ||||
|     private Long ingredientId; | ||||
|  | ||||
|     private Long dishesId; | ||||
|  | ||||
|     private Long cusUnit; | ||||
|  | ||||
|     private BigDecimal cusWeight; | ||||
|  | ||||
|     private BigDecimal weight; | ||||
|  | ||||
|     public Long getIngredientId() { | ||||
|         return ingredientId; | ||||
|     } | ||||
|  | ||||
|     public void setIngredientId(Long ingredientId) { | ||||
|         this.ingredientId = ingredientId; | ||||
|     } | ||||
|  | ||||
|     public Long getDishesId() { | ||||
|         return dishesId; | ||||
|     } | ||||
|  | ||||
|     public void setDishesId(Long dishesId) { | ||||
|         this.dishesId = dishesId; | ||||
|     } | ||||
|  | ||||
|     public BigDecimal getWeight() { | ||||
|         return weight; | ||||
|     } | ||||
|  | ||||
|     public void setWeight(BigDecimal weight) { | ||||
|         this.weight = weight; | ||||
|     } | ||||
|  | ||||
|     public BigDecimal getCusWeight() { | ||||
|         return cusWeight; | ||||
|     } | ||||
|  | ||||
|     public void setCusWeight(BigDecimal cusWeight) { | ||||
|         this.cusWeight = cusWeight; | ||||
|     } | ||||
|  | ||||
|     public Long getCusUnit() { | ||||
|         return cusUnit; | ||||
|     } | ||||
|  | ||||
|     public void setCusUnit(Long cusUnit) { | ||||
|         this.cusUnit = cusUnit; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) | ||||
|                 .append("ingredientId", getIngredientId()) | ||||
|                 .append("dishesId", getDishesId()) | ||||
|                 .append("weight", getWeight()) | ||||
|                 .append("cusWeight", getCusWeight()) | ||||
|                 .append("cusUnit", getCusUnit()) | ||||
|                 .toString(); | ||||
|     } | ||||
| } | ||||
| @@ -33,24 +33,6 @@ public class SysIngredient extends BaseEntity { | ||||
|     @Excel(name = "食材类别") | ||||
|     private String type; | ||||
|  | ||||
|     /** | ||||
|      * 推荐分量估算 | ||||
|      */ | ||||
|     @Excel(name = "推荐分量估算") | ||||
|     private Long recEstimation; | ||||
|  | ||||
|     /** | ||||
|      * 推荐分量估算单位id | ||||
|      */ | ||||
|     @Excel(name = "推荐分量估算单位id") | ||||
|     private Long recEstUnit; | ||||
|  | ||||
|     /** | ||||
|      * 推荐分量 | ||||
|      */ | ||||
|     @Excel(name = "推荐分量") | ||||
|     private Long recPortion; | ||||
|  | ||||
|     /** | ||||
|      * 蛋白质比例 | ||||
|      */ | ||||
| @@ -123,30 +105,6 @@ public class SysIngredient extends BaseEntity { | ||||
|         this.type = type; | ||||
|     } | ||||
|  | ||||
|     public Long getRecEstimation() { | ||||
|         return recEstimation; | ||||
|     } | ||||
|  | ||||
|     public void setRecEstimation(Long recEstimation) { | ||||
|         this.recEstimation = recEstimation; | ||||
|     } | ||||
|  | ||||
|     public Long getRecEstUnit() { | ||||
|         return recEstUnit; | ||||
|     } | ||||
|  | ||||
|     public void setRecEstUnit(Long recEstUnit) { | ||||
|         this.recEstUnit = recEstUnit; | ||||
|     } | ||||
|  | ||||
|     public Long getRecPortion() { | ||||
|         return recPortion; | ||||
|     } | ||||
|  | ||||
|     public void setRecPortion(Long recPortion) { | ||||
|         this.recPortion = recPortion; | ||||
|     } | ||||
|  | ||||
|     public BigDecimal getProteinRatio() { | ||||
|         return proteinRatio; | ||||
|     } | ||||
| @@ -201,9 +159,6 @@ public class SysIngredient extends BaseEntity { | ||||
|                 .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()) | ||||
|   | ||||
| @@ -1,7 +1,11 @@ | ||||
| package com.stdiet.custom.mapper; | ||||
|  | ||||
| import java.lang.reflect.Array; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import com.stdiet.custom.domain.SysDishes; | ||||
| import com.stdiet.custom.domain.SysDishesIngredient; | ||||
| import com.stdiet.custom.domain.SysIngredient; | ||||
|  | ||||
| /** | ||||
|  * 菜品Mapper接口 | ||||
| @@ -19,6 +23,8 @@ public interface SysDishesMapper | ||||
|      */ | ||||
|     public SysDishes selectSysDishesById(Long id); | ||||
|  | ||||
|     public ArrayList<SysDishesIngredient> selectSysIngreditentsById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询菜品列表 | ||||
|      *  | ||||
| @@ -58,4 +64,10 @@ public interface SysDishesMapper | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteSysDishesByIds(Long[] ids); | ||||
|  | ||||
|     public int deleteIngredientById(Long id); | ||||
|  | ||||
|     public int deleteIngredientByIds(Long[] ids); | ||||
|  | ||||
|     public int bashInsertDishesIngredent(List<SysDishesIngredient> sysDishesIngredients); | ||||
| } | ||||
| @@ -68,4 +68,8 @@ public interface SysIngredientMapper | ||||
|     public int deleteIngredentRecByIngredientId(Long recId); | ||||
|  | ||||
|     public int deleteIngredentNotRecByIngredientId(Long notRecId); | ||||
|  | ||||
|     public int deleteIngredentRecByIngredientIds(Long[] id); | ||||
|  | ||||
|     public int deleteIngredentNotRecByIngredientIds(Long[] id); | ||||
| } | ||||
| @@ -2,6 +2,8 @@ package com.stdiet.custom.service; | ||||
|  | ||||
| import java.util.List; | ||||
| import com.stdiet.custom.domain.SysDishes; | ||||
| import com.stdiet.custom.domain.SysDishesIngredient; | ||||
| import com.stdiet.custom.domain.SysIngredient; | ||||
|  | ||||
| /** | ||||
|  * 菜品Service接口 | ||||
| @@ -19,6 +21,8 @@ public interface ISysDishesService | ||||
|      */ | ||||
|     public SysDishes selectSysDishesById(Long id); | ||||
|  | ||||
|     public List<SysDishesIngredient> selectSysIngreditentsById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询菜品列表 | ||||
|      *  | ||||
|   | ||||
| @@ -1,96 +1,127 @@ | ||||
| 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.SysDishes; | ||||
| import com.stdiet.custom.domain.SysDishesIngredient; | ||||
| import com.stdiet.custom.mapper.SysDishesMapper; | ||||
| import com.stdiet.custom.service.ISysDishesService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
| import com.stdiet.custom.mapper.SysDishesMapper; | ||||
| import com.stdiet.custom.domain.SysDishes; | ||||
| import com.stdiet.custom.service.ISysDishesService; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 菜品Service业务层处理 | ||||
|  *  | ||||
|  * | ||||
|  * @author wonder | ||||
|  * @date 2020-12-28 | ||||
|  */ | ||||
| @Service | ||||
| public class SysDishesServiceImpl implements ISysDishesService  | ||||
| { | ||||
| public class SysDishesServiceImpl implements ISysDishesService { | ||||
|     @Autowired | ||||
|     private SysDishesMapper sysDishesMapper; | ||||
|  | ||||
|     /** | ||||
|      * 查询菜品 | ||||
|      *  | ||||
|      * | ||||
|      * @param id 菜品ID | ||||
|      * @return 菜品 | ||||
|      */ | ||||
|     @Override | ||||
|     public SysDishes selectSysDishesById(Long id) | ||||
|     { | ||||
|         return sysDishesMapper.selectSysDishesById(id); | ||||
|     public SysDishes selectSysDishesById(Long id) { | ||||
|         SysDishes dishes = sysDishesMapper.selectSysDishesById(id); | ||||
|         if (StringUtils.isNotNull(dishes)) { | ||||
|             List<SysDishesIngredient> ingredientArray = selectSysIngreditentsById(id); | ||||
|             if (StringUtils.isNull(ingredientArray)) { | ||||
|                 dishes.setIgdList(new ArrayList<>()); | ||||
|             } else { | ||||
|                 dishes.setIgdList(ingredientArray); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|         return dishes; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<SysDishesIngredient> selectSysIngreditentsById(Long id) { | ||||
|         return sysDishesMapper.selectSysIngreditentsById(id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询菜品列表 | ||||
|      *  | ||||
|      * | ||||
|      * @param sysDishes 菜品 | ||||
|      * @return 菜品 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<SysDishes> selectSysDishesList(SysDishes sysDishes) | ||||
|     { | ||||
|     public List<SysDishes> selectSysDishesList(SysDishes sysDishes) { | ||||
|         return sysDishesMapper.selectSysDishesList(sysDishes); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 新增菜品 | ||||
|      *  | ||||
|      * | ||||
|      * @param sysDishes 菜品 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int insertSysDishes(SysDishes sysDishes) | ||||
|     { | ||||
|     public int insertSysDishes(SysDishes sysDishes) { | ||||
|         sysDishes.setCreateTime(DateUtils.getNowDate()); | ||||
|         return sysDishesMapper.insertSysDishes(sysDishes); | ||||
|         int rows = sysDishesMapper.insertSysDishes(sysDishes); | ||||
|         // | ||||
|         insertDishesIngredient(sysDishes); | ||||
|         return rows; | ||||
|     } | ||||
|  | ||||
|     public void insertDishesIngredient(SysDishes sysDishes) { | ||||
|         if (StringUtils.isNotNull(sysDishes.getIgdList())) { | ||||
|             List<SysDishesIngredient> list = sysDishes.getIgdList(); | ||||
|             for (SysDishesIngredient dishesIngredient : list) { | ||||
|                 dishesIngredient.setDishesId(sysDishes.getId()); | ||||
|                 dishesIngredient.setIngredientId(dishesIngredient.getId()); | ||||
|             } | ||||
|             sysDishesMapper.bashInsertDishesIngredent(list); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改菜品 | ||||
|      *  | ||||
|      * | ||||
|      * @param sysDishes 菜品 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int updateSysDishes(SysDishes sysDishes) | ||||
|     { | ||||
|     public int updateSysDishes(SysDishes sysDishes) { | ||||
|         sysDishes.setUpdateTime(DateUtils.getNowDate()); | ||||
|         Long dishesId = sysDishes.getId(); | ||||
|         sysDishesMapper.deleteIngredientById(dishesId); | ||||
|         insertDishesIngredient(sysDishes); | ||||
|         return sysDishesMapper.updateSysDishes(sysDishes); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 批量删除菜品 | ||||
|      *  | ||||
|      * | ||||
|      * @param ids 需要删除的菜品ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteSysDishesByIds(Long[] ids) | ||||
|     { | ||||
|     public int deleteSysDishesByIds(Long[] ids) { | ||||
|         sysDishesMapper.deleteIngredientByIds(ids); | ||||
|         return sysDishesMapper.deleteSysDishesByIds(ids); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除菜品信息 | ||||
|      *  | ||||
|      * | ||||
|      * @param id 菜品ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteSysDishesById(Long id) | ||||
|     { | ||||
|     public int deleteSysDishesById(Long id) { | ||||
|         sysDishesMapper.deleteIngredientById(id); | ||||
|         return sysDishesMapper.deleteSysDishesById(id); | ||||
|     } | ||||
| } | ||||
| @@ -128,6 +128,8 @@ public class SysIngredientServiceImpl implements ISysIngredientService { | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteSysIngredientByIds(Long[] ids) { | ||||
|         sysIngredientMapper.deleteIngredentRecByIngredientIds(ids); | ||||
|         sysIngredientMapper.deleteIngredentNotRecByIngredientIds(ids); | ||||
|         return sysIngredientMapper.deleteSysIngredientByIds(ids); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -15,6 +15,21 @@ | ||||
|         <result property="updateTime"    column="update_time"    /> | ||||
|     </resultMap> | ||||
|  | ||||
|     <resultMap type="SysDishesIngredient" id="SysDishesIngredientResult"> | ||||
|         <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="rec"    column="rec"    /> | ||||
|         <result property="notRec"    column="not_rec"    /> | ||||
|         <result property="cusWeight"    column="cus_weight"    /> | ||||
|         <result property="cusUnit"    column="cus_unit"    /> | ||||
|         <result property="weight"    column="weight"    /> | ||||
|     </resultMap> | ||||
|  | ||||
|     <sql id="selectSysDishesVo"> | ||||
|         select id, name, type, methods, create_by, create_time, update_by, update_time from sys_dishes | ||||
|     </sql> | ||||
| @@ -27,6 +42,38 @@ | ||||
|         </where> | ||||
|     </select> | ||||
|  | ||||
|     <sql id="selectSysIngreditentsByIdVo"> | ||||
|         SELECT * FROM( | ||||
|             SELECT ingredient_id AS id, ingredient_weight AS weight, cus_weight, cus_unit | ||||
|             FROM sys_dishes_ingredient | ||||
|             WHERE dishes_id = #{id} | ||||
|         ) dishes | ||||
|         LEFT JOIN ( | ||||
|             SELECT id, name, type, protein_ratio, fat_ratio, carbon_ratio, area, not_rec, rec | ||||
|             FROM sys_ingredient igd | ||||
|             LEFT JOIN ( | ||||
|                 SELECT ingredient_id as id, GROUP_CONCAT(name SEPARATOR ',') not_rec FROM( | ||||
|                     SELECT physical_signs_id as id, ingredient_id | ||||
|                     FROM sys_ingredient_not_rec | ||||
|                 ) notRec JOIN sys_physical_signs phy USING(id) | ||||
|                 GROUP BY id | ||||
|             ) notRecT USING(id) | ||||
|             LEFT JOIN ( | ||||
|                 SELECT ingredient_id as id, GROUP_CONCAT(name SEPARATOR ',') rec FROM( | ||||
|                     SELECT physical_signs_id as id, ingredient_id | ||||
|                     FROM sys_ingredient_rec | ||||
|                 ) rec JOIN sys_physical_signs phy USING(id) | ||||
|                 GROUP BY id | ||||
|             ) recT USING(id) | ||||
|         ) ing USING(id) | ||||
|     </sql> | ||||
|  | ||||
|     <select id="selectSysIngreditentsById" parameterType="Long" resultMap="SysDishesIngredientResult"> | ||||
|         <include refid="selectSysIngreditentsByIdVo" > | ||||
|             <property name="id" value="#{id}"/> | ||||
|         </include> | ||||
|     </select> | ||||
|  | ||||
|     <select id="selectSysDishesById" parameterType="Long" resultMap="SysDishesResult"> | ||||
|         <include refid="selectSysDishesVo"/> | ||||
|         where id = #{id} | ||||
| @@ -79,4 +126,22 @@ | ||||
|         </foreach> | ||||
|     </delete> | ||||
|  | ||||
|     <delete id="deleteIngredientById" parameterType="Long"> | ||||
|         delete from sys_dishes_ingredient where dishes_id = #{id} | ||||
|     </delete> | ||||
|  | ||||
|     <delete id="deleteIngredientByIds" parameterType="String"> | ||||
|         delete from sys_dishes_ingredient where dishes_id in | ||||
|         <foreach item="id" collection="array" open="(" separator="," close=")"> | ||||
|             #{id} | ||||
|         </foreach> | ||||
|     </delete> | ||||
|  | ||||
|     <insert id="bashInsertDishesIngredent"> | ||||
|         insert into sys_dishes_ingredient(dishes_id, ingredient_id, ingredient_weight, cus_unit, cus_weight) values | ||||
|         <foreach collection="list" separator="," item="item" index="index"> | ||||
|             (#{item.dishesId}, #{item.ingredientId}, #{item.weight}, #{item.cusUnit}, #{item.cusWeight}) | ||||
|         </foreach> | ||||
|     </insert> | ||||
|  | ||||
| </mapper> | ||||
| @@ -159,6 +159,20 @@ | ||||
|         delete from sys_ingredient_not_rec where ingredient_id=#{ingredientId} | ||||
|     </delete> | ||||
|  | ||||
|     <delete id="deleteIngredentRecByIngredientIds" parameterType="Long"> | ||||
|         delete from sys_ingredient_rec where ingredient_id in | ||||
|         <foreach item="id" collection="array" open="(" separator="," close=")"> | ||||
|             #{id} | ||||
|         </foreach> | ||||
|     </delete> | ||||
|  | ||||
|     <delete id="deleteIngredentNotRecByIngredientIds" parameterType="String"> | ||||
|         delete from sys_ingredient_not_rec where ingredient_id in | ||||
|         <foreach item="id" collection="array" open="(" separator="," close=")"> | ||||
|             #{id} | ||||
|         </foreach> | ||||
|     </delete> | ||||
|  | ||||
|     <update id="updateSysIngredient" parameterType="SysIngredient"> | ||||
|         update sys_ingredient | ||||
|         <trim prefix="SET" suffixOverrides=","> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user