<?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.ruoyi.system.mapper.PosFoodMapper">

    <resultMap type="PosFood" id="PosFoodResult">
        <result property="id"    column="id"    />
        <result property="flId"    column="fl_id"    />
        <result property="mdid"    column="mdid"    />
        <result property="name"    column="name"    />
        <result property="image"    column="image"    />
        <result property="price"    column="price"    />
        <result property="introduce"    column="introduce"    />
        <result property="recommend"    column="recommend"    />
        <result property="sort"    column="sort"    />
        <result property="stackingUp"    column="stacking_up"    />
        <result property="language"    column="language"    />
        <result property="toExamine"    column="to_examine"    />
    </resultMap>

    <sql id="selectPosFoodVo">
        select id, fl_id, mdid, name, image, price, introduce, recommend, sort,language,stacking_up,to_examine from pos_food
    </sql>

    <select id="selectPosFoodList" parameterType="PosFood" resultMap="PosFoodResult">
        <include refid="selectPosFoodVo"/>
        <where>
            <if test="flId != null "> and fl_id = #{flId}</if>
            <if test="mdid != null "> and mdid = #{mdid}</if>
            <if test="name != null  and name != ''"> and BINARY name like concat('%', #{name}, '%')</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="introduce != null  and introduce != ''"> and introduce = #{introduce}</if>
            <if test="recommend != null "> and recommend = #{recommend}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="stackingUp != null "> and stacking_up = #{stackingUp}</if>
            <if test="language != null "> and language = #{language}</if>
            <if test="toExamine != null "> and to_examine = #{toExamine}</if>
        </where>
        order by id desc
    </select>

    <select id="selectPosFoodById" parameterType="Long" resultMap="PosFoodResult">
        <include refid="selectPosFoodVo"/>
        where id = #{id}
    </select>

    <insert id="insertPosFood" parameterType="PosFood" useGeneratedKeys="true" keyProperty="id">
        insert into pos_food
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="flId != null">fl_id,</if>
            <if test="mdid != null">mdid,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="image != null and image != ''">image,</if>
            <if test="price != null">price,</if>
            <if test="introduce != null">introduce,</if>
            <if test="recommend != null">recommend,</if>
            <if test="sort != null">sort,</if>
            <if test="language != null">language,</if>
            <if test="toExamine != null">to_examine,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="flId != null">#{flId},</if>
            <if test="mdid != null">#{mdid},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="image != null and image != ''">#{image},</if>
            <if test="price != null">#{price},</if>
            <if test="introduce != null">#{introduce},</if>
            <if test="recommend != null">#{recommend},</if>
            <if test="sort != null">#{sort},</if>
            <if test="language != null">#{language},</if>
            <if test="toExamine != null">#{toExamine},</if>
         </trim>
    </insert>

    <update id="updatePosFood" parameterType="PosFood">
        update pos_food
        <trim prefix="SET" suffixOverrides=",">
            <if test="flId != null">fl_id = #{flId},</if>
            <if test="mdid != null">mdid = #{mdid},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="image != null and image != ''">image = #{image},</if>
            <if test="price != null">price = #{price},</if>
            <if test="introduce != null">introduce = #{introduce},</if>
            <if test="recommend != null">recommend = #{recommend},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="language != null">language = #{language},</if>
            <if test="toExamine != null">to_examine = #{toExamine},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePosFoodById" parameterType="Long">
        delete from pos_food where id = #{id}
    </delete>

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

    <select id="countPosFoodByCreatedAt" resultType="int">
        SELECT COUNT(*)
        FROM pos_food
        <where>
            <if test="createdAt != null">
                created_at &gt; #{createdAt}
            </if>
            AND stacking_up = 1
        </where>
    </select>
</mapper>
