设备状态更新

This commit is contained in:
Flow 2025-06-12 16:50:39 +08:00
parent e21877486e
commit b6189d5d85
4 changed files with 36 additions and 2 deletions

View File

@ -97,4 +97,14 @@ public class DeviceController {
BeanUtils.toBean(list, DeviceRespVO.class));
}
@PutMapping("/updateDeviceStatus")
@Operation(summary = "根据设备ID更新设备状态")
@Parameter(name = "deviceid", description = "设备ID", required = true)
@Parameter(name = "devicestatus", description = "设备状态", required = true)
public CommonResult<Boolean> updateDeviceStatus(@RequestParam("devicecode") Integer devicecode,
@RequestParam("devicestatus") Integer devicestatus) {
deviceService.updateDeviceStatus(devicecode, devicestatus);
return success(true);
}
}

View File

@ -27,10 +27,10 @@ public class DeviceuserSaveReqVO {
private Integer userid;
@Schema(description = "创建时间")
private LocalDateTime createtime;
private String createtime;
@Schema(description = "更新时间")
private LocalDateTime updatetime;
private String updatetime;
@Schema(description = "创建人")
private String createby;

View File

@ -60,4 +60,12 @@ public interface DeviceService {
*/
PageResult<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO);
/**
* 根据设备ID更新设备状态
*
* @param devicecode 设备编号
* @param devicestatus 设备状态
*/
void updateDeviceStatus(Integer devicecode, Integer devicestatus);
}

View File

@ -81,4 +81,20 @@ public class DeviceServiceImpl implements DeviceService {
return deviceMapper.selectPage(pageReqVO);
}
@Override
public void updateDeviceStatus(Integer devicecode, Integer devicestatus) {
// 校验设备是否存在
DeviceDO device = deviceMapper.selectOne(DeviceDO::getDevicecode, devicecode);
if (device == null) {
throw exception(DEVICE_NOT_EXISTS);
}
// 更新设备状态
DeviceDO updateObj = new DeviceDO();
updateObj.setDevicestatus(devicestatus);
// 使用QueryWrapper构建更新条件
QueryWrapper<DeviceDO> wrapper = new QueryWrapper<>();
wrapper.eq("devicecode", devicecode);
deviceMapper.update(updateObj, wrapper);
}
}