Commit 8d51c0f7 sunke

设备状态独立

1 个父辈 d474006c
...@@ -29,6 +29,7 @@ import com.neotel.smfcore.core.system.service.manager.IHumitureManager; ...@@ -29,6 +29,7 @@ import com.neotel.smfcore.core.system.service.manager.IHumitureManager;
import com.neotel.smfcore.core.system.service.po.AlarmInfo; import com.neotel.smfcore.core.system.service.po.AlarmInfo;
import com.neotel.smfcore.core.system.service.po.DataLog; import com.neotel.smfcore.core.system.service.po.DataLog;
import com.neotel.smfcore.core.system.service.po.Humiture; import com.neotel.smfcore.core.system.service.po.Humiture;
import com.neotel.smfcore.core.system.util.DevicesStatusUtil;
import com.neotel.smfcore.core.system.util.TaskService; import com.neotel.smfcore.core.system.util.TaskService;
import com.neotel.smfcore.security.service.manager.IGroupManager; import com.neotel.smfcore.security.service.manager.IGroupManager;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -72,16 +73,6 @@ public class BaseDeviceHandler implements IDeviceHandler { ...@@ -72,16 +73,6 @@ public class BaseDeviceHandler implements IDeviceHandler {
protected IGroupManager groupManager; protected IGroupManager groupManager;
/** /**
* 状态 map,key为 cid value 为状态 Bean
*/
protected static Map<String, StatusBean> statusMap = Maps.newConcurrentMap();
/**
* CID的设备故障消息(key 为 cid)
*/
private static Map<String, StatusBean> clientMsgs = Maps.newConcurrentMap();
/**
* 权限验证API列表 * 权限验证API列表
*/ */
protected List<IOpAuthApi> opAuthApiList = Lists.newArrayList(); protected List<IOpAuthApi> opAuthApiList = Lists.newArrayList();
...@@ -291,7 +282,7 @@ public class BaseDeviceHandler implements IDeviceHandler { ...@@ -291,7 +282,7 @@ public class BaseDeviceHandler implements IDeviceHandler {
String storageCid = storage.getCid(); String storageCid = storage.getCid();
//先查找空闲 BOX同尺寸的,如果找不到,再查找可入库 BOX 同尺寸或比盘尺寸大的仓位 //先查找空闲 BOX同尺寸的,如果找不到,再查找可入库 BOX 同尺寸或比盘尺寸大的仓位
StatusBean statusBean = statusMap.get(storageCid); StatusBean statusBean = DevicesStatusUtil.getStatusBean(storageCid);
if (statusBean == null) {//当前料仓不可用 if (statusBean == null) {//当前料仓不可用
throw new ValidateException("error.storage.offline", new String[]{storageCid}, "料仓[ " + storageCid + "]离线"); throw new ValidateException("error.storage.offline", new String[]{storageCid}, "料仓[ " + storageCid + "]离线");
} }
...@@ -729,7 +720,7 @@ public class BaseDeviceHandler implements IDeviceHandler { ...@@ -729,7 +720,7 @@ public class BaseDeviceHandler implements IDeviceHandler {
//展示到界面 //展示到界面
String msg = statusBean.getMsg(); String msg = statusBean.getMsg();
String msgEn = statusBean.getMsgEn(); String msgEn = statusBean.getMsgEn();
updateClientMsg(statusBean.getCid(), msg, msgEn); DevicesStatusUtil.updateClientMsg(statusBean.getCid(), msg, msgEn);
} catch (Exception e) { } catch (Exception e) {
log.error("客户端故障消息处理出错", e); log.error("客户端故障消息处理出错", e);
} }
...@@ -737,20 +728,6 @@ public class BaseDeviceHandler implements IDeviceHandler { ...@@ -737,20 +728,6 @@ public class BaseDeviceHandler implements IDeviceHandler {
/** /**
* 更新客户端发上来的消息(设备故障等消息)
*/
protected static void updateClientMsg(String cid, String clientMsg, String clientMsgEn) {
if (clientMsg == null) {
clientMsg = "";
clientMsgEn = "";
}
StatusBean statusBean = new StatusBean();
statusBean.setMsg(clientMsg);
statusBean.setMsgEn(clientMsgEn);
clientMsgs.put(cid, statusBean);
}
/**
* 更新状态,保存温湿度和报警信息 * 更新状态,保存温湿度和报警信息
* *
* @param statusBeanToSave * @param statusBeanToSave
...@@ -758,7 +735,7 @@ public class BaseDeviceHandler implements IDeviceHandler { ...@@ -758,7 +735,7 @@ public class BaseDeviceHandler implements IDeviceHandler {
*/ */
protected StatusBean saveAlarmAndHumidity(StatusBean statusBeanToSave) { protected StatusBean saveAlarmAndHumidity(StatusBean statusBeanToSave) {
String cid = statusBeanToSave.getCid(); String cid = statusBeanToSave.getCid();
StatusBean statusBean = statusMap.get(cid); StatusBean statusBean = DevicesStatusUtil.getStatusBean(cid);
boolean needSaveToMongo = false; boolean needSaveToMongo = false;
if (statusBean == null) { if (statusBean == null) {
statusBean = statusBeanToSave; statusBean = statusBeanToSave;
...@@ -807,7 +784,7 @@ public class BaseDeviceHandler implements IDeviceHandler { ...@@ -807,7 +784,7 @@ public class BaseDeviceHandler implements IDeviceHandler {
} }
} }
statusMap.put(cid, statusBean); DevicesStatusUtil.updateStatusBean(statusBean);
//清空 msg 的内容,因为客户端会据此决定命令是否执行 //清空 msg 的内容,因为客户端会据此决定命令是否执行
statusBean.setMsg(""); statusBean.setMsg("");
......
package com.neotel.smfcore.core.system.util;
import com.google.common.collect.Maps;
import com.neotel.smfcore.core.device.bean.StatusBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* Created by sunke on 2021/8/4.
*/
@Slf4j
public class DevicesStatusUtil {
/**
* 状态 map,key为 cid value 为状态 Bean
*/
protected static Map<String, StatusBean> statusMap = Maps.newConcurrentMap();
/**
* CID的设备故障消息(key 为 cid)
*/
private static Map<String, StatusBean> clientMsgs = Maps.newConcurrentMap();
/**
* 获取设备状态Bean
*/
public static StatusBean getStatusBean(String cid){
return statusMap.get(cid);
}
/**
* 更新设备状态信息
*/
public static void updateStatusBean(StatusBean statusBean){
statusMap.put(statusBean.getCid(),statusBean);
}
/**
* 更新客户端发上来的消息(设备故障等消息)
*/
public static StatusBean updateClientMsg(String cid, String clientMsg, String clientMsgEn) {
if (clientMsg == null) {
clientMsg = "";
clientMsgEn = "";
}
StatusBean statusBean = new StatusBean();
statusBean.setMsg(clientMsg);
statusBean.setMsgEn(clientMsgEn);
clientMsgs.put(cid, statusBean);
return statusBean;
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!