修改一些细节

This commit is contained in:
qianlan 2021-10-12 19:52:46 +08:00
parent ae96037d2f
commit 78a0d8429a
9 changed files with 139 additions and 20 deletions

View File

@ -62,8 +62,10 @@ public class TestNodeController extends BaseController {
@GetMapping("/listWithChildren")
public AjaxResult listWithChildren(String nodeName) {
List<TestNode> nodeList = iTestNodeService.queryListWithChildren(nodeName);
if (nodeList == null) {
return AjaxResult.error("查询无果");
List<TestNode> list = iTestNodeService.queryListWithSizhi(nodeName);
return AjaxResult.success(list);
} else {
return AjaxResult.success(nodeList);
}
@ -75,9 +77,9 @@ public class TestNodeController extends BaseController {
@ApiOperation("查询节点维护列表")
@PreAuthorize("@ss.hasPermi('system:node:list')")
@GetMapping("/list")
public AjaxResult<List<TestNodeVo>> list(@Validated TestNodeBo bo) {
List<TestNodeVo> list = iTestNodeService.queryList(bo);
return AjaxResult.success(list);
public AjaxResult list(@Validated TestNode node) {
List<TestNode> list = iTestNodeService.queryLists(node);
return (list != null) ? AjaxResult.success(list) : AjaxResult.error("查询无果");
}
/**

View File

@ -216,8 +216,8 @@ swagger:
version: '版本号: ${ruoyi-vue-plus.version}'
# 作者信息
contact:
name: Lion Li
email: crazylionli@163.com
name: qianlan
email: 3220857484@qq.com
url: https://gitee.com/JavaLionLi/RuoYi-Vue-Plus
# 防止XSS攻击

View File

@ -17,6 +17,13 @@
<dependencies>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<!-- Spring框架基本的核心工具 -->
<dependency>
<groupId>org.springframework</groupId>

View File

@ -28,7 +28,7 @@ public class TestNode implements Serializable {
/**
* 主键
*/
@TableId(value = "id")
@TableId(value = "id",type = IdType.INPUT)
private Long id;
/**

View File

@ -72,4 +72,19 @@ public interface ITestNodeService extends IServicePlus<TestNode, TestNodeVo> {
* @return
*/
AjaxResult<Void> addMultiple(Map map);
/**
* 若数据库查询不到则从第三方接口取得数据并插入到数据库中
* @param nodeName
* @return
*/
List<TestNode> queryListWithSizhi(String nodeName);
/**
* 查出维护列表
* @param node 前端传来的搜索条件
* @return
*/
List<TestNode> queryLists(TestNode node);
}

View File

@ -1,9 +1,12 @@
package com.ruoyi.system.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.HttpRequestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
@ -15,10 +18,7 @@ import com.ruoyi.system.domain.TestNode;
import com.ruoyi.system.mapper.TestNodeMapper;
import com.ruoyi.system.service.ITestNodeService;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.*;
/**
* 节点维护Service业务层处理
@ -37,12 +37,12 @@ public class TestNodeServiceImpl extends ServicePlusImpl<TestNodeMapper, TestNod
return getVoById(id);
}
@Override
public List<TestNodeVo> queryList(TestNodeBo bo) {
return listVo(buildQueryWrapper(bo));
}
private LambdaQueryWrapper<TestNode> buildQueryWrapper(TestNodeBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<TestNode> lqw = Wrappers.lambdaQuery();
@ -54,6 +54,7 @@ public class TestNodeServiceImpl extends ServicePlusImpl<TestNodeMapper, TestNod
@Override
public Boolean insertByBo(TestNodeBo bo) {
bo.setId(RandomUtil.randomLong(100000000000000l));
TestNode add = BeanUtil.toBean(bo, TestNode.class);
validEntityBeforeSave(add);
return save(add);
@ -91,7 +92,13 @@ public class TestNodeServiceImpl extends ServicePlusImpl<TestNodeMapper, TestNod
*/
@Override
public List<TestNode> queryListWithChildren(String nodeName) {
List<TestNode> nodeList = testNodeMapper.selectList(new QueryWrapper<TestNode>().like("name", nodeName));
List<TestNode> nodeList = null;
nodeList = testNodeMapper.selectList(new QueryWrapper<TestNode>()
.eq("name", nodeName).eq("pid", 0));
if (nodeList.size() == 0) {
nodeList = testNodeMapper.selectList(new QueryWrapper<TestNode>().like("name", nodeName));
}
if (nodeList.size() == 0) {
return null;
}
@ -141,6 +148,7 @@ public class TestNodeServiceImpl extends ServicePlusImpl<TestNodeMapper, TestNod
} else {
for (int i = 0; i < nameArray.length; i++) {
TestNode testNode = new TestNode();
testNode.setId(RandomUtil.randomLong(100000000000000l));
testNode.setName(nameArray[i]);
testNode.setCategary(categaryArray[i]);
testNode.setPid(pid);
@ -154,6 +162,7 @@ public class TestNodeServiceImpl extends ServicePlusImpl<TestNodeMapper, TestNod
} else {
for (int i = 0; i < nameArray.length; i++) {
TestNode testNode = new TestNode();
testNode.setId(RandomUtil.randomLong(100000000000000l));
testNode.setName(nameArray[i]);
testNode.setPid(pid);
testNodeMapper.insert(testNode);
@ -166,4 +175,77 @@ public class TestNodeServiceImpl extends ServicePlusImpl<TestNodeMapper, TestNod
return AjaxResult.error("添加失败");
}
}
/**
* 若数据库查询不到则从第三方接口取得数据并插入到数据库中
*
* @param nodeName
* @return
*/
@Override
public List<TestNode> queryListWithSizhi(String nodeName) {
long id = RandomUtil.randomLong(100000000000000l);
TestNode testNode = new TestNode();
testNode.setName(nodeName);
testNode.setId(id);
testNode.setPid(0l);
testNodeMapper.insert(testNode);
List<Object[]> list = HttpRequestUtils.testHutoolGet("https://api.ownthink.com/kg/knowledge?entity=", nodeName);
int count = 0;
for (Object[] strings : list) {
TestNode node = new TestNode();
node.setId(RandomUtil.randomLong(100000000000000l));
node.setName((String) strings[1]);
node.setCategary((String) strings[0]);
node.setPid(id);
testNodeMapper.insert(node);
count++;
if (count > 20) break;
}
return queryListWithChildren(nodeName);
}
/**
* 查出维护列表
*
* @param node 前端传来的搜索条件
* @return
*/
@Override
public List<TestNode> queryLists(TestNode node) {
if (node.getName() == null && node.getCategary() == null && node.getPid() == null) {
return testNodeMapper.selectList(null);
}
Queue<Long> q = new LinkedList<>(); //初始化一个队列
LambdaQueryWrapper<TestNode> lqw = Wrappers.lambdaQuery();
lqw.like(StrUtil.isNotBlank(node.getName()), TestNode::getName, node.getName());
lqw.eq(StrUtil.isNotBlank(node.getCategary()), TestNode::getCategary, node.getCategary());
lqw.eq(node.getPid() != null, TestNode::getPid, node.getPid());
List<TestNode> nodeList = testNodeMapper.selectList(lqw);
if (nodeList.size() == 0) {
return null;
} else {
for (TestNode testNode : nodeList) {
q.offer(testNode.getId());
}
//循环队列bfs算法查出所有子节点
while (!q.isEmpty()) {
for (int i = 0; i < q.size(); i++) {
Long cur = q.poll();
List<TestNode> nodeLists = testNodeMapper.selectList(new QueryWrapper<TestNode>().eq("pid", cur));
if (nodeLists.size() != 0) {
for (TestNode list : nodeLists) {
q.offer(list.getId());
nodeList.add(list);
}
}
}
}
return nodeList;
}
}
}

View File

@ -55,6 +55,7 @@
"vue": "2.6.12",
"vue-count-to": "1.0.13",
"vue-cropper": "0.5.5",
"vue-lazyload": "^1.3.3",
"vue-meta": "^2.4.0",
"vue-router": "3.4.9",
"vuedraggable": "2.24.3",

View File

@ -14,9 +14,17 @@ import directive from './directive' //directive
import './assets/icons' // icon
import './permission' // permission control
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, download, handleTree } from "@/utils/ruoyi";
import {getDicts} from "@/api/system/dict/data";
import {getConfigKey} from "@/api/system/config";
import {
parseTime,
resetForm,
addDateRange,
selectDictLabel,
selectDictLabels,
download,
handleTree
} from "@/utils/ruoyi";
import Pagination from "@/components/Pagination";
// 自定义表格工具组件
import RightToolbar from "@/components/RightToolbar"
@ -30,6 +38,8 @@ import ImageUpload from "@/components/ImageUpload"
import DictTag from '@/components/DictTag'
// 头部标签组件
import VueMeta from 'vue-meta'
// 图片懒加载
import VueLazyload from 'vue-lazyload'
// 全局方法挂载
Vue.prototype.getDicts = getDicts
@ -43,11 +53,11 @@ Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.msgSuccess = function (msg) {
this.$message({ showClose: true, message: msg, type: "success" });
this.$message({showClose: true, message: msg, type: "success"});
}
Vue.prototype.msgError = function (msg) {
this.$message({ showClose: true, message: msg, type: "error" });
this.$message({showClose: true, message: msg, type: "error"});
}
Vue.prototype.msgInfo = function (msg) {
@ -64,7 +74,10 @@ Vue.component('ImageUpload', ImageUpload)
Vue.use(directive)
Vue.use(VueMeta)
Vue.use(VueLazyload, {
loading: require('./assets/images/loading.gif'),//加载中图片,一定要有,不然会一直重复加载占位图
// error: require('img/error.png') //加载失败图片
})
/**
* If you don't want to use mock-server
* you want to use MockJs for mock api

View File

@ -184,7 +184,6 @@ export default {
methods: {
/** 查询节点维护列表 */
getList() {
this.loading = true;
listNode(this.queryParams).then(response => {
this.nodeList = this.handleTree(response.data, "id", "pid");
this.loading = false;