<?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.ximai.mes.pro.mapper.productionSolution.ProProductionSolutionProcessDrawingMapper">

    <resultMap type="ProProductionSolutionProcessDrawing" id="ProProductionSolutionProcessDrawingResult">
            <result property="productionSolutionProcessFileId"    column="production_solution_process_file_id"    />
            <result property="productionSolutionProcessId"    column="production_solution_process_id"    />
            <result property="productionSolutionId"    column="production_solution_id"    />
            <result property="filePath"    column="file_path"    />
            <result property="fileSize"    column="file_size"    />
            <result property="remark"    column="remark"    />
            <result property="fileOriginalName"    column="file_original_name"    />
    </resultMap>

    <resultMap type="com.ximai.mes.pro.dto.productionSolution.ProProductionSolutionProcessDrawingDto" id="ProProductionSolutionProcessDrawingResult2">
            <result property="productionSolutionProcessFileId"    column="production_solution_process_file_id"    />
            <result property="productionSolutionProcessId"    column="production_solution_process_id"    />
            <result property="productionSolutionId"    column="production_solution_id"    />
            <result property="filePath"    column="file_path"    />
            <result property="fileSize"    column="file_size"    />
            <result property="remark"    column="remark"    />
            <result property="fileOriginalName"    column="file_original_name"    />
    </resultMap>

    <sql id="selectProProductionSolutionProcessDrawingVo">
        select production_solution_process_file_id, production_solution_process_id, production_solution_id, file_path, file_size, remark, file_original_name from pro_production_solution_process_drawing
    </sql>

    <select id="selectProProductionSolutionProcessDrawingList" parameterType="ProProductionSolutionProcessDrawing" resultMap="ProProductionSolutionProcessDrawingResult2">
        <include refid="selectProProductionSolutionProcessDrawingVo"/>
        <where>  
            <if test="productionSolutionProcessId != null "> and production_solution_process_id = #{productionSolutionProcessId}</if>
            <if test="productionSolutionId != null "> and production_solution_id = #{productionSolutionId}</if>
            <if test="filePath != null  and filePath != ''"> and file_path = #{filePath}</if>
            <if test="fileOriginalName != null  and fileOriginalName != ''"> and file_original_name like concat('%', #{fileOriginalName}, '%')</if>
        </where>
    </select>
    
    <select id="selectProProductionSolutionProcessDrawingByProductionSolutionProcessFileId" parameterType="Long" resultMap="ProProductionSolutionProcessDrawingResult2">
        <include refid="selectProProductionSolutionProcessDrawingVo"/>
        where production_solution_process_file_id = #{productionSolutionProcessFileId}
    </select>
        
    <insert id="insertProProductionSolutionProcessDrawing" parameterType="ProProductionSolutionProcessDrawing" useGeneratedKeys="true" keyProperty="productionSolutionProcessFileId">
        insert into pro_production_solution_process_drawing
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productionSolutionProcessId != null">production_solution_process_id,</if>
            <if test="productionSolutionId != null">production_solution_id,</if>
            <if test="filePath != null">file_path,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="remark != null">remark,</if>
            <if test="fileOriginalName != null">file_original_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productionSolutionProcessId != null">#{productionSolutionProcessId},</if>
            <if test="productionSolutionId != null">#{productionSolutionId},</if>
            <if test="filePath != null">#{filePath},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="remark != null">#{remark},</if>
            <if test="fileOriginalName != null">#{fileOriginalName},</if>
         </trim>
    </insert>

    <update id="updateProProductionSolutionProcessDrawing" parameterType="ProProductionSolutionProcessDrawing">
        update pro_production_solution_process_drawing
        <trim prefix="SET" suffixOverrides=",">
            <if test="productionSolutionProcessId != null">production_solution_process_id = #{productionSolutionProcessId},</if>
            <if test="productionSolutionId != null">production_solution_id = #{productionSolutionId},</if>
            <if test="filePath != null">file_path = #{filePath},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="fileOriginalName != null">file_original_name = #{fileOriginalName},</if>
        </trim>
        where production_solution_process_file_id = #{productionSolutionProcessFileId}
    </update>

    <delete id="deleteProProductionSolutionProcessDrawingByProductionSolutionProcessFileId" parameterType="Long">
        delete from pro_production_solution_process_drawing where production_solution_process_file_id = #{productionSolutionProcessFileId}
    </delete>

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