<?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="org.springblade.modules.mapper.SyryMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="blogResultMap" type="org.springblade.modules.entity.SyryEntity">
        <result column="id" property="id"/>
    </resultMap>

    <select id="getFwry" resultType="org.springblade.modules.entity.SyryEntity">
        SELECT
            *
        FROM
            (
                SELECT
                    cz.id,
                    cz.fw_id AS fwId,
                    cz.ry_xm AS ryXm,
                    cz.ry_xb AS ryXb,
                    cz.dzbm AS dzbm,
                    '常住人口' AS ryType,
                    cz.ry_sfzh AS rySfzh,
                    cz.ry_dh AS ryDh,
                    cz.ry_hzgx AS ryHzgx,
                    cz.ry_hyzk AS ryHyzk,
                    cz.ry_whcd AS ryWhcd,
                    cz.ry_zzmm AS ryZzmm,
                    cz.ry_byzk AS ryByzk,
                    cz.zjxy,
                    cz.ry_ts_lb AS ryTsLb,
                    cz.ry_ts_jtqk AS ryTsJtqk,
                    cz.ry_mz_dm AS ryMzDm,
                    cz.ry_hyzk_dm AS ryHyzkDm,
                    cz.ry_whcd_dm AS ryWhcdDm,
                    cz.ry_zzmm_dm AS ryZzmmDm,
                    cz.ry_byzk_dm AS ryByzkDm,
                    cz.zjxy_dm AS zjxyDm,
                    cz.dw_mc AS dwMc,
                    cz.dw_lb AS dwLb,
                    cz.dw_dz AS dwDz,
                    cz.dw_xz AS dwXz,
                    cz.vx,
                    cz.ry_zp AS ryZp,
                    cz.bz AS bz,
                    cz.create_user,
                    cz.create_time,
                    cz.update_user,
                    cz.update_time,
                    sj.id as sjid,
                    fj.id as fjid,
                    pcs.id as pcsid,
                    sq.id as sqid,
                    cz.status,
                    cz.update_dept AS updateDept,
                    cz.new_dzbm AS newDzbm,
                    cz.new_fw_id AS newFwId,
                    dept.dept_name AS updateDeptName
                FROM
                    jdrh.rhzf_ry_czrk cz
                LEFT JOIN jdrh.blade_dept sq ON sq.id = cz.create_dept
                LEFT JOIN jdrh.blade_dept dept ON dept.id :: text = cz.update_dept
                LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
                LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
                LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
                WHERE
                    cz.is_deleted = 0
                    and (sq.id = #{params.deptId} :: int8 or sq.ancestors like '%' || #{params.deptId} || '%')
                UNION ALL
                SELECT
                    jw.id,
                    jw.fw_id AS fwId,
                    jw.ry_mz || ' ' || jw.ry_xs AS ryXm,
                    jw.ry_xb AS ryXb,
                    jw.dzbm AS dzbm,
                    '境外人口' AS ryType,
                    jw.ry_zjhm AS rySfzh,
                    jw.ry_dh AS ryDh,
                    '' AS ryHzgx,
                    '' AS ryHyzk,
                    '' AS ryWhcd,
                    '' AS ryZzmm,
                    '' AS ryByzk,
                    jw.zjxy,
                    jw.ry_ts_lb AS ryTsLb,
                    jw.ry_ts_jtqk AS ryTsJtqk,
                    '' AS ryMzDm,
                    '' AS ryHyzkDm,
                    '' AS ryWhcdDm,
                    '' AS ryZzmmDm,
                    '' AS ryByzkDm,
                    jw.zjxy_dm AS zjxyDm,
                    jw.dw_mc AS dwMc,
                    jw.dw_lb AS dwLb,
                    jw.dw_dz AS dwDz,
                    jw.dw_xz AS dwXz,
                    jw.vx,
                    jw.ry_zp AS ryZp,
                    jw.bz AS bz,
                    jw.create_user,
                    jw.create_time,
                    jw.update_user,
                    jw.update_time,
                    sj.id as sjid,
                    fj.id as fjid,
                    pcs.id as pcsid,
                    sq.id as sqid,
                    jw.status,
                    jw.update_dept AS updateDept,
                    jw.new_dzbm AS newDzbm,
                    jw.new_fw_id AS newFwId,
                    dept.dept_name AS updateDeptName
                FROM
                    jdrh.rhzf_ry_jwrk jw
                LEFT JOIN jdrh.blade_dept sq ON sq.id = jw.create_dept
                LEFT JOIN jdrh.blade_dept dept ON dept.id :: text = jw.update_dept
                LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
                LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
                LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
                WHERE
                    jw.is_deleted = 0
                    and (sq.id = #{params.deptId} :: int8 or sq.ancestors like '%' || #{params.deptId} || '%')
                UNION ALL
                SELECT
                    jz.id,
                    jz.fw_id AS fwId,
                    jz.ry_xm AS ryXm,
                    jz.ry_xb AS ryXb,
                    jz.dzbm AS dzbm,
                    '寄住人口' AS ryType,
                    jz.ry_sfzh AS rySfzh,
                    jz.ry_dh AS ryDh,
                    jz.ry_hzgx AS ryHzgx,
                    jz.ry_hyzk AS ryHyzk,
                    jz.ry_whcd AS ryWhcd,
                    jz.ry_zzmm AS ryZzmm,
                    jz.ry_byzk AS ryByzk,
                    jz.zjxy,
                    jz.ry_ts_lb AS ryTsLb,
                    jz.ry_ts_jtqk AS ryTsJtqk,
                    jz.ry_mz_dm AS ryMzDm,
                    jz.ry_hyzk_dm AS ryHyzkDm,
                    jz.ry_whcd_dm AS ryWhcdDm,
                    jz.ry_zzmm_dm AS ryZzmmDm,
                    jz.ry_byzk_dm AS ryByzkDm,
                    jz.zjxy_dm AS zjxyDm,
                    jz.dw_mc AS dwMc,
                    jz.dw_lb AS dwLb,
                    jz.dw_dz AS dwDz,
                    jz.dw_xz AS dwXz,
                    jz.vx,
                    jz.ry_zp AS ryZp,
                    jz.bz AS bz,
                    jz.create_user,
                    jz.create_time,
                    jz.update_user,
                    jz.update_time,
                    sj.id as sjid,
                    fj.id as fjid,
                    pcs.id as pcsid,
                    sq.id as sqid,
                    jz.status,
                    jz.update_dept AS updateDept,
                    jz.new_dzbm AS newDzbm,
                    jz.new_fw_id AS newFwId,
                    dept.dept_name AS updateDeptName
                FROM
                    jdrh.rhzf_ry_jzrk jz
                LEFT JOIN jdrh.blade_dept sq ON sq.id = jz.create_dept
                LEFT JOIN jdrh.blade_dept dept ON dept.id :: text = jz.update_dept
                LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
                LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
                LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
                WHERE
                    jz.is_deleted = 0
                    and (sq.id = #{params.deptId} :: int8 or sq.ancestors like '%' || #{params.deptId} || '%')
                UNION ALL
                SELECT
                    wl.id,
                    wl.fw_id AS fwId,
                    wl.ry_xm AS ryXm,
                    wl.ry_xb AS ryXb,
                    wl.dzbm AS dzbm,
                    '未落人口' AS ryType,
                    wl.ry_sfzh AS rySfzh,
                    wl.ry_dh AS ryDh,
                    wl.ry_hzgx AS ryHzgx,
                    wl.ry_hyzk AS ryHyzk,
                    wl.ry_whcd AS ryWhcd,
                    wl.ry_zzmm AS ryZzmm,
                    wl.ry_byzk AS ryByzk,
                    wl.zjxy,
                    wl.ry_ts_lb AS ryTsLb,
                    wl.ry_ts_jtqk AS ryTsJtqk,
                    wl.ry_mz_dm AS ryMzDm,
                    wl.ry_hyzk_dm AS ryHyzkDm,
                    wl.ry_whcd_dm AS ryWhcdDm,
                    wl.ry_zzmm_dm AS ryZzmmDm,
                    wl.ry_byzk_dm AS ryByzkDm,
                    wl.zjxy_dm AS zjxyDm,
                    wl.dw_mc AS dwMc,
                    wl.dw_lb AS dwLb,
                    wl.dw_dz AS dwDz,
                    wl.dw_xz AS dwXz,
                    wl.vx,
                    wl.ry_zp AS ryZp,
                    wl.bz AS bz,
                    wl.create_user,
                    wl.create_time,
                    wl.update_user,
                    wl.update_time,
                    sj.id as sjid,
                    fj.id as fjid,
                    pcs.id as pcsid,
                    sq.id as sqid,
                    wl.status,
                    wl.update_dept AS updateDept,
                    wl.new_dzbm AS newDzbm,
                    wl.new_fw_id AS newFwId,
                    dept.dept_name AS updateDeptName
                FROM
                    jdrh.rhzf_ry_wlrk wl
                LEFT JOIN jdrh.blade_dept sq ON sq.id = wl.create_dept
                LEFT JOIN jdrh.blade_dept dept ON dept.id :: text = wl.update_dept
                LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
                LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
                LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
                WHERE
                    wl.is_deleted = 0
                    and (sq.id = #{params.deptId} :: int8 or sq.ancestors like '%' || #{params.deptId} || '%')
                UNION ALL
                SELECT
                    zz.id,
                    zz.fw_id AS fwId,
                    zz.ry_xm AS ryXm,
                    zz.ry_xb AS ryXb,
                    zz.dzbm AS dzbm,
                    '暂住人口' AS ryType,
                    zz.ry_sfzh AS rySfzh,
                    zz.ry_dh AS ryDh,
                    zz.ry_hzgx AS ryHzgx,
                    zz.ry_hyzk AS ryHyzk,
                    zz.ry_whcd AS ryWhcd,
                    zz.ry_zzmm AS ryZzmm,
                    zz.ry_byzk AS ryByzk,
                    zz.zjxy,
                    zz.ry_ts_lb AS ryTsLb,
                    zz.ry_ts_jtqk AS ryTsJtqk,
                    zz.ry_mz_dm AS ryMzDm,
                    zz.ry_hyzk_dm AS ryHyzkDm,
                    zz.ry_whcd_dm AS ryWhcdDm,
                    zz.ry_zzmm_dm AS ryZzmmDm,
                    zz.ry_byzk_dm AS ryByzkDm,
                    zz.zjxy_dm AS zjxyDm,
                    zz.dw_mc AS dwMc,
                    zz.dw_lb AS dwLb,
                    zz.dw_dz AS dwDz,
                    zz.dw_xz AS dwXz,
                    zz.vx,
                    zz.ry_zp AS ryZp,
                    zz.bz AS bz,
                    zz.create_user,
                    zz.create_time,
                    zz.update_user,
                    zz.update_time,
                    sj.id as sjid,
                    fj.id as fjid,
                    pcs.id as pcsid,
                    sq.id as sqid,
                    zz.status,
                    zz.update_dept AS updateDept,
                    zz.new_dzbm AS newDzbm,
                    zz.new_fw_id AS newFwId,
                    dept.dept_name AS updateDeptName
                FROM
                    jdrh.rhzf_ry_zzrk zz
                LEFT JOIN jdrh.blade_dept sq ON sq.id = zz.create_dept
                LEFT JOIN jdrh.blade_dept dept ON dept.id :: text = zz.update_dept
                LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
                LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
                LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
                WHERE
                    zz.is_deleted = 0
                    and (sq.id = #{params.deptId} :: int8 or sq.ancestors like '%' || #{params.deptId} || '%')
            ) rys
            where 1 = 1
            <if test="params.rySfzh != null and params.rySfzh != ''">
                and rys.rySfzh = #{params.rySfzh}
            </if>
            <if test="params.ryXm != null and params.ryXm != ''">
                and rys.ryXm = #{params.ryXm}
            </if>
            <if test="params.ryXb != null and params.ryXb != ''">
                and rys.ryXb = #{params.ryXb}
            </if>
            <if test="params.ryDh != null and params.ryDh != ''">
                and rys.ryDh = #{params.ryDh}
            </if>
            <if test="params.ryType != null and params.ryType != ''">
                and rys.ryType = #{params.ryType}
            </if>
    </select>

    <select id="getFwxzByRkDzxx" resultType="java.lang.String">
        select xz from sspt.rk_dzxx where dzbm = #{dzbm} limit 1
    </select>

    <select id="fwryCzrkDetail" resultType="org.springblade.modules.vo.CzrkVO">
        select
            czrk.*,
            '常住人口' as ryType,
            bu.account,
            bu.name,
            bu.sfzh,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bu.dept_id :: int8) as sssq,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bd.parent_id) as sspcs
        from jdrh.rhzf_ry_czrk czrk
        left join blade_user bu on bu.id = czrk.create_user
        left join jdrh.blade_dept bd on bd.id = czrk.create_dept
        where czrk.is_deleted = 0 and czrk.id = #{id}
    </select>

    <select id="fwryJwrkDetail" resultType="org.springblade.modules.vo.JwrkVO">
        select
            jwrk.*,
            '境外人口' as ryType,
            bu.account,
            bu.name,
            bu.sfzh,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bu.dept_id :: int8) as sssq,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bd.parent_id) as sspcs
        from jdrh.rhzf_ry_jwrk jwrk
        left join blade_user bu on bu.id = jwrk.create_user
        left join jdrh.blade_dept bd on bd.id = jwrk.create_dept
        where jwrk.is_deleted = 0 and jwrk.id = #{id}
    </select>

    <select id="fwryJzrkDetail" resultType="org.springblade.modules.vo.JzrkVO">
        select
            jzrk.*,
            '寄住人口' as ryType,
            bu.account,
            bu.name,
            bu.sfzh,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bu.dept_id :: int8) as sssq,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bd.parent_id) as sspcs
        from jdrh.rhzf_ry_jzrk jzrk
        left join blade_user bu on bu.id = jzrk.create_user
        left join jdrh.blade_dept bd on bd.id = jzrk.create_dept
        where jzrk.is_deleted = 0 and jzrk.id = #{id}
    </select>

    <select id="fwryWlrkDetail" resultType="org.springblade.modules.vo.WlrkVO">
        select
            wlrk.*,
            '未落人口' as ryType,
            bu.account,
            bu.name,
            bu.sfzh,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bu.dept_id :: int8) as sssq,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bd.parent_id) as sspcs
        from jdrh.rhzf_ry_wlrk wlrk
        left join blade_user bu on bu.id = wlrk.create_user
        left join jdrh.blade_dept bd on bd.id = wlrk.create_dept
        where wlrk.is_deleted = 0 and wlrk.id = #{id}
    </select>

    <select id="fwryZzrkDetail" resultType="org.springblade.modules.vo.ZzrkVO">
        select
            zzrk.*,
            '暂住人口' as ryType,
            bu.account,
            bu.name,
            bu.sfzh,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bu.dept_id :: int8) as sssq,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bd.parent_id) as sspcs
        from jdrh.rhzf_ry_zzrk zzrk
        left join blade_user bu on bu.id = zzrk.create_user
        left join jdrh.blade_dept bd on bd.id = zzrk.create_dept
        where zzrk.is_deleted = 0 and zzrk.id = #{id}
    </select>

    <select id="selectDictBiz" resultType="java.lang.String">
        select dict_value from jdrh.blade_dict_biz where code = 'tsrq' and dict_key :: text = #{tsrq}
    </select>

    <select id="djxx" resultType="org.springblade.modules.vo.UserVO">
        select
            bu.account,
            bu.name,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bu.dept_id :: int8) as sssq,
            (select dept_name from jdrh.blade_dept where blade_dept.id = bd.parent_id) as sspcs
        from blade_user bu
        left join jdrh.blade_dept bd on bu.dept_id :: int8 = bd.id
        where bu.is_deleted = 0 and bu.id = #{id}
    </select>

    <update id="updateFwId">
        UPDATE jdrh.rhzf_fw_ry
        SET fw_id = #{fwId},
            update_time = now()
        WHERE
            dzbm = #{dzbm}
          AND ry_type = #{ryType}
          AND ry_id = #{ryId}
    </update>

    <select id="cyryCzrkDetail" resultType="org.springblade.modules.vo.CzrkVO">
        select
            czrk.*,
            '常住人口' as ryType,
            ( select zy from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = czrk.ry_sfzh ) as zy,
            ( select zylb from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = czrk.ry_sfzh ) as zylb
        from jdrh.rhzf_ry_czrk czrk
        where czrk.is_deleted = 0 and czrk.ry_sfzh = #{gmsfhm}
    </select>

    <select id="cyryJwrkDetail" resultType="org.springblade.modules.vo.JwrkVO">
        select
            jwrk.*,
            '境外人口' as ryType,
            ( select zy from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = jwrk.ry_zjhm ) as zy,
            ( select zylb from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = jwrk.ry_zjhm ) as zylb
        from jdrh.rhzf_ry_jwrk jwrk
        where jwrk.is_deleted = 0 and jwrk.ry_zjhm = #{gmsfhm}
    </select>

    <select id="cyryJzrkDetail" resultType="org.springblade.modules.vo.JzrkVO">
        select
            jzrk.*,
            '寄住人口' as ryType,
            ( select zy from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = jzrk.ry_sfzh ) as zy,
            ( select zylb from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = jzrk.ry_sfzh ) as zylb
        from jdrh.rhzf_ry_jzrk jzrk
        where jzrk.is_deleted = 0 and jzrk.ry_sfzh = #{gmsfhm}
    </select>

    <select id="cyryWlrkDetail" resultType="org.springblade.modules.vo.WlrkVO">
        select
            wlrk.*,
            '未落人口' as ryType,
            ( select zy from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = wlrk.ry_sfzh ) as zy,
            ( select zylb from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = wlrk.ry_sfzh ) as zylb
        from jdrh.rhzf_ry_wlrk wlrk
        where wlrk.is_deleted = 0 and wlrk.ry_sfzh = #{gmsfhm}
    </select>

    <select id="cyryZzrkDetail" resultType="org.springblade.modules.vo.ZzrkVO">
        select
            zzrk.*,
            '暂住人口' as ryType,
            ( select zy from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = zzrk.ry_sfzh ) as zy,
            ( select zylb from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = zzrk.ry_sfzh ) as zylb
        from jdrh.rhzf_ry_zzrk zzrk
        where zzrk.is_deleted = 0 and zzrk.ry_sfzh = #{gmsfhm}
    </select>

    <select id="cyrylsCzrkDetail" resultType="org.springblade.modules.vo.CzrkVO">
        select
            czrk.*,
            '常住人口' as ryType,
            ( select zy from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = czrk.ry_sfzh ) as zy,
            ( select zylb from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = czrk.ry_sfzh ) as zylb
        from jdrh.rhzf_ry_czrk czrk
        where czrk.is_deleted = 1 and czrk.ry_sfzh = #{gmsfhm} and czrk.dzbm = #{dzbm}
    </select>

    <select id="cyrylsJwrkDetail" resultType="org.springblade.modules.vo.JwrkVO">
        select
            jwrk.*,
            '境外人口' as ryType,
            ( select zy from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = jwrk.ry_zjhm ) as zy,
            ( select zylb from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = jwrk.ry_zjhm ) as zylb
        from jdrh.rhzf_ry_jwrk jwrk
        where jwrk.is_deleted = 1 and jwrk.ry_zjhm = #{gmsfhm} and jwrk.dzbm = #{dzbm}
    </select>

    <select id="cyrylsJzrkDetail" resultType="org.springblade.modules.vo.JzrkVO">
        select
            jzrk.*,
            '寄住人口' as ryType,
            ( select zy from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = jzrk.ry_sfzh ) as zy,
            ( select zylb from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = jzrk.ry_sfzh ) as zylb
        from jdrh.rhzf_ry_jzrk jzrk
        where jzrk.is_deleted = 1 and jzrk.ry_sfzh = #{gmsfhm} and jzrk.dzbm = #{dzbm}
    </select>

    <select id="cyrylsWlrkDetail" resultType="org.springblade.modules.vo.WlrkVO">
        select
            wlrk.*,
            '未落人口' as ryType,
            ( select zy from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = wlrk.ry_sfzh ) as zy,
            ( select zylb from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = wlrk.ry_sfzh ) as zylb
        from jdrh.rhzf_ry_wlrk wlrk
        where wlrk.is_deleted = 1 and wlrk.ry_sfzh = #{gmsfhm} and wlrk.dzbm = #{dzbm}
    </select>

    <select id="cyrylsZzrkDetail" resultType="org.springblade.modules.vo.ZzrkVO">
        select
            zzrk.*,
            '暂住人口' as ryType,
            ( select zy from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = zzrk.ry_sfzh ) as zy,
            ( select zylb from jdrh.ybss_cyry where is_deleted = 0 and ybss_cyry.gmsfhm = zzrk.ry_sfzh ) as zylb
        from jdrh.rhzf_ry_zzrk zzrk
        where zzrk.is_deleted = 1 and zzrk.ry_sfzh = #{gmsfhm} and zzrk.dzbm = #{dzbm}
    </select>

    <select id="cyryDetail" resultType="org.springblade.modules.entity.CyryEntity">
        select
            xm as ryXm,
            xb as ryXb,
            gmsfhm as rySfzh,
            lxdh as ryDh,
            xz as dzXz,
            zy,
            zylb
        from jdrh.ybss_cyry where is_deleted = 0 and gmsfhm = #{gmsfhm}
    </select>

    <select id="getMphxlhByLdphxlh" resultType="org.springblade.modules.entity.SyryEntity">
        select dzbm from sspt.rk_dzxx where ldphxlh = coalesce (nullif (#{params.ldphxlh}, ''), '0'):: int8
    </select>

    <select id="selectFwInfo" resultType="org.springblade.modules.entity.SyryEntity">
        SELECT
        *
        FROM
        (
        SELECT
        cz.id,
        cz.fw_id AS fwId,
        cz.ry_xm AS ryXm,
        cz.ry_xb AS ryXb,
        cz.dzbm AS dzbm,
        '常住人口' AS ryType,
        cz.ry_sfzh AS rySfzh,
        cz.ry_dh AS ryDh,
        cz.ry_hzgx AS ryHzgx,
        cz.ry_hyzk AS ryHyzk,
        cz.ry_whcd AS ryWhcd,
        cz.ry_zzmm AS ryZzmm,
        cz.ry_byzk AS ryByzk,
        cz.zjxy,
        cz.ry_ts_lb AS ryTsLb,
        cz.ry_ts_jtqk AS ryTsJtqk,
        cz.ry_mz_dm AS ryMzDm,
        cz.ry_hyzk_dm AS ryHyzkDm,
        cz.ry_whcd_dm AS ryWhcdDm,
        cz.ry_zzmm_dm AS ryZzmmDm,
        cz.ry_byzk_dm AS ryByzkDm,
        cz.zjxy_dm AS zjxyDm,
        cz.dw_mc AS dwMc,
        cz.dw_lb AS dwLb,
        cz.dw_dz AS dwDz,
        cz.dw_xz AS dwXz,
        cz.vx,
        cz.ry_zp AS ryZp,
        cz.bz AS bz,
        cz.create_user,
        cz.create_time,
        cz.update_user,
        cz.update_time,
        sj.id as sjid,
        fj.id as fjid,
        pcs.id as pcsid,
        sq.id as sqid,
        cz.status,
        cz.update_dept AS updateDept,
        cz.new_dzbm AS newDzbm,
        cz.new_fw_id AS newFwId,
        dept.dept_name AS updateDeptName
        FROM
        jdrh.rhzf_ry_czrk cz
        LEFT JOIN jdrh.blade_dept sq ON sq.id = cz.create_dept
        LEFT JOIN jdrh.blade_dept dept ON dept.id :: text = cz.update_dept
        LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
        LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
        LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
        WHERE
        cz.is_deleted = 0
        and (sq.id = #{params.deptId} :: int8 or sq.ancestors like '%' || #{params.deptId} || '%')
        UNION ALL
        SELECT
        jw.id,
        jw.fw_id AS fwId,
        jw.ry_mz || ' ' || jw.ry_xs AS ryXm,
        jw.ry_xb AS ryXb,
        jw.dzbm AS dzbm,
        '境外人口' AS ryType,
        jw.ry_zjhm AS rySfzh,
        jw.ry_dh AS ryDh,
        '' AS ryHzgx,
        '' AS ryHyzk,
        '' AS ryWhcd,
        '' AS ryZzmm,
        '' AS ryByzk,
        jw.zjxy,
        jw.ry_ts_lb AS ryTsLb,
        jw.ry_ts_jtqk AS ryTsJtqk,
        '' AS ryMzDm,
        '' AS ryHyzkDm,
        '' AS ryWhcdDm,
        '' AS ryZzmmDm,
        '' AS ryByzkDm,
        jw.zjxy_dm AS zjxyDm,
        jw.dw_mc AS dwMc,
        jw.dw_lb AS dwLb,
        jw.dw_dz AS dwDz,
        jw.dw_xz AS dwXz,
        jw.vx,
        jw.ry_zp AS ryZp,
        jw.bz AS bz,
        jw.create_user,
        jw.create_time,
        jw.update_user,
        jw.update_time,
        sj.id as sjid,
        fj.id as fjid,
        pcs.id as pcsid,
        sq.id as sqid,
        jw.status,
        jw.update_dept AS updateDept,
        jw.new_dzbm AS newDzbm,
        jw.new_fw_id AS newFwId,
        dept.dept_name AS updateDeptName
        FROM
        jdrh.rhzf_ry_jwrk jw
        LEFT JOIN jdrh.blade_dept sq ON sq.id = jw.create_dept
        LEFT JOIN jdrh.blade_dept dept ON dept.id :: text = jw.update_dept
        LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
        LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
        LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
        WHERE
        jw.is_deleted = 0
        and (sq.id = #{params.deptId} :: int8 or sq.ancestors like '%' || #{params.deptId} || '%')
        UNION ALL
        SELECT
        jz.id,
        jz.fw_id AS fwId,
        jz.ry_xm AS ryXm,
        jz.ry_xb AS ryXb,
        jz.dzbm AS dzbm,
        '寄住人口' AS ryType,
        jz.ry_sfzh AS rySfzh,
        jz.ry_dh AS ryDh,
        jz.ry_hzgx AS ryHzgx,
        jz.ry_hyzk AS ryHyzk,
        jz.ry_whcd AS ryWhcd,
        jz.ry_zzmm AS ryZzmm,
        jz.ry_byzk AS ryByzk,
        jz.zjxy,
        jz.ry_ts_lb AS ryTsLb,
        jz.ry_ts_jtqk AS ryTsJtqk,
        jz.ry_mz_dm AS ryMzDm,
        jz.ry_hyzk_dm AS ryHyzkDm,
        jz.ry_whcd_dm AS ryWhcdDm,
        jz.ry_zzmm_dm AS ryZzmmDm,
        jz.ry_byzk_dm AS ryByzkDm,
        jz.zjxy_dm AS zjxyDm,
        jz.dw_mc AS dwMc,
        jz.dw_lb AS dwLb,
        jz.dw_dz AS dwDz,
        jz.dw_xz AS dwXz,
        jz.vx,
        jz.ry_zp AS ryZp,
        jz.bz AS bz,
        jz.create_user,
        jz.create_time,
        jz.update_user,
        jz.update_time,
        sj.id as sjid,
        fj.id as fjid,
        pcs.id as pcsid,
        sq.id as sqid,
        jz.status,
        jz.update_dept AS updateDept,
        jz.new_dzbm AS newDzbm,
        jz.new_fw_id AS newFwId,
        dept.dept_name AS updateDeptName
        FROM
        jdrh.rhzf_ry_jzrk jz
        LEFT JOIN jdrh.blade_dept sq ON sq.id = jz.create_dept
        LEFT JOIN jdrh.blade_dept dept ON dept.id :: text = jz.update_dept
        LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
        LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
        LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
        WHERE
        jz.is_deleted = 0
        and (sq.id = #{params.deptId} :: int8 or sq.ancestors like '%' || #{params.deptId} || '%')
        UNION ALL
        SELECT
        wl.id,
        wl.fw_id AS fwId,
        wl.ry_xm AS ryXm,
        wl.ry_xb AS ryXb,
        wl.dzbm AS dzbm,
        '未落人口' AS ryType,
        wl.ry_sfzh AS rySfzh,
        wl.ry_dh AS ryDh,
        wl.ry_hzgx AS ryHzgx,
        wl.ry_hyzk AS ryHyzk,
        wl.ry_whcd AS ryWhcd,
        wl.ry_zzmm AS ryZzmm,
        wl.ry_byzk AS ryByzk,
        wl.zjxy,
        wl.ry_ts_lb AS ryTsLb,
        wl.ry_ts_jtqk AS ryTsJtqk,
        wl.ry_mz_dm AS ryMzDm,
        wl.ry_hyzk_dm AS ryHyzkDm,
        wl.ry_whcd_dm AS ryWhcdDm,
        wl.ry_zzmm_dm AS ryZzmmDm,
        wl.ry_byzk_dm AS ryByzkDm,
        wl.zjxy_dm AS zjxyDm,
        wl.dw_mc AS dwMc,
        wl.dw_lb AS dwLb,
        wl.dw_dz AS dwDz,
        wl.dw_xz AS dwXz,
        wl.vx,
        wl.ry_zp AS ryZp,
        wl.bz AS bz,
        wl.create_user,
        wl.create_time,
        wl.update_user,
        wl.update_time,
        sj.id as sjid,
        fj.id as fjid,
        pcs.id as pcsid,
        sq.id as sqid,
        wl.status,
        wl.update_dept AS updateDept,
        wl.new_dzbm AS newDzbm,
        wl.new_fw_id AS newFwId,
        dept.dept_name AS updateDeptName
        FROM
        jdrh.rhzf_ry_wlrk wl
        LEFT JOIN jdrh.blade_dept sq ON sq.id = wl.create_dept
        LEFT JOIN jdrh.blade_dept dept ON dept.id :: text = wl.update_dept
        LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
        LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
        LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
        WHERE
        wl.is_deleted = 0
        and (sq.id = #{params.deptId} :: int8 or sq.ancestors like '%' || #{params.deptId} || '%')
        UNION ALL
        SELECT
        zz.id,
        zz.fw_id AS fwId,
        zz.ry_xm AS ryXm,
        zz.ry_xb AS ryXb,
        zz.dzbm AS dzbm,
        '暂住人口' AS ryType,
        zz.ry_sfzh AS rySfzh,
        zz.ry_dh AS ryDh,
        zz.ry_hzgx AS ryHzgx,
        zz.ry_hyzk AS ryHyzk,
        zz.ry_whcd AS ryWhcd,
        zz.ry_zzmm AS ryZzmm,
        zz.ry_byzk AS ryByzk,
        zz.zjxy,
        zz.ry_ts_lb AS ryTsLb,
        zz.ry_ts_jtqk AS ryTsJtqk,
        zz.ry_mz_dm AS ryMzDm,
        zz.ry_hyzk_dm AS ryHyzkDm,
        zz.ry_whcd_dm AS ryWhcdDm,
        zz.ry_zzmm_dm AS ryZzmmDm,
        zz.ry_byzk_dm AS ryByzkDm,
        zz.zjxy_dm AS zjxyDm,
        zz.dw_mc AS dwMc,
        zz.dw_lb AS dwLb,
        zz.dw_dz AS dwDz,
        zz.dw_xz AS dwXz,
        zz.vx,
        zz.ry_zp AS ryZp,
        zz.bz AS bz,
        zz.create_user,
        zz.create_time,
        zz.update_user,
        zz.update_time,
        sj.id as sjid,
        fj.id as fjid,
        pcs.id as pcsid,
        sq.id as sqid,
        zz.status,
        zz.update_dept AS updateDept,
        zz.new_dzbm AS newDzbm,
        zz.new_fw_id AS newFwId,
        dept.dept_name AS updateDeptName
        FROM
        jdrh.rhzf_ry_zzrk zz
        LEFT JOIN jdrh.blade_dept sq ON sq.id = zz.create_dept
        LEFT JOIN jdrh.blade_dept dept ON dept.id :: text = zz.update_dept
        LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
        LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
        LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
        WHERE
        zz.is_deleted = 0
        and (sq.id = #{params.deptId} :: int8 or sq.ancestors like '%' || #{params.deptId} || '%')
        ) rys
        where 1 = 1 and rys.dzbm = #{dzbm}
        <if test="params.rySfzh != null and params.rySfzh != ''">
            and rys.rySfzh = #{params.rySfzh}
        </if>
        <if test="params.ryXm != null and params.ryXm != ''">
            and rys.ryXm = #{params.ryXm}
        </if>
        <if test="params.ryDh != null and params.ryDh != ''">
            and rys.ryDh = #{params.ryDh}
        </if>
        <if test="params.ryType != null and params.ryType != ''">
            and rys.ryType = #{params.ryType}
        </if>
    </select>
</mapper>
