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

大佬请教一下多表连接要怎么操作 我写的有点怪怪的 #516

Open
zhangle1 opened this issue Jun 5, 2024 · 1 comment
Open

Comments

@zhangle1
Copy link

zhangle1 commented Jun 5, 2024

   @PostMapping({"/_queryTest"})
    @QueryAction
    @QueryOperation(
        summary = "使用Post方式分页动态查询"
    )
    public Mono<PagerResult<DeviceInstanceEntity>> queryPagerTest(Mono<QueryParamEntity> query) {

       String today = LocalDate.now().toString();

       return QueryHelper
            .transformPageResult(
                //分页查询原始数据
                service.queryPager(query),
                list -> {
                    Mono<List<DeviceInstanceEntity>> collectList = QueryHelper
                        .combineOneToMany(
                            //原始数据转为 ExampleInfo
                            Flux.fromIterable(list).map(e -> e.copyTo(new DeviceInstanceEntity())),
                            //主表数据ID
                            DeviceInstanceEntity::getId,
                            //查询关联表
                            gkDeviceStateRepository
                                .createQuery()
                                .gt(GkDeviceStateEntity::getStart_time, today + " 00:00:00"),
                            //关联表中的主表ID属性
                            GkDeviceStateEntity::getDevice_code,
                            //关联数据设置到主表中
                            GkDeviceStateEntity::setDeviceStateList
                        )
                        .collectList().flatMap((result)->{
                           return  QueryHelper
                                .combineOneToMany(
                                    //原始数据转为 ExampleInfo
                                    Flux.fromIterable(result).map(e -> e.copyTo(new DeviceInstanceEntity())),
                                    //主表数据ID
                                    DeviceInstanceEntity::getId,
                                    //查询关联表
                                    gkMesOrderRepository
                                        .createQuery(),
                                    //关联表中的主表ID属性
                                    GkMesOrderEntity::getDevice_code,
                                    //关联数据设置到主表中
                                    GkDeviceStateEntity::setMesOrderList
                                )
                                .collectList();
                        });


                    return collectList;

                });
    }
@zhou-hao
Copy link
Member

zhou-hao commented Jun 5, 2024

用QueryHelper的 原生sql 或者 join 查询试试。

  1. 注入 QueryHelper helper;
  2. helper.select...

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

2 participants