mybatis-plus
mybatis-plus copied to clipboard
多租户查询出现问题
当前使用版本(必填,否则不予处理)
3.5.2
该问题是如何引起的?(确定最新版也有问题再提!!!)
查询内部时,涉及子查询作为函数里的参数时,不会将租户的id加上
原始语句 Select a., b., IF((Select c.value From C as c Where c.code = "1") = 1, c.type, a.type) as type from A as a, B as b Where a.b_id = b.id
执行语句 Select a., b., IF((Select c.value From C as c Where c.code = "1") = 1, c.type, a.type) as type from A as a, B as b Where a.b_id = b.id And a.tenant_id = 1 And b.tenant_id = 1
期望语句 Select a., b., IF((Select c.value From C as c Where c.code = "1" And c.tenant_id = 1) = 1, c.type, a.type) as type from A as a, B as b Where a.b_id = b.id And a.tenant_id = 1 And b.tenant_id = 1
目前来说应该是不支持:IF((Select c.value From C as c Where c.code = "1" And c.tenant_id = 1) = 1, c.type, a.type)这个是一个函数,内部是一个等式,不是一个函数:(Select c.value From C as c Where c.code = "1" And c.tenant_id = 1) = 1。只考虑了部分场景,出问题的代码如下: protected void processFunction(Function function, final String whereSegment) { ExpressionList<?> parameters = function.getParameters(); if (parameters != null) { parameters.forEach(expression -> { if (expression instanceof Select) { processSelectBody(((Select) expression), whereSegment); } else if (expression instanceof Function) { processFunction((Function) expression, whereSegment); } }); } }想要支持的话,需要修改源码com.baomidou.mybatisplus.extension.plugins.inner.BaseMultiTableInnerInterceptor