<?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.chinaweal.aiccs.org.mapper.OauthAuthorizationCodeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.org.entity.OauthAuthorizationCode">
        <id column="code_id" property="codeId"/>
        <result column="authorization_code" property="authorizationCode"/>
        <result column="client_id" property="clientId"/>
        <result column="user_id" property="userId"/>
        <result column="user_name" property="userName"/>
        <result column="scope" property="scope"/>
        <result column="redirect_uri" property="redirectUri"/>
        <result column="state" property="state"/>
        <result column="grant_type" property="grantType"/>
        <result column="expires_at" property="expiresAt"/>
        <result column="is_used" property="isUsed"/>
        <result column="is_active" property="isActive"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        code_id, authorization_code, client_id, user_id, user_name, scope, redirect_uri, state,
        grant_type, expires_at, is_used, is_active, create_time, update_time
    </sql>

    <!-- 根据授权码查询信息 -->
    <select id="selectByAuthorizationCode" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM oauth_authorization_code
        WHERE authorization_code = #{authorizationCode}
        LIMIT 1
    </select>

    <!-- 根据授权码和客户端ID查询信息 -->
    <select id="selectByCodeAndClientId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM oauth_authorization_code
        WHERE authorization_code = #{authorizationCode}
        AND client_id = #{clientId}
        LIMIT 1
    </select>

</mapper>