<?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.send.QwSendLogMapper">
    <resultMap type="com.gic.haoban.manage.service.entity.send.TabQwSendLog" id="TabQwSendLogMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="memberId" column="member_id" jdbcType="VARCHAR"/>
        <result property="externalUserId" column="external_user_id" jdbcType="VARCHAR"/>
        <result property="clerkId" column="clerk_id" jdbcType="VARCHAR"/>
        <result property="staffId" column="staff_id" jdbcType="VARCHAR"/>
        <result property="msgId" column="msg_id" jdbcType="VARCHAR"/>
        <result property="sendStatus" column="send_status" jdbcType="INTEGER"/>
        <result property="sendTime" column="send_time" jdbcType="TIMESTAMP"/>
        <result property="failReasonType" column="fail_reason_type" jdbcType="INTEGER"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="enterpriseId" column="enterprise_id" jdbcType="VARCHAR"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="TabQwSendLogMap">
        select
        id, member_id, external_user_id, clerk_id, staff_id, msg_id, send_status,send_time, fail_reason_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
        from tab_qw_send_log
        where id = #{id}
        and delete_flag = 0
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="TabQwSendLogMap">
        select
        id, member_id, external_user_id, clerk_id, staff_id, msg_id, send_status,send_time, fail_reason_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
        from tab_qw_send_log
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="memberId != null and memberId != ''">
                and member_id = #{memberId}
            </if>
            <if test="externalUserId != null and externalUserId != ''">
                and external_user_id = #{externalUserId}
            </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="msgId != null and msgId != ''">
                and msg_id = #{msgId}
            </if>
            <if test="sendStatus != null">
                and send_status = #{sendStatus}
            </if>
            <if test="failReasonType != null">
                and fail_reason_type = #{failReasonType}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
            <if test="enterpriseId != null and enterpriseId != ''">
                and enterprise_id = #{enterpriseId}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            and delete_flag = 0
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from tab_qw_send_log
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="memberId != null and memberId != ''">
                and member_id = #{memberId}
            </if>
            <if test="externalUserId != null and externalUserId != ''">
                and external_user_id = #{externalUserId}
            </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="msgId != null and msgId != ''">
                and msg_id = #{msgId}
            </if>
            <if test="sendStatus != null">
                and send_status = #{sendStatus}
            </if>
            <if test="failReasonType != null">
                and fail_reason_type = #{failReasonType}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
            <if test="enterpriseId != null and enterpriseId != ''">
                and enterprise_id = #{enterpriseId}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            and delete_flag = 0
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into
        tab_qw_send_log(id,member_id, external_user_id, clerk_id, staff_id, msg_id, send_status,send_time, fail_reason_type, wx_enterprise_id, enterprise_id)
        values
        (#{id},#{memberId}, #{externalUserId}, #{clerkId}, #{staffId}, #{msgId}, #{sendStatus}, #{sendTime}, #{failReasonType}, #{wxEnterpriseId}, #{enterpriseId})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into
        tab_qw_send_log(id,member_id, external_user_id, clerk_id, staff_id, msg_id, send_status,send_time, fail_reason_type, wx_enterprise_id, enterprise_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id},#{entity.memberId}, #{entity.externalUserId}, #{entity.clerkId}, #{entity.staffId}, #{entity.msgId}, #{entity.sendStatus}, #{entity.sendTime}, #{entity.failReasonType}, #{entity.wxEnterpriseId}, #{entity.enterpriseId})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into
        tab_qw_send_log(id,member_id, external_user_id, clerk_id, staff_id, msg_id, send_status,send_time, fail_reason_type, wx_enterprise_id, enterprise_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id},#{entity.memberId}, #{entity.externalUserId}, #{entity.clerkId}, #{entity.staffId}, #{entity.msgId}, #{entity.sendStatus},#{entity.sendTime}, #{entity.failReasonType}, #{entity.wxEnterpriseId}, #{entity.enterpriseId})
        </foreach>
        on duplicate key update
        member_id = values(member_id), external_user_id = values(external_user_id), clerk_id = values(clerk_id), staff_id = values(staff_id), msg_id = values(msg_id), send_status = values(send_status),send_time = values(send_time), fail_reason_type = values(fail_reason_type), wx_enterprise_id = values(wx_enterprise_id), enterprise_id = values(enterprise_id)
    </insert>
</mapper>