|
|
@@ -68,23 +68,20 @@ import java.util.concurrent.CompletableFuture;
|
|
|
public class OperationMessageService {
|
|
|
|
|
|
@Autowired
|
|
|
- OperationMessageDao operationMessageDao;
|
|
|
+ private OperationMessageDao operationMessageDao;
|
|
|
|
|
|
@Autowired
|
|
|
- DeviceInfoService deviceInfoService;
|
|
|
+ private DeviceInfoService deviceInfoService;
|
|
|
|
|
|
@Autowired
|
|
|
- GateWayInfoService gateWayInfoService;
|
|
|
+ private GateWayInfoService gateWayInfoService;
|
|
|
|
|
|
@Autowired
|
|
|
- MQClient mqClient;
|
|
|
+ private MQClient mqClient;
|
|
|
|
|
|
@Autowired
|
|
|
- DeviceInfoDao deviceInfoDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- HxzService hxzService;
|
|
|
-
|
|
|
+ private DeviceInfoDao deviceInfoDao;
|
|
|
+
|
|
|
// 保存90天
|
|
|
@Value("${artemisstore.time}")
|
|
|
private Long ttlMill = 30 * 24L * 60 * 60 * 1000L;
|
|
|
@@ -96,16 +93,16 @@ public class OperationMessageService {
|
|
|
private ApplicationContext applicationContext;
|
|
|
|
|
|
@Autowired
|
|
|
- IotMainDao iotMainDao;
|
|
|
+ private IotMainDao iotMainDao;
|
|
|
|
|
|
@Autowired
|
|
|
- OperationMessageResultDao operationMessageResultDao;
|
|
|
+ private OperationMessageResultDao operationMessageResultDao;
|
|
|
|
|
|
@Autowired
|
|
|
- ApiRequestService apiRequestService;
|
|
|
+ private ApiRequestService apiRequestService;
|
|
|
|
|
|
@Autowired
|
|
|
- IotDataVerifyService iotDataVerifyService;
|
|
|
+ private IotDataVerifyService iotDataVerifyService;
|
|
|
|
|
|
/**
|
|
|
* 发送指令
|
|
|
@@ -190,6 +187,7 @@ public class OperationMessageService {
|
|
|
*/
|
|
|
public void handlerGateWayMessage(Message message) {
|
|
|
// 处理接收到的消息
|
|
|
+ String msg = "";
|
|
|
try {
|
|
|
ActiveMQTopic activeMQTopic = (ActiveMQTopic) message.getJMSDestination();
|
|
|
String topicName = activeMQTopic.getTopicName();
|
|
|
@@ -201,11 +199,9 @@ public class OperationMessageService {
|
|
|
// log.info("receiveMessage {} 消息监听clientId: {}", messageId, clientId);
|
|
|
if (StringUtils.isNotEmpty(topicName) && topicName.endsWith("reply")) {
|
|
|
// 这是响应的数据,不处理
|
|
|
-// log.warn("回复消息不处理");
|
|
|
return;
|
|
|
}
|
|
|
String messageClass = "";
|
|
|
- String msg = "";
|
|
|
if (message instanceof ActiveMQBytesMessage) {
|
|
|
ActiveMQBytesMessage activeMQBytesMessage = (ActiveMQBytesMessage) message;
|
|
|
messageClass = ActiveMQBytesMessage.class.getSimpleName();
|
|
|
@@ -234,6 +230,9 @@ public class OperationMessageService {
|
|
|
String gateWayId = jsonObject.getStr("gatewayId");
|
|
|
String deviceId = jsonObject.getStr("deviceId");
|
|
|
boolean isTimeOut = false;
|
|
|
+ if (time == null) {
|
|
|
+ time = System.currentTimeMillis();
|
|
|
+ }
|
|
|
if (System.currentTimeMillis() > (time + ttl)) {
|
|
|
isTimeOut = true;
|
|
|
}
|
|
|
@@ -242,7 +241,7 @@ public class OperationMessageService {
|
|
|
String timeStr = DateUtils.paresTime(time, DateUtils.patternyyyySSS);
|
|
|
jsonObject.set("timeStr", timeStr);
|
|
|
|
|
|
- // --------------------处理业务 start------------------
|
|
|
+ // --------------------消息处理 start------------------
|
|
|
OperationMessage operationMessage = new OperationMessage();
|
|
|
operationMessage.setMessageId(messageId); // 消息ID
|
|
|
operationMessage.setClientId(clientId); // 终端ID
|
|
|
@@ -261,6 +260,7 @@ public class OperationMessageService {
|
|
|
}
|
|
|
initAddOperationMessage(operationMessage);
|
|
|
} catch (Exception e) {
|
|
|
+ log.error(msg);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
@@ -298,7 +298,7 @@ public class OperationMessageService {
|
|
|
// 消息的过期时间
|
|
|
entity.setTtl(new Date(System.currentTimeMillis() + ttlMill));
|
|
|
boolean isTimeOut = entity.getIsTimeOut();
|
|
|
- isTimeOut = true;
|
|
|
+ isTimeOut = false;
|
|
|
if (entity.getEvent().equals("ping")) {
|
|
|
Date da = new Date(System.currentTimeMillis() + 10 * 60 * 1000);
|
|
|
entity.setTtl(da);
|
|
|
@@ -307,7 +307,7 @@ public class OperationMessageService {
|
|
|
entity.setHandleMsg("超时不处理");
|
|
|
}
|
|
|
// TODO
|
|
|
- if (isTimeOut) {
|
|
|
+ if (!isTimeOut) {
|
|
|
// 未超时,处理消息
|
|
|
handleOperationMessage(entity);
|
|
|
} else {
|
|
|
@@ -470,6 +470,8 @@ public class OperationMessageService {
|
|
|
// 参数验证成功
|
|
|
org.springframework.util.StopWatch stopWatch = new org.springframework.util.StopWatch();
|
|
|
stopWatch.start();
|
|
|
+
|
|
|
+ // 请求业务端处理
|
|
|
APIResponseModel apiResponseModel = apiRequestService.requestAPI(remoteUrl, data);
|
|
|
messageResult.setResultData(apiResponseModel);
|
|
|
if (apiResponseModel.isSuccess()) {
|
|
|
@@ -479,7 +481,6 @@ public class OperationMessageService {
|
|
|
if (ObjectUtils.isNotEmpty(content)) {
|
|
|
object = JSONUtil.parseObj(content);
|
|
|
}
|
|
|
- messageResult.setResultData(content);
|
|
|
messageResult.setReplayData(object);
|
|
|
isHandleSuccess = true;
|
|
|
if (iotMain.getIsReturnData() != null && iotMain.getIsReturnData()) {
|
|
|
@@ -498,13 +499,14 @@ public class OperationMessageService {
|
|
|
stopWatch.stop();
|
|
|
messageResult.setUseTime(stopWatch.getTotalTimeMillis());
|
|
|
} else {
|
|
|
+ // 参数验证失败
|
|
|
isHandleSuccess = false;
|
|
|
isNeedReplay = Boolean.TRUE;
|
|
|
handleMsg = verifyContent.getMsg();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(!isHandleSuccess) {
|
|
|
+ if (!isHandleSuccess) {
|
|
|
handleError.setFailed(handleMsg);
|
|
|
JSONObject replayData = JSONUtil.parseObj(handleError);
|
|
|
messageResult.setReplayData(replayData);
|