From 7201205af85508421037119ba66b3a6a48de61ec Mon Sep 17 00:00:00 2001
From: guang <guang@guang.com>
Date: 星期六, 06 五月 2023 11:58:57 +0800
Subject: [PATCH] 分布及druid

---
 src/main/java/com/hx/other/service/PhiOtherService.java                             |    1 
 src/main/resources/application-local.properties                                     |   25 ++++++------
 src/main/resources/application-prod.properties                                      |   45 ++++++++--------------
 src/main/java/com/hx/other/service/controller/admin/AdminQueryRecordController.java |    6 +-
 src/main/java/com/hx/other/service/config/DataSourceConfig.java                     |   19 +++++++++
 src/main/java/com/hx/other/service/controller/admin/AdminQueryTempController.java   |    4 -
 6 files changed, 51 insertions(+), 49 deletions(-)

diff --git a/src/main/java/com/hx/other/service/PhiOtherService.java b/src/main/java/com/hx/other/service/PhiOtherService.java
index b774bbc..9fa0e23 100644
--- a/src/main/java/com/hx/other/service/PhiOtherService.java
+++ b/src/main/java/com/hx/other/service/PhiOtherService.java
@@ -2,6 +2,7 @@
 
 import com.hx.other.service.config.UniqueNameGenerator;
 import com.thebeastshop.forest.springboot.annotation.ForestScan;
+import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
diff --git a/src/main/java/com/hx/other/service/config/DataSourceConfig.java b/src/main/java/com/hx/other/service/config/DataSourceConfig.java
index 0912e34..ba495ae 100644
--- a/src/main/java/com/hx/other/service/config/DataSourceConfig.java
+++ b/src/main/java/com/hx/other/service/config/DataSourceConfig.java
@@ -1,13 +1,27 @@
 package com.hx.other.service.config;
 
+import com.alibaba.druid.pool.DruidDataSource;
+import com.github.pagehelper.PageInterceptor;
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionFactoryBean;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.boot.jdbc.DataSourceBuilder;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Primary;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.ResourcePatternResolver;
 
 import javax.sql.DataSource;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
 
 /**
  * 鏁版嵁婧愰厤缃�
@@ -16,6 +30,9 @@
  */
 @Configuration
 public class DataSourceConfig {
+
+    @Value("${mybatis.mapperLocations}")
+    private String writeMapperLocatioin;
 
     @Bean(name = "readDataSource")
     @Qualifier("readDataSource")
@@ -31,6 +48,6 @@
     @Primary
     public DataSource writeDataSource()
     {
-        return DataSourceBuilder.create().build();
+        return new DruidDataSource();
     }
 }
diff --git a/src/main/java/com/hx/other/service/controller/admin/AdminQueryRecordController.java b/src/main/java/com/hx/other/service/controller/admin/AdminQueryRecordController.java
index 90b71e6..30a46fd 100644
--- a/src/main/java/com/hx/other/service/controller/admin/AdminQueryRecordController.java
+++ b/src/main/java/com/hx/other/service/controller/admin/AdminQueryRecordController.java
@@ -50,7 +50,7 @@
             baseVo.setPageNum(1);
         }
 
-        if(baseVo.getPageSize() == null || baseVo.getPageSize() <= 0 || baseVo.getPageSize() >= 100)
+        if(baseVo.getPageSize() == null || baseVo.getPageSize() <= 0 || baseVo.getPageSize() > 100)
         {
             baseVo.setPageSize(20);
         }
@@ -61,7 +61,7 @@
         map.put("isDel", BaseEntity.NO);
 
         StringBuilder stringBuilder = new StringBuilder();
-        stringBuilder.append("select createTime from query_record where isDel = #{m.isDel}");
+        stringBuilder.append("select * from query_record where isDel = #{m.isDel}");
 
         if(!StringUtils.isEmpty(baseVo.getKeyWord()))
         {
@@ -76,7 +76,7 @@
         }
 
         sqlSentence.setSqlSentence(stringBuilder.toString());
-        PageHelper.startPage(1, 1, " createTime desc ");
+        PageHelper.startPage(baseVo.getPageNum(), baseVo.getPageSize(), " createTime desc ");
         List<QueryRecord> list = queryRecordService.selectList(sqlSentence);
         PageInfo<QueryRecord> pageInfo = new PageInfo<>(list);
 
diff --git a/src/main/java/com/hx/other/service/controller/admin/AdminQueryTempController.java b/src/main/java/com/hx/other/service/controller/admin/AdminQueryTempController.java
index f4cc76a..26dd6d8 100644
--- a/src/main/java/com/hx/other/service/controller/admin/AdminQueryTempController.java
+++ b/src/main/java/com/hx/other/service/controller/admin/AdminQueryTempController.java
@@ -47,12 +47,10 @@
             baseVo.setPageNum(1);
         }
 
-        if(baseVo.getPageSize() == null || baseVo.getPageSize() <= 0 || baseVo.getPageSize() >= 100)
+        if(baseVo.getPageSize() == null || baseVo.getPageSize() <= 0 || baseVo.getPageSize() > 100)
         {
             baseVo.setPageSize(20);
         }
-
-        log.info(baseVo.getPageNum() + " " + baseVo.getPageSize());
 
         SqlSentence sqlSentence = new SqlSentence();
         Map<String, Object> map = new HashMap<>();
diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties
index 1cc8789..8894ae6 100644
--- a/src/main/resources/application-local.properties
+++ b/src/main/resources/application-local.properties
@@ -2,10 +2,10 @@
 
 logging.config=classpath:log4j2-local.xml
 
-spring.datasource.write.jdbc-url=jdbc:mysql://localhost:3306/phi_other_service?useUnicode=true&characterEncoding=UTF-8
+spring.datasource.write.url=jdbc:mysql://localhost:3306/phi_other_service?useUnicode=true&characterEncoding=UTF-8
 spring.datasource.write.username=root
 spring.datasource.write.password=root
-spring.datasource.write.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.write.driverClassName=com.mysql.cj.jdbc.Driver
 
 spring.datasource.read.jdbc-url=jdbc:mysql://localhost:3306/phi_other_service_read?useUnicode=true&characterEncoding=UTF-8
 spring.datasource.read.username=root
@@ -14,16 +14,16 @@
 
 logging.level.org.springframework.boot.autoconfigure = error
 
-spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
-spring.datasource.druid.filters=stat,wall,log4j
-spring.datasource.druid.initial-size=10
-spring.datasource.druid.max-active=50
-spring.datasource.druid.min-idle=10
-spring.datasource.druid.max-wait=20
-spring.datasource.druid.time-between-eviction-runs-millis=60000
-spring.datasource.druid.min-evictable-idle-time-millis=300000
-spring.datasource.druid.test-on-borrow=true
-spring.datasource.druid.test-while-idle=false
+spring.datasource.write.type=com.alibaba.druid.pool.DruidDataSource
+spring.datasource.write.filters=stat,wall,log4j
+spring.datasource.write.initial-size=10
+spring.datasource.write.max-active=50
+spring.datasource.write.min-idle=10
+spring.datasource.write.max-wait=20
+spring.datasource.write.time-between-eviction-runs-millis=60000
+spring.datasource.write.min-evictable-idle-time-millis=300000
+spring.datasource.write.test-on-borrow=true
+spring.datasource.write.test-while-idle=false
 
 mybatis.type-aliases-package=com.hx.other.servcie.model
 mybatis.mapperLocations=com/hx/other/service/dao/mapper/xml/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml,classpath*:mapper/*.xml
@@ -40,6 +40,5 @@
 pagehelper.params=count=countSql
 pagehelper.reasonable=true
 pagehelper.support-methods-arguments=true
-pagehelper.auto-runtime-dialect=true
 
 forest.timeout=10000
diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties
index 9bd252e..8894ae6 100644
--- a/src/main/resources/application-prod.properties
+++ b/src/main/resources/application-prod.properties
@@ -2,41 +2,28 @@
 
 logging.config=classpath:log4j2-local.xml
 
-#ai?
-spring.datasource.write.jdbc-url=jdbc:mysql://172.17.0.2:3306/ai_data?useUnicode=true&characterEncoding=UTF-8
-spring.datasource.write.username=phiskin_ai
-spring.datasource.write.password=phiskin985AI6DATAfvrg
-spring.datasource.write.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.write.url=jdbc:mysql://localhost:3306/phi_other_service?useUnicode=true&characterEncoding=UTF-8
+spring.datasource.write.username=root
+spring.datasource.write.password=root
+spring.datasource.write.driverClassName=com.mysql.cj.jdbc.Driver
 
-#bi??
-spring.datasource.read.jdbc-url=jdbc:mysql://172.17.0.45:3306/phiskin_bi?useUnicode=true&characterEncoding=UTF-8
-spring.datasource.read.username=phiskin_bi
-spring.datasource.read.password=phiskinBI33W6854#%
+spring.datasource.read.jdbc-url=jdbc:mysql://localhost:3306/phi_other_service_read?useUnicode=true&characterEncoding=UTF-8
+spring.datasource.read.username=root
+spring.datasource.read.password=root
 spring.datasource.read.driver-class-name=com.mysql.cj.jdbc.Driver
 
 logging.level.org.springframework.boot.autoconfigure = error
 
 spring.datasource.write.type=com.alibaba.druid.pool.DruidDataSource
-spring.datasource.write.druid.filters=stat,wall,log4j
-spring.datasource.write.druid.initial-size=10
-spring.datasource.write.druid.max-active=50
-spring.datasource.write.druid.min-idle=10
-spring.datasource.write.druid.max-wait=20
-spring.datasource.write.druid.time-between-eviction-runs-millis=60000
-spring.datasource.write.druid.min-evictable-idle-time-millis=300000
-spring.datasource.write.druid.test-on-borrow=true
-spring.datasource.write.druid.test-while-idle=false
-
-spring.datasource.read.type=com.alibaba.druid.pool.DruidDataSource
-spring.datasource.read.druid.filters=stat,wall,log4j
-spring.datasource.read.druid.initial-size=10
-spring.datasource.read.druid.max-active=50
-spring.datasource.read.druid.min-idle=10
-spring.datasource.read.druid.max-wait=20
-spring.datasource.read.druid.time-between-eviction-runs-millis=60000
-spring.datasource.read.druid.min-evictable-idle-time-millis=300000
-spring.datasource.read.druid.test-on-borrow=true
-spring.datasource.read.druid.test-while-idle=false
+spring.datasource.write.filters=stat,wall,log4j
+spring.datasource.write.initial-size=10
+spring.datasource.write.max-active=50
+spring.datasource.write.min-idle=10
+spring.datasource.write.max-wait=20
+spring.datasource.write.time-between-eviction-runs-millis=60000
+spring.datasource.write.min-evictable-idle-time-millis=300000
+spring.datasource.write.test-on-borrow=true
+spring.datasource.write.test-while-idle=false
 
 mybatis.type-aliases-package=com.hx.other.servcie.model
 mybatis.mapperLocations=com/hx/other/service/dao/mapper/xml/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml,classpath*:mapper/*.xml

--
Gitblit v1.8.0