guang
2023-05-06 7201205af85508421037119ba66b3a6a48de61ec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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);
        }
 
        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();
    }
}