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 * 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(baseVo.getPageNum(), baseVo.getPageSize(), " 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();
|
}
|
}
|