<?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.fs.store.mapper.FsMedicatedFoodMapper">

    <resultMap type="FsMedicatedFood" id="FsMedicatedFoodResult">
        <result property="id"    column="id"    />
        <result property="foodName"    column="food_name"    />
        <result property="imgUrl"    column="img_url"    />
        <result property="sort"    column="sort"    />
        <result property="action"    column="action"    />
        <result property="food"    column="food"    />
        <result property="indications"    column="indications"    />
        <result property="descs"    column="descs"    />
        <result property="createTime"    column="create_time"    />
        <result property="status"    column="status"    />
        <result property="pinyin"    column="pinyin"    />
        <result property="actionTitle"    column="action_title"    />
    </resultMap>

    <sql id="selectFsMedicatedFoodVo">
        select id, food_name, img_url, action_title,pinyin,sort, action, food, indications, descs, create_time, status from fs_medicated_food
    </sql>

    <select id="selectFsMedicatedFoodList" parameterType="FsMedicatedFood" resultMap="FsMedicatedFoodResult">
        <include refid="selectFsMedicatedFoodVo"/>
        <where>
            <if test="foodName != null  and foodName != ''"> and food_name like concat('%', #{foodName}, '%')</if>
            <if test="imgUrl != null  and imgUrl != ''"> and img_url = #{imgUrl}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="action != null  and action != ''"> and action = #{action}</if>
            <if test="food != null  and food != ''"> and food = #{food}</if>
            <if test="indications != null  and indications != ''"> and indications = #{indications}</if>
            <if test="descs != null  and descs != ''"> and descs = #{descs}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectFsMedicatedFoodById" parameterType="Long" resultMap="FsMedicatedFoodResult">
        <include refid="selectFsMedicatedFoodVo"/>
        where id = #{id}
    </select>

    <insert id="insertFsMedicatedFood" parameterType="FsMedicatedFood" useGeneratedKeys="true" keyProperty="id">
        insert into fs_medicated_food
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="foodName != null">food_name,</if>
            <if test="imgUrl != null">img_url,</if>
            <if test="sort != null">sort,</if>
            <if test="action != null">action,</if>
            <if test="food != null">food,</if>
            <if test="indications != null">indications,</if>
            <if test="descs != null">descs,</if>
            <if test="createTime != null">create_time,</if>
            <if test="status != null">status,</if>
            <if test="pinyin != null">pinyin,</if>
            <if test="actionTitle != null">action_title,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="foodName != null">#{foodName},</if>
            <if test="imgUrl != null">#{imgUrl},</if>
            <if test="sort != null">#{sort},</if>
            <if test="action != null">#{action},</if>
            <if test="food != null">#{food},</if>
            <if test="indications != null">#{indications},</if>
            <if test="descs != null">#{descs},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
            <if test="pinyin != null">#{pinyin},</if>
            <if test="actionTitle != null">#{actionTitle},</if>
         </trim>
    </insert>

    <update id="updateFsMedicatedFood" parameterType="FsMedicatedFood">
        update fs_medicated_food
        <trim prefix="SET" suffixOverrides=",">
            <if test="foodName != null">food_name = #{foodName},</if>
            <if test="imgUrl != null">img_url = #{imgUrl},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="action != null">action = #{action},</if>
            <if test="food != null">food = #{food},</if>
            <if test="indications != null">indications = #{indications},</if>
            <if test="descs != null">descs = #{descs},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="pinyin != null">pinyin = #{pinyin},</if>
            <if test="actionTitle != null">action_title = #{actionTitle},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsMedicatedFoodById" parameterType="Long">
        delete from fs_medicated_food where id = #{id}
    </delete>

    <delete id="deleteFsMedicatedFoodByIds" parameterType="String">
        delete from fs_medicated_food where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
