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

    <resultMap type="ShopGuestRecord" id="ShopGuestRecordResult">
        <result property="shopGuestRecord"    column="shop_guest_record"    />
        <result property="shopId"    column="shop_id"    />
        <result property="shopName"    column="shop_name"    />
        <result property="guestName"    column="guest_name"    />
        <result property="idCard"    column="id_card"    />
        <result property="phone"    column="phone"    />
        <result property="checkInTime"    column="check_in_time"    />
        <result property="guestType"    column="guest_type"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectShopGuestRecordVo">
        select shop_guest_record, shop_id, guest_name, id_card, phone, check_in_time, guest_type, create_time,
         (select name from t_shop where t_shop.shop_id = t_shop_sales_record.shop_id) shop_name
         from t_shop_guest_record
    </sql>

    <select id="selectShopGuestRecordList" parameterType="ShopGuestRecord" resultMap="ShopGuestRecordResult">
        <include refid="selectShopGuestRecordVo"/>
        <where>
            <if test="guestName != null  and guestName != ''"> and guest_name like concat('%', #{guestName}, '%')</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
        </where>
    </select>

    <select id="selectShopGuestRecordByShopGuestRecord" parameterType="Long" resultMap="ShopGuestRecordResult">
        <include refid="selectShopGuestRecordVo"/>
        where shop_guest_record = #{shopGuestRecord}
    </select>

    <insert id="insertShopGuestRecord" parameterType="ShopGuestRecord">
        insert into t_shop_guest_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="shopGuestRecord != null">shop_guest_record,</if>
            <if test="shopId != null">shop_id,</if>
            <if test="guestName != null">guest_name,</if>
            <if test="idCard != null">id_card,</if>
            <if test="phone != null">phone,</if>
            <if test="checkInTime != null">check_in_time,</if>
            <if test="guestType != null">guest_type,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="shopGuestRecord != null">#{shopGuestRecord},</if>
            <if test="shopId != null">#{shopId},</if>
            <if test="guestName != null">#{guestName},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="phone != null">#{phone},</if>
            <if test="checkInTime != null">#{checkInTime},</if>
            <if test="guestType != null">#{guestType},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateShopGuestRecord" parameterType="ShopGuestRecord">
        update t_shop_guest_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="shopId != null">shop_id = #{shopId},</if>
            <if test="guestName != null">guest_name = #{guestName},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="checkInTime != null">check_in_time = #{checkInTime},</if>
            <if test="guestType != null">guest_type = #{guestType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where shop_guest_record = #{shopGuestRecord}
    </update>

    <delete id="deleteShopGuestRecordByShopGuestRecord" parameterType="Long">
        delete from t_shop_guest_record where shop_guest_record = #{shopGuestRecord}
    </delete>

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