<?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="hw.tagApi.system.mapper.SysApiTokenMapper">
    
    <resultMap type="SysApiToken" id="SysApiTokenResult">
        <result property="tokenId"    column="token_id"    />
        <result property="tokenCode"    column="token_code"    />
        <result property="expiresTime"    column="expires_time"    />
        <result property="enableFlag"    column="enable_flag"    />
        <result property="fields1"    column="fields_1"    />
        <result property="fields2"    column="fields_2"    />
        <result property="fields3"    column="fields_3"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysApiTokenVo">
        select token_id, token_code, expires_time, enable_flag, fields_1, fields_2, fields_3, create_by, create_time, update_by, update_time, remark from sys_api_token
    </sql>

    <select id="selectSysApiTokenList" parameterType="SysApiToken" resultMap="SysApiTokenResult">
        <include refid="selectSysApiTokenVo"/>
        <where>  
            <if test="tokenCode != null  and tokenCode != ''"> and token_code like concat('%', #{tokenCode}, '%')</if>
            <if test="params.beginExpiresTime != null and params.beginExpiresTime != '' and params.endExpiresTime != null and params.endExpiresTime != ''"> and expires_time between #{params.beginExpiresTime} and #{params.endExpiresTime}</if>
            <if test="enableFlag != null  and enableFlag != ''"> and enable_flag = #{enableFlag}</if>
            <if test="fields1 != null  and fields1 != ''"> and fields_1 = #{fields1}</if>
            <if test="fields2 != null  and fields2 != ''"> and fields_2 = #{fields2}</if>
            <if test="fields3 != null  and fields3 != ''"> and fields_3 = #{fields3}</if>
        </where>
    </select>
    
    <select id="selectSysApiTokenByTokenId" parameterType="Long" resultMap="SysApiTokenResult">
        <include refid="selectSysApiTokenVo"/>
        where token_id = #{tokenId}
    </select>

    <insert id="insertSysApiToken" parameterType="SysApiToken" useGeneratedKeys="true" keyProperty="tokenId">
        insert into sys_api_token
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tokenCode != null and tokenCode != ''">token_code,</if>
            <if test="expiresTime != null">expires_time,</if>
            <if test="enableFlag != null and enableFlag != ''">enable_flag,</if>
            <if test="fields1 != null">fields_1,</if>
            <if test="fields2 != null">fields_2,</if>
            <if test="fields3 != null">fields_3,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tokenCode != null and tokenCode != ''">#{tokenCode},</if>
            <if test="expiresTime != null">#{expiresTime},</if>
            <if test="enableFlag != null and enableFlag != ''">#{enableFlag},</if>
            <if test="fields1 != null">#{fields1},</if>
            <if test="fields2 != null">#{fields2},</if>
            <if test="fields3 != null">#{fields3},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysApiToken" parameterType="SysApiToken">
        update sys_api_token
        <trim prefix="SET" suffixOverrides=",">
            <if test="tokenCode != null and tokenCode != ''">token_code = #{tokenCode},</if>
            <if test="expiresTime != null">expires_time = #{expiresTime},</if>
            <if test="enableFlag != null and enableFlag != ''">enable_flag = #{enableFlag},</if>
            <if test="fields1 != null">fields_1 = #{fields1},</if>
            <if test="fields2 != null">fields_2 = #{fields2},</if>
            <if test="fields3 != null">fields_3 = #{fields3},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where token_id = #{tokenId}
    </update>

    <delete id="deleteSysApiTokenByTokenId" parameterType="Long">
        delete from sys_api_token where token_id = #{tokenId}
    </delete>

    <delete id="deleteSysApiTokenByTokenIds" parameterType="String">
        delete from sys_api_token where token_id in 
        <foreach item="tokenId" collection="array" open="(" separator="," close=")">
            #{tokenId}
        </foreach>
    </delete>
</mapper>