pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/hx/other/service/controller/SqlQueryController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/hx/other/service/controller/admin/AdminQueryRecordController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/hx/other/service/controller/admin/AdminQueryTempController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/hx/other/service/model/QueryRecord.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/hx/other/service/vo/BaseVo.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/hx/other/service/vo/ai/QueryRecordVo.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/application-local.properties | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
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> 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); src/main/java/com/hx/other/service/controller/admin/AdminQueryRecordController.java
New file @@ -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(); } } src/main/java/com/hx/other/service/controller/admin/AdminQueryTempController.java
New file @@ -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(); } } 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; } 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; } src/main/java/com/hx/other/service/vo/ai/QueryRecordVo.java
New file @@ -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; } 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