<?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.fs.baidu.mapper.BdApiMapper">
    
    <resultMap type="BdApi" id="BdApiResult">
        <result property="id"    column="id"    />
        <result property="appId"    column="app_id"    />
        <result property="appSecretKey"    column="app_secret_key"    />
        <result property="apppName"    column="appp_name"    />
        <result property="openId"    column="open_id"    />
        <result property="authCode"    column="auth_code"    />
        <result property="accessToken"    column="access_token"    />
        <result property="refreshToken"    column="refresh_token"    />
        <result property="expiresIn"    column="expires_in"    />
        <result property="refreshExpiresIn"    column="refresh_expires_in"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectBdApiVo">
        select * from bd_api
    </sql>

    <select id="selectBdApiList" parameterType="BdApi" resultMap="BdApiResult">
        <include refid="selectBdApiVo"/>
        <where>  
            <if test="appId != null  and appId != ''"> and app_id = #{appId}</if>
            <if test="appSecretKey != null  and appSecretKey != ''"> and app_secret_key = #{appSecretKey}</if>
            <if test="apppName != null  and apppName != ''"> and appp_name like concat('%', #{apppName}, '%')</if>
            <if test="openId != null  and openId != ''"> and open_id = #{openId}</if>
            <if test="authCode != null  and authCode != ''"> and auth_code = #{authCode}</if>
            <if test="accessToken != null  and accessToken != ''"> and access_token = #{accessToken}</if>
            <if test="refreshToken != null  and refreshToken != ''"> and refresh_token = #{refreshToken}</if>
            <if test="expiresIn != null "> and expires_in = #{expiresIn}</if>
            <if test="refreshExpiresIn != null "> and refresh_expires_in = #{refreshExpiresIn}</if>
        </where>
    </select>
    
    <select id="selectBdApiById" parameterType="Long" resultMap="BdApiResult">
        <include refid="selectBdApiVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBdApi" parameterType="BdApi" useGeneratedKeys="true" keyProperty="id">
        insert into bd_api
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appId != null">app_id,</if>
            <if test="appSecretKey != null">app_secret_key,</if>
            <if test="apppName != null">appp_name,</if>
            <if test="openId != null">open_id,</if>
            <if test="authCode != null">auth_code,</if>
            <if test="accessToken != null">access_token,</if>
            <if test="refreshToken != null">refresh_token,</if>
            <if test="expiresIn != null">expires_in,</if>
            <if test="refreshExpiresIn != null">refresh_expires_in,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="appId != null">#{appId},</if>
            <if test="appSecretKey != null">#{appSecretKey},</if>
            <if test="apppName != null">#{apppName},</if>
            <if test="openId != null">#{openId},</if>
            <if test="authCode != null">#{authCode},</if>
            <if test="accessToken != null">#{accessToken},</if>
            <if test="refreshToken != null">#{refreshToken},</if>
            <if test="expiresIn != null">#{expiresIn},</if>
            <if test="refreshExpiresIn != null">#{refreshExpiresIn},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateBdApi" parameterType="BdApi">
        update bd_api
        <trim prefix="SET" suffixOverrides=",">
            <if test="appId != null">app_id = #{appId},</if>
            <if test="appSecretKey != null">app_secret_key = #{appSecretKey},</if>
            <if test="apppName != null">appp_name = #{apppName},</if>
            <if test="openId != null">open_id = #{openId},</if>
            <if test="authCode != null">auth_code = #{authCode},</if>
            <if test="accessToken != null">access_token = #{accessToken},</if>
            <if test="refreshToken != null">refresh_token = #{refreshToken},</if>
            <if test="expiresIn != null">expires_in = #{expiresIn},</if>
            <if test="refreshExpiresIn != null">refresh_expires_in = #{refreshExpiresIn},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBdApiById" parameterType="Long">
        delete from bd_api where id = #{id}
    </delete>

    <delete id="deleteBdApiByIds" parameterType="String">
        delete from bd_api where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>