This commit is contained in:
Jesse-Ma
2022-12-01 16:35:21 +08:00
parent 3ae8f94916
commit 17ff6e710c
5 changed files with 21 additions and 12 deletions

4
.gitignore vendored
View File

@@ -21,5 +21,7 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
.settings/org.eclipse.m2e.core.prefs .settings/
.project .project
/target/
.classpath

View File

@@ -49,15 +49,17 @@ public class NoteController {
public NoteMeta getNoteMeta(@PathVariable("key") String key) { public NoteMeta getNoteMeta(@PathVariable("key") String key) {
NoteMeta meta = new NoteMeta(); NoteMeta meta = new NoteMeta();
Note note = noteService.getNote(key); Note note = noteService.getNote(key);
meta.setKey(key);
if (null == note) { if (null == note) {
return meta; return meta;
} }
meta.setServerTime(new Date().getTime()); meta.setServerTime(new Date().getTime());
meta.setKey(key);
meta.setLock(note.getLock()); meta.setLock(note.getLock());
meta.setMd5(note.getMd5()); meta.setMd5(note.getMd5());
meta.setState(note.getState());
meta.setTtl(note.getTtl()); meta.setTtl(note.getTtl());
return meta; return meta;

View File

@@ -17,8 +17,6 @@ public class Note implements Serializable {
private String key; private String key;
private String text;
private String md5; private String md5;
private Integer lock; private Integer lock;

View File

@@ -16,6 +16,8 @@ public class NoteMeta implements Serializable {/**
private String key; private String key;
private Integer state;
private String cipher; private String cipher;
private Integer lock; private Integer lock;

View File

@@ -3,10 +3,6 @@ package com.flagnote.note.service;
import java.util.Date; import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.flagnote.note.entity.Note; import com.flagnote.note.entity.Note;
@@ -14,6 +10,7 @@ import com.flagnote.note.repository.NoteMongoRepository;
import com.flagnote.note.utils.BizKeyUtils; import com.flagnote.note.utils.BizKeyUtils;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
@Service @Service
public class NoteServiceImpl implements NoteService { public class NoteServiceImpl implements NoteService {
@@ -33,11 +30,14 @@ public class NoteServiceImpl implements NoteService {
} }
if (note.getState() != 1) { if (note.getState() != 1) {
return null; note.setTextBytes(null);
return note;
} }
if (note.getExpireTime().getTime() <= new Date().getTime()) { if (note.getExpireTime().getTime() <= new Date().getTime()) {
return null; note.setState(0);
note.setTextBytes(null);
return note;
} }
return note; return note;
@@ -63,8 +63,13 @@ public class NoteServiceImpl implements NoteService {
@Override @Override
public void deleteNote(String key) { public void deleteNote(String key) {
String mixKey = BizKeyUtils.mixKey(key); String mixKey = BizKeyUtils.mixKey(key);
Note note = noteMongoRepository.findById(mixKey).orElse(null);
noteMongoRepository.deleteById(mixKey); if(null!=note && ArrayUtil.isNotEmpty(note.getTextBytes())) {
note.setState(0);
note.setTextBytes(null);
noteMongoRepository.save(note);
}
} }
} }