<?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.VYpzsPresInfoReturnMapper">
  <resultMap id="BaseResultMap" type="com.glxp.mipsdl.entity.ctqyy.VYpzsPresInfoReturn">
    <!--@mbg.generated-->
    <!--@Table v_ypzs_pres_info_return-->
    <result column="APPLY_NO" jdbcType="VARCHAR" property="APPLY_NO" />
    <result column="SICK_ID" jdbcType="VARCHAR" property="SICK_ID" />
    <result column="STORAGE_CODE" jdbcType="INTEGER" property="STORAGE_CODE" />
    <result column="DEPT_NAME" jdbcType="VARCHAR" property="DEPT_NAME" />
    <result column="KEEP_BOOK_TIME" jdbcType="DATE" property="KEEP_BOOK_TIME" />
    <result column="KEEP_BOOK_OPERATOR" jdbcType="VARCHAR" property="KEEP_BOOK_OPERATOR" />
    <result column="SETTLE_NO" jdbcType="VARCHAR" property="SETTLE_NO" />
    <result column="PHYSIC_CODE" jdbcType="VARCHAR" property="PHYSIC_CODE" />
    <result column="PHYSIC_NAME" jdbcType="VARCHAR" property="PHYSIC_NAME" />
    <result column="PHYSIC_SPEC" jdbcType="VARCHAR" property="PHYSIC_SPEC" />
    <result column="QUANTITY" jdbcType="INTEGER" property="QUANTITY" />
    <result column="PHYSIC_UNIT" jdbcType="VARCHAR" property="PHYSIC_UNIT" />
    <result column="PRICE" jdbcType="DECIMAL" property="PRICE" />
    <result column="COST" jdbcType="DECIMAL" property="COST" />
    <result column="BATCH_NUMBER" jdbcType="VARCHAR" property="BATCH_NUMBER" />
    <result column="FEE_SEQUENCE_NO" jdbcType="VARCHAR" property="FEE_SEQUENCE_NO" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    APPLY_NO, SICK_ID, STORAGE_CODE, DEPT_NAME, KEEP_BOOK_TIME, KEEP_BOOK_OPERATOR, SETTLE_NO, 
    PHYSIC_CODE, PHYSIC_NAME, PHYSIC_SPEC, QUANTITY, PHYSIC_UNIT, PRICE, COST, BATCH_NUMBER, 
    FEE_SEQUENCE_NO
  </sql>


  <select id="selectGroupedWithPagination" resultType="com.glxp.mipsdl.entity.ctqyy.VYpzsPresInfoReturn">
        SELECT APPLY_NO
        FROM v_ypzs_pres_info_return
        <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 (APPLY_NO  = #{udiwmsBasicSkPrescribeRequest.code})
            </if>
            <if test="udiwmsBasicSkPrescribeRequest.fromCorpName != null and udiwmsBasicSkPrescribeRequest.fromCorpName != ''
            and udiwmsBasicSkPrescribeRequest.databaseProductName == 'Oracle' ">
                and (PSN_NAME  like '%'  || #{udiwmsBasicSkPrescribeRequest.fromCorpName} || '%' )
            </if>

            <if test="udiwmsBasicSkPrescribeRequest.key != null and udiwmsBasicSkPrescribeRequest.key != ''
            and udiwmsBasicSkPrescribeRequest.databaseProductName == 'Oracle' ">
                and (APPLY_NO like '%'  || #{udiwmsBasicSkPrescribeRequest.key}  || '%'
                 or PSN_NAME like '%'  ||#{udiwmsBasicSkPrescribeRequest.key}  || '%'
                 or PSN_NO like '%'  || #{udiwmsBasicSkPrescribeRequest.key}  ||'%'
                        )
            </if>

            <if test="udiwmsBasicSkPrescribeRequest.fromCorpName != null and udiwmsBasicSkPrescribeRequest.fromCorpName != ''
            and udiwmsBasicSkPrescribeRequest.databaseProductName == 'MySQL' ">
                and (PSN_NAME  like concat('%', #{udiwmsBasicSkPrescribeRequest.key}, '%')
            </if>

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