今天主要是介绍这部分的后端设计方面。
通过online表单生成的代码,基本的录入列表都可以用,但相关数据库测试等都需要单独进行编写。
一、BsSourceTypeController
这个增加一个接口,通过code获取数据
/** * 通过code查询 * * @param code * @return */ @AutoLog(value = "bs_source_type-通过code查询") @ApiOperation(value="bs_source_type-通过code查询", notes="bs_source_type-通过code查询") @GetMapping(value = "/queryByCode") public Result<?> queryByCode(@RequestParam(name="code",required=true) String code) { Result<BsSourceType> result = new Result<BsSourceType>(); QueryWrapper<BsSourceType> queryWrapper = new QueryWrapper<BsSourceType>(); queryWrapper.eq("code",code); BsSourceType bsSourceType = bsSourceTypeService.getOne(queryWrapper); if (bsSourceType == null) { result.error500("未找到对应实体"); } else { result.setResult(bsSourceType); result.setSuccess(true); } return result; }
二、BsDataSourceController
这个要先增加一个测试连接数据源的接口如下:
/** * 测试 连接 * @param connectionParam * @return */ @AutoLog(value = "testConnection-测试数据源") @ApiOperation(value="testConnection-测试数据源", notes="testConnection-测试数据源") @PostMapping("/testConnection") public Result<?> testConnection(@Validated @RequestBody ConnectionParam connectionParam) { return bsDataSourceService.testConnection(connectionParam); }
三、BsDataSourceServiceImpl
增加下面方法
/** * 测试 连接 * * @param connectionParam * @return */ @Override public Result testConnection(ConnectionParam connectionParam) { String sourceType = connectionParam.getSourceType(); String sourceConfig = connectionParam.getSourceConfig(); DataSourceDto dto = new DataSourceDto(); dto.setSourceConfig(sourceConfig); switch (sourceType) { case JdbcConstants.ELASTIC_SEARCH_SQL: Result elasticresult = testElasticsearchSqlConnection(dto); if(elasticresult.isSuccess()) { break; } else { return elasticresult; } case JdbcConstants.MYSQL: case JdbcConstants.KUDU_IMAPLA: case JdbcConstants.ORACLE: case JdbcConstants.SQL_SERVER: case JdbcConstants.JDBC: case JdbcConstants.POSTGRESQL: Result testresult = testRelationalDb(dto); if(testresult.isSuccess()) { break; } else { return testresult; } case JdbcConstants.HTTP: Result httpresult = testHttp(dto); if(httpresult.isSuccess()) { break; } else { return httpresult; } default: return Result.error("连接失败:" + ResponseCode.DATA_SOURCE_TYPE_DOES_NOT_MATCH_TEMPORARILY); } log.info("测试连接成功:{}", JSONObject.toJSONString(connectionParam)); return Result.OK("测试连接成功!"); } /** * 关系型数据库 测试连接 * * @param dto */ public Result testRelationalDb(DataSourceDto dto) { analysisRelationalDbConfig(dto); try { Connection unPooledConnection = jdbcService.getUnPooledConnection(dto); String catalog = unPooledConnection.getCatalog(); log.info("数据库测试连接成功:{}", catalog); unPooledConnection.close(); return Result.OK("数据库测试连接成功"); } catch (SQLException e) { log.error("error",e); if (e.getCause() instanceof ClassNotFoundException) { return Result.error(ResponseCode.CLASS_NOT_FOUND, "数据库测试连接失败:" + e.getCause().getMessage()); } else { return Result.error(ResponseCode.DATA_SOURCE_CONNECTION_FAILED, "数据库测试连接失败:" + e.getMessage()); } } }
四、效果图: