- 新增 GET /{sn}/location 接口,支持网页端查询设备最新定位信息
- 新增 DeviceLocationVO 视图对象用于返回定位数据
- 在 LocationService 中实现 getLatestBySn 方法
- 修复 map_error 字段类型错误:从 INT 改为 VARCHAR(255)
- 修复移动端上报定位时 lastSuccessfulTime 缺失问题,由服务端统一写入
177 lines
7.1 KiB
Java
177 lines
7.1 KiB
Java
package com.youlai.boot.device.controller;
|
||
|
||
import com.youlai.boot.common.annotation.Log;
|
||
import com.youlai.boot.common.enums.ActionTypeEnum;
|
||
import com.youlai.boot.common.enums.LogModuleEnum;
|
||
import com.youlai.boot.common.result.Result;
|
||
import com.youlai.boot.device.model.entity.SnDeviceInfo;
|
||
import com.youlai.boot.device.model.form.AppActionForm;
|
||
import com.youlai.boot.device.model.form.DeveloperForm;
|
||
import com.youlai.boot.device.model.vo.DeviceLocationVO;
|
||
import com.youlai.boot.device.model.vo.DevicePageVO;
|
||
import com.youlai.boot.device.service.DeviceService;
|
||
import com.youlai.boot.device.service.LocationService;
|
||
import io.swagger.v3.oas.annotations.Operation;
|
||
import io.swagger.v3.oas.annotations.Parameter;
|
||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||
import jakarta.validation.Valid;
|
||
import lombok.RequiredArgsConstructor;
|
||
import org.springframework.security.access.prepost.PreAuthorize;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
/**
|
||
* 设备操作管理控制层(还原原 DeviceController 中的设备操作类接口)
|
||
* 与 DeviceController(列表 + 分面板信息查询)分离,职责更清晰。
|
||
*
|
||
* @author TTSTD
|
||
* @since 2026/08/05
|
||
*/
|
||
@Tag(name = "15.SN管理-操作")
|
||
@RestController
|
||
@RequestMapping("/api/v1/device")
|
||
@RequiredArgsConstructor
|
||
public class DeviceOpsController {
|
||
|
||
private final DeviceService deviceService;
|
||
private final LocationService locationService;
|
||
|
||
@Operation(summary = "获取SN绑定激活信息")
|
||
@GetMapping("/{sn}/info")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.VIEW)
|
||
public Result<DevicePageVO> getSnBindInfo(@PathVariable String sn) {
|
||
DevicePageVO detail = deviceService.getSnBindInfo(sn);
|
||
return Result.success(detail);
|
||
}
|
||
|
||
@Operation(summary = "新增SN")
|
||
@PostMapping("/add")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.INSERT)
|
||
public Result<Void> addSn(@RequestBody SnDeviceInfo snDeviceInfo) {
|
||
deviceService.addSn(snDeviceInfo);
|
||
return Result.success();
|
||
}
|
||
|
||
@Operation(summary = "删除SN")
|
||
@DeleteMapping("/{sn}")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.DELETE)
|
||
@PreAuthorize("@ss.hasPerm('sys:sn:delete')")
|
||
public Result<Void> deleteSn(@PathVariable String sn) {
|
||
deviceService.deleteSn(sn);
|
||
return Result.success();
|
||
}
|
||
|
||
@Operation(summary = "设备刷新")
|
||
@PostMapping("/refresh")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.REFRESH)
|
||
public Result<?> devicerefresh(@RequestParam String sn) {
|
||
boolean result = deviceService.deviceRefresh(sn);
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "设备截图")
|
||
@PostMapping("/screenshot")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.SCREENSHOT)
|
||
public Result<?> screenSnapshot(@RequestParam String sn) {
|
||
boolean result = deviceService.screenSnapshot(sn);
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "设备重启")
|
||
@PostMapping("/reboot")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.REBOOT)
|
||
public Result<?> reboot(@RequestParam String sn) {
|
||
boolean result = deviceService.deviceReboot(sn);
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "设备关机")
|
||
@PostMapping("/shutdown")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.SHUTDOWN)
|
||
public Result<?> shutdown(@RequestParam String sn) {
|
||
boolean result = deviceService.deviceShutdown(sn);
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "设备定位")
|
||
@PostMapping("/locate")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.LOCATE)
|
||
public Result<?> deviceLocate(@RequestParam String sn) {
|
||
boolean result = deviceService.deviceLocate(sn);
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "获取设备最新定位信息", description = "返回设备最近一次上报的定位信息,用于网页端展示百度地图")
|
||
@GetMapping("/{sn}/location")
|
||
public Result<DeviceLocationVO> getLocation(@Parameter(description = "设备序列号", required = true) @PathVariable String sn) {
|
||
DeviceLocationVO location = locationService.getLatestBySn(sn);
|
||
return Result.success(location);
|
||
}
|
||
|
||
@Operation(summary = "设备重置")
|
||
@PostMapping("/restore")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.RESTORE)
|
||
public Result<?> deviceRestore(@RequestParam String sn) {
|
||
boolean result = deviceService.restore(sn);
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "开发者模式")
|
||
@PostMapping("/developer")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.DEVELOPER)
|
||
public Result<?> deviceDeveloper(@RequestParam String sn) {
|
||
boolean result = deviceService.setDeviceDeveloper(sn);
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "新增开发者选项配置")
|
||
@PostMapping("/developer/config")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.INSERT)
|
||
public Result<Void> addDeveloperConfig(@Valid @RequestBody DeveloperForm developerForm) {
|
||
boolean result = deviceService.addDeveloperConfig(
|
||
developerForm.getSn(),
|
||
developerForm.getDeveloperOptions()
|
||
);
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "删除开发者选项配置")
|
||
@DeleteMapping("/developer/config")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.DELETE)
|
||
public Result<Void> deleteDeveloperConfig(@RequestParam String sn) {
|
||
boolean result = deviceService.deleteDeveloperConfig(sn);
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "打开应用")
|
||
@PostMapping("/{sn}/app/launch")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.LAUNCH_APP)
|
||
public Result<?> launchApp(@PathVariable String sn, @Valid @RequestBody AppActionForm form) {
|
||
boolean result = deviceService.launchApp(sn, form.getPackageName());
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "清除应用数据")
|
||
@PostMapping("/{sn}/app/clear_data")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.CLEAR_APP_DATA)
|
||
public Result<?> clearAppData(@PathVariable String sn, @Valid @RequestBody AppActionForm form) {
|
||
boolean result = deviceService.clearAppData(sn, form.getPackageName());
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "卸载应用")
|
||
@PostMapping("/{sn}/app/uninstall")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.UNINSTALL_APP)
|
||
public Result<?> uninstallApp(@PathVariable String sn, @Valid @RequestBody AppActionForm form) {
|
||
boolean result = deviceService.uninstallApp(sn, form.getPackageName());
|
||
return Result.judge(result);
|
||
}
|
||
|
||
@Operation(summary = "停止应用")
|
||
@PostMapping("/{sn}/app/stop")
|
||
@Log(module = LogModuleEnum.DEVICE, value = ActionTypeEnum.STOP_APP)
|
||
public Result<?> stopApp(@PathVariable String sn, @Valid @RequestBody AppActionForm form) {
|
||
boolean result = deviceService.stopApp(sn, form.getPackageName());
|
||
return Result.judge(result);
|
||
}
|
||
}
|