inittime
This commit is contained in:
@@ -40,8 +40,9 @@ public class NoteController {
|
||||
KeyMeta c = new KeyMeta();
|
||||
String key = BizKeyUtils.getKey();
|
||||
c.setKey(key);
|
||||
c.setCipher(BizKeyUtils.getCipher(key));
|
||||
c.setServerTime(new Date().getTime());
|
||||
c.setCipher(BizKeyUtils.getCipher(key,c.getServerTime().toString()));
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -105,7 +106,7 @@ public class NoteController {
|
||||
|
||||
@RequestMapping(value = "/note/{key:[abcdefghijkmnopqrstuvwxyz23456789]{16}}", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public String saveNote(@PathVariable("key") String key, @RequestPart("file") MultipartFile file,
|
||||
@RequestParam("lock") Integer lock, @RequestParam("md5") String md5) throws IOException {
|
||||
@RequestParam("lock") Integer lock, @RequestParam("md5") String md5,@RequestParam("initTime") String initTime) throws IOException {
|
||||
Date pushTime = new Date();
|
||||
|
||||
Note note = new Note();
|
||||
@@ -113,6 +114,7 @@ public class NoteController {
|
||||
note.setTextBytes(file.getBytes());
|
||||
note.setLock(lock);
|
||||
note.setMd5(md5);
|
||||
note.setInitTime(new Date(Long.parseLong(initTime)));
|
||||
note.setPushTime(pushTime);
|
||||
|
||||
noteService.saveNote(note);
|
||||
|
||||
@@ -24,6 +24,8 @@ public class Note implements Serializable {
|
||||
private String cipher;
|
||||
|
||||
private Integer state;
|
||||
|
||||
private Date initTime;
|
||||
|
||||
private Date pushTime;
|
||||
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
package com.flagnote.note.repository;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.flagnote.note.entity.Note;
|
||||
|
||||
@Repository
|
||||
public interface NoteMongoRepository extends MongoRepository<Note, String> {
|
||||
|
||||
|
||||
@Query(value = "{'state' : {'$eq' : 1},'expireTime' : {'$lt' : ?0}}")
|
||||
public Page<Note> findExpireNote(Date date,Pageable page);
|
||||
|
||||
}
|
||||
|
||||
45
src/main/java/com/flagnote/note/schedule/NoteSchedule.java
Normal file
45
src/main/java/com/flagnote/note/schedule/NoteSchedule.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.flagnote.note.schedule;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import com.flagnote.note.entity.Note;
|
||||
import com.flagnote.note.repository.NoteMongoRepository;
|
||||
|
||||
@EnableScheduling
|
||||
@Configuration
|
||||
public class NoteSchedule {
|
||||
|
||||
@Autowired
|
||||
private NoteMongoRepository noteMongoRepository;
|
||||
|
||||
@Scheduled(cron = "0/10 * * * * ?")
|
||||
public void updateExpiredNote() {
|
||||
|
||||
while(true) {
|
||||
|
||||
PageRequest pageRequest = PageRequest.of(0,5);
|
||||
Page<Note> noteList = noteMongoRepository.findExpireNote(new Date(),pageRequest);
|
||||
|
||||
if(noteList.getNumberOfElements()>0) {
|
||||
for (Note note : noteList) {
|
||||
note.setState(0);
|
||||
note.setTextBytes(null);
|
||||
}
|
||||
noteMongoRepository.saveAll(noteList);
|
||||
}else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class NoteServiceImpl implements NoteService {
|
||||
|
||||
|
||||
note.setExpireTime(DateUtil.offsetHour(note.getPushTime(), 1));
|
||||
note.setRetentionTime(DateUtil.offsetSecond(note.getPushTime(), 4000 * 3600));
|
||||
note.setRetentionTime(DateUtil.offsetSecond(note.getPushTime(), 400 * 3600));
|
||||
|
||||
note.setState(1);
|
||||
|
||||
|
||||
@@ -84,12 +84,51 @@ public class BizKeyUtils {
|
||||
return Integer.parseInt(String.valueOf(new Date().getTime()).substring(0, 4));
|
||||
}
|
||||
|
||||
public static String getCipher(String key) {
|
||||
return md5(key + MIX_STRING + key);
|
||||
public static String getCipher(String key,String initTime) {
|
||||
return md5(key +"#"+ MIX_STRING + "#" + initTime);
|
||||
}
|
||||
|
||||
public static Boolean validateCipher(String key,String initTime,String cipher) {
|
||||
return md5(key +"#"+ MIX_STRING + "#" + initTime).equals(cipher);
|
||||
}
|
||||
|
||||
|
||||
public static String getSecretKey(String key, String password) {
|
||||
return md5(key + md5(MIX_STRING + password));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int c = 0;
|
||||
while(true) {
|
||||
c++;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
sb.append(RANGE_STRING.charAt(RandomUtils.nextInt(30)));
|
||||
}
|
||||
|
||||
Boolean result = validateKey(sb.toString());
|
||||
|
||||
if(c%1000==0) {
|
||||
System.out.println(c);
|
||||
System.out.println(result);
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
|
||||
if(result) {
|
||||
System.out.println(c);
|
||||
System.out.println(result);
|
||||
System.out.println(sb.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user