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();
|
}
|
}
|