<?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.easyproject.service.mapper.coze.CozeTokenSetMapper">
    
    <resultMap type="CozeTokenSet" id="CozeTokenSetResult">
        <result property="id"    column="id"    />
        <result property="cozeAccount"    column="coze_account"    />
        <result property="personToken"    column="person_token"    />
        <result property="oauthToken"    column="oauth_token"    />
        <result property="expirationDate"    column="expiration_date"    />
        <result property="status"    column="status"    />
        <result property="tokenStatus"    column="token_status"    />
        <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="selectCozeTokenSetVo">
        select id, coze_account, person_token, oauth_token, expiration_date, status,token_status, create_by, create_time, update_by, update_time, remark from coze_token_set
    </sql>

    <select id="selectCozeTokenSetList" parameterType="CozeTokenSet" resultMap="CozeTokenSetResult">
        <include refid="selectCozeTokenSetVo"/>
        <where>
            <if test="cozeAccount != null  and cozeAccount != ''"> and coze_account = #{cozeAccount}</if>
            <if test="personToken != null  and personToken != ''"> and person_token = #{personToken}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="tokenStatus != null "> and token_status = #{tokenStatus}</if>
        </where>
        order by status asc,id desc
    </select>
    
    <select id="selectCozeTokenSetById" parameterType="Long" resultMap="CozeTokenSetResult">
        <include refid="selectCozeTokenSetVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCozeTokenSet" parameterType="CozeTokenSet" useGeneratedKeys="true" keyProperty="id">
        insert into coze_token_set
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cozeAccount != null and cozeAccount != ''">coze_account,</if>
            <if test="personToken != null and personToken != ''">person_token,</if>
            <if test="oauthToken != null">oauth_token,</if>
            <if test="expirationDate != null">expiration_date,</if>
            <if test="status != null">status,</if>
            <if test="tokenStatus != null">token_status,</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="cozeAccount != null and cozeAccount != ''">#{cozeAccount},</if>
            <if test="personToken != null and personToken != ''">#{personToken},</if>
            <if test="oauthToken != null">#{oauthToken},</if>
            <if test="expirationDate != null">#{expirationDate},</if>
            <if test="status != null">#{status},</if>
            <if test="tokenStatus != null">#{tokenStatus},</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="updateCozeTokenSet" parameterType="CozeTokenSet">
        update coze_token_set
        <trim prefix="SET" suffixOverrides=",">
            <if test="status != null">status = #{status},</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 id = #{id}
    </update>

    <delete id="deleteCozeTokenSetById" parameterType="Long">
        delete from coze_token_set where id = #{id}
    </delete>

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