一、该问题的重现步骤是什么?
1. 数据库为SqlServer
2. 在测试数据权限时,在Mapper分页方法上,添加 @DataAuth(type = DataScopeEnum.OWN_DEPT)
/**
* 自定义分页
*
* @param page 分页
* @param notice 实体
* @return List<NoticeVO>
*/
@DataAuth(type = DataScopeEnum.OWN_DEPT)
List<NoticeVO> selectNoticePage(IPage page, NoticeVO notice);
3. 该Mapper分页的sql是一个普通查询,对CreateTime排序
select * from table u order by u.CreateTime desc
4.最后生成的带数据权限的分页sql,是错误的
WITH selectTemp AS (
SELECT TOP 100 PERCENT ROW_NUMBER() OVER (ORDER BY u.CreateTime DESC) scope where scope.CreateDept in (1)) as __row_number__,
* from (
-- sqlserver普通查询,带order by CreateTime
select top 100 percent *
from table u
order by u.CreateTime desc
) scope
where scope.CreateDept in (1)
)
SELECT *
FROM selectTemp
WHERE __row_number__ BETWEEN 1 AND 10 ORDER BY __row_number__
二、你期待的结果是什么?实际看到的又是什么?
期待正常的sql如下
WITH selectTemp AS (
SELECT TOP 100 PERCENT ROW_NUMBER() OVER (ORDER BY CreateTime DESC) as __row_number__,
* from (
-- sqlserver普通查询,带order by CreateTime
select top 100 percent *
from table u
order by u.CreateTime desc
) scope
where scope.CreateDept in (1)
)
SELECT *
FROM selectTemp
WHERE __row_number__ BETWEEN 1 AND 10 ORDER BY __row_number__
三、你正在使用的是什么产品,什么版本?在什么操作系统上?
BladeX企业版
四、请提供详细的错误堆栈信息,这很重要。
五、若有更多详细信息,请在下面提供。
问题已记录,后续会安排时间排查修复
=====
请问你的版本是?我记得之前有个老版本是有这个问题的,后来mybatis-plus修复了就没问题了。
我现在本地跑出来的sql语句如下,没有问题,你试着更新到最新版本试试
WITH selectTemp AS (
SELECT TOP
100 PERCENT row_number ( ) OVER ( ORDER BY CURRENT_TIMESTAMP ) AS __row_number__, *
FROM
(
SELECT
n.*,
d.dict_value AS categoryName
FROM
blade_notice n
LEFT JOIN ( SELECT * FROM blade_dict WHERE CODE = 'notice' ) d ON n.category = d.dict_key
WHERE
n.is_deleted = 0
AND n.tenant_id = '000000'
) scope
WHERE
scope.create_dept IN ( 1123598813738675202 )
) SELECT
*
FROM
selectTemp
WHERE
__row_number__ BETWEEN 1
AND 10
ORDER BY
__row_number__
扫一扫访问 Blade技术社区 移动端