<?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.tofly.feesapi.sfgl.mapper.YyWyjtzMapper">

    <resultMap id="yyWyjtzMap" type="com.tofly.feesapi.sfgl.entity.YyWyjtz">
        <id property="id" column="ID"/>
        <result property="yhbh" column="YHBH"/>
        <result property="qfid" column="QFID"/>
        <result property="ssgs" column="SSGS"/>
        <result property="ysyf" column="YSYF"/>
        <result property="cwrq" column="CWRQ"/>
        <result property="tzqje" column="TZQJE"/>
        <result property="tzje" column="TZJE"/>
        <result property="tzhje" column="TZHJE"/>
        <result property="tzyy" column="TZYY"/>
        <result property="shry" column="SHRY"/>
        <result property="shyj" column="SHYJ"/>
        <result property="czrybm" column="CZRYBM"/>
        <result property="czryxm" column="CZRYXM"/>
        <result property="czsj" column="CZSJ"/>
        <result property="sfbz" column="SFBZ"/>
        <result property="gdbh" column="GDBH"/>
        <result property="gdzt" column="GDZT"/>
        <result property="cbrq" column="CBRQ"/>
        <result property="yssl" column="YSSL"/>
        <result property="yssf" column="YSSF"/>
        <result property="type" column="TYPE"/>
        <result property="jmyj" column="JMYJ"/>
        <result property="gdlsbh" column="GDLSBH"/>
    </resultMap>

    <select id="getPage" resultType="com.tofly.feesapi.sfgl.entity.vo.YyWyjtzVo">
        select a.id,a.yhbh,b.yhxm,a.cwrq,a.ysyf,a.cbrq,a.yssl,a.yssf,a.tzqje,a.tzje,
        a.tzyy,a.type,a.jmyj,a.qfid,a.gdbh,a.czsj,a.shry,a.czryxm
        from yy_wyjtz a
        left join yh_khjbxx b on a.yhbh=b.yhbh
        where 1=1
        <!--模糊查询 -->
        <if test="dto.searchText!=null">
            AND ( a.yhbh like '%${dto.searchText}%'
            OR b.yhxm like '%${dto.searchText}%'
            OR b.yhdz like '%${dto.searchText}%' )
        </if>

        <if test="dto.sscbb!=null">
            AND a.sscbb = #{dto.sscbb}
        </if>
        <if test="dto.sscbpq!=null">
            AND a.sscbpq = #dto.sscbpq
        </if>
        <if test="dto.yhbh!=null">
            AND a.yhbh = #{dto.yhbh}
        </if>
        <if test="dto.gdzt!=null">
            AND a.gdzt = #{dto.gdzt}
        </if>
        <if test="dto.sfbz!=null">
            AND a.sfbz = #{dto.sfbz}
        </if>
        <if test="dto.ssgs!=null">
            AND b.ssgs = #{dto.ssgs}
        </if>
        <if test="dto.czry!=null">
            AND a.czrybm = #{dto.czry}
        </if>
        <if test="dto.cwrq!=null">
            AND a.cwrq = #{dto.cwrq}
        </if>
        <if test="dto.ysyfStart!=null">
            AND a.ysyf >= #{dto.ysyfStart}
        </if>
        <if test="dto.ysyfEnd!=null">
            AND a.ysyf &lt;= #{dto.ysyfEnd}
        </if>
        <if test="dto.czsjStart!=null and dto.czsjEnd!=null">
            AND a.czsj BETWEEN #{dto.czsjStart} AND #{dto.czsjEnd}
        </if>
    </select>


    <select id="getWyjhj" resultType="com.tofly.feesapi.sfgl.entity.vo.YyQfmxWyjSelect">
        select nvl(sum(a.tzje),0) tzje
        from yy_wyjtz a
        left join yh_khjbxx b on a.yhbh=b.yhbh
        where 1=1
        <!--模糊查询 -->
        <if test="dto.searchText!=null">
            AND ( a.yhbh like '%${dto.searchText}%'
            OR b.yhxm like '%${dto.searchText}%'
            OR b.yhdz like '%${dto.searchText}%' )
        </if>

        <if test="dto.sscbb!=null">
            AND a.sscbb = #{dto.sscbb}
        </if>
        <if test="dto.sscbpq!=null">
            AND a.sscbpq = #dto.sscbpq
        </if>
        <if test="dto.yhbh!=null">
            AND a.yhbh = #{dto.yhbh}
        </if>
        <if test="dto.gdzt!=null">
            AND a.gdzt = #{dto.gdzt}
        </if>
        <if test="dto.sfbz!=null">
            AND a.sfbz = #{dto.sfbz}
        </if>
        <if test="dto.ssgs!=null">
            AND b.ssgs = #{dto.ssgs}
        </if>
        <if test="dto.czry!=null">
            AND a.czrybm = #{dto.czry}
        </if>
        <if test="dto.cwrq!=null">
            AND a.cwrq = #{dto.cwrq}
        </if>
        <if test="dto.ysyfStart!=null">
            AND a.ysyf >= #{dto.ysyfStart}
        </if>
        <if test="dto.ysyfEnd!=null">
            AND a.ysyf &lt;= #{dto.ysyfEnd}
        </if>
        <if test="dto.czsjStart!=null and dto.czsjEnd!=null">
            AND a.czsj BETWEEN #{dto.czsjStart} AND #{dto.czsjEnd}
        </if>
    </select>


    <select id="getGdPage" resultType="com.tofly.feesapi.sfgl.entity.vo.YyWyjtzVo">
        select a.yhbh,b.yhxm,
        (case
        when <![CDATA[ min(a.cwrq)<>max(a.cwrq) ]]> then
        (min(a.cwrq)||'-'||max(a.cwrq))
        else min(a.cwrq)
        end )
        cwrq,
        (case
        when <![CDATA[ min(a.cbrq)<>max(a.cbrq) ]]> then
        (min(to_char(a.cbrq,'yyyy-MM-dd hh24:mi:ss'))||'-'||max(to_char(a.cbrq,'yyyy-MM-dd hh24:mi:ss')))
        else min(to_char(a.cbrq,'yyyy-MM-dd hh24:mi:ss'))
        end )cbrq,
        sum(nvl(a.yssl,0)) yssl,
        sum(nvl(a.yssf,0))yssf,
        sum(nvl(a.tzqje,0))tzqje,
        sum(nvl(a.tzje,0))tzje,
        sum(nvl(c.znj,0)) znj,
        a.jmyj,
        a.gdlsbh,
        a.gdbh,
        a.tzyy,
        a.type,
        count(a.id) countnum
        from yy_wyjtz a
        left join yh_khjbxx b on a.yhbh=b.yhbh
        left join yy_qfmx c on a.qfid=c.id
        where 1=1
        <!--模糊查询 -->
        <if test="dto.searchText!=null">
            AND ( a.yhbh like '%${dto.searchText}%'
            OR b.yhxm like '%${dto.searchText}%'
            OR b.yhdz like '%${dto.searchText}%' )
        </if>
        <if test="dto.gdzt!=null">
            AND a.gdzt = #{dto.gdzt}
        </if>
        <if test="dto.sfbz!=null">
            AND a.sfbz = #{dto.sfbz}
        </if>
        <if test="dto.ssgs!=null">
            AND b.ssgs = #{dto.ssgs}
        </if>
        <if test="dto.sscbpq!=null">
            AND b.sscbpq = #dto.sscbpq
        </if>
        <if test="dto.sscbb!=null">
            AND b.sscbb = #{dto.sscbb}
        </if>
        <if test="dto.qyfzr!=null">
            AND b.sscbb in (select cbbbm from bm_cbb where qyfzr=#{dto.qyfzr})
        </if>
        <if test="dto.gdlsbh!=null">
            AND a.gdlsbh = #{dto.gdlsbh}
        </if>
        group by a.yhbh,b.yhxm,a.gdlsbh,a.gdbh,a.tzyy,a.type,a.jmyj
    </select>
</mapper>
