<?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.FoodStatisticsMapper">

    <resultMap type="FoodStatistics" id="FoodStatisticsResult">
        <result property="id"    column="id"    />
        <result property="foodId"    column="food_id"    />
        <result property="number"    column="number"    />
    </resultMap>

    <sql id="selectFoodStatisticsVo">
        select id, food_id, number from food_statistics
    </sql>

    <select id="selectFoodStatisticsList" parameterType="FoodStatistics" resultMap="FoodStatisticsResult">
        <include refid="selectFoodStatisticsVo"/>
        <where>
            <if test="number != null "> and number = #{number}</if>
        </where>
    </select>

    <select id="selectFoodStatisticsById" parameterType="Long" resultMap="FoodStatisticsResult">
        <include refid="selectFoodStatisticsVo"/>
        where id = #{id}
    </select>

    <insert id="insertFoodStatistics" parameterType="FoodStatistics" useGeneratedKeys="true" keyProperty="id">
        insert into food_statistics
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="foodId != null">food_id,</if>
            <if test="number != null">number,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="foodId != null">#{foodId},</if>
            <if test="number != null">#{number},</if>
        </trim>
    </insert>

    <update id="updateFoodStatistics" parameterType="FoodStatistics">
        update food_statistics
        <trim prefix="SET" suffixOverrides=",">
            <if test="foodId != null">food_id = #{foodId},</if>
            <if test="number != null">number = #{number},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFoodStatisticsById" parameterType="Long">
        delete from food_statistics where id = #{id}
    </delete>

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