From 21dd8033d189c4f99ecae7be218bac9a00430c54 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Tue, 26 Jul 2022 22:46:00 +0800 Subject: [PATCH] =?UTF-8?q?update:=E9=87=8D=E6=9E=84=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/JianRScriptController.java | 196 ++++++++++++++---- .../yutou/qqbot/data/jianr/AndroidDevice.java | 35 ++++ .../data/{ => jianr}/JianRScriptData.java | 2 +- .../qqbot/data/jianr/JianRScriptV2Data.java | 26 +++ .../com/yutou/qqbot/data/jianr/Vector2D.java | 38 ++++ .../yutou/qqbot/utlis/JianRTaskManager.java | 192 +++++++++++++++-- web/jianrTask.html | 190 +++++++++++++++-- 7 files changed, 607 insertions(+), 72 deletions(-) create mode 100644 src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java rename src/main/java/com/yutou/qqbot/data/{ => jianr}/JianRScriptData.java (95%) create mode 100644 src/main/java/com/yutou/qqbot/data/jianr/JianRScriptV2Data.java create mode 100644 src/main/java/com/yutou/qqbot/data/jianr/Vector2D.java diff --git a/src/main/java/com/yutou/qqbot/Controllers/JianRScriptController.java b/src/main/java/com/yutou/qqbot/Controllers/JianRScriptController.java index 2dd7654..fed6b8d 100644 --- a/src/main/java/com/yutou/qqbot/Controllers/JianRScriptController.java +++ b/src/main/java/com/yutou/qqbot/Controllers/JianRScriptController.java @@ -3,47 +3,58 @@ 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.data.jianr.AndroidDevice; +import com.yutou.qqbot.data.jianr.JianRScriptV2Data; 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; +import java.util.Map; @Controller public class JianRScriptController { @RequestMapping("/jianr/run.do") @ResponseBody - public JSONObject runScript(String task) { + public JSONObject runScript(String task, String device, String modelName) { JSONObject json = new JSONObject(); - String data = RedisTools.get("jianrScript_Model_" + task); - if (data == null) { + String data = RedisTools.getHashMap(JianRTaskManager.Redis_Script, task); + String deviceJsonString = RedisTools.getHashMap(JianRTaskManager.Redis_Device, device); + if (data == null || deviceJsonString == null) { json.put("code", -1); - json.put("msg", "没有找到该方案,请配置"); + json.put("msg", "没有找到该方案或设备错误,请配置"); } else { - JianRScriptData script = JSON.parseObject(data, JianRScriptData.class); + JianRScriptV2Data script = JSON.parseObject(data, JianRScriptV2Data.class); + AndroidDevice androidDevice = JSON.parseObject(deviceJsonString, AndroidDevice.class); JianRTaskManager manager = JianRTaskManager.getInstance(); if (manager.isRunning()) { manager.stop(); } - manager.setTask(script); + for (int i = 0; i < androidDevice.getDeviceDisplay().size(); i++) { + if (androidDevice.getDeviceDisplay().get(i).getTitle().equals(modelName)) { + manager.setModelId(i); + break; + } + } + manager.setTask(script, androidDevice); manager.start(); json.put("code", 0); json.put("msg", "任务创建成功"); } return json; } + @RequestMapping("/jianr/stop.do") @ResponseBody - public JSONObject stop(){ + 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() { @@ -64,8 +75,8 @@ public class JianRScriptController { public JSONObject tasks() { JSONObject json = new JSONObject(); JSONArray array = new JSONArray(); - Set jianrScript_model = RedisTools.list_get("jianrScript_Model"); - array.addAll(jianrScript_model); + Map map = RedisTools.getHashMap(JianRTaskManager.Redis_Script); + array.addAll(map.keySet()); json.put("code", 0); json.put("data", array); return json; @@ -80,35 +91,150 @@ public class JianRScriptController { json.put("code", -1); json.put("msg", "JSON格式错误"); } else { - String taskName = data.getString("name"); - if (RedisTools.list_isExist("jianrScript_Model", taskName)) { + String taskName = data.getString("title"); + if (RedisTools.getHashMap(JianRTaskManager.Redis_Script).containsKey(taskName)) { json.put("code", -1); json.put("msg", "该任务名称已存在"); } else { - RedisTools.list_add("jianrScript_Model", taskName); - RedisTools.set("jianrScript_Model_"+taskName,task); + RedisTools.setHashMap(JianRTaskManager.Redis_Script, 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; - } + 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.getHashMap(JianRTaskManager.Redis_Script, task)); + return json; + } + + @RequestMapping("/jianr/task/remove.do") + @ResponseBody + public JSONObject removeTask(String task) { + RedisTools.removeHashMap(JianRTaskManager.Redis_Script, task); + JSONObject json = new JSONObject(); + json.put("code", 0); + json.put("msg", "任务删除成功"); + return json; + } + + @RequestMapping("/jianr/device/connect.do") + @ResponseBody + public JSONObject connectDevice(String device) { + JSONObject json = new JSONObject(); + JianRTaskManager.getInstance().connect(device); + json.put("code", 0); + json.put("msg", "成功"); + return json; + } + + @RequestMapping("/jianr/device/add.do") + @ResponseBody + public JSONObject addDevice(String device) { + Map hashMap = RedisTools.getHashMap(JianRTaskManager.Redis_Device); + JSONObject deviceJson = JSON.parseObject(device); + JSONObject json = new JSONObject(); + json.put("code", 0); + if (deviceJson == null) { + json.put("msg", "JSON格式错误"); + } else { + if (hashMap.containsKey(device)) { + json.put("msg", "设备已存在"); + } else { + json.put("msg", RedisTools.setHashMap(JianRTaskManager.Redis_Device, + deviceJson.getString("title"), device) ? + "设备添加成功" : "设备添加失败"); + } + } + return json; + } + + @RequestMapping("/jianr/device/edit.do") + @ResponseBody + public JSONObject editDevice(String device, String oldDevice) { + JSONObject deviceJson = JSON.parseObject(device); + JSONObject json = new JSONObject(); + json.put("code", 0); + if (deviceJson == null) { + json.put("msg", "JSON格式错误"); + } else { + RedisTools.removeHashMap(JianRTaskManager.Redis_Device, oldDevice); + json.put("msg", RedisTools.setHashMap(JianRTaskManager.Redis_Device, + deviceJson.getString("title"), device) ? + "设备修改成功" : "设备修改失败"); + } + return json; + } + + @RequestMapping("/jianr/device/del.do") + @ResponseBody + public JSONObject delDevice(String device) { + JSONObject deviceJson = JSON.parseObject(device); + JSONObject json = new JSONObject(); + json.put("code", 0); + if (deviceJson == null) { + json.put("msg", "JSON格式错误"); + } else { + json.put("msg", RedisTools.removeHashMap(JianRTaskManager.Redis_Device) ? + "设备修改成功" : "设备修改失败"); + } + return json; + } + + @RequestMapping("/jianr/device/list.do") + @ResponseBody + public JSONObject getDeviceList() { + Map hashMap = RedisTools.getHashMap(JianRTaskManager.Redis_Device); + JSONObject json = new JSONObject(); + JSONArray array = new JSONArray(); + json.put("code", 0); + hashMap.keySet().forEach(key -> { + JSONObject device = JSONObject.parseObject(hashMap.get(key)); + JSONArray child = new JSONArray(); + JSONObject item = new JSONObject(); + JSONObject del = new JSONObject(); + JSONObject edit = new JSONObject(); + JSONObject select = new JSONObject(); + JSONObject connect = new JSONObject(); + item.put("title", key); + del.put("title", "删除"); + del.put("data", "del"); + del.put("device", device); + edit.put("title", "编辑"); + edit.put("data", "edit"); + edit.put("device", device); + select.put("title", "选择"); + select.put("data", "select"); + select.put("device", device); + connect.put("title", "连接设备"); + connect.put("data", "connect"); + connect.put("device", device); + child.add(connect); + child.add(select); + child.add(del); + child.add(edit); + item.put("child", child); + array.add(item); + }); + json.put("data", array); + return json; + } + + public static void main(String[] args) { + Map hashMap = RedisTools.getHashMap(JianRTaskManager.Redis_Device); + JSONObject json = new JSONObject(); + JSONArray array = new JSONArray(); + json.put("code", 0); + hashMap.keySet().forEach(key -> { + JSONObject item = JSONObject.parseObject(hashMap.get(key)); + array.add(item); + }); + json.put("data", array); + System.out.println(json); + } +} diff --git a/src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java b/src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java new file mode 100644 index 0000000..48b9043 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java @@ -0,0 +1,35 @@ +package com.yutou.qqbot.data.jianr; + +import lombok.Data; + +import java.util.List; + +@Data +public class AndroidDevice { + String title; + String deviceId; + DeviceDisplay androidDevice; + List deviceDisplay; + + + @Data + public static class DeviceDisplay { + int width, height; + } + + @Data + public static class GameDisplay { + String title; + double width, height; + Vector2D start, end; + + public double getWidth() { + return end.getX() - start.getX(); + } + + public double getHeight() { + return end.getY() - start.getY(); + } + } + +} diff --git a/src/main/java/com/yutou/qqbot/data/JianRScriptData.java b/src/main/java/com/yutou/qqbot/data/jianr/JianRScriptData.java similarity index 95% rename from src/main/java/com/yutou/qqbot/data/JianRScriptData.java rename to src/main/java/com/yutou/qqbot/data/jianr/JianRScriptData.java index 33cb8f6..be0ed0f 100644 --- a/src/main/java/com/yutou/qqbot/data/JianRScriptData.java +++ b/src/main/java/com/yutou/qqbot/data/jianr/JianRScriptData.java @@ -1,4 +1,4 @@ -package com.yutou.qqbot.data; +package com.yutou.qqbot.data.jianr; import lombok.Data; diff --git a/src/main/java/com/yutou/qqbot/data/jianr/JianRScriptV2Data.java b/src/main/java/com/yutou/qqbot/data/jianr/JianRScriptV2Data.java new file mode 100644 index 0000000..76801c5 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/data/jianr/JianRScriptV2Data.java @@ -0,0 +1,26 @@ +package com.yutou.qqbot.data.jianr; + +import lombok.Data; + +import java.util.List; + +@Data +public class JianRScriptV2Data { + private String title; + private List