新增查询条数方法

master
面包骑士 2024-09-06 10:19:32 +08:00
parent fd57183af4
commit f8f07247ae
3 changed files with 35 additions and 0 deletions

View File

@ -41,6 +41,19 @@ public class DataValueController {
return Result.success(dataValueList);
}
/**
* IDSQL
*
* @param dataValueModel IDsql
* @return DataValue{kltv}
*/
@PostMapping("/getTableValueTotal")
@Operation(summary = "根据基础表ID和SQL语句新增数据", description = "根据基础表ID和SQL语句新增数据")
public Result getTableValueTotal(@RequestBody DataValueModel dataValueModel) {
Integer i = dataValueService.getTableValueTotal(dataValueModel);
return Result.success(i);
}
/**
* IDSQL
*

View File

@ -21,4 +21,6 @@ public interface DataValueService extends IService<DataValue> {
List<DataValue> findTableValueByTableName(Long basicId, String tableName) throws SQLException;
Integer addTableValue(DataValueModel dataValueModel);
Integer getTableValueTotal(DataValueModel dataValueModel);
}

View File

@ -140,6 +140,26 @@ public class DataValueServiceImpl extends ServiceImpl<DataValueMapper, DataValue
throw new RuntimeException(e);
}
}
@Override
public Integer getTableValueTotal(DataValueModel dataValueModel) {
MysqlQuery mysqlQuery = new MysqlQuery();
mysqlQuery.setDataSourceId(String.valueOf(dataValueModel.getBasicId()));
DataSource dataSource = dataSourceService.getById(dataValueModel.getBasicId());
MysqlPool mysqlPool = new MysqlPool(dataSource);
mysqlPool.init();
Connection conn = mysqlPool.getConn();
try (Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery(dataValueModel.getSql())) {
if (resultSet.next()) {
return resultSet.getInt(1);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return 0;
}
private static final int THREAD_POOL_SIZE = 10;
private final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE);