<?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.ruoyi.system.mapper.SysClientDetailsMapper">
    
    <resultMap type="SysClientDetails" id="SysClientDetailsResult">
        <result property="clientId"               column="client_id"                />
        <result property="resourceIds"            column="resource_ids"             />
        <result property="clientSecret"           column="client_secret"            />
        <result property="scope"                  column="scope"                    />
        <result property="authorizedGrantTypes"   column="authorized_grant_types"   />
        <result property="webServerRedirectUri"   column="web_server_redirect_uri"  />
        <result property="authorities"            column="authorities"              />
        <result property="accessTokenValidity"    column="access_token_validity"    />
        <result property="refreshTokenValidity"   column="refresh_token_validity"   />
        <result property="additionalInformation"  column="additional_information"   />
        <result property="autoapprove"            column="autoapprove"              />
    </resultMap>

    <sql id="selectSysClientDetailsVo">
        select client_id, resource_ids, client_secret, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove from sys_oauth_client_details
    </sql>

    <select id="selectSysClientDetailsList" parameterType="SysClientDetails" resultMap="SysClientDetailsResult">
        <include refid="selectSysClientDetailsVo"/>
        <where>  
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
    </select>
    
    <select id="selectSysClientDetailsById" parameterType="String" resultMap="SysClientDetailsResult">
        <include refid="selectSysClientDetailsVo"/>
        where client_id = #{clientId}
    </select>
        
    <insert id="insertSysClientDetails" parameterType="SysClientDetails">
        insert into sys_oauth_client_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientId != null">client_id,</if>
            <if test="resourceIds != null">resource_ids,</if>
            <if test="clientSecret != null">client_secret,</if>
            <if test="scope != null">scope,</if>
            <if test="authorizedGrantTypes != null">authorized_grant_types,</if>
            <if test="webServerRedirectUri != null">web_server_redirect_uri,</if>
            <if test="authorities != null">authorities,</if>
            <if test="accessTokenValidity != null">access_token_validity,</if>
            <if test="refreshTokenValidity != null">refresh_token_validity,</if>
            <if test="additionalInformation != null">additional_information,</if>
            <if test="autoapprove != null">autoapprove,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="clientId != null">#{clientId},</if>
            <if test="resourceIds != null">#{resourceIds},</if>
            <if test="clientSecret != null">#{clientSecret},</if>
            <if test="scope != null">#{scope},</if>
            <if test="authorizedGrantTypes != null">#{authorizedGrantTypes},</if>
            <if test="webServerRedirectUri != null">#{webServerRedirectUri},</if>
            <if test="authorities != null">#{authorities},</if>
            <if test="accessTokenValidity != null">#{accessTokenValidity},</if>
            <if test="refreshTokenValidity != null">#{refreshTokenValidity},</if>
            <if test="additionalInformation != null">#{additionalInformation},</if>
            <if test="autoapprove != null ">#{autoapprove},</if>
         </trim>
    </insert>

    <update id="updateSysClientDetails" parameterType="SysClientDetails">
        update sys_oauth_client_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="resourceIds != null">resource_ids = #{resourceIds},</if>
            <if test="clientSecret != null">client_secret = #{clientSecret},</if>
            <if test="scope != null">scope = #{scope},</if>
            <if test="authorizedGrantTypes != null">authorized_grant_types = #{authorizedGrantTypes},</if>
            <if test="webServerRedirectUri != null">web_server_redirect_uri = #{webServerRedirectUri},</if>
            <if test="authorities != null">authorities = #{authorities},</if>
            <if test="accessTokenValidity != null">access_token_validity = #{accessTokenValidity},</if>
            <if test="refreshTokenValidity != null">refresh_token_validity = #{refreshTokenValidity},</if>
            <if test="additionalInformation != null">additional_information = #{additionalInformation},</if>
            <if test="autoapprove != null">autoapprove = #{autoapprove},</if>
        </trim>
        where client_id = #{clientId}
    </update>

    <delete id="deleteSysClientDetailsById" parameterType="String">
        delete from sys_oauth_client_details where client_id = #{clientId}
    </delete>

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