<?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.system.mapper.UserMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="userResultMap" type="org.springblade.modules.system.entity.User">
        <result column="id" property="id"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="code" property="code"/>
        <result column="user_type" property="userType"/>
        <result column="account" property="account"/>
        <result column="password" property="password"/>
        <result column="name" property="name"/>
        <result column="real_name" property="realName"/>
        <result column="email" property="email"/>
        <result column="phone" property="phone"/>
        <result column="birthday" property="birthday"/>
        <result column="sex" property="sex"/>
        <result column="role_id" property="roleId"/>
        <result column="dept_id" property="deptId"/>
        <result column="post_id" property="postId"/>
    </resultMap>

    <select id="selectUserPage" resultMap="userResultMap">
        select * from jdrh.blade_user bu,
        split_part( bu.dept_id, ',', '1' ) AS deptid
        left join jdrh.blade_dept bd on bd.id :: text = deptid
        where bu.is_deleted = 0 and bu.name not like '%' || '系统创建' || '%' and (bd.ancestors like '%' || #{deptId} || '%' or bd.id :: text = #{deptId})
        <if test="tenantId!=null and tenantId != ''">
            and bu.tenant_id = #{tenantId}
        </if>
        <if test="user.tenantId!=null and user.tenantId != ''">
            and bu.tenant_id = #{user.tenantId}
        </if>
        <if test="user.roleId!=null and user.roleId != ''">
            and bu.role_id = #{user.roleId}
        </if>
        <if test="user.status!=null and user.status != ''">
            and bu.status = #{user.status}
        </if>
        <if test="user.account!=null and user.account != ''">
            and bu.account = #{user.account}
        </if>
        <if test="user.realName!=null and user.realName != ''">
            and bu.real_name = #{user.realName}
        </if>
        <if test="user.userType!=null and user.userType != ''">
            and bu.user_type = #{user.userType}
        </if>
        <if test="user.phone!=null and user.phone != ''">
            and bu.phone like '%' || #{user.phone} || '%'
        </if>
        ORDER BY bu.id
    </select>

    <select id="selectUserPage1" resultMap="userResultMap">
        select * from blade_user where is_deleted = 0
        <if test="tenantId!=null and tenantId != ''">
            and tenant_id = #{tenantId}
        </if>
        <if test="user.tenantId!=null and user.tenantId != ''">
            and tenant_id = #{user.tenantId}
        </if>
        <if test="user.account!=null and user.account != ''">
            and account = #{user.account}
        </if>
        <if test="user.realName!=null and user.realName != ''">
            and real_name = #{user.realName}
        </if>
        <if test="user.userType!=null and user.userType != ''">
            and user_type = #{user.userType}
        </if>
        <if test="deptIdList!=null and deptIdList.size>0">
            and id in (
            SELECT
            user_id
            FROM
            blade_user_dept
            WHERE
            dept_id IN
            <foreach collection="deptIdList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
            )
        </if>
        ORDER BY id
    </select>

    <select id="getUser" resultMap="userResultMap">
        SELECT
            *
        FROM
            blade_user
        WHERE
            tenant_id = #{param1} and account = #{param2} and password = #{param3} and is_deleted = 0
    </select>

    <select id="exportUser" resultType="org.springblade.modules.system.excel.UserExcel">
        SELECT id, tenant_id, user_type, account, name, real_name, email, phone, birthday, role_id, dept_id, post_id FROM blade_user ${ew.customSqlSegment}
    </select>

    <select id="getCodeByUsername" resultType="java.lang.String">
        SELECT
            code
        FROM
            blade_user
        WHERE
            account = #{username}
    </select>

    <select id="getUsernameByCode" resultType="java.lang.String">
        SELECT
            account
        FROM
            blade_user
        WHERE
            code = #{code}
    </select>

    <update id="updateCode">
        UPDATE blade_user
        SET code = #{code}
        WHERE
            account = #{username}

    </update>

    <select id="selectUserIdByPhone" resultMap="userResultMap">
        select * from blade_user where phone = #{xpmjlxdh}
    </select>

    <select id="selectUser" resultMap="userResultMap">
        SELECT
	        uses.*,
	        sq.id as sssq_bm,
	        pcs.id as sspcs_bm,
	        fj.id as ssfj_bm
        FROM
	        blade_user uses
	    LEFT JOIN blade_dept sq ON uses.dept_id = sq.ID :: TEXT
	    LEFT JOIN blade_dept pcs ON sq.parent_id = pcs.id
	    LEFT JOIN blade_dept fj ON pcs.parent_id = fj.id
        WHERE uses.id = #{userId}
    </select>

    <select id="selectSq" resultType="org.springblade.modules.rk.vo.LbVO">
        SELECT
	        sq.id AS value,
	        sq.dept_name AS label
        FROM
	        blade_user uses
	    LEFT JOIN blade_dept sq ON uses.dept_id = sq.parent_id :: TEXT
        WHERE uses.id = #{userId}
    </select>

    <select id="getMjList" resultType="org.springblade.modules.system.vo.UserVO">
        SELECT
            id,
            real_name,
            phone
        FROM
            blade_user
        WHERE
            dept_id LIKE '%' || #{params.sqId} || '%'
    </select>

    <select id="getUsernameBySfzh" resultType="java.lang.String">
        SELECT
            account
        FROM
            blade_user
        WHERE
            sfzh = #{sfzh}
    </select>

    <select id="getRoleId" resultType="java.lang.String">
        SELECT id
        FROM
            blade_role
        WHERE
            role_name = #{roleName}
    </select>

    <select id="getSqId" resultType="java.lang.String">
        SELECT
            string_agg ( id :: TEXT, ',' )
        FROM
            blade_dept,
            "unnest" ( string_to_array( #{sqName}, ',' ) ) AS tem
        WHERE
            dept_name IN ( tem )
            AND parent_id = ( SELECT id FROM blade_dept WHERE dept_name = #{pcsName} AND parent_id = #{fjId} )
    </select>

    <select id="getPcsId" resultType="java.lang.String">
        SELECT
            id
        FROM
            blade_dept
        WHERE
            dept_name = #{pcsName}
            AND parent_id = #{fjId}
    </select>

    <select id="getUserList" resultType="org.springblade.modules.system.entity.User">
        SELECT
            id,
            sfzh
        FROM
            blade_user
        WHERE
            sfzh IS NOT NULL
    </select>

    <update id="updateSfzh" parameterType="org.springblade.modules.system.entity.User">
        UPDATE blade_user
        SET sfzh = #{sfzh},
            update_time = now()
        WHERE
            id = #{id}
    </update>

    <select id="getRoleName" resultType="java.lang.String">
        SELECT
            string_agg ( br.role_name, ',' ) AS roleName
        FROM
            jdrh.blade_user bu,
            jdrh.blade_role br,
            UNNEST ( pg_catalog.string_to_array( bu.role_id, ',' ) ) AS roleid
        WHERE
            bu.account = #{username}
          AND br.id IN ( roleid :: int8 )
          AND bu.is_deleted = 0
        GROUP BY
            bu.id
    </select>

    <select id="getById" resultType="org.springblade.modules.system.entity.User">
        SELECT
            bu.*,
            bd.parent_id
        FROM
            blade_user bu
        LEFT JOIN blade_dept bd ON bd.ID = (( string_to_array( bu.dept_id, ',' ) ) [ 1 ]) :: int8
        WHERE bu.id = #{userId} AND bu.is_deleted = 0
    </select>

    <update id="updateLastLoginTime">
        UPDATE blade_user
        SET last_login_time = now(), update_time = now()
        WHERE
            account = #{username}
    </update>

    <select id="getZxxdSqId" resultType="java.lang.String">
        SELECT ID
        FROM
            blade_dept
        WHERE
            parent_id = #{pcsDm} :: int8
    </select>

    <select id="getIdByAccount" resultType="java.lang.Long">
        SELECT
            id
        FROM
            blade_user
        WHERE
            account = #{account}
        AND is_deleted = 0
    </select>

    <select id="getUserNameById" resultType="org.springblade.modules.system.entity.User">
        SELECT
            *
        FROM
            public.blade_user
        WHERE
            id = #{createUser}
    </select>

    <update id="updateDeptId">
        UPDATE blade_user
        SET update_time = now( ),
            dept_id = #{ids}
        WHERE
            id = #{userId}
    </update>

    <select id="getPcsIdByPcsName" resultType="java.lang.String">
        SELECT
            id
        FROM
            blade_dept
        WHERE
            is_deleted = 0
          AND dept_category = #{deptCategory}
          AND dept_name = #{pcsName}
    </select>

    <select id="getSyBottom" resultType="org.springblade.modules.system.vo.SyBottomVO">
        select
            (select count(0) from jdrh.cs_info info left join jdrh.blade_dept bd on bd.id = info.create_dept where info.is_deleted = '0' and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))) as jxcs,
            (select
	            COUNT (1)
            from
	            jdrh.cs_info info
            left join jdrh.csjc_info jc on
	            info.jc_id = jc.id
            left join jdrh.blade_dept bd on
	            bd.id = info.create_dept
            where info.is_deleted = 0 and jc.is_deleted = 0 and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))) as csjc,
            (select count(0) from jdrh.mdjf_dj mdjf left join jdrh.blade_dept bd on bd.id = mdjf.jfsssq where mdjf.is_deleted = '0' and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))) as mdjf
    </select>

    <select id="getSyCenter" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select
        (select count(0) from jdrh.rhzf_fw_info fw left join jdrh.blade_dept bd on fw.create_dept = bd.id where fw.is_deleted = '0' and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))) as fwinfo,
        (select count(0) from jdrh.rhzf_fw_ry ry left join jdrh.blade_dept bd on ry.create_dept = bd.id where ry.is_deleted = '0' AND ry.fw_id is not null and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))) as fwry,
        (select count(0) from jdrh.cs_info info left join jdrh.blade_dept bd on bd.id = info.create_dept where info.is_deleted = '0' and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))) as jxcs,
        (select
        COUNT (1)
        from
        jdrh.cs_info info
        left join jdrh.csjc_info jc on
        info.jc_id = jc.id
        left join jdrh.blade_dept bd on
        bd.id = info.create_dept
        where info.is_deleted = 0 and jc.is_deleted = 0 and #{deptId} LIKE '%' || bd.id :: text || '%') as csjc,
        (select count(0) from jdrh.mdjf_dj mdjf left join jdrh.blade_dept bd on bd.id = mdjf.jfsssq where mdjf.is_deleted = '0' and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))) as mdjf,
        (select count(0) from jdrh.rhzf_fw_info fwinfos left join jdrh.blade_dept bd on fwinfos.create_dept = bd.id where fwinfos.is_deleted = '0' and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%')) and fwinfos.gzyj is not null) as yjjy
    </select>

    <select id="getSyCenterzs" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select
            (select count(0) from jdrh.rhzf_fw_info fw left join jdrh.blade_dept bd on fw.create_dept = bd.id where fw.is_deleted = '0' and bd.ancestors like '%220000000000%') as fwinfozs,
            (select count(0) from jdrh.rhzf_fw_ry ry left join jdrh.blade_dept bd on ry.create_dept = bd.id where ry.is_deleted = '0' AND ry.fw_id is not null and bd.ancestors like '%220000000000%') as fwryzs,
            (select count(0) from jdrh.cs_info info left join jdrh.blade_dept bd on bd.id = info.create_dept where info.is_deleted = '0' and bd.ancestors like '%220000000000%') as jxcszs,
            (select
	            COUNT (1)
            from
	            jdrh.cs_info info
            left join jdrh.csjc_info jc on
	            info.jc_id = jc.id
            left join jdrh.blade_dept bd on
	            bd.id = info.create_dept
            where info.is_deleted = 0 and jc.is_deleted = 0 and bd.ancestors like '%220000000000%') as csjczs,
            (select count(0) from jdrh.mdjf_dj mdjf left join jdrh.blade_dept bd on bd.id = mdjf.jfsssq where mdjf.is_deleted = '0' and jfsssq is not null and bd.ancestors like '%220000000000%') as mdjfzs,
            (select count(0) from jdrh.rhzf_fw_info fwinfos left join jdrh.blade_dept bd on fwinfos.create_dept = bd.id where fwinfos.is_deleted = '0' and fwinfos.gzyj is not null and bd.ancestors like '%220000000000%') as yjjyzs
    </select>

    <select id="getSyTop" resultType="org.springblade.modules.system.vo.SyTopVO">
        select
            (select count(0) from jdrh.blade_dept where is_deleted = 0 and dept_category = '5' and ancestors like '%' || #{deptId} || '%') as xqzs,
            (select count(0) from public.zdb left join jdrh.blade_dept dept on dept.id :: text = zdb.qv where lb = '4' and ((#{deptId} LIKE '%' || dept.id || '%') OR (dept.ancestors LIKE '%' || #{deptId} || '%'))) as jdzs,
            (select count(0) from jdrh.blade_dept where is_deleted = 0 and dept_category = '7' and ancestors like '%' || #{deptId} || '%') as sqzs,
            (select count(0) from jdrh.jlrh_jws jws left join jdrh.blade_dept bd on bd.id = jws.sssq_bm where jws.is_deleted = '0'<if test="dept != '220000000000'"> and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))</if>) as jwszs
    </select>

    <select id="getByName" resultMap="userResultMap">
        select id from jdrh.blade_user where name = #{cjr}
    </select>

    <select id="selectAccountByUserName" resultMap="userResultMap">
        select id, zp from jdrh.blade_user where account = #{username} and is_deleted = 0
    </select>

    <select id="getSyCenterPh" resultType="org.springblade.modules.system.vo.PhVO">
        select count(0) as sl from jdrh.cs_info info
        <if test="dept == '220000000000'">left join jdrh.blade_dept dept on dept.id = info.create_dept where (dept.id :: text = #{deptId} or dept.ancestors like '%' || #{deptId} || '%') and info.is_deleted = 0 and dept.is_deleted = 0</if>
        <if test="dept != '220000000000'"> left join jdrh.blade_dept bd on bd.id = info.create_dept where ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%')) and info.is_deleted = 0 and bd.is_deleted = 0</if>
    </select>

    <select id="getGsdrsjb" resultType="org.springblade.modules.system.vo.GsdrsjbVO">
        select
            zj_sj,
            xg_sj,
            bgjg_mc,
            bg_rq,
            bgxx_ms,
            qy_dzmc,
            qy_mc,
            dwmc,
            dwlx_ms,
            fr_lxdh,
            fr_xm,
            fe_zjhm,
            frzjlx_ms,
            gd_xm,
            gdxx_ms,
            gs_czbs,
            gsdjjg_ms,
            gszchm,
            jyfwzy,
            jy_zt,
            khmc,
            yhzh,
            rz_bh,
            rz_lx,
            shty_bm,
            qyhy_ms,
            ss_xzqhmc,
            zcrq,
            zcxs_ms,
            zczj_sz,
            zg_rs,
            zjbz_ms,
            gssc_bm,
            rgxksj,
            tsqy_mc
        from qsgssj.gsdrsjb as g where 1=1
        <if test="qyMc!='' and qyMc !=null">
            and tsqy_mc @@ to_tsquery('public.zhcfg', #{qyMc})
        </if>
        <if test="shtyBm!='' and shtyBm !=null">
            And shty_bm = #{shtyBm}
        </if>
    </select>

<!--    <select id="getGsdrsjb" resultType="org.springblade.modules.system.vo.GsdrsjbVO">-->
<!--        select-->
<!--        zj_sj,-->
<!--        xg_sj,-->
<!--        bgjg_mc,-->
<!--        bg_rq,-->
<!--        bgxx_ms,-->
<!--        qy_dzmc,-->
<!--        qy_mc,-->
<!--        dwmc,-->
<!--        dwlx_ms,-->
<!--        fr_lxdh,-->
<!--        fr_xm,-->
<!--        fe_zjhm,-->
<!--        frzjlx_ms,-->
<!--        gd_xm,-->
<!--        gdxx_ms,-->
<!--        gs_czbs,-->
<!--        gsdjjg_ms,-->
<!--        gszchm,-->
<!--        jyfwzy,-->
<!--        jy_zt,-->
<!--        khmc,-->
<!--        yhzh,-->
<!--        rz_bh,-->
<!--        rz_lx,-->
<!--        shty_bm,-->
<!--        qyhy_ms,-->
<!--        ss_xzqhmc,-->
<!--        zcrq,-->
<!--        zcxs_ms,-->
<!--        zczj_sz,-->
<!--        zg_rs,-->
<!--        zjbz_ms,-->
<!--        gssc_bm,-->
<!--        rgxksj,-->
<!--        tsqy_mc-->
<!--        from public.gsdrsjb as g where 1=1-->
<!--        <if test="qyMc!='' and qyMc !=null">-->
<!--            and tsqy_mc @@ to_tsquery('public.testzhcfg', #{qyMc})-->
<!--        </if>-->
<!--        <if test="shtyBm!='' and shtyBm !=null">-->
<!--            And shty_bm = #{shtyBm}-->
<!--        </if>-->
<!--    </select>-->

    <select id="getYhByCreateTime" resultType="org.springblade.modules.system.excel.UserYhExcel">
        SELECT
        bu.account,
        bu.NAME,
        bu.phone,
        case when bd.dept_category = 7 then sj.dept_name || '/' || fj.dept_name || '/' || pcs.dept_name
        when bd.dept_category = 6 then fj.dept_name || '/' || pcs.dept_name || '/' || bd.dept_name
        when bd.dept_category = 5 then pcs.dept_name || '/' || bd.dept_name
        when bd.dept_category = 4 then bd.dept_name end as deptname,
        case when bu.is_deleted = 1 then '删除'
        when bu.create_time &lt; bu.update_time then '修改'
        when bu.create_time = bu.update_time then '新增' end as zt,
        br.role_name
        FROM
        jdrh.blade_user bu
        LEFT JOIN jdrh.blade_dept bd ON bd.ID = split_part( bu.dept_id, ',', '1' ) :: int8
        LEFT JOIN jdrh.blade_dept pcs ON bd.parent_id = pcs.id
        LEFT JOIN jdrh.blade_dept fj ON pcs.parent_id = fj.id
        LEFT JOIN jdrh.blade_dept sj ON fj.parent_id = sj.id
        LEFT JOIN jdrh.blade_role br ON bu.role_id = br.id :: text
        where bu.update_time between #{user.str} :: timestamp and #{user.strEnd} :: timestamp
    </select>

    <update id="qcCode">
        update jdrh.blade_user set code = null where id = #{id} :: int8
    </update>

    <select id="getFjsl" resultType="int">
        SELECT
            COUNT(1)
        FROM
            jdrh.blade_mj_fj
        WHERE
            mj_id = #{id}
          AND is_deleted = 0
          AND status = 0
    </select>

    <select id="getPhone" resultType="java.lang.String">
        select phone from jdrh.blade_user where id = #{id} and is_deleted = 0
    </select>

    <select id="getPhoneXz" resultType="java.lang.Integer">
        select count(0) from jdrh.blade_user where phone = #{phone} and is_deleted = 0
    </select>

    <select id="getFjgl" resultMap="userResultMap">
        SELECT
            bu.id,
            bu.NAME AS fjxm,
            bu.sfzh AS fjsfzh,
            bu.phone AS fjlxdh,
            bu.dept_id,
            pcs.dept_name AS gzdw,
            mj.id AS mjId,
            mj.NAME AS ssmjxm,
            mj.account AS ssmjjh,
            bmf.status
        FROM
            jdrh.blade_user bu
            LEFT JOIN jdrh.blade_mj_fj bmf ON bu.id = bmf.fj_id
            LEFT JOIN jdrh.blade_user mj ON mj.ID = bmf.mj_id
            LEFT JOIN jdrh.blade_dept bd ON split_part( bu.dept_id, ',', '1' ) :: int8 = bd.ID
            LEFT JOIN jdrh.blade_dept pcs ON bd.parent_id = pcs.ID
        WHERE
            bu.role_id = '1694608532769734657' and bu.is_deleted = 0
        <if test="user.sspcs != null and user.sspcs != ''">
            and (bd.id :: text = #{user.sspcs} or bd.ancestors like '%' || #{user.sspcs} || '%')
        </if>
        <if test="user.fjsfzh != null and user.fjsfzh != ''">
            and bu.sfzh = #{user.fjsfzh}
        </if>
        <if test="user.fjxm != null and user.fjxm != ''">
            and bu.name = #{user.fjxm}
        </if>
        <if test="user.fjlxdh != null and user.fjlxdh != ''">
            and bu.phone = #{user.fjlxdh}
        </if>
        <if test="user.ssmjxm != null and user.ssmjxm != ''">
            and mj.name = #{user.ssmjxm}
        </if>
        <if test="user.gzdw != null and user.gzdw != ''">
            and pcs.dept_name like '%' || #{user.gzdw} || '%'
        </if>
        <if test="user.ssmjjh != null and user.ssmjjh != ''">
            and mj.account = #{user.ssmjjh}
        </if>
    </select>

    <select id="getPcsFj" resultMap="userResultMap">
        SELECT
	        bu.ID,
	        bu.name,
	        bu.account as ssmjjh
        FROM
	        jdrh.blade_user bu
        LEFT JOIN jdrh.blade_dept bd on split_part( bu.dept_id, ',', '1' ) :: int8 = bd.id
        Left join jdrh.blade_mj_fj bmf on bu.id = bmf.fj_id
        WHERE
	        bu.is_deleted = 0 and (bd.id = #{id} or bd.ancestors like '%' || #{id} :: text || '%') and bu.role_id = '1677215233615192065' and bmf.id is null
    </select>

    <update id="updateFj">
        update jdrh.blade_mj_fj set mj_id = #{fjInfo.mjId} where fj_id = #{fjInfo.fjId}
    </update>

    <update id="updateUserFj">
        update jdrh.blade_user set name = #{fjxm},sfzh = #{sfzh},phone = #{fjlxdh} where id = #{id}
    </update>

    <select id="getFj" resultType="org.springblade.modules.fjInfo.entity.FjInfoEntity">
        select fj_id from jdrh.blade_mj_fj where mj_id = #{id} and is_deleted = 0
    </select>

    <update id="deleteFj">
        update jdrh.blade_user set is_deleted = 1 where id = #{id}
    </update>

    <select id="exportFjxx" resultType="org.springblade.modules.system.excel.FjxxExcel">
        SELECT
        bu.NAME AS fjxm,
        bu.sfzh AS fjsfzh,
        bu.phone AS fjlxdh,
        pcs.dept_name AS gzdw,
        mj.NAME AS ssmjxm,
        mj.account AS ssmjjh
        FROM
        jdrh.blade_user bu
        LEFT JOIN jdrh.blade_mj_fj bmf ON bu.id = bmf.fj_id
        LEFT JOIN jdrh.blade_user mj ON mj.ID = bmf.mj_id
        LEFT JOIN jdrh.blade_dept bd ON split_part( bu.dept_id, ',', '1' ) :: int8 = bd.ID
        LEFT JOIN jdrh.blade_dept pcs ON bd.parent_id = pcs.ID
        WHERE
        bu.role_id = '1694608532769734657' and bu.is_deleted = 0
        <if test="params.roleId == '1677215233615192065'">
            AND bmf.mj_id = #{params.id}
        </if>
        <if test="params.roleId == '1677215117370056705'">
            and (bd.id :: text = #{params.deptId} or bd.ancestors like '%' || #{params.deptId} || '%')
        </if>
        <if test="params.fjsfzh != null and params.fjsfzh != ''">
            and bu.sfzh = #{params.fjsfzh}
        </if>
        <if test="params.fjxm != null and params.fjxm != ''">
            and bu.name = #{params.fjxm}
        </if>
        <if test="params.fjlxdh != null and params.fjlxdh != ''">
            and bu.phone = #{params.fjlxdh}
        </if>
        <if test="params.ssmjxm != null and params.ssmjxm != ''">
            and mj.name = #{params.ssmjxm}
        </if>
        <if test="params.gzdw != null and params.gzdw != ''">
            and pcs.dept_name like '%' || #{params.gzdw} || '%'
        </if>
        <if test="params.ssmjjh != null and params.ssmjjh != ''">
            and mj.account = #{params.ssmjjh}
        </if>
    </select>

    <select id="selectMj" resultMap="userResultMap">
        select mj.id as mjId,mj.name as mjname,pcs.dept_name as sspcs from jdrh.blade_user bu
        left join jdrh.blade_mj_fj bmf on bu.id = bmf.fj_id
        left join jdrh.blade_user mj on mj.id = bmf.mj_id
        LEFT JOIN jdrh.blade_dept bd ON split_part( bu.dept_id, ',', '1' ) :: int8 = bd.ID
        LEFT JOIN jdrh.blade_dept pcs ON bd.parent_id = pcs.ID
        where bu.id = #{id} and bu.is_deleted = 0 and bmf.is_deleted = 0
    </select>

    <select id="selectMjPcs" resultMap="userResultMap">
        select pcs.dept_name as sspcs from jdrh.blade_user bu
        LEFT JOIN jdrh.blade_dept bd ON split_part( bu.dept_id, ',', '1' ) :: int8 = bd.ID
        LEFT JOIN jdrh.blade_dept pcs ON bd.parent_id = pcs.ID
        where bu.id = #{id} and bu.is_deleted = 0
    </select>

    <update id="updateStatus">
        update jdrh.blade_user set status = 1
    </update>

    <update id="zx">
        update jdrh.blade_user
        set is_deleted  = 2,
            update_time = now()
        where id = #{id}
    </update>

    <select id="getSyCenterFwInfo" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select
            count(0) as fwinfo
        from jdrh.rhzf_fw_info fw
        left join jdrh.blade_dept bd on fw.create_dept = bd.id
        where fw.is_deleted = '0' and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))
    </select>

    <select id="getSyCenterFwry" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select
            count(0) as fwry
        from
            jdrh.rhzf_fw_ry ry
        left join jdrh.blade_dept bd on ry.create_dept = bd.id
        where ry.is_deleted = '0' AND ry.fw_id is not null and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))
    </select>

    <select id="getSyCenterJxcs" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select
            count(0) as jxcs
        from
            jdrh.cs_info info
        left join jdrh.blade_dept bd on bd.id = info.create_dept
        where info.is_deleted = '0' and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))
    </select>

    <select id="getSyCenterCsjc" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select
            COUNT (1) as csjc
        from
            jdrh.cs_info info
        left join jdrh.csjc_info jc on info.jc_id = jc.id
        left join jdrh.blade_dept bd on bd.id = info.create_dept
        where info.is_deleted = 0 and jc.is_deleted = 0 and #{deptId} LIKE '%' || bd.id :: text || '%'
    </select>

    <select id="getSyCenterMdjf" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select
            count(0) as mdjf
        from
            jdrh.mdjf_dj mdjf
        left join jdrh.blade_dept bd on bd.id = mdjf.jfsssq
        where mdjf.is_deleted = '0' and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))
    </select>

    <select id="getSyCenterYjjy" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select count(0) as yjjy from jdrh.rhzf_fw_info fwinfos left join jdrh.blade_dept bd on fwinfos.create_dept = bd.id where fwinfos.is_deleted = '0' and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%')) and fwinfos.gzyj is not null
    </select>

    <select id="getSyCenterFwInfoZs" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select count(0) as fwinfozs from jdrh.rhzf_fw_info fw left join jdrh.blade_dept bd on fw.create_dept = bd.id where fw.is_deleted = '0' and bd.ancestors like '%220000000000%'
    </select>

    <select id="getSyCenterFwryZs" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select count(0) as fwryzs from jdrh.rhzf_fw_ry ry left join jdrh.blade_dept bd on ry.create_dept = bd.id where ry.is_deleted = '0' AND ry.fw_id is not null and bd.ancestors like '%220000000000%'
    </select>

    <select id="getSyCenterJxcsZs" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select count(0) as jxcszs from jdrh.cs_info info left join jdrh.blade_dept bd on bd.id = info.create_dept where info.is_deleted = '0' and bd.ancestors like '%220000000000%'
    </select>

    <select id="getSyCenterCsjcZs" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select
            COUNT (1) as csjczs
        from
            jdrh.cs_info info
        left join jdrh.csjc_info jc on
            info.jc_id = jc.id
        left join jdrh.blade_dept bd on
            bd.id = info.create_dept
        where info.is_deleted = 0 and jc.is_deleted = 0 and bd.ancestors like '%220000000000%'
    </select>

    <select id="getSyCenterMdjfZs" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select count(0) as mdjfzs from jdrh.mdjf_dj mdjf left join jdrh.blade_dept bd on bd.id = mdjf.jfsssq where mdjf.is_deleted = '0' and jfsssq is not null and bd.ancestors like '%220000000000%'
    </select>

    <select id="getSyCenterYjjyZs" resultType="org.springblade.modules.system.vo.SyCenterVO">
        select count(0) as yjjyzs from jdrh.rhzf_fw_info fwinfos left join jdrh.blade_dept bd on fwinfos.create_dept = bd.id where fwinfos.is_deleted = '0' and fwinfos.gzyj is not null and bd.ancestors like '%220000000000%'
    </select>

    <select id="getFwzs" resultType="java.lang.Integer">
        select
            count(0) as fwzs
        from jdrh.rhzf_fw_info rfi
        left join jdrh.blade_dept bd on rfi.create_dept = bd.id
        where rfi.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>

    <select id="getSydwzs" resultType="java.lang.Integer">
        select
            count(0) as sydwzs
        from jdrh.ybss_sydw ys
        left join jdrh.blade_dept bd on ys.create_dept = bd.id
        where ys.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>

    <select id="getCzrk" resultType="java.lang.Integer">
        select
            count(0) as czrk
        from jdrh.rhzf_ry_czrk rrc
        left join jdrh.blade_dept bd on rrc.create_dept = bd.id
        where rrc.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>

    <select id="getJzrk" resultType="java.lang.Integer">
        select
            count(0) as jzrk
        from jdrh.rhzf_ry_jzrk rrj
        left join jdrh.blade_dept bd on rrj.create_dept = bd.id
        where rrj.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>

    <select id="getZzrk" resultType="java.lang.Integer">
        select
            count(0) as zzrk
        from jdrh.rhzf_ry_zzrk rrz
        left join jdrh.blade_dept bd on rrz.create_dept = bd.id
        where rrz.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>

    <select id="getJwrk" resultType="java.lang.Integer">
        select
            count(0) as jwrk
        from jdrh.rhzf_ry_jwrk rrj
        left join jdrh.blade_dept bd on rrj.create_dept = bd.id
        where rrj.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>

    <select id="getWlrk" resultType="java.lang.Integer">
        select
            count(0) as wlrk
        from jdrh.rhzf_ry_wlrk rrw
        left join jdrh.blade_dept bd on rrw.create_dept = bd.id
        where rrw.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>

    <select id="getSwzdrzs" resultType="java.lang.Integer">
        select
            count(0) as swzdrzs
        from sqjw.swzdr_ry_info sri
        left join jdrh.blade_dept bd on sri.create_dept = bd.id
        where sri.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>

    <select id="getTddxzs" resultType="java.lang.Integer">
        select
            count(0) as tddxzs
        from sqjw.tdry_jbxx tj
        left join jdrh.blade_dept bd on tj.create_dept = bd.id
        where tj.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>

    <select id="getMdjfzs" resultType="java.lang.Integer">
        select
            count(0) as mdjfzs
        from jdrh.mdjf_dj md
        left join jdrh.blade_dept bd on md.create_dept = bd.id
        where md.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>

    <select id="getJxcszs" resultType="java.lang.Integer">
        select
            count(0) as jxcszs
        from jdrh.cs_info ci
        left join jdrh.blade_dept bd on ci.create_dept = bd.id
        where ci.is_deleted = 0 and (bd.id :: text = any(string_to_array(#{deptId},',')) or bd.ancestors like '%' || #{deptId} || '%')
    </select>
</mapper>
