<?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.BaseReadMapper">

    <resultMap type="BaseRead" id="BaseReadResult">
        <result property="tenantId" column="tenant_id"/>
        <result property="revision" column="revision"/>
        <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="type" column="type"/>
        <result property="typeDesc" column="type_desc"/>
        <result property="userId" column="user_id"/>
        <result property="userName" column="user_name"/>
        <result property="id" column="id"/>
        <result property="formId" column="form_id"/>
        <result property="formCode" column="form_code"/>
        <result property="formName" column="form_name"/>
    </resultMap>

    <sql id="selectBaseReadVo">
        select tenant_id,
               revision,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               type,
               type_desc,
               user_id,
               user_name,
               id,
               form_id,
               form_code,
               form_name
        from base_read
    </sql>

    <select id="selectBaseReadList" parameterType="BaseRead" resultMap="BaseReadResult">
        <include refid="selectBaseReadVo"/>
        <where>
            <if test="tenantId != null  and tenantId != ''">and tenant_id = #{tenantId}</if>
            <if test="revision != null ">and revision = #{revision}</if>
            <if test="type != null  and type != ''">and type = #{type}</if>
            <if test="typeDesc != null  and typeDesc != ''">and type_desc = #{typeDesc}</if>
            <if test="userId != null ">and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''">and user_name like concat('%', #{userName}, '%')</if>
            <if test="formId != null ">and form_id = #{formId}</if>
            <if test="formCode != null  and formCode != ''">and form_code = #{formCode}</if>
            <if test="formName != null  and formName != ''">and form_name like concat('%', #{formName}, '%')</if>
        </where>
    </select>

    <select id="selectBaseReadById" parameterType="Long" resultMap="BaseReadResult">
        <include refid="selectBaseReadVo"/>
        where id = #{id}
    </select>

    <insert id="insertBaseRead" parameterType="BaseRead" useGeneratedKeys="true" keyProperty="id">
        insert into base_read
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tenantId != null">tenant_id,</if>
            <if test="revision != null">revision,</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="type != null and type != ''">type,</if>
            <if test="typeDesc != null">type_desc,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="formId != null">form_id,</if>
            <if test="formCode != null">form_code,</if>
            <if test="formName != null">form_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tenantId != null">#{tenantId},</if>
            <if test="revision != null">#{revision},</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="type != null and type != ''">#{type},</if>
            <if test="typeDesc != null">#{typeDesc},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="formId != null">#{formId},</if>
            <if test="formCode != null">#{formCode},</if>
            <if test="formName != null">#{formName},</if>
        </trim>
    </insert>

    <update id="updateBaseRead" parameterType="BaseRead">
        update base_read
        <trim prefix="SET" suffixOverrides=",">
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
            <if test="revision != null">revision = #{revision},</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="type != null and type != ''">type = #{type},</if>
            <if test="typeDesc != null">type_desc = #{typeDesc},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="formId != null">form_id = #{formId},</if>
            <if test="formCode != null">form_code = #{formCode},</if>
            <if test="formName != null">form_name = #{formName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBaseReadById" parameterType="Long">
        delete
        from base_read
        where id = #{id}
    </delete>

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