Compare commits

...

2 Commits

2 changed files with 12 additions and 4 deletions

View File

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

View File

@ -80,6 +80,14 @@ public class DeviceServiceImpl implements DeviceService {
@Override @Override
public void deleteDevice(Long id) { 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>() deviceMapper.delete(new LambdaQueryWrapper<Device>()
.eq(Device::getId, id)); .eq(Device::getId, id));
} }