新增管理员修改设备信息的代码 #138

Merged
hnu202326010106 merged 1 commits from wanglei_branch into develop 2 weeks ago

@ -236,4 +236,21 @@ public class DeviceController {
}
}
// ========== 新增:管理员编辑设备基本信息接口 ==========
@PutMapping("/edit")
@PreAuthorize("hasAnyRole('ADMIN', 'SUPER_ADMIN')") // 限制仅管理员/超级管理员可访问
@Operation(summary = "编辑设备基本信息", description = "管理员更新设备名称、类型、安装位置等基本信息(不含设备状态、创建时间)")
public ResponseEntity<ResultVO<Device>> editDevice(@Valid @RequestBody Device device) {
try {
// 校验设备ID不能为空编辑必须指定设备ID
if (device.getDeviceId() == null || device.getDeviceId().trim().isEmpty()) {
return ResponseEntity.ok(ResultVO.error(400, "设备ID不能为空"));
}
Device updatedDevice = deviceService.updateDeviceInfo(device);
return ResponseEntity.ok(ResultVO.success(updatedDevice, "设备信息编辑成功"));
} catch (Exception e) {
return ResponseEntity.ok(ResultVO.error(500, "设备信息编辑失败: " + e.getMessage()));
}
}
}

@ -61,10 +61,10 @@ public class DeviceService {
Device existingDevice = getDeviceById(device.getDeviceId());
// 保留创建时间,更新其他可编辑字段
existingDevice.setDeviceName(device.getDeviceName());
existingDevice.setDeviceType(device.getDeviceType());
existingDevice.setAreaId(device.getAreaId());
existingDevice.setInstallLocation(device.getInstallLocation());
existingDevice.setInstallDate(device.getInstallDate());
existingDevice.setParentMakerId(device.getParentMakerId());
return deviceRepository.save(existingDevice);
}

Loading…
Cancel
Save