Commit 03683200 by 罗志长

feat: 设备上报故障处理

parent 3eb46154
......@@ -109,7 +109,7 @@ public class RedisConst {
public static final String ALARM_HEALTH_CONFIG_PREFIX = "alarm:config:device:id:";
public static final String PLAT_IOT_DEVICE_FAULT_STATE_PREFIX = "plat:iot:device:faultState:";
......
......@@ -123,4 +123,18 @@ public class IotDevicePropertiesOperateService extends IotCommonService {
}
return "";
}
public boolean changeDeviceFaultState(String deviceId, String state) {
String url = iotUrl + DEVICE_PREFIX_URL + deviceId + "/change/" + state;
HttpRequest request = buildRequest(url, "{}");
try {
ResponseMessage responseMessage = sendPost(url, request);
log.info("更改设备故障状态返回信息:{}", responseMessage.getMessage());
return responseMessage.getStatus() == 200;
} catch (IOException e) {
log.error("调用:{}接口异常:{}", url, e.getMessage());
return false;
}
}
}
......@@ -11,6 +11,7 @@ import com.makeit.dto.platform.device.*;
import com.makeit.dto.saas.device.PlatDeviceEditSaasDTO;
import com.makeit.dto.wechat.device.*;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.module.iot.vo.DeviceInfo;
import com.makeit.module.iot.vo.DeviceProperties;
import com.makeit.shengwang.agora.dto.PlatCallingDeviceDTO;
import com.makeit.shengwang.agora.vo.PlatAlarmCallDeviceVO;
......@@ -99,4 +100,9 @@ public interface PlatDeviceService extends IService<PlatDevice> {
void syncIotProperties(String deviceId, JSONObject iotProperties);
List<PlatDevice> listOffBed(String oriDeviceId);
/**
* 故障处理
*/
void handleFault(DeviceInfo deviceInfo);
}
......@@ -49,10 +49,7 @@ import com.makeit.module.iot.dto.UserServerInfo;
import com.makeit.module.iot.service.IotDevicePropertiesOperateService;
import com.makeit.module.iot.service.IotOrgService;
import com.makeit.module.iot.service.IotProductDeviceService;
import com.makeit.module.iot.vo.DeviceDetail;
import com.makeit.module.iot.vo.DeviceInstanceEntity;
import com.makeit.module.iot.vo.DeviceProperties;
import com.makeit.module.iot.vo.DeviceState;
import com.makeit.module.iot.vo.*;
import com.makeit.module.system.service.SysDictionaryCategoryService;
import com.makeit.module.system.vo.DictionaryVo;
import com.makeit.oss.AliyunOSSRepository;
......@@ -1181,4 +1178,34 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
public List<PlatDevice> listOffBed(String oriDeviceId) {
return list(Wrappers.<PlatDevice>lambdaQuery().eq(PlatDevice::getOriDeviceId, oriDeviceId));
}
@Override
public void handleFault(DeviceInfo deviceInfo) {
String deviceId = deviceInfo.getDeviceId();
JSONObject properties = deviceInfo.getProperties();
String faultState = properties.getString("radarHitch");
boolean isNormal = "normal".equals(faultState);
String key = RedisConst.PLAT_IOT_DEVICE_FAULT_STATE_PREFIX + deviceId;
String value = RedisUtil.get(key);
if (!isNormal) {
if (StringUtils.isBlank(value)) {
boolean isSuccess = devicePropertiesOperateService.changeDeviceFaultState(deviceId, "abnormal");
if (!isSuccess) {
return;
}
RedisUtil.set(key, faultState);
log.info("handleFault设置故障");
}
} else {
if (StringUtils.isNotBlank(value)) {
boolean isSuccess = devicePropertiesOperateService.changeDeviceFaultState(deviceId, "normal");
if (!isSuccess) {
return;
}
RedisUtil.delete(key);
log.info("handleFault恢复正常");
}
}
}
}
......@@ -122,6 +122,8 @@ public class PushCallback implements MqttCallbackExtended {
return;
}
handleFault(device);
CompletableFuture.runAsync(() -> {
checkAlarm(device);
}, taskExecutor);
......@@ -273,6 +275,18 @@ public class PushCallback implements MqttCallbackExtended {
}
/**
* 处理设备故障
*/
public void handleFault(DeviceInfo device) {
if (!REPORT_PROPERTY.equals(device.getMessageType())) {
return;
}
CompletableFuture.runAsync(() -> {
platDeviceService.handleFault(device);
});
}
/**
* 离床预警
* @param platDevice
* @param properties
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment