UsrUserMapper.xml 3.35 KB
<?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">
<!-- REQ-USR-003 T3:查询用户跨表分页 SQL(LEFT JOIN + 动态单条件)。
     map-underscore-to-camel-case=false,故用显式 resultMap 映射列别名到 UserVO 字段;
     不 SELECT u.sPassword 与租户列;值用 #{} 预编译占位,列 token 由 Service 白名单产出。 -->
<mapper namespace="com.xly.erp.modules.usr.mapper.UsrUserMapper">

    <resultMap id="userVOMap" type="com.xly.erp.modules.usr.vo.UserVO">
        <id property="id" column="id"/>
        <result property="sUserName" column="sUserName"/>
        <result property="employeeName" column="employeeName"/>
        <result property="sUserNo" column="sUserNo"/>
        <result property="department" column="department"/>
        <result property="sUserType" column="sUserType"/>
        <result property="sLanguage" column="sLanguage"/>
        <result property="iIsVoid" column="iIsVoid"/>
        <result property="tLastLoginDate" column="tLastLoginDate"/>
        <result property="sCreator" column="sCreator"/>
        <result property="tCreateDate" column="tCreateDate"/>
    </resultMap>

    <select id="selectUserPage" resultMap="userVOMap">
        SELECT
            u.iIncrement      AS id,
            u.sUserName       AS sUserName,
            e.sEmployeeName   AS employeeName,
            u.sUserNo         AS sUserNo,
            e.sDepartment     AS department,
            u.sUserType       AS sUserType,
            u.sLanguage       AS sLanguage,
            u.iIsVoid         AS iIsVoid,
            u.tLastLoginDate  AS tLastLoginDate,
            u.sCreator        AS sCreator,
            u.tCreateDate     AS tCreateDate
        FROM usr_user u
        LEFT JOIN usr_employee e ON u.iEmployeeId = e.iIncrement
        <where>
            <if test="cond != null and cond.text">
                <choose>
                    <when test="cond.textEquals">
                        ${cond.column} = #{cond.textValue}
                    </when>
                    <when test="cond.textNotContains">
                        ${cond.column} NOT LIKE CONCAT('%', #{cond.textValue}, '%') ESCAPE '\\'
                    </when>
                    <otherwise>
                        ${cond.column} LIKE CONCAT('%', #{cond.textValue}, '%') ESCAPE '\\'
                    </otherwise>
                </choose>
            </if>
            <if test="cond != null and cond.bool">
                <choose>
                    <when test="cond.boolNegated">
                        ${cond.column} &lt;&gt; #{cond.boolValue}
                    </when>
                    <otherwise>
                        ${cond.column} = #{cond.boolValue}
                    </otherwise>
                </choose>
            </if>
            <if test="cond != null and cond.date">
                <choose>
                    <when test="cond.dateNegated">
                        (${cond.column} &lt; #{cond.dateStart} OR ${cond.column} &gt;= #{cond.dateEnd})
                    </when>
                    <otherwise>
                        ${cond.column} &gt;= #{cond.dateStart} AND ${cond.column} &lt; #{cond.dateEnd}
                    </otherwise>
                </choose>
            </if>
        </where>
        ORDER BY u.iIncrement
    </select>

</mapper>