refactor(device): 重构设备信息模块,按面板拆分数据存储和接口
将原 SnDeviceSystemInfo 单一实体拆分为基本信息、硬件、网络、安全、其他信息五个独立子表和服务,重构 DeviceController 和 MobileController 接口以支持分面板查询和上传
This commit is contained in:
@@ -8,8 +8,16 @@ import com.youlai.boot.common.enums.LogModuleEnum;
|
||||
import com.youlai.boot.common.result.Result;
|
||||
import com.youlai.boot.common.util.HashUtils;
|
||||
import com.youlai.boot.device.model.entity.SnDeviceSystemInfo;
|
||||
import com.youlai.boot.device.model.entity.SnDeviceHardwareInfo;
|
||||
import com.youlai.boot.device.model.entity.SnDeviceNetworkInfo;
|
||||
import com.youlai.boot.device.model.entity.SnDeviceSecurityInfo;
|
||||
import com.youlai.boot.device.model.entity.SnDeviceOtherInfo;
|
||||
import com.youlai.boot.device.model.req.ApkInstallInfoReq;
|
||||
import com.youlai.boot.device.model.req.SnSystemInfoReq;
|
||||
import com.youlai.boot.device.model.req.SnHardwareInfoReq;
|
||||
import com.youlai.boot.device.model.req.SnNetworkInfoReq;
|
||||
import com.youlai.boot.device.model.req.SnSecurityInfoReq;
|
||||
import com.youlai.boot.device.model.req.SnOtherInfoReq;
|
||||
import com.youlai.boot.device.model.req.SnLocationReq;
|
||||
import com.youlai.boot.device.model.entity.SnLocation;
|
||||
import com.youlai.boot.device.model.entity.SnScreenshot;
|
||||
@@ -52,6 +60,10 @@ public class MobileController {
|
||||
private final DeveloperService developerService;
|
||||
private final ApkInstallService apkInstallService;
|
||||
private final SystemInfoService systemInfoService;
|
||||
private final HardwareInfoService hardwareInfoService;
|
||||
private final NetworkInfoService networkInfoService;
|
||||
private final SecurityInfoService securityInfoService;
|
||||
private final OtherInfoService otherInfoService;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(MobileController.class);
|
||||
|
||||
@@ -122,6 +134,194 @@ public class MobileController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "上传设备其他信息")
|
||||
@PostMapping("/update_other_info")
|
||||
@Log(module = LogModuleEnum.MOBILE, value = ActionTypeEnum.DEVELOPER)
|
||||
public Result<Void> updateOtherInfo(
|
||||
@RequestHeader(value = "X-Device-SN") String sn,
|
||||
@RequestBody SnOtherInfoReq snOtherInfoReq
|
||||
) {
|
||||
try {
|
||||
if (sn == null || sn.trim().isEmpty()) {
|
||||
return Result.failed("设备序列号不能为空");
|
||||
}
|
||||
|
||||
if (snOtherInfoReq == null) {
|
||||
return Result.failed("其他信息不能为空");
|
||||
}
|
||||
|
||||
SnDeviceOtherInfo otherInfo = new SnDeviceOtherInfo();
|
||||
BeanUtils.copyProperties(snOtherInfoReq, otherInfo);
|
||||
otherInfo.setSerialno(sn);
|
||||
otherInfo.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
SnDeviceOtherInfo existingOtherInfo = otherInfoService.lambdaQuery()
|
||||
.eq(SnDeviceOtherInfo::getSerialno, sn)
|
||||
.one();
|
||||
|
||||
boolean saved;
|
||||
if (existingOtherInfo != null) {
|
||||
otherInfo.setId(existingOtherInfo.getId());
|
||||
saved = otherInfoService.updateById(otherInfo);
|
||||
} else {
|
||||
otherInfo.setCreateTime(LocalDateTime.now());
|
||||
saved = otherInfoService.save(otherInfo);
|
||||
}
|
||||
|
||||
if (!saved) {
|
||||
return Result.failed("保存其他信息失败");
|
||||
}
|
||||
|
||||
logger.info("其他信息上传成功, sn: {}", sn);
|
||||
return Result.success();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("updateOtherInfo error, sn: {}", sn, e);
|
||||
return Result.failed("上传其他信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "上传设备硬件信息")
|
||||
@PostMapping("/update_hardware_info")
|
||||
@Log(module = LogModuleEnum.MOBILE, value = ActionTypeEnum.DEVELOPER)
|
||||
public Result<Void> updateHardwareInfo(
|
||||
@RequestHeader(value = "X-Device-SN") String sn,
|
||||
@RequestBody SnHardwareInfoReq snHardwareInfoReq
|
||||
) {
|
||||
try {
|
||||
if (sn == null || sn.trim().isEmpty()) {
|
||||
return Result.failed("设备序列号不能为空");
|
||||
}
|
||||
|
||||
if (snHardwareInfoReq == null) {
|
||||
return Result.failed("硬件信息不能为空");
|
||||
}
|
||||
|
||||
SnDeviceHardwareInfo hardwareInfo = new SnDeviceHardwareInfo();
|
||||
BeanUtils.copyProperties(snHardwareInfoReq, hardwareInfo);
|
||||
hardwareInfo.setSerialno(sn);
|
||||
hardwareInfo.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
SnDeviceHardwareInfo existingHardwareInfo = hardwareInfoService.lambdaQuery()
|
||||
.eq(SnDeviceHardwareInfo::getSerialno, sn)
|
||||
.one();
|
||||
|
||||
boolean saved;
|
||||
if (existingHardwareInfo != null) {
|
||||
hardwareInfo.setId(existingHardwareInfo.getId());
|
||||
saved = hardwareInfoService.updateById(hardwareInfo);
|
||||
} else {
|
||||
hardwareInfo.setCreateTime(LocalDateTime.now());
|
||||
saved = hardwareInfoService.save(hardwareInfo);
|
||||
}
|
||||
|
||||
if (!saved) {
|
||||
return Result.failed("保存硬件信息失败");
|
||||
}
|
||||
|
||||
logger.info("硬件信息上传成功, sn: {}", sn);
|
||||
return Result.success();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("updateHardwareInfo error, sn: {}", sn, e);
|
||||
return Result.failed("上传硬件信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "上传设备网络信息")
|
||||
@PostMapping("/update_network_info")
|
||||
@Log(module = LogModuleEnum.MOBILE, value = ActionTypeEnum.DEVELOPER)
|
||||
public Result<Void> updateNetworkInfo(
|
||||
@RequestHeader(value = "X-Device-SN") String sn,
|
||||
@RequestBody SnNetworkInfoReq snNetworkInfoReq
|
||||
) {
|
||||
try {
|
||||
if (sn == null || sn.trim().isEmpty()) {
|
||||
return Result.failed("设备序列号不能为空");
|
||||
}
|
||||
|
||||
if (snNetworkInfoReq == null) {
|
||||
return Result.failed("网络信息不能为空");
|
||||
}
|
||||
|
||||
SnDeviceNetworkInfo networkInfo = new SnDeviceNetworkInfo();
|
||||
BeanUtils.copyProperties(snNetworkInfoReq, networkInfo);
|
||||
networkInfo.setSerialno(sn);
|
||||
networkInfo.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
SnDeviceNetworkInfo existingNetworkInfo = networkInfoService.lambdaQuery()
|
||||
.eq(SnDeviceNetworkInfo::getSerialno, sn)
|
||||
.one();
|
||||
|
||||
boolean saved;
|
||||
if (existingNetworkInfo != null) {
|
||||
networkInfo.setId(existingNetworkInfo.getId());
|
||||
saved = networkInfoService.updateById(networkInfo);
|
||||
} else {
|
||||
networkInfo.setCreateTime(LocalDateTime.now());
|
||||
saved = networkInfoService.save(networkInfo);
|
||||
}
|
||||
|
||||
if (!saved) {
|
||||
return Result.failed("保存网络信息失败");
|
||||
}
|
||||
|
||||
logger.info("网络信息上传成功, sn: {}", sn);
|
||||
return Result.success();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("updateNetworkInfo error, sn: {}", sn, e);
|
||||
return Result.failed("上传网络信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "上传设备安全信息")
|
||||
@PostMapping("/update_security_info")
|
||||
@Log(module = LogModuleEnum.MOBILE, value = ActionTypeEnum.DEVELOPER)
|
||||
public Result<Void> updateSecurityInfo(
|
||||
@RequestHeader(value = "X-Device-SN") String sn,
|
||||
@RequestBody SnSecurityInfoReq snSecurityInfoReq
|
||||
) {
|
||||
try {
|
||||
if (sn == null || sn.trim().isEmpty()) {
|
||||
return Result.failed("设备序列号不能为空");
|
||||
}
|
||||
|
||||
if (snSecurityInfoReq == null) {
|
||||
return Result.failed("安全信息不能为空");
|
||||
}
|
||||
|
||||
SnDeviceSecurityInfo securityInfo = new SnDeviceSecurityInfo();
|
||||
BeanUtils.copyProperties(snSecurityInfoReq, securityInfo);
|
||||
securityInfo.setSerialno(sn);
|
||||
securityInfo.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
SnDeviceSecurityInfo existingSecurityInfo = securityInfoService.lambdaQuery()
|
||||
.eq(SnDeviceSecurityInfo::getSerialno, sn)
|
||||
.one();
|
||||
|
||||
boolean saved;
|
||||
if (existingSecurityInfo != null) {
|
||||
securityInfo.setId(existingSecurityInfo.getId());
|
||||
saved = securityInfoService.updateById(securityInfo);
|
||||
} else {
|
||||
securityInfo.setCreateTime(LocalDateTime.now());
|
||||
saved = securityInfoService.save(securityInfo);
|
||||
}
|
||||
|
||||
if (!saved) {
|
||||
return Result.failed("保存安全信息失败");
|
||||
}
|
||||
|
||||
logger.info("安全信息上传成功, sn: {}", sn);
|
||||
return Result.success();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("updateSecurityInfo error, sn: {}", sn, e);
|
||||
return Result.failed("上传安全信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "上传设备截图")
|
||||
@PostMapping("/upload_screenshot")
|
||||
@Log(module = LogModuleEnum.MOBILE, value = ActionTypeEnum.SCREENSHOT)
|
||||
|
||||
Reference in New Issue
Block a user