fix:更改数据表结构,在测试的同时异步添加表结构 bug修改,不会重复添加,可区分添加和修改
parent
8839f7fe20
commit
5da4983e6d
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.etl.domain.TableInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 库表基础信息Mapper接口
|
||||
|
@ -60,4 +61,7 @@ public interface TableInfoMapper extends BaseMapper<TableInfo>
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteTableInfoByIds(Long[] ids);
|
||||
|
||||
|
||||
TableInfo selectTableInfoByName(TableInfo table);
|
||||
}
|
||||
|
|
|
@ -60,4 +60,7 @@ public interface TableInfoService extends IService<TableInfo>
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteTableInfoById(Long id);
|
||||
|
||||
TableInfo selectTableInfoByName(TableInfo build);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.etl.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
@ -154,10 +155,7 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMapp
|
|||
PreparedStatement ps = conn.prepareStatement("select * from " + tableName1);
|
||||
ResultSet rset = ps.executeQuery();
|
||||
Long rowCount = 0L;
|
||||
while(rset.next())
|
||||
{
|
||||
rowCount++;
|
||||
}
|
||||
while(rset.next()) {rowCount++;}
|
||||
TableInfo build = TableInfo.builder()
|
||||
.basicId(basicConfigInfo.getId())
|
||||
.tableName(tableName1)
|
||||
|
@ -172,17 +170,19 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMapp
|
|||
eq(TableInfo::getTableName,build.getTableName());
|
||||
eq(TableInfo::getBasicId,basicConfigInfo.getId());
|
||||
}});
|
||||
new Runnable() {
|
||||
TableInfo table = tableInfoService.selectTableInfoByName(build);
|
||||
Runnable thread = new Runnable() {
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
syncData(finalConn,databaseName,build);
|
||||
syncData(finalConn, databaseName, table);
|
||||
} catch (SQLException e) {
|
||||
throw new ServletException("连接失败");
|
||||
}
|
||||
}
|
||||
};
|
||||
thread.run();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new ServletException("连接失败");
|
||||
|
@ -198,6 +198,7 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMapp
|
|||
" CASE WHEN COLUMN_KEY = 'PRI' THEN '是' ELSE '否' END AS '是否主键'," +
|
||||
" CASE \n" +
|
||||
" WHEN DATA_TYPE = 'int' THEN 'Integer' " +
|
||||
" WHEN DATA_TYPE = 'bigint' THEN 'Long' " +
|
||||
" WHEN DATA_TYPE = 'varchar' THEN 'String' " +
|
||||
" WHEN DATA_TYPE = 'decimal' THEN 'BigDecimal' " +
|
||||
" WHEN DATA_TYPE = 'tinyint' AND COLUMN_TYPE = 'tinyint(1)' THEN 'Boolean'" +
|
||||
|
@ -212,32 +213,26 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMapp
|
|||
"FROM INFORMATION_SCHEMA.COLUMNS WHERE \n" +
|
||||
"TABLE_SCHEMA = '" + databaseName + "' -- 替换为你的数据库名称 \n" +
|
||||
"AND TABLE_NAME = '" + table.getTableName() + "'");
|
||||
// "SELECT COLUMN_NAME,DATA_TYPE,IS_NULLABLE,COLUMN_KEY,COLUMN_DEFAULT,
|
||||
// COLUMN_COMMENT,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,
|
||||
// NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS
|
||||
// WHERE TABLE_SCHEMA = '数据库名' AND TABLE_NAME = '表名'"
|
||||
ResultSet resultSet = ps.executeQuery();
|
||||
ArrayList<Structure> structureList = new ArrayList<>();
|
||||
while (resultSet.next()){
|
||||
String columnName = resultSet.getObject(0).toString();
|
||||
String columnComment = resultSet.getObject(1).toString();
|
||||
String columnKey = resultSet.getObject(2).toString();
|
||||
String end = resultSet.getObject(3).toString();
|
||||
String dataType = resultSet.getObject(4).toString();
|
||||
String columnType = resultSet.getObject(5).toString();
|
||||
String characterMaximumLength = resultSet.getObject(6).toString();
|
||||
String NumericScale = resultSet.getObject(7).toString();
|
||||
String isNullable = resultSet.getObject(8).toString();
|
||||
String columnDefault = resultSet.getObject(9).toString();
|
||||
System.out.println(columnName);
|
||||
System.out.println(columnComment);
|
||||
System.out.println(columnKey);
|
||||
System.out.println(end);
|
||||
System.out.println(dataType);
|
||||
System.out.println(columnType);
|
||||
System.out.println(characterMaximumLength);
|
||||
System.out.println(NumericScale);
|
||||
System.out.println(isNullable);
|
||||
System.out.println(columnDefault);
|
||||
String columnName = (String) resultSet.getString(1);
|
||||
String columnComment = (String) resultSet.getObject(2);
|
||||
String columnKey = (String) resultSet.getObject(3);
|
||||
String end = (String) resultSet.getObject(4);
|
||||
String dataType = (String) resultSet.getObject(5);
|
||||
String columnType = (String) resultSet.getObject(6);
|
||||
String characterMaximumLength = String.valueOf(resultSet.getInt(7));
|
||||
String NumericScale = String.valueOf(resultSet.getInt(8));
|
||||
String isNullable = (String) resultSet.getObject(9);
|
||||
String columnDefault = (String) resultSet.getObject(10);
|
||||
|
||||
Structure build = Structure.builder()
|
||||
.tableId(table.getId())
|
||||
.columnName(columnName)
|
||||
.columnName(String.valueOf(columnName))
|
||||
.columnRemark(columnComment)
|
||||
.isPrimary("是".equals(columnKey) ? "Y" : "N")
|
||||
.javaType( end)
|
||||
|
@ -249,7 +244,11 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMapp
|
|||
.defaultValue( columnDefault)
|
||||
.build();
|
||||
log.info(build);
|
||||
structureList.add(build);
|
||||
structureService.saveOrUpdate(build,new LambdaUpdateWrapper<Structure>(){{
|
||||
eq(Structure::getTableId,build.getTableId());
|
||||
eq(Structure::getColumnName,build.getColumnName());
|
||||
eq(Structure::getRemark,build.getRemark());
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,48 +286,6 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMapp
|
|||
}catch (Exception exception){
|
||||
continue;
|
||||
}
|
||||
// ResultSet tables = metaData.getTables(
|
||||
// catalogs,
|
||||
// info.getDatabaseName(),
|
||||
// "%",
|
||||
// new String[]{"TABLE", "VIEW"});
|
||||
// while (tables.next()) {
|
||||
// //表名
|
||||
// String tableName = tables.getString("TABLE_NAME");
|
||||
// ResultSet rs = metaData.getColumns(catalogs, info.getDatabaseName(), tableName, "%");
|
||||
// try {
|
||||
// while (rs.next()) {
|
||||
//
|
||||
// HashMap<String, String> map = new HashMap<>();
|
||||
// // 列明
|
||||
// map.put("columnName", rs.getString("COLUMN_NAME"));
|
||||
// // 列类型
|
||||
// map.put("typeName", rs.getString("TYPE_NAME"));
|
||||
// // 列备注
|
||||
// map.put("remarks", rs.getString("REMARKS"));
|
||||
//// list.add(map);
|
||||
// //库名
|
||||
// System.out.println("TABLE_CAT" + "===" + rs.getString("TABLE_CAT"));
|
||||
//
|
||||
// System.out.println("TABLE_SCHEM" + "===" + rs.getString("TABLE_SCHEM"));
|
||||
// System.out.println("TABLE_NAME" + "===" + rs.getString("TABLE_NAME"));
|
||||
//// System.out.println("NON_UNIQUE" + "===" + rs.getString("NON_UNIQUE"));
|
||||
// System.out.println("INDEX_QUALIFIER" + "===" + rs.getString("INDEX_QUALIFIER"));
|
||||
// System.out.println("INDEX_NAME" + "===" + rs.getString("INDEX_NAME"));
|
||||
// System.out.println("TYPE" + "===" + rs.getString("TYPE"));
|
||||
// System.out.println("ORDINAL_POSITION" + "===" + rs.getString("ORDINAL_POSITION"));
|
||||
// System.out.println("COLUMN_NAME" + "===" + rs.getString("COLUMN_NAME"));
|
||||
// System.out.println("ASC_OR_DESC" + "===" + rs.getString("ASC_OR_DESC"));
|
||||
// System.out.println("CARDINALITY" + "===" + rs.getString("CARDINALITY"));
|
||||
// System.out.println("PAGES" + "===" + rs.getString("PAGES"));
|
||||
// System.out.println("FILTER_CONDITION" + "===" + rs.getString("FILTER_CONDITION"));
|
||||
//
|
||||
// }
|
||||
// }catch (Exception e){
|
||||
// log.error(e.getMessage());
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
} catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
|
|
|
@ -95,4 +95,9 @@ public class TableInfoServiceImpl extends ServiceImpl<TableInfoMapper, TableIn
|
|||
{
|
||||
return tableInfoMapper.deleteTableInfoById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableInfo selectTableInfoByName(TableInfo table) {
|
||||
return tableInfoMapper.selectTableInfoByName(table);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,12 @@
|
|||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectTableInfoByName" parameterType="com.muyu.etl.domain.TableInfo" resultMap="TableInfoResult">
|
||||
select * from table_info
|
||||
where basic_id = #{basicId} and table_name = #{tableName}
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insertTableInfo" parameterType="com.muyu.etl.domain.TableInfo" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into table_info
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
|
Loading…
Reference in New Issue