refactor(storage): 业务文件统一走对象存储并移除本地静态资源映射
- 删除 FilePath 与 WebMvcConfig,取消 /static/** 本地磁盘映射 - 安装包、壁纸、截图、分类图标、家属端图片全部使用存储服务返回的完整 URL - 设备截图与拍照改存 StorageDir.DEVICE_SCREENSHOT,file_path 保存完整访问地址 - 壁纸/图片收藏按库中完整 URL 直接匹配,去掉相对路径归一化 - 家属于已绑定同一账号的设备再次发起绑定时下发确认请求,支持重置后重新授权
This commit is contained in:
1 parent
ee94762905
commit
9530b49be2
17 files changed
+72
-385
No files matched your search
@@ -1,7 +1,7 @@
|
||||
package com.youlai.boot.device.controller;
|
||||
|
||||
import com.youlai.boot.common.annotation.Log;
|
||||
import com.youlai.boot.common.config.FilePath;
|
||||
import com.youlai.boot.common.config.StorageDir;
|
||||
import com.youlai.boot.common.enums.ActionTypeEnum;
|
||||
import com.youlai.boot.common.enums.LogModuleEnum;
|
||||
import com.youlai.boot.common.exception.BusinessException;
|
||||
@@ -33,6 +33,8 @@ import com.youlai.boot.device.model.vo.DeviceWallpaperVO;
|
||||
import com.youlai.boot.device.converter.DevicePolicyConverter;
|
||||
import com.youlai.boot.device.service.*;
|
||||
import com.youlai.boot.framework.security.signature.DeviceSignatureVerifier;
|
||||
import com.youlai.boot.support.file.model.FileInfo;
|
||||
import com.youlai.boot.support.file.service.FileService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -44,7 +46,6 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -76,6 +77,7 @@ public class MobileController {
|
||||
private final DeviceSignatureVerifier deviceSignatureVerifier;
|
||||
private final DeviceWallpaperService deviceWallpaperService;
|
||||
private final DeviceAlarmService deviceAlarmService;
|
||||
private final FileService fileService;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(MobileController.class);
|
||||
|
||||
@@ -114,16 +116,33 @@ public class MobileController {
|
||||
return Result.failed(ResultCode.MOBILE_SIGN_INVALID, "设备签名验证失败");
|
||||
}
|
||||
|
||||
// 2. 注册设备(绑定即注册):SN ↔ 公钥,不存在则新建,已存在则更新公钥
|
||||
// 2. 查已有记录:封禁与手机号冲突必须在写公钥之前校验,
|
||||
// 否则错误手机号的请求会先把公钥换掉,导致真正绑定的设备无法再验签
|
||||
SnDeviceInfo device = deviceService.lambdaQuery()
|
||||
.eq(SnDeviceInfo::getSerialno, sn)
|
||||
.one();
|
||||
if (device != null) {
|
||||
if (device.getStatus() != null && device.getStatus() == 0) {
|
||||
return Result.failed(ResultCode.MOBILE_DEVICE_BANNED);
|
||||
}
|
||||
if (StringUtils.hasText(device.getSnMobile())
|
||||
&& !device.getSnMobile().equals(phone.trim())) {
|
||||
return Result.failed("该设备已绑定其他手机号");
|
||||
}
|
||||
if (StringUtils.hasText(device.getPublicKey())
|
||||
&& !device.getPublicKey().equals(publicKey)) {
|
||||
logger.info("设备公钥变更(重新授权), sn: {}, phone: {}", sn, phone.trim());
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 注册设备(绑定即注册):SN ↔ 公钥 + 手机号一次写入
|
||||
if (device == null) {
|
||||
device = new SnDeviceInfo();
|
||||
device.setSerialno(sn);
|
||||
device.setStatus(1);
|
||||
device.setSnModel(model);
|
||||
device.setPublicKey(publicKey);
|
||||
device.setSnMobile(phone.trim());
|
||||
boolean saved = deviceService.save(device);
|
||||
if (!saved) {
|
||||
return Result.failed("设备注册失败");
|
||||
@@ -133,21 +152,13 @@ public class MobileController {
|
||||
if (model != null && !model.trim().isEmpty()) {
|
||||
device.setSnModel(model);
|
||||
}
|
||||
device.setSnMobile(phone.trim());
|
||||
deviceService.updateById(device);
|
||||
}
|
||||
|
||||
// 3. 已绑定给其他手机号则拒绝(同一设备仅允许一个家属手机号)
|
||||
if (StringUtils.hasText(device.getSnMobile())
|
||||
&& !device.getSnMobile().equals(phone.trim())) {
|
||||
return Result.failed("该设备已绑定其他手机号");
|
||||
}
|
||||
|
||||
// 4. 写入绑定关系
|
||||
device.setSnMobile(phone.trim());
|
||||
deviceService.updateById(device);
|
||||
logger.info("设备确认绑定成功(绑定即注册), sn: {}, phone: {}", sn, phone.trim());
|
||||
|
||||
// 5. 回推绑定成功通知到设备端(contentType=21)
|
||||
// 4. 回推绑定成功通知到设备端(contentType=21)
|
||||
deviceService.pushBindSuccess(sn, phone.trim());
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
@@ -479,18 +490,6 @@ public class MobileController {
|
||||
return Result.failed("设备序列号不能为空");
|
||||
}
|
||||
|
||||
String screenshotPath = FilePath.getScreenshotPath();
|
||||
logger.info("uploadScreenshot, screenshotPath: {}", screenshotPath);
|
||||
|
||||
File fileDir = new File(screenshotPath);
|
||||
if (!fileDir.exists()) {
|
||||
boolean created = fileDir.mkdirs();
|
||||
if (!created) {
|
||||
logger.error("创建目录失败: {}", screenshotPath);
|
||||
return Result.failed("创建目录失败");
|
||||
}
|
||||
}
|
||||
|
||||
String originName = file.getOriginalFilename();
|
||||
if (originName == null || originName.isEmpty()) {
|
||||
return Result.failed("文件名无效");
|
||||
@@ -505,10 +504,10 @@ public class MobileController {
|
||||
String md5 = HashUtils.calculateMultipartFileMd5(file);
|
||||
String sha1 = HashUtils.calculateMultipartFileSha1(file);
|
||||
String sha256 = HashUtils.calculateMultipartFileSha256(file);
|
||||
String fileName = sn + "_" + System.currentTimeMillis() + "_" + md5 + "." + fileExtension;
|
||||
File destFile = new File(fileDir, fileName);
|
||||
|
||||
file.transferTo(destFile);
|
||||
FileInfo stored = fileService.uploadFile(file, StorageDir.DEVICE_SCREENSHOT);
|
||||
String url = stored.getUrl();
|
||||
int slash = url.lastIndexOf('/');
|
||||
|
||||
SnScreenshot screenshotInfo = new SnScreenshot();
|
||||
screenshotInfo.setSn(sn);
|
||||
@@ -517,10 +516,10 @@ public class MobileController {
|
||||
// 保存MIME类型与扩展名,便于前端筛选/预览
|
||||
screenshotInfo.setMimeType(file.getContentType());
|
||||
screenshotInfo.setFileExtension(fileExtension);
|
||||
// fileName 仅存纯文件名;前端访问 URL = /static/screenshot/{fileName}(由 WebMvcConfig 静态映射)
|
||||
screenshotInfo.setFileName(fileName);
|
||||
// filePath 仅存相对子目录,避免耦合绝对路径
|
||||
screenshotInfo.setFilePath(FilePath.TABLET_PATH + "/" + FilePath.SCREENSHOT_PATH + "/" + fileName);
|
||||
// 对象名由存储服务生成(UUID),fileName 仅存末段便于展示
|
||||
screenshotInfo.setFileName(slash >= 0 ? url.substring(slash + 1) : url);
|
||||
// 保存存储返回的完整 URL(s3 / aliyun / local),前端按 URL 直接访问
|
||||
screenshotInfo.setFilePath(url);
|
||||
screenshotInfo.setFileSize(file.getSize());
|
||||
screenshotInfo.setFileMd5(md5);
|
||||
screenshotInfo.setFileSha1(sha1);
|
||||
@@ -530,7 +529,7 @@ public class MobileController {
|
||||
|
||||
screenshotService.save(screenshotInfo);
|
||||
|
||||
logger.info("截图上传成功, sn: {}, fileName: {}", sn, fileName);
|
||||
logger.info("截图上传成功, sn: {}, url: {}", sn, url);
|
||||
return Result.success();
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in new issue
Block a user