ETL模块1
parent
ca2b2ce9d5
commit
247bc15afc
|
@ -0,0 +1,24 @@
|
|||
package com.etl.data.source.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 资产模块
|
||||
* @author YunFei.Du
|
||||
* @date 19:25 2024/4/21
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AssetsModule {
|
||||
private HashMap<String, String> structure;
|
||||
private List<Map<String, VtModel>> kvtList;
|
||||
|
||||
private List<TableAssets> tableAssets;
|
||||
}
|
|
@ -5,13 +5,13 @@ import com.etl.common.core.annotation.Excel;
|
|||
import com.etl.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】对象 data_source
|
||||
* 数据源对象 data_source
|
||||
*
|
||||
* @author fei
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
public class DataSource extends BaseEntity
|
||||
{
|
||||
public class DataSource extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键 */
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.etl.data.source.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TableAssets {
|
||||
// private String Field;
|
||||
// private String Type;
|
||||
// private String Null;
|
||||
// private String Key;
|
||||
// private String Default;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.etl.data.source.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* VT模型
|
||||
* @author YunFei.Du
|
||||
* @date 19:25 2024/4/21
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class VtModel {
|
||||
private String value;
|
||||
private String type;
|
||||
}
|
|
@ -38,7 +38,7 @@ public class DataSourceController extends BaseController
|
|||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*/
|
||||
@RequiresPermissions("data_source:source:list")
|
||||
@RequiresPermissions("dataSource:source:list")
|
||||
@GetMapping("/list")
|
||||
public Result< TableDataInfo< DataSource > > list(DataSource dataSource)
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ public class DataSourceController extends BaseController
|
|||
/**
|
||||
* 导出【请填写功能名称】列表
|
||||
*/
|
||||
@RequiresPermissions("data_source:source:export")
|
||||
@RequiresPermissions("dataSource:source:export")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, DataSource dataSource)
|
||||
|
@ -63,7 +63,7 @@ public class DataSourceController extends BaseController
|
|||
/**
|
||||
* 获取【请填写功能名称】详细信息
|
||||
*/
|
||||
@RequiresPermissions("data_source:source:query")
|
||||
@RequiresPermissions("dataSource:source:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ public class DataSourceController extends BaseController
|
|||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*/
|
||||
@RequiresPermissions("data_source:source:add")
|
||||
@RequiresPermissions("dataSource:source:add")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public Result add(@RequestBody DataSource dataSource)
|
||||
|
@ -84,7 +84,7 @@ public class DataSourceController extends BaseController
|
|||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*/
|
||||
@RequiresPermissions("data_source:source:edit")
|
||||
@RequiresPermissions("dataSource:source:edit")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public Result edit(@RequestBody DataSource dataSource)
|
||||
|
@ -95,11 +95,27 @@ public class DataSourceController extends BaseController
|
|||
/**
|
||||
* 删除【请填写功能名称】
|
||||
*/
|
||||
@RequiresPermissions("data_source:source:remove")
|
||||
@RequiresPermissions("dataSource:source:remove")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(dataSourceService.deleteDataSourceByIds(ids));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试连接
|
||||
*/
|
||||
@RequiresPermissions("dataSource:source:test")
|
||||
@Log(title = "测试连接", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/TestConnection")
|
||||
public Result testConnection(@RequestBody DataSource dataSource)
|
||||
{
|
||||
return dataSourceService.testConnection(dataSource);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.etl.data.source.service;
|
||||
|
||||
import com.etl.common.core.domain.Result;
|
||||
import com.etl.data.source.domain.DataSource;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -60,4 +61,6 @@ public interface IDataSourceService
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteDataSourceById(Long id);
|
||||
|
||||
Result testConnection(DataSource dataSource);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.etl.data.source.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import com.etl.common.core.domain.Result;
|
||||
import com.etl.common.core.utils.DateUtils;
|
||||
import com.etl.data.source.domain.DataSource;
|
||||
import com.etl.data.source.mapper.DataSourceMapper;
|
||||
|
@ -93,4 +95,64 @@ public class DataSourceServiceImpl implements IDataSourceService
|
|||
{
|
||||
return dataSourceMapper.deleteDataSourceById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result testConnection(DataSource dataSource) {
|
||||
String user=dataSource.getUsername();
|
||||
String password=dataSource.getPassword ();
|
||||
String jdbcDriver = "com.mysql.cj.jdbc.Driver";
|
||||
String jdbcUrl = "jdbc:mysql://"+dataSource.getHost ()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||
if (dataSource.getConnectionParam()!=null && dataSource.getConnectionParam()!=""){
|
||||
jdbcUrl = jdbcUrl+"?"+dataSource.getConnectionParam();
|
||||
}
|
||||
Connection conn = null;
|
||||
PreparedStatement pst=null;
|
||||
try {
|
||||
Class.forName(jdbcDriver);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return Result.error("连接失败");
|
||||
}
|
||||
try {
|
||||
conn = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
|
||||
pst= conn.prepareStatement ( "select * from city " );
|
||||
|
||||
ResultSet resultSet = pst.executeQuery ( );
|
||||
ResultSetMetaData resultSetMetaData = resultSet.getMetaData ( );
|
||||
|
||||
// 获取列数
|
||||
int columnCount = resultSetMetaData.getColumnCount();
|
||||
// 获取每列的信息,注意列的序列从1开始
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
// 获取列名并打印
|
||||
String columnName = resultSetMetaData.getColumnName(i);
|
||||
System.out.print(" " + columnName + " ");
|
||||
}
|
||||
System.out.println();// 换行
|
||||
|
||||
// 将每行数据存储在Vector集合中
|
||||
Vector< Vector<String> > rowData = new Vector<>();
|
||||
while (resultSet.next()){
|
||||
Vector<String> columnData = new Vector<>();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
columnData.add(resultSet.getString(i));
|
||||
}
|
||||
rowData.add(columnData);
|
||||
}
|
||||
|
||||
// 第一层循环遍历每行数据
|
||||
for (int i = 0; i < rowData.size(); i++) {
|
||||
Vector<String> columnData = rowData.get(i);
|
||||
// 第二层循环遍历每行中每列数据
|
||||
for (int j = 0; j < columnData.size(); j++) {
|
||||
System.out.print(" " + columnData.get(j) + " ");
|
||||
}
|
||||
System.out.println();// 换行
|
||||
}
|
||||
conn.close();
|
||||
}catch (Exception e){
|
||||
return Result.error("连接失败");
|
||||
}
|
||||
return Result.success("连接成功");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue