<?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.eqplc.dao.EqplcMapper">

	<select id="selectList" parameterType="cokr.xit.fims.eqplc.EqplcQuery" resultType="dataObject">
		/* 단속장비 정보 목록 조회(eqplcMapper.selectList) */
		SELECT A.*, 
		       CASE DRCTN WHEN '0' THEN '상행' WHEN '1' THEN '하행' ELSE NULL END DRCTN_STR,
		       (SELECT USER_NM FROM TB_USER X WHERE X.USER_ID = A.RGTR) AS RGTR_NM
		  FROM TB_EQP_PLC A
		 WHERE USE_YN = 'Y'
		<if test="schTypeTxt != null and schTypeTxt != ''">
			<if test="schType == 'placeName'">AND PLC_NM like concat('%',#{schTypeTxt},'%')</if>
			<if test="schType == 'eqplcCode'">AND EQP_CD = #{schTypeTxt}</if>		
		</if>		
	</select>
	
	<select id="selectOne" parameterType="string" resultType="dataObject">
		/* 단속장비 정보 상세 조회(eqplcMapper.selectOne) */
		SELECT A.*
		  FROM TB_EQP_PLC A
		 WHERE USE_YN = 'Y'
		   AND EQPLC_CD = #{schEqplcCd}		
	</select>	
	
	<select id="selectNextNo" parameterType="cokr.xit.fims.eqplc.Eqplc" resultType="string">
		SELECT LPAD(IFNULL(MAX(EQPLC_CD), 0) + 1, 5, '0') AS NEXT_NO
		  FROM TB_EQP_PLC
	</select>	
	
    <insert id="insert" parameterType="cokr.xit.fims.eqplc.Eqplc">
		INSERT INTO TB_EQP_PLC (
			  EQPLC_CD
			, CMPNY_CD
			, EQP_CD
			, PLC_NM
			, STDG_NM
			, ROAD_NM
			, PLC
			, LANE_NO
			, DRCTN
			, ETC_INFO
			, REG_DT
			, RGTR
			, USE_YN
		) VALUES (
			  #{eqplcCd}
			, #{cmpnyCd}
			, #{eqpCd}
			, #{plcNm}
			, #{stdgNm}
			, #{roadNm}
			, #{plc}
			, #{laneNo}
			, #{drctn}
			, #{etcInfo}
			, <include refid="utility.now" />
			, #{createdBy}
			, 'Y'
		)
    </insert>
    
    <update id="update" parameterType="cokr.xit.fims.eqplc.Eqplc">
        UPDATE TB_EQP_PLC
		<set>
			<if test="cmpnyCd != null">	CMPNY_CD	= #{cmpnyCd},	</if>
			<if test="eqpCd != null">	EQP_CD		= #{eqpCd},		</if>
			<if test="plcNm != null">	PLC_NM		= #{plcNm},		</if>
			<if test="stdgNm != null">	STDG_NM		= #{stdgNm},	</if>
			<if test="roadNm != null">	ROAD_NM		= #{roadNm},	</if>
			<if test="plc != null">		PLC			= #{plc},		</if>
			<if test="laneNo != null">	LANE_NO		= #{laneNo},	</if>
			<if test="drctn != null">	DRCTN		= #{drctn},		</if>
			<if test="etcInfo != null">	ETC_INFO	= #{etcInfo},	</if>
			<if test="useYN != null">	USE_YN		= #{useYN},		</if>			
		</set>
		 WHERE EQPLC_CD = #{eqplcCd}     
    </update>    	

</mapper>