<?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.ff.common.mapper.TenantSecretKeyMapper">

    <resultMap type="TenantSecretKey" id="TenantSecretKeyResult">
        <result property="id"    column="id"    />
        <result property="tenantKey"    column="tenant_key"    />
        <result property="tenantSn"    column="tenant_sn"    />
        <result property="tenantSecret"    column="tenant_secret"    />
        <result property="tenantStatus"    column="tenant_status"    />
        <result property="tenantType"    column="tenant_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTenantSecretKeyVo">
        select id, tenant_key, tenant_sn, tenant_secret, tenant_status, tenant_type, create_by, create_time, update_by, update_time from ff_tenant_secret_key
    </sql>

    <select id="selectTenantSecretKeyList" parameterType="TenantSecretKey" resultMap="TenantSecretKeyResult">
        <include refid="selectTenantSecretKeyVo"/>
        <where>
            <if test="tenantKey != null  and tenantKey != ''"> and tenant_key = #{tenantKey}</if>
            <if test="tenantSn != null  and tenantSn != ''"> and tenant_sn = #{tenantSn}</if>
            <if test="tenantSecret != null  and tenantSecret != ''"> and tenant_secret = #{tenantSecret}</if>
            <if test="tenantStatus != null "> and tenant_status = #{tenantStatus}</if>
            <if test="tenantType != null "> and tenant_type = #{tenantType}</if>
        </where>
    </select>

    <select id="selectTenantSecretKeyById" parameterType="Long" resultMap="TenantSecretKeyResult">
        <include refid="selectTenantSecretKeyVo"/>
        where id = #{id}
    </select>

    <select id="selectTenantSecretKeyByTenantKey" parameterType="String" resultMap="TenantSecretKeyResult">
        <include refid="selectTenantSecretKeyVo"/>
        where tenant_key = #{tenantKey}
    </select>

    <insert id="insertTenantSecretKey" parameterType="TenantSecretKey" useGeneratedKeys="true" keyProperty="id">
        insert into ff_tenant_secret_key
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tenantKey != null and tenantKey != ''">tenant_key,</if>
            <if test="tenantSn != null">tenant_sn,</if>
            <if test="tenantSecret != null and tenantSecret != ''">tenant_secret,</if>
            <if test="tenantStatus != null">tenant_status,</if>
            <if test="tenantType != null">tenant_type,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tenantKey != null and tenantKey != ''">#{tenantKey},</if>
            <if test="tenantSn != null">#{tenantSn},</if>
            <if test="tenantSecret != null and tenantSecret != ''">#{tenantSecret},</if>
            <if test="tenantStatus != null">#{tenantStatus},</if>
            <if test="tenantType != null">#{tenantType},</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>
        </trim>
    </insert>

    <update id="updateTenantSecretKey" parameterType="TenantSecretKey">
        update ff_tenant_secret_key
        <trim prefix="SET" suffixOverrides=",">
            <if test="tenantKey != null and tenantKey != ''">tenant_key = #{tenantKey},</if>
            <if test="tenantSn != null">tenant_sn = #{tenantSn},</if>
            <if test="tenantSecret != null and tenantSecret != ''">tenant_secret = #{tenantSecret},</if>
            <if test="tenantStatus != null">tenant_status = #{tenantStatus},</if>
            <if test="tenantType != null">tenant_type = #{tenantType},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTenantSecretKeyById" parameterType="Long">
        delete from ff_tenant_secret_key where id = #{id}
    </delete>

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