Commit 4d419695 LN

设备定时通信消息结构更改,消息改为集合

1 个父辈 eba8d243
package com.neotel.smfcore.core.device.bean;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MsgInfo implements Serializable {
public MsgInfo(String msg,String type){
this.msg=msg;
this.type=type;
}
/**
* 提示消息
*/
private String msg = "";
/**
* 消息类型,INFO,WARNING,ERROR,DATA
*/
private String type;
/**
* 英文提示消息
*/
private String msgEn = "";
private String msgJp="";
/**
* 翻译key
*/
private String msgKey="";
/**
* 翻译参数
*/
private String[] msgParam ;
/**
* 报警类型
*/
private String alarmType="";
/**
*报警错误码
*/
private String alarmCode="";
}
...@@ -79,6 +79,9 @@ public class StatusBean { ...@@ -79,6 +79,9 @@ public class StatusBean {
public String msgJp=""; public String msgJp="";
/**
* 翻译key
*/
public String msgCode=""; public String msgCode="";
public String[] msgParam ; public String[] msgParam ;
...@@ -112,6 +115,10 @@ public class StatusBean { ...@@ -112,6 +115,10 @@ public class StatusBean {
*/ */
public String language=""; public String language="";
/** /**
* 消息集合
*/
public List<MsgInfo> msgList;
/**
* 料仓类型 * 料仓类型
*/ */
private String deviceType = DeviceType.AUTO.name(); private String deviceType = DeviceType.AUTO.name();
...@@ -536,75 +543,174 @@ public class StatusBean { ...@@ -536,75 +543,174 @@ public class StatusBean {
} }
return doorReelSignal; return doorReelSignal;
} }
//
// public String getShowMsg(Locale locale) {
// if(ObjectUtil.isEmpty(this.msg)){
// return "";
// }
// //从收到数据中查找
// String lan = locale.toLanguageTag();
// if (lan.equals(MessageUtils.JA_JP) && ObjectUtil.isNotEmpty(getMsgJp())) {
// String resultMsg= getMsgJp().replace("A=","").replace("I=","").replace("W=","");
// return resultMsg;
// } else if (lan.equals(MessageUtils.EN_US) && ObjectUtil.isNotEmpty(getMsgEn())) {
// String resultMsg= getMsgEn().replace("A=","").replace("I=","").replace("W=","");
// return resultMsg;
// }
// //提示信息国际化
// if (ObjectUtil.isEmpty(getMsgCode())) {
// return this.msg.replace("A=","").replace("I=","").replace("W=","");
// } else {
// String code = this.msgCode;
// if (!code.startsWith(MessageUtils.smfcore)) {
// code = MessageUtils.smfcore + "." + this.msgCode;
// }
// String newMsg=this.msg.replace("A=","").replace("I=","").replace("W=","");
// newMsg = MessageUtils.getText(code, getMsgParam(), locale, newMsg);
// return newMsg;
// }
// }
//
// public String getErrorMsg(Locale locale) {
// if(ObjectUtil.isEmpty(this.msg)){
// return "";
// }
//
// //判断是否有换行
// String[] msgArray=this.msg.split("\r\n");
// if(msgArray.length>0) {
// for (String msg :
// msgArray) {
// String msgType = MessageType.ERROR.name();
// if (msg.startsWith("A=")) {
// msgType = MessageType.ERROR.name();
// msg = msg.substring(2);
// } else if (msg.startsWith("I=")) {
// msgType = MessageType.INFO.name();
// msg = msg.substring(2);
// } else if (msg.startsWith("W=")) {
// msgType = MessageType.WARNING.name();
// msg = msg.substring(2);
// }
// if(msgType.equals(MessageType.ERROR.name())){
// return msg;
// }
// }
// }
// return "";
// }
//
// public Map<String,String> getMsgMap() {
// Map<String,String> resultMap=new HashMap<>();
// if(ObjectUtil.isEmpty(this.msg)){
// return resultMap;
// }
//
// //判断是否有换行
// String[] msgArray=this.msg.split("\r\n");
// if(msgArray.length>0) {
// for (String msg :
// msgArray) {
// if(ObjectUtil.isEmpty(msg)){
// continue;
// }
// String msgType = MessageType.ERROR.name();
// if (msg.startsWith("A=")) {
// msgType = MessageType.ERROR.name();
// msg = msg.substring(2);
// } else if (msg.startsWith("I=")) {
// msgType = MessageType.INFO.name();
// msg = msg.substring(2);
// } else if (msg.startsWith("W=")) {
// msgType = MessageType.WARNING.name();
// msg = msg.substring(2);
// }
// resultMap.put(msg,msgType);
// }
// }
// return resultMap;
// }
public String getShowMsg(Locale locale) { private String GetMsgStr(MsgInfo msg,Locale locale){
if(ObjectUtil.isEmpty(this.msg)){ String mMsg = "";
return "";
}
//从收到数据中查找 //从收到数据中查找
String lan = locale.toLanguageTag(); String lan = locale.toLanguageTag();
if (lan.equals(MessageUtils.JA_JP) && ObjectUtil.isNotEmpty(getMsgJp())) { if (lan.equals(MessageUtils.JA_JP) && ObjectUtil.isNotEmpty(msg.getMsgJp())) {
String resultMsg= getMsgJp().replace("A=","").replace("I=","").replace("W=",""); mMsg = msg.getMsgJp();
return resultMsg; } else if (lan.equals(MessageUtils.EN_US) && ObjectUtil.isNotEmpty(msg.getMsgEn())) {
} else if (lan.equals(MessageUtils.EN_US) && ObjectUtil.isNotEmpty(getMsgEn())) { mMsg = msg.getMsgEn();
String resultMsg= getMsgEn().replace("A=","").replace("I=","").replace("W=","");
return resultMsg;
} }
//提示信息国际化 //提示信息国际化
if (ObjectUtil.isEmpty(getMsgCode())) { else if (ObjectUtil.isEmpty(msg.getMsgKey())) {
return this.msg.replace("A=","").replace("I=","").replace("W=",""); mMsg = msg.getMsg();
} else { } else {
String code = this.msgCode; String code = msg.getMsgKey();
if (!code.startsWith(MessageUtils.smfcore)) { if (!code.startsWith(MessageUtils.smfcore)) {
code = MessageUtils.smfcore + "." + this.msgCode; code = MessageUtils.smfcore + "." + msg.getMsgKey();
} }
String newMsg=this.msg.replace("A=","").replace("I=","").replace("W=",""); String newMsg = msg.getMsg().replace("A=", "").replace("I=", "").replace("W=", "");
newMsg = MessageUtils.getText(code, getMsgParam(), locale, newMsg); mMsg = MessageUtils.getText(code, msg.getMsgParam(), locale, newMsg);
return newMsg;
} }
return mMsg;
} }
public String getErrorMsg(Locale locale) { public String getShowMsg(Locale locale) {
if(ObjectUtil.isEmpty(this.msg)){ if (ObjectUtil.isEmpty(this.msgList)) {
return ""; return "";
} }
String returnMsg = "";
//判断是否有换行 for (MsgInfo msg :
String[] msgArray=this.msg.split("\r\n"); msgList) {
if(msgArray.length>0) { String mMsg = GetMsgStr(msg,locale);
for (String msg : if (ObjectUtil.isEmpty(returnMsg)) {
msgArray) { returnMsg = mMsg;
String msgType = MessageType.ERROR.name(); } else {
if (msg.startsWith("A=")) { returnMsg += "\r\n" + mMsg;
msgType = MessageType.ERROR.name(); }
msg = msg.substring(2); }
} else if (msg.startsWith("I=")) { return returnMsg;
msgType = MessageType.INFO.name();
msg = msg.substring(2);
} else if (msg.startsWith("W=")) {
msgType = MessageType.WARNING.name();
msg = msg.substring(2);
} }
if(msgType.equals(MessageType.ERROR.name())){
return msg; public String getErrorMsg(Locale locale) {
if (ObjectUtil.isEmpty(this.msgList)) {
return "";
} }
for (MsgInfo msg :
msgList) {
if (msg.getType().toUpperCase().equals(MessageType.ERROR.name())) {
return msg.getMsg();
} }
} }
return ""; return "";
} }
public Map<String,String> getMsgMap() { public Map<String,String> getMsgMap(Locale locale) {
Map<String,String> resultMap=new HashMap<>(); Map<String, String> resultMap = new HashMap<>();
if(ObjectUtil.isEmpty(this.msg)){ if (ObjectUtil.isEmpty(msgList)) {
return resultMap;
}
//判断是否有换行
for (MsgInfo msg : msgList) {
resultMap.put(GetMsgStr(msg,locale) , msg.getType());
}
return resultMap; return resultMap;
} }
public void MsgDataProcess() {
//消息格式处理
if( getMsgList()==null&& ObjectUtil.isNotEmpty(msg)){
msgList=new ArrayList<>();
//判断是否有换行 //判断是否有换行
String[] msgArray=this.msg.split("\r\n"); String[] msgArray=this.msg.split("\r\n");
if(msgArray.length>0) { if(msgArray.length>0) {
for (String msg : for (String msg :
msgArray) { msgArray) {
if(ObjectUtil.isEmpty(msg)){ if (ObjectUtil.isEmpty(msg)) {
continue; continue;
} }
String msgType = MessageType.ERROR.name(); String msgType = MessageType.ERROR.name();
...@@ -618,10 +724,15 @@ public class StatusBean { ...@@ -618,10 +724,15 @@ public class StatusBean {
msgType = MessageType.WARNING.name(); msgType = MessageType.WARNING.name();
msg = msg.substring(2); msg = msg.substring(2);
} }
resultMap.put(msg,msgType);
if (msgArray.length == 1) {
msgList.add(new MsgInfo(msg, msgType,msgEn,msgJp,msgCode,msgParam,"",""));
} else {
msgList.add(new MsgInfo(msg, msgType));
}
}
} }
} }
return resultMap;
} }
public void setRMsg(String msgKey, String[] msgParam, String message) { public void setRMsg(String msgKey, String[] msgParam, String message) {
......
...@@ -843,25 +843,39 @@ public class BaseDeviceHandler implements IDeviceHandler { ...@@ -843,25 +843,39 @@ public class BaseDeviceHandler implements IDeviceHandler {
protected void handleMsg(StatusBean statusBean) { protected void handleMsg(StatusBean statusBean) {
try { try {
//转换为新格式
statusBean.MsgDataProcess();
//判断是否刚刚上线 //判断是否刚刚上线
StatusBean bean = DevicesStatusUtil.getStatusBean(statusBean.getCid()); StatusBean bean = DevicesStatusUtil.getStatusBean(statusBean.getCid());
if (bean == null || bean.getBoxStatus() == null) { if (bean == null || bean.getBoxStatus() == null) {
DeviceMessageUtil.addOnlineMessage(statusBean.getCid(), "",statusBean.getClientIp()); DeviceMessageUtil.addOnlineMessage(statusBean.getCid(), "",statusBean.getClientIp());
DevicesStatusUtil.updateClientMsg(statusBean.getCid(), "", "", "","", null); DevicesStatusUtil.updateClientMsg(statusBean.getCid(),new ArrayList<>());
} else if (bean.timeOut() && (bean.getOfflineTime() > -1)) { } else if (bean.timeOut() && (bean.getOfflineTime() > -1)) {
DeviceMessageUtil.addOnlineMessage(statusBean.getCid(), "",statusBean.getClientIp()); DeviceMessageUtil.addOnlineMessage(statusBean.getCid(), "",statusBean.getClientIp());
DevicesStatusUtil.updateClientMsg(statusBean.getCid(), "", "", "","", null); DevicesStatusUtil.updateClientMsg(statusBean.getCid(), new ArrayList<>());
} }
if(ObjectUtil.isNotEmpty(statusBean.msgList)&& statusBean.msgList.size()>0) {
//展示到界面 DevicesStatusUtil.updateClientMsg(statusBean.getCid(), statusBean.msgList);
String msg = statusBean.getMsg(); }
String msgEn = statusBean.getMsgEn(); // //判断是否刚刚上线
String msgCode = statusBean.getMsgCode(); // StatusBean bean = DevicesStatusUtil.getStatusBean(statusBean.getCid());
String msgJp=statusBean.getMsgJp(); // if (bean == null || bean.getBoxStatus() == null) {
// DeviceMessageUtil.addOnlineMessage(statusBean.getCid(), "",statusBean.getClientIp());
if(ObjectUtil.isNotEmpty(msg)||ObjectUtil.isNotEmpty(msgCode)) { // DevicesStatusUtil.updateClientMsg(statusBean.getCid(), "", "", "","", null);
DevicesStatusUtil.updateClientMsg(statusBean.getCid(), msgCode, msg, msgEn, msgJp,statusBean.getMsgParam()); // } else if (bean.timeOut() && (bean.getOfflineTime() > -1)) {
} // DeviceMessageUtil.addOnlineMessage(statusBean.getCid(), "",statusBean.getClientIp());
// DevicesStatusUtil.updateClientMsg(statusBean.getCid(), "", "", "","", null);
// }
//
// //展示到界面
// String msg = statusBean.getMsg();
// String msgEn = statusBean.getMsgEn();
// String msgCode = statusBean.getMsgCode();
// String msgJp=statusBean.getMsgJp();
//
// if(ObjectUtil.isNotEmpty(msg)||ObjectUtil.isNotEmpty(msgCode)) {
// DevicesStatusUtil.updateClientMsg(statusBean.getCid(), msgCode, msg, msgEn, msgJp,statusBean.getMsgParam());
// }
} catch (Exception e) { } catch (Exception e) {
log.error("客户端故障消息处理出错", e); log.error("客户端故障消息处理出错", e);
} }
......
...@@ -63,13 +63,23 @@ public class MessageUtils { ...@@ -63,13 +63,23 @@ public class MessageUtils {
private static Map<String,Map<String, LanguageMsg>> msgMap = new HashMap<>(); private static Map<String,Map<String, LanguageMsg>> msgMap = new HashMap<>();
private static ILanguageMsgManager languageMsgManager;
private static DataCache dataCache;
private static LanguageMsgService messageService;
@Autowired @Autowired
ILanguageMsgManager languageMsgManager; void setLanguageMsgManager(ILanguageMsgManager languageMsgManager) {
@Autowired MessageUtils.languageMsgManager = languageMsgManager;
DataCache dataCache; }
@Autowired @Autowired
LanguageMsgService messageService; void SetDataCache(DataCache dataCache) {
MessageUtils.dataCache = dataCache;
}
@Autowired
void SetMessageService(LanguageMsgService messageService) {
MessageUtils.messageService = messageService;
}
public static final String ZH_CN = "zh-CN"; public static final String ZH_CN = "zh-CN";
public static final String ZH_TW = "zh-TW"; public static final String ZH_TW = "zh-TW";
...@@ -157,6 +167,7 @@ public class MessageUtils { ...@@ -157,6 +167,7 @@ public class MessageUtils {
return msg.getMsg(); return msg.getMsg();
} }
log.info("获取资源[" + msgKey + "][" + defaultMsg + "][" + lanType + "]失败:未找到code[" + msgKey + "]"); log.info("获取资源[" + msgKey + "][" + defaultMsg + "][" + lanType + "]失败:未找到code[" + msgKey + "]");
// autoAddMsg(msgKey,defaultMsg,"");
} }
return defaultMsg; return defaultMsg;
} }
...@@ -224,6 +235,23 @@ public class MessageUtils { ...@@ -224,6 +235,23 @@ public class MessageUtils {
return lanList; return lanList;
} }
private static void autoAddMsg(String msgKey, String defaultMsg,String type ) {
try {
if (ObjectUtil.isEmpty(type)) {
type = smfcore;
}
LanguageMsg languageMsg = new LanguageMsg(msgKey, defaultMsg, type);
List<LanguageInfo> list=dataCache.getLanguageList();
for (LanguageInfo lan:list
) {
languageMsg.setContent(lan.getLanCode(),defaultMsg);
}
languageMsg = languageMsgManager.save(languageMsg);
updateMsg(languageMsg);
log.info("autoAddMsg: key=" + msgKey + ",msg=" + defaultMsg + ",type=" + type + ",defLocal=" + getDefaultLocal().toLanguageTag() + "");
} catch (Exception ex) {
log.error("autoAddMsg: key=" + msgKey + ",msg=" + defaultMsg + ",type=" + type + ",defLocal=" + getDefaultLocal().toLanguageTag() + "出错:" + ex.toString());
}
}
} }
...@@ -22,13 +22,20 @@ import java.util.Locale; ...@@ -22,13 +22,20 @@ import java.util.Locale;
@AllArgsConstructor @AllArgsConstructor
public class Message extends BasePo implements Serializable { public class Message extends BasePo implements Serializable {
public static Message newMsg(MessageType type,String deviceName,String deviceId,String module,String msgCode,String msg,String[] msgParams){ public static Message newMsg(MessageType type,String deviceName,String deviceId,String module,String msgCode,String msg,String[] msgParams){
Message message=new Message(deviceName,deviceId,module, type.name(),msgCode,msg,msgParams,null,null,""); Message message=new Message(deviceName,deviceId,module, type.name(),msgCode,msg,msgParams,null,null,"",msgCode,"");
return message; return message;
} }
public static Message newMsg(String type,String deviceName,String deviceId,String module,String msgCode,String msg,String[] msgParams){ public static Message newMsg(String type,String deviceName,String deviceId,String module,String msgCode,String msg,String[] msgParams){
Message message=new Message(deviceName,deviceId,module, type,msgCode,msg,msgParams,null,null,""); Message message=new Message(deviceName,deviceId,module, type,msgCode,msg,msgParams,null,null,"",msgCode,"");
return message;
}
public static Message newMsg(MessageType type,String deviceName,String deviceId,String module,String msgCode,String msg,String[] msgParams,String alarmType,String alarmCode){
Message message=new Message(deviceName,deviceId,module, type.name(),msgCode,msg,msgParams,null,null,"",alarmType,alarmCode);
return message;
}
public static Message newMsg(String type,String deviceName,String deviceId,String module,String msgCode,String msg,String[] msgParams,String alarmType,String alarmCode){
Message message=new Message(deviceName,deviceId,module, type,msgCode,msg,msgParams,null,null,"",alarmType,alarmCode);
return message; return message;
} }
/** /**
...@@ -75,6 +82,14 @@ public class Message extends BasePo implements Serializable { ...@@ -75,6 +82,14 @@ public class Message extends BasePo implements Serializable {
*/ */
private String operator; private String operator;
/**
* 报警类型
*/
public String alarmType="";
/**
*报警错误码
*/
public String alarmCode="";
public void addData(String key,String value){ public void addData(String key,String value){
if(dataList==null){ if(dataList==null){
dataList=new ArrayList<>(); dataList=new ArrayList<>();
......
...@@ -96,6 +96,20 @@ public class DeviceMessageUtil { ...@@ -96,6 +96,20 @@ public class DeviceMessageUtil {
messageManager.save(message); messageManager.save(message);
} }
} }
public static void addDeviceMessage(String cid,String msgType, String moudle, String msgCode, String msg, String[] msgParam,String almType,String almCode) {
DeviceInfo deviceInfo=getDeviceName(cid);
if (deviceInfo!=null) {
String code=msgCode;
if(ObjectUtil.isNotEmpty(msgCode)){
if(!msgCode.startsWith(MessageUtils.smfcore)){
code=MessageUtils.smfcore+"."+msgCode;
}
}
Message message=Message.newMsg(msgType ,deviceInfo.getName(), deviceInfo.getId(), moudle, code,msg,msgParam,almType,almCode);
messageManager.save(message);
}
}
public static void addOnlineMessage(String cid, String moudle,String ip) { public static void addOnlineMessage(String cid, String moudle,String ip) {
DeviceInfo deviceInfo=getDeviceName(cid); DeviceInfo deviceInfo=getDeviceName(cid);
......
...@@ -3,6 +3,7 @@ package com.neotel.smfcore.core.system.util; ...@@ -3,6 +3,7 @@ package com.neotel.smfcore.core.system.util;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.neotel.smfcore.common.utils.SecurityUtils; import com.neotel.smfcore.common.utils.SecurityUtils;
import com.neotel.smfcore.core.device.bean.MsgInfo;
import com.neotel.smfcore.core.device.bean.StatusBean; import com.neotel.smfcore.core.device.bean.StatusBean;
import com.neotel.smfcore.core.message.enums.MessageType; import com.neotel.smfcore.core.message.enums.MessageType;
import com.neotel.smfcore.core.message.util.DeviceMessageUtil; import com.neotel.smfcore.core.message.util.DeviceMessageUtil;
...@@ -44,6 +45,7 @@ public class DevicesStatusUtil { ...@@ -44,6 +45,7 @@ public class DevicesStatusUtil {
statusBean.setMsgCode(msgBean.getMsgCode()); statusBean.setMsgCode(msgBean.getMsgCode());
statusBean.setMsgParam(msgBean.getMsgParam()); statusBean.setMsgParam(msgBean.getMsgParam());
statusBean.setMsgJp(msgBean.getMsgJp()); statusBean.setMsgJp(msgBean.getMsgJp());
statusBean.setMsgList(msgBean.getMsgList());
} }
} }
return statusBean; return statusBean;
...@@ -55,75 +57,111 @@ public class DevicesStatusUtil { ...@@ -55,75 +57,111 @@ public class DevicesStatusUtil {
public static void updateStatusBean(StatusBean statusBean) { public static void updateStatusBean(StatusBean statusBean) {
statusMap.put(statusBean.getCid(), statusBean); statusMap.put(statusBean.getCid(), statusBean);
} }
//
// /**
// * 更新客户端发上来的消息(设备故障等消息)
// */
// public static StatusBean updateClientMsg(String cid,String msgCode, String clientMsg, String clientMsgEn,String clientMsgJp,String[] msgParam) {
// if (clientMsg == null) {
// clientMsg = "";
// clientMsgEn = "";
// clientMsgJp="";
// }
// if(msgCode==null){
// msgCode="";
// }
// if(clientMsg==null){
// clientMsg="";
// }
// //判断消息是否有内容
// if(ObjectUtil.isNotEmpty(msgCode)||ObjectUtil.isNotEmpty(clientMsg)){
// boolean newMsg=true;
// //和上个消息是否一样
// StatusBean msgBean=clientMsgs.get(cid);
// if(msgBean!=null) {
//// if (msgBean.msgTimeOut()) {
//// newMsg = true;
//// } else
// if (msgBean.getMsgCode().equals(msgCode) && msgBean.getMsg().equals(clientMsg)) {
// newMsg = false;
// }
// }
// if(newMsg){
//
// //判断是否有换行
// String[] msgArray=clientMsg.split("\r\n");
// if(msgArray!=null&& msgArray.length>0) {
// for (String msg :
// msgArray) {
// String msgType = MessageType.ERROR.name();
// if (msg.startsWith("A=")) {
// msgType = MessageType.ERROR.name();
// msg = msg.substring(2);
// } else if (msg.startsWith("I=")) {
// msgType = MessageType.INFO.name();
// msg = msg.substring(2);
// } else if (msg.startsWith("W=")) {
// msgType = MessageType.WARNING.name();
// msg = msg.substring(2);
// }
// DeviceMessageUtil.addDeviceMessage(cid, msgType, "", msgCode, msg, msgParam);
// }
// }
// else {
// DeviceMessageUtil.addDeviceMessage(cid, MessageType.ERROR.name(), "", msgCode, clientMsg, msgParam);
// }
// }
// }
//
// StatusBean statusBean = new StatusBean();
// statusBean.setCid(cid);
// statusBean.setTime(System.currentTimeMillis());
// statusBean.setMsg(clientMsg);
// statusBean.setMsgEn(clientMsgEn);
// statusBean.setMsgCode(msgCode);
// statusBean.setMsgParam(msgParam);
// statusBean.setMsgJp(clientMsgJp);
// clientMsgs.put(cid, statusBean);
// return statusBean;
// }
/** /**
* 更新客户端发上来的消息(设备故障等消息) * 更新客户端发上来的消息(设备故障等消息)
*/ */
public static StatusBean updateClientMsg(String cid,String msgCode, String clientMsg, String clientMsgEn,String clientMsgJp,String[] msgParam) { public static StatusBean updateClientMsg(String cid, List<MsgInfo> msgs) {
if (clientMsg == null) {
clientMsg = "";
clientMsgEn = "";
clientMsgJp="";
}
if(msgCode==null){
msgCode="";
}
if(clientMsg==null){
clientMsg="";
}
//判断消息是否有内容 //判断消息是否有内容
if(ObjectUtil.isNotEmpty(msgCode)||ObjectUtil.isNotEmpty(clientMsg)){ if (msgs != null && msgs.size() > 0) {
boolean newMsg=true;
//和上个消息是否一样
StatusBean msgBean=clientMsgs.get(cid);
if(msgBean!=null) {
// if (msgBean.msgTimeOut()) {
// newMsg = true;
// } else
if (msgBean.getMsgCode().equals(msgCode) && msgBean.getMsg().equals(clientMsg)) {
newMsg = false;
}
}
if(newMsg){
//判断是否有换行 StatusBean msgBean = clientMsgs.get(cid);
String[] msgArray=clientMsg.split("\r\n"); List<MsgInfo> oldMsgs = msgBean.getMsgList();
if(msgArray!=null&& msgArray.length>0) { for (MsgInfo msg :
for (String msg : msgs) {
msgArray) { boolean newMsg = true;
String msgType = MessageType.ERROR.name();
if (msg.startsWith("A=")) { if (oldMsgs != null) {
msgType = MessageType.ERROR.name(); for (MsgInfo old :
msg = msg.substring(2); oldMsgs) {
} else if (msg.startsWith("I=")) { if (old.getMsgKey().equals(msg.getMsgKey()) && old.getMsg().equals(msg.getMsg())) {
msgType = MessageType.INFO.name(); newMsg = false;
msg = msg.substring(2); break;
} else if (msg.startsWith("W=")) {
msgType = MessageType.WARNING.name();
msg = msg.substring(2);
} }
DeviceMessageUtil.addDeviceMessage(cid, msgType, "", msgCode, msg, msgParam);
} }
} }
else { if (newMsg) {
DeviceMessageUtil.addDeviceMessage(cid, MessageType.ERROR.name(), "", msgCode, clientMsg, msgParam); DeviceMessageUtil.addDeviceMessage(cid, MessageType.ERROR.name(), "", msg.getMsgKey(), msg.getMsg(), msg.getMsgParam(),msg.getAlarmType(),msg.getAlarmCode());
} }
} }
} }
StatusBean statusBean = new StatusBean(); StatusBean statusBean = new StatusBean();
statusBean.setCid(cid); statusBean.setCid(cid);
statusBean.setTime(System.currentTimeMillis()); statusBean.setTime(System.currentTimeMillis());
statusBean.setMsg(clientMsg); statusBean.setMsgList(msgs);
statusBean.setMsgEn(clientMsgEn);
statusBean.setMsgCode(msgCode);
statusBean.setMsgParam(msgParam);
statusBean.setMsgJp(clientMsgJp);
clientMsgs.put(cid, statusBean); clientMsgs.put(cid, statusBean);
return statusBean; return statusBean;
} }
/** /**
* 主要用来存储感应料架库位报警信息 * 主要用来存储感应料架库位报警信息
*/ */
......
...@@ -8,6 +8,7 @@ import com.neotel.smfcore.core.device.bean.BoxStatusBean; ...@@ -8,6 +8,7 @@ import com.neotel.smfcore.core.device.bean.BoxStatusBean;
import com.neotel.smfcore.core.device.bean.StatusBean; import com.neotel.smfcore.core.device.bean.StatusBean;
import com.neotel.smfcore.core.device.enums.OP_STATUS; import com.neotel.smfcore.core.device.enums.OP_STATUS;
import com.neotel.smfcore.core.device.util.DataCache; import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.language.util.MessageUtils;
import com.neotel.smfcore.core.message.enums.MessageType; import com.neotel.smfcore.core.message.enums.MessageType;
import com.neotel.smfcore.core.report.bean.ChartItem; import com.neotel.smfcore.core.report.bean.ChartItem;
import com.neotel.smfcore.core.storage.bean.UsageItem; import com.neotel.smfcore.core.storage.bean.UsageItem;
...@@ -109,10 +110,18 @@ public class MicronStatusController { ...@@ -109,10 +110,18 @@ public class MicronStatusController {
} }
//料仓状态 //料仓状态
List<String> boxList = new ArrayList<>(); List<String> boxList = new ArrayList<>();
for (int i = 1; i <= 8; i++ // for (int i = 1; i <= 8; i++
) { // ) {
boxList.add("M" + i); // boxList.add("M" + i);
} // }
boxList.add("KTS-R001A");
boxList.add("KTS-R001B");
boxList.add("KTS-R001C");
boxList.add("KTS-R001D");
boxList.add("KTS-R002A");
boxList.add("KTS-R002B");
boxList.add("KTS-R002C");
boxList.add("KTS-R002D");
// SBDH1, SBDH2, SBDH3, SBSH1, SBSH2 // SBDH1, SBDH2, SBDH3, SBSH1, SBSH2
boxList.add("SBDH1-1"); boxList.add("SBDH1-1");
boxList.add("SBDH1-2"); boxList.add("SBDH1-2");
...@@ -156,7 +165,6 @@ public class MicronStatusController { ...@@ -156,7 +165,6 @@ public class MicronStatusController {
dto.getMsgList().add(dtoMsg); dto.getMsgList().add(dtoMsg);
// } // }
} }
return dto; return dto;
} }
...@@ -165,9 +173,9 @@ public class MicronStatusController { ...@@ -165,9 +173,9 @@ public class MicronStatusController {
Map<String, Storage> allStorages = dataCache.getAllStorage(); Map<String, Storage> allStorages = dataCache.getAllStorage();
for (Storage storage : for (Storage storage :
allStorages.values()) { allStorages.values()) {
if (storage.getCid().contains(boxName)) { if (storage.getCid().contains(boxName.trim())) {
cids.add(storage.getCid()); cids.add(storage.getCid());
}else if(storage.getName().equals(boxName)){ }else if(storage.getName().trim().equals(boxName.trim())){
cids.add(storage.getCid()); cids.add(storage.getCid());
} }
} }
...@@ -213,12 +221,17 @@ public class MicronStatusController { ...@@ -213,12 +221,17 @@ public class MicronStatusController {
else if(dto.getStatus()==0) { else if(dto.getStatus()==0) {
dto.setStatus(1); dto.setStatus(1);
} }
Map<String,String> msgMap=s.getMsgMap(); Map<String,String> msgMap=s.getMsgMap(locale);
if(msgMap!=null&&msgMap.size()>0) { if(msgMap!=null&&msgMap.size()>0) {
String name=cid;
Storage storage=dataCache.getStorage(cid);
if(storage!=null){
name=storage.getName();
}
for (String msg : for (String msg :
msgMap.keySet()) { msgMap.keySet()) {
String type= msgMap.getOrDefault(msg, ""); String type= msgMap.getOrDefault(msg, "");
dto.getMsgList().add(new EquipMsg(cid, s.getStatus(), msg, new Date(s.getTime()), type.toUpperCase(), "", "", new String[]{})); dto.getMsgList().add(new EquipMsg(name, s.getStatus(), msg, new Date(s.getTime()), type.toUpperCase(), "", "", new String[]{}));
} }
} }
// String msg=s.getErrorMsg(locale); // String msg=s.getErrorMsg(locale);
...@@ -245,6 +258,7 @@ public class MicronStatusController { ...@@ -245,6 +258,7 @@ public class MicronStatusController {
for (String cid : for (String cid :
cids) { cids) {
Storage storage = dataCache.getStorage(cid); Storage storage = dataCache.getStorage(cid);
String name=storage.getName();
for (UsageItem item : storage.getUsageMap().values() for (UsageItem item : storage.getUsageMap().values()
) { ) {
useCount += item.getUsedCount(); useCount += item.getUsedCount();
...@@ -259,14 +273,14 @@ public class MicronStatusController { ...@@ -259,14 +273,14 @@ public class MicronStatusController {
dto.setHumidity(humidity); dto.setHumidity(humidity);
dto.setTemperature(temperature); dto.setTemperature(temperature);
} }
dto.getStatuMap().put(cid, boxStatus.getStatus()); dto.getStatuMap().put(name, boxStatus.getStatus());
dto.getMsgMap().put(cid, statusBean.getErrorMsg(servletRequest.getLocale())); dto.getMsgMap().put(name, statusBean.getErrorMsg(servletRequest.getLocale()));
} }
}else{ }else{
dto.getStatuMap().put(cid,0); dto.getStatuMap().put(name,0);
dto.getMsgMap().put(cid,""); dto.getMsgMap().put(name,"");
} }
//出入库报表 默认过去一周到现在的 //出入库报表 默认过去一周到现在的
...@@ -313,10 +327,12 @@ public class MicronStatusController { ...@@ -313,10 +327,12 @@ public class MicronStatusController {
String[] nameList = new String[]{}; String[] nameList = new String[]{};
String robotName = "R1"; String robotName = "R1";
if (boxName.equals("MI1")) { if (boxName.equals("MI1")) {
nameList = new String[]{"M3", "M4", "M7", "M8"}; // nameList = new String[]{"M3", "M4", "M7", "M8"};
nameList = new String[]{"KTS-R001A", "KTS-R001B", "KTS-R001C", "KTS-R001D"};
robotName = "R1"; robotName = "R1";
} else if (boxName.equals("MI2")) { } else if (boxName.equals("MI2")) {
nameList = new String[]{"M1", "M2", "M5", "M6"}; // nameList = new String[]{"M1", "M2", "M5", "M6"};
nameList = new String[]{ "KTS-R002A", "KTS-R002B","KTS-R002C", "KTS-R002D"};
robotName = "R2"; robotName = "R2";
} }
...@@ -430,7 +446,7 @@ public class MicronStatusController { ...@@ -430,7 +446,7 @@ public class MicronStatusController {
// if (ObjectUtil.isNotEmpty(msg)) { // if (ObjectUtil.isNotEmpty(msg)) {
// count += 1; // count += 1;
// } // }
Map<String, String> msgMap = statusBean.getMsgMap(); Map<String, String> msgMap = statusBean.getMsgMap(MessageUtils.getDefaultLocal());
if (msgMap != null && msgMap.size() > 0) { if (msgMap != null && msgMap.size() > 0) {
for (String msg : for (String msg :
msgMap.keySet()) { msgMap.keySet()) {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!