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

    <resultMap id="BaseResultMap" type="com.ms.dal.entity.Shop">
            <id property="shopId" column="shop_id" jdbcType="BIGINT"/>
            <result property="shopName" column="shop_name" jdbcType="VARCHAR"/>
            <result property="accessToken" column="access_token" jdbcType="VARCHAR"/>
            <result property="refreshToken" column="refresh_token" jdbcType="VARCHAR"/>
            <result property="expiresIn" column="expires_in" jdbcType="VARCHAR"/>
            <result property="lastLoginIp" column="last_login_ip" jdbcType="VARCHAR"/>
            <result property="totalProduct" column="total_product" jdbcType="INTEGER"/>
            <result property="totalMoveDetail" column="total_move_detail" jdbcType="INTEGER"/>
            <result property="appVersion" column="app_version" jdbcType="VARCHAR"/>
            <result property="gmtLastLogin" column="gmt_last_login" jdbcType="TIMESTAMP"/>
            <result property="gmtExpire" column="gmt_expire" jdbcType="TIMESTAMP"/>
            <result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
            <result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        shop_id,shop_name,access_token,
        refresh_token,expires_in,last_login_ip,
        total_product,total_move_detail,app_version,
        gmt_last_login,gmt_expire,gmt_create,
        gmt_modified
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from shop
        where  shop_id = #{shopId,jdbcType=BIGINT}
    </select>
    <select id="getShopByIds" resultMap="BaseResultMap">
        select  * from shop
        where  shop_id in
        <foreach collection="shopIds" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    <select id="selectShopIdsByExpirePositionPage" resultType="java.lang.Long">
        select shop_id
        from shop
        where  gmt_expire > now() and shop_id > #{startId,jdbcType=BIGINT}
        order by shop_id asc limit #{limit}
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from shop
        where  shop_id = #{shopId,jdbcType=BIGINT}
    </delete>
    <insert id="insert" keyColumn="shop_id" keyProperty="shopId" parameterType="com.ms.dal.entity.Shop" useGeneratedKeys="true">
        insert into shop
        ( shop_id,shop_name,access_token
        ,refresh_token,expires_in,last_login_ip
        ,total_product,total_move_detail,app_version
        ,gmt_last_login,gmt_expire,gmt_create
        ,gmt_modified)
        values (#{shopId,jdbcType=BIGINT},#{shopName,jdbcType=VARCHAR},#{accessToken,jdbcType=VARCHAR}
        ,#{refreshToken,jdbcType=VARCHAR},#{expiresIn,jdbcType=VARCHAR},#{lastLoginIp,jdbcType=VARCHAR}
        ,#{totalProduct,jdbcType=INTEGER},#{totalMoveDetail,jdbcType=INTEGER},#{appVersion,jdbcType=VARCHAR}
        ,#{gmtLastLogin,jdbcType=TIMESTAMP},#{gmtExpire,jdbcType=TIMESTAMP},#{gmtCreate,jdbcType=TIMESTAMP}
        ,#{gmtModified,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" keyColumn="shop_id" keyProperty="shopId" parameterType="com.ms.dal.entity.Shop" useGeneratedKeys="true">
        insert into shop
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="shopId != null">shop_id,</if>
                <if test="shopName != null">shop_name,</if>
                <if test="accessToken != null">access_token,</if>
                <if test="refreshToken != null">refresh_token,</if>
                <if test="expiresIn != null">expires_in,</if>
                <if test="lastLoginIp != null">last_login_ip,</if>
                <if test="totalProduct != null">total_product,</if>
                <if test="totalMoveDetail != null">total_move_detail,</if>
                <if test="appVersion != null">app_version,</if>
                <if test="gmtLastLogin != null">gmt_last_login,</if>
                <if test="gmtExpire != null">gmt_expire,</if>
                <if test="gmtCreate != null">gmt_create,</if>
                <if test="gmtModified != null">gmt_modified,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="shopId != null">#{shopId,jdbcType=BIGINT},</if>
                <if test="shopName != null">#{shopName,jdbcType=VARCHAR},</if>
                <if test="accessToken != null">#{accessToken,jdbcType=VARCHAR},</if>
                <if test="refreshToken != null">#{refreshToken,jdbcType=VARCHAR},</if>
                <if test="expiresIn != null">#{expiresIn,jdbcType=VARCHAR},</if>
                <if test="lastLoginIp != null">#{lastLoginIp,jdbcType=VARCHAR},</if>
                <if test="totalProduct != null">#{totalProduct,jdbcType=INTEGER},</if>
                <if test="totalMoveDetail != null">#{totalMoveDetail,jdbcType=INTEGER},</if>
                <if test="appVersion != null">#{appVersion,jdbcType=VARCHAR},</if>
                <if test="gmtLastLogin != null">#{gmtLastLogin,jdbcType=TIMESTAMP},</if>
                <if test="gmtExpire != null">#{gmtExpire,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.Shop">
        update shop
        <set>
                <if test="shopName != null">
                    shop_name = #{shopName,jdbcType=VARCHAR},
                </if>
                <if test="accessToken != null">
                    access_token = #{accessToken,jdbcType=VARCHAR},
                </if>
                <if test="refreshToken != null">
                    refresh_token = #{refreshToken,jdbcType=VARCHAR},
                </if>
                <if test="expiresIn != null">
                    expires_in = #{expiresIn,jdbcType=VARCHAR},
                </if>
                <if test="lastLoginIp != null">
                    last_login_ip = #{lastLoginIp,jdbcType=VARCHAR},
                </if>
                <if test="totalProduct != null">
                    total_product = #{totalProduct,jdbcType=INTEGER},
                </if>
                <if test="totalMoveDetail != null">
                    total_move_detail = #{totalMoveDetail,jdbcType=INTEGER},
                </if>
                <if test="appVersion != null">
                    app_version = #{appVersion,jdbcType=VARCHAR},
                </if>
                <if test="gmtLastLogin != null">
                    gmt_last_login = #{gmtLastLogin,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtExpire != null">
                    gmt_expire = #{gmtExpire,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   shop_id = #{shopId,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ms.dal.entity.Shop">
        update shop
        set
            shop_name =  #{shopName,jdbcType=VARCHAR},
            access_token =  #{accessToken,jdbcType=VARCHAR},
            refresh_token =  #{refreshToken,jdbcType=VARCHAR},
            expires_in =  #{expiresIn,jdbcType=VARCHAR},
            last_login_ip =  #{lastLoginIp,jdbcType=VARCHAR},
            total_product =  #{totalProduct,jdbcType=INTEGER},
            total_move_detail =  #{totalMoveDetail,jdbcType=INTEGER},
            app_version =  #{appVersion,jdbcType=VARCHAR},
            gmt_last_login =  #{gmtLastLogin,jdbcType=TIMESTAMP},
            gmt_expire =  #{gmtExpire,jdbcType=TIMESTAMP},
            gmt_create =  #{gmtCreate,jdbcType=TIMESTAMP},
            gmt_modified =  #{gmtModified,jdbcType=TIMESTAMP}
        where   shop_id = #{shopId,jdbcType=BIGINT}
    </update>
    <select id="getExpiresTokenShops" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from shop
        where  gmt_expire &lt; #{gmtExpireStart} and gmt_expire &gt; #{gmtExpireEnd}
    </select>
</mapper>
