diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/qianlan/TestNodeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/qianlan/TestNodeController.java index 7d8cd55e1..9cc198423 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/qianlan/TestNodeController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/qianlan/TestNodeController.java @@ -62,8 +62,10 @@ public class TestNodeController extends BaseController { @GetMapping("/listWithChildren") public AjaxResult listWithChildren(String nodeName) { List nodeList = iTestNodeService.queryListWithChildren(nodeName); + if (nodeList == null) { - return AjaxResult.error("查询无果"); + List 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(@Validated TestNodeBo bo) { - List list = iTestNodeService.queryList(bo); - return AjaxResult.success(list); + public AjaxResult list(@Validated TestNode node) { + List list = iTestNodeService.queryLists(node); + return (list != null) ? AjaxResult.success(list) : AjaxResult.error("查询无果"); } /** diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 0f7fcb138..111b9e60f 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -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攻击 diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 016c4576d..aba0bea69 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -17,6 +17,13 @@ + + + com.alibaba + fastjson + 1.2.75 + + org.springframework diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TestNode.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TestNode.java index 8774a110c..86873a4fb 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TestNode.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TestNode.java @@ -28,7 +28,7 @@ public class TestNode implements Serializable { /** * 主键 */ - @TableId(value = "id") + @TableId(value = "id",type = IdType.INPUT) private Long id; /** diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ITestNodeService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITestNodeService.java index d684237cc..181a96506 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ITestNodeService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITestNodeService.java @@ -72,4 +72,19 @@ public interface ITestNodeService extends IServicePlus { * @return */ AjaxResult addMultiple(Map map); + + /** + * 若数据库查询不到,则从第三方接口取得数据,并插入到数据库中 + * @param nodeName + * @return + */ + List queryListWithSizhi(String nodeName); + + /** + * 查出维护列表 + * @param node 前端传来的搜索条件 + * @return + */ + List queryLists(TestNode node); + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestNodeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestNodeServiceImpl.java index f03e0147b..8e289df2d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestNodeServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestNodeServiceImpl.java @@ -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 queryList(TestNodeBo bo) { return listVo(buildQueryWrapper(bo)); } + private LambdaQueryWrapper buildQueryWrapper(TestNodeBo bo) { Map params = bo.getParams(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); @@ -54,6 +54,7 @@ public class TestNodeServiceImpl extends ServicePlusImpl queryListWithChildren(String nodeName) { - List nodeList = testNodeMapper.selectList(new QueryWrapper().like("name", nodeName)); + List nodeList = null; + nodeList = testNodeMapper.selectList(new QueryWrapper() + .eq("name", nodeName).eq("pid", 0)); + if (nodeList.size() == 0) { + nodeList = testNodeMapper.selectList(new QueryWrapper().like("name", nodeName)); + } + if (nodeList.size() == 0) { return null; } @@ -141,6 +148,7 @@ public class TestNodeServiceImpl extends ServicePlusImpl 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 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 queryLists(TestNode node) { + if (node.getName() == null && node.getCategary() == null && node.getPid() == null) { + return testNodeMapper.selectList(null); + } + Queue q = new LinkedList<>(); //初始化一个队列 + LambdaQueryWrapper 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 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 nodeLists = testNodeMapper.selectList(new QueryWrapper().eq("pid", cur)); + if (nodeLists.size() != 0) { + for (TestNode list : nodeLists) { + q.offer(list.getId()); + nodeList.add(list); + } + } + } + } + return nodeList; + } + + } } diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index c980bab82..5844688a9 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -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", diff --git a/ruoyi-ui/src/main.js b/ruoyi-ui/src/main.js index d07dead41..d728bf328 100644 --- a/ruoyi-ui/src/main.js +++ b/ruoyi-ui/src/main.js @@ -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 diff --git a/ruoyi-ui/src/views/system/node/index.vue b/ruoyi-ui/src/views/system/node/index.vue index b41a88ca9..fbf420ce1 100644 --- a/ruoyi-ui/src/views/system/node/index.vue +++ b/ruoyi-ui/src/views/system/node/index.vue @@ -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;