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

    <select id="selectRkByExcel" resultType="org.springblade.modules.rhzf.fwInfo.excel.HcbdExcel">
        SELECT DISTINCT
            *
        FROM
            (
                SELECT
                    cz.ry_sfzh as sfzh
                FROM
                    jdrh.rhzf_ry_czrk cz
                left join jdrh.blade_dept bd on cz.create_dept = bd.id
                WHERE
                    cz.is_deleted = 0
                  and cz.ry_sfzh = #{sfzh} and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))
                UNION ALL
                SELECT
                    jw.ry_zjhm as sfzh
                FROM
                    jdrh.rhzf_ry_jwrk jw
                left join jdrh.blade_dept bd on jw.create_dept = bd.id
                WHERE
                    jw.is_deleted = 0
                  and jw.ry_zjhm = #{sfzh} and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))
                UNION ALL
                SELECT
                    jz.ry_sfzh as sfzh
                FROM
                    jdrh.rhzf_ry_jzrk jz
                left join jdrh.blade_dept bd on jz.create_dept = bd.id
                WHERE
                    jz.is_deleted = 0
                  and jz.ry_sfzh = #{sfzh} and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))
                UNION ALL
                SELECT
                    wl.ry_sfzh as sfzh
                FROM
                    jdrh.rhzf_ry_wlrk wl
                left join jdrh.blade_dept bd on wl.create_dept = bd.id
                WHERE
                    wl.is_deleted = 0
                  and wl.ry_sfzh = #{sfzh} and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))
                UNION ALL
                SELECT
                    zz.ry_sfzh as sfzh
                FROM
                    jdrh.rhzf_ry_zzrk zz
                left join jdrh.blade_dept bd on zz.create_dept = bd.id
                WHERE
                    zz.is_deleted = 0
                  and zz.ry_sfzh = #{sfzh} and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))
            ) rys
    </select>

    <select id="exportHcbd" resultType="org.springblade.modules.rhzf.fwInfo.excel.HcbdExcel">
        select
            *
        from rhzf_hcbd rh
        left join jdrh.blade_dept bd on rh.create_dept = bd.id
        where rh.is_deleted = 0 and ((#{deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{deptId} || '%'))
    </select>

    <update id="deletedHcbd">
        update rhzf_hcbd set is_deleted = 1 where create_user = #{userId}
    </update>

    <select id="selectHcbdPage" resultType="org.springblade.modules.rhzf.fwInfo.entity.HcbdEntity">
        select * from rhzf_hcbd where is_deleted = 0 and create_user = #{params.userId}
    </select>
</mapper>
