| | |
| | | import com.highdatas.mdm.service.ISysAssembleService; |
| | | import com.highdatas.mdm.util.Constant; |
| | | import com.highdatas.mdm.util.DbUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | * @since 2020-02-19 |
| | | */ |
| | | @RestController |
| | | @Slf4j |
| | | @RequestMapping("/assemble/db") |
| | | public class SysAssembleDbController { |
| | | public class SysAssembleDbController { |
| | | @Autowired |
| | | ISysAssembleDbService dbService; |
| | | @Autowired |
| | |
| | | @Autowired |
| | | ISysAssembleService assembleService; |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过汇集id获取保存的源信息 |
| | | * @param id 汇集id |
| | | * @return: 源list |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/get/parent/{id}", method = RequestMethod.GET) |
| | | public Result get(@PathVariable String id, HttpServletRequest request) { |
| | | //通过assemble 获取汇集信息 |
| | | SysAssemble assemble = assembleService.selectById(id); |
| | | if (assemble == null) { |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | |
| | | return Result.success(result); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 测试连接 |
| | | * @param id 数据源id |
| | | * @return: 测试连接结果 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/testConnection/{id}", method = RequestMethod.GET) |
| | | public Result testConnection(@PathVariable String id, HttpServletRequest request) { |
| | | boolean b = dbService.testConnection(id); |
| | | return Result.success(b); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 测试连接 |
| | | * @param id 数据源id |
| | | * @return: 测试连接结果 |
| | | * |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping(value = "/testConnection", method = RequestMethod.POST) |
| | | public Result testConnection(@RequestBody SysAssembleDb sysAssembleDb) { |
| | |
| | | boolean b = dbService.testConnection(sysAssembleDb); |
| | | return Result.success(b); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取目前用到的数据源list |
| | | * @return: 数据源list |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/getSet", method = RequestMethod.GET) |
| | | public Result getSet(HttpServletRequest request) { |
| | | List<SysAssembleDb> dbList = dbService.selectList(null); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 数据源获取表list |
| | | * @param id 数据源id |
| | | * @return: 源表list |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/getTableList/{id}", method = RequestMethod.GET) |
| | | public Result getTable(@PathVariable String id, HttpServletRequest request) { |
| | | Connection connection = null; |
| | |
| | | String username = sysAssembleDb.getDatasourceUser(); |
| | | connection = dbService.getConnection(id); |
| | | DatabaseMetaData metaData = connection.getMetaData(); |
| | | ResultSet tables = metaData.getTables( null, username.toUpperCase(), null, new String[]{ "TABLE" } ); |
| | | String dbStr = sysAssembleDb.toString(); |
| | | log.info(dbStr); |
| | | ResultSet tables = metaData.getTables(null, "%", "%", new String[]{ "TABLE" } ); |
| | | ArrayList<String> tableNameList = new ArrayList<>(); |
| | | while (tables.next()) { |
| | | String tableName = tables.getString(Constant.TABLE_NAME); |
| | | log.info(tableName); |
| | | tableNameList.add(tableName); |
| | | } |
| | | |
| | | List<SysAssembleDbTable> tableList = dbTableService.selectList(new EntityWrapper<SysAssembleDbTable>().eq(Constant.PARENT_ID, id)); |
| | | List<String> selectedTableNameList = tableList.stream().map(sysAssembleDbTable -> sysAssembleDbTable.getTableName()).collect(Collectors.toList()); |
| | | |
| | | List<String> result = tableNameList.stream().filter(s -> !selectedTableNameList.contains(s)).collect(Collectors.toList()); |
| | | |
| | | |
| | | return Result.success(result); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 源表获取字段list |
| | | * @param id 数据源表id |
| | | * @return: 源表字段list |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/getFields/{id}", method = RequestMethod.GET) |
| | | public Result getFields(@PathVariable String id, @RequestParam String tableName, HttpServletRequest request) { |
| | | List<String> fieldsByTableName = dbService.getFieldsByTableName(id, tableName); |
| | |
| | | return Result.success(fieldsByTableName); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 删除数据源 |
| | | * @param id 数据源id |
| | | * @return: 删除结果 |
| | | * |
| | | */ |
| | | @Transactional(rollbackFor=Exception.class) |
| | | @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) |
| | | public Result delete(@PathVariable String id) { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 添加数据源 |
| | | * @return: 数据源添加结果 |
| | | * |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST) |
| | | public Result addOne(@RequestBody SysAssembleDb sysAssembleDb) { |