移植之前版本所有功能
This commit is contained in:
@@ -13,10 +13,15 @@ import org.springframework.util.ObjectUtils;
|
||||
import java.io.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
|
||||
public class AppTools {
|
||||
|
||||
40
src/main/java/com/yutou/qqbot/utlis/ApplicationInit.java
Normal file
40
src/main/java/com/yutou/qqbot/utlis/ApplicationInit.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.yutou.qqbot.utlis;
|
||||
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
@Component
|
||||
public class ApplicationInit implements ApplicationRunner {
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
new Timer().schedule(new TimerTask() {
|
||||
private String oldTime = "";
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String time = new SimpleDateFormat("HH:mm").format(new Date());
|
||||
if (time.equals(oldTime)) {
|
||||
return;
|
||||
}
|
||||
for (Class<?> model : Model.classList) {
|
||||
try {
|
||||
Model useModel= (Model) model.getDeclaredConstructor().newInstance();
|
||||
useModel.onTime(time);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
},0, 35 * 1000);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class RedisTools {
|
||||
Jedis jedis = getRedis();
|
||||
jedis.select(dbIndex);
|
||||
String ret = jedis.set(key, value);
|
||||
Log.i("Redis set =" + ret);
|
||||
Log.i("Redis set =" + ret,"key = "+key+" value = "+value);
|
||||
jedis.close();
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
@@ -54,16 +54,15 @@ public class RedisTools {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean set(String key, String value) {
|
||||
return set(0, key, value);
|
||||
}
|
||||
|
||||
public static boolean set(String key, String value, int timeout) {
|
||||
public static boolean set (String key,String value, long timeout,int db){
|
||||
try {
|
||||
if (isNotInstallRedis) {
|
||||
return false;
|
||||
}
|
||||
Jedis jedis = getRedis();
|
||||
if(db>-1){
|
||||
jedis.select(db);
|
||||
}
|
||||
if (timeout == -1) {
|
||||
jedis.set(key, value);
|
||||
} else {
|
||||
@@ -78,6 +77,14 @@ public class RedisTools {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean set(Object key, String value) {
|
||||
return set(3, key+"", value);
|
||||
}
|
||||
|
||||
public static boolean set(String key, String value, long timeout) {
|
||||
return set(key, value, timeout,3);
|
||||
}
|
||||
|
||||
public static String get(String key, int dbIndex) {
|
||||
String value = "-999";
|
||||
if (isNotInstallRedis) {
|
||||
@@ -94,12 +101,12 @@ public class RedisTools {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static String get(String key) {
|
||||
return get(key, 0);
|
||||
public static String get(Object key) {
|
||||
return get(key+"", 3);
|
||||
}
|
||||
|
||||
public static boolean remove(String key) {
|
||||
return remove(key,0);
|
||||
return remove(key,3);
|
||||
}
|
||||
|
||||
public static void removeLoginState(String uid) {
|
||||
@@ -119,13 +126,21 @@ public class RedisTools {
|
||||
jedis.close();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public static boolean exists(String key, String value) {
|
||||
public static boolean exists(Object key,String value){
|
||||
return exists(3,key,value);
|
||||
}
|
||||
public static boolean exists(int db,Object key, String value) {
|
||||
if (isNotInstallRedis) {
|
||||
return false;
|
||||
}
|
||||
Jedis jedis = getRedis();
|
||||
boolean flag = value.equals(jedis.get(key));
|
||||
jedis.select(db);
|
||||
boolean flag=false;
|
||||
if(value==null){
|
||||
flag= jedis.exists(key+"");
|
||||
}else {
|
||||
flag = value.equals(jedis.get(key+""));
|
||||
}
|
||||
jedis.close();
|
||||
return flag;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user