2021-04-27 17:18:54 +08:00

210 lines
9.6 KiB
XML

<?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.SysDishesMapper">
<resultMap type="SysDishes" id="SysDishesResult">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="bigClass" column="big_class"/>
<result property="smallClass" column="small_class"/>
<result property="type" column="type"/>
<result property="isMain" column="is_main"/>
<result property="methods" column="methods"/>
<result property="reviewStatus" column="review_status"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<!-- 非持久化字段 -->
<result property="bigClassName" column="bigClassName"/>
<result property="smallClassName" column="smallClassName"/>
<association property="igdList" column="id" select="selectSysIngreditentsById"/>
</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="recIdsStr" column="rec_ids"/>
<result property="notRec" column="not_rec"/>
<result property="notRecIdsStr" column="not_rec_ids"/>
<result property="cusWeight" column="cus_weight"/>
<result property="cusUnit" column="cus_unit"/>
<result property="weight" column="weight"/>
</resultMap>
<sql id="selectSysDishesVo">
select id, name, big_class, small_class, type, is_main, methods, create_by, create_time, update_by, update_time, review_status from sys_dishes
</sql>
<select id="selectSysDishesList" parameterType="SysDishes" resultMap="SysDishesResult">
<include refid="selectSysDishesVo"/>
<where>
<if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="type != null and type != ''">and FIND_IN_SET(#{type}, type)</if>
<if test="physical != null and physical != ''">
and id in(SELECT DISTINCT(dishes_id) FROM sys_dishes_rec WHERE physical_signs_id = #{physical})
</if>
<if test="igdName != null and igdName != ''">
and id in(SELECT DISTINCT(dishes_id) FROM sys_dishes_ingredient WHERE name like concat('%', #{igdName}, '%'))
</if>
<if test="bigClass != null">and big_class = #{bigClass}</if>
<if test="smallClass != null">and small_class = #{smallClass}</if>
<if test="reviewStatus != null and type != ''">and review_status = #{reviewStatus}</if>
<if test="isMain != null and type != ''">and is_main = #{isMain}</if>
<if test="true">and del_flag=0</if>
</where>
order by id desc
</select>
<sql id="selectSysIngreditentsByIdVo">
SELECT * FROM(
SELECT ingredient_id AS id, ingredient_weight AS weight, cus_weight, cus_unit, remark
FROM sys_dishes_ingredient
WHERE dishes_id = #{id}
) dishes
LEFT JOIN (
SELECT id, name, type, protein_ratio, fat_ratio, carbon_ratio, area, not_rec, not_rec_ids, rec, rec_ids
FROM sys_ingredient igd
LEFT JOIN (
SELECT ingredient_id as id, GROUP_CONCAT(name SEPARATOR ',') not_rec, GROUP_CONCAT(notRec.id SEPARATOR ',') not_rec_ids 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, GROUP_CONCAT(rec.id SEPARATOR ',') rec_ids 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}
</select>
<insert id="insertSysDishes" parameterType="SysDishes" useGeneratedKeys="true" keyProperty="id">
insert into sys_dishes
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">name,</if>
<if test="bigClass != null">big_class,</if>
<if test="smallClass != null">small_class,</if>
<if test="type != null">type,</if>
<if test="isMain != null">is_main,</if>
<if test="methods != null">methods,</if>
<if test="createBy != null">create_by,</if>
<if test="reviewStatus != null">review_status,</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="bigClass != null">#{bigClass},</if>
<if test="smallClass != null">#{smallClass},</if>
<if test="type != null">#{type},</if>
<if test="isMain != null">#{isMain},</if>
<if test="methods != null">#{methods},</if>
<if test="createBy != null">#{createBy},</if>
<if test="reviewStatus != null">#{reviewStatus},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateSysDishes" parameterType="SysDishes">
update sys_dishes
<trim prefix="SET" suffixOverrides=",">
<if test="name != null">name = #{name},</if>
<if test="bigClass != null">big_class = #{bigClass},</if>
<if test="smallClass != null">small_class = #{smallClass},</if>
<if test="type != null">type = #{type},</if>
<if test="isMain != null">is_main = #{isMain},</if>
<if test="methods != null">methods = #{methods},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="reviewStatus != null">review_status = #{reviewStatus},</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>
<update id="deleteSysDishesById" parameterType="Long">
update sys_dishes set del_flag=1 where id = #{id}
</update>
<!-- <delete id="deleteSysDishesByIds" parameterType="String">-->
<!-- delete from sys_dishes where id in-->
<!-- <foreach item="id" collection="array" open="(" separator="," close=")">-->
<!-- #{id}-->
<!-- </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, remark)
values
<foreach collection="list" separator="," item="item" index="index">
(#{item.dishesId}, #{item.ingredientId}, #{item.weight}, #{item.cusUnit}, #{item.cusWeight}, #{item.remark})
</foreach>
</insert>
<select id="getDishesMenuTypeById" parameterType="Long" resultType="String">
select type from sys_dishes where id=#{id}
</select>
<!-- 推荐,不推荐-->
<insert id="batchInsertDishesRec">
insert into sys_dishes_rec(dishes_id, physical_signs_id) values
<foreach collection="list" separator="," item="item" index="index">
(#{item.targetId},#{item.physicalSignsId})
</foreach>
</insert>
<insert id="batchInsertDishesNotRec">
insert into sys_dishes_not_rec(dishes_id, physical_signs_id) values
<foreach collection="list" separator="," item="item" index="index">
(#{item.targetId},#{item.physicalSignsId})
</foreach>
</insert>
<delete id="deleteDishesRecByDishesId" parameterType="Long">
delete from sys_dishes_rec where dishes_id=#{dishesId}
</delete>
<delete id="deleteDishesNotRecByDishesId" parameterType="Long">
delete from sys_dishes_not_rec where dishes_id=#{dishesId}
</delete>
</mapper>