<?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.ygtx.gxt.mapper.GxtWorkOrderAttachmentMapper">

    <resultMap type="GxtWorkOrderAttachment" id="GxtWorkOrderAttachmentResult">
        <result property="id"    column="id"    />
        <result property="workOrderId"    column="work_order_id"    />
        <result property="workOrderCode"    column="work_order_code"    />
        <result property="fileName"    column="file_name"    />
        <result property="filePath"    column="file_path"    />
        <result property="fileSize"    column="file_size"    />
        <result property="fileType"    column="file_type"    />
        <result property="uploadTime"    column="upload_time"    />
        <result property="uploadUserId"    column="upload_user_id"    />
        <result property="uploadUserName"    column="upload_user_name"    />
        <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"    />
    </resultMap>

    <sql id="selectGxtWorkOrderAttachmentVo">
        select id, work_order_id, work_order_code, file_name, file_path, file_size, file_type, 
               upload_time, upload_user_id, upload_user_name, create_by, create_time, update_by, 
               update_time, remark
        from gxt_work_order_attachment
    </sql>

    <select id="selectGxtWorkOrderAttachmentById" parameterType="Long" resultMap="GxtWorkOrderAttachmentResult">
        <include refid="selectGxtWorkOrderAttachmentVo"/>
        where id = #{id}
    </select>

    <select id="selectGxtWorkOrderAttachmentByOrderId" parameterType="Long" resultMap="GxtWorkOrderAttachmentResult">
        <include refid="selectGxtWorkOrderAttachmentVo"/>
        where work_order_id = #{id}
        order by upload_time desc
    </select>

    <insert id="insertGxtWorkOrderAttachment" parameterType="GxtWorkOrderAttachment" useGeneratedKeys="true" keyProperty="id">
        insert into gxt_work_order_attachment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workOrderId != null">work_order_id,</if>
            <if test="workOrderCode != null">work_order_code,</if>
            <if test="fileName != null">file_name,</if>
            <if test="filePath != null">file_path,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="fileType != null">file_type,</if>
            <if test="uploadTime != null">upload_time,</if>
            <if test="uploadUserId != null">upload_user_id,</if>
            <if test="uploadUserName != null">upload_user_name,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workOrderId != null">#{workOrderId},</if>
            <if test="workOrderCode != null">#{workOrderCode},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="filePath != null">#{filePath},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="uploadTime != null">#{uploadTime},</if>
            <if test="uploadUserId != null">#{uploadUserId},</if>
            <if test="uploadUserName != null">#{uploadUserName},</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>
         </trim>
    </insert>

    <delete id="deleteGxtWorkOrderAttachmentById" parameterType="Long">
        delete from gxt_work_order_attachment where id = #{id}
    </delete>

    <delete id="deleteGxtWorkOrderAttachmentByOrderId" parameterType="Long">
        delete from gxt_work_order_attachment where work_order_id = #{id}
    </delete>

</mapper>
