<?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.sqjw.jwtdzrq.mapper.JwtdZrqMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="jwtdzrqResultMap" type="org.springblade.modules.sqjw.jwtdzrq.entity.JwtdZrqEntity">
        <result column="id" property="id"/>
        <result column="dtdw" property="dtdw"/>
        <result column="sssq" property="sssq"/>
        <result column="sssqbm" property="sssqbm"/>
        <result column="sspcs" property="sspcs"/>
        <result column="pcsbm" property="pcsbm"/>
        <result column="ssfj" property="ssfj"/>
        <result column="ssfjbm" property="ssfjbm"/>
        <result column="sssj" property="sssj"/>
        <result column="sssjbm" property="sssjbm"/>
        <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="is_deleted" property="isDeleted"/>
        <result column="status" property="status"/>
    </resultMap>

    <select id="selectJwtdZrqPage" resultMap="jwtdzrqResultMap">
        select * from jwtd_zrq where is_deleted = 0
    </select>

    <select id="exportJwtdZrq" resultType="org.springblade.modules.sqjw.jwtdzrq.excel.JwtdZrqExcel">
        SELECT * FROM jwtd_zrq ${ew.customSqlSegment}
    </select>

    <select id="selectJwtdZrqList" resultType="org.springblade.modules.sqjw.jwtdzrq.vo.JwtdZrqVO">
        SELECT
            zrq.id,
            zrq.dtdw,
            zrq.sssqbm,
            sq.dept_name AS sssq
        FROM
            jdrh.jwtd_zrq zrq
        LEFT JOIN jdrh.blade_dept sq ON sq.id = zrq.sssqbm
        WHERE zrq.is_deleted = 0
          AND (#{params.deptId} like '%' || sq.id || '%' or sq.ancestors like '%' || #{params.deptId} || '%')
    </select>

    <select id="getMjList" resultType="org.springblade.modules.system.entity.User">
        SELECT
            bu.id,
            bu.name
        FROM
            jdrh.blade_user bu
        WHERE
            bu.is_deleted = 0
          AND bu.dept_id LIKE '%' || #{sssqbm} || '%'
    </select>

    <select id="getDkfw" resultType="java.lang.String">
        SELECT
            REPLACE(REPLACE(dtdw, '[', '(' ), ']', ')') AS dtdw
        FROM
            jdrh.jwtd_zrq
        WHERE
            is_deleted = 0
          AND sssqbm :: TEXT = ANY ( string_to_array( #{deptId}, ',' ) )
    </select>
</mapper>
