数据添加更改
parent
2c37501b9e
commit
288e36e2e7
|
@ -172,16 +172,12 @@ public class ProductServiceImpl implements ProductService {
|
|||
|
||||
@Override
|
||||
public int addProduct(Long basicId, Long tableId, DataValue[][] listList) {
|
||||
// TableInfo tableInfoDataSources = tableInfoService.getById(basicId);
|
||||
// Long basicId1 = tableInfoDataSources.getBasicId();
|
||||
|
||||
Source dataSources = sourceService.getById(basicId);
|
||||
TableInfo tableInfo = tableInfoService.getById(tableId);
|
||||
String tableName = tableInfo.getTableName();
|
||||
|
||||
HikariDataSource hikariDataSource = HikariPool.getHikariDataSource(dataSources);
|
||||
|
||||
// HikariDataSource hikariDataSource = new HikariDataSource(hikariConfig);
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(8);
|
||||
AtomicInteger addCount = new AtomicInteger();
|
||||
|
||||
|
@ -192,11 +188,14 @@ public class ProductServiceImpl implements ProductService {
|
|||
conn.setAutoCommit(false); // 开启事务
|
||||
|
||||
for (DataValue[][] batch : batches) {
|
||||
log.info("数量batch{}", batch.length);
|
||||
executorService.submit(() -> {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
|
||||
String sql = buildBatchInsertSQL(tableName, batch);
|
||||
|
||||
stmt.executeUpdate(sql);
|
||||
|
||||
addCount.addAndGet(batch.length);
|
||||
} catch (SQLException e) {
|
||||
log.error("SQLException异常发生", e);
|
||||
|
@ -237,7 +236,6 @@ public class ProductServiceImpl implements ProductService {
|
|||
// 删除最后一个逗号和空格
|
||||
columns.delete(columns.length() - 2, columns.length());
|
||||
|
||||
|
||||
// 构建值部分
|
||||
for (DataValue[] dataValueList : batch) {
|
||||
values.append("(");
|
||||
|
@ -251,6 +249,7 @@ public class ProductServiceImpl implements ProductService {
|
|||
values.delete(values.length() - 2, values.length());
|
||||
// 完成 SQL 插入语句
|
||||
String sql = "INSERT INTO " + tableName + " " + columns.toString() + ") " + values.toString();
|
||||
log.info("执行的sql添加的sql语句"+sql);
|
||||
return sql;
|
||||
}
|
||||
|
||||
|
@ -307,5 +306,4 @@ public class ProductServiceImpl implements ProductService {
|
|||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue