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

    <resultMap id="BaseResultMap" type="com.ms.dal.entity.LogisticsMatchRule">
            <id property="logisticsMatchRuleId" column="logistics_match_rule_id" jdbcType="INTEGER"/>
            <result property="logisticsName" column="logistics_name" jdbcType="VARCHAR"/>
            <result property="platform" column="platform" jdbcType="VARCHAR"/>
            <result property="platformLogisticsName" column="platform_logistics_name" jdbcType="VARCHAR"/>
            <result property="waybillCodeRule" column="waybill_code_rule" jdbcType="VARCHAR"/>
            <result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
            <result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        logistics_match_rule_id,logistics_name,platform,
        platform_logistics_name,waybill_code_rule,gmt_create,
        gmt_modified
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from logistics_match_rule
        where  logistics_match_rule_id = #{logisticsMatchRuleId,jdbcType=INTEGER} 
    </select>
    <select id="getListByPlatform" resultType="com.ms.dal.entity.LogisticsMatchRule">
        select
        <include refid="Base_Column_List" />
        from logistics_match_rule
        where  platform in ('all', #{platform,jdbcType=VARCHAR})
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from logistics_match_rule
        where  logistics_match_rule_id = #{logisticsMatchRuleId,jdbcType=INTEGER} 
    </delete>
    <insert id="insert" keyColumn="logistics_match_rule_id" keyProperty="logisticsMatchRuleId" parameterType="com.ms.dal.entity.LogisticsMatchRule" useGeneratedKeys="true">
        insert into logistics_match_rule
        ( logistics_match_rule_id,logistics_name,platform
        ,platform_logistics_name,waybill_code_rule,gmt_create
        ,gmt_modified)
        values (#{logisticsMatchRuleId,jdbcType=INTEGER},#{logisticsName,jdbcType=VARCHAR},#{platform,jdbcType=VARCHAR}
        ,#{platformLogisticsName,jdbcType=VARCHAR},#{waybillCodeRule,jdbcType=VARCHAR},#{gmtCreate,jdbcType=TIMESTAMP}
        ,#{gmtModified,jdbcType=TIMESTAMP})
    </insert>
    <update id="insertOrUpdate"  keyColumn="logistics_match_rule_id" keyProperty="logisticsMatchRuleId" parameterType="com.ms.dal.entity.LogisticsMatchRule"
        useGeneratedKeys="true">
        insert into logistics_match_rule
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="logisticsMatchRuleId != null">logistics_match_rule_id,</if>
                <if test="logisticsName != null">logistics_name,</if>
                <if test="platform != null">platform,</if>
                <if test="platformLogisticsName != null">platform_logistics_name,</if>
                <if test="waybillCodeRule != null">waybill_code_rule,</if>
                <if test="gmtCreate != null">gmt_create,</if>
                <if test="gmtModified != null">gmt_modified,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="logisticsMatchRuleId != null">#{logisticsMatchRuleId,jdbcType=INTEGER},</if>
                <if test="logisticsName != null">#{logisticsName,jdbcType=VARCHAR},</if>
                <if test="platform != null">#{platform,jdbcType=VARCHAR},</if>
                <if test="platformLogisticsName != null">#{platformLogisticsName,jdbcType=VARCHAR},</if>
                <if test="waybillCodeRule != null">#{waybillCodeRule,jdbcType=VARCHAR},</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="logisticsName != null">
                    logistics_name = #{logisticsName,jdbcType=VARCHAR},
                </if>
                <if test="platform != null">
                    platform = #{platform,jdbcType=VARCHAR},
                </if>
                <if test="platformLogisticsName != null">
                    platform_logistics_name = #{platformLogisticsName,jdbcType=VARCHAR},
                </if>
                <if test="waybillCodeRule != null">
                    waybill_code_rule = #{waybillCodeRule,jdbcType=VARCHAR},
                </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="logistics_match_rule_id" keyProperty="logisticsMatchRuleId" parameterType="com.ms.dal.entity.LogisticsMatchRule" useGeneratedKeys="true">
        insert into logistics_match_rule
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="logisticsMatchRuleId != null">logistics_match_rule_id,</if>
                <if test="logisticsName != null">logistics_name,</if>
                <if test="platform != null">platform,</if>
                <if test="platformLogisticsName != null">platform_logistics_name,</if>
                <if test="waybillCodeRule != null">waybill_code_rule,</if>
                <if test="gmtCreate != null">gmt_create,</if>
                <if test="gmtModified != null">gmt_modified,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="logisticsMatchRuleId != null">#{logisticsMatchRuleId,jdbcType=INTEGER},</if>
                <if test="logisticsName != null">#{logisticsName,jdbcType=VARCHAR},</if>
                <if test="platform != null">#{platform,jdbcType=VARCHAR},</if>
                <if test="platformLogisticsName != null">#{platformLogisticsName,jdbcType=VARCHAR},</if>
                <if test="waybillCodeRule != null">#{waybillCodeRule,jdbcType=VARCHAR},</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.LogisticsMatchRule">
        update logistics_match_rule
        <set>
                <if test="logisticsName != null">
                    logistics_name = #{logisticsName,jdbcType=VARCHAR},
                </if>
                <if test="platform != null">
                    platform = #{platform,jdbcType=VARCHAR},
                </if>
                <if test="platformLogisticsName != null">
                    platform_logistics_name = #{platformLogisticsName,jdbcType=VARCHAR},
                </if>
                <if test="waybillCodeRule != null">
                    waybill_code_rule = #{waybillCodeRule,jdbcType=VARCHAR},
                </if>
                <if test="gmtCreate != null">
                    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtModified != null">
                    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
                </if>
        </set>
        where   logistics_match_rule_id = #{logisticsMatchRuleId,jdbcType=INTEGER} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ms.dal.entity.LogisticsMatchRule">
        update logistics_match_rule
        set 
            logistics_name =  #{logisticsName,jdbcType=VARCHAR},
            platform =  #{platform,jdbcType=VARCHAR},
            platform_logistics_name =  #{platformLogisticsName,jdbcType=VARCHAR},
            waybill_code_rule =  #{waybillCodeRule,jdbcType=VARCHAR},
            gmt_create =  #{gmtCreate,jdbcType=TIMESTAMP},
            gmt_modified =  #{gmtModified,jdbcType=TIMESTAMP}
        where   logistics_match_rule_id = #{logisticsMatchRuleId,jdbcType=INTEGER} 
    </update>
</mapper>
