<?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.oqpo.api.mapper.FileMapper">
    <insert id="insertFile">
        <selectKey keyProperty="fileSeq" resultType="int" order="BEFORE">
            select (ifnull((select max(file.file_seq) from np_file file where file.file_no = #{fileNo}), 0) + 1) as file_seq
        </selectKey>
        insert into np_file (
            file_no
            , file_seq
            , file_path
            , file_type
            , file_nm
            , file_org_nm
            , file_size
            , add_dt
            , add_id
        ) values (
            #{fileNo}
            , #{fileSeq}
            , #{filePath}
            , #{fileType}
            , #{fileNm}
            , #{fileOrgNm}
            , #{fileSize}
            , now()
            , #{addId}
        )
    </insert>

    <delete id="deleteFile">
        delete from np_file
        where file_no = #{fileNo}
        and file_seq = #{fileSeq}
    </delete>

    <select id="selectFile" resultType="com.oqpo.api.entity.oper.FileEntity">
        select /* selectFile */
            file_no
            , file_seq
            , file_path
            , file_type
            , file_nm
            , file_org_nm
            , file_size
        from np_file
        where file_no = #{fileNo}
        and file_seq = #{fileSeq}
    </select>

    <select id="selectFileList" resultType="com.oqpo.api.entity.oper.FileEntity">
        select /* selectFileList */
            file_no
            , file_seq
            , file_path
            , file_type
            , file_nm
            , file_org_nm
            , file_size
        from np_file
        where file_no = #{fileNo}
    </select>
</mapper>
