<?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.bonus.canteen.core.cook.mapper.CookDishesSaleRecordMapper">
    <resultMap type="com.bonus.canteen.core.cook.domain.CookDishesSaleRecord" id="CookDishesSaleRecordResult">
        <result property="id"    column="id"    />
        <result property="dishesId"    column="dishes_id"    />
        <result property="stallId"    column="stall_id"    />
        <result property="saleNum"    column="sale_num"    />
        <result property="monthlySales"    column="monthly_sales"    />
        <result property="saleMonth"    column="sale_month"    />
        <result property="evaluateNum"    column="evaluate_num"    />
        <result property="evaluateLevel"    column="evaluate_level"    />
        <result property="goodProbability"    column="good_probability"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectCookDishesSaleRecordVo">
        select id, dishes_id, stall_id, sale_num, monthly_sales, sale_month, evaluate_num, evaluate_level, good_probability, create_by, create_time, update_by, update_time from cook_dishes_sale_record
    </sql>

    <select id="selectCookDishesSaleRecordList" parameterType="com.bonus.canteen.core.cook.domain.CookDishesSaleRecord" resultMap="CookDishesSaleRecordResult">
        <include refid="selectCookDishesSaleRecordVo"/>
        <where>  
            <if test="dishesId != null "> and dishes_id = #{dishesId}</if>
            <if test="stallId != null "> and stall_id = #{stallId}</if>
            <if test="saleNum != null "> and sale_num = #{saleNum}</if>
            <if test="monthlySales != null "> and monthly_sales = #{monthlySales}</if>
            <if test="saleMonth != null "> and sale_month = #{saleMonth}</if>
            <if test="evaluateNum != null "> and evaluate_num = #{evaluateNum}</if>
            <if test="evaluateLevel != null "> and evaluate_level = #{evaluateLevel}</if>
            <if test="goodProbability != null "> and good_probability = #{goodProbability}</if>
        </where>
    </select>
    
    <select id="selectCookDishesSaleRecordById" parameterType="Long" resultMap="CookDishesSaleRecordResult">
        <include refid="selectCookDishesSaleRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCookDishesSaleRecord" parameterType="com.bonus.canteen.core.cook.domain.CookDishesSaleRecord" useGeneratedKeys="true" keyProperty="id">
        insert into cook_dishes_sale_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dishesId != null">dishes_id,</if>
            <if test="stallId != null">stall_id,</if>
            <if test="saleNum != null">sale_num,</if>
            <if test="monthlySales != null">monthly_sales,</if>
            <if test="saleMonth != null">sale_month,</if>
            <if test="evaluateNum != null">evaluate_num,</if>
            <if test="evaluateLevel != null">evaluate_level,</if>
            <if test="goodProbability != null">good_probability,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dishesId != null">#{dishesId},</if>
            <if test="stallId != null">#{stallId},</if>
            <if test="saleNum != null">#{saleNum},</if>
            <if test="monthlySales != null">#{monthlySales},</if>
            <if test="saleMonth != null">#{saleMonth},</if>
            <if test="evaluateNum != null">#{evaluateNum},</if>
            <if test="evaluateLevel != null">#{evaluateLevel},</if>
            <if test="goodProbability != null">#{goodProbability},</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>
         </trim>
    </insert>

    <update id="updateCookDishesSaleRecord" parameterType="com.bonus.canteen.core.cook.domain.CookDishesSaleRecord">
        update cook_dishes_sale_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="dishesId != null">dishes_id = #{dishesId},</if>
            <if test="stallId != null">stall_id = #{stallId},</if>
            <if test="saleNum != null">sale_num = #{saleNum},</if>
            <if test="monthlySales != null">monthly_sales = #{monthlySales},</if>
            <if test="saleMonth != null">sale_month = #{saleMonth},</if>
            <if test="evaluateNum != null">evaluate_num = #{evaluateNum},</if>
            <if test="evaluateLevel != null">evaluate_level = #{evaluateLevel},</if>
            <if test="goodProbability != null">good_probability = #{goodProbability},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCookDishesSaleRecordById" parameterType="Long">
        delete from cook_dishes_sale_record where id = #{id}
    </delete>

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