feat(device): 新增远程拍照功能

- 新增设备端与家属端远程拍照接口
- 新增截图实体字段(原始文件名、MIME类型、扩展名)
- 补充截图上传信息记录
- 提取设备操作指令常量
This commit is contained in:
TongTongStudio
2026-08-21 17:12:41 +08:00
parent 32921274a3
commit 9bc37286b7
10 changed files with 388 additions and 11 deletions

View File

@@ -81,6 +81,14 @@ public class DeviceOpsController {
return Result.judge(result);
}
@Operation(summary = "相机拍照")
@PostMapping("/take_photo")
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.SCREENSHOT)
public Result<?> takePhoto(@RequestParam String sn) {
boolean result = deviceService.takePhoto(sn);
return Result.judge(result);
}
@Operation(summary = "设备重启")
@PostMapping("/reboot")
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.REBOOT)

View File

@@ -397,6 +397,11 @@ public class MobileController {
SnScreenshot screenshotInfo = new SnScreenshot();
screenshotInfo.setSn(sn);
// 保存原始文件名,便于追溯/调试
screenshotInfo.setOriginName(safeBaseName);
// 保存MIME类型与扩展名便于前端筛选/预览
screenshotInfo.setMimeType(file.getContentType());
screenshotInfo.setFileExtension(fileExtension);
// fileName 仅存纯文件名;前端访问 URL = /static/screenshot/{fileName}(由 WebMvcConfig 静态映射)
screenshotInfo.setFileName(fileName);
// filePath 仅存相对子目录,避免耦合绝对路径

View File

@@ -0,0 +1,72 @@
package com.youlai.boot.device.model.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.youlai.boot.common.base.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
/**
* 设备截图实体
*/
@TableName("sys_sn_camera_photo")
@Getter
@Setter
public class SnCameraPhoto extends BaseEntity {
/**
* 设备序列号
*/
private String sn;
/**
* 文件名称
*/
private String fileName;
/**
* 原始文件名(上传时的原始文件名)
*/
private String originName;
/**
* 文件MIME类型
*/
private String mimeType;
/**
* 文件扩展名
*/
private String fileExtension;
/**
* 文件路径
*/
private String filePath;
/**
* 文件大小(字节)
*/
private Long fileSize;
/**
* 文件MD5值
*/
private String fileMd5;
/**
* 文件Sha1值
*/
private String fileSha1;
/**
* 文件Sha256值
*/
private String fileSha256;
/**
* 上传时间戳
*/
private LocalDateTime uploadTime;
}

View File

@@ -25,6 +25,21 @@ public class SnScreenshot extends BaseEntity {
*/
private String fileName;
/**
* 原始文件名(上传时的原始文件名)
*/
private String originName;
/**
* 文件MIME类型
*/
private String mimeType;
/**
* 文件扩展名
*/
private String fileExtension;
/**
* 文件路径
*/
@@ -54,4 +69,9 @@ public class SnScreenshot extends BaseEntity {
* 上传时间戳
*/
private LocalDateTime uploadTime;
/**
* 逻辑删除标志0未删除 1已删除
*/
private boolean isDeleted;
}

View File

@@ -24,6 +24,15 @@ public class ScreenshotVO {
@Schema(description = "文件名称")
private String fileName;
@Schema(description = "原始文件名(上传时的原始文件名)")
private String originName;
@Schema(description = "文件MIME类型")
private String mimeType;
@Schema(description = "文件扩展名")
private String fileExtension;
@Schema(description = "文件大小(字节)")
private Long fileSize;

View File

@@ -97,6 +97,7 @@ public interface DeviceService extends IService<SnDeviceInfo> {
* @return 是否推送成功
*/
boolean screenSnapshot(String sn);
boolean takePhoto(String sn);
boolean deviceReboot(String sn);
boolean deviceShutdown(String sn);

View File

@@ -55,6 +55,20 @@ import java.util.Set;
@RequiredArgsConstructor
@Slf4j
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> implements DeviceService {
private static final String DEVICE_REFRESH = "1";
private static final String DEVICE_SCREEN_SNAPSHOT = "2";
private static final String DEVICE_REBOOT = "3";
private static final String DEVICE_SHUTDOWN = "4";
private static final String DEVICE_LOCATE = "5";
private static final String DEVICE_RESTORE = "6";
private static final String DEVICE_DEVELOPER = "7";
private static final String DEVICE_APP_LAUNCH = "8";
private static final String DEVICE_APP_CLEAR_DATA = "9";
private static final String DEVICE_APP_UNINSTALL = "10";
private static final String DEVICE_APP_STOP = "11";
private static final String DEVICE_TAKE_PHOTO = "12";
PushApi pushApi = new PushApi.Builder()
.setAppKey("d779178d9900d4fb5d633678")
.setMasterSecret("be0e197d30fec7bec118a70d")
@@ -254,7 +268,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean deviceRefresh(String sn) {
PushSendParam pushSendParam = getSinglePushSendParam(sn, "1", "deviceRefresh", "refresh");
PushSendParam pushSendParam = getSinglePushSendParam(sn, DEVICE_REFRESH, "deviceRefresh", "refresh");
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
@@ -272,7 +286,24 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean screenSnapshot(String sn) {
PushSendParam pushSendParam = getSinglePushSendParam(sn, "2", "screenSnapshot", "screenshot");
PushSendParam pushSendParam = getSinglePushSendParam(sn, DEVICE_SCREEN_SNAPSHOT, "screenSnapshot", "screenshot");
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
return true;
} catch (ApiErrorException e) {
// 错误信息
int httpStatus = e.getStats(); // HTTP状态码
int errorCode = e.getApiError().getError().getCode(); // 错误码
String errorMessage = e.getApiError().getError().getMessage(); // 错误信息
log.error("send error, httpStatus:{} code:{}, message:{}", httpStatus, errorCode, errorMessage);
return false;
}
}
@Override
public boolean takePhoto(String sn) {
PushSendParam pushSendParam = getSinglePushSendParam(sn, DEVICE_TAKE_PHOTO, "takePhoto", "camera");
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
@@ -289,7 +320,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean deviceReboot(String sn) {
PushSendParam pushSendParam = getSinglePushSendParam(sn, "3", "deviceReboot", "reboot");
PushSendParam pushSendParam = getSinglePushSendParam(sn, DEVICE_REBOOT, "deviceReboot", "reboot");
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
@@ -306,7 +337,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean deviceShutdown(String sn) {
PushSendParam pushSendParam = getSinglePushSendParam(sn, "4", "deviceShutdown", "shutdown");
PushSendParam pushSendParam = getSinglePushSendParam(sn, DEVICE_SHUTDOWN, "deviceShutdown", "shutdown");
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
@@ -323,7 +354,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean deviceLocate(String sn) {
PushSendParam pushSendParam = getSinglePushSendParam(sn, "5", "deviceLocate", "locate");
PushSendParam pushSendParam = getSinglePushSendParam(sn, DEVICE_LOCATE, "deviceLocate", "locate");
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
@@ -340,7 +371,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean restore(String sn) {
PushSendParam pushSendParam = getSinglePushSendParam(sn, "6", "deviceRestore", "restore");
PushSendParam pushSendParam = getSinglePushSendParam(sn, DEVICE_RESTORE, "deviceRestore", "restore");
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
@@ -357,7 +388,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean setDeviceDeveloper(String sn) {
PushSendParam pushSendParam = getSinglePushSendParam(sn, "7", "deviceDeveloper", "developer");
PushSendParam pushSendParam = getSinglePushSendParam(sn, DEVICE_DEVELOPER, "deviceDeveloper", "developer");
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
@@ -385,7 +416,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean launchApp(String sn, String packageName) {
PushSendParam pushSendParam = getAppPushSendParam(sn, "8", "appLaunch", "launch", packageName);
PushSendParam pushSendParam = getAppPushSendParam(sn, DEVICE_APP_LAUNCH, "appLaunch", "launch", packageName);
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
@@ -401,7 +432,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean clearAppData(String sn, String packageName) {
PushSendParam pushSendParam = getAppPushSendParam(sn, "9", "appClearData", "clearData", packageName);
PushSendParam pushSendParam = getAppPushSendParam(sn, DEVICE_APP_CLEAR_DATA, "appClearData", "clearData", packageName);
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
@@ -417,7 +448,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean uninstallApp(String sn, String packageName) {
PushSendParam pushSendParam = getAppPushSendParam(sn, "10", "appUninstall", "uninstall", packageName);
PushSendParam pushSendParam = getAppPushSendParam(sn, DEVICE_APP_UNINSTALL, "appUninstall", "uninstall", packageName);
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);
@@ -433,7 +464,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean stopApp(String sn, String packageName) {
PushSendParam pushSendParam = getAppPushSendParam(sn, "11", "appStop", "stop", packageName);
PushSendParam pushSendParam = getAppPushSendParam(sn, DEVICE_APP_STOP, "appStop", "stop", packageName);
try {
PushSendResult result = pushApi.send(pushSendParam);
log.info("send success:{}", result);