<?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.shzg.project.worn.mapper.WornTechnicalAppraisalFileMapper">
    
    <resultMap type="WornTechnicalAppraisalFile" id="WornTechnicalAppraisalFileResult">
        <result property="id"    column="id"    />
        <result property="appraisalId"    column="appraisal_id"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="fileType"    column="file_type"    />
        <result property="sortNum"    column="sort_num"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="isDelete"    column="is_delete"    />
    </resultMap>

    <sql id="selectWornTechnicalAppraisalFileVo">
        select id, appraisal_id, file_name, file_url, file_type, sort_num, remark, create_by, create_time, is_delete from worn_technical_appraisal_file
    </sql>

    <select id="selectWornTechnicalAppraisalFileList" parameterType="WornTechnicalAppraisalFile" resultMap="WornTechnicalAppraisalFileResult">
        <include refid="selectWornTechnicalAppraisalFileVo"/>
        <where>  
            <if test="appraisalId != null "> and appraisal_id = #{appraisalId}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="fileType != null  and fileType != ''"> and file_type = #{fileType}</if>
            <if test="sortNum != null "> and sort_num = #{sortNum}</if>
            <if test="isDelete != null  and isDelete != ''"> and is_delete = #{isDelete}</if>
        </where>
    </select>
    
    <select id="selectWornTechnicalAppraisalFileById" parameterType="Long" resultMap="WornTechnicalAppraisalFileResult">
        <include refid="selectWornTechnicalAppraisalFileVo"/>
        where id = #{id}
    </select>

    <insert id="insertWornTechnicalAppraisalFile" parameterType="WornTechnicalAppraisalFile" useGeneratedKeys="true" keyProperty="id">
        insert into worn_technical_appraisal_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appraisalId != null">appraisal_id,</if>
            <if test="fileName != null and fileName != ''">file_name,</if>
            <if test="fileUrl != null and fileUrl != ''">file_url,</if>
            <if test="fileType != null and fileType != ''">file_type,</if>
            <if test="sortNum != null">sort_num,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isDelete != null and isDelete != ''">is_delete,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="appraisalId != null">#{appraisalId},</if>
            <if test="fileName != null and fileName != ''">#{fileName},</if>
            <if test="fileUrl != null and fileUrl != ''">#{fileUrl},</if>
            <if test="fileType != null and fileType != ''">#{fileType},</if>
            <if test="sortNum != null">#{sortNum},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isDelete != null and isDelete != ''">#{isDelete},</if>
        </trim>
    </insert>

    <update id="updateWornTechnicalAppraisalFile" parameterType="WornTechnicalAppraisalFile">
        update worn_technical_appraisal_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="appraisalId != null">appraisal_id = #{appraisalId},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="fileType != null">file_type = #{fileType},</if>
            <if test="sortNum != null">sort_num = #{sortNum},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWornTechnicalAppraisalFileById" parameterType="Long">
        delete from worn_technical_appraisal_file where id = #{id}
    </delete>

    <delete id="deleteWornTechnicalAppraisalFileByIds" parameterType="String">
        delete from worn_technical_appraisal_file where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectWornTechnicalAppraisalFileByAppraisalId"
            parameterType="java.lang.Long"
            resultType="com.shzg.project.worn.domain.WornTechnicalAppraisalFile">

        SELECT
            id,
            appraisal_id,
            file_name,
            file_url,
            file_type,
            sort_num,
            remark,
            create_by,
            create_time,
            is_delete
        FROM worn_technical_appraisal_file
        WHERE appraisal_id = #{appraisalId}
          AND (is_delete = '0' OR is_delete IS NULL)
        ORDER BY sort_num ASC, id ASC

    </select>
</mapper>