移除mongodb 新增前端个人中心管理
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
package com.ruoyi.note.domain;
|
||||
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
//import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import java.io.Serializable;
|
||||
@ -10,7 +10,7 @@ import java.io.Serializable;
|
||||
* @Date: 2020/10/08 19:07
|
||||
* 功能描述:
|
||||
*/
|
||||
@Document(collection = "NoteContent")
|
||||
//@Document(collection = "NoteContent")
|
||||
public class NoteContentMgDb implements Serializable {
|
||||
|
||||
@Id
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.ruoyi.note.service;
|
||||
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.model.Filters;
|
||||
//import com.mongodb.client.MongoCollection;
|
||||
//import com.mongodb.client.model.Filters;
|
||||
import com.ruoyi.note.domain.NoteContentMgDb;
|
||||
import com.sun.corba.se.spi.ior.ObjectId;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
//import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -15,14 +15,14 @@ import java.util.List;
|
||||
*/
|
||||
public interface INoteRepositoryService {
|
||||
|
||||
void save(NoteContentMgDb noteContentMgDb);
|
||||
|
||||
void update(NoteContentMgDb noteContentMgDb);
|
||||
|
||||
List<NoteContentMgDb> findAll();
|
||||
|
||||
void delete(Integer id);
|
||||
|
||||
//根据id查询
|
||||
List<NoteContentMgDb> findById(String id);
|
||||
// void save(NoteContentMgDb noteContentMgDb);
|
||||
//
|
||||
// void update(NoteContentMgDb noteContentMgDb);
|
||||
//
|
||||
// List<NoteContentMgDb> findAll();
|
||||
//
|
||||
// void delete(Integer id);
|
||||
//
|
||||
// //根据id查询
|
||||
// List<NoteContentMgDb> findById(String id);
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ import java.util.Map;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.github.wujun234.uid.UidGenerator;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoCursor;
|
||||
//import com.mongodb.BasicDBObject;
|
||||
//import com.mongodb.DBObject;
|
||||
//import com.mongodb.client.MongoCollection;
|
||||
//import com.mongodb.client.MongoCursor;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
@ -18,7 +18,7 @@ import com.ruoyi.note.domain.NoteContentMgDb;
|
||||
import com.ruoyi.note.service.INmNoteContentService;
|
||||
import com.ruoyi.note.service.INoteRepositoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
//import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.note.mapper.NmNoteMapper;
|
||||
import com.ruoyi.note.domain.NmNote;
|
||||
@ -167,31 +167,31 @@ public class NmNoteServiceImpl implements INmNoteService {
|
||||
*/
|
||||
@Override
|
||||
public void redisToMongonDB() {
|
||||
//模糊查询 获取所有的key
|
||||
Collection<String> listNote= redisCache.keys(Constants.NM_NOTE_CONTENT+"*");
|
||||
for(String str:listNote){
|
||||
//文章UUID
|
||||
String mgDbContentUUID=str.replace(Constants.NM_NOTE_CONTENT,"");
|
||||
//文章
|
||||
String redisContent= redisCache.getCacheObject(str).toString();
|
||||
//查询mongoDb 存在就修改 不存在就新增
|
||||
List<NoteContentMgDb> 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);
|
||||
}
|
||||
// //模糊查询 获取所有的key
|
||||
// Collection<String> listNote= redisCache.keys(Constants.NM_NOTE_CONTENT+"*");
|
||||
// for(String str:listNote){
|
||||
// //文章UUID
|
||||
// String mgDbContentUUID=str.replace(Constants.NM_NOTE_CONTENT,"");
|
||||
// //文章
|
||||
// String redisContent= redisCache.getCacheObject(str).toString();
|
||||
// //查询mongoDb 存在就修改 不存在就新增
|
||||
// List<NoteContentMgDb> 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);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
package com.ruoyi.note.service.impl;
|
||||
|
||||
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.model.Filters;
|
||||
//import com.mongodb.client.MongoCollection;
|
||||
//import com.mongodb.client.model.Filters;
|
||||
import com.ruoyi.note.domain.NoteContentMgDb;
|
||||
import com.ruoyi.note.service.INoteRepositoryService;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
//import org.bson.types.ObjectId;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
//import org.springframework.data.mongodb.core.mapping.Document;
|
||||
//import org.springframework.data.mongodb.core.query.Criteria;
|
||||
//import org.springframework.data.mongodb.core.query.Query;
|
||||
//import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@ -25,64 +25,64 @@ import java.util.List;
|
||||
@Service
|
||||
public class NoteRepositoryServiceImpl implements INoteRepositoryService {
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 新增信息
|
||||
* @param student
|
||||
*/
|
||||
@Override
|
||||
public void save(NoteContentMgDb student) {
|
||||
mongoTemplate.save(student);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改信息
|
||||
* @param noteContentMgDb
|
||||
*/
|
||||
@Override
|
||||
public void update(NoteContentMgDb noteContentMgDb) {
|
||||
//修改的条件
|
||||
Query query = new Query(Criteria.where("id").is(noteContentMgDb.getId()));
|
||||
|
||||
//修改的内容
|
||||
Update update = new Update();
|
||||
update.set("name", noteContentMgDb.getNoteContent());
|
||||
|
||||
mongoTemplate.updateFirst(query,update, NoteContentMgDb.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<NoteContentMgDb> findAll() {
|
||||
return mongoTemplate.findAll(NoteContentMgDb.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询所有信息
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void delete(Integer id) {
|
||||
NoteContentMgDb byId = mongoTemplate.findById(1, NoteContentMgDb.class);
|
||||
mongoTemplate.remove(byId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<NoteContentMgDb> findById(String id) {
|
||||
//修改的条件
|
||||
Query query = new Query(Criteria.where("_id").is(Long.valueOf(id)));
|
||||
//修改的内容
|
||||
return mongoTemplate.find(query, NoteContentMgDb.class);
|
||||
}
|
||||
// @Autowired
|
||||
// private MongoTemplate mongoTemplate;
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 新增信息
|
||||
// * @param student
|
||||
// */
|
||||
// @Override
|
||||
// public void save(NoteContentMgDb student) {
|
||||
// mongoTemplate.save(student);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改信息
|
||||
// * @param noteContentMgDb
|
||||
// */
|
||||
// @Override
|
||||
// public void update(NoteContentMgDb noteContentMgDb) {
|
||||
// //修改的条件
|
||||
// Query query = new Query(Criteria.where("id").is(noteContentMgDb.getId()));
|
||||
//
|
||||
// //修改的内容
|
||||
// Update update = new Update();
|
||||
// update.set("name", noteContentMgDb.getNoteContent());
|
||||
//
|
||||
// mongoTemplate.updateFirst(query,update, NoteContentMgDb.class);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 查询所有信息
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// public List<NoteContentMgDb> findAll() {
|
||||
// return mongoTemplate.findAll(NoteContentMgDb.class);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 根据id查询所有信息
|
||||
// * @param id
|
||||
// */
|
||||
// @Override
|
||||
// public void delete(Integer id) {
|
||||
// NoteContentMgDb byId = mongoTemplate.findById(1, NoteContentMgDb.class);
|
||||
// mongoTemplate.remove(byId);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public List<NoteContentMgDb> findById(String id) {
|
||||
// //修改的条件
|
||||
// Query query = new Query(Criteria.where("_id").is(Long.valueOf(id)));
|
||||
// //修改的内容
|
||||
// return mongoTemplate.find(query, NoteContentMgDb.class);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user