<?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.QwSendMsgMapper">
    <resultMap type="com.gic.haoban.manage.service.entity.send.TabQwSendMsg" id="TabQwSendMsgMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <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="sendTime" column="send_time" jdbcType="TIMESTAMP"/>
        <result property="bizType" column="biz_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="TabQwSendMsgMap">
        select
        id, clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
        from tab_qw_send_msg
        where id = #{id}
        and delete_flag = 0
    </select>

    <select id="queryByMsgId" resultMap="TabQwSendMsgMap">
        select
        id, clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
        from tab_qw_send_msg
        where msg_id = #{msgId}
        and delete_flag = 0
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="TabQwSendMsgMap">
        select
        id, clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
        from tab_qw_send_msg
        <where>
            delete_flag = 0
            <if test="id != null">
                and id = #{id}
            </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="sendTime != null">
                and send_time = #{sendTime}
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </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="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from tab_qw_send_msg
        <where>
            delete_flag = 0
            <if test="id != null">
                and id = #{id}
            </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="sendTime != null">
                and send_time = #{sendTime}
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </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="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into tab_qw_send_msg (
        id,clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id
        ) values (
        #{id},#{clerkId}, #{staffId}, #{msgId}, #{sendTime}, #{bizType}, #{wxEnterpriseId}, #{enterpriseId}
        )
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into tab_qw_send_msg (
        id,clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id
        ) values
        <foreach collection="entities" item="entity" separator=",">
            (#{id},#{entity.clerkId}, #{entity.staffId}, #{entity.msgId}, #{entity.sendTime}, #{entity.bizType}, #{entity.wxEnterpriseId}, #{entity.enterpriseId})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into tab_qw_send_msg (
        id,clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id
        ) values
        <foreach collection="entities" item="entity" separator=",">
            (#{id},#{entity.clerkId}, #{entity.staffId}, #{entity.msgId}, #{entity.sendTime}, #{entity.bizType}, #{entity.wxEnterpriseId}, #{entity.enterpriseId})
        </foreach>
        on duplicate key update
        id = values(id),
        clerk_id = values(clerk_id),
        staff_id = values(staff_id),
        msg_id = values(msg_id),
        send_time = values(send_time),
        biz_type = values(biz_type),
        wx_enterprise_id = values(wx_enterprise_id),
        enterprise_id = values(enterprise_id)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update tab_qw_send_msg
        <set>
            <if test="clerkId != null and clerkId != ''">clerk_id = #{clerkId},</if>
            <if test="staffId != null and staffId != ''">staff_id = #{staffId},</if>
            <if test="msgId != null and msgId != ''">msg_id = #{msgId},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="bizType != null">biz_type = #{bizType},</if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">wx_enterprise_id = #{wxEnterpriseId},</if>
            <if test="enterpriseId != null and enterpriseId != ''">enterprise_id = #{enterpriseId},</if>
            <if test="deleteFlag != null">delete_flag = #{deleteFlag},</if>
            <if test="updateTime != null">update_time = #{updateTime}</if>
        </set>
        where id = #{id}
    </update>

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