<?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.huashe.common.data.mapper.AdmApiAuthMapper">
    <resultMap id="BaseResultMap" type="com.huashe.common.data.model.AdmApiAuth">
        <result column="id" property="id" jdbcType="BIGINT"/>
        <result column="client_id" property="clientId" jdbcType="VARCHAR"/>
        <result column="client_name" property="clientName" jdbcType="VARCHAR"/>
        <result column="api_key" property="apiKey" jdbcType="VARCHAR"/>
        <result column="status" property="status" jdbcType="VARCHAR"/>
        <result column="expire_time" property="expireTime" jdbcType="DATE"/>
    </resultMap>

    <insert id="insert" parameterType="com.huashe.common.data.model.AdmApiAuth">
        INSERT INTO `adm_api_auth` (`client_id`, `client_name`, `api_key`, `status`, `expire_time`) VALUES (#{clientId}, #{clientName}, #{apiKey}, #{status}, #{expireTime});
    </insert>

    <update id="update" parameterType="com.huashe.common.data.model.AdmApiAuth">
        UPDATE `adm_api_auth`
        SET `client_name` = #{clientName},
            `api_key` = #{apiKey},
            `status` = #{status},
            `expire_time` = #{expireTime}
        WHERE `client_id` = #{clientId};
    </update>

    <delete id="delete" parameterType="java.lang.String">
        DELETE FROM `adm_api_auth` WHERE `client_id` = #{clientId};
    </delete>

    <select id="getByKey" resultType="java.lang.String" resultMap="BaseResultMap">
        SELECT
            `id`, `client_id`, `client_name`, `api_key`, `status`, `expire_time`
        FROM
            adm_api_auth
        WHERE
            `api_key` = #{apiKey}
    </select>
</mapper>
