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

    <resultMap type="BaseAttachment" id="BaseAttachmentResult">
        <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="sourceType" column="source_type"/>
        <result property="sourceTypeName" column="source_type_name"/>
        <result property="sourceId" column="source_id"/>
        <result property="sourceName" column="source_name"/>
        <result property="id" column="id"/>
        <result property="attachmentId" column="attachment_id"/>
        <result property="attachmentName" column="attachment_name"/>
        <result property="attachmentUrl" column="attachment_url"/>
    </resultMap>

    <sql id="selectBaseAttachmentVo">
        select tenant_id,
               revision,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               source_type,
               source_type_name,
               source_id,
               source_name,
               id,
               attachment_id,
               attachment_name,
               attachment_url
        from base_attachment
    </sql>

    <select id="selectBaseAttachmentList" parameterType="BaseAttachment" resultMap="BaseAttachmentResult">
        <include refid="selectBaseAttachmentVo"/>
        <where>
            <if test="tenantId != null  and tenantId != ''">and tenant_id = #{tenantId}</if>
            <if test="revision != null ">and revision = #{revision}</if>
            <if test="sourceType != null  and sourceType != ''">and source_type = #{sourceType}</if>
            <if test="sourceTypeName != null  and sourceTypeName != ''">and source_type_name like concat('%',
                #{sourceTypeName}, '%')
            </if>
            <if test="sourceId != null ">and source_id = #{sourceId}</if>
            <if test="sourceName != null  and sourceName != ''">and source_name like concat('%', #{sourceName}, '%')
            </if>
            <if test="attachmentId != null  and attachmentId != ''">and attachment_id = #{attachmentId}</if>
            <if test="attachmentName != null  and attachmentName != ''">and attachment_name like concat('%',
                #{attachmentName}, '%')
            </if>
            <if test="attachmentUrl != null  and attachmentUrl != ''">and attachment_url = #{attachmentUrl}</if>
        </where>
    </select>

    <select id="selectBaseAttachmentById" parameterType="Long" resultMap="BaseAttachmentResult">
        <include refid="selectBaseAttachmentVo"/>
        where id = #{id}
    </select>

    <insert id="insertBaseAttachment" parameterType="BaseAttachment" useGeneratedKeys="true" keyProperty="id">
        insert into base_attachment
        <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="sourceType != null and sourceType != ''">source_type,</if>
            <if test="sourceTypeName != null and sourceTypeName != ''">source_type_name,</if>
            <if test="sourceId != null">source_id,</if>
            <if test="sourceName != null">source_name,</if>
            <if test="attachmentId != null and attachmentId != ''">attachment_id,</if>
            <if test="attachmentName != null and attachmentName != ''">attachment_name,</if>
            <if test="attachmentUrl != null and attachmentUrl != ''">attachment_url,</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="sourceType != null and sourceType != ''">#{sourceType},</if>
            <if test="sourceTypeName != null and sourceTypeName != ''">#{sourceTypeName},</if>
            <if test="sourceId != null">#{sourceId},</if>
            <if test="sourceName != null">#{sourceName},</if>
            <if test="attachmentId != null and attachmentId != ''">#{attachmentId},</if>
            <if test="attachmentName != null and attachmentName != ''">#{attachmentName},</if>
            <if test="attachmentUrl != null and attachmentUrl != ''">#{attachmentUrl},</if>
        </trim>
    </insert>

    <update id="updateBaseAttachment" parameterType="BaseAttachment">
        update base_attachment
        <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="sourceType != null and sourceType != ''">source_type = #{sourceType},</if>
            <if test="sourceTypeName != null and sourceTypeName != ''">source_type_name = #{sourceTypeName},</if>
            <if test="sourceId != null">source_id = #{sourceId},</if>
            <if test="sourceName != null">source_name = #{sourceName},</if>
            <if test="attachmentId != null and attachmentId != ''">attachment_id = #{attachmentId},</if>
            <if test="attachmentName != null and attachmentName != ''">attachment_name = #{attachmentName},</if>
            <if test="attachmentUrl != null and attachmentUrl != ''">attachment_url = #{attachmentUrl},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBaseAttachmentById" parameterType="Long">
        delete
        from base_attachment
        where id = #{id}
    </delete>

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