<?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="go.kr.project.api.mapper.VmisCarBassMatterInqireMapper">

    <!-- 시퀀스로 새로운 ID 생성 -->
    <select id="selectNextCarBassMatterInqireId" resultType="String">
        SELECT CONCAT('CBMI', LPAD(NEXTVAL(seq_car_bass_matter_inqire), 16, '0')) AS id
    </select>

    <!-- 최초 요청 정보 INSERT -->
    <insert id="insertCarBassMatterInqire" parameterType="VmisCarBassMatterInqireVO">
        INSERT INTO tb_car_bass_matter_inqire (
            CAR_BASS_MATTER_INQIRE_ID,
            INFO_SYS_ID,
            INFO_SYS_IP,
            SIGUNGU_CODE,
            CNTC_INFO_CODE,
            CHARGER_ID,
            CHARGER_IP,
            CHARGER_NM,
            DMND_LEVY_STDDE,
            DMND_INQIRE_SE_CODE,
            DMND_VHRNO,
            DMND_VIN,
            REG_DT,
            RGTR
        ) VALUES (
            #{carBassMatterInqireId},
            #{infoSysId},
            #{infoSysIp},
            #{sigunguCode},
            #{cntcInfoCode},
            #{chargerId},
            #{chargerIp},
            #{chargerNm},
            #{dmndLevyStdde},
            #{dmndInqireSeCode},
            #{dmndVhrno},
            #{dmndVin},
            NOW(),
            #{rgtr}
        )
    </insert>

    <!-- 응답 결과 UPDATE -->
    <update id="updateCarBassMatterInqire" parameterType="VmisCarBassMatterInqireVO">
        UPDATE tb_car_bass_matter_inqire
        <set>
            <if test="cntcResultCode != null">CNTC_RESULT_CODE = #{cntcResultCode},</if>
            <if test="cntcResultDtls != null">CNTC_RESULT_DTLS = #{cntcResultDtls},</if>
            <if test="prye != null">PRYE = #{prye},</if>
            <if test="registDe != null">REGIST_DE = #{registDe},</if>
            <if test="ersrRegistSeCode != null">ERSR_REGIST_SE_CODE = #{ersrRegistSeCode},</if>
            <if test="ersrRegistSeNm != null">ERSR_REGIST_SE_NM = #{ersrRegistSeNm},</if>
            <if test="ersrRegistDe != null">ERSR_REGIST_DE = #{ersrRegistDe},</if>
            <if test="registDetailCode != null">REGIST_DETAIL_CODE = #{registDetailCode},</if>
            <if test="dsplvl != null">DSPLVL = #{dsplvl},</if>
            <if test="useStrnghldLegaldongCode != null">USE_STRNGHLD_LEGALDONG_CODE = #{useStrnghldLegaldongCode},</if>
            <if test="useStrnghldAdstrdCode != null">USE_STRNGHLD_ADSTRD_CODE = #{useStrnghldAdstrdCode},</if>
            <if test="useStrnghldMntn != null">USE_STRNGHLD_MNTN = #{useStrnghldMntn},</if>
            <if test="useStrnghldLnbr != null">USE_STRNGHLD_LNBR = #{useStrnghldLnbr},</if>
            <if test="useStrnghldHo != null">USE_STRNGHLD_HO = #{useStrnghldHo},</if>
            <if test="useStrnghldAdresNm != null">USE_STRNGHLD_ADRES_NM = #{useStrnghldAdresNm},</if>
            <if test="useStrnghldRoadNmCode != null">USE_STRNGHLD_ROAD_NM_CODE = #{useStrnghldRoadNmCode},</if>
            <if test="usgsrhldUndgrndBuldSeCode != null">USGSRHLD_UNDGRND_BULD_SE_CODE = #{usgsrhldUndgrndBuldSeCode},</if>
            <if test="useStrnghldBuldMainNo != null">USE_STRNGHLD_BULD_MAIN_NO = #{useStrnghldBuldMainNo},</if>
            <if test="useStrnghldBuldSubNo != null">USE_STRNGHLD_BULD_SUB_NO = #{useStrnghldBuldSubNo},</if>
            <if test="usgsrhldAdresFull != null">USGSRHLD_ADRES_FULL = #{usgsrhldAdresFull},</if>
            <if test="mberSeCode != null">MBER_SE_CODE = #{mberSeCode},</if>
            <if test="mberSeNo != null">MBER_SE_NO = #{mberSeNo},</if>
            <if test="telno != null">TELNO = #{telno},</if>
            <if test="ownerLegaldongCode != null">OWNER_LEGALDONG_CODE = #{ownerLegaldongCode},</if>
            <if test="ownerAdstrdCode != null">OWNER_ADSTRD_CODE = #{ownerAdstrdCode},</if>
            <if test="ownerMntn != null">OWNER_MNTN = #{ownerMntn},</if>
            <if test="ownerLnbr != null">OWNER_LNBR = #{ownerLnbr},</if>
            <if test="ownerHo != null">OWNER_HO = #{ownerHo},</if>
            <if test="ownerAdresNm != null">OWNER_ADRES_NM = #{ownerAdresNm},</if>
            <if test="ownerRoadNmCode != null">OWNER_ROAD_NM_CODE = #{ownerRoadNmCode},</if>
            <if test="ownerUndgrndBuldSeCode != null">OWNER_UNDGRND_BULD_SE_CODE = #{ownerUndgrndBuldSeCode},</if>
            <if test="ownerBuldMainNo != null">OWNER_BULD_MAIN_NO = #{ownerBuldMainNo},</if>
            <if test="ownerBuldSubNo != null">OWNER_BULD_SUB_NO = #{ownerBuldSubNo},</if>
            <if test="ownrWholaddr != null">OWNR_WHOLADDR = #{ownrWholaddr},</if>
            <if test="aftrVhrno != null">AFTR_VHRNO = #{aftrVhrno},</if>
            <if test="useFuelCode != null">USE_FUEL_CODE = #{useFuelCode},</if>
            <if test="prposSeCode != null">PRPOS_SE_CODE = #{prposSeCode},</if>
            <if test="mtrsFomNm != null">MTRS_FOM_NM = #{mtrsFomNm},</if>
            <if test="frntVhrno != null">FRNT_VHRNO = #{frntVhrno},</if>
            <if test="vhrno != null">VHRNO = #{vhrno},</if>
            <if test="vin != null">VIN = #{vin},</if>
            <if test="cnm != null">CNM = #{cnm},</if>
            <if test="vhcleTotWt != null">VHCLE_TOT_WT = #{vhcleTotWt},</if>
            <if test="caagEndde != null">CAAG_ENDDE = #{caagEndde},</if>
            <if test="changeDe != null">CHANGE_DE = #{changeDe},</if>
            <if test="vhctyAsortCode != null">VHCTY_ASORT_CODE = #{vhctyAsortCode},</if>
            <if test="vhctyTyCode != null">VHCTY_TY_CODE = #{vhctyTyCode},</if>
            <if test="vhctySeCode != null">VHCTY_SE_CODE = #{vhctySeCode},</if>
            <if test="mxmmLdg != null">MXMM_LDG = #{mxmmLdg},</if>
            <if test="vhctyAsortNm != null">VHCTY_ASORT_NM = #{vhctyAsortNm},</if>
            <if test="vhctyTyNm != null">VHCTY_TY_NM = #{vhctyTyNm},</if>
            <if test="vhctySeNm != null">VHCTY_SE_NM = #{vhctySeNm},</if>
            <if test="frstRegistDe != null">FRST_REGIST_DE = #{frstRegistDe},</if>
            <if test="fomNm != null">FOM_NM = #{fomNm},</if>
            <if test="acqsDe != null">ACQS_DE = #{acqsDe},</if>
            <if test="acqsEndDe != null">ACQS_END_DE = #{acqsEndDe},</if>
            <if test="yblMd != null">YBL_MD = #{yblMd},</if>
            <if test="transrRegistDe != null">TRANSR_REGIST_DE = #{transrRegistDe},</if>
            <if test="spcfRegistSttusCode != null">SPCF_REGIST_STTUS_CODE = #{spcfRegistSttusCode},</if>
            <if test="colorNm != null">COLOR_NM = #{colorNm},</if>
            <if test="mrtgCo != null">MRTG_CO = #{mrtgCo},</if>
            <if test="seizrCo != null">SEIZR_CO = #{seizrCo},</if>
            <if test="stmdCo != null">STMD_CO = #{stmdCo},</if>
            <if test="nmplCsdyAt != null">NMPL_CSDY_AT = #{nmplCsdyAt},</if>
            <if test="nmplCsdyRemnrDe != null">NMPL_CSDY_REMNR_DE = #{nmplCsdyRemnrDe},</if>
            <if test="originSeCode != null">ORIGIN_SE_CODE = #{originSeCode},</if>
            <if test="nmplStndrdCode != null">NMPL_STNDRD_CODE = #{nmplStndrdCode},</if>
            <if test="acqsAmount != null">ACQS_AMOUNT = #{acqsAmount},</if>
            <if test="insptValidPdBgnde != null">INSPT_VALID_PD_BGNDE = #{insptValidPdBgnde},</if>
            <if test="insptValidPdEndde != null">INSPT_VALID_PD_ENDDE = #{insptValidPdEndde},</if>
            <if test="useStrnghldGrcCode != null">USE_STRNGHLD_GRC_CODE = #{useStrnghldGrcCode},</if>
            <if test="tkcarPscapCo != null">TKCAR_PSCAP_CO = #{tkcarPscapCo},</if>
            <if test="spmnno != null">SPMNNO = #{spmnno},</if>
            <if test="trvlDstnc != null">TRVL_DSTNC = #{trvlDstnc},</if>
            <if test="frstRegistRqrcno != null">FRST_REGIST_RQRCNO = #{frstRegistRqrcno},</if>
            <if test="vlntErsrPrvntcNticeDe != null">VLNT_ERSR_PRVNTC_NTICE_DE = #{vlntErsrPrvntcNticeDe},</if>
            <if test="registInsttNm != null">REGIST_INSTT_NM = #{registInsttNm},</if>
            <if test="processImprtyResnCode != null">PROCESS_IMPRTY_RESN_CODE = #{processImprtyResnCode},</if>
            <if test="processImprtyResnDtls != null">PROCESS_IMPRTY_RESN_DTLS = #{processImprtyResnDtls},</if>
            <if test="cbdLt != null">CBD_LT = #{cbdLt},</if>
            <if test="cbdBt != null">CBD_BT = #{cbdBt},</if>
            <if test="cbdHg != null">CBD_HG = #{cbdHg},</if>
            <if test="frstMxmmLdg != null">FRST_MXMM_LDG = #{frstMxmmLdg},</if>
            <if test="fuelCnsmpRt != null">FUEL_CNSMP_RT = #{fuelCnsmpRt},</if>
            <if test="elctyCmpndFuelCnsmpRt != null">ELCTY_CMPND_FUEL_CNSMP_RT = #{elctyCmpndFuelCnsmpRt},</if>
            <if test="mberNm != null">MBER_NM = #{mberNm},</if>
        </set>
        WHERE CAR_BASS_MATTER_INQIRE_ID = #{carBassMatterInqireId}
    </update>

    <!-- ID로 조회 -->
    <select id="selectCarBassMatterInqireById" parameterType="String" resultType="VmisCarBassMatterInqireVO">
        SELECT *
        FROM tb_car_bass_matter_inqire
        WHERE CAR_BASS_MATTER_INQIRE_ID = #{carBassMatterInqireId}
    </select>

</mapper>
