From 72c49f3afa22c4f84760d57001e45a4fadf2d482 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 12 三月 2026 09:32:33 +0800
Subject: [PATCH] #升级JDK17
---
src/main/java/com/zy/asrs/service/impl/TvDeviceServiceImpl.java | 92 +++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 82 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/zy/asrs/service/impl/TvDeviceServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/TvDeviceServiceImpl.java
index 136ccf8..e3eb42a 100644
--- a/src/main/java/com/zy/asrs/service/impl/TvDeviceServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/TvDeviceServiceImpl.java
@@ -1,7 +1,7 @@
package com.zy.asrs.service.impl;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
-import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.asrs.entity.TvDevice;
import com.zy.asrs.mapper.TvDeviceMapper;
import com.zy.asrs.service.TvDeviceService;
@@ -37,7 +37,7 @@
@Override
public String testConnection(Long id) throws Exception {
- TvDevice device = this.selectById(id);
+ TvDevice device = this.getById(id);
if (device == null) {
throw new RuntimeException("璁惧涓嶅瓨鍦�");
}
@@ -83,7 +83,7 @@
@Override
public int refreshAllStatus() {
- List<TvDevice> devices = this.selectList(null);
+ List<TvDevice> devices = this.list(new QueryWrapper<>());
int count = 0;
for (TvDevice device : devices) {
try {
@@ -98,7 +98,7 @@
@Override
public String installApk(Long deviceId, String apkPath) throws Exception {
- TvDevice device = this.selectById(deviceId);
+ TvDevice device = this.getById(deviceId);
if (device == null) {
throw new RuntimeException("璁惧涓嶅瓨鍦�");
}
@@ -143,7 +143,7 @@
public List<String> batchInstallApk(List<Long> deviceIds, String apkPath) {
List<String> results = new ArrayList<>();
for (Long deviceId : deviceIds) {
- TvDevice device = this.selectById(deviceId);
+ TvDevice device = this.getById(deviceId);
String deviceName = device != null ? device.getName() : "ID:" + deviceId;
try {
String result = installApk(deviceId, apkPath);
@@ -157,12 +157,12 @@
@Override
public List<TvDevice> getOnlineDevices() {
- return this.selectList(new EntityWrapper<TvDevice>().eq("status", 1));
+ return this.list(new QueryWrapper<TvDevice>().eq("status", 1));
}
@Override
public String launchApp(Long deviceId, String packageName) throws Exception {
- TvDevice device = this.selectById(deviceId);
+ TvDevice device = this.getById(deviceId);
if (device == null) {
throw new RuntimeException("璁惧涓嶅瓨鍦�");
}
@@ -253,7 +253,7 @@
public List<String> batchLaunchApp(List<Long> deviceIds, String packageName) {
List<String> results = new ArrayList<>();
for (Long deviceId : deviceIds) {
- TvDevice device = this.selectById(deviceId);
+ TvDevice device = this.getById(deviceId);
String deviceName = device != null ? device.getName() : "ID:" + deviceId;
try {
String result = launchApp(deviceId, packageName);
@@ -267,7 +267,7 @@
@Override
public String captureScreen(Long deviceId) throws Exception {
- TvDevice device = this.selectById(deviceId);
+ TvDevice device = this.getById(deviceId);
if (device == null) {
throw new RuntimeException("璁惧涓嶅瓨鍦�");
}
@@ -334,6 +334,78 @@
return base64Image;
}
+ @Override
+ public String stopApp(Long deviceId, String packageName) throws Exception {
+ TvDevice device = this.getById(deviceId);
+ if (device == null) {
+ throw new RuntimeException("璁惧涓嶅瓨鍦�");
+ }
+
+ String pkg = (packageName != null && !packageName.trim().isEmpty()) ? packageName.trim() : defaultPackage;
+ StringBuilder result = new StringBuilder();
+ String adbAddress = device.getAdbAddress();
+
+ // 鍏堣繛鎺ヨ澶�
+ String connectResult = executeAdbCommand("connect", adbAddress);
+ result.append("杩炴帴: ").append(connectResult).append("\n");
+
+ if (connectResult.contains("failed")) {
+ device.setStatus((short) 0);
+ device.setUpdateTime(new Date());
+ this.updateById(device);
+ throw new RuntimeException("杩炴帴璁惧澶辫触: " + connectResult);
+ }
+
+ Thread.sleep(500);
+
+ // 浣跨敤am force-stop鍏抽棴搴旂敤
+ String stopResult = executeAdbCommand("-s", adbAddress, "shell", "am", "force-stop", pkg);
+ result.append("鍏抽棴: ").append(stopResult.isEmpty() ? "鎴愬姛" : stopResult);
+
+ // 鏇存柊璁惧鐘舵��
+ device.setStatus((short) 1);
+ device.setLastConnectTime(new Date());
+ device.setUpdateTime(new Date());
+ this.updateById(device);
+
+ log.info("璁惧 {} 鍏抽棴搴旂敤 {} 鎴愬姛", device.getName(), pkg);
+ return result.toString();
+ }
+
+ @Override
+ public String restartApp(Long deviceId, String packageName) throws Exception {
+ StringBuilder result = new StringBuilder();
+
+ // 鍏堝叧闂簲鐢�
+ String stopResult = stopApp(deviceId, packageName);
+ result.append("銆愬叧闂簲鐢ㄣ�慭n").append(stopResult).append("\n\n");
+
+ // 绛夊緟1绉掔‘淇濆簲鐢ㄥ畬鍏ㄥ叧闂�
+ Thread.sleep(1000);
+
+ // 鍐嶅惎鍔ㄥ簲鐢�
+ String launchResult = launchApp(deviceId, packageName);
+ result.append("銆愬惎鍔ㄥ簲鐢ㄣ�慭n").append(launchResult);
+
+ return result.toString();
+ }
+
+ @Override
+ public List<String> batchRestartApp(List<Long> deviceIds, String packageName) {
+ List<String> results = new ArrayList<>();
+ for (Long deviceId : deviceIds) {
+ TvDevice device = this.getById(deviceId);
+ String deviceName = device != null ? device.getName() : "ID:" + deviceId;
+ try {
+ String result = restartApp(deviceId, packageName);
+ results.add(deviceName + ": 閲嶅惎鎴愬姛\n" + result);
+ } catch (Exception e) {
+ results.add(deviceName + ": 閲嶅惎澶辫触 - " + e.getMessage());
+ }
+ }
+ return results;
+ }
+
/**
* 鎵цADB鍛戒护
*/
--
Gitblit v1.9.1