<?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.aucma.base.mapper.ProcessDocumentMapper">

    <resultMap type="ProcessDocument" id="ProcessDocumentResult">
        <result property="docId" column="doc_id"/>
        <result property="docCode" column="doc_code"/>
        <result property="docName" column="doc_name"/>
        <result property="docType" column="doc_type"/>
        <result property="productCode" column="product_code"/>
        <result property="productName" column="product_name"/>
        <result property="deviceCode" column="device_code"/>
        <result property="deviceName" column="device_name"/>
        <result property="moldCode" column="mold_code"/>
        <result property="moldName" column="mold_name"/>
        <result property="docVersion" column="doc_version"/>
        <result property="filePath" column="file_path"/>
        <result property="fileName" column="file_name"/>
        <result property="fileSize" column="file_size"/>
        <result property="docStatus" column="doc_status"/>
        <result property="isFlag" column="is_flag"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectProcessDocumentVo">
        select doc_id, doc_code, doc_name, doc_type, product_code, product_name, device_code, device_name, 
               mold_code, mold_name, doc_version, file_path, file_name, file_size, doc_status, is_flag, 
               remark, create_by, create_time, update_by, update_time
        from process_document
    </sql>

    <select id="selectProcessDocumentList" parameterType="ProcessDocument" resultMap="ProcessDocumentResult">
        <include refid="selectProcessDocumentVo"/>
        <where>
            <if test="docCode != null and docCode != ''">and doc_code like concat(concat('%', #{docCode}), '%')</if>
            <if test="docName != null and docName != ''">and doc_name like concat(concat('%', #{docName}), '%')</if>
            <if test="docType != null and docType != ''">and doc_type = #{docType}</if>
            <if test="productCode != null and productCode != ''">and product_code = #{productCode}</if>
            <if test="deviceCode != null and deviceCode != ''">and device_code = #{deviceCode}</if>
            <if test="moldCode != null and moldCode != ''">and mold_code = #{moldCode}</if>
            <if test="docStatus != null and docStatus != ''">and doc_status = #{docStatus}</if>
            <if test="isFlag != null and isFlag != ''">and is_flag = #{isFlag}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectProcessDocumentByDocId" parameterType="Long" resultMap="ProcessDocumentResult">
        <include refid="selectProcessDocumentVo"/>
        where doc_id = #{docId}
    </select>

    <insert id="insertProcessDocument" parameterType="ProcessDocument">
        <selectKey keyProperty="docId" resultType="long" order="BEFORE">
            SELECT PROCESS_DOCUMENT_SEQ.NEXTVAL as docId FROM DUAL
        </selectKey>
        insert into process_document
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="docId != null">doc_id,</if>
            <if test="docCode != null and docCode != ''">doc_code,</if>
            <if test="docName != null and docName != ''">doc_name,</if>
            <if test="docType != null">doc_type,</if>
            <if test="productCode != null">product_code,</if>
            <if test="productName != null">product_name,</if>
            <if test="deviceCode != null">device_code,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="moldCode != null">mold_code,</if>
            <if test="moldName != null">mold_name,</if>
            <if test="docVersion != null">doc_version,</if>
            <if test="filePath != null">file_path,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="docStatus != null">doc_status,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="remark != null">remark,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="docId != null">#{docId},</if>
            <if test="docCode != null and docCode != ''">#{docCode},</if>
            <if test="docName != null and docName != ''">#{docName},</if>
            <if test="docType != null">#{docType},</if>
            <if test="productCode != null">#{productCode},</if>
            <if test="productName != null">#{productName},</if>
            <if test="deviceCode != null">#{deviceCode},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="moldCode != null">#{moldCode},</if>
            <if test="moldName != null">#{moldName},</if>
            <if test="docVersion != null">#{docVersion},</if>
            <if test="filePath != null">#{filePath},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="docStatus != null">#{docStatus},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="remark != null">#{remark},</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>
        </trim>
    </insert>

    <update id="updateProcessDocument" parameterType="ProcessDocument">
        update process_document
        <trim prefix="SET" suffixOverrides=",">
            <if test="docCode != null and docCode != ''">doc_code = #{docCode},</if>
            <if test="docName != null and docName != ''">doc_name = #{docName},</if>
            <if test="docType != null">doc_type = #{docType},</if>
            <if test="productCode != null">product_code = #{productCode},</if>
            <if test="productName != null">product_name = #{productName},</if>
            <if test="deviceCode != null">device_code = #{deviceCode},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="moldCode != null">mold_code = #{moldCode},</if>
            <if test="moldName != null">mold_name = #{moldName},</if>
            <if test="docVersion != null">doc_version = #{docVersion},</if>
            <if test="filePath != null">file_path = #{filePath},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="docStatus != null">doc_status = #{docStatus},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where doc_id = #{docId}
    </update>

    <delete id="deleteProcessDocumentByDocId" parameterType="Long">
        delete from process_document where doc_id = #{docId}
    </delete>

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