提交 | 用户 | age
|
56608e
|
1 |
package com.hx.other.service.controller.admin; |
G |
2 |
|
|
3 |
import com.github.pagehelper.PageHelper; |
|
4 |
import com.github.pagehelper.PageInfo; |
|
5 |
import com.hx.common.BaseController; |
|
6 |
import com.hx.mybatisTool.SqlSentence; |
|
7 |
import com.hx.other.service.model.BaseEntity; |
|
8 |
import com.hx.other.service.model.QueryRecord; |
|
9 |
import com.hx.other.service.model.SqlQueryTemp; |
|
10 |
import com.hx.other.service.service.QueryRecordService; |
|
11 |
import com.hx.other.service.service.SqlQueryTempService; |
|
12 |
import com.hx.other.service.vo.BaseVo; |
|
13 |
import com.hx.other.service.vo.ai.QueryRecordVo; |
|
14 |
import com.hx.resultTool.Result; |
|
15 |
import com.hx.util.StringUtils; |
|
16 |
import org.springframework.web.bind.annotation.PostMapping; |
|
17 |
import org.springframework.web.bind.annotation.RequestBody; |
|
18 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
19 |
import org.springframework.web.bind.annotation.RestController; |
|
20 |
|
|
21 |
import javax.annotation.Resource; |
|
22 |
import java.util.HashMap; |
|
23 |
import java.util.List; |
|
24 |
import java.util.Map; |
|
25 |
|
|
26 |
/** |
|
27 |
* @Author: cmg |
|
28 |
* @Date: 2023/5/5 14:37 |
|
29 |
*/ |
|
30 |
@RestController |
|
31 |
@RequestMapping("/ai/query/record") |
|
32 |
public class AdminQueryRecordController extends BaseController { |
|
33 |
|
|
34 |
@Resource |
|
35 |
private QueryRecordService queryRecordService; |
|
36 |
|
|
37 |
@Resource |
|
38 |
private SqlQueryTempService sqlQueryTempService; |
|
39 |
|
|
40 |
@PostMapping("/list") |
|
41 |
public Result list(@RequestBody(required = false) QueryRecordVo baseVo) |
|
42 |
{ |
|
43 |
if(baseVo == null) |
|
44 |
{ |
|
45 |
baseVo = new QueryRecordVo(); |
|
46 |
} |
|
47 |
|
|
48 |
if(baseVo.getPageNum() == null || baseVo.getPageNum() <= 0) |
|
49 |
{ |
|
50 |
baseVo.setPageNum(1); |
|
51 |
} |
|
52 |
|
720120
|
53 |
if(baseVo.getPageSize() == null || baseVo.getPageSize() <= 0 || baseVo.getPageSize() > 100) |
56608e
|
54 |
{ |
G |
55 |
baseVo.setPageSize(20); |
|
56 |
} |
|
57 |
|
|
58 |
SqlSentence sqlSentence = new SqlSentence(); |
|
59 |
Map<String, Object> map = new HashMap<>(); |
|
60 |
sqlSentence.setM(map); |
|
61 |
map.put("isDel", BaseEntity.NO); |
|
62 |
|
|
63 |
StringBuilder stringBuilder = new StringBuilder(); |
720120
|
64 |
stringBuilder.append("select * from query_record where isDel = #{m.isDel}"); |
56608e
|
65 |
|
G |
66 |
if(!StringUtils.isEmpty(baseVo.getKeyWord())) |
|
67 |
{ |
|
68 |
stringBuilder.append(" and content like #{m.content} "); |
|
69 |
map.put("content", "%" + baseVo.getKeyWord() + "%"); |
|
70 |
} |
|
71 |
|
|
72 |
if(baseVo.getIsFromTemp() != null) |
|
73 |
{ |
|
74 |
stringBuilder.append(" and isFromQuery = #{m.isFromQuery} "); |
|
75 |
map.put("isFromQuery", baseVo.getIsFromTemp()); |
|
76 |
} |
|
77 |
|
|
78 |
sqlSentence.setSqlSentence(stringBuilder.toString()); |
720120
|
79 |
PageHelper.startPage(baseVo.getPageNum(), baseVo.getPageSize(), " createTime desc "); |
56608e
|
80 |
List<QueryRecord> list = queryRecordService.selectList(sqlSentence); |
G |
81 |
PageInfo<QueryRecord> pageInfo = new PageInfo<>(list); |
|
82 |
|
|
83 |
return Result.success(pageInfo); |
|
84 |
} |
|
85 |
|
|
86 |
@PostMapping("/change/temp") |
|
87 |
public Result changeToTemp(@RequestBody(required = false) BaseVo baseVo) |
|
88 |
{ |
|
89 |
if(baseVo == null || StringUtils.isEmpty(baseVo.getId())) |
|
90 |
{ |
|
91 |
throwParamException("请选择记录"); |
|
92 |
} |
|
93 |
|
|
94 |
QueryRecord queryRecord = queryRecordService.selectOneByKey(baseVo.getId()); |
|
95 |
if(queryRecord == null) |
|
96 |
{ |
|
97 |
throwParamException("找不到记录"); |
|
98 |
} |
|
99 |
|
|
100 |
String sql = sqlQueryTempService.selectByContent(queryRecord.getContent()); |
|
101 |
if(!StringUtils.isEmpty(sql)) |
|
102 |
{ |
|
103 |
throwServiceException("已加入模板"); |
|
104 |
} |
|
105 |
|
|
106 |
SqlQueryTemp sqlQueryTemp = new SqlQueryTemp(); |
|
107 |
sqlQueryTemp.setSqlStr(queryRecord.getSqlStr()); |
|
108 |
sqlQueryTemp.setContent(queryRecord.getContent()); |
|
109 |
sqlQueryTemp.setIsUp(BaseEntity.YES); |
|
110 |
sqlQueryTempService.insert(sqlQueryTemp); |
|
111 |
|
|
112 |
return Result.success(); |
|
113 |
} |
|
114 |
} |