<?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.gic.haoban.manage.service.dao.mapper.content.TabHaobanTriggerCustomerDetailMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.content.TabHaobanTriggerCustomerDetail"
               id="TabHaobanTriggerCustomerDetailMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="enterpriseId" column="enterprise_id" jdbcType="VARCHAR"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="bizId" column="biz_id" jdbcType="VARCHAR"/>
        <result property="bizType" column="biz_type" jdbcType="INTEGER"/>
        <result property="clerkId" column="clerk_id" jdbcType="VARCHAR"/>
        <result property="staffId" column="staff_id" jdbcType="VARCHAR"/>
        <result property="storeId" column="store_id" jdbcType="VARCHAR"/>
        <result property="channelType" column="channel_type" jdbcType="INTEGER"/>
        <result property="customerId" column="customer_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="baseSql">
        id
        , enterprise_id,wxEnterpriseId,
               biz_id,
               biz_type,
               clerk_id,
               staff_id,
                store_id,
               channel_type,
               customer_id,
               create_time,
               update_time,
               delete_flag
    </sql>

    <!--查询单个-->
    <select id="queryById" resultMap="TabHaobanTriggerCustomerDetailMap">
        select <include refid="baseSql"/>
        from tab_haoban_trigger_customer_detail
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryWithCondition" resultMap="TabHaobanTriggerCustomerDetailMap">
        select
        <include refid="baseSql"/>
        from tab_haoban_trigger_customer_detail
        <where>
            delete_flag = 0
            <if test="enterpriseId != null and enterpriseId != ''">
                and enterprise_id = #{enterpriseId}
            </if>
            <if test="bizId != null and bizId != ''">
                and biz_id = #{bizId}
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </if>
            <if test="clerkId != null and clerkId != ''">
                and clerk_id = #{clerkId}
            </if>
            <if test="channelType != null">
                and channel_type = #{channelType}
            </if>
            <if test="startTime != null ">
                and create_time >= #{startTime}
            </if>
            <if test="endTime != null ">
                and create_time <![CDATA[ <= ]]> #{endTime}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from tab_haoban_trigger_customer_detail
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="enterpriseId != null and enterpriseId != ''">
                and enterprise_id = #{enterpriseId}
            </if>
            <if test="bizId != null and bizId != ''">
                and biz_id = #{bizId}
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </if>
            <if test="clerkId != null and clerkId != ''">
                and clerk_id = #{clerkId}
            </if>
            <if test="staffId != null and staffId != ''">
                and staff_id = #{staffId}
            </if>
            <if test="channelType != null">
                and channel_type = #{channelType}
            </if>
            <if test="customerId != null and customerId != ''">
                and customer_id = #{customerId}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into tab_haoban_trigger_customer_detail(enterprise_id, wx_enterprise_id, biz_id, biz_type, clerk_id,
                                                       staff_id,
                                                       channel_type, customer_id, create_time, update_time, delete_flag)
        values (#{enterpriseId}, #{wxEnterpriseId}, #{bizId}, #{bizType}, #{clerkId}, #{staffId}, #{channelType},
                #{customerId},
                #{createTime}, #{updateTime}, #{deleteFlag})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into tab_haoban_trigger_customer_detail(id, enterprise_id, wx_enterprise_id, biz_id, biz_type, clerk_id,
        staff_id,store_id,
        channel_type, customer_id, create_time, update_time, delete_flag)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}, #{entity.enterpriseId}, #{entity.wxEnterpriseId}, #{entity.bizId}, #{entity.bizType},
            #{entity.clerkId}, #{entity.staffId}, #{entity.storeId},
            #{entity.channelType}, #{entity.customerId}, #{entity.createTime}, #{entity.updateTime},
            #{entity.deleteFlag})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into tab_haoban_trigger_customer_detail(enterprise_id, wx_enterprise_id, biz_id, biz_type, clerk_id,
        staff_id, store_id,
        channel_type, customer_id, create_time, update_time, delete_flag)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.enterpriseId}, #{entity.wxEnterpriseId}, #{entity.bizId}, #{entity.bizType}, #{entity.clerkId},
            #{entity.staffId}, #{entity.storeId},
            #{entity.channelType}, #{entity.customerId}, #{entity.createTime}, #{entity.updateTime},
            #{entity.deleteFlag})
        </foreach>
        on duplicate key update
        enterprise_id = values(enterprise_id),
        biz_id = values(biz_id),
        biz_type = values(biz_type),
        clerk_id = values(clerk_id),
        staff_id = values(staff_id),
        store_id = values(store_id),
        channel_type = values(channel_type),
        customer_id = values(customer_id),
        create_time = values(create_time),
        update_time = values(update_time),
        delete_flag = values(delete_flag)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update tab_haoban_trigger_customer_detail
        <set>
            <if test="enterpriseId != null and enterpriseId != ''">
                enterprise_id = #{enterpriseId},
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                wx_enterprise_id = #{wxEnterpriseId}
            </if>
            <if test="bizId != null and bizId != ''">
                biz_id = #{bizId},
            </if>
            <if test="bizType != null">
                biz_type = #{bizType},
            </if>
            <if test="clerkId != null and clerkId != ''">
                clerk_id = #{clerkId},
            </if>
            <if test="staffId != null and staffId != ''">
                staff_id = #{staffId},
            </if>
            <if test="channelType != null">
                channel_type = #{channelType},
            </if>
            <if test="customerId != null and customerId != ''">
                customer_id = #{customerId},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="deleteFlag != null">
                delete_flag = #{deleteFlag},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete
        from tab_haoban_trigger_customer_detail
        where id = #{id}
    </delete>

</mapper>

