<?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="cokr.xit.fims.cvlc.dao.SoCvlcptIndviDmndMapper">

<select id="selectDmndDataList" parameterType="cokr.xit.fims.crdn.CrdnQuery" resultType="dataobject">
/* 새올요청자료 목록 조회(soCvlcptIndviDmndMapper.selectDmndDataList) */
<include refid="utility.paging-prefix"/>
SELECT SA.INDIV_ID           <!-- 개별 ID -->
     , SA.DMND_YMD           <!-- 요청일자 -->
     , SA.RCPT_YMD           <!-- 접수 일자 -->
     , SA.PST_NO             <!-- 게시물 번호  -->
     , SA.CRDN_ID            <!-- 단속 ID -->
     , SA.STTS_CD            <!-- 상태 코드 -->
     , GET_CODE_NM('FIM063', SA.STTS_CD) AS STTS_NM            <!-- 상태명 -->
     , SA.RSPNS_DT           <!-- 응답 일시 -->
     , (SELECT USER_NM
          FROM TB_USER
         WHERE USER_ID = SA.RGTR
       ) AS RGTR             <!-- 요청자 -->
  FROM TB_SAEOL_CVLCPT_INDIV_DMND SA
 WHERE SA.DEL_YN = 'N'
   AND SA.SGG_CD = #{sggCd}
   AND SA.TASK_SE_CD = #{taskSeCd}
<if test="schDmndYmdFrom != null or schDmndYmdTo != null">
	<if test="schDmndYmdFrom != null">AND SA.DMND_YMD <![CDATA[ >= ]]> #{schDmndYmdFrom} </if>
	<if test="schDmndYmdTo != null">AND SA.DMND_YMD <![CDATA[ <= ]]> #{schDmndYmdTo} </if>
</if>
<include refid="utility.orderBy" />
<include refid="utility.paging-suffix"/>
</select>

<insert id="insertDmndDataInfo" parameterType="cokr.xit.fims.cvlc.CrdnCvlcpt">
<selectKey resultType="string" keyProperty="indivId" keyColumn="NEW_ID" order="BEFORE">
	<include refid="numbering.keyByYear">
		<property name="TABLE_NAME" value="TB_SAEOL_CVLCPT_INDIV_DMND" />
		<property name="TABLE_KEY" value="INDIV_ID" />
		<property name="pad" value="30" />
	</include>
</selectKey>
/* 새올요청자료 등록(soCvlcptIndviDmndMapper.insertDmndDataInfo) */
INSERT
  INTO TB_SAEOL_CVLCPT_INDIV_DMND (
    INDIV_ID
  , SGG_CD
  , TASK_SE_CD
  , RCPT_YMD
  , PST_NO
  , DMND_YMD
  , STTS_CD
  , DEL_YN
  , REG_DT
  , RGTR
  , MDFCN_DT
  , MDFR
  )
  VALUES (
    #{indivId}
  , #{sggCd}
  , #{taskSeCd}
  , REPLACE(#{rcptYmd},'-','')
  , LPAD(#{pstNo}, 6, '0')
  , <include refid="utility.today" />
  , '0'
  , 'N'
  , <include refid="utility.now" />
  , #{modifiedBy}
  , <include refid="utility.now" />
  , #{modifiedBy}
  )
</insert>

<update id="deleteDmndDataInfo" parameterType="map">
/* 새올요청자료 삭제(soCvlcptIndviDmndMapper.deleteDmndDataInfo) */
UPDATE TB_SAEOL_CVLCPT_INDIV_DMND
   SET DEL_YN = 'Y'
     , DEL_DT = <include refid="utility.now" /> /* 삭제일시 */
     , DLTR = #{removedBy}                   /* 삭제자 */
 WHERE INDIV_ID IN (
 <foreach collection="indivIds" item="indivId" separator=",">#{indivId}</foreach>
 )
</update>

</mapper>