<?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.HmdglMapper">
    <select id="getHmdglGrList" parameterType="com.zjrs.zwnw.rlzysc.dto.HmdGrQueryDTO" resultType="HashMap">
        select e.aac003 as "aac003",
        e.aac147 as "aac147",
        e.aac067 as "aac067",
        e.zt as "zt",
        e.lhyy as "lhyy",
        e.useridcode as "useridcode",
        (select max(org_name)
        from v_rs_sy_org_area
        where org_id = e.bae001) as "bae001",
        (select user_name
        from v_rs_sy_org_area
        where user_id = e.bae002) as "bae002",
        e.bae003 as "bae003",
        (select user_name
        from v_rs_sy_org_area
        where user_id = e.bae004) as "bae004",
        e.bae005 as "bae005",
        (select max(org_name)
        from v_rs_sy_org_area
        where org_id = e.bae006) as "bae006"
        from (select v.*,
        (select decode(count(d.rs_rlzy_hmdgl_lsh), 0, '1', '2')
        from v_rs_rlzy_hmdgl d
        where d.rs_rlzy_ts_lsh = v.useridcode
        and d.ts_yxbz = '1') zt,
        w.bae001,
        w.bae002,
        w.bae003,
        w.bae004,
        w.bae005,
        w.bae006,
        w.lhyy
        from (select c.aac003,
        c.aac058,
        c.aac147,
        c.aac067,
        b.userid useridcode
        from rs_ggfw_user b, v_s_ac01 c
        where b.fwdx = '1'
        and b.ztid = c.ztid) v,
        v_rs_rlzy_hmdgl w
        where w.rs_rlzy_ts_lsh(+) = v.useridcode) e
        where 1=1
        <if test="dto.idcardtype != null and dto.idcardtype != ''">
            and e.aac147 = #{dto.idcardtype}
        </if>
    </select>

    <select id="getHmdglDwList" parameterType="com.zjrs.zwnw.rlzysc.dto.HmdDwQueryDTO" resultType="HashMap">
        select e.aab013 as "aab013",
        e.aab004 as "aab004",
        e.aae005 as "aae005",
        e.zt as "zt",
        e.lhyy as "lhyy",
        e.useridcode as "useridcode",
        (select max(org_name)
        from v_rs_sy_org_area
        where org_id = e.bae001) as "bae001",
        (select user_name
        from v_rs_sy_org_area
        where user_id = e.bae002) as "bae002",
        e.bae003 as "bae003",
        (select user_name
        from v_rs_sy_org_area
        where user_id = e.bae004) as "bae004",
        e.bae005 as "bae005",
        (select max(org_name)
        from v_rs_sy_org_area
        where org_id = e.bae006) as "bae006"
        from (select v.*,
        (select decode(count(d.rs_rlzy_hmdgl_lsh), 0, '1', '2')
        from v_rs_rlzy_hmdgl d
        where d.rs_rlzy_ts_lsh = v.useridcode
        and d.ts_yxbz = '1') zt,
        w.bae001,
        w.bae002,
        w.bae003,
        w.bae004,
        w.bae005,
        w.bae006,
        w.lhyy
        from (select c.aab004,
        c.aab013,
        c.aae005,
        c.aab998,
        b.userid useridcode
        from rs_ggfw_user b, v_s_ab01 c
        where b.fwdx = '2'
        and b.ztid = c.ztid) v,
        v_rs_rlzy_hmdgl w
        where w.rs_rlzy_ts_lsh(+) = v.useridcode) e
        where 1 = 1
        <if test="dto.idcardtype != null and dto.idcardtype != ''">
            and e.aab998 = #{dto.idcardtype}
        </if>
        <if test="dto.cn != null and dto.cn != ''">
            and e.aab004 like '%${ dto.cn }%'
        </if>
        <if test="dto.zt != null and dto.zt != ''">
            and e.zt = #{dto.zt}
        </if>
    </select>

</mapper>
