<?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="example.dao.OrdersDao">

    <!-- 查询结果列 -->
    <sql id="base_columns">
        orders.id,
        orders.order_number,
        orders.status,
        orders.create_time,
        orders.updateInfo.operatorName,
        orders.updateInfo.operateTime
        <!-- 其他列... -->
    </sql>

    <!-- 分页查询 -->
    <select id="queryPage" resultType="example.domain.vo.OrderVO">
        SELECT
        <include refid="base_columns"/>
        FROM orders
        <where>
            <!-- 其他查询条件... -->
            
            <!-- 用户过滤条件：如果是admin则不过滤，否则只显示当前操作员的数据 -->
            AND (orders.updateInfo.operatorName=#{SESSION_USERS} or orders.updateInfo.operatorName='admin')
        </where>
        ORDER BY orders.create_time DESC
    </select>

    <!-- 另一种实现方式，使用动态SQL更灵活控制 -->
    <select id="queryPageAlt" resultType="example.domain.vo.OrderVO">
        SELECT
        <include refid="base_columns"/>
        FROM orders
        <where>
            <!-- 其他查询条件... -->
            
            <!-- 当前操作员为admin时不添加过滤条件，否则只显示当前操作员的数据 -->
            <if test="SESSION_USERS != 'admin'">
                AND orders.updateInfo.operatorName=#{SESSION_USERS}
            </if>
        </where>
        ORDER BY orders.create_time DESC
    </select>

</mapper> 