<?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.swzdr.mapper.RyInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="ryInfoResultMap" type="org.springblade.swzdr.pojo.entity.RyInfoEntity">
        <result column="id" property="id"/>
        <result column="gmsfhm" property="gmsfhm"/>
        <result column="xm" property="xm"/>
        <result column="xb" property="xb"/>
        <result column="csrq" property="csrq"/>
        <result column="mz" property="mz"/>
        <result column="hjdxz" property="hjdxz"/>
        <result column="hjdpcs" property="hjdpcs"/>
        <result column="jzdxz" property="jzdxz"/>
        <result column="jzdpcs" property="jzdpcs"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <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"/>
    </resultMap>

    <select id="selectRyInfoPage" resultMap="ryInfoResultMap">
        SELECT
            *
        FROM
            swzdr_ry_info ry
        LEFT JOIN blade_dept pcs ON pcs.id = ry.pcs_id
        WHERE
            ry.is_deleted = 0
        AND (ry.mj_id = #{userId} :: int8 OR pcs.id = #{deptId} :: int8 OR pcs.ancestors LIKE '%' || #{deptId} || '%')
    </select>

    <select id="exportRyInfo" resultType="org.springblade.swzdr.excel.RyInfoExcel">
        SELECT * FROM swzdr_ry_info ${ew.customSqlSegment}
    </select>

    <select id="getSwzdrList" resultType="java.lang.Long">
        SELECT
            id
        FROM
            swzdr_ry_info
        WHERE
            is_deleted = 0
    </select>

</mapper>
