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

    <resultMap id="BaseResultMap" type="com.ms.dal.entity.DsMessage">
            <id property="dsMessageId" column="ds_message_id" jdbcType="BIGINT"/>
            <result property="platformPushMsgId" column="platform_push_msg_id" jdbcType="BIGINT"/>
            <result property="shopId" column="shop_id" jdbcType="BIGINT"/>
            <result property="bizId" column="biz_id" jdbcType="VARCHAR"/>
            <result property="bizType" column="biz_type" jdbcType="VARCHAR"/>
            <result property="data" column="data" jdbcType="VARCHAR"/>
            <result property="status" column="status" jdbcType="VARCHAR"/>
            <result property="reason" column="reason" jdbcType="VARCHAR"/>
            <result property="tryTimes" column="try_times" jdbcType="TINYINT"/>
            <result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
            <result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        ds_message_id,platform_push_msg_id,shop_id,
        biz_id,biz_type,data,
        status,reason,try_times,
        gmt_create,gmt_modified
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from ds_message
        where  ds_message_id = #{dsMessageId,jdbcType=BIGINT} 
    </select>
    <select id="getNewestDsMessage" resultType="com.ms.dal.entity.DsMessage">
        select ds_message_id
        from ds_message
        where biz_id = #{bizId,jdbcType=VARCHAR}
          and biz_type = #{bizType,jdbcType=VARCHAR}
          and platform_push_msg_id > #{curPlatformPushMsgId,jdbcType=BIGINT}
          and gmt_create >= #{curGmtCreate,jdbcType=TIMESTAMP}
        <if test="purchaseOrderSn != null">
            and data like '%${purchaseOrderSn}%'
        </if>
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from ds_message
        where  ds_message_id = #{dsMessageId,jdbcType=BIGINT} 
    </delete>
    <insert id="insert" keyColumn="ds_message_id" keyProperty="dsMessageId" parameterType="com.ms.dal.entity.DsMessage" useGeneratedKeys="true">
        insert into ds_message
        ( ds_message_id,platform_push_msg_id,shop_id
        ,biz_id,biz_type,data
        ,status,reason,try_times
        ,gmt_create,gmt_modified)
        values (#{dsMessageId,jdbcType=BIGINT},#{platformPushMsgId,jdbcType=BIGINT},#{shopId,jdbcType=BIGINT}
        ,#{bizId,jdbcType=VARCHAR},#{bizType,jdbcType=VARCHAR},#{data,jdbcType=VARCHAR}
        ,#{status,jdbcType=VARCHAR},#{reason,jdbcType=VARCHAR},#{tryTimes,jdbcType=TINYINT}
        ,#{gmtCreate,jdbcType=TIMESTAMP},#{gmtModified,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" keyColumn="ds_message_id" keyProperty="dsMessageId" parameterType="com.ms.dal.entity.DsMessage" useGeneratedKeys="true">
        insert into ds_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="dsMessageId != null">ds_message_id,</if>
                <if test="platformPushMsgId != null">platform_push_msg_id,</if>
                <if test="shopId != null">shop_id,</if>
                <if test="bizId != null">biz_id,</if>
                <if test="bizType != null">biz_type,</if>
                <if test="data != null">data,</if>
                <if test="status != null">status,</if>
                <if test="reason != null">reason,</if>
                <if test="tryTimes != null">try_times,</if>
                <if test="gmtCreate != null">gmt_create,</if>
                <if test="gmtModified != null">gmt_modified,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="dsMessageId != null">#{dsMessageId,jdbcType=BIGINT},</if>
                <if test="platformPushMsgId != null">#{platformPushMsgId,jdbcType=BIGINT},</if>
                <if test="shopId != null">#{shopId,jdbcType=BIGINT},</if>
                <if test="bizId != null">#{bizId,jdbcType=VARCHAR},</if>
                <if test="bizType != null">#{bizType,jdbcType=VARCHAR},</if>
                <if test="data != null">#{data,jdbcType=VARCHAR},</if>
                <if test="status != null">#{status,jdbcType=VARCHAR},</if>
                <if test="reason != null">#{reason,jdbcType=VARCHAR},</if>
                <if test="tryTimes != null">#{tryTimes,jdbcType=TINYINT},</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.DsMessage">
        update ds_message
        <set>
                <if test="platformPushMsgId != null">
                    platform_push_msg_id = #{platformPushMsgId,jdbcType=BIGINT},
                </if>
                <if test="shopId != null">
                    shop_id = #{shopId,jdbcType=BIGINT},
                </if>
                <if test="bizId != null">
                    biz_id = #{bizId,jdbcType=VARCHAR},
                </if>
                <if test="bizType != null">
                    biz_type = #{bizType,jdbcType=VARCHAR},
                </if>
                <if test="data != null">
                    data = #{data,jdbcType=VARCHAR},
                </if>
                <if test="status != null">
                    status = #{status,jdbcType=VARCHAR},
                </if>
                <if test="reason != null">
                    reason = #{reason,jdbcType=VARCHAR},
                </if>
                <if test="tryTimes != null">
                    try_times = #{tryTimes,jdbcType=TINYINT},
                </if>
                <if test="gmtCreate != null">
                    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtModified != null">
                    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
                </if>
        </set>
        where   ds_message_id = #{dsMessageId,jdbcType=BIGINT} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ms.dal.entity.DsMessage">
        update ds_message
        set 
            platform_push_msg_id =  #{platformPushMsgId,jdbcType=BIGINT},
            shop_id =  #{shopId,jdbcType=BIGINT},
            biz_id =  #{bizId,jdbcType=VARCHAR},
            biz_type =  #{bizType,jdbcType=VARCHAR},
            data =  #{data,jdbcType=VARCHAR},
            status =  #{status,jdbcType=VARCHAR},
            reason =  #{reason,jdbcType=VARCHAR},
            try_times =  #{tryTimes,jdbcType=TINYINT},
            gmt_create =  #{gmtCreate,jdbcType=TIMESTAMP},
            gmt_modified =  #{gmtModified,jdbcType=TIMESTAMP}
        where   ds_message_id = #{dsMessageId,jdbcType=BIGINT} 
    </update>
    <update id="updateStatus">
        update ds_message
        set
            status =  #{status,jdbcType=VARCHAR},
            reason =  #{reason,jdbcType=VARCHAR},
            gmt_modified = now()
        where ds_message_id = #{dsMessageId,jdbcType=BIGINT}
    </update>
</mapper>
