class ReactorQLDeviceSelectorBuilder implements DeviceSelectorBuilder {

    private final DeviceRegistry registry;

    private final ReactiveRepository<DeviceInstanceEntity, String> deviceRepository;


    @Override
    @SuppressWarnings("all")
    public DeviceSelector createSelector(DeviceSelectorSpec spec) {<FILL_FUNCTION_BODY>}

    @AllArgsConstructor
    static class ReactorQLDeviceSelector implements DeviceSelector {

        private final ReactorQL ql;

        private final DeviceRegistry registry;

        @Override
        public Flux<DeviceOperator> select(Map<String, Object> context) {
            return ql
                .start(
                    ReactorQLContext
                        .ofDatasource((r) -> Flux.just(context))
                        .bindAll(context)
                )
                .map(ReactorQLRecord::asMap)
                .flatMap(res -> registry.getDevice((String) res.get("id")))
                ;
        }
    }
}

        DeviceSelectorProvider provider = DeviceSelectorProviders
            .getProvider(spec.getSelector())
            .orElseThrow(() -> new UnsupportedOperationException("unsupported selector:" + spec.getSelector()));

        //固定设备,直接获取,避免查询数据库性能低.
        if (DeviceSelectorProviders.isFixed(spec)) {
            return ctx -> {
                return spec
                    .resolveSelectorValues(ctx)
                    .map(String::valueOf)
                    .flatMap(registry::getDevice);
            };
        }

        BiFunction<NestConditional<ReactiveQuery<DeviceInstanceEntity>>,
            Map<String, Object>,
            Mono<NestConditional<ReactiveQuery<DeviceInstanceEntity>>>> function = provider
            .createLazy(spec);

        return context -> function
            .apply(deviceRepository
                       .createQuery()
                       .select(DeviceInstanceEntity::getId)
                       .nest(),
                   context
            )
            .flatMapMany(ctd -> ctd.end().fetch().map(DeviceInstanceEntity::getId))
            .flatMap(registry::getDevice);
    
<no_super_class>