<?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.srs.dormitory.mapper.DmsOutsideAccommodationAttachmentMapper">
    
    <resultMap type="DmsOutsideAccommodationAttachment" id="DmsOutsideAccommodationAttachmentResult">
        <result property="id"    column="id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="attachmentName"    column="attachment_name"    />
        <result property="attachmentUrl"    column="attachment_url"    />
        <result property="attachmentType"    column="attachment_type"    />
        <result property="fileSize"    column="file_size"    />
        <result property="fileSuffix"    column="file_suffix"    />
        <result property="createTime"    column="create_time"    />
        <result property="processInstanceId"    column="process_instance_id"    />
        <result property="studentName"    column="student_name"    />
        <result property="studentNo"    column="student_no"    />
    </resultMap>

    <sql id="selectDmsOutsideAccommodationAttachmentVo">
        select id, apply_id, attachment_name, attachment_url, attachment_type, file_size, file_suffix, create_time, process_instance_id, student_name, student_no from dms_outside_accommodation_attachment
    </sql>

    <select id="selectDmsOutsideAccommodationAttachmentList" parameterType="DmsOutsideAccommodationAttachment" resultMap="DmsOutsideAccommodationAttachmentResult">
        <include refid="selectDmsOutsideAccommodationAttachmentVo"/>
        <where>  
            <if test="applyId != null "> and apply_id = #{applyId}</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>
            <if test="attachmentType != null "> and attachment_type = #{attachmentType}</if>
            <if test="fileSize != null "> and file_size = #{fileSize}</if>
            <if test="fileSuffix != null  and fileSuffix != ''"> and file_suffix = #{fileSuffix}</if>
            <if test="processInstanceId != null  and processInstanceId != ''"> and process_instance_id = #{processInstanceId}</if>
            <if test="studentName != null  and studentName != ''"> and student_name like concat('%', #{studentName}, '%')</if>
            <if test="studentNo != null  and studentNo != ''"> and student_no = #{studentNo}</if>
        </where>
    </select>
    
    <select id="selectDmsOutsideAccommodationAttachmentById" parameterType="Long" resultMap="DmsOutsideAccommodationAttachmentResult">
        <include refid="selectDmsOutsideAccommodationAttachmentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertDmsOutsideAccommodationAttachment" parameterType="DmsOutsideAccommodationAttachment" useGeneratedKeys="true" keyProperty="id">
        insert into dms_outside_accommodation_attachment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyId != null">apply_id,</if>
            <if test="attachmentName != null and attachmentName != ''">attachment_name,</if>
            <if test="attachmentUrl != null and attachmentUrl != ''">attachment_url,</if>
            <if test="attachmentType != null">attachment_type,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="fileSuffix != null and fileSuffix != ''">file_suffix,</if>
            <if test="createTime != null">create_time,</if>
            <if test="processInstanceId != null">process_instance_id,</if>
            <if test="studentName != null and studentName != ''">student_name,</if>
            <if test="studentNo != null and studentNo != ''">student_no,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyId != null">#{applyId},</if>
            <if test="attachmentName != null and attachmentName != ''">#{attachmentName},</if>
            <if test="attachmentUrl != null and attachmentUrl != ''">#{attachmentUrl},</if>
            <if test="attachmentType != null">#{attachmentType},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="fileSuffix != null and fileSuffix != ''">#{fileSuffix},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="processInstanceId != null">#{processInstanceId},</if>
            <if test="studentName != null and studentName != ''">#{studentName},</if>
            <if test="studentNo != null and studentNo != ''">#{studentNo},</if>
         </trim>
    </insert>

    <update id="updateDmsOutsideAccommodationAttachment" parameterType="DmsOutsideAccommodationAttachment">
        update dms_outside_accommodation_attachment
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="attachmentName != null and attachmentName != ''">attachment_name = #{attachmentName},</if>
            <if test="attachmentUrl != null and attachmentUrl != ''">attachment_url = #{attachmentUrl},</if>
            <if test="attachmentType != null">attachment_type = #{attachmentType},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="fileSuffix != null and fileSuffix != ''">file_suffix = #{fileSuffix},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="processInstanceId != null">process_instance_id = #{processInstanceId},</if>
            <if test="studentName != null and studentName != ''">student_name = #{studentName},</if>
            <if test="studentNo != null and studentNo != ''">student_no = #{studentNo},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDmsOutsideAccommodationAttachmentById" parameterType="Long">
        delete from dms_outside_accommodation_attachment where id = #{id}
    </delete>

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