From 566411019444e53ca143298ee490d33cf510e28c Mon Sep 17 00:00:00 2001
From: guang <guang@guang.com>
Date: 星期五, 05 五月 2023 12:22:06 +0800
Subject: [PATCH] 增加phi正式使用版本

---
 src/main/resources/application-local.properties                       |   46 ++++++++++-----
 src/main/resources/application-prod.properties                        |   46 ++++++++++----
 src/main/java/com/hx/other/service/controller/SqlQueryController.java |    5 +
 src/main/java/com/hx/other/service/api/ai/SqlAiApi.java               |    2 
 src/main/java/com/hx/other/service/config/JdbcTemplateConfig.java     |   23 +++++++
 src/main/java/com/hx/other/service/config/DataSourceConfig.java       |   36 ++++++++++++
 src/main/java/com/hx/other/service/controller/TestController.java     |   21 +++++++
 7 files changed, 148 insertions(+), 31 deletions(-)

diff --git a/src/main/java/com/hx/other/service/api/ai/SqlAiApi.java b/src/main/java/com/hx/other/service/api/ai/SqlAiApi.java
index 951bc1b..ad3b6e9 100644
--- a/src/main/java/com/hx/other/service/api/ai/SqlAiApi.java
+++ b/src/main/java/com/hx/other/service/api/ai/SqlAiApi.java
@@ -15,7 +15,7 @@
     JSONObject getSql(@JSONBody String param);
 
     @Post(
-            url = "http://chatgpt.phiskin.com/chat/msg/short",
+            url = "http://chatgpt.phiskin.com/chat/msg/short/ai",
             headers = {
                     "Content-Type: application/json"
             }
diff --git a/src/main/java/com/hx/other/service/config/DataSourceConfig.java b/src/main/java/com/hx/other/service/config/DataSourceConfig.java
new file mode 100644
index 0000000..0912e34
--- /dev/null
+++ b/src/main/java/com/hx/other/service/config/DataSourceConfig.java
@@ -0,0 +1,36 @@
+package com.hx.other.service.config;
+
+import org.springframework.beans.factory.annotation.Qualifier;
+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 javax.sql.DataSource;
+
+/**
+ * 鏁版嵁婧愰厤缃�
+ * @Author: cmg
+ * @Date: 2023/5/5 10:56
+ */
+@Configuration
+public class DataSourceConfig {
+
+    @Bean(name = "readDataSource")
+    @Qualifier("readDataSource")
+    @ConfigurationProperties(prefix = "spring.datasource.read")
+    public DataSource readDataSource()
+    {
+        return DataSourceBuilder.create().build();
+    }
+
+    @Bean(name = "writeDataSource")
+    @Qualifier("writeDataSource")
+    @ConfigurationProperties(prefix = "spring.datasource.write")
+    @Primary
+    public DataSource writeDataSource()
+    {
+        return DataSourceBuilder.create().build();
+    }
+}
diff --git a/src/main/java/com/hx/other/service/config/JdbcTemplateConfig.java b/src/main/java/com/hx/other/service/config/JdbcTemplateConfig.java
new file mode 100644
index 0000000..3299c78
--- /dev/null
+++ b/src/main/java/com/hx/other/service/config/JdbcTemplateConfig.java
@@ -0,0 +1,23 @@
+package com.hx.other.service.config;
+
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.sql.DataSource;
+
+/**
+ * jdbc鏁版嵁婧愰厤缃�
+ * @Author: cmg
+ * @Date: 2023/5/5 10:59
+ */
+@Configuration
+public class JdbcTemplateConfig {
+
+    @Bean(name = "readJdbcTemplate")
+    public JdbcTemplate readJdbTemplate(@Qualifier("readDataSource") DataSource dataSource)
+    {
+        return new JdbcTemplate(dataSource);
+    }
+}
diff --git a/src/main/java/com/hx/other/service/controller/SqlQueryController.java b/src/main/java/com/hx/other/service/controller/SqlQueryController.java
index bc41cd9..03d0393 100644
--- a/src/main/java/com/hx/other/service/controller/SqlQueryController.java
+++ b/src/main/java/com/hx/other/service/controller/SqlQueryController.java
@@ -12,6 +12,8 @@
 import com.hx.other.service.vo.ai.SqlVo;
 import com.hx.resultTool.Result;
 import com.hx.util.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -36,7 +38,8 @@
     @Resource
     private SqlQueryTempService sqlQueryTempService;
 
-    @Resource
+    @Autowired
+    @Qualifier("readJdbcTemplate")
     private JdbcTemplate jdbcTemplate;
 
     @Resource
diff --git a/src/main/java/com/hx/other/service/controller/TestController.java b/src/main/java/com/hx/other/service/controller/TestController.java
new file mode 100644
index 0000000..acdbf9d
--- /dev/null
+++ b/src/main/java/com/hx/other/service/controller/TestController.java
@@ -0,0 +1,21 @@
+package com.hx.other.service.controller;
+
+import com.hx.resultTool.Result;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Author: cmg
+ * @Date: 2023/5/5 11:43
+ */
+@RestController
+@RequestMapping("/ai/test")
+public class TestController {
+
+    @RequestMapping("test")
+    public Result test()
+    {
+        return Result.success("test");
+    }
+
+}
diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties
index 2a882f0..e3a0366 100644
--- a/src/main/resources/application-local.properties
+++ b/src/main/resources/application-local.properties
@@ -2,23 +2,39 @@
 
 logging.config=classpath:log4j2-local.xml
 
-spring.datasource.url=jdbc:mysql://localhost:3306/phi_other_service?useUnicode=true&characterEncoding=UTF-8
-spring.datasource.username=root
-spring.datasource.password=root
-spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+spring.datasource.write.jdbc-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.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
+spring.datasource.read.password=root
+spring.datasource.read.driver-class-name=com.mysql.jdbc.Driver
 
 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.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
 
 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
@@ -36,4 +52,4 @@
 pagehelper.reasonable=true
 pagehelper.support-methods-arguments=true
 
-forest.timeout=10000
\ No newline at end of file
+forest.timeout=10000
diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties
index adaa88d..9bd252e 100644
--- a/src/main/resources/application-prod.properties
+++ b/src/main/resources/application-prod.properties
@@ -2,23 +2,41 @@
 
 logging.config=classpath:log4j2-local.xml
 
-spring.datasource.url=jdbc:mysql://localhost:3306/phi_other_service?useUnicode=true&characterEncoding=UTF-8
-spring.datasource.username=root
-spring.datasource.password=root
-spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+#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
+
+#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.driver-class-name=com.mysql.cj.jdbc.Driver
 
 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.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
 
 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