<?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.zjrs.zwnw.bsdb.entity.DbgzMapper">

    <select id="queryDbglRuleSelectList"
            parameterType="com.zjrs.zwnw.bsdb.dto.DbglPageQueryDTO"
            resultType="com.zjrs.zwnw.bsdb.dto.DbglDTO">
        select
            rs_bsdb_dbsx_lsh as "rsbsdbdbsxlsh",
            ywlsh,
            sllsh,
            rs_bsdb_sxlx as "rsbsdbsxlx",
            rs_bsdb_sxmc as "rsbsdbsxmc",
            rs_bsdb_sxjjzt as "rsbsdbsxjjzt",
            rs_bsdb_fzdw as "rsbsdbfzdw",
            f_common_getSSgUser(fzr) as "fzr",
            f_common_getSSgUser(dbr) as "dbr",
            rs_bsdb_fbzt as "rsbsdbfbzt",
            rs_bsdb_jdzt as "rsbsdbjdzt",
            rs_bsdb_pfzt as "rsbsdbpfzt",
            bae003
        from rs_bsdb_dbsx a
        where        
        <if test="dto.rsbsdbsxlx != null and dto.rsbsdbsxlx != ''">
            a.rs_bsdb_sxlx = #{ dto.rsbsdbsxlx }
        </if>
        order by a.bae005 desc
    </select>

    <select id="queryDbglRuleList"
            parameterType="com.zjrs.zwnw.bsdb.dto.DbglPageQueryDTO"
            resultType="com.zjrs.zwnw.bsdb.dto.DbglDTO">
        select
        a.rs_bsdb_dbsx_lsh as "rsbsdbdbsxlsh",
        b.rs_bsdb_dbgz_lsh as "rsbsdbdbgzlsh",
        ywlsh,
        sllsh,
        rs_bsdb_sxlx as "rsbsdbsxlx",
        rs_bsdb_sxmc as "rsbsdbsxmc",
        rs_bsdb_sxjjzt as "rsbsdbsxjjzt",
        (select org_name from s_sg_org a where a.id = rs_bsdb_fzdw) as "rsbsdbfzdw",
        fzr,
        dbr,
        rs_bsdb_fbzt as "rsbsdbfbzt",
        rs_bsdb_jdzt as "rsbsdbjdzt",
        rs_bsdb_pfzt as "rsbsdbpfzt",
        a.bae003,
        b.blsx,
        b.yellow_bz as "yellowbz",
        b.red_bz as "redbz"
        from rs_bsdb_dbsx a, rs_bsdb_dbgz b
        where
        a.rs_bsdb_dbsx_lsh = b.rs_bsdb_dbsx_lsh
        <if test="dto.rsbsdbdbsxlsh != null and dto.rsbsdbdbsxlsh != ''">
            and a.rs_bsdb_dbsx_lsh = #{ dto.rsbsdbdbsxlsh }
        </if>
        order by a.bae003 desc
    </select>

    <select id="queryDbglRule"
            parameterType="com.zjrs.zwnw.bsdb.dto.DbglRuleQueryDTO"
            resultType="com.zjrs.zwnw.bsdb.dto.DbglDTO">
        select
        a.rs_bsdb_dbsx_lsh as "rsbsdbdbsxlsh",
        b.rs_bsdb_dbgz_lsh as "rsbsdbdbgzlsh",
        ywlsh,
        sllsh,
        rs_bsdb_sxlx as "rsbsdbsxlx",
        rs_bsdb_sxmc as "rsbsdbsxmc",
        rs_bsdb_sxjjzt as "rsbsdbsxjjzt",
        rs_bsdb_fzdw as "rsbsdbfzdw",
        f_common_getSSgUser(fzr) as "fzr",
        f_common_getSSgUser(dbr) as "dbr",
        rs_bsdb_fbzt as "rsbsdbfbzt",
        rs_bsdb_jdzt as "rsbsdbjdzt",
        rs_bsdb_pfzt as "rsbsdbpfzt",
        a.bae003,
        b.blsx,
        b.yellow_bz as "yellowbz",
        b.red_bz as "redbz"
        from rs_bsdb_dbsx a, rs_bsdb_dbgz b
        where
        a.rs_bsdb_dbsx_lsh = b.rs_bsdb_dbsx_lsh
        and b.rs_bsdb_dbgz_lsh = #{dto.rsbsdbdbgzlsh}
        order by a.bae005 desc
    </select>

    <select id="queryDbglDbrwList"
            parameterType="com.zjrs.zwnw.bsdb.dto.DbglPageQueryDTO"
            resultType="com.zjrs.zwnw.bsdb.dto.DbglDTO">
        select
        t.rs_bsdb_dbsx_lsh as "rsbsdbdbsxlsh",
        t.rs_bsdb_dbgz_lsh as "rsbsdbdbgzlsh",
        t.ywlsh,
        t.sllsh,
        t.rs_bsdb_sxlx as "rsbsdbsxlx",
        t.rs_bsdb_sxmc as "rsbsdbsxmc",
        t.rs_bsdb_sxjjzt as "rsbsdbsxjjzt",
        f_common_getSSgUserOrg(t.rs_bsdb_fzdw ) as "rsbsdbfzdw",
        t.fzr,
        t.dbr,
        t.rs_bsdb_fbzt as "rsbsdbfbzt",
        t.rs_bsdb_jdzt as "rsbsdbjdzt",
        t.bae003,
        t.blsx,
        t.yellow_bz as "yellowbz",
        t.red_bz as "redbz",
        t.rs_bsdb_pfsj as "rsbsdbpfsj",
        t.cqsj as "cqsj",
        t.rs_bsdb_fkzt as "rsbsdbfkzt",
        '1' cqzt,
        t.rs_bsdb_pfzt as "rsbsdbpfzt"
        from (
        select
            a.rs_bsdb_dbsx_lsh,
            b.rs_bsdb_dbgz_lsh,
            ywlsh,
            sllsh,
            rs_bsdb_sxlx,
            rs_bsdb_sxmc,
            rs_bsdb_sxjjzt,
            rs_bsdb_fzdw,
            f_common_getSSgUser(fzr) fzr,
            f_common_getSSgUser(dbr) dbr,
            fzr fzrid,
            dbr dbrid,
            a.rs_bsdb_pfsj,
            a.rs_bsdb_fbzt,
            a.rs_bsdb_jdzt,
            a.bae003,
            a.bae005,
            b.blsx,
            b.yellow_bz,
            b.red_bz,
            a.rs_bsdb_fkzt,
            f_common_getTimeoutDay(a.rs_bsdb_pfsj) cqsj,
            a.rs_bsdb_pfzt
        from rs_bsdb_dbsx a, rs_bsdb_dbgz b
        where
        a.rs_bsdb_dbsx_lsh = b.rs_bsdb_dbsx_lsh
        ) t
        <where>
            <trim prefixOverrides="and">
                <if test="dto.rsbsdbdbsxlsh != null and dto.rsbsdbdbsxlsh != ''">
                    and t.rs_bsdb_dbsx_lsh = #{ dto.rsbsdbdbsxlsh }
                </if>
                <if test="dto.rsbsdbsxlx != null and dto.rsbsdbsxlx != ''">
                    and t.rs_bsdb_sxlx = #{ dto.rsbsdbsxlx }
                </if>
                <if test="dto.rsbsdbsxmc != null and dto.rsbsdbsxmc != ''">
                    and t.rs_bsdb_sxmc like '%'||#{ dto.rsbsdbsxmc }||'%'
                </if>
                <if test="dto.rsbsdbsxjjzt != null and dto.rsbsdbsxjjzt != ''">
                    and t.rs_bsdb_sxjjzt = #{ dto.rsbsdbsxjjzt }
                </if>
                <if test="dto.rsbsdbfbzt != null and dto.rsbsdbfbzt != ''">
                    and t.rs_bsdb_fbzt = #{ dto.rsbsdbfbzt }
                </if>
                <if test="dto.fzr != null and dto.fzr != ''">
                    and t.fzrid = #{ dto.fzr }
                </if>
                <if test="dto.rsbsdbfkzt != null and dto.rsbsdbfkzt != ''">
                    and t.rs_bsdb_fkzt = #{ dto.rsbsdbfkzt }
                </if>
            </trim>
        </where>
        order by t.bae005 desc
    </select>

    <select id="queryDbglTaskList"
            parameterType="com.zjrs.zwnw.bsdb.dto.DbglPageQueryDTO"
            resultType="com.zjrs.zwnw.bsdb.dto.DbglDTO">
        select
        t.rs_bsdb_dbsx_lsh as "rsbsdbdbsxlsh",
        t.rs_bsdb_dbgz_lsh as "rsbsdbdbgzlsh",
        t.ywlsh,
        t.sllsh,
        t.rs_bsdb_sxlx as "rsbsdbsxlx",
        t.rs_bsdb_sxmc as "rsbsdbsxmc",
        t.rs_bsdb_sxjjzt as "rsbsdbsxjjzt",
        f_common_getSSgUserOrg(t.rs_bsdb_fzdw ) as "rsbsdbfzdw",
        t.fzr,
        t.dbr,
        t.rs_bsdb_fbzt as "rsbsdbfbzt",
        t.rs_bsdb_jdzt as "rsbsdbjdzt",
        t.bae003,
        t.blsx,
        t.yellow_bz as "yellowbz",
        t.red_bz as "redbz",
        t.rs_bsdb_pfsj as "rsbsdbpfsj",
        t.cqsj as "cqsj",
        t.rs_bsdb_fkzt as "rsbsdbfkzt",
        '1' cqzt,
        t.rs_bsdb_pfzt as "rsbsdbpfzt"
        from (
        select
        a.rs_bsdb_dbsx_lsh,
        b.rs_bsdb_dbgz_lsh,
        ywlsh,
        sllsh,
        rs_bsdb_sxlx,
        rs_bsdb_sxmc,
        rs_bsdb_sxjjzt,
        rs_bsdb_fzdw,
        f_common_getSSgUser(fzr) fzr,
        f_common_getSSgUser(dbr) dbr,
        fzr fzrid,
        dbr dbrid,
        a.rs_bsdb_pfsj,
        a.rs_bsdb_fbzt,
        a.rs_bsdb_jdzt,
        a.bae003,
        a.bae005,
        b.blsx,
        b.yellow_bz,
        b.red_bz,
        a.rs_bsdb_fkzt,
        f_common_getTimeoutDay(a.rs_bsdb_pfsj) cqsj,
        a.rs_bsdb_pfzt,
        (to_date(rs_bsdb_pfsj,'yyyy-mm-dd,hh24:mi:ss') + to_number(blsx)) jzsj
        from rs_bsdb_dbsx a, rs_bsdb_dbgz b
        where
        a.rs_bsdb_dbsx_lsh = b.rs_bsdb_dbsx_lsh
        ) t
        <where>
            <trim prefixOverrides="and">
                <if test="dto.rsbsdbdbsxlsh != null and dto.rsbsdbdbsxlsh != ''">
                    and t.rs_bsdb_dbsx_lsh = #{ dto.rsbsdbdbsxlsh }
                </if>
                <if test="dto.rsbsdbsxlx != null and dto.rsbsdbsxlx != ''">
                    and t.rs_bsdb_sxlx = #{ dto.rsbsdbsxlx }
                </if>
            </trim>
        </where>
        order by t.jzsj asc
    </select>
</mapper>
