<?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.dxhy.jxpt.baseService.dao.ZzsDkdjWspzDao">


    <select id="selectCountByParam" resultType="long" parameterType="com.dxhy.pojo.obj.erp.ZzsDkdjWspzCjReq" databaseId="mysql">
        SELECT
        count(1)
        FROM
        t_dx_zzs_dkdjwspz
        <where>
            <if test="param.buyerTaxNo != null and param.buyerTaxNo != ''">
                and kjywrsbh = #{param.buyerTaxNo}
            </if>
            <if test="param.dkdjwspzbh != null and param.dkdjwspzbh != ''">
                and dkdjwspzh = #{param.dkdjwspzbh}
            </if>
            <if test="param.createDateBegin != null and param.createDateBegin != ''">
                <![CDATA[ AND create_time >= date_format(#{param.createDateBegin},'%Y-%m-%d %H:%i:%s') ]]>
            </if>
            <if test="param.createDateEnd != null and param.createDateEnd != ''">
                <![CDATA[ AND create_time <= date_format(#{param.createDateEnd},'%Y-%m-%d %H:%i:%s') ]]>
            </if>
            <if test="param.rzzt != null and param.rzzt != '' and param.rzzt == '0'">
                and rzzt = '0'
            </if>
            <if test="param.rzzt != null and param.rzzt != '' and param.rzzt == '1'">
                <if test="param.rzlx == null or param.rzlx == ''">
                    and (rzzt = '1' or rzzt = '2')
                </if>
                <if test="param.rzlx != null or param.rzlx != '' and param.rzlx == '1'">
                    and rzzt = '1'
                </if>
                <if test="param.rzlx != null or param.rzlx != '' and param.rzlx == '2'">
                    and rzzt = '2'
                </if>
            </if>
        </where>
    </select>

    <select id="selectCountByParam" resultType="long" parameterType="com.dxhy.pojo.obj.erp.ZzsDkdjWspzCjReq" databaseId="oracle">
        SELECT
        count(1)
        FROM
        t_dx_zzs_dkdjwspz
        <where>
            <if test="param.buyerTaxNo != null and param.buyerTaxNo != ''">
                and kjywrsbh = #{param.buyerTaxNo}
            </if>
            <if test="param.dkdjwspzbh != null and param.dkdjwspzbh != ''">
                and dkdjwspzh = #{param.dkdjwspzbh}
            </if>
            <if test="param.createDateBegin != null and param.createDateBegin != ''">
                <![CDATA[ AND create_time >= to_date(#{param.createDateBegin},'yyyymmddhh24:mi:ss') ]]>
            </if>
            <if test="param.createDateEnd != null and param.createDateEnd != ''">
                <![CDATA[ AND create_time <= to_date(#{param.createDateEnd},'yyyymmddhh24:mi:ss') ]]>
            </if>
            <if test="param.rzzt != null and param.rzzt != '' and param.rzzt == '0'">
                and rzzt = '0'
            </if>
            <if test="param.rzzt != null and param.rzzt != '' and param.rzzt == '1'">
                <if test="param.rzlx == null or param.rzlx == ''">
                    and (rzzt = '1' or rzzt = '2')
                </if>
                <if test="param.rzlx != null or param.rzlx != '' and param.rzlx == '1'">
                    and rzzt = '1'
                </if>
                <if test="param.rzlx != null or param.rzlx != '' and param.rzlx == '2'">
                    and rzzt = '2'
                </if>
            </if>
        </where>
    </select>

    <select id="selectByParam" resultType="com.dxhy.api.model.db.TDxZzsDkdjWspzEntity" parameterType="com.dxhy.pojo.obj.erp.ZzsDkdjWspzCjReq" databaseId="mysql">
        SELECT
        *
        FROM
        t_dx_zzs_dkdjwspz
        <where>
            <if test="param.buyerTaxNo != null and param.buyerTaxNo != ''">
                and kjywrsbh = #{param.buyerTaxNo}
            </if>
            <if test="param.dkdjwspzbh != null and param.dkdjwspzbh != ''">
                and dkdjwspzh = #{param.dkdjwspzbh}
            </if>
            <if test="param.createDateBegin != null and param.createDateBegin != ''">
                <![CDATA[ AND create_time >= date_format(#{param.createDateBegin},'%Y-%m-%d %H:%i:%s') ]]>
            </if>
            <if test="param.createDateEnd != null and param.createDateEnd != ''">
                <![CDATA[ AND create_time <= date_format(#{param.createDateEnd},'%Y-%m-%d %H:%i:%s') ]]>
            </if>
            <if test="param.rzzt != null and param.rzzt != '' and param.rzzt == '0'">
                and rzzt = '0'
            </if>
            <if test="param.rzzt != null and param.rzzt != '' and param.rzzt == '1'">
                <if test="param.rzlx == null or param.rzlx == ''">
                    and (rzzt = '1' or rzzt = '2')
                </if>
                <if test="param.rzlx != null or param.rzlx != '' and param.rzlx == '1'">
                    and rzzt = '1'
                </if>
                <if test="param.rzlx != null or param.rzlx != '' and param.rzlx == '2'">
                    and rzzt = '2'
                </if>
            </if>
            order by create_time
            limit #{param.pageNum},#{param.pageCount}
        </where>
    </select>

    <select id="selectByParam" resultType="com.dxhy.api.model.db.TDxZzsDkdjWspzEntity" parameterType="com.dxhy.pojo.obj.erp.ZzsDkdjWspzCjReq" databaseId="oracle">
        select b.* from (
        select c.*,rownum r from (
        SELECT
        *
        FROM
        t_dx_zzs_dkdjwspz
        <where>
            <if test="param.buyerTaxNo != null and param.buyerTaxNo != ''">
                and kjywrsbh = #{param.buyerTaxNo}
            </if>
            <if test="param.dkdjwspzbh != null and param.dkdjwspzbh != ''">
                and dkdjwspzh = #{param.dkdjwspzbh}
            </if>
            <if test="param.createDateBegin != null and param.createDateBegin != ''">
                <![CDATA[ AND create_time >= to_date(#{param.createDateBegin},'yyyymmddhh24:mi:ss') ]]>
            </if>
            <if test="param.createDateEnd != null and param.createDateEnd != ''">
                <![CDATA[ AND create_time <= to_date(#{param.createDateEnd},'yyyymmddhh24:mi:ss') ]]>
            </if>
            <if test="param.rzzt != null and param.rzzt != '' and param.rzzt == '0'">
                and rzzt = '0'
            </if>
            <if test="param.rzzt != null and param.rzzt != '' and param.rzzt == '1'">
                <if test="param.rzlx == null or param.rzlx == ''">
                    and (rzzt = '1' or rzzt = '2')
                </if>
                <if test="param.rzlx != null or param.rzlx != '' and param.rzlx == '1'">
                    and rzzt = '1'
                </if>
                <if test="param.rzlx != null or param.rzlx != '' and param.rzlx == '2'">
                    and rzzt = '2'
                </if>
            </if>
            order by create_time
            ) c where  <![CDATA[rownum<= #{param.pageNum}+#{param.pageCount}]]>
            )  b  where b.r > #{param.pageNum}
        </where>
    </select>
</mapper>
