<?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.rlzysc.entity.VRsRlzyQytjMapper">

    <select id="getSyzdqyglList" parameterType="com.zjrs.zwnw.rlzysc.dto.SyzdqyglQueryDTO" resultType="HashMap">
        select t.gsmc as "gsmc",
        t.tyshxydm as "tyshxydm",
        t.tjzt as "tjzt",
        t.rs_rlzy_qyxx_lsh as "rsrlzyqyxxlsh",
        (case
        when t.tjzt = '1' then
        (select user_name
        from v_rs_sy_org_area p, v_rs_rlzy_qytj q
        where p.user_id = q.bae004
        and q.rs_rlzy_qyxx_lsh = t.rs_rlzy_qyxx_lsh)
        else
        ''
        end)  as "bae004",
        (case
        when t.tjzt = '1' then
        (select q.bae005 from  v_rs_rlzy_qytj q
        where q.rs_rlzy_qyxx_lsh = t.rs_rlzy_qyxx_lsh)
        else
        ''
        end)  as "bae005",
        (case
        when t.tjzt = '1' then
        (select max(org_name)
        from v_rs_sy_org_area p, v_rs_rlzy_qytj q
        where p.org_id = q.bae006
        and q.rs_rlzy_qyxx_lsh = t.rs_rlzy_qyxx_lsh)
        else
        ''
        end)  as "bae006"
        from (select v.aab004 as gsmc,
        v.aab998 as tyshxydm,
        f.rs_rlzy_qyxx_lsh,
        (select decode(count(e.rs_rlzy_qytj_lsh), 0, '0', '1')
        from v_rs_rlzy_qytj e
        where e.rs_rlzy_qyxx_lsh = f.rs_rlzy_qyxx_lsh and e.ts_yxbz = '1') tjzt
        from (select *
        from (select c.aab004,
        c.aab013,
        c.aae005,
        c.aab998,
        b.userid useridcode,
        (select decode(count(d.rs_rlzy_hmdgl_lsh),0,'1','2') from v_rs_rlzy_hmdgl d
        where d.rs_rlzy_ts_lsh = b.userid
        and d.ts_yxbz = '1') zt
        from rs_ggfw_user b, v_s_ab01 c
        where b.fwdx = '2'
        and b.ztid = c.ztid)
        where zt = '1') v,
        v_rs_rlzy_qyxx f
        where v.useridcode = f.rs_yhlsh
<!--        and f.qyxx_shzt = '1'-->
        ) t where 1=1
        <if test="dto.tyshxydm != null and dto.tyshxydm != ''">
            and t.tyshxydm = #{dto.tyshxydm}
        </if>
    </select>

</mapper>
