新增显示大头菜预测
修复定时器重复触发问题
This commit is contained in:
parent
f4733ab9bc
commit
4c2f4abaa5
@ -57,11 +57,49 @@ public class TurnipProphet extends Model {
|
||||
try {
|
||||
money = Integer.parseInt(msg.trim());
|
||||
} catch (Exception e) {
|
||||
if (msg.equals(QQFromCommands.TURNIP_PROPHET)) {
|
||||
showData(event.getSource().getFromId());
|
||||
}
|
||||
return;
|
||||
}
|
||||
setData(money, event.getSource().getFromId());
|
||||
}
|
||||
|
||||
private void showData(long qq) {
|
||||
String redisKey = qq + "_turnip";
|
||||
String data = RedisTools.get(redisKey);
|
||||
if (StringUtils.isEmpty(data)) {
|
||||
QQBotManager.getInstance().sendMessage(qq, "没有本周数据,无法预测");
|
||||
return;
|
||||
}
|
||||
JSONObject json = JSONObject.parseObject(data);
|
||||
String prices = json.getString("prices");
|
||||
String pattern = null;
|
||||
if (json.containsKey("old_pattern")) {
|
||||
try {
|
||||
pattern = json.getString("old_pattern");
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
if (pattern != null) {
|
||||
switch (pattern) {
|
||||
case "波动型" -> pattern = "0";
|
||||
case "大幅上涨(三期型)" -> pattern = "1";
|
||||
case "递减型" -> pattern = "2";
|
||||
case "小幅上涨(四期型)" -> pattern = "3";
|
||||
}
|
||||
}
|
||||
Map<String, String> map = null;
|
||||
try {
|
||||
map = WebClient.getInstance().openTurnip(prices, pattern);
|
||||
sendQQ(map, prices, pattern, qq);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
showData(qq);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setData(int money, long qq) {
|
||||
String redisKey = qq + "_turnip";
|
||||
String data = RedisTools.get(redisKey);
|
||||
@ -139,15 +177,32 @@ public class TurnipProphet extends Model {
|
||||
}
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq, "已记录,正在预测本周走势...");
|
||||
|
||||
Map<String, String> map = WebClient.getInstance().openTurnip(prices, pattern);
|
||||
|
||||
String tmp_pattern = sendQQ(map, prices, pattern, qq);
|
||||
if (!StringUtils.isEmpty(tmp_pattern)) {
|
||||
json.put("pattern", tmp_pattern);
|
||||
RedisTools.set(redisKey, json.toJSONString());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
setData(money, qq);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private String sendQQ(Map<String, String> map, String prices, String pattern, long qq) {
|
||||
|
||||
if (map == null) {
|
||||
String url = String.format("https://turnipprophet.io?prices=%s%s",
|
||||
prices,
|
||||
pattern == null ? "" : "&pattern=" + pattern
|
||||
);
|
||||
QQBotManager.getInstance().sendMessage(qq, "没有结果,请检查数据是否有误。 \n网页预览:" + url);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject pr = JSONObject.parseObject(map.get(TurnipData.MODEL));
|
||||
@ -183,16 +238,10 @@ public class TurnipProphet extends Model {
|
||||
}
|
||||
out.append("------------").append("\n");
|
||||
out.append("祝好运 :)");
|
||||
json.put("pattern", prArray.getJSONObject(0).getString(TurnipData.MODEL));
|
||||
RedisTools.set(redisKey, json.toJSONString());
|
||||
|
||||
Log.i("TurnipProphet", out.toString());
|
||||
QQBotManager.getInstance().sendMessage(qq, out.toString());
|
||||
} catch (Exception e) {
|
||||
setData(money, qq);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return prArray.getJSONObject(0).getString(TurnipData.MODEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,7 @@ public class ApplicationInit implements ApplicationRunner {
|
||||
if (time.equals(oldTime)) {
|
||||
return;
|
||||
}
|
||||
oldTime=time;
|
||||
for (Class<?> model : Model.classList) {
|
||||
try {
|
||||
Model useModel= (Model) model.getDeclaredConstructor().newInstance();
|
||||
|
Loading…
x
Reference in New Issue
Block a user