<?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.ms.dal.mapper.DoudianMsgParseQueueMapper">

    <resultMap id="BaseResultMap" type="com.ms.dal.entity.DoudianMsgParseQueue">
            <id property="doudianMsgParseQueueId" column="doudian_msg_parse_queue_id" jdbcType="BIGINT"/>
            <result property="doudianMsgId" column="doudian_msg_id" jdbcType="BIGINT"/>
            <result property="locked" column="locked" jdbcType="BIGINT"/>
            <result property="gmtLocked" column="gmt_locked" jdbcType="TIMESTAMP"/>
            <result property="hostname" column="hostname" jdbcType="VARCHAR"/>
            <result property="gmtLastHeartbeat" column="gmt_last_heartbeat" jdbcType="TIMESTAMP"/>
            <result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
            <result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        doudian_msg_parse_queue_id,doudian_msg_id,locked,
        gmt_locked,hostname,gmt_last_heartbeat,
        gmt_create,gmt_modified
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from doudian_msg_parse_queue
        where  doudian_msg_parse_queue_id = #{doudianMsgParseQueueId,jdbcType=BIGINT} 
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from doudian_msg_parse_queue
        where  doudian_msg_parse_queue_id = #{doudianMsgParseQueueId,jdbcType=BIGINT} 
    </delete>
    <insert id="insert" keyColumn="doudian_msg_parse_queue_id" keyProperty="doudianMsgParseQueueId" parameterType="com.ms.dal.entity.DoudianMsgParseQueue" useGeneratedKeys="true">
        insert into doudian_msg_parse_queue
        ( doudian_msg_parse_queue_id,doudian_msg_id,locked
        ,gmt_locked,hostname,gmt_last_heartbeat
        ,gmt_create,gmt_modified)
        values (#{doudianMsgParseQueueId,jdbcType=BIGINT},#{doudianMsgId,jdbcType=BIGINT},#{locked,jdbcType=BIGINT}
        ,#{gmtLocked,jdbcType=TIMESTAMP},#{hostname,jdbcType=VARCHAR},#{gmtLastHeartbeat,jdbcType=TIMESTAMP}
        ,#{gmtCreate,jdbcType=TIMESTAMP},#{gmtModified,jdbcType=TIMESTAMP})
    </insert>
    <update id="insertOrUpdate"  keyColumn="doudian_msg_parse_queue_id" keyProperty="doudianMsgParseQueueId" parameterType="com.ms.dal.entity.DoudianMsgParseQueue"
        useGeneratedKeys="true">
        insert into doudian_msg_parse_queue
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="doudianMsgParseQueueId != null">doudian_msg_parse_queue_id,</if>
                <if test="doudianMsgId != null">doudian_msg_id,</if>
                <if test="locked != null">locked,</if>
                <if test="gmtLocked != null">gmt_locked,</if>
                <if test="hostname != null">hostname,</if>
                <if test="gmtLastHeartbeat != null">gmt_last_heartbeat,</if>
                <if test="gmtCreate != null">gmt_create,</if>
                <if test="gmtModified != null">gmt_modified,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="doudianMsgParseQueueId != null">#{doudianMsgParseQueueId,jdbcType=BIGINT},</if>
                <if test="doudianMsgId != null">#{doudianMsgId,jdbcType=BIGINT},</if>
                <if test="locked != null">#{locked,jdbcType=BIGINT},</if>
                <if test="gmtLocked != null">#{gmtLocked,jdbcType=TIMESTAMP},</if>
                <if test="hostname != null">#{hostname,jdbcType=VARCHAR},</if>
                <if test="gmtLastHeartbeat != null">#{gmtLastHeartbeat,jdbcType=TIMESTAMP},</if>
                <if test="gmtCreate != null">#{gmtCreate,jdbcType=TIMESTAMP},</if>
                <if test="gmtModified != null">#{gmtModified,jdbcType=TIMESTAMP},</if>
        </trim>
        ON DUPLICATE KEY UPDATE
        <trim  suffixOverrides=",">
                <if test="doudianMsgId != null">
                    doudian_msg_id = #{doudianMsgId,jdbcType=BIGINT},
                </if>
                <if test="locked != null">
                    locked = #{locked,jdbcType=BIGINT},
                </if>
                <if test="gmtLocked != null">
                    gmt_locked = #{gmtLocked,jdbcType=TIMESTAMP},
                </if>
                <if test="hostname != null">
                    hostname = #{hostname,jdbcType=VARCHAR},
                </if>
                <if test="gmtLastHeartbeat != null">
                    gmt_last_heartbeat = #{gmtLastHeartbeat,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtCreate != null">
                    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtModified != null">
                    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
                </if>
        </trim>
    </update>
    <insert id="insertSelective" keyColumn="doudian_msg_parse_queue_id" keyProperty="doudianMsgParseQueueId" parameterType="com.ms.dal.entity.DoudianMsgParseQueue" useGeneratedKeys="true">
        insert into doudian_msg_parse_queue
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="doudianMsgParseQueueId != null">doudian_msg_parse_queue_id,</if>
                <if test="doudianMsgId != null">doudian_msg_id,</if>
                <if test="locked != null">locked,</if>
                <if test="gmtLocked != null">gmt_locked,</if>
                <if test="hostname != null">hostname,</if>
                <if test="gmtLastHeartbeat != null">gmt_last_heartbeat,</if>
                <if test="gmtCreate != null">gmt_create,</if>
                <if test="gmtModified != null">gmt_modified,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="doudianMsgParseQueueId != null">#{doudianMsgParseQueueId,jdbcType=BIGINT},</if>
                <if test="doudianMsgId != null">#{doudianMsgId,jdbcType=BIGINT},</if>
                <if test="locked != null">#{locked,jdbcType=BIGINT},</if>
                <if test="gmtLocked != null">#{gmtLocked,jdbcType=TIMESTAMP},</if>
                <if test="hostname != null">#{hostname,jdbcType=VARCHAR},</if>
                <if test="gmtLastHeartbeat != null">#{gmtLastHeartbeat,jdbcType=TIMESTAMP},</if>
                <if test="gmtCreate != null">#{gmtCreate,jdbcType=TIMESTAMP},</if>
                <if test="gmtModified != null">#{gmtModified,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.ms.dal.entity.DoudianMsgParseQueue">
        update doudian_msg_parse_queue
        <set>
                <if test="doudianMsgId != null">
                    doudian_msg_id = #{doudianMsgId,jdbcType=BIGINT},
                </if>
                <if test="locked != null">
                    locked = #{locked,jdbcType=BIGINT},
                </if>
                <if test="gmtLocked != null">
                    gmt_locked = #{gmtLocked,jdbcType=TIMESTAMP},
                </if>
                <if test="hostname != null">
                    hostname = #{hostname,jdbcType=VARCHAR},
                </if>
                <if test="gmtLastHeartbeat != null">
                    gmt_last_heartbeat = #{gmtLastHeartbeat,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtCreate != null">
                    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtModified != null">
                    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
                </if>
        </set>
        where   doudian_msg_parse_queue_id = #{doudianMsgParseQueueId,jdbcType=BIGINT} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ms.dal.entity.DoudianMsgParseQueue">
        update doudian_msg_parse_queue
        set 
            doudian_msg_id =  #{doudianMsgId,jdbcType=BIGINT},
            locked =  #{locked,jdbcType=BIGINT},
            gmt_locked =  #{gmtLocked,jdbcType=TIMESTAMP},
            hostname =  #{hostname,jdbcType=VARCHAR},
            gmt_last_heartbeat =  #{gmtLastHeartbeat,jdbcType=TIMESTAMP},
            gmt_create =  #{gmtCreate,jdbcType=TIMESTAMP},
            gmt_modified =  #{gmtModified,jdbcType=TIMESTAMP}
        where   doudian_msg_parse_queue_id = #{doudianMsgParseQueueId,jdbcType=BIGINT} 
    </update>
    <select id="selectUnlockRowByQueueId" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from doudian_msg_parse_queue
        where  doudian_msg_parse_queue_id = #{queueId,jdbcType=BIGINT}
        and locked = 0
        limit 1
    </select>
</mapper>
