<?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.sundot.airport.system.mapper.SysDynamicSqlMapper">

    <resultMap type="SysDynamicSql" id="SysDynamicSqlResult">
        <result property="id" column="id"/>
        <result property="sqlKey" column="sql_key"/>
        <result property="sqlContent" column="sql_content"/>
        <result property="description" column="description"/>
        <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"/>
        <result property="paramsConfig" column="params_config"/>
    </resultMap>

    <sql id="selectSysDynamicSqlVo">
        select id,
               sql_key,
               sql_content,
               description,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               params_config
        from sys_dynamic_sql
    </sql>

    <select id="selectSysDynamicSqlList" parameterType="SysDynamicSql" resultMap="SysDynamicSqlResult">
        <include refid="selectSysDynamicSqlVo"/>
        <where>
            <if test="sqlKey != null  and sqlKey != ''">and sql_key = #{sqlKey}</if>
            <if test="sqlContent != null  and sqlContent != ''">and sql_content = #{sqlContent}</if>
            <if test="description != null  and description != ''">and description = #{description}</if>
            <if test="paramsConfig != null  and paramsConfig != ''">and params_config = #{paramsConfig}</if>
        </where>
    </select>

    <select id="selectSysDynamicSqlById" parameterType="Long" resultMap="SysDynamicSqlResult">
        <include refid="selectSysDynamicSqlVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysDynamicSql" parameterType="SysDynamicSql" useGeneratedKeys="true" keyProperty="id">
        insert into sys_dynamic_sql
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sqlKey != null and sqlKey != ''">sql_key,</if>
            <if test="sqlContent != null and sqlContent != ''">sql_content,</if>
            <if test="description != null">description,</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>
            <if test="paramsConfig != null">params_config,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sqlKey != null and sqlKey != ''">#{sqlKey},</if>
            <if test="sqlContent != null and sqlContent != ''">#{sqlContent},</if>
            <if test="description != null">#{description},</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>
            <if test="paramsConfig != null">#{paramsConfig},</if>
        </trim>
    </insert>

    <update id="updateSysDynamicSql" parameterType="SysDynamicSql">
        update sys_dynamic_sql
        <trim prefix="SET" suffixOverrides=",">
            <if test="sqlKey != null and sqlKey != ''">sql_key = #{sqlKey},</if>
            <if test="sqlContent != null and sqlContent != ''">sql_content = #{sqlContent},</if>
            <if test="description != null">description = #{description},</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>
            <if test="paramsConfig != null">params_config = #{paramsConfig},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysDynamicSqlById" parameterType="Long">
        delete
        from sys_dynamic_sql
        where id = #{id}
    </delete>

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

    <select id="selectBySqlKey" parameterType="String" resultMap="SysDynamicSqlResult">
        <include refid="selectSysDynamicSqlVo"/>
        <where>
            <if test="sqlKey != null  and sqlKey != ''">and sql_key = #{sqlKey}</if>
        </where>
        limit 1
    </select>
</mapper>