<?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.RyRwzlMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="ryRwzlResultMap" type="org.springblade.swzdr.pojo.entity.RyRwzlEntity">
        <result column="id" property="id"/>
        <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"/>
        <result column="ry_id" property="ryId"/>
        <result column="js_pcs_id" property="jsPcsId"/>
        <result column="zt" property="zt"/>
        <result column="zd_pcs_id" property="zdPcsId"/>
    </resultMap>

    <select id="selectRyRwzlPage" resultType="org.springblade.swzdr.pojo.vo.RyRwzlVO">
        SELECT
            rw.id,
            rw.ry_id,
            ry.wklb,
            ry.xm,
            ry.xb,
            ry.level,
            ry.gmsfhm,
            ry.jzdxz,
            string_agg ( dh.lxdh, ',' ) AS lxdh,
            ry.wklb,
            ry.hjdpcsdm AS zdPcsId,
            dept.dept_name AS wkdwName
        FROM
            swzdr_ry_rwzl rw
        LEFT JOIN swzdr_ry_info ry ON ry.id = rw.ry_id
        LEFT JOIN swzdr_ry_lxdh dh ON dh.user_id = ry.id
        LEFT JOIN blade_dept dept ON dept.id = ry.wkdw
        WHERE
            rw.js_pcs_id = #{params.deptId} :: int8
          AND rw.zt = 0
        GROUP BY
            rw.id,
            rw.ry_id,
            ry.wklb,
            ry.xm,
            ry.xb,
            ry.level,
            ry.gmsfhm,
            ry.jzdxz,
            ry.wklb,
            ry.hjdpcsdm,
            dept.dept_name
    </select>

    <select id="exportRyRwzl" resultType="org.springblade.swzdr.excel.RyRwzlExcel">
        SELECT * FROM swzdr_ry_rwzl ${ew.customSqlSegment}
    </select>

</mapper>
