1. 新增命令记录时,保存msg
2. 无订单关锁只发一次
This commit is contained in:
parent
55e6bb5e07
commit
881ec010f9
|
@ -79,6 +79,8 @@ public class ReceiveController {
|
|||
|
||||
private final Object lock = new Object();
|
||||
|
||||
private boolean lockCommandSent = false; // 添加标志变量
|
||||
|
||||
|
||||
/**
|
||||
* 功能描述:第三方平台数据接收。<p>
|
||||
|
@ -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; // 设置标志为已发送
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,4 +58,8 @@ public class EtCommandLog extends BaseEntity
|
|||
@Excel(name = "订单号")
|
||||
private String orderNo;
|
||||
|
||||
/** onenet上报的消息 */
|
||||
@Excel(name = "onenet上报的消息")
|
||||
private String msg;
|
||||
|
||||
}
|
||||
|
|
|
@ -177,6 +177,11 @@ public interface IAsDeviceService extends IService<AsDevice>
|
|||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 发送命令(带响应)
|
||||
*/
|
||||
|
|
|
@ -968,6 +968,35 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> 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<AsDeviceMapper, AsDevice> 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) {
|
||||
|
|
|
@ -18,10 +18,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="orderNo" column="order_no" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="msg" column="msg" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectEtCommandLogVo">
|
||||
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
|
||||
</sql>
|
||||
|
||||
<select id="selectEtCommandLogList" parameterType="EtCommandLog" resultMap="EtCommandLogResult">
|
||||
|
@ -58,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="callStatus != null">call_status,</if>
|
||||
<if test="orderNo != null">order_no,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="msg != null">msg,</if>
|
||||
create_time
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
|
@ -72,6 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="callStatus != null">#{callStatus},</if>
|
||||
<if test="orderNo != null">#{orderNo},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="msg != null">#{msg},</if>
|
||||
sysdate()
|
||||
</trim>
|
||||
</insert>
|
||||
|
@ -89,6 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="longitude != null">longitude = #{longitude},</if>
|
||||
<if test="callStatus != null">call_status = #{callStatus},</if>
|
||||
<if test="orderNo != null">order_no = #{orderNo},</if>
|
||||
<if test="msg != null">msg = #{msg},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
|
Loading…
Reference in New Issue
Block a user