From c2dafcc271950ce1a469b2c7e3b3aca3f9b6005e Mon Sep 17 00:00:00 2001 From: haha Date: Tue, 8 Jul 2025 22:45:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E5=9E=8B=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E8=BF=9E=E6=8E=A5=E6=B1=A0=E4=BB=A3=E7=A0=81=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yanzhu/manage/bim/BimDataSource.java | 5 +- .../controller/bim/BimModelController.java | 53 +++++++++++-------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/bim/BimDataSource.java b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/bim/BimDataSource.java index a670f8de..330e9a1a 100644 --- a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/bim/BimDataSource.java +++ b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/bim/BimDataSource.java @@ -30,8 +30,11 @@ public class BimDataSource { HikariConfig config = new HikariConfig(); config.setDriverClassName(driverName); config.setJdbcUrl(url); - config.setConnectionTimeout(120*1000L); + config.setConnectionTimeout(60000L); + config.setIdleTimeout(60000L); + config.setMaxLifetime(600000L); config.setMaximumPoolSize(100); + config.setMinimumIdle(5); config.setConnectionTestQuery("SELECT 1"); DataSource ds= new HikariDataSource(config); dataSourceMap.put(dbName, ds); diff --git a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/bim/BimModelController.java b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/bim/BimModelController.java index beadce81..a7c7437e 100644 --- a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/bim/BimModelController.java +++ b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/bim/BimModelController.java @@ -13,8 +13,8 @@ import com.yanzhu.manage.domain.bim.ModelTypeVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import javax.sql.DataSource; import java.io.File; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; @@ -80,8 +80,8 @@ public class BimModelController { return AjaxResult.error("file not found!"); } try { - DataSource ds = bimDataSource.getDataSource(name); - PreparedStatement pss= ds.getConnection().prepareStatement(sql); + Connection conn = bimDataSource.getDataSource(name).getConnection(); + PreparedStatement pss= conn.prepareStatement(sql); if(StringUtils.isNotEmpty(pid)) { pss.setString(1,pid); } @@ -99,6 +99,7 @@ public class BimModelController { list.add(modelTreeVo); } redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); + conn.close(); return AjaxResult.success(list); } catch (Exception e) { return AjaxResult.error(e.getMessage()); @@ -130,8 +131,8 @@ public class BimModelController { return AjaxResult.error("file not found!"); } try { - DataSource ds = bimDataSource.getDataSource(name); - PreparedStatement pss= ds.getConnection().prepareStatement(sql); + Connection conn = bimDataSource.getDataSource(name).getConnection(); + PreparedStatement pss= conn.prepareStatement(sql); for (int i = 1; i <= glids.size(); i++) { pss.setLong(i, glids.get(i - 1)); } @@ -149,6 +150,7 @@ public class BimModelController { list.add(modelTreeVo); } redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); + conn.close(); return AjaxResult.success(list); } catch (Exception e) { return AjaxResult.error(e.getMessage()); @@ -167,8 +169,8 @@ public class BimModelController { return AjaxResult.error("file not found!"); } try { - DataSource ds = bimDataSource.getDataSource(name); - PreparedStatement pss= ds.getConnection().prepareStatement(sql); + Connection conn = bimDataSource.getDataSource(name).getConnection(); + PreparedStatement pss= conn.prepareStatement(sql); pss.setString(1,externalId); ResultSet rs = pss.executeQuery(); List list = new ArrayList<>(); @@ -184,6 +186,7 @@ public class BimModelController { list.add(modelTreeVo); } redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); + conn.close(); return AjaxResult.success(list); } catch (Exception e) { return AjaxResult.error(e.getMessage()); @@ -222,8 +225,8 @@ public class BimModelController { return AjaxResult.error("file not found!"); } try { - DataSource ds = bimDataSource.getDataSource(name); - PreparedStatement pss= ds.getConnection().prepareStatement(sql); + Connection conn = bimDataSource.getDataSource(name).getConnection(); + PreparedStatement pss= conn.prepareStatement(sql); if(StringUtils.isNotEmpty(pid)) { pss.setString(1,pid); } @@ -241,6 +244,7 @@ public class BimModelController { list.add(modelTreeVo); } redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); + conn.close(); return AjaxResult.success(list); } catch (Exception e) { return AjaxResult.error(e.getMessage()); @@ -250,7 +254,6 @@ public class BimModelController { /** * 叶子节点的model_tree查询 * @param name - * @param pid * @return */ @PostMapping("/modelTreeAllLeafChildByGlids/{name}") @@ -288,8 +291,8 @@ public class BimModelController { return AjaxResult.error("file not found!"); } try { - DataSource ds = bimDataSource.getDataSource(name); - PreparedStatement pss= ds.getConnection().prepareStatement(sql); + Connection conn = bimDataSource.getDataSource(name).getConnection(); + PreparedStatement pss= conn.prepareStatement(sql); for (int i = 1; i <= glids.size(); i++) { pss.setString(i, glids.get(i - 1)); } @@ -307,6 +310,7 @@ public class BimModelController { list.add(modelTreeVo); } redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); + conn.close(); return AjaxResult.success(list); } catch (Exception e) { return AjaxResult.error(e.getMessage()); @@ -340,8 +344,8 @@ public class BimModelController { return AjaxResult.error("file not found!"); } try { - DataSource ds = bimDataSource.getDataSource(name); - PreparedStatement pss= ds.getConnection().prepareStatement(sql); + Connection conn = bimDataSource.getDataSource(name).getConnection(); + PreparedStatement pss= conn.prepareStatement(sql); if(StringUtils.isNotEmpty(pid)) { pss.setString(1,pid); } @@ -359,6 +363,7 @@ public class BimModelController { list.add(modelTreeVo); } redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); + conn.close(); return AjaxResult.success(list); } catch (Exception e) { return AjaxResult.error(e.getMessage()); @@ -398,8 +403,8 @@ public class BimModelController { return AjaxResult.error("file not found!"); } try { - DataSource ds = bimDataSource.getDataSource(name); - PreparedStatement pss= ds.getConnection().prepareStatement(sql); + Connection conn = bimDataSource.getDataSource(name).getConnection(); + PreparedStatement pss= conn.prepareStatement(sql); if(StringUtils.isNotEmpty(pid)) { pss.setString(1,pid); } @@ -417,6 +422,7 @@ public class BimModelController { list.add(vo); } redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); + conn.close(); return AjaxResult.success(list); } catch (Exception e) { return AjaxResult.error(e.getMessage()); @@ -450,8 +456,8 @@ public class BimModelController { return AjaxResult.error("file not found!"); } try { - DataSource ds = bimDataSource.getDataSource(name); - PreparedStatement pss= ds.getConnection().prepareStatement(sql); + Connection conn = bimDataSource.getDataSource(name).getConnection(); + PreparedStatement pss= conn.prepareStatement(sql); if(StringUtils.isNotEmpty(pid)) { pss.setString(1,pid); } @@ -469,6 +475,7 @@ public class BimModelController { list.add(vo); } redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); + conn.close(); return AjaxResult.success(list); } catch (Exception e) { return AjaxResult.error(e.getMessage()); @@ -492,8 +499,8 @@ public class BimModelController { return AjaxResult.error("file not found!"); } try { - DataSource ds = bimDataSource.getDataSource(name); - PreparedStatement pss = ds.getConnection().prepareStatement(sql); + Connection conn = bimDataSource.getDataSource(name).getConnection(); + PreparedStatement pss= conn.prepareStatement(sql); pss.setLong(1, externalId); ResultSet rs = pss.executeQuery(); @@ -513,6 +520,7 @@ public class BimModelController { list.add(vo); } redisService.setCacheObject(key, list, 60 * 60 * 24L, TimeUnit.SECONDS); + conn.close(); return AjaxResult.success(list); } catch (Exception e) { return AjaxResult.error(e.getMessage()); @@ -544,8 +552,8 @@ public class BimModelController { return AjaxResult.error("file not found!"); } try { - DataSource ds = bimDataSource.getDataSource(name); - PreparedStatement pss= ds.getConnection().prepareStatement(sql); + Connection conn = bimDataSource.getDataSource(name).getConnection(); + PreparedStatement pss= conn.prepareStatement(sql); for (int i = 1; i <= glids.size(); i++) { pss.setLong(i, glids.get(i - 1)); } @@ -566,6 +574,7 @@ public class BimModelController { list.add(vo); } redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); + conn.close(); return AjaxResult.success(list); } catch (Exception e) { return AjaxResult.error(e.getMessage());