<?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.crm.mapper.CrmCustomerThirdMapper">

    <resultMap type="CrmCustomerThird" id="CrmCustomerThirdResult">
        <result property="id"    column="id"    />
        <result property="thirdName"    column="third_name"    />
        <result property="thirdType"    column="third_type"    />
        <result property="appId"    column="app_id"    />
        <result property="appSecret"    column="app_secret"    />
        <result property="account"    column="account"    />
        <result property="status"    column="status"    />
        <result property="accessStatus"    column="access_status"    />
        <result property="refreshStatus"    column="refresh_status"    />
        <result property="accessToken"    column="access_token"    />
        <result property="refreshToken"    column="refresh_token"    />
        <result property="advertiserIds"    column="advertiser_ids"    />
        <result property="advertiserNames"    column="advertiser_names"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateUserId"    column="update_user_id"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectCrmCustomerThirdVo">
        select id, third_name, third_type, app_id, app_secret, account, status, access_status, refresh_status, access_token, refresh_token,advertiser_ids,advertiser_names, create_user_id, create_time, update_user_id, update_time from crm_customer_third
    </sql>

    <select id="selectCrmCustomerThirdList" parameterType="CrmCustomerThird" resultMap="CrmCustomerThirdResult">
        <include refid="selectCrmCustomerThirdVo"/>
        <where>
            <if test="thirdName != null  and thirdName != ''"> and third_name like concat('%', #{thirdName}, '%')</if>
            <if test="thirdType != null  and thirdType != ''"> and third_type = #{thirdType}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectCrmCustomerThirdById" parameterType="Long" resultMap="CrmCustomerThirdResult">
        <include refid="selectCrmCustomerThirdVo"/>
        where id = #{id}
    </select>

    <insert id="insertCrmCustomerThird" parameterType="CrmCustomerThird" useGeneratedKeys="true" keyProperty="id">
        insert into crm_customer_third
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="thirdName != null">third_name,</if>
            <if test="thirdType != null">third_type,</if>
            <if test="appId != null">app_id,</if>
            <if test="appSecret != null">app_secret,</if>
            <if test="account != null">account,</if>
            <if test="status != null">status,</if>
            <if test="accessStatus != null">access_status,</if>
            <if test="refreshStatus != null">refresh_status,</if>
            <if test="accessToken != null">access_token,</if>
            <if test="refreshToken != null">refresh_token,</if>
            <if test="advertiserIds != null">advertiser_ids,</if>
            <if test="advertiserNames != null">advertiser_names,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateUserId != null">update_user_id,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="thirdName != null">#{thirdName},</if>
            <if test="thirdType != null">#{thirdType},</if>
            <if test="appId != null">#{appId},</if>
            <if test="appSecret != null">#{appSecret},</if>
            <if test="account != null">#{account},</if>
            <if test="status != null">#{status},</if>
            <if test="accessStatus != null">#{accessStatus},</if>
            <if test="refreshStatus != null">#{refreshStatus},</if>
            <if test="accessToken != null">#{accessToken},</if>
            <if test="refreshToken != null">#{refreshToken},</if>
            <if test="advertiserIds != null">#{advertiserIds},</if>
            <if test="advertiserNames != null">#{advertiserNames},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateCrmCustomerThird" parameterType="CrmCustomerThird">
        update crm_customer_third
        <trim prefix="SET" suffixOverrides=",">
            <if test="thirdName != null">third_name = #{thirdName},</if>
            <if test="thirdType != null">third_type = #{thirdType},</if>
            <if test="appId != null">app_id = #{appId},</if>
            <if test="appSecret != null">app_secret = #{appSecret},</if>
            <if test="account != null">account = #{account},</if>
            <if test="status != null">status = #{status},</if>
            <if test="accessStatus != null">access_status = #{accessStatus},</if>
            <if test="refreshStatus != null">refresh_status = #{refreshStatus},</if>
            <if test="accessToken != null">access_token = #{accessToken},</if>
            <if test="refreshToken != null">refresh_token = #{refreshToken},</if>
            <if test="advertiserIds != null">advertiser_ids = #{advertiserIds},</if>
            <if test="advertiserNames != null">advertiser_names = #{advertiserNames},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateUserId != null">update_user_id = #{updateUserId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCrmCustomerThirdById" parameterType="Long">
        delete from crm_customer_third where id = #{id}
    </delete>

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

</mapper>
