bugfix:修复上传设备图片时前端读取不到设备id的问题,返回的设备信息id统一使用DeviceAdminVO

This commit is contained in:
BenjaminNH 2025-07-08 18:23:31 +08:00
parent 32315882b4
commit ce5a5c3bcb
2 changed files with 12 additions and 4 deletions

View File

@ -53,10 +53,10 @@ public class DeviceController {
@PreAuthorize("hasRole('DEVICE_ADMIN')")
@PostMapping("/{userId}")
public ResponseResult<Device> addDevice(@PathVariable("userId") Long userId,
public ResponseResult<DeviceAdminVO> addDevice(@PathVariable("userId") Long userId,
@RequestBody Device device) {
deviceService.addDevice(userId, device);
return ResponseResult.success(device);
return ResponseResult.success(new DeviceAdminVO(device));
}
@PreAuthorize("hasRole('DEVICE_ADMIN')")
@ -68,11 +68,11 @@ public class DeviceController {
@PreAuthorize("hasRole('DEVICE_ADMIN')")
@PutMapping("/{id}")
public ResponseResult<?> updateDevice(@PathVariable("id") Long id,
public ResponseResult<DeviceAdminVO> updateDevice(@PathVariable("id") Long id,
@RequestBody Device device) {
device.setId(id);
Device updatedDevice = deviceService.updateDevice(device);
return ResponseResult.success(updatedDevice);
return ResponseResult.success(new DeviceAdminVO(updatedDevice));
}
@PreAuthorize("hasRole('DEVICE_ADMIN')")

View File

@ -80,6 +80,14 @@ public class DeviceServiceImpl implements DeviceService {
@Override
public void deleteDevice(Long id) {
Device device = deviceMapper.selectById(id);
if (StringUtils.hasText(device.getImagePath())) {
Path fullPath = Paths.get(System.getProperty("user.dir"), device.getImagePath()).normalize();
File file = fullPath.toFile();
if (file.exists() && file.isFile()) {
file.delete();
}
}
deviceMapper.delete(new LambdaQueryWrapper<Device>()
.eq(Device::getId, id));
}