feat: iot修改设备在线和离线
This commit is contained in:
+29
@@ -6,6 +6,8 @@ import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.device.model.AgeDevice;
|
||||
import com.central.device.model.dto.DeviceStatusDTO;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.central.device.model.excel.AgeDeviceExcel;
|
||||
import com.central.device.model.vo.AgeDeviceLocationVO;
|
||||
import com.central.device.service.IAgeDeviceService;
|
||||
@@ -26,6 +28,7 @@ import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -323,4 +326,30 @@ public class AgeDeviceController {
|
||||
return Result.failed("更新失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备状态(在线/离线)
|
||||
* deviceStatus: 0-在线,1-离线
|
||||
*/
|
||||
@Operation(summary = "修改设备状态")
|
||||
@PostMapping("/updateDeviceStatus")
|
||||
public Result updateDeviceStatus(@Validated @RequestBody DeviceStatusDTO dto) {
|
||||
try {
|
||||
log.info("修改设备状态,deviceSn: {}, deviceStatus: {}", dto.getDeviceSn(), dto.getDeviceStatus());
|
||||
|
||||
AgeDevice device = ageDeviceService.getByDeviceSn(dto.getDeviceSn());
|
||||
if (device == null) {
|
||||
return Result.failed("设备不存在");
|
||||
}
|
||||
|
||||
device.setBoundStatus(dto.getDeviceStatus());
|
||||
device.setBoundTime(new Date());
|
||||
boolean result = ageDeviceService.updateById(device);
|
||||
|
||||
return result ? Result.succeed("更新成功") : Result.failed("更新失败");
|
||||
} catch (Exception e) {
|
||||
log.error("修改设备状态失败", e);
|
||||
return Result.failed("更新失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class AgeDevice extends SuperEntity {
|
||||
private Date createTime;
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
private Long boundTime;
|
||||
private Date boundTime;
|
||||
private Integer boundStatus;
|
||||
private Long loginTime;
|
||||
private String deviceDesc;
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.central.device.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 修改设备状态DTO
|
||||
* deviceStatus: 0-在线,1-离线
|
||||
*/
|
||||
@Data
|
||||
public class DeviceStatusDTO {
|
||||
|
||||
/**
|
||||
* 设备SN
|
||||
*/
|
||||
@NotBlank(message = "设备SN不能为空")
|
||||
private String deviceSn;
|
||||
|
||||
/**
|
||||
* 设备状态(0-在线,1-离线)
|
||||
*/
|
||||
@NotNull(message = "设备状态不能为空")
|
||||
@Min(value = 0, message = "设备状态值无效,0-在线,1-离线")
|
||||
@Max(value = 1, message = "设备状态值无效,0-在线,1-离线")
|
||||
private Integer deviceStatus;
|
||||
}
|
||||
Reference in New Issue
Block a user