@Override
    public PageResult<Operation> queryPage(OperationPageQueryParam param) {
        QueryWrapper<OperationSavedDO> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(param.getSearchKey())) {
            queryWrapper.like("name", param.getSearchKey());
        }
        if (Objects.nonNull(param.getDataSourceId())) {
            queryWrapper.eq("data_source_id", param.getDataSourceId());
        }
        if (StringUtils.isNotBlank(param.getDatabaseName())) {
            queryWrapper.eq("database_name", param.getDatabaseName());
        }
        if (StringUtils.isNotBlank(param.getStatus())) {
            queryWrapper.eq("status", param.getStatus());
        }
        if (StringUtils.isNotBlank(param.getTabOpened())) {
            queryWrapper.eq("tab_opened", param.getTabOpened());
        }
        if (StringUtils.isNotBlank(param.getOperationType())) {
            queryWrapper.eq("operation_type", param.getOperationType());
        }
        if (param.getUserId() != null) {
            queryWrapper.eq("user_id", param.getUserId());
        }
        Integer start = param.getPageNo();
        Integer offset = param.getPageSize();
        Page<OperationSavedDO> page = new Page<>(start, offset);
        page.setOptimizeCountSql(false);
        if (Objects.nonNull(param.getOrderByDesc()) && param.getOrderByDesc()) {
            queryWrapper.orderByDesc("gmt_modified");
        }
        if (Objects.nonNull(param.getOrderByCreateDesc()) && param.getOrderByCreateDesc()) {
            queryWrapper.orderByDesc("gmt_create");
        }
        IPage<OperationSavedDO> iPage = getMapper().selectPage(page, queryWrapper);
        List<Operation> userSavedDdlDOS = operationConverter.do2dto(iPage.getRecords());
        if (CollectionUtils.isEmpty(userSavedDdlDOS)) {
            return PageResult.empty(param.getPageNo(), param.getPageSize());
        }
        List<Long> dataSourceIds = userSavedDdlDOS.stream().map(Operation::getDataSourceId).toList();
        Map<Long, DataSource> dataSourceMap = getDataSourceInfo(dataSourceIds);
        userSavedDdlDOS.forEach(userSavedDdl -> userSavedDdl.setDataSourceName(
            dataSourceMap.containsKey(userSavedDdl.getDataSourceId()) ? dataSourceMap.get(
                userSavedDdl.getDataSourceId()).getAlias() : null));
        return PageResult.of(userSavedDdlDOS, iPage.getTotal(), param);
    }
@author moji
@version UserSavedDdlCoreServiceImpl.java, v 0.1 September 25, 2022 15:50 moji Exp $
@date 2022/09/25
chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/OperationServiceImpl.java