<?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.glxp.mipsdl.thirddao.ctqyy.VInsurNationGoodsReturnMapper">
    <resultMap id="BaseResultMap" type="com.glxp.mipsdl.entity.ctqyy.VInsurNationGoodsReturn">
        <!--@mbg.generated-->
        <!--@Table v_insur_nation_goods_return-->
        <result column="MED_LIST_CODG" jdbcType="VARCHAR" property="MED_LIST_CODG"/>
        <result column="FIXMEDINS_HILIST_ID" jdbcType="INTEGER" property="FIXMEDINS_HILIST_ID"/>
        <result column="FIXMEDINS_HILIST_NAME" jdbcType="VARCHAR" property="FIXMEDINS_HILIST_NAME"/>
        <result column="FIXMEDINS_BCHNO" jdbcType="INTEGER" property="FIXMEDINS_BCHNO"/>
        <result column="SETL_ID" jdbcType="INTEGER" property="SETL_ID"/>
        <result column="PSN_NO" jdbcType="INTEGER" property="PSN_NO"/>
        <result column="PSN_CERT_TYPE" jdbcType="VARCHAR" property="PSN_CERT_TYPE"/>
        <result column="CERTNO" jdbcType="VARCHAR" property="CERTNO"/>
        <result column="PSN_NAME" jdbcType="VARCHAR" property="PSN_NAME"/>
        <result column="MANU_LOTNUM" jdbcType="VARCHAR" property="MANU_LOTNUM"/>
        <result column="MANU_DATE" jdbcType="DATE" property="MANU_DATE"/>
        <result column="EXPY_END" jdbcType="DATE" property="EXPY_END"/>
        <result column="RX_FLAG" jdbcType="VARCHAR" property="RX_FLAG"/>
        <result column="TRDN_FLAG" jdbcType="VARCHAR" property="TRDN_FLAG"/>
        <result column="FINL_TRNS_PRIC" jdbcType="DECIMAL" property="FINL_TRNS_PRIC"/>
        <result column="SEL_RETN_CNT" jdbcType="INTEGER" property="SEL_RETN_CNT"/>
        <result column="SEL_RETN_TIME" jdbcType="DATE" property="SEL_RETN_TIME"/>
        <result column="SEL_RETN_OPTER_NAME" jdbcType="VARCHAR" property="SEL_RETN_OPTER_NAME"/>
        <result column="MEMO" jdbcType="VARCHAR" property="MEMO"/>
        <result column="MEDINS_PROL_SEL_NO" jdbcType="VARCHAR" property="MEDINS_PROL_SEL_NO"/>
        <result column="DRUGTRACINFO" jdbcType="VARCHAR" property="DRUGTRACINFO"/>
        <result column="SETTLE_NO" jdbcType="VARCHAR" property="SETTLE_NO"/>
        <result column="SICK_ID" jdbcType="VARCHAR" property="SICK_ID"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        MED_LIST_CODG, FIXMEDINS_HILIST_ID, FIXMEDINS_HILIST_NAME, FIXMEDINS_BCHNO, SETL_ID,
        PSN_NO, PSN_CERT_TYPE, CERTNO, PSN_NAME, MANU_LOTNUM, MANU_DATE, EXPY_END, RX_FLAG,
        TRDN_FLAG, FINL_TRNS_PRIC, SEL_RETN_CNT, SEL_RETN_TIME, SEL_RETN_OPTER_NAME, MEMO,
        MEDINS_PROL_SEL_NO, DRUGTRACINFO, SETTLE_NO, SICK_ID
    </sql>


    <select id="selectGroupedWithPagination" resultType="com.glxp.mipsdl.entity.ctqyy.VInsurNationGoodsReturn">
        SELECT APPLY_NO
        FROM V_INSUR_NATION_GOODS_RETURN
        <where>
            <if test="udiwmsBasicSkPrescribeRequest.startTime != null and udiwmsBasicSkPrescribeRequest.startTime != ''">
                <![CDATA[
                and SEL_RETN_TIME >= TO_DATE(#{udiwmsBasicSkPrescribeRequest.startTime}
                  , 'YYYY-MM-DD HH24:MI:SS')
                ]]>
            </if>
            <if test="udiwmsBasicSkPrescribeRequest.endTime != null and udiwmsBasicSkPrescribeRequest.endTime != ''">
                <![CDATA[
                and SEL_RETN_TIME <= TO_DATE(#{udiwmsBasicSkPrescribeRequest.endTime}
                  , 'YYYY-MM-DD HH24:MI:SS')
                ]]>
            </if>
            <if test="udiwmsBasicSkPrescribeRequest.code != null and udiwmsBasicSkPrescribeRequest.code != ''">
                and (APPLY_NO  = #{udiwmsBasicSkPrescribeRequest.code})
            </if>
            <if test="udiwmsBasicSkPrescribeRequest.fromCorpName != null and udiwmsBasicSkPrescribeRequest.fromCorpName != ''">
                and (PSN_NAME  like '%'  || #{udiwmsBasicSkPrescribeRequest.fromCorpName} || '%' )
            </if>

            <if test="udiwmsBasicSkPrescribeRequest.key != null and udiwmsBasicSkPrescribeRequest.key != ''">
                and (APPLY_NO like '%'  || #{udiwmsBasicSkPrescribeRequest.key}  || '%'
                 or PSN_NAME like '%'  ||#{udiwmsBasicSkPrescribeRequest.key}  || '%'
                 or PSN_NO like '%'  || #{udiwmsBasicSkPrescribeRequest.key}  ||'%'
                        )
            </if>
        </where>
        GROUP BY
                APPLY_NO
        ORDER BY
                APPLY_NO
    </select>
</mapper>