xkrs_ms/stdiet-custom/src/main/resources/mapper/custom/SysIngredientMapper.xml
2021-02-23 18:53:29 +08:00

216 lines
9.7 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.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" />
<result property="rec" column="rec" />
<result property="notRec" column="not_rec" />
<result property="reviewStatus" column="review_status" />
</resultMap>
<sql id="selectSysIngredientVo">
SELECT * 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)
</sql>
<sql id="selectSysIngredientByPhyVo">
SELECT * FROM sys_ingredient igd
RIGHT JOIN(
SELECT * FROM(
SELECT DISTINCT(ingredient_id) as id FROM sys_ingredient_rec
<where>
<if test="recIds != null">
physical_signs_id in
<foreach collection="recIds" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
) recId
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
) recM USING(id)
INNER JOIN (
SELECT * FROM(
SELECT DISTINCT(ingredient_id) as id FROM sys_ingredient_not_rec
<where>
<if test="notRecIds != null">
physical_signs_id in
<foreach collection="notRecIds" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
) notRecId
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
) notRecM USING(id)
) notRecT USING(id)
) recT USING(id)
</sql>
<select id="selectSysIngredientList" parameterType="SysIngredient" resultMap="SysIngredientResult">
<choose>
<when test="recIds == null and notRecIds == null">
<include refid="selectSysIngredientVo"/>
</when>
<otherwise>
<include refid="selectSysIngredientByPhyVo">
<property name="recIds" value="#{recIds}"/>
<property name="notRecIds" value="#{notRecIds}"/>
</include>
</otherwise>
</choose>
<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>
<if test="reviewStatus != null and reviewStatus != ''"> and review_status = #{reviewStatus}</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>
<if test="reviewStatus != null">review_status,</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>
<if test="reviewStatus != null">#{reviewStatus},</if>
</trim>
</insert>
<insert id="batchIngredientRec" >
insert into sys_ingredient_rec(ingredient_id, physical_signs_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, physical_signs_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>
<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=",">
<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>
<if test="reviewStatus != null">review_status = #{reviewStatus},</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>
<!-- 根据食材名称查询食材 -->
<select id="selectSysIngredientByName" parameterType="String" resultMap="SysIngredientResult">
select id,name,protein_ratio,fat_ratio,carbon_ratio from sys_ingredient
where name = #{name} limit 1
</select>
</mapper>