<?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.huijy.management.mapper.ShopSalesRecordMapper">

    <resultMap type="ShopSalesRecord" id="ShopSalesRecordResult">
        <result property="shopSalesRecordId"    column="shop_sales_record_id"    />
        <result property="shopId"    column="shop_id"    />
        <result property="shopName"    column="shop_name"    />
        <result property="salesTime"    column="sales_time"    />
        <result property="scatteredAppointment"    column="scattered_appointment"    />
        <result property="scatteredReception"    column="scattered_reception"    />
        <result property="groupAppointment"    column="group_appointment"    />
        <result property="groupReception"    column="group_reception"    />
        <result property="salesAmount"    column="sales_amount"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectShopSalesRecordVo">
        select shop_sales_record_id, shop_id, sales_time, scattered_appointment, scattered_reception, group_appointment, group_reception, sales_amount, create_time,
         (select name from t_shop where t_shop.shop_id = t_shop_sales_record.shop_id) shop_name
         from t_shop_sales_record
    </sql>

    <select id="selectShopSalesRecordList" parameterType="ShopSalesRecord" resultMap="ShopSalesRecordResult">
        <include refid="selectShopSalesRecordVo"/>
        <where>
        </where>
    </select>

    <select id="selectShopSalesRecordByShopSalesRecordId" parameterType="Long" resultMap="ShopSalesRecordResult">
        <include refid="selectShopSalesRecordVo"/>
        where shop_sales_record_id = #{shopSalesRecordId}
    </select>

    <insert id="insertShopSalesRecord" parameterType="ShopSalesRecord" useGeneratedKeys="true" keyProperty="shopSalesRecordId">
        insert into t_shop_sales_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="shopId != null">shop_id,</if>
            <if test="salesTime != null">sales_time,</if>
            <if test="scatteredAppointment != null">scattered_appointment,</if>
            <if test="scatteredReception != null">scattered_reception,</if>
            <if test="groupAppointment != null">group_appointment,</if>
            <if test="groupReception != null">group_reception,</if>
            <if test="salesAmount != null">sales_amount,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="shopId != null">#{shopId},</if>
            <if test="salesTime != null">#{salesTime},</if>
            <if test="scatteredAppointment != null">#{scatteredAppointment},</if>
            <if test="scatteredReception != null">#{scatteredReception},</if>
            <if test="groupAppointment != null">#{groupAppointment},</if>
            <if test="groupReception != null">#{groupReception},</if>
            <if test="salesAmount != null">#{salesAmount},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateShopSalesRecord" parameterType="ShopSalesRecord">
        update t_shop_sales_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="shopId != null">shop_id = #{shopId},</if>
            <if test="salesTime != null">sales_time = #{salesTime},</if>
            <if test="scatteredAppointment != null">scattered_appointment = #{scatteredAppointment},</if>
            <if test="scatteredReception != null">scattered_reception = #{scatteredReception},</if>
            <if test="groupAppointment != null">group_appointment = #{groupAppointment},</if>
            <if test="groupReception != null">group_reception = #{groupReception},</if>
            <if test="salesAmount != null">sales_amount = #{salesAmount},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where shop_sales_record_id = #{shopSalesRecordId}
    </update>

    <delete id="deleteShopSalesRecordByShopSalesRecordId" parameterType="Long">
        delete from t_shop_sales_record where shop_sales_record_id = #{shopSalesRecordId}
    </delete>

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