修复一处异常问题

This commit is contained in:
Yutou 2024-01-20 17:39:40 +08:00
parent 22416227d8
commit d4b8e58946

View File

@ -13,56 +13,61 @@ import java.util.Set;
public class QQNumberManager { public class QQNumberManager {
private static QQNumberManager manager; private static QQNumberManager manager;
private QQNumberManager(){
private QQNumberManager() {
} }
public static QQNumberManager getManager() { public static QQNumberManager getManager() {
if(manager==null) { if (manager == null) {
manager=new QQNumberManager(); manager = new QQNumberManager();
} }
return manager; return manager;
} }
public void addNumber(Long qq,boolean isGroup){
if(RedisTools.exists(qq,null)){ public void addNumber(Long qq, boolean isGroup) {
if (RedisTools.exists(qq, null)) {
return; return;
} }
JSONObject json=new JSONObject(); JSONObject json = new JSONObject();
json.put("group",isGroup); json.put("group", isGroup);
json.put("power",new JSONArray()); json.put("power", new JSONArray());
json.put("model",new JSONArray()); json.put("model", new JSONArray());
RedisTools.set(qq,json.toJSONString()); RedisTools.set(qq, json.toJSONString());
} }
public List<Long> getNumber(){
List<Long> list =new ArrayList<>(); public List<Long> getNumber() {
Jedis jedis=RedisTools.getRedis(); List<Long> list = new ArrayList<>();
Jedis jedis = RedisTools.getRedis();
jedis.select(RedisTools.QQBOT_USER); jedis.select(RedisTools.QQBOT_USER);
Set<String> set=jedis.keys("*"); Set<String> set = jedis.keys("*");
for (String s : set) { for (String s : set) {
try { try {
list.add(Long.parseLong(s)); list.add(Long.parseLong(s));
}catch (Exception ignored){ } catch (Exception ignored) {
} }
} }
jedis.close(); jedis.close();
return list; return list;
} }
public boolean addPower(Long qq, String power){
if(RedisTools.exists(qq,null)){ public boolean addPower(Long qq, String power) {
JSONObject json=JSON.parseObject(RedisTools.get(qq)); if (RedisTools.exists(qq, null)) {
JSONArray array=json.getJSONArray("power"); JSONObject json = JSON.parseObject(RedisTools.get(qq));
JSONArray array = json.getJSONArray("power");
array.add(power); array.add(power);
json.put("power",array); json.put("power", array);
return RedisTools.set(qq,json.toJSONString()); return RedisTools.set(qq, json.toJSONString());
} }
return false; return false;
} }
public List<String> getPower(Long qq){
List<String> list=new ArrayList<>(); public List<String> getPower(Long qq) {
if(RedisTools.exists(qq,null)){ List<String> list = new ArrayList<>();
JSONObject json=JSON.parseObject(RedisTools.get(qq)); if (RedisTools.exists(qq, null)) {
JSONArray array=json.getJSONArray("power"); JSONObject json = JSON.parseObject(RedisTools.get(qq));
JSONArray array = json.getJSONArray("power");
for (Object power : array) { for (Object power : array) {
list.add((String) power); list.add((String) power);
} }
@ -70,11 +75,12 @@ public class QQNumberManager {
} }
return list; return list;
} }
public List<String> getUseModel(long qq) { public List<String> getUseModel(long qq) {
List<String> list=new ArrayList<>(); List<String> list = new ArrayList<>();
if(RedisTools.exists(qq,null)){ if (RedisTools.exists(qq, null)) {
JSONObject json=JSON.parseObject(RedisTools.get(qq)); JSONObject json = JSON.parseObject(RedisTools.get(qq));
JSONArray array=json.getJSONArray("model"); JSONArray array = json.getJSONArray("model");
for (Object power : array) { for (Object power : array) {
list.add((String) power); list.add((String) power);
} }
@ -82,43 +88,47 @@ public class QQNumberManager {
} }
return list; return list;
} }
public boolean delPower(Long qq, String power){
if(RedisTools.exists(qq,null)){ public boolean delPower(Long qq, String power) {
JSONObject json=JSON.parseObject(RedisTools.get(qq)); if (RedisTools.exists(qq, null)) {
JSONArray array=json.getJSONArray("power"); JSONObject json = JSON.parseObject(RedisTools.get(qq));
JSONArray array = json.getJSONArray("power");
array.remove(power); array.remove(power);
json.put("power",array); json.put("power", array);
return RedisTools.set(qq,json.toJSONString()); return RedisTools.set(qq, json.toJSONString());
} }
return false; return false;
} }
public boolean addUseModel(Long qq,Class<?> modelClass){
if(RedisTools.exists(qq,null)){ public boolean addUseModel(Long qq, Class<?> modelClass) {
JSONObject json=JSON.parseObject(RedisTools.get(qq)); if (RedisTools.exists(qq, null)) {
JSONArray array=json.getJSONArray("model"); JSONObject json = JSON.parseObject(RedisTools.get(qq));
JSONArray array = json.getJSONArray("model");
array.add(modelClass.getName()); array.add(modelClass.getName());
json.put("model",array); json.put("model", array);
return RedisTools.set(qq,json.toJSONString()); return RedisTools.set(qq, json.toJSONString());
} }
return false; return false;
} }
public boolean delUseModel(Long qq,Class<?> modelClass){
if(RedisTools.exists(qq,null)){ public boolean delUseModel(Long qq, Class<?> modelClass) {
JSONObject json=JSON.parseObject(RedisTools.get(qq)); if (RedisTools.exists(qq, null)) {
JSONArray array=json.getJSONArray("model"); JSONObject json = JSON.parseObject(RedisTools.get(qq));
JSONArray array = json.getJSONArray("model");
array.remove(modelClass.getName()); array.remove(modelClass.getName());
json.put("model",array); json.put("model", array);
return RedisTools.set(qq,json.toJSONString()); return RedisTools.set(qq, json.toJSONString());
} }
return false; return false;
} }
public boolean isExistsPower(Long qq, String... power){
public boolean isExistsPower(Long qq, String... power) {
//1 //1
if(RedisTools.exists(qq,null)){ if (RedisTools.exists(qq, null)) {
JSONObject json=JSON.parseObject(RedisTools.get(qq)); JSONObject json = JSON.parseObject(RedisTools.get(qq));
JSONArray array=json.getJSONArray("power"); JSONArray array = json.getJSONArray("power");
for (String key : power) { for (String key : power) {
if(!array.contains(key)){ if (!array.contains(key)) {
return false; return false;
} }
} }
@ -126,19 +136,26 @@ public class QQNumberManager {
} }
return false; return false;
} }
public boolean isGroup(Long qq){
if(RedisTools.exists(qq,null)){ public boolean isGroup(Long qq) {
JSONObject json= JSON.parseObject(RedisTools.get(qq)); if (RedisTools.exists(qq, null)) {
JSONObject json = JSON.parseObject(RedisTools.get(qq));
return json.getBooleanValue("group"); return json.getBooleanValue("group");
} }
return false; return false;
} }
public boolean isUseModel(Long qq,Class<?> modelClass){
if(RedisTools.exists(qq,null)){ public boolean isUseModel(Long qq, Class<?> modelClass) {
JSONObject json=JSON.parseObject(RedisTools.get(qq)); try {
JSONArray array=json.getJSONArray("model"); if (RedisTools.exists(qq, null)) {
JSONObject json = JSON.parseObject(RedisTools.get(qq));
JSONArray array = json.getJSONArray("model");
return array.contains(modelClass.getName()); return array.contains(modelClass.getName());
} }
} catch (Exception e) {
e.printStackTrace();
Log.i("isUseModel", qq + " " + modelClass.getName());
}
return false; return false;
} }