diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java
index 21d8546..460e38f 100644
--- a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java
+++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java
@@ -79,6 +79,8 @@ public class ReceiveController {
private final Object lock = new Object();
+ private boolean lockCommandSent = false; // 添加标志变量
+
/**
* 功能描述:第三方平台数据接收。
@@ -296,11 +298,17 @@ public class ReceiveController {
// 优化轨迹,如果获取到的定位与最后一个定位相同,则不添加
optimizeRoute(jsonArray, newPoint,lon,lat,etOrder);
+
+ // 重置关锁命令发送标志
+ lockCommandSent = false;
}else{
//当前无订单,并且不是管理员开锁的情况下,直接关锁
if(!isAdminUnlocking.equals("1")){
- log.info("当前无订单,并且不是管理员开锁的情况下,直接关锁--------" +logEntry.getDevName());
- asDeviceService.sendCommand(asDevice.getMac(), Token.getToken(), IotConstants.COMMAND_CLOSE+IotConstants.COMMAND_FREQUENCY_3600,"无订单关锁",null,null);
+ if (!lockCommandSent) { // 如果未发送过关锁命令
+ log.info("当前无订单,并且不是管理员开锁的情况下,直接关锁--------" + logEntry.getDevName());
+ asDeviceService.sendCommand(asDevice.getMac(), Token.getToken(), IotConstants.COMMAND_CLOSE + IotConstants.COMMAND_FREQUENCY_3600, "无订单关锁", null, null, msg);
+ lockCommandSent = true; // 设置标志为已发送
+ }
}
}
}
diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java
index 25b6649..e045ed2 100644
--- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java
+++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java
@@ -58,4 +58,8 @@ public class EtCommandLog extends BaseEntity
@Excel(name = "订单号")
private String orderNo;
+ /** onenet上报的消息 */
+ @Excel(name = "onenet上报的消息")
+ private String msg;
+
}
diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java
index eaabe6e..3f9ae71 100644
--- a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java
+++ b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java
@@ -177,6 +177,11 @@ public interface IAsDeviceService extends IService
*/
public void sendCommand(String mac, String token,String command,String type,String orderNo,String userName);
+ /**
+ * 发送命令
+ */
+ public void sendCommand(String mac, String token,String command,String type,String orderNo,String userName,String msg);
+
/**
* 发送命令(带响应)
*/
diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java
index 20882d7..c8e0297 100644
--- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java
+++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java
@@ -968,6 +968,35 @@ public class AsDeviceServiceImpl extends ServiceImpl i
}
}
+ @Transactional
+ @Override
+ /** 发送命令*/
+ public void sendCommand(String mac, String token,String command,String type,String orderNo,String userName,String msg) {
+ String param = "device_name=" + mac + "&product_id=" + productId +"&timeout=" + timeout;
+ String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND + "?"+param;
+ String result = HttpUtils.sendPostWithToken(sendUrl, command, token);
+ log.info("【"+type+"】===>IOT请求调用结果:【{}】",result);
+ JSONObject paramsObj = JSON.parseObject(result);
+ String code = paramsObj.getString("code");
+
+ if ("10500".equals(code)) { // 超时
+ log.info("第一次请求超时,进行第二次请求...");
+ result = HttpUtils.sendPostWithToken(sendUrl, command, token);
+ log.info("【" + type + "】===>IOT第二次请求调用结果:【{}】", result);
+ paramsObj = JSON.parseObject(result);
+ code = paramsObj.getString("code");
+ }
+
+ asynchronousSaveLog(sendUrl,command,mac,result,type,orderNo,userName,msg);
+ //记录命令
+ if (!HttpStatus.IOT_SUCCESS.equals(code))
+ {
+ // 异步更新在线状态
+ asynchronousUpdateOnlineStatus(mac);
+ throw new ServiceException(code+"-----"+ IotUtil.formatMsg(code));
+ }
+ }
+
private void asynchronousUpdateOnlineStatus(String mac) {
AsDevice device = asDeviceMapper.selectAsDeviceByMac(mac);
//异步更新在线状态
@@ -1021,6 +1050,34 @@ public class AsDeviceServiceImpl extends ServiceImpl i
}, 0, TimeUnit.SECONDS);
}
+ /* 异步保存发送命令日志*/
+ private void asynchronousSaveLog(String url,String command,String mac,String result,String type,String orderNo,String userName,String msg) {
+ //异步保存发送命令日志
+ scheduledExecutorService.schedule(() -> {
+ EtCommandLog etCommandLog = new EtCommandLog();
+ etCommandLog.setUrl(url);
+ etCommandLog.setCommand(command);
+ etCommandLog.setType(type);
+ etCommandLog.setMac(mac);
+ AsDevice device = asDeviceMapper.selectAsDeviceByMac(mac);
+ etCommandLog.setSn(device.getSn());
+ etCommandLog.setResult(result);
+ etCommandLog.setMsg(msg);
+ etCommandLog.setLongitude(device.getLongitude());
+ etCommandLog.setLatitude(device.getLatitude());
+ etCommandLog.setCreateTime(DateUtils.getNowDate());
+ JSONObject paramsObj = JSON.parseObject(result);
+ String code = paramsObj.getString("code");
+ etCommandLog.setCallStatus(code);
+ etCommandLog.setOrderNo(orderNo);
+ etCommandLog.setCreateBy(userName);
+ int i = etCommandLogMapper.insertEtCommandLog(etCommandLog);
+ if(i>0){
+ log.info("【发送命令】异步保存发送命令日志");
+ }
+ }, 0, TimeUnit.SECONDS);
+ }
+
@Override
/** 发送命令*/
public ResponseVo sendCommandWithResp(String mac, String token,String command,String type,String orderNo) {
diff --git a/electripper-system/src/main/resources/mapper/system/EtCommandLogMapper.xml b/electripper-system/src/main/resources/mapper/system/EtCommandLogMapper.xml
index 0782dd0..5533ae9 100644
--- a/electripper-system/src/main/resources/mapper/system/EtCommandLogMapper.xml
+++ b/electripper-system/src/main/resources/mapper/system/EtCommandLogMapper.xml
@@ -18,10 +18,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+
- select id, url, command, type, mac, sn, result, longitude, latitude, call_status, create_by, create_time, order_no from et_command_log
+ select id, url, command, type, mac, sn, result, longitude, latitude, call_status, create_by, create_time, order_no, msg from et_command_log