处理发送命令后超时报错,但是车辆启动的问题
This commit is contained in:
parent
ef093e84c3
commit
e405734501
|
@ -226,7 +226,7 @@ iot:
|
||||||
# iot秘钥
|
# iot秘钥
|
||||||
accessKey: dJqF0qYhUbK/o1Pr9I5qxNoP14FlJLC+BFK2ZTjUX+lnKwoNYvBYsM/7Xu1ERIzSkUoxVkP/N1RMvGlBKMoBtA==
|
accessKey: dJqF0qYhUbK/o1Pr9I5qxNoP14FlJLC+BFK2ZTjUX+lnKwoNYvBYsM/7Xu1ERIzSkUoxVkP/N1RMvGlBKMoBtA==
|
||||||
# 超时响应时间(秒)
|
# 超时响应时间(秒)
|
||||||
timeout: 5
|
timeout: 10
|
||||||
# token过期时间
|
# token过期时间
|
||||||
daysToExpire: 100
|
daysToExpire: 100
|
||||||
# 推送消息token
|
# 推送消息token
|
||||||
|
|
|
@ -882,34 +882,8 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
}
|
}
|
||||||
String sessionId = IdUtils.randomUUIDByDigit(8);
|
String sessionId = IdUtils.randomUUIDByDigit(8);
|
||||||
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(orderVo.getSn());
|
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(orderVo.getSn());
|
||||||
/** 1.获取token*/
|
|
||||||
String token = Token.getToken();
|
|
||||||
String finalOrderNo = orderNo;
|
|
||||||
if(!"true".equals(orderVo.getIsBluetooth())){
|
|
||||||
/** 2.发送命令*/
|
|
||||||
ResponseVo responseVo = sendCommandWithResp(asDevice.getMac(), token, IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5, "编号开锁", finalOrderNo);
|
|
||||||
if(responseVo.getCode() != 0){
|
|
||||||
// todo asDevice.getMac()
|
|
||||||
log.info("【扫码/编号开锁骑行】发送开锁命令失败,通过api重新查询状态");
|
|
||||||
|
|
||||||
throw new ServiceException("【扫码/编号开锁骑行】发送开锁命令失败");
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
asDevice.setLongitude(orderVo.getLon());
|
|
||||||
asDevice.setLatitude(orderVo.getLat());
|
|
||||||
asDevice.setLastTime(DateUtils.getNowDate());
|
|
||||||
}
|
|
||||||
/** 3.更新车辆状态*/
|
|
||||||
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
|
|
||||||
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_USING);
|
|
||||||
asDevice.setIsAdminUnlocking("0");
|
|
||||||
int device = asDeviceMapper.updateAsDevice(asDevice);
|
|
||||||
if(device==0){
|
|
||||||
log.info("【扫码/编号开锁骑行】更新车辆状态失败");
|
|
||||||
throw new ServiceException("【扫码/编号开锁骑行】更新车辆状态失败");
|
|
||||||
}
|
|
||||||
/** 4.如果有预约订单则更新订单的预约结束时间,如果没有预约,则创建订单*/
|
/** 4.如果有预约订单则更新订单的预约结束时间,如果没有预约,则创建订单*/
|
||||||
EtOrder order = etOrderService.selectEtOrderByOrderNo(finalOrderNo);
|
EtOrder order = etOrderService.selectEtOrderByOrderNo(orderNo);
|
||||||
if(ObjectUtil.isNotNull(order)){//有订单号:可能是套餐也可能是有预约
|
if(ObjectUtil.isNotNull(order)){//有订单号:可能是套餐也可能是有预约
|
||||||
if(ObjectUtil.isNotNull(order.getRuleId())){//套餐
|
if(ObjectUtil.isNotNull(order.getRuleId())){//套餐
|
||||||
log.info("【扫码/编号开锁骑行】---预约扫码骑行");
|
log.info("【扫码/编号开锁骑行】---预约扫码骑行");
|
||||||
|
@ -931,7 +905,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
log.info("【扫码/编号开锁骑行】---无订单号,正常开锁骑行订单");
|
log.info("【扫码/编号开锁骑行】---无订单号,正常开锁骑行订单");
|
||||||
order = etOrderService.createOrder(orderVo, finalOrderNo);
|
order = etOrderService.createOrder(orderVo, orderNo);
|
||||||
int etOrder = etOrderService.insertEtOrder(order);
|
int etOrder = etOrderService.insertEtOrder(order);
|
||||||
if(etOrder==0){
|
if(etOrder==0){
|
||||||
log.info("【扫码/编号开锁骑行】保存订单失败");
|
log.info("【扫码/编号开锁骑行】保存订单失败");
|
||||||
|
@ -944,12 +918,68 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
log.info("【扫码/编号开锁骑行】记录行程失败");
|
log.info("【扫码/编号开锁骑行】记录行程失败");
|
||||||
throw new ServiceException("【扫码/编号开锁骑行】记录行程失败");
|
throw new ServiceException("【扫码/编号开锁骑行】记录行程失败");
|
||||||
}
|
}
|
||||||
|
/** 1.获取token*/
|
||||||
|
String token = Token.getToken();
|
||||||
|
if(!"true".equals(orderVo.getIsBluetooth())){
|
||||||
|
/** 2.发送命令*/
|
||||||
|
ResponseVo responseVo = sendCommandWithResp(asDevice.getMac(), token, IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5, "编号开锁", orderNo);
|
||||||
|
if(responseVo.getCode() != 0){
|
||||||
|
// 开锁失败的处理
|
||||||
|
boolean b = failHandle(responseVo, asDevice, token);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
asDevice.setLongitude(orderVo.getLon());
|
||||||
|
asDevice.setLatitude(orderVo.getLat());
|
||||||
|
asDevice.setLastTime(DateUtils.getNowDate());
|
||||||
|
}
|
||||||
|
/** 3.更新车辆状态*/
|
||||||
|
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
|
||||||
|
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_USING);
|
||||||
|
asDevice.setIsAdminUnlocking("0");
|
||||||
|
int device = asDeviceMapper.updateAsDevice(asDevice);
|
||||||
|
if(device==0){
|
||||||
|
log.info("【扫码/编号开锁骑行】更新车辆状态失败");
|
||||||
|
throw new ServiceException("【扫码/编号开锁骑行】更新车辆状态失败");
|
||||||
|
}
|
||||||
log.info("【扫码/编号开锁骑行】车辆开锁成功");
|
log.info("【扫码/编号开锁骑行】车辆开锁成功");
|
||||||
response.setOrderNo(orderNo);
|
response.setOrderNo(orderNo);
|
||||||
response.setSessionId(sessionId);
|
response.setSessionId(sessionId);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean failHandle(ResponseVo responseVo, AsDevice asDevice, String token) throws InterruptedException {
|
||||||
|
// todo asDevice.getMac() 2秒之后重新发送命令 10500
|
||||||
|
if(responseVo.getCode() == 10500){
|
||||||
|
log.info("【扫码/编号开锁骑行】发送开锁命令失败,隔两秒之后通过api重新查询状态");
|
||||||
|
// 2秒之后执行以下代码
|
||||||
|
Thread.sleep(2000);
|
||||||
|
DataPointRes datapoints = historyDatapoints(asDevice.getMac(), token);
|
||||||
|
if(datapoints.getCode() == 0){
|
||||||
|
Data data = datapoints.getData();
|
||||||
|
List<Datastream> datastreams = data.getDevices();
|
||||||
|
for (Datastream datastream: datastreams) {
|
||||||
|
List<Datapoint> datapointList = datastream.getDatastreams();
|
||||||
|
if(ObjectUtil.isNotNull(datapointList)){
|
||||||
|
for (Datapoint datapoint:datapointList) {
|
||||||
|
if(datapoint.getId().equals(IotConstants.ONENET_LOCATION)){
|
||||||
|
String string = JSON.toJSONString(datapoint.getValue());
|
||||||
|
if(StrUtil.isNotBlank(string)){
|
||||||
|
LocationVo locationVo = JSONObject.parseObject(string, LocationVo.class);
|
||||||
|
log.info("【发送开锁命令失败,通过api重新查询状态】: locationVo---【{}】" , JSON.toJSONString(locationVo));
|
||||||
|
if(locationVo.getStatus() == 1){
|
||||||
|
log.info("【车已经打开了】");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ServiceException("【扫码/编号开锁骑行】发送开锁命令失败");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 管理员开锁
|
* 管理员开锁
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user