239 lines
10 KiB
XML
239 lines
10 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"/>
|
|
<result property="info" column="info"/>
|
|
<association property="imgList" column="id" select="selectIngredentFileById"/>
|
|
</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>
|
|
<if test="true">and del_flag=0</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>
|
|
<if test="info != null">info,</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>
|
|
<if test="info != null">#{info},</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.targetId},#{item.physicalSignsId})
|
|
</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.targetId},#{item.physicalSignsId})
|
|
</foreach>
|
|
</insert>
|
|
|
|
<delete id="deleteIngredientRecByIngredientId" parameterType="Long">
|
|
delete from sys_ingredient_rec where ingredient_id=#{ingredientId}
|
|
</delete>
|
|
|
|
<delete id="deleteIngredientNotRecByIngredientId" parameterType="Long">
|
|
delete from sys_ingredient_not_rec where ingredient_id=#{ingredientId}
|
|
</delete>
|
|
|
|
<!-- <delete id="deleteIngredientRecByIngredientIds" parameterType="Long">-->
|
|
<!-- delete from sys_ingredient_rec where ingredient_id in-->
|
|
<!-- <foreach item="id" collection="array" open="(" separator="," close=")">-->
|
|
<!-- #{id}-->
|
|
<!-- </foreach>-->
|
|
<!-- </delete>-->
|
|
|
|
<!-- <delete id="deleteIngredientNotRecByIngredientIds" 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>
|
|
<if test="info != null">info = #{info},</if>
|
|
</trim>
|
|
where id = #{id}
|
|
</update>
|
|
|
|
<update id="deleteSysIngredientById" parameterType="Long">
|
|
update sys_ingredient set del_flag=1 where id = #{id}
|
|
</update>
|
|
|
|
<!-- 根据食材名称查询食材 -->
|
|
<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>
|
|
|
|
<!-- 添加食材图片-->
|
|
<insert id="batchInsertIngredientImage">
|
|
insert into sys_ingredient_file(igd_id, url, name, create_by, create_time, update_by, update_time )
|
|
values
|
|
<foreach collection="list" separator="," item="item" index="index">
|
|
(#{item.igdId},#{item.url},#{item.name},#{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime})
|
|
</foreach>
|
|
</insert>
|
|
|
|
<resultMap id="SysIngredentFileResult" type="SysIngredentFile">
|
|
<result property="id" column="id"/>
|
|
<result property="name" column="name"/>
|
|
<result property="url" column="url"/>
|
|
</resultMap>
|
|
|
|
<!-- 查找图片-->
|
|
<select id="selectIngredentFileById" parameterType="Long" resultMap="SysIngredentFileResult">
|
|
select id, url, name from sys_ingredient_file where igd_id = #{id} and del_flag = 0
|
|
</select>
|
|
|
|
<!-- 删除图片记录-->
|
|
<delete id="deleteIngredientImageById" parameterType="Long">
|
|
delete from sys_ingredient_file where igd_id=#{id}
|
|
</delete>
|
|
</mapper> |