From 046aba8a2800f2bd68fce4e5c163f1bc4c519b5e Mon Sep 17 00:00:00 2001 From: WangHao <43278047@qq.com> Date: Sun, 18 Oct 2020 18:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=20Redis=E6=96=87=E7=AB=A0=E8=BD=ACMongoDB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MongdbApplicationTests.java | 27 ++++++++++++++++- .../note/service/impl/NmNoteServiceImpl.java | 5 ++-- ruoyi-quartz/pom.xml | 8 ++++- .../java/com/ruoyi/quartz/task/RyTask.java | 26 +++++++++++++++- ruoyi-ui/src/api/note/note.js | 2 +- .../src/components/BookmarkList/index.vue | 2 +- .../src/views/bookmark/bookmark/index.vue | 5 ++-- ruoyi-ui/src/views/bookmark/common/NqEdit.vue | 30 +++++++++++++++---- ruoyi-ui/src/views/bookmark/index/index.vue | 3 -- 9 files changed, 90 insertions(+), 18 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/test/controller/MongdbApplicationTests.java b/ruoyi-admin/src/main/java/com/ruoyi/web/test/controller/MongdbApplicationTests.java index 3f3ff2dbd..2250bb13a 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/test/controller/MongdbApplicationTests.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/test/controller/MongdbApplicationTests.java @@ -104,7 +104,32 @@ public class MongdbApplicationTests extends BaseSpringBootTest{ */ @Test public void redisToMgDB(){ - + //模糊查询 获取所有的key + Collection listNote= redisCache.keys(Constants.NM_NOTE_CONTENT+"*"); + for(String str:listNote){ + //文章UUID + String mgDbContentUUID=str.replace(Constants.NM_NOTE_CONTENT,""); + System.out.println("str:"+str); + //文章 + String redisContent= redisCache.getCacheObject(str).toString(); + //查询mongoDb 存在就修改 不存在就新增 + List listMgDbContent = noteRepositoryService.findById(mgDbContentUUID); + if (listMgDbContent!=null&&!listMgDbContent.isEmpty()){ + //修改 + NoteContentMgDb noteContentMgDb = new NoteContentMgDb(); + noteContentMgDb.setId(Long.valueOf(mgDbContentUUID)); + noteContentMgDb.setNoteContent(redisContent); + noteRepositoryService.update(noteContentMgDb); + }else { + //新增 + NoteContentMgDb noteContentMgDb = new NoteContentMgDb(); + noteContentMgDb.setId(Long.valueOf(mgDbContentUUID)); + noteContentMgDb.setNoteContent(redisContent); + noteRepositoryService.save(noteContentMgDb); + } + //删除对应缓存 + //redisCache.deleteObject(str); + } } diff --git a/ruoyi-note/src/main/java/com/ruoyi/note/service/impl/NmNoteServiceImpl.java b/ruoyi-note/src/main/java/com/ruoyi/note/service/impl/NmNoteServiceImpl.java index 3ab8ce85b..115a53620 100644 --- a/ruoyi-note/src/main/java/com/ruoyi/note/service/impl/NmNoteServiceImpl.java +++ b/ruoyi-note/src/main/java/com/ruoyi/note/service/impl/NmNoteServiceImpl.java @@ -157,7 +157,8 @@ public class NmNoteServiceImpl implements INmNoteService { public int userUpdateNote(NmNote nmNote) { //储存到redis中 只缓存频繁操作的文章内容 redisCache.setCacheObject(Constants.NM_NOTE_CONTENT+nmNote.getTiymceUeditor(),nmNote.getUeditorContent()); - return 1; + // 更新标题信息 + return nmNoteMapper.updateNmNote(nmNote); } /** @@ -174,7 +175,7 @@ public class NmNoteServiceImpl implements INmNoteService { //文章UUID String mgDbContentUUID=str.replace(Constants.NM_NOTE_CONTENT,""); //文章 - String redisContent= redisCache.getCacheObject(str); + String redisContent= redisCache.getCacheObject(str).toString(); //查询mongoDb 存在就修改 不存在就新增 List listMgDbContent = noteRepositoryService.findById(mgDbContentUUID); if (listMgDbContent!=null&&!listMgDbContent.isEmpty()){ diff --git a/ruoyi-quartz/pom.xml b/ruoyi-quartz/pom.xml index b62c7f7f0..2b4a3936e 100644 --- a/ruoyi-quartz/pom.xml +++ b/ruoyi-quartz/pom.xml @@ -35,6 +35,12 @@ ruoyi-common + + + com.ruoyi + ruoyi-note + + - \ No newline at end of file + diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java index 25d1ddd02..756fc01ee 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java @@ -1,16 +1,27 @@ package com.ruoyi.quartz.task; +import cn.hutool.core.date.DateUtil; +import com.ruoyi.common.utils.http.HttpUtils; +import com.ruoyi.note.service.INmNoteService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.ruoyi.common.utils.StringUtils; /** * 定时任务调度测试 - * + * * @author ruoyi */ @Component("ryTask") public class RyTask { + private static final Logger log = LoggerFactory.getLogger(RyTask.class); + + @Autowired + private INmNoteService nmNoteService; + public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); @@ -25,4 +36,17 @@ public class RyTask { System.out.println("执行无参方法"); } + + /** + * 每天凌晨 Redis缓存中的文章 转移到MongoDB数据库 + * + * @param + * @return + */ + public void redisToMongonDB() + { + log.info(DateUtil.now()+"开始执行>>>Redis缓存中的文章 转移到MongoDB数据库"); + nmNoteService.redisToMongonDB(); + log.info(DateUtil.now()+"执行完毕>>>Redis缓存中的文章 转移到MongoDB数据库"); + } } diff --git a/ruoyi-ui/src/api/note/note.js b/ruoyi-ui/src/api/note/note.js index 4bd492075..d3ebae043 100644 --- a/ruoyi-ui/src/api/note/note.js +++ b/ruoyi-ui/src/api/note/note.js @@ -34,7 +34,7 @@ export function addUserNote(data) { export function userUpdateNote(data) { return request({ url: '/note/note/userUpdateNote', - method: 'put', + method: 'post', data: data }) } diff --git a/ruoyi-ui/src/components/BookmarkList/index.vue b/ruoyi-ui/src/components/BookmarkList/index.vue index 1c2231002..047b7ac6a 100644 --- a/ruoyi-ui/src/components/BookmarkList/index.vue +++ b/ruoyi-ui/src/components/BookmarkList/index.vue @@ -90,7 +90,7 @@ break; case 1: //便签模式 - that.isdescription = true; + that.isdescription = false; that.noteTime = true; that.isBookmarkIcon = false; break; diff --git a/ruoyi-ui/src/views/bookmark/bookmark/index.vue b/ruoyi-ui/src/views/bookmark/bookmark/index.vue index 4404afb46..3f2f13201 100644 --- a/ruoyi-ui/src/views/bookmark/bookmark/index.vue +++ b/ruoyi-ui/src/views/bookmark/bookmark/index.vue @@ -477,7 +477,7 @@ that.queryParams.menuId = routedata; that.noteParams.menuId = routedata; } - console.log("当前状态:"+that.property) + if (property != null && property != undefined && property != ''){ that.property =property; } @@ -575,7 +575,7 @@ //缓存状态 that.$store.state.property=e; this.showimg=false; - console.log("缓存property:"+that.$store.state.property) + // console.log("缓存property:"+that.$store.state.property) // console.log("缓存property:"+store.state.property) //初始化 this.queryParams.pageNum=1; @@ -837,7 +837,6 @@ this.loading = true; selectBymenuIdUserID(this.queryParams).then(response => { if (response.code == 200) { - console.log("response.rows" + response.rows) this.bookmarkList = this.bookmarkList.concat(response.rows); this.total = response.total; this.listloading = false diff --git a/ruoyi-ui/src/views/bookmark/common/NqEdit.vue b/ruoyi-ui/src/views/bookmark/common/NqEdit.vue index ca0136a18..cf4d4d61b 100644 --- a/ruoyi-ui/src/views/bookmark/common/NqEdit.vue +++ b/ruoyi-ui/src/views/bookmark/common/NqEdit.vue @@ -5,6 +5,10 @@
+
+ {{queryParamsAndMg.updateTime==null?'0000:00:00':queryParamsAndMg.updateTime}} + {{updateOpn}} +
@@ -21,7 +25,7 @@
- +
@@ -94,6 +98,7 @@ }, showEditor:false, loading:false, + updateOpn:'编辑' } }, created() { @@ -103,12 +108,17 @@ /** 实时更新文章的信息 */ UpdateNote() { userUpdateNote(this.queryParamsAndMg).then(response => { - console.log("已保存:" + Date.now()) + if (response.code==200){ + console.log("已保存:" + Date.now()) + this.$message({ + message: '保存成功!', + type: 'success' + }); + } }); }, /** 查询便签管理列表 */ getNoteById() { - console.log("请求执行了!!!") var that = this; that.loading=true; var blueditor = that.ueditor != null && that.ueditor != '' && that.ueditor != undefined; @@ -135,6 +145,16 @@ //清空内容 clear() { this.$refs.editor.clear() + }, + updateEdit(){ + var that=this; + + that.showEditor=!that.showEditor; + if (that.showEditor) { + that.updateOpn='退出编辑'; + }else { + that.updateOpn='编辑'; + } } } } @@ -168,11 +188,11 @@ overflow: scroll; } .edit{ - margin-left: 3px; + margin-left: 13px; } .nqtitle{ - margin-left: 3px; + margin-left: 13px; margin-bottom: 10px; } .inputtop{ diff --git a/ruoyi-ui/src/views/bookmark/index/index.vue b/ruoyi-ui/src/views/bookmark/index/index.vue index fb350e3f4..7afa08d0e 100644 --- a/ruoyi-ui/src/views/bookmark/index/index.vue +++ b/ruoyi-ui/src/views/bookmark/index/index.vue @@ -575,10 +575,7 @@ //颜色改变提醒 resize[i].style.background = 'transparent'; var startX = e.clientX; - console.log("鼠标按下后:" + e.clientX) resize[i].left = resize[i].offsetLeft; - console.log("鼠标按下后:" + resize[i].left) - console.log("鼠标按下后:" + resize[i].offsetLeft) // 鼠标拖动事件 document.onmousemove = function (e) { var endX = e.clientX;