<?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.xpgxb.mapper.XpgxbMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="xpgxbResultMap" type="org.springblade.modules.xpgxb.entity.XpgxbEntity">
        <result column="id" property="id"/>
        <result column="xpmjxm" property="xpmjxm"/>
        <result column="xpmjzzjhm" property="xpmjzzjhm"/>
        <result column="xpmjlxdh" property="xpmjlxdh"/>
        <result column="xpmjssdw" property="xpmjssdw"/>
        <result column="xpmjssdwdm" property="xpmjssdwdm"/>
        <result column="xpfj" property="xpfj"/>
        <result column="xpfjdm" property="xpfjdm"/>
        <result column="xppcs" property="xppcs"/>
        <result column="xppcsdm" property="xppcsdm"/>
        <result column="xpjws" property="xpjws"/>
        <result column="xpjwsid" property="xpjwsid"/>
        <result column="xpwg" property="xpwg"/>
        <result column="jdmjjh" property="jdmjjh"/>
        <result column="jdmjdhh" property="jdmjdhh"/>
        <result column="jdmjzjhm" property="jdmjzjhm"/>
        <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="xpqx" property="xpqx"/>
    </resultMap>

    <select id="selectXpgxbPage" resultType="org.springblade.modules.xpgxb.entity.XpgxbEntity">
        SELECT
            jx.*,
            bu.ID AS userId
        FROM
            jlrh_xpgxb jx
        LEFT JOIN blade_user bu ON bu.phone = jx.xpmjlxdh
        LEFT JOIN blade_dept pcs ON pcs.ID = jx.xppcsdm
        WHERE
            jx.is_deleted = 0
        AND ( ( #{params.deptId} LIKE '%' || pcs.ID || '%' ) OR ( pcs.ancestors LIKE '%' || #{params.deptId} || '%' ) )
        <if test="params.xpmjxm!=null and params.xpmjxm!=''">
            and jx.xpmjxm = #{params.xpmjxm}
        </if>
        <if test="params.xpmjzzjhm!=null and params.xpmjzzjhm!=''">
            and jx.xpmjzzjhm = #{params.xpmjzzjhm}
        </if>
        <if test="params.xppcs!=null and params.xppcs!=''">
            and jx.xppcs = #{params.xppcs}
        </if>
        <if test="params.xpmjlxdh!=null and params.xpmjlxdh!=''">
            and jx.xpmjlxdh = #{params.xpmjlxdh}
        </if>
        <if test="params.xpjws!=null and params.xpjws!=''">
            and jx.xpjws = #{params.xpjws}
        </if>
        ORDER BY jx.create_time
    </select>

    <select id="exportXpgxb" resultType="org.springblade.modules.xpgxb.excel.XpgxbExcel">
        SELECT * FROM jlrh_xpgxb ${ew.customSqlSegment}
    </select>

</mapper>
