From 30fda14264e0888d32fb2c52d063bdd70dadd808 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 25 Jul 2022 12:35:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=88=B0R=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/JianRScriptController.java | 115 ++++++++++++++++ .../com/yutou/qqbot/data/JianRScriptData.java | 38 ++++++ .../yutou/qqbot/utlis/JianRTaskManager.java | 113 ++++++++++++++++ web/jianrTask.html | 123 ++++++++++++++++++ 4 files changed, 389 insertions(+) create mode 100644 src/main/java/com/yutou/qqbot/Controllers/JianRScriptController.java create mode 100644 src/main/java/com/yutou/qqbot/data/JianRScriptData.java create mode 100644 src/main/java/com/yutou/qqbot/utlis/JianRTaskManager.java create mode 100644 web/jianrTask.html diff --git a/src/main/java/com/yutou/qqbot/Controllers/JianRScriptController.java b/src/main/java/com/yutou/qqbot/Controllers/JianRScriptController.java new file mode 100644 index 0000000..df0b227 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/Controllers/JianRScriptController.java @@ -0,0 +1,115 @@ +package com.yutou.qqbot.Controllers; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.yutou.qqbot.data.JianRScriptData; +import com.yutou.qqbot.utlis.JianRTaskManager; +import com.yutou.qqbot.utlis.RedisTools; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.Set; + +@Controller +public class JianRScriptController { + @RequestMapping("/jianr/run.do") + @ResponseBody + public JSONObject runScript(String task) { + JSONObject json = new JSONObject(); + String data = RedisTools.get("jianrScript_Model_" + task); + if (data == null) { + json.put("code", -1); + json.put("msg", "没有找到该方案,请配置"); + } else { + JianRScriptData script = JSON.parseObject(data, JianRScriptData.class); + JianRTaskManager manager = JianRTaskManager.getInstance(); + if (manager.isRunning()) { + manager.stop(); + } + manager.setTask(script); + manager.start(); + manager.start(); + json.put("code", 0); + json.put("msg", "任务创建成功"); + } + return json; + } + @RequestMapping("/jianr/stop.do") + @ResponseBody + public JSONObject stop(){ + JianRTaskManager.getInstance().stop(); + JSONObject json = new JSONObject(); + json.put("code", 0); + json.put("msg", "任务已停止"); + return json; + } + @RequestMapping("/jianr/status.do") + @ResponseBody + public JSONObject status() { + JSONObject json = new JSONObject(); + JSONObject data = new JSONObject(); + JianRTaskManager manager = JianRTaskManager.getInstance(); + data.put("status", manager.isRunning()); + data.put("runIndex", manager.getRunIndex()); + data.put("taskName", manager.getTaskName()); + data.put("log", manager.getLog()); + json.put("code", 0); + json.put("data", data); + return json; + } + + @RequestMapping("/jianr/task/list.do") + @ResponseBody + public JSONObject tasks() { + JSONObject json = new JSONObject(); + JSONArray array = new JSONArray(); + Set jianrScript_model = RedisTools.list_get("jianrScript_Model"); + array.addAll(jianrScript_model); + json.put("code", 0); + json.put("data", array); + return json; + } + + @RequestMapping("/jianr/task/add.do") + @ResponseBody + public JSONObject addTask(String task) { + JSONObject json = new JSONObject(); + JSONObject data = JSON.parseObject(task); + if (data == null) { + json.put("code", -1); + json.put("msg", "JSON格式错误"); + } else { + String taskName = data.getString("name"); + if (RedisTools.list_isExist("jianrScript_Model", taskName)) { + json.put("code", -1); + json.put("msg", "该任务名称已存在"); + } else { + RedisTools.list_add("jianrScript_Model", taskName); + RedisTools.set("jianrScript_Model_"+taskName,task); + json.put("code", 0); + json.put("msg", "任务创建成功"); + } + } + return json; + } + @RequestMapping("/jianr/task/get.do") + @ResponseBody + public JSONObject getTask (String task){ + JSONObject json = new JSONObject(); + json.put("code", 0); + json.put("data", RedisTools.get("jianrScript_Model_" + task)); + return json; + } + @RequestMapping("/jianr/task/remove.do") + @ResponseBody + public JSONObject removeTask (String task){ + RedisTools.remove("jianrScript_Model_" + task); + RedisTools.list_remove("jianrScript_Model", task); + JSONObject json = new JSONObject(); + json.put("code", 0); + json.put("msg", "任务删除成功"); + return json; + } + } diff --git a/src/main/java/com/yutou/qqbot/data/JianRScriptData.java b/src/main/java/com/yutou/qqbot/data/JianRScriptData.java new file mode 100644 index 0000000..33cb8f6 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/data/JianRScriptData.java @@ -0,0 +1,38 @@ +package com.yutou.qqbot.data; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class JianRScriptData { + private String name; + private String device; + private List + + + + + \ No newline at end of file