ncdmapper.xml 21 KB
Newer Older
hulei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
<?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="com.brilliance.isc.mda.dao.NcdMapper">

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Ncd">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="ownref" column="ownref" jdbcType="VARCHAR"/>
        <result property="pntinr" column="pntinr" jdbcType="VARCHAR"/>
        <result property="pnttyp" column="pnttyp" jdbcType="VARCHAR"/>
        <result property="nam" column="nam" jdbcType="VARCHAR"/>
        <result property="credat" column="credat" jdbcType="DATE"/>
        <result property="clsdat" column="clsdat" jdbcType="DATE"/>
        <result property="opndat" column="opndat" jdbcType="DATE"/>
        <result property="newexpdat" column="newexpdat" jdbcType="DATE"/>
        <result property="ownusr" column="ownusr" jdbcType="VARCHAR"/>
        <result property="ver" column="ver" jdbcType="VARCHAR"/>
        <result property="clmtyp" column="clmtyp" jdbcType="VARCHAR"/>
        <result property="clmctl" column="clmctl" jdbcType="VARCHAR"/>
        <result property="clmdat" column="clmdat" jdbcType="DATE"/>
        <result property="cannowflg" column="cannowflg" jdbcType="VARCHAR"/>
        <result property="msgdat" column="msgdat" jdbcType="DATE"/>
        <result property="payrol" column="payrol" jdbcType="VARCHAR"/>
        <result property="docprbrol" column="docprbrol" jdbcType="VARCHAR"/>
        <result property="demstat" column="demstat" jdbcType="VARCHAR"/>
        <result property="dipreiday" column="dipreiday" jdbcType="INTEGER"/>
        <result property="dipreiflg1" column="dipreiflg1" jdbcType="VARCHAR"/>
        <result property="dipreiflg3" column="dipreiflg3" jdbcType="VARCHAR"/>
        <result property="paydat" column="paydat" jdbcType="DATE"/>
        <result property="totamt" column="totamt" jdbcType="DECIMAL"/>
        <result property="totcur" column="totcur" jdbcType="VARCHAR"/>
        <result property="etyextkey" column="etyextkey" jdbcType="VARCHAR"/>
        <result property="frepayflg" column="frepayflg" jdbcType="VARCHAR"/>
        <result property="bchkeyinr" column="bchkeyinr" jdbcType="VARCHAR"/>
        <result property="branchinr" column="branchinr" jdbcType="VARCHAR"/>
        <result property="prechkdat" column="prechkdat" jdbcType="DATE"/>
        <result property="ischktyp" column="ischktyp" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        inr,ownref,pntinr,pnttyp,nam,credat,clsdat,opndat,newexpdat,ownusr,ver,clmtyp,clmctl,clmdat,cannowflg,msgdat,payrol,docprbrol,demstat,dipreiday,dipreiflg1,dipreiflg3,paydat,totamt,totcur,etyextkey,frepayflg,bchkeyinr,branchinr,prechkdat,ischktyp
    </sql>

    <select id="selectByPrimaryKey" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from ncd
        where inr = #{inr,jdbcType=VARCHAR}
    </select>

    <delete id="deleteByPrimaryKey">
        delete from ncd
        where inr = #{inr,jdbcType=VARCHAR}
    </delete>

    <insert id="insert">
        insert into ncd (<include refid="Base_Column_List"/>)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{inr,jdbcType=VARCHAR},
            #{ownref,jdbcType=VARCHAR},
            #{pntinr,jdbcType=VARCHAR},
            #{pnttyp,jdbcType=VARCHAR},
            #{nam,jdbcType=VARCHAR},
            #{credat,jdbcType=DATE},
            #{clsdat,jdbcType=DATE},
            #{opndat,jdbcType=DATE},
            #{newexpdat,jdbcType=DATE},
            #{ownusr,jdbcType=VARCHAR},
            #{ver,jdbcType=VARCHAR},
            #{clmtyp,jdbcType=VARCHAR},
            #{clmctl,jdbcType=VARCHAR},
            #{clmdat,jdbcType=DATE},
            #{cannowflg,jdbcType=VARCHAR},
            #{msgdat,jdbcType=DATE},
            #{payrol,jdbcType=VARCHAR},
            #{docprbrol,jdbcType=VARCHAR},
            #{demstat,jdbcType=VARCHAR},
            #{dipreiday,jdbcType=INTEGER},
            #{dipreiflg1,jdbcType=VARCHAR},
            #{dipreiflg3,jdbcType=VARCHAR},
            #{paydat,jdbcType=DATE},
            #{totamt,jdbcType=DECIMAL},
            #{totcur,jdbcType=VARCHAR},
            #{etyextkey,jdbcType=VARCHAR},
            #{frepayflg,jdbcType=VARCHAR},
            #{bchkeyinr,jdbcType=VARCHAR},
            #{branchinr,jdbcType=VARCHAR},
            #{prechkdat,jdbcType=DATE},
            #{ischktyp,jdbcType=VARCHAR},
        </trim>
    </insert>

    <insert id="insertSelective">
        insert into ncd
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inr != null">inr,</if>
            <if test="ownref != null">ownref,</if>
            <if test="pntinr != null">pntinr,</if>
            <if test="pnttyp != null">pnttyp,</if>
            <if test="nam != null">nam,</if>
            <if test="credat != null">credat,</if>
            <if test="clsdat != null">clsdat,</if>
            <if test="opndat != null">opndat,</if>
            <if test="newexpdat != null">newexpdat,</if>
            <if test="ownusr != null">ownusr,</if>
            <if test="ver != null">ver,</if>
            <if test="clmtyp != null">clmtyp,</if>
            <if test="clmctl != null">clmctl,</if>
            <if test="clmdat != null">clmdat,</if>
            <if test="cannowflg != null">cannowflg,</if>
            <if test="msgdat != null">msgdat,</if>
            <if test="payrol != null">payrol,</if>
            <if test="docprbrol != null">docprbrol,</if>
            <if test="demstat != null">demstat,</if>
            <if test="dipreiday != null">dipreiday,</if>
            <if test="dipreiflg1 != null">dipreiflg1,</if>
            <if test="dipreiflg3 != null">dipreiflg3,</if>
            <if test="paydat != null">paydat,</if>
            <if test="totamt != null">totamt,</if>
            <if test="totcur != null">totcur,</if>
            <if test="etyextkey != null">etyextkey,</if>
            <if test="frepayflg != null">frepayflg,</if>
            <if test="bchkeyinr != null">bchkeyinr,</if>
            <if test="branchinr != null">branchinr,</if>
            <if test="prechkdat != null">prechkdat,</if>
            <if test="ischktyp != null">ischktyp,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inr != null">#{inr,jdbcType=VARCHAR},</if>
            <if test="ownref != null">#{ownref,jdbcType=VARCHAR},</if>
            <if test="pntinr != null">#{pntinr,jdbcType=VARCHAR},</if>
            <if test="pnttyp != null">#{pnttyp,jdbcType=VARCHAR},</if>
            <if test="nam != null">#{nam,jdbcType=VARCHAR},</if>
            <if test="credat != null">#{credat,jdbcType=DATE},</if>
            <if test="clsdat != null">#{clsdat,jdbcType=DATE},</if>
            <if test="opndat != null">#{opndat,jdbcType=DATE},</if>
            <if test="newexpdat != null">#{newexpdat,jdbcType=DATE},</if>
            <if test="ownusr != null">#{ownusr,jdbcType=VARCHAR},</if>
            <if test="ver != null">#{ver,jdbcType=VARCHAR},</if>
            <if test="clmtyp != null">#{clmtyp,jdbcType=VARCHAR},</if>
            <if test="clmctl != null">#{clmctl,jdbcType=VARCHAR},</if>
            <if test="clmdat != null">#{clmdat,jdbcType=DATE},</if>
            <if test="cannowflg != null">#{cannowflg,jdbcType=VARCHAR},</if>
            <if test="msgdat != null">#{msgdat,jdbcType=DATE},</if>
            <if test="payrol != null">#{payrol,jdbcType=VARCHAR},</if>
            <if test="docprbrol != null">#{docprbrol,jdbcType=VARCHAR},</if>
            <if test="demstat != null">#{demstat,jdbcType=VARCHAR},</if>
            <if test="dipreiday != null">#{dipreiday,jdbcType=INTEGER},</if>
            <if test="dipreiflg1 != null">#{dipreiflg1,jdbcType=VARCHAR},</if>
            <if test="dipreiflg3 != null">#{dipreiflg3,jdbcType=VARCHAR},</if>
            <if test="paydat != null">#{paydat,jdbcType=DATE},</if>
            <if test="totamt != null">#{totamt,jdbcType=DECIMAL},</if>
            <if test="totcur != null">#{totcur,jdbcType=VARCHAR},</if>
            <if test="etyextkey != null">#{etyextkey,jdbcType=VARCHAR},</if>
            <if test="frepayflg != null">#{frepayflg,jdbcType=VARCHAR},</if>
            <if test="bchkeyinr != null">#{bchkeyinr,jdbcType=VARCHAR},</if>
            <if test="branchinr != null">#{branchinr,jdbcType=VARCHAR},</if>
            <if test="prechkdat != null">#{prechkdat,jdbcType=DATE},</if>
            <if test="ischktyp != null">#{ischktyp,jdbcType=VARCHAR},</if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update ncd
        <set>
            <if test="ownref != null">ownref = #{ownref,jdbcType=VARCHAR},</if>
            <if test="pntinr != null">pntinr = #{pntinr,jdbcType=VARCHAR},</if>
            <if test="pnttyp != null">pnttyp = #{pnttyp,jdbcType=VARCHAR},</if>
            <if test="nam != null">nam = #{nam,jdbcType=VARCHAR},</if>
            <if test="credat != null">credat = #{credat,jdbcType=DATE},</if>
            clsdat = #{clsdat,jdbcType=DATE},
            <if test="opndat != null">opndat = #{opndat,jdbcType=DATE},</if>
            <if test="newexpdat != null">newexpdat = #{newexpdat,jdbcType=DATE},</if>
            <if test="ownusr != null">ownusr = #{ownusr,jdbcType=VARCHAR},</if>
            <if test="ver != null">ver = #{ver,jdbcType=VARCHAR},</if>
            <if test="clmtyp != null">clmtyp = #{clmtyp,jdbcType=VARCHAR},</if>
            <if test="clmctl != null">clmctl = #{clmctl,jdbcType=VARCHAR},</if>
            <if test="clmdat != null">clmdat = #{clmdat,jdbcType=DATE},</if>
            <if test="cannowflg != null">cannowflg = #{cannowflg,jdbcType=VARCHAR},</if>
            <if test="msgdat != null">msgdat = #{msgdat,jdbcType=DATE},</if>
            <if test="payrol != null">payrol = #{payrol,jdbcType=VARCHAR},</if>
            <if test="docprbrol != null">docprbrol = #{docprbrol,jdbcType=VARCHAR},</if>
            <if test="demstat != null">demstat = #{demstat,jdbcType=VARCHAR},</if>
            <if test="dipreiday != null">dipreiday = #{dipreiday,jdbcType=INTEGER},</if>
            <if test="dipreiflg1 != null">dipreiflg1 = #{dipreiflg1,jdbcType=VARCHAR},</if>
            <if test="dipreiflg3 != null">dipreiflg3 = #{dipreiflg3,jdbcType=VARCHAR},</if>
            <if test="paydat != null">paydat = #{paydat,jdbcType=DATE},</if>
            <if test="totamt != null">totamt = #{totamt,jdbcType=DECIMAL},</if>
            <if test="totcur != null">totcur = #{totcur,jdbcType=VARCHAR},</if>
            <if test="etyextkey != null">etyextkey = #{etyextkey,jdbcType=VARCHAR},</if>
            <if test="frepayflg != null">frepayflg = #{frepayflg,jdbcType=VARCHAR},</if>
            <if test="bchkeyinr != null">bchkeyinr = #{bchkeyinr,jdbcType=VARCHAR},</if>
            <if test="branchinr != null">branchinr = #{branchinr,jdbcType=VARCHAR},</if>
            <if test="prechkdat != null">prechkdat = #{prechkdat,jdbcType=DATE},</if>
            <if test="ischktyp != null">ischktyp = #{ischktyp,jdbcType=VARCHAR},</if>
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKey">
        update ncd
        <set>
            ownref = #{ownref,jdbcType=VARCHAR},
            pntinr = #{pntinr,jdbcType=VARCHAR},
            pnttyp = #{pnttyp,jdbcType=VARCHAR},
            nam = #{nam,jdbcType=VARCHAR},
            credat = #{credat,jdbcType=DATE},
            clsdat = #{clsdat,jdbcType=DATE},
            opndat = #{opndat,jdbcType=DATE},
            newexpdat = #{newexpdat,jdbcType=DATE},
            ownusr = #{ownusr,jdbcType=VARCHAR},
            ver = #{ver,jdbcType=VARCHAR},
            clmtyp = #{clmtyp,jdbcType=VARCHAR},
            clmctl = #{clmctl,jdbcType=VARCHAR},
            clmdat = #{clmdat,jdbcType=DATE},
            cannowflg = #{cannowflg,jdbcType=VARCHAR},
            msgdat = #{msgdat,jdbcType=DATE},
            payrol = #{payrol,jdbcType=VARCHAR},
            docprbrol = #{docprbrol,jdbcType=VARCHAR},
            demstat = #{demstat,jdbcType=VARCHAR},
            dipreiday = #{dipreiday,jdbcType=INTEGER},
            dipreiflg1 = #{dipreiflg1,jdbcType=VARCHAR},
            dipreiflg3 = #{dipreiflg3,jdbcType=VARCHAR},
            paydat = #{paydat,jdbcType=DATE},
            totamt = #{totamt,jdbcType=DECIMAL},
            totcur = #{totcur,jdbcType=VARCHAR},
            etyextkey = #{etyextkey,jdbcType=VARCHAR},
            frepayflg = #{frepayflg,jdbcType=VARCHAR},
            bchkeyinr = #{bchkeyinr,jdbcType=VARCHAR},
            branchinr = #{branchinr,jdbcType=VARCHAR},
            prechkdat = #{prechkdat,jdbcType=DATE},
            ischktyp = #{ischktyp,jdbcType=VARCHAR},
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <delete id="deleteByIds">
        delete from act where inr in
        <foreach item="item" index="index" collection="collection" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>

    <delete id="dyncDelete">
        ${sql}
    </delete>

    <select id="dyncRead" resultMap="BaseResultMap">
        ${sql}
    </select>

    <select id="getNcdCount" resultType="java.lang.Integer">
        select count(*) from NCD WHERE PNTINR = #{inr} AND PNTTYP = 'NID'
    </select>

    <select id="getNcdOwnrefList" resultType="java.lang.String">
        select OWNREF from NCD WHERE PNTINR = #{inr} AND PNTTYP = 'NID'
    </select>

    <select id="getSptCount" resultType="java.lang.Integer">
       SELECT COUNT(*) FROM SPT WHERE OWNREF LIKE concat(#{ownref},'%')  AND OBJTYP ='NCD'
            AND OWNREF NOT IN (SELECT OWNREF FROM NCD WHERE PNTINR=#{inr})
    </select>

    <select id="getSptOwnrefList" resultType="java.lang.String">
       SELECT OWNREF FROM SPT WHERE OWNREF LIKE concat(#{ownref},'%')  AND OBJTYP ='NCD'
            AND OWNREF NOT IN (SELECT OWNREF FROM NCD WHERE PNTINR=#{inr})
    </select>

    <select id="getActPendingClaimCount" resultType="java.lang.Integer">
         select count(*) from NCD WHERE PNTINR =  #{inr} AND PNTTYP = 'NID' AND CLSDAT IS NULL
    </select>

    <select id="getNcdByNidinr" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from NCD where pntinr = #{nidinr, jdbcType=VARCHAR}
    </select>

    <select id="selectByPntinr" resultType="com.brilliance.isc.bo.Ncd">
        select
        <include refid="Base_Column_List"/>
        from ncd WHERE pntinr = #{pntinr,jdbcType=VARCHAR}
        and cannowflg is not null
    </select>

    <select id="queryInfncd" resultType="com.brilliance.isc.vo.lg.InfncdDetailVo">
        select
        ncd.INR inr,
        ncd.OWNREF ncdownref,
        ncd.OWNUSR ncdownusr,
        ncd.OPNDAT ncdopndat,
        ncd.CLSDAT ncdclsdat,
        apl.EXTKEY ncdaplextkey,
        apl.NAM ncdaplnam,
        ben.EXTKEY ncdbenextkey,
        ben.NAM ncdbennam,
        maxsum.CUR ncdmaxcur,
        maxsum.AMT ncdmaxamt,
        opn.CUR ncdopncur,
        opn.AMT ncdopnamt
        from ncd
        left join nid on nid.INR = ncd.PNTINR
        left join pts apl on apl.OBJTYP = 'NCD' and apl.OBJINR = ncd.INR and apl.ROL = 'APL'
        left join pts ben on ben.OBJTYP = 'NCD' and ben.OBJINR = ncd.INR and ben.ROL = 'BEN'
        left join cbb maxsum on maxsum.OBJTYP = 'NCD' and maxsum.OBJINR = ncd.INR and maxsum.CBC = 'MAXSUM' and maxsum.EXTID = 'AMT1' and maxsum.enddat = '2299-12-31'
        left join cbb opn on opn.OBJTYP = 'NCD' and opn.OBJINR = ncd.INR and opn.CBC = 'OPN' and opn.EXTID = 'AMT1'  and opn.enddat = '2299-12-31'
        where
        NCD.ETYEXTKEY = 'CEB'
        <if test="bchLst != null and bchLst.size() >0 ">
            and ncd.bchkeyinr in (select inr from bch where branch in
            <foreach item="bch" collection="bchLst" open="(" separator="," close=")">
                #{bch.branch}
            </foreach>
            )
        </if>
        <if test="nam != null and nam != ''">
            and UPPER(NCD.NAM) LIKE concat(concat('%', UPPER(#{nam})), '%')
        </if>
        <if test="seaownref != null and seaownref != ''">
            AND UPPER(NCD.OWNREF) LIKE concat(concat('%', UPPER(#{seaownref})), '%')
        </if>

        <if test="opndatfrom != null ">
            AND NCD.CREDAT &gt;= #{opndatfrom}

        </if>

        <if test="opndatto != null">
            AND NCD.CREDAT &lt;= #{opndatto}
        </if>

        <if test="seacur != null and seacur != ''">
            AND EXISTS (
            select 1 from CBB INFCONCBS where
            UPPER(INFCONCBS.CUR ) = UPPER(#{seacur})
            <if test="seaamtfr != null and seaamtfr != '' and seaamtto != null and seaamtto != ''">
                AND INFCONCBS.AMT &gt;= #{seaamtfr}
                AND INFCONCBS.AMT &lt;= #{seaamtto}
            </if>
            AND (INFCONCBS.OBJTYP = 'NCD'
            AND INFCONCBS.OBJINR = NCD.INR
            AND (INFCONCBS.BEGDAT &lt;= str_to_date('2299-12-30',  '%Y-%m-%d')
            AND INFCONCBS.ENDDAT &gt; str_to_date('2299-12-30',  '%Y-%m-%d'))
            AND INFCONCBS.EXTID IN (' ', 'AMT1')
            AND INFCONCBS.CBC IN ('MAXSUM', 'PRESUM', 'NOMSUM', 'OPN'))

            )
        </if>
        <if test="searol != null and searol != ''">
            AND EXISTS (
            select 1 from PTS where
            NCD.INR = PTS.OBJINR
            AND 'NCD' = PTS.OBJTYP
            AND PTS.ROL = #{searol}
            )
        </if>
        <if test="ptyExtkey != null and ptyExtkey != ''">
            and exists (
            select 1 from PTS, PTA where
            PTS.PTAINR = PTA.INR
            AND NCD.INR = PTS.OBJINR
            AND 'NCD' = PTS.OBJTYP
            <choose>
                <when test="searol != null and searol != ''" >AND PTS.ROL =  #{searol}</when>
                <otherwise>AND PTS.ROL IN ('BEN','APL') </otherwise>
            </choose>
            AND UPPER(PTA.PTYINR) IN (SELECT INR FROM PTY WHERE EXTKEY = UPPER(#{ptyExtkey}))
            )
        </if>

        <if test="seapty != null and seapty != ''">
            and exists (
            select 1 from PTS, PTA where
            PTS.PTAINR = PTA.INR
            AND NCD.INR = PTS.OBJINR
            AND 'NCD' = PTS.OBJTYP
            AND (
            UPPER(PTA.PTYEXTKEY) LIKE concat(concat('%', UPPER(#{seapty})), '%')
            or UPPER(PTA.BIC) LIKE concat(concat('%', UPPER(#{seapty})), '%')
            or UPPER(PTA.NAM) LIKE concat(concat('%', UPPER(#{seapty})), '%')
            )

            <choose>
                <when test="searol != null and searol != ''" >AND PTS.ROL =  #{searol}</when>
                <otherwise>AND PTS.ROL IN ('BEN','APL') </otherwise>
            </choose>
            )
        </if>

        <if test="seagtyp != null and seagtyp != ''">
            AND nid.gartyp = #{seagtyp}
        </if>

        <if test="searef != null and searef != ''">
            and (UPPER(apl.REF) LIKE concat(concat('%', UPPER(#{searef})), '%')
            or UPPER(ben.REF) LIKE concat(concat('%', UPPER(#{searef})), '%'))
        </if>

        <if test="seasta != null and seasta != ''">
            <if test="seasta== 'O'.toString()">
                AND NCD.OPNDAT IS NOT NULL
                AND NCD.CLSDAT IS NULL
            </if>
            <if test="seasta== 'C'.toString()">
                AND NCD.CLSDAT IS NOT NULL
            </if>
        </if>

        <if test="seaauthorized != null  and seaauthorized != ''">
            <if test="seaauthorized == 'Y'.toString()">
                AND NOT EXISTS (
                SELECT 1 FROM TRN WHERE
                TRN.OBJINR= NCD.INR
                AND TRN.OBJTYP='NCD'
                AND TRN.RELFLG in ('W','C')
                )
            </if>
            <if test="seaauthorized == 'N'.toString()">
                AND EXISTS (
                SELECT 1 FROM TRN WHERE
                TRN.OBJINR= NCD.INR
                AND TRN.OBJTYP='NCD'
                AND TRN.RELFLG in ('W','C')
                )
            </if>
        </if>

        <if test="isGuarantee != null and isGuarantee != ''">
            AND substring(ncd.OWNREF,1,2) = #{isGuarantee}
        </if>


        order by NCD.OPNDAT DESC
    </select>

    <select id="selectByAnyref" resultType="com.brilliance.isc.bo.Ncd">
        select
        <include refid="Base_Column_List"/>
        from ncd WHERE INR = ( select distinct OBJINR from PTS where OBJTYP = #{objtyp} and REF = #{ref}
        <if test="rol != null and rol != ''">
            and rol = #{rol}
        </if>
        )
    </select>

    <select id="selectByWhere" resultType="com.brilliance.isc.bo.Ncd">
        select
        <include refid="Base_Column_List"/>
        from ncd WHERE 1=1
        <if test="pntinr != null and pntinr != ''"> and pntinr = #{pntinr,jdbcType=VARCHAR}</if>
        <if test="cannowflg != null and cannowflg != ''"> and cannowflg = #{cannowflg,jdbcType=VARCHAR}</if>
        <if test="ownref != null and ownref != ''"> and ownref = #{ownref,jdbcType=VARCHAR}</if>
        limit 1
    </select>

    <select id="selectOneByOwnRef" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from NCD
        where OWNREF = #{ownRef,jdbcType=VARCHAR}
        ORDER BY CREDAT desc
        limit 1
    </select>
</mapper>