<?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.VYpzsPresInfoMapper">
    <resultMap id="BaseResultMap" type="com.glxp.mipsdl.entity.ctqyy.VYpzsPresInfo">
        <!--@mbg.generated-->
        <!--@Table v_ypzs_pres_info-->
        <result column="LAY_TIME" jdbcType="TIMESTAMP" property="LAY_TIME"/>
        <result column="STOOUT_NO" jdbcType="VARCHAR" property="STOOUT_NO"/>
        <result column="PRESCRIBE_NUMBER" jdbcType="VARCHAR" property="PRESCRIBE_NUMBER"/>
        <result column="PHYSIC_CODE" jdbcType="VARCHAR" property="PHYSIC_CODE"/>
        <result column="PHYSIC_NAME" jdbcType="VARCHAR" property="PHYSIC_NAME"/>
        <result column="BATCH_NUMBER" jdbcType="VARCHAR" property="BATCH_NUMBER"/>
        <result column="PACK_SPEC" jdbcType="VARCHAR" property="PACK_SPEC"/>
        <result column="LAY_PHYSIC_QUANTITY" jdbcType="DECIMAL" property="LAY_PHYSIC_QUANTITY"/>
        <result column="PHYSIC_UNIT" jdbcType="VARCHAR" property="PHYSIC_UNIT"/>
        <result column="SICK_ID" jdbcType="VARCHAR" property="SICK_ID"/>
        <result column="RESIDENCE_NO" jdbcType="VARCHAR" property="RESIDENCE_NO"/>
        <result column="COUNTRY_CODE" jdbcType="VARCHAR" property="COUNTRY_CODE"/>
        <result column="CONFECT_MAN" jdbcType="VARCHAR" property="CONFECT_MAN"/>
        <result column="SICK_NAME" jdbcType="VARCHAR" property="SICK_NAME"/>
        <result column="SEX" jdbcType="CHAR" property="SEX"/>
        <result column="IC_CARD_ID" jdbcType="VARCHAR" property="IC_CARD_ID"/>
        <result column="NL" jdbcType="VARCHAR" property="NL"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        LAY_TIME,
        STOOUT_NO,
        PRESCRIBE_NUMBER,
        PHYSIC_CODE,
        PHYSIC_NAME,
        BATCH_NUMBER,
        PACK_SPEC,
        LAY_PHYSIC_QUANTITY,
        PHYSIC_UNIT,
        SICK_ID,
        RESIDENCE_NO,
        COUNTRY_CODE,
        CONFECT_MAN,
        SICK_NAME,
        SEX,
        IC_CARD_ID,
        NL
    </sql>


    <select id="selectGroupedWithPagination" resultType="com.glxp.mipsdl.entity.ctqyy.VYpzsPresInfo">
        SELECT PRESCRIBE_NUMBER
        FROM v_ypzs_pres_info
        <where>
            <if test="udiwmsBasicSkPrescribeRequest.startTime != null and udiwmsBasicSkPrescribeRequest.startTime != ''
            and udiwmsBasicSkPrescribeRequest.databaseProductName == 'Oracle'">
                <![CDATA[
                and LAY_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 LAY_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 LAY_TIME >= #{udiwmsBasicSkPrescribeRequest.startTime}
                ]]>
            </if>
            <if test="udiwmsBasicSkPrescribeRequest.endTime != null and udiwmsBasicSkPrescribeRequest.endTime != ''
            and udiwmsBasicSkPrescribeRequest.databaseProductName == 'MySQL'">
                <![CDATA[
                and LAY_TIME <= #{udiwmsBasicSkPrescribeRequest.endTime}
                ]]>
            </if>

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