增加截图上传,图片地址优化
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
package com.onekeycall.videotablet.controller.sn;
|
||||
|
||||
import com.onekeycall.videotablet.config.FilePath;
|
||||
import com.onekeycall.videotablet.entity.ApkIconFileInfo;
|
||||
import com.onekeycall.videotablet.entity.Contact;
|
||||
import com.onekeycall.videotablet.entity.DeviceInfo;
|
||||
import com.onekeycall.videotablet.entity.DeviceLocation;
|
||||
import com.onekeycall.videotablet.entity.*;
|
||||
import com.onekeycall.videotablet.result.Result;
|
||||
import com.onekeycall.videotablet.service.ApkIconService;
|
||||
import com.onekeycall.videotablet.service.ContactService;
|
||||
import com.onekeycall.videotablet.service.DeviceLocationService;
|
||||
import com.onekeycall.videotablet.service.DeviceSnService;
|
||||
import com.onekeycall.videotablet.service.*;
|
||||
import com.onekeycall.videotablet.utils.HashUtils;
|
||||
import com.onekeycall.videotablet.utils.JwtUtil;
|
||||
import com.onekeycall.videotablet.utils.TextUtils;
|
||||
@@ -38,6 +32,8 @@ public class DevicesController {
|
||||
private ContactService contactService;
|
||||
@Autowired
|
||||
private ApkIconService apkIconService;
|
||||
@Autowired
|
||||
private ScreenshotService screenshotService;
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(DevicesController.class);
|
||||
|
||||
@@ -157,4 +153,36 @@ public class DevicesController {
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/upload_screenshot")
|
||||
public Result uploadScreenshot(
|
||||
@RequestPart(value = "file") MultipartFile file,
|
||||
@RequestParam(value = "sn") String sn
|
||||
) throws Exception {
|
||||
String screenshotPath = FilePath.getScreenshotPath();
|
||||
logger.info("uploadScreenshot, screenshotPath: {}", screenshotPath);
|
||||
File fileDir = new File(screenshotPath);
|
||||
if (!fileDir.exists()) {
|
||||
fileDir.mkdirs();
|
||||
}
|
||||
|
||||
String originName = file.getOriginalFilename();
|
||||
String fileExtension = FilenameUtils.getExtension(originName);
|
||||
String hash = HashUtils.calculateMultipartFileMd5(file);
|
||||
String fileName = sn + "_" + System.currentTimeMillis() + "_" + hash + "." + fileExtension;
|
||||
File destFile = new File(fileDir, fileName);
|
||||
try {
|
||||
file.transferTo(destFile);
|
||||
ScreenshotInfo screenshotInfo =new ScreenshotInfo();
|
||||
screenshotInfo.setSn(sn);
|
||||
screenshotInfo.setFile_name(fileName);
|
||||
screenshotInfo.setUpload_time(new Date(System.currentTimeMillis()).getTime());
|
||||
screenshotService.save(screenshotInfo);
|
||||
} catch (Exception e) {
|
||||
logger.error("uploadScreenshot error", e.getMessage());
|
||||
return Result.error().message("upload screenshot error");
|
||||
}
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ public class UserController {
|
||||
private DeviceApkInfoService deviceApkInfoService;
|
||||
@Autowired
|
||||
private ApkIconService apkIconService;
|
||||
@Autowired
|
||||
private ScreenshotService screenshotService;
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(LoginController.class);
|
||||
|
||||
@@ -262,7 +264,7 @@ public class UserController {
|
||||
) throws ExecutionException, InterruptedException {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("package_name", packageName);
|
||||
switch (action){
|
||||
switch (action) {
|
||||
case "open":
|
||||
DevicePushUtils.aliyunAsyncPush(PushIdConfig.OPEN_APP, sn, GsonUtils.toJSONString(params));
|
||||
break;
|
||||
@@ -280,4 +282,44 @@ public class UserController {
|
||||
}
|
||||
return Result.ok().message("success");
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/screen_snapshot")
|
||||
public Result screenSnapshot(@RequestParam String sn) throws ExecutionException, InterruptedException {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("sn", sn);
|
||||
params.put("timestamp", System.currentTimeMillis());
|
||||
DevicePushUtils.aliyunAsyncPush(PushIdConfig.SCREEN_SNAPSHOT, sn, GsonUtils.toJSONString(params));
|
||||
return Result.ok().message("success");
|
||||
}
|
||||
|
||||
@GetMapping("/get_snapshot")
|
||||
public Result getScreenSnapshot(@RequestParam String sn) {
|
||||
List<ScreenshotInfo> screenSnapshot = screenshotService.findBySn(sn);
|
||||
if (screenSnapshot == null) {
|
||||
return Result.notFound().message("Screen snapshot not found");
|
||||
}
|
||||
return Result.ok().data(screenSnapshot);
|
||||
}
|
||||
|
||||
@PostMapping("/delete_all_snapshot")
|
||||
public Result deleteAllScreenSnapshot(@RequestParam String sn) {
|
||||
screenshotService.deleteAllBySn(sn);
|
||||
return Result.ok().message("success");
|
||||
}
|
||||
|
||||
@PostMapping("/delete_snapshot")
|
||||
public Result deleteScreenSnapshot(@RequestParam String sn, @RequestParam Long id) {
|
||||
if (screenshotService.existsBySnAndId(sn, id)) {
|
||||
boolean deleteSuccess = screenshotService.deleteBySnAndId(sn, id);
|
||||
if (deleteSuccess) {
|
||||
logger.info("deleteScreenSnapshot success, sn: {}, id: {}", sn, id);
|
||||
} else {
|
||||
logger.info("deleteScreenSnapshot fail, sn: {}, id: {}", sn, id);
|
||||
}
|
||||
} else {
|
||||
logger.info("deleteScreenSnapshot not found, sn: {}, id: {}", sn, id);
|
||||
}
|
||||
return Result.ok().message("success");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user