<?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="org.jeecg.ctop.finance.agent.mapper.CtopAgentAccountMapper">
    <resultMap id="BaseResultMap" type="cn.com.ctop.common.module.entity.CtopOauthToken">
        <result column="id" property="id" jdbcType="BIGINT"/>
        <result column="media_id" property="mediaId" jdbcType="VARCHAR"/>
        <result column="advertiser_id" property="advertiserId" jdbcType="VARCHAR"/>
        <result column="account_id" property="accountId" jdbcType="BIGINT"/>
        <result column="access_token" property="accessToken" jdbcType="VARCHAR"/>
        <result column="refresh_token" property="refreshToken" jdbcType="VARCHAR"/>
        <result column="access_token_expires_in" property="accessTokenExpiresIn" jdbcType="TIMESTAMP"/>
        <result column="refresh_token_expires_in" property="refreshTokenExpiresIn" jdbcType="TIMESTAMP"/>
        <result column="agent_type" property="agentType" jdbcType="INTEGER"/>
        <result column="app_id" property="appId" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,media_id,advertiser_id,account_id,access_token,refresh_token,access_token_expires_in,refresh_token_expires_in,agent_type,app_id,create_time,update_time
   </sql>
    <!--获取所有账户-->
    <select id="getAllAccountId" resultType="String">
        select account_id from ctop_agent_account where state=0
    </select>
   <!-- 根据账户id修改账户状态-->
    <update id="updateAccountState">
        update ctop_agent_account set state=#{state} where account_id in
        <foreach item="item" index="index" collection="list" open="("  close=")" separator=",">
            #{item}
        </foreach>
    </update>
   <!-- 批量插入新增数据-->
    <insert id="insertAccountData">
        insert  into ctop_agent_account (account_id,agent_id,state,create_time) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item},
            #{agent_id},
            0,
            #{create_time}
            )
        </foreach>
    </insert>

    <select id="selectByAccountId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from ctop_oauth_token
        where account_id = #{accountId}
        order by create_time desc
        limit 1
    </select>

</mapper>