更新 推送新增status + time

This commit is contained in:
caixiang 2021-09-27 10:53:23 +08:00
parent 303664eda3
commit e36ca8ae57
5 changed files with 68 additions and 22 deletions

View File

@ -6,6 +6,7 @@ import com.qgs.dc.mq.entity.MQMessage;
import com.qgs.dc.opcua.constant.PLCTypeConstant; import com.qgs.dc.opcua.constant.PLCTypeConstant;
import org.eclipse.milo.opcua.stack.core.types.builtin.ByteString; import org.eclipse.milo.opcua.stack.core.types.builtin.ByteString;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.*; import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.*;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
@ -94,6 +95,18 @@ public class CommonFunction {
} }
} }
public static String quality(StatusCode statusCode) {
if (statusCode.isGood()) {
return "good";
} else if (statusCode.isBad()) {
return "bad";
} else if (statusCode.isUncertain()) {
return "uncertain";
} else {
return "unknown";
}
}
/** /**
* 用处在从OPC Server 读到变量要把变量包装一下 传给前端 * 用处在从OPC Server 读到变量要把变量包装一下 传给前端
* 含义: 包装变量 * 含义: 包装变量

View File

@ -72,6 +72,8 @@ public class PID00BReceived {
} }
//2.模拟异常 然后 拒签消息 然后丢到死信队列 //2.模拟异常 然后 拒签消息 然后丢到死信队列
//throw new Exception("11111"); //throw new Exception("11111");

View File

@ -41,6 +41,7 @@ public class TestController {
public R eapRequest(){ public R eapRequest(){
try { try {
//properties 这里的参数是写在MQ消息 header里面的如果EAP端 需要某些参数 可以写在这里eap去取更方便一些 //properties 这里的参数是写在MQ消息 header里面的如果EAP端 需要某些参数 可以写在这里eap去取更方便一些
for(int i =0;i<20;i++){
Map<String,Object> properties = new HashMap<>(); Map<String,Object> properties = new HashMap<>();
CallbackMessageEntity callbackMessageEntity = new CallbackMessageEntity(); CallbackMessageEntity callbackMessageEntity = new CallbackMessageEntity();
properties.put("equipmentName","PID001"); properties.put("equipmentName","PID001");
@ -62,6 +63,9 @@ public class TestController {
callbackMessageEntity.setMqMessage(mesResponse); callbackMessageEntity.setMqMessage(mesResponse);
properties.put("transitionId", "12312"); properties.put("transitionId", "12312");
rabbitSender.reply(callbackMessageEntity.getMqMessage(),properties, callbackMessageEntity.getExchangeName(), callbackMessageEntity.getRoutingKey()); rabbitSender.reply(callbackMessageEntity.getMqMessage(),properties, callbackMessageEntity.getExchangeName(), callbackMessageEntity.getRoutingKey());
}
return R.ok("回复成功"); return R.ok("回复成功");
}catch (Exception e){ }catch (Exception e){
return R.error().put("result",e.getMessage()); return R.error().put("result",e.getMessage());

View File

@ -13,8 +13,11 @@ import com.qgs.dc.opcua.selfunion.entity.SubscribeEventArgEntity;
import com.qgs.dc.opcua.selfunion.entity.SubscribeVarArgEntity; import com.qgs.dc.opcua.selfunion.entity.SubscribeVarArgEntity;
import com.qgs.dc.common.websocket.WebSocketServer; import com.qgs.dc.common.websocket.WebSocketServer;
import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem; import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem;
import org.eclipse.milo.opcua.stack.core.StatusCodes;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.DateTime;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger; import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort; import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -24,6 +27,7 @@ import org.springframework.web.bind.annotation.*;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
@RestController @RestController
@ -38,6 +42,22 @@ public class OperateController {
@Autowired @Autowired
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
@PostMapping("/testForWeight")
public R testForWeight(){
//压力测试
try {
DataValue dv = uaService.getValue(5,"Boolean", "plc1");
Object value = dv.getValue().getValue();
logger.info(CommonFunction.judgeVarType(value));
return R.ok().put("result", CommonFunction.var(value));
}catch (Exception e){
String s = uaService.extractError(e.getMessage());
s = s+";详细:"+e.getMessage();
return R.error().put("result",s);
}
}
@PostMapping("/addThisPlc") @PostMapping("/addThisPlc")
/** /**
* @Description * @Description
@ -188,8 +208,9 @@ public class OperateController {
Object value = dataValue.getValue().getValue(); Object value = dataValue.getValue().getValue();
String varType = CommonFunction.judgeVarType(value); String varType = CommonFunction.judgeVarType(value);
String status = CommonFunction.quality(dataValue.getStatusCode());
String res = namespaceIndex + "," + identifier + "|" + CommonFunction.var2String(value) + "|" + varType+ "|" +subscribeVarArgEntity.getPlcName(); String time = dataValue.getSourceTime().getJavaDate().toString();
String res = namespaceIndex + "," + identifier + "|" + CommonFunction.var2String(value) + "|" + varType+ "|" +subscribeVarArgEntity.getPlcName()+"|"+status+"|"+time;
try { try {
webSocketServer.sendtoAll(res); webSocketServer.sendtoAll(res);
@ -241,7 +262,9 @@ public class OperateController {
Object value = dataValue.getValue().getValue(); Object value = dataValue.getValue().getValue();
String varType = CommonFunction.judgeVarType(value); String varType = CommonFunction.judgeVarType(value);
String res = namespaceIndex + "," + identifier + "|" + CommonFunction.var2String(value) + "|" + varType+ "|" +subscribeVarArgEntity.getPlcName(); String status = CommonFunction.quality(dataValue.getStatusCode());
String time = dataValue.getSourceTime().getJavaDate().toString();
String res = namespaceIndex + "," + identifier + "|" + CommonFunction.var2String(value) + "|" + varType+ "|" +subscribeVarArgEntity.getPlcName()+"|"+status+"|"+time;
try { try {
webSocketServer.sendtoAll(res); webSocketServer.sendtoAll(res);
@ -367,10 +390,13 @@ public class OperateController {
return R.error().put("result",subscribeVarArgEntity.getPlcName()+" 这台plc不存在 / 或参数异常"); return R.error().put("result",subscribeVarArgEntity.getPlcName()+" 这台plc不存在 / 或参数异常");
} }
if(integer == 1){ if(integer == 1){
logger.info("取消订阅变量:"+subscribeVarArgEntity.toString() +"成功");
return R.ok().put("result","成功"); return R.ok().put("result","成功");
}else if(integer == 2) { }else if(integer == 2) {
logger.error("取消订阅变量:"+subscribeVarArgEntity.toString() +"失败取消订阅的这个Node 不存在");
return R.error().put("result","取消订阅的这个Node 不存在"); return R.error().put("result","取消订阅的这个Node 不存在");
}else { }else {
logger.error("取消订阅变量:"+subscribeVarArgEntity.toString() +"失败");
return R.error().put("result","取消订阅的这个Node 失败"); return R.error().put("result","取消订阅的这个Node 失败");
} }
}catch (Exception e){ }catch (Exception e){

View File

@ -319,6 +319,7 @@ public class UAService {
DataValue value2 = null; DataValue value2 = null;
try { try {
value2 = node2.readValue(); value2 = node2.readValue();
StatusCode statusCode = value2.getStatusCode();
}catch (Exception e){ }catch (Exception e){
throw new Exception("OPCUA 读变量出现异常,,具体异常是: "+e.getMessage()); throw new Exception("OPCUA 读变量出现异常,,具体异常是: "+e.getMessage());
} }