<?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.VInsurNationGoodsClMapper">
  <select id="selectGroupedWithPagination" resultType="com.glxp.mipsdl.entity.ctqyy.VInsurNationGoodsCl">
        SELECT STOOUT_NO
        FROM v_insur_nation_goods_cl
        <where>
            <if test="udiwmsBasicSkPrescribeRequest.startTime != null and udiwmsBasicSkPrescribeRequest.startTime != ''
            and udiwmsBasicSkPrescribeRequest.databaseProductName == 'Oracle' ">
                <![CDATA[
                and SEL_RETN_TIME >= TO_DATE(#{udiwmsBasicSkPrescribeRequest.startTime}
                  , 'YYYY-MM-DD HH24:MI:SS')
                ]]>
            </if>
            <if test="udiwmsBasicSkPrescribeRequest.endTime != null and udiwmsBasicSkPrescribeRequest.endTime != ''
            and udiwmsBasicSkPrescribeRequest.databaseProductName == 'Oracle' ">
                <![CDATA[
                and SEL_RETN_TIME <= TO_DATE(#{udiwmsBasicSkPrescribeRequest.endTime}
                  , 'YYYY-MM-DD HH24:MI:SS')
                ]]>
            </if>

       <if test="udiwmsBasicSkPrescribeRequest.startTime != null and udiwmsBasicSkPrescribeRequest.startTime != ''
               and udiwmsBasicSkPrescribeRequest.databaseProductName == 'MySQL'">
           <![CDATA[
           and SEL_RETN_TIME >= #{udiwmsBasicSkPrescribeRequest.startTime}
           ]]>
       </if>
       <if test="udiwmsBasicSkPrescribeRequest.endTime != null and udiwmsBasicSkPrescribeRequest.endTime != ''
               and udiwmsBasicSkPrescribeRequest.databaseProductName == 'MySQL'">
           <![CDATA[
           and SEL_RETN_TIME <= #{udiwmsBasicSkPrescribeRequest.endTime}
           ]]>
       </if>

            <if test="udiwmsBasicSkPrescribeRequest.code != null and udiwmsBasicSkPrescribeRequest.code != ''">
                and ( STOOUT_NO = #{udiwmsBasicSkPrescribeRequest.code}
                or RXNO = #{udiwmsBasicSkPrescribeRequest.code}
                        )
            </if>

            <if test="udiwmsBasicSkPrescribeRequest.key != null and udiwmsBasicSkPrescribeRequest.key != ''
            and udiwmsBasicSkPrescribeRequest.databaseProductName == 'Oracle' ">
                and (STOOUT_NO like   '%'  || #{udiwmsBasicSkPrescribeRequest.key}  || '%'
                or RXNO like   '%'  || #{udiwmsBasicSkPrescribeRequest.key}  || '%'
                        )
            </if>
            <if test="udiwmsBasicSkPrescribeRequest.key != null and udiwmsBasicSkPrescribeRequest.key != ''
            and udiwmsBasicSkPrescribeRequest.databaseProductName == 'MySQL' ">
                and (STOOUT_NO like  concat('%', #{udiwmsBasicSkPrescribeRequest.key}, '%')
               or RXNO like  concat('%', #{udiwmsBasicSkPrescribeRequest.key}, '%')
                        )
            </if>
        </where>
        GROUP BY
                STOOUT_NO
        ORDER BY
                STOOUT_NO
    </select>
</mapper>