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