<?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.StandardDocumentMapper">

    <resultMap type="StandardDocument" id="StandardDocumentResult">
        <result property="objId" column="obj_id" />
        <result property="documentCode" column="document_code" />
        <result property="documentName" column="document_name" />
        <result property="documentType" column="document_type" />
        <result property="productCode" column="product_code" />
        <result property="productName" column="product_name" />
        <result property="versionNo" column="version_no" />
        <result property="documentPath" column="document_path" />
        <result property="documentSize" column="document_size" />
        <result property="uploader" column="uploader" />
        <result property="uploadTime" column="upload_time" />
        <result property="effectiveDate" column="effective_date" />
        <result property="expiryDate" column="expiry_date" />
        <result property="status" column="status" />
        <result property="remark" column="remark" />
        <result property="createdTime" column="created_time" />
        <result property="updatedTime" column="updated_time" />
    </resultMap>

    <sql id="selectStandardDocumentVo">
        select "obj_id", "document_code", "document_name", "document_type", "product_code", "product_name",
               "version_no", "document_path", "document_size", "uploader", "upload_time", "effective_date",
               "expiry_date", "status", "remark", "created_time", "updated_time"
        from "standard_document"
    </sql>

    <select id="selectStandardDocumentList" parameterType="StandardDocument" resultMap="StandardDocumentResult">
        <include refid="selectStandardDocumentVo"/>
        <where>
            <if test="documentCode != null and documentCode != ''"> and "document_code" = #{documentCode}</if>
            <if test="documentName != null and documentName != ''"> and "document_name" like concat(concat('%', #{documentName}), '%')</if>
            <if test="documentType != null and documentType != ''"> and "document_type" = #{documentType}</if>
            <if test="productCode != null and productCode != ''"> and "product_code" = #{productCode}</if>
            <if test="productName != null and productName != ''"> and "product_name" like concat(concat('%', #{productName}), '%')</if>
            <if test="status != null and status != ''"> and "status" = #{status}</if>
        </where>
        order by obj_id desc
    </select>

    <select id="selectStandardDocumentByObjId" parameterType="Long" resultMap="StandardDocumentResult">
        <include refid="selectStandardDocumentVo"/>
        where "obj_id" = #{objId}
    </select>

    <insert id="insertStandardDocument" parameterType="StandardDocument">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_standard_document.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into "standard_document"
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">"obj_id",</if>
            <if test="documentCode != null">"document_code",</if>
            <if test="documentName != null">"document_name",</if>
            <if test="documentType != null">"document_type",</if>
            <if test="productCode != null">"product_code",</if>
            <if test="productName != null">"product_name",</if>
            <if test="versionNo != null">"version_no",</if>
            <if test="documentPath != null">"document_path",</if>
            <if test="documentSize != null">"document_size",</if>
            <if test="uploader != null">"uploader",</if>
            <if test="uploadTime != null">"upload_time",</if>
            <if test="effectiveDate != null">"effective_date",</if>
            <if test="expiryDate != null">"expiry_date",</if>
            <if test="status != null">"status",</if>
            <if test="remark != null">"remark",</if>
            <if test="createdTime != null">"created_time",</if>
            <if test="updatedTime != null">"updated_time",</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="documentCode != null">#{documentCode},</if>
            <if test="documentName != null">#{documentName},</if>
            <if test="documentType != null">#{documentType},</if>
            <if test="productCode != null">#{productCode},</if>
            <if test="productName != null">#{productName},</if>
            <if test="versionNo != null">#{versionNo},</if>
            <if test="documentPath != null">#{documentPath},</if>
            <if test="documentSize != null">#{documentSize},</if>
            <if test="uploader != null">#{uploader},</if>
            <if test="uploadTime != null">#{uploadTime},</if>
            <if test="effectiveDate != null">#{effectiveDate},</if>
            <if test="expiryDate != null">#{expiryDate},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
        </trim>
    </insert>

    <update id="updateStandardDocument" parameterType="StandardDocument">
        update "standard_document"
        <trim prefix="SET" suffixOverrides=",">
            <if test="documentCode != null">"document_code" = #{documentCode},</if>
            <if test="documentName != null">"document_name" = #{documentName},</if>
            <if test="documentType != null">"document_type" = #{documentType},</if>
            <if test="productCode != null">"product_code" = #{productCode},</if>
            <if test="productName != null">"product_name" = #{productName},</if>
            <if test="versionNo != null">"version_no" = #{versionNo},</if>
            <if test="documentPath != null">"document_path" = #{documentPath},</if>
            <if test="documentSize != null">"document_size" = #{documentSize},</if>
            <if test="uploader != null">"uploader" = #{uploader},</if>
            <if test="uploadTime != null">"upload_time" = #{uploadTime},</if>
            <if test="effectiveDate != null">"effective_date" = #{effectiveDate},</if>
            <if test="expiryDate != null">"expiry_date" = #{expiryDate},</if>
            <if test="status != null">"status" = #{status},</if>
            <if test="remark != null">"remark" = #{remark},</if>
            <if test="updatedTime != null">"updated_time" = #{updatedTime},</if>
        </trim>
        where "obj_id" = #{objId}
    </update>

    <delete id="deleteStandardDocumentByObjId" parameterType="Long">
        delete from "standard_document" where "obj_id" = #{objId}
    </delete>

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