inittime
This commit is contained in:
8
pom.xml
8
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.7.2</version>
|
<version>2.7.6</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.flagnote</groupId>
|
<groupId>com.flagnote</groupId>
|
||||||
@@ -24,6 +24,10 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-quartz</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -32,7 +36,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
<version>5.7.22</version>
|
<version>5.8.10</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ public class NoteController {
|
|||||||
KeyMeta c = new KeyMeta();
|
KeyMeta c = new KeyMeta();
|
||||||
String key = BizKeyUtils.getKey();
|
String key = BizKeyUtils.getKey();
|
||||||
c.setKey(key);
|
c.setKey(key);
|
||||||
c.setCipher(BizKeyUtils.getCipher(key));
|
|
||||||
c.setServerTime(new Date().getTime());
|
c.setServerTime(new Date().getTime());
|
||||||
|
c.setCipher(BizKeyUtils.getCipher(key,c.getServerTime().toString()));
|
||||||
|
|
||||||
return c;
|
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)
|
@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,
|
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();
|
Date pushTime = new Date();
|
||||||
|
|
||||||
Note note = new Note();
|
Note note = new Note();
|
||||||
@@ -113,6 +114,7 @@ public class NoteController {
|
|||||||
note.setTextBytes(file.getBytes());
|
note.setTextBytes(file.getBytes());
|
||||||
note.setLock(lock);
|
note.setLock(lock);
|
||||||
note.setMd5(md5);
|
note.setMd5(md5);
|
||||||
|
note.setInitTime(new Date(Long.parseLong(initTime)));
|
||||||
note.setPushTime(pushTime);
|
note.setPushTime(pushTime);
|
||||||
|
|
||||||
noteService.saveNote(note);
|
noteService.saveNote(note);
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ public class Note implements Serializable {
|
|||||||
|
|
||||||
private Integer state;
|
private Integer state;
|
||||||
|
|
||||||
|
private Date initTime;
|
||||||
|
|
||||||
private Date pushTime;
|
private Date pushTime;
|
||||||
|
|
||||||
private Date expireTime;
|
private Date expireTime;
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package com.flagnote.note.repository;
|
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.MongoRepository;
|
||||||
|
import org.springframework.data.mongodb.repository.Query;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import com.flagnote.note.entity.Note;
|
import com.flagnote.note.entity.Note;
|
||||||
@@ -8,4 +13,8 @@ import com.flagnote.note.entity.Note;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface NoteMongoRepository extends MongoRepository<Note, String> {
|
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.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);
|
note.setState(1);
|
||||||
|
|
||||||
|
|||||||
@@ -84,12 +84,51 @@ public class BizKeyUtils {
|
|||||||
return Integer.parseInt(String.valueOf(new Date().getTime()).substring(0, 4));
|
return Integer.parseInt(String.valueOf(new Date().getTime()).substring(0, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCipher(String key) {
|
public static String getCipher(String key,String initTime) {
|
||||||
return md5(key + MIX_STRING + key);
|
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) {
|
public static String getSecretKey(String key, String password) {
|
||||||
return md5(key + md5(MIX_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
server:
|
server:
|
||||||
port: 3333
|
address: 127.0.0.1
|
||||||
|
port: 20000
|
||||||
spring:
|
spring:
|
||||||
codec:
|
codec:
|
||||||
max-in-memory-size: 128MB
|
max-in-memory-size: 128MB
|
||||||
@@ -14,3 +15,19 @@ spring:
|
|||||||
autoConnectRetry: true
|
autoConnectRetry: true
|
||||||
socketKeepAlive: true
|
socketKeepAlive: true
|
||||||
socketTimeout: 1000
|
socketTimeout: 1000
|
||||||
|
|
||||||
|
management:
|
||||||
|
# server:
|
||||||
|
# address: 127.0.0.1
|
||||||
|
# port: 29000
|
||||||
|
endpoint:
|
||||||
|
shutdown:
|
||||||
|
enabled: true
|
||||||
|
health:
|
||||||
|
enabled: true
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
base-path: /f2w8u47ie56edc93/actuator
|
||||||
|
exposure:
|
||||||
|
include: shutdown,health
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user