<?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="kr.co.jinwoosi.clfd.clfd.dgns.mapper.DgnsListMapper">
    <insert id="insert" parameterType="dgnsList">
        <selectKey keyProperty="dgnsListId" resultType="java.lang.Long" order="BEFORE" >
            select DGNS_LIST_ID_SEQ.NEXTVAL from DUAL
        </selectKey>
        INSERT INTO CF_DGNS_LIST (
            DGNS_LIST_ID, DGNS_ASK_ID, DGNS_ANS_ID, DGNS_ID,
            REG_ID, REG_DT, REC_ST
        ) VALUES (
            #{dgnsListId}, #{dgnsAskId}, #{dgnsAnsId}, #{dgnsId},
            #{regId}, SYSDATE, 'Y'
        )
    </insert>

    <select id="select" parameterType="dgnsListSearch" resultType="dgnsList">
        SELECT *
        FROM CF_DGNS_LIST
        WHERE 1 = 1
        <if test="dgnsListId != null" > AND DGNS_LIST_ID = #{dgnsListId} </if>
        <if test="dgnsId != null" > AND DGNS_ID = #{dgnsId} </if>
        <if test="!empty(recSt)" > AND REC_ST = #{recSt} </if>
    </select>
    
    <select id="selectList" parameterType="dgnsListSearch" resultType="dgnsList">
        SELECT *
        FROM (
            SELECT ROWNUM RNUM , LIST.*
            FROM (
                SELECT *
                FROM CF_DGNS_LIST
                WHERE 1 = 1
                    <if test="recSt != null" > AND REC_ST = #{recSt} </if>
                    <if test="dgnsId != null" > AND DGNS_ID = #{dgnsId} </if>
                    <if test="dgnsListId != null" > AND DGNS_LIST_ID = #{dgnsListId} </if>
                <if test="!empty(sort) and !empty(sortOrd)">
                ORDER BY ${sort} ${sortOrd}
                </if>
            ) LIST
        )
        <if test="pagingYn == true" >
            <![CDATA[
			WHERE RNUM > #{start} AND RNUM <= #{start} + #{length}
		    ]]>
        </if>
    </select>

    <select id="count" parameterType="dgnsListSearch" resultType="java.lang.Integer">
        select
            COUNT(*)
        from
            CF_DGNS_LIST
        WHERE 1 = 1
        <if test="recSt != null" > AND REC_ST = #{recSt} </if>
        <if test="dgnsId != null" > AND DGNS_ID = #{dgnsId} </if>
        <if test="dgnsListId != null" > AND DGNS_LIST_ID = #{dgnsListId} </if>
    </select>
</mapper>
