Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[错误报告]: selectAs 和selectAssociation一起使用查询结果不对 #247

Open
3 tasks done
tom055 opened this issue Jan 22, 2025 · 1 comment
Open
3 tasks done

Comments

@tom055
Copy link

tom055 commented Jan 22, 2025

确认

  • 我的版本是最新版本, 我的版本号与 version 相同, 并且项目里无依赖冲突
  • 我已经在 issue 中搜索过, 确认问题没有被提出过
  • 我已经修改标题, 将标题中的 描述 替换为遇到的问题

当前程序版本

1.5.2

问题描述

MPJLambdaWrapper<DeviceProtocolPo> from1 = JoinWrappers.lambda(DeviceProtocolPo.class)
                .selectAs("t.gatewayTotal",DeviceProtocolPageDto::getGatewayTotal)
                .selectAssociation("t", DeviceProtocolPo.class, DeviceProtocolPageDto::getProtocolPo)
                .selectAssociation("t1", SysDimensionPo.class, DeviceProtocolPageDto::getSysDimensionPo)
                .from(from -> {
                    wrapper(from.setAlias("r")
                            .selectAll(DeviceProtocolPo.class)
                            .selectCount(DeviceGatewayPo::getId, "gatewayTotal")
                            .leftJoin(DeviceGatewayPo.class, "t2", DeviceGatewayPo::getProtocolId, DeviceProtocolPo::getId)
                            .in(DeviceProtocolPo::getOrgId,dimens)
                            .groupBy(DeviceProtocolPo::getId)
                            .having("COUNT( r.id ) >= {0}", 0), param);
                    return from;
                }).leftJoin(SysDimensionPo.class, SysDimensionPo::getId, DeviceProtocolPo::getOrgId);
        Page<DeviceProtocolPageDto> page = getBaseMapper().selectJoinPage(page(param),DeviceProtocolPageDto.class, from1);

你好,大佬,上面执行的日志打印出sql查出来的结果有4条,但实际page的记录只有3条
如果去掉.selectAs("t.gatewayTotal",DeviceProtocolPageDto::getGatewayTotal)这段代码,结果就是4条
这是什么问题呢?要怎么解决?非常感谢

详细堆栈日志

@tom055
Copy link
Author

tom055 commented Jan 23, 2025

换了一种写法,问题还是一样

MPJLambdaWrapper<DeviceProtocolPo> wrapper = new MPJLambdaWrapper<DeviceProtocolPo>()
                .selectAssociation("t",DeviceProtocolPo.class,DeviceProtocolPageDto::getProtocolPo)
                //.selectCount(DeviceGatewayPo::getId, DeviceProtocolPageDto::getGatewayTotal)
                .leftJoin(DeviceGatewayPo.class, "t2", DeviceGatewayPo::getProtocolId, DeviceProtocolPo::getId)
                .leftJoin(SysDimensionPo.class,"t1", SysDimensionPo::getId, DeviceProtocolPo::getOrgId)
                .in(DeviceProtocolPo::getOrgId, dimens)
                .groupBy(DeviceProtocolPo::getId)
                .having("COUNT( t.id ) >= {0}", 0);
        Page<DeviceProtocolPageDto> page = getBaseMapper().selectJoinPage(page(param), DeviceProtocolPageDto.class, wrapper);

.selectCount(DeviceGatewayPo::getId, DeviceProtocolPageDto::getGatewayTotal)
加上该语句,sql日志查询的结果数量是对的,但是获取到的page对象中结果集数量是不对的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant