<?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="CarBassMatterInqireVO">
        INSERT INTO tb_car_bass_matter_inqire (
            CAR_BASS_MATTER_INQIRE_ID,
            INFO_SYS_ID,
            INFO_SYS_IP_ADDR,
            SGG_CD,
            LINK_INFO_CD,
            PIC_ID,
            PIC_IP_ADDR,
            PIC_NM,
            DMND_LEVY_CRTR_YMD,
            DMND_INQ_SE_CD,
            DMND_VHRNO,
            DMND_VIN,
            LINK_RSLT_CD,
            REG_DT,
            RGTR
        ) VALUES (
            #{carBassMatterInqireId},
            #{infoSysId},
            #{infoSysIpAddr},
            #{sggCd},
            #{linkInfoCd},
            #{picId},
            #{picIpAddr},
            #{picNm},
            #{dmndLevyCrtrYmd},
            #{dmndInqSeCd},
            #{dmndVhrno},
            #{dmndVin},
            #{linkRsltCd},
            NOW(),
            #{rgtr}
        )
    </insert>

    <!-- 응답 결과 UPDATE -->
    <update id="updateCarBassMatterInqire" parameterType="CarBassMatterInqireVO">
        UPDATE tb_car_bass_matter_inqire
        <set>
            <if test="txId != null">TX_ID = #{txId},</if>
            <if test="linkRsltCd != null">LINK_RSLT_CD = #{linkRsltCd},</if>
            <if test="linkRsltDtl != null">LINK_RSLT_DTL = #{linkRsltDtl},</if>
            <if test="yridnw != null">YRIDNW = #{yridnw},</if>
            <if test="regYmd != null">REG_YMD = #{regYmd},</if>
            <if test="ersrRegSeCd != null">ERSR_REG_SE_CD = #{ersrRegSeCd},</if>
            <if test="ersrRegSeNm != null">ERSR_REG_SE_NM = #{ersrRegSeNm},</if>
            <if test="ersrRegYmd != null">ERSR_REG_YMD = #{ersrRegYmd},</if>
            <if test="regDtlCd != null">REG_DTL_CD = #{regDtlCd},</if>
            <if test="dsplvl != null">DSPLVL = #{dsplvl},</if>
            <if test="usgsrhldStdgCd != null">USGSRHLD_STDG_CD = #{usgsrhldStdgCd},</if>
            <if test="usgsrhldDongCd != null">USGSRHLD_DONG_CD = #{usgsrhldDongCd},</if>
            <if test="usgsrhldMtnYn != null">USGSRHLD_MTN_YN = #{usgsrhldMtnYn},</if>
            <if test="usgsrhldLnbr != null">USGSRHLD_LNBR = #{usgsrhldLnbr},</if>
            <if test="usgsrhldHo != null">USGSRHLD_HO = #{usgsrhldHo},</if>
            <if test="usgsrhldAddrNm != null">USGSRHLD_ADDR_NM = #{usgsrhldAddrNm},</if>
            <if test="usgsrhldRoadNmCd != null">USGSRHLD_ROAD_NM_CD = #{usgsrhldRoadNmCd},</if>
            <if test="usgsrhldUdgdBldgSeCd != null">USGSRHLD_UDGD_BLDG_SE_CD = #{usgsrhldUdgdBldgSeCd},</if>
            <if test="usgsrhldBmno != null">USGSRHLD_BMNO = #{usgsrhldBmno},</if>
            <if test="usgsrhldBsno != null">USGSRHLD_BSNO = #{usgsrhldBsno},</if>
            <if test="usgsrhldWholAddr != null">USGSRHLD_WHOL_ADDR = #{usgsrhldWholAddr},</if>
            <if test="rprsOwnrMbrSeCd != null">RPRS_OWNR_MBR_SE_CD = #{rprsOwnrMbrSeCd},</if>
            <if test="rprsvOwnrIdecno != null">RPRSV_OWNR_IDECNO = #{rprsvOwnrIdecno},</if>
            <if test="rprsOwnrTelno != null">RPRS_OWNR_TELNO = #{rprsOwnrTelno},</if>
            <if test="ownrStdgCd != null">OWNR_STDG_CD = #{ownrStdgCd},</if>
            <if test="ownrDongCd != null">OWNR_DONG_CD = #{ownrDongCd},</if>
            <if test="ownrMtnYn != null">OWNR_MTN_YN = #{ownrMtnYn},</if>
            <if test="ownrLnbr != null">OWNR_LNBR = #{ownrLnbr},</if>
            <if test="ownrHo != null">OWNR_HO = #{ownrHo},</if>
            <if test="ownrAddrNm != null">OWNR_ADDR_NM = #{ownrAddrNm},</if>
            <if test="ownrRoadNmCd != null">OWNR_ROAD_NM_CD = #{ownrRoadNmCd},</if>
            <if test="ownrUdgdBldgSeCd != null">OWNR_UDGD_BLDG_SE_CD = #{ownrUdgdBldgSeCd},</if>
            <if test="ownrBmno != null">OWNR_BMNO = #{ownrBmno},</if>
            <if test="ownrBsno != null">OWNR_BSNO = #{ownrBsno},</if>
            <if test="ownrWholaddr != null">OWNR_WHOL_ADDR = #{ownrWholaddr},</if>
            <if test="rearVhrno != null">REAR_VHRNO = #{rearVhrno},</if>
            <if test="useFuelCd != null">USE_FUEL_CD = #{useFuelCd},</if>
            <if test="usgSeCd != null">USG_SE_CD = #{usgSeCd},</if>
            <if test="mtrsFomNm != null">MTRS_FOM_NM = #{mtrsFomNm},</if>
            <if test="bfrVhrno != null">BFR_VHRNO = #{bfrVhrno},</if>
            <if test="vhrno != null">VHRNO = #{vhrno},</if>
            <if test="vin != null">VIN = #{vin},</if>
            <if test="atmbNm != null">ATMB_NM = #{atmbNm},</if>
            <if test="vhclTotlWt != null">VHCL_TOTL_WT = #{vhclTotlWt},</if>
            <if test="veagEndYmd != null">VEAG_END_YMD = #{veagEndYmd},</if>
            <if test="chgYmd != null">CHG_YMD = #{chgYmd},</if>
            <if test="carmdlAsortCd != null">CARMDL_ASORT_CD = #{carmdlAsortCd},</if>
            <if test="carmdlTypeCd != null">CARMDL_TYPE_CD = #{carmdlTypeCd},</if>
            <if test="carmdlSeCd != null">CARMDL_SE_CD = #{carmdlSeCd},</if>
            <if test="mxmmLdg != null">MXMM_LDG = #{mxmmLdg},</if>
            <if test="carmdlAsortNm != null">CARMDL_ASORT_NM = #{carmdlAsortNm},</if>
            <if test="carmdlTypeNm != null">CARMDL_TYPE_NM = #{carmdlTypeNm},</if>
            <if test="carmdlClsfNm != null">CARMDL_CLSF_NM = #{carmdlClsfNm},</if>
            <if test="frstRegYmd != null">FRST_REG_YMD = #{frstRegYmd},</if>
            <if test="fomNm != null">FOM_NM = #{fomNm},</if>
            <if test="acqsYmd != null">ACQS_YMD = #{acqsYmd},</if>
            <if test="acqsEndYmd != null">ACQS_END_YMD = #{acqsEndYmd},</if>
            <if test="fbctnYmd != null">FBCTN_YMD = #{fbctnYmd},</if>
            <if test="transrRegYmd != null">TRANSR_REG_YMD = #{transrRegYmd},</if>
            <if test="spcfRegSttsCd != null">SPCF_REG_STTS_CD = #{spcfRegSttsCd},</if>
            <if test="colorNm != null">COLOR_NM = #{colorNm},</if>
            <if test="mrtgCnt != null">MRTG_CNT = #{mrtgCnt},</if>
            <if test="szrCnt != null">SZR_CNT = #{szrCnt},</if>
            <if test="strctChgCnt != null">STRCT_CHG_CNT = #{strctChgCnt},</if>
            <if test="nopltCsdyYn != null">NOPLT_CSDY_YN = #{nopltCsdyYn},</if>
            <if test="nopltCsdyAvtsmtYmd != null">NOPLT_CSDY_AVTSMT_YMD = #{nopltCsdyAvtsmtYmd},</if>
            <if test="srcSeCd != null">SRC_SE_CD = #{srcSeCd},</if>
            <if test="nopltSpcfctCd != null">NOPLT_SPCFCT_CD = #{nopltSpcfctCd},</if>
            <if test="acqsAmt != null">ACQS_AMT = #{acqsAmt},</if>
            <if test="inspVldPdBgngYmd != null">INSP_VLD_PD_BGNG_YMD = #{inspVldPdBgngYmd},</if>
            <if test="inspVldPdEndYmd != null">INSP_VLD_PD_END_YMD = #{inspVldPdEndYmd},</if>
            <if test="usgsrhldGrcCd != null">USGSRHLD_GRC_CD = #{usgsrhldGrcCd},</if>
            <if test="rdcpctCnt != null">RDCPCT_CNT = #{rdcpctCnt},</if>
            <if test="spmnno != null">SPMNNO = #{spmnno},</if>
            <if test="drvngDstnc != null">DRVNG_DSTNC = #{drvngDstnc},</if>
            <if test="frstRegAplyRcptNo != null">FRST_REG_APLY_RCPT_NO = #{frstRegAplyRcptNo},</if>
            <if test="vlntErsrPrvntcAvtsmtYmd != null">VLNT_ERSR_PRVNTC_AVTSMT_YMD = #{vlntErsrPrvntcAvtsmtYmd},</if>
            <if test="ognzNm != null">OGNZ_NM = #{ognzNm},</if>
            <if test="prcsImprtyRsnCd != null">PRCS_IMPRTY_RSN_CD = #{prcsImprtyRsnCd},</if>
            <if test="prcsImprtyRsnDtls != null">PRCS_IMPRTY_RSN_DTLS = #{prcsImprtyRsnDtls},</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_CNSMPRT = #{fuelCnsmprt},</if>
            <if test="elctyCmpndFuelCnsmprt != null">ELCTY_CMPND_FUEL_CNSMPRT = #{elctyCmpndFuelCnsmprt},</if>
            <if test="rprsOwnrNm != null">RPRS_OWNR_NM = #{rprsOwnrNm},</if>
            <if test="carFfnlgTrgtId != null">CAR_FFNLG_TRGT_ID = #{carFfnlgTrgtId}</if>
        </set>
        WHERE CAR_BASS_MATTER_INQIRE_ID = #{carBassMatterInqireId}
    </update>

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

    <!-- txId로 CAR_FFNLG_TRGT_ID 업데이트 (지연/미필 공통) -->
    <update id="updateCarFfnlgTrgtIdByTxId">
        UPDATE tb_car_bass_matter_inqire
        SET CAR_FFNLG_TRGT_ID = #{param2}
        WHERE TX_ID = #{param1}
    </update>

</mapper>
