更新 推送新增status + time
This commit is contained in:
parent
303664eda3
commit
e36ca8ae57
@ -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 中 读到变量,要把变量包装一下 传给前端
|
||||||
* 含义: 包装变量
|
* 含义: 包装变量
|
||||||
|
@ -72,6 +72,8 @@ public class PID00BReceived {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//2.模拟异常 ,然后 拒签消息 ,然后丢到死信队列
|
//2.模拟异常 ,然后 拒签消息 ,然后丢到死信队列
|
||||||
|
|
||||||
//throw new Exception("11111");
|
//throw new Exception("11111");
|
||||||
|
@ -41,27 +41,31 @@ public class TestController {
|
|||||||
public R eapRequest(){
|
public R eapRequest(){
|
||||||
try {
|
try {
|
||||||
//properties 这里的参数是写在MQ消息 header里面的,如果EAP端 需要某些参数 可以写在这里,eap去取更方便一些
|
//properties 这里的参数是写在MQ消息 header里面的,如果EAP端 需要某些参数 可以写在这里,eap去取更方便一些
|
||||||
Map<String,Object> properties = new HashMap<>();
|
for(int i =0;i<20;i++){
|
||||||
CallbackMessageEntity callbackMessageEntity = new CallbackMessageEntity();
|
Map<String,Object> properties = new HashMap<>();
|
||||||
properties.put("equipmentName","PID001");
|
CallbackMessageEntity callbackMessageEntity = new CallbackMessageEntity();
|
||||||
callbackMessageEntity.setExchangeName("00B_Exchange");
|
properties.put("equipmentName","PID001");
|
||||||
callbackMessageEntity.setRoutingKey("00B_EAP_Request_Queue_RoutingKey");
|
callbackMessageEntity.setExchangeName("00B_Exchange");
|
||||||
|
callbackMessageEntity.setRoutingKey("00B_EAP_Request_Queue_RoutingKey");
|
||||||
|
|
||||||
MQMessage mesResponse = new MQMessage();
|
MQMessage mesResponse = new MQMessage();
|
||||||
|
|
||||||
|
Header header = new Header("Request","Execute","QUERYEQPStatus","12");
|
||||||
|
QueryEQStatusBody queryEQStatusBody = new QueryEQStatusBody();
|
||||||
|
queryEQStatusBody.setVidType("u4");
|
||||||
|
List<String> vids = new ArrayList<>();
|
||||||
|
vids.add("10000");
|
||||||
|
vids.add("10001");
|
||||||
|
vids.add("10002");
|
||||||
|
queryEQStatusBody.setVidList(vids);
|
||||||
|
mesResponse.setBody(JSONObject.toJSONString(queryEQStatusBody));
|
||||||
|
mesResponse.setHeader(header);
|
||||||
|
callbackMessageEntity.setMqMessage(mesResponse);
|
||||||
|
properties.put("transitionId", "12312");
|
||||||
|
rabbitSender.reply(callbackMessageEntity.getMqMessage(),properties, callbackMessageEntity.getExchangeName(), callbackMessageEntity.getRoutingKey());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Header header = new Header("Request","Execute","QUERYEQPStatus","12");
|
|
||||||
QueryEQStatusBody queryEQStatusBody = new QueryEQStatusBody();
|
|
||||||
queryEQStatusBody.setVidType("u4");
|
|
||||||
List<String> vids = new ArrayList<>();
|
|
||||||
vids.add("10000");
|
|
||||||
vids.add("10001");
|
|
||||||
vids.add("10002");
|
|
||||||
queryEQStatusBody.setVidList(vids);
|
|
||||||
mesResponse.setBody(JSONObject.toJSONString(queryEQStatusBody));
|
|
||||||
mesResponse.setHeader(header);
|
|
||||||
callbackMessageEntity.setMqMessage(mesResponse);
|
|
||||||
properties.put("transitionId", "12312");
|
|
||||||
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());
|
||||||
|
@ -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){
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user