From 56608e48288a97e59fb97340187f57f4a4fcf11e Mon Sep 17 00:00:00 2001
From: guang <guang@guang.com>
Date: 星期六, 06 五月 2023 09:19:59 +0800
Subject: [PATCH] 增加phi正式使用版本

---
 src/main/java/com/hx/other/service/model/QueryRecord.java                           |    2 
 src/main/java/com/hx/other/service/vo/BaseVo.java                                   |    4 
 src/main/resources/application-local.properties                                     |   36 ++----
 src/main/java/com/hx/other/service/controller/SqlQueryController.java               |    1 
 src/main/java/com/hx/other/service/controller/admin/AdminQueryRecordController.java |  114 ++++++++++++++++++++++
 pom.xml                                                                             |   12 ++
 src/main/java/com/hx/other/service/vo/ai/QueryRecordVo.java                         |   15 +++
 src/main/java/com/hx/other/service/controller/admin/AdminQueryTempController.java   |   91 ++++++++++++++++++
 8 files changed, 251 insertions(+), 24 deletions(-)

diff --git a/pom.xml b/pom.xml
index 6a42bf0..5b9504d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,6 +78,18 @@
             <!--<scope>provided</scope>-->
         </dependency>
 
+        <!--pageHelper鍒嗛〉-->
+        <dependency>
+            <groupId>com.github.pagehelper</groupId>
+            <artifactId>pagehelper-spring-boot-starter</artifactId>
+            <version>1.4.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.github.pagehelper</groupId>
+            <artifactId>pagehelper</artifactId>
+            <version>5.1.11</version>
+        </dependency>
     </dependencies>
 
     <profiles>
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 03d0393..9ecabf9 100644
--- a/src/main/java/com/hx/other/service/controller/SqlQueryController.java
+++ b/src/main/java/com/hx/other/service/controller/SqlQueryController.java
@@ -107,6 +107,7 @@
         }
 
         SqlVo sqlVo = new SqlVo();
+        sqlVo.setNow(sql);
         sqlVo.setOrigin(queryRecord.getAiResult());
         sqlVo.setQueryContent(queryRecord.getAiQueryContent());
         sqlVo.setIsArr(1);
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
new file mode 100644
index 0000000..90b71e6
--- /dev/null
+++ b/src/main/java/com/hx/other/service/controller/admin/AdminQueryRecordController.java
@@ -0,0 +1,114 @@
+package com.hx.other.service.controller.admin;
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.hx.common.BaseController;
+import com.hx.mybatisTool.SqlSentence;
+import com.hx.other.service.model.BaseEntity;
+import com.hx.other.service.model.QueryRecord;
+import com.hx.other.service.model.SqlQueryTemp;
+import com.hx.other.service.service.QueryRecordService;
+import com.hx.other.service.service.SqlQueryTempService;
+import com.hx.other.service.vo.BaseVo;
+import com.hx.other.service.vo.ai.QueryRecordVo;
+import com.hx.resultTool.Result;
+import com.hx.util.StringUtils;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Author: cmg
+ * @Date: 2023/5/5 14:37
+ */
+@RestController
+@RequestMapping("/ai/query/record")
+public class AdminQueryRecordController extends BaseController {
+
+    @Resource
+    private QueryRecordService queryRecordService;
+
+    @Resource
+    private SqlQueryTempService sqlQueryTempService;
+
+    @PostMapping("/list")
+    public Result list(@RequestBody(required = false) QueryRecordVo baseVo)
+    {
+        if(baseVo == null)
+        {
+            baseVo = new QueryRecordVo();
+        }
+
+        if(baseVo.getPageNum() == null || baseVo.getPageNum() <= 0)
+        {
+            baseVo.setPageNum(1);
+        }
+
+        if(baseVo.getPageSize() == null || baseVo.getPageSize() <= 0 || baseVo.getPageSize() >= 100)
+        {
+            baseVo.setPageSize(20);
+        }
+
+        SqlSentence sqlSentence = new SqlSentence();
+        Map<String, Object> map = new HashMap<>();
+        sqlSentence.setM(map);
+        map.put("isDel", BaseEntity.NO);
+
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder.append("select createTime from query_record where isDel = #{m.isDel}");
+
+        if(!StringUtils.isEmpty(baseVo.getKeyWord()))
+        {
+            stringBuilder.append(" and content like #{m.content} ");
+            map.put("content", "%" + baseVo.getKeyWord() + "%");
+        }
+
+        if(baseVo.getIsFromTemp() != null)
+        {
+            stringBuilder.append(" and isFromQuery = #{m.isFromQuery} ");
+            map.put("isFromQuery", baseVo.getIsFromTemp());
+        }
+
+        sqlSentence.setSqlSentence(stringBuilder.toString());
+        PageHelper.startPage(1, 1, " createTime desc ");
+        List<QueryRecord> list = queryRecordService.selectList(sqlSentence);
+        PageInfo<QueryRecord> pageInfo = new PageInfo<>(list);
+
+        return Result.success(pageInfo);
+    }
+
+    @PostMapping("/change/temp")
+    public Result changeToTemp(@RequestBody(required = false) BaseVo baseVo)
+    {
+        if(baseVo == null || StringUtils.isEmpty(baseVo.getId()))
+        {
+            throwParamException("璇烽�夋嫨璁板綍");
+        }
+
+        QueryRecord queryRecord = queryRecordService.selectOneByKey(baseVo.getId());
+        if(queryRecord == null)
+        {
+            throwParamException("鎵句笉鍒拌褰�");
+        }
+
+        String sql = sqlQueryTempService.selectByContent(queryRecord.getContent());
+        if(!StringUtils.isEmpty(sql))
+        {
+            throwServiceException("宸插姞鍏ユā鏉�");
+        }
+
+        SqlQueryTemp sqlQueryTemp = new SqlQueryTemp();
+        sqlQueryTemp.setSqlStr(queryRecord.getSqlStr());
+        sqlQueryTemp.setContent(queryRecord.getContent());
+        sqlQueryTemp.setIsUp(BaseEntity.YES);
+        sqlQueryTempService.insert(sqlQueryTemp);
+
+        return Result.success();
+    }
+}
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
new file mode 100644
index 0000000..f4cc76a
--- /dev/null
+++ b/src/main/java/com/hx/other/service/controller/admin/AdminQueryTempController.java
@@ -0,0 +1,91 @@
+package com.hx.other.service.controller.admin;
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.hx.common.BaseController;
+import com.hx.mybatisTool.SqlSentence;
+import com.hx.other.service.model.BaseEntity;
+import com.hx.other.service.model.SqlQueryTemp;
+import com.hx.other.service.service.SqlQueryTempService;
+import com.hx.other.service.vo.BaseVo;
+import com.hx.other.service.vo.ai.QueryRecordVo;
+import com.hx.resultTool.Result;
+import com.hx.util.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Author: cmg
+ * @Date: 2023/5/5 14:37
+ */
+@Slf4j
+@RestController
+@RequestMapping("/ai/query/temp")
+public class AdminQueryTempController extends BaseController {
+
+    @Resource
+    private SqlQueryTempService sqlQueryTempService;
+
+    @PostMapping("/list")
+    public Result list(@RequestBody(required = false) QueryRecordVo baseVo)
+    {
+        if(baseVo == null)
+        {
+            baseVo = new QueryRecordVo();
+        }
+
+        if(baseVo.getPageNum() == null || baseVo.getPageNum() <= 0)
+        {
+            baseVo.setPageNum(1);
+        }
+
+        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<>();
+        sqlSentence.setM(map);
+        map.put("isDel", BaseEntity.NO);
+
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder.append("select * from sql_query_temp where isDel = #{m.isDel}");
+
+        if(!StringUtils.isEmpty(baseVo.getKeyWord()))
+        {
+            stringBuilder.append(" and content like #{m.content} ");
+            map.put("content", "%" + baseVo.getKeyWord() + "%");
+        }
+
+        PageHelper.startPage(baseVo.getPageNum(), baseVo.getPageSize(), " createTime desc ");
+        sqlSentence.setSqlSentence(stringBuilder.toString());
+        List<SqlQueryTemp> list = sqlQueryTempService.selectList(sqlSentence);
+        PageInfo<SqlQueryTemp> pageInfo = new PageInfo<>(list);
+
+        return Result.success(pageInfo);
+    }
+
+    @PostMapping("/delete")
+    public Result delete(@RequestBody(required = false) BaseVo baseVo)
+    {
+        if(baseVo == null || StringUtils.isEmpty(baseVo.getId()))
+        {
+            throwParamException("璇烽�夋嫨璁板綍");
+        }
+
+        sqlQueryTempService.deleteOne(baseVo.getId());
+
+        return Result.success();
+    }
+}
diff --git a/src/main/java/com/hx/other/service/model/QueryRecord.java b/src/main/java/com/hx/other/service/model/QueryRecord.java
index 29968ed..90d0d47 100644
--- a/src/main/java/com/hx/other/service/model/QueryRecord.java
+++ b/src/main/java/com/hx/other/service/model/QueryRecord.java
@@ -37,6 +37,6 @@
     @Column(comment = "sql鏌ヨ鐨勬椂闂达紝璞鏁�", length = 13, type = MySqlTypeConstant.BIGINT)
     private Long sqlTime;
 
-    @Column(comment = "鏄惁鏉ヨ嚜妯℃嫙", length = 2, type = MySqlTypeConstant.TINYINT)
+    @Column(comment = "鏄惁鏉ヨ嚜妯℃澘", length = 2, type = MySqlTypeConstant.TINYINT)
     private Integer isFromQuery = BaseEntity.NO;
 }
diff --git a/src/main/java/com/hx/other/service/vo/BaseVo.java b/src/main/java/com/hx/other/service/vo/BaseVo.java
index 2695ee3..ef8c0e0 100644
--- a/src/main/java/com/hx/other/service/vo/BaseVo.java
+++ b/src/main/java/com/hx/other/service/vo/BaseVo.java
@@ -13,4 +13,8 @@
     private String id;
 
     private String keyWord;
+
+    private Integer pageNum;
+
+    private Integer pageSize;
 }
diff --git a/src/main/java/com/hx/other/service/vo/ai/QueryRecordVo.java b/src/main/java/com/hx/other/service/vo/ai/QueryRecordVo.java
new file mode 100644
index 0000000..a8c3912
--- /dev/null
+++ b/src/main/java/com/hx/other/service/vo/ai/QueryRecordVo.java
@@ -0,0 +1,15 @@
+package com.hx.other.service.vo.ai;
+
+import com.hx.other.service.vo.BaseVo;
+import lombok.Data;
+
+/**
+ * 鏌ヨ璁板綍vo
+ * @Author: cmg
+ * @Date: 2023/5/5 15:07
+ */
+@Data
+public class QueryRecordVo extends BaseVo {
+
+    private Integer isFromTemp;
+}
diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties
index e3a0366..1cc8789 100644
--- a/src/main/resources/application-local.properties
+++ b/src/main/resources/application-local.properties
@@ -5,36 +5,25 @@
 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.write.driver-class-name=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
 spring.datasource.read.password=root
-spring.datasource.read.driver-class-name=com.mysql.jdbc.Driver
+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.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
 
 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
@@ -51,5 +40,6 @@
 pagehelper.params=count=countSql
 pagehelper.reasonable=true
 pagehelper.support-methods-arguments=true
+pagehelper.auto-runtime-dialect=true
 
 forest.timeout=10000

--
Gitblit v1.8.0