|
|
@@ -98,69 +98,70 @@ public class DeviceOnlineTask {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public void resetTheConnection(){
|
|
|
-try {
|
|
|
- //差正常的设备,禁用设备不管
|
|
|
- logger.info("设备连接检查");
|
|
|
- QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
|
|
|
- deviceQueryWrapper.eq("disabled", DeviceOnlineStatus.NORMAL);
|
|
|
- List<Device> list = deviceService.list(deviceQueryWrapper);
|
|
|
- logger.info("查询到设备"+list.size());
|
|
|
- //云快充设备缓存过滤订阅消息
|
|
|
- Set<String> imeiList = list.stream().map(device ->
|
|
|
- device.getDeviceImei()
|
|
|
- ).collect(Collectors.toSet());
|
|
|
- //redisCache.setCacheObject(RedisConstant.DEVICE_INFO, imeiList, 10 * 1000 * 60, TimeUnit.MILLISECONDS);
|
|
|
- redisCache.setCacheObject(RedisConstant.DEVICE_INFO,imeiList);
|
|
|
-
|
|
|
-
|
|
|
- QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
|
|
|
- deviceStatusQueryWrapper.eq("online_status", DeviceOnlineStatus.ONLINE);
|
|
|
- List<DeviceStatus> onlineList = deviceStatusService.list(deviceStatusQueryWrapper);
|
|
|
-
|
|
|
- List<DeviceStatus> newOnlineList = onlineList.stream().map(deviceStatus -> {
|
|
|
- long updateTime = deviceStatus.getUpdateTime();
|
|
|
- long nowTime = System.currentTimeMillis();
|
|
|
- if ((nowTime - updateTime) > gapTime) {
|
|
|
- if (socketHandle.existDeviceConnection(deviceStatus.getPileCode())) {
|
|
|
- redisCache.deleteObject(RedisConstant.KEYS + deviceStatus.getPileCode());
|
|
|
- socketHandle.removeDeviceConnection(deviceStatus.getPileCode());
|
|
|
+ public void resetTheConnection() {
|
|
|
+ try {
|
|
|
+ //差正常的设备,禁用设备不管
|
|
|
+ logger.info("设备连接检查");
|
|
|
+ QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
|
|
|
+ deviceQueryWrapper.eq("disabled", DeviceOnlineStatus.NORMAL);
|
|
|
+ List<Device> list = deviceService.list(deviceQueryWrapper);
|
|
|
+ logger.info("查询到设备" + list.size());
|
|
|
+ //云快充设备缓存过滤订阅消息
|
|
|
+ Set<String> imeiList = list.stream().map(device ->
|
|
|
+ device.getDeviceImei()
|
|
|
+ ).collect(Collectors.toSet());
|
|
|
+ //redisCache.setCacheObject(RedisConstant.DEVICE_INFO, imeiList, 10 * 1000 * 60, TimeUnit.MILLISECONDS);
|
|
|
+ redisCache.setCacheObject(RedisConstant.DEVICE_INFO, imeiList);
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
|
|
|
+ deviceStatusQueryWrapper.eq("online_status", DeviceOnlineStatus.ONLINE);
|
|
|
+ List<DeviceStatus> onlineList = deviceStatusService.list(deviceStatusQueryWrapper);
|
|
|
+
|
|
|
+ List<DeviceStatus> newOnlineList = onlineList.stream().map(deviceStatus -> {
|
|
|
+ long updateTime = deviceStatus.getUpdateTime();
|
|
|
+ long nowTime = System.currentTimeMillis();
|
|
|
+ if ((nowTime - updateTime) > gapTime) {
|
|
|
+ if (socketHandle.existDeviceConnection(deviceStatus.getPileCode())) {
|
|
|
+ redisCache.deleteObject(RedisConstant.KEYS + deviceStatus.getPileCode());
|
|
|
+ socketHandle.removeDeviceConnection(deviceStatus.getPileCode());
|
|
|
+ }
|
|
|
+ deviceStatus.setOnlineStatus(DeviceOnlineStatus.OFFLINE);
|
|
|
+ //deviceStatus.setGunStatus(StatusConstant.OFFLINE);
|
|
|
}
|
|
|
- deviceStatus.setOnlineStatus(DeviceOnlineStatus.OFFLINE);
|
|
|
- //deviceStatus.setGunStatus(StatusConstant.OFFLINE);
|
|
|
+ return deviceStatus;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (redisCache.hasKey(RedisConstant.DEVICE_INFO)) {
|
|
|
+ Set<String> imeis = redisCache.getCacheObject(RedisConstant.DEVICE_INFO);
|
|
|
+ logger.info("redis-imei>>>" + imeis.size());
|
|
|
}
|
|
|
- return deviceStatus;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- if (redisCache.hasKey(RedisConstant.DEVICE_INFO)) {
|
|
|
- Set<String> imeis = redisCache.getCacheObject(RedisConstant.DEVICE_INFO);
|
|
|
- logger.info("redis-imei>>>" + imeis.size());
|
|
|
- }
|
|
|
- logger.info("dataBase device status change:" + newOnlineList.size());
|
|
|
- deviceStatusService.updateBatchById(newOnlineList);
|
|
|
+ logger.info("dataBase device status change:" + newOnlineList.size());
|
|
|
+ deviceStatusService.updateBatchById(newOnlineList);
|
|
|
|
|
|
- Map<String, Device> collect = list.stream().collect(Collectors.toMap(device -> device.getDeviceImei(), device -> device,(exis,repl)->exis));
|
|
|
+ Map<String, Device> collect = list.stream().collect(Collectors.toMap(device -> device.getDeviceImei(), device -> device, (exis, repl) -> exis));
|
|
|
|
|
|
- newOnlineList.stream().forEach(deviceStatus -> {
|
|
|
- //logger.info(" newOnlineList.stream().forEach");
|
|
|
- if (!socketHandle.existDeviceConnection(deviceStatus.getPileCode())) {
|
|
|
- try {
|
|
|
- Device device = collect.get(deviceStatus.getDeviceImei());
|
|
|
- socketHandle.addDeviceConnection(device.getIp(),device.getPort(),deviceStatus.getPileCode(), deviceStatus.getDeviceImei(), deviceStatus.getDeviceSn());
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ newOnlineList.stream().forEach(deviceStatus -> {
|
|
|
+ //logger.info(" newOnlineList.stream().forEach");
|
|
|
+ if (!socketHandle.existDeviceConnection(deviceStatus.getPileCode())) {
|
|
|
+ try {
|
|
|
+ Device device = collect.get(deviceStatus.getDeviceImei());
|
|
|
+ socketHandle.addDeviceConnection(device.getIp(), device.getPort(), deviceStatus.getPileCode(), deviceStatus.getDeviceImei(), deviceStatus.getDeviceSn(), device.getCommProtocolVer());
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(deviceStatus.getPileCode());
|
|
|
- //logger.info("deviceConnection");
|
|
|
- if (deviceConnection.getLoginStatus()== Constant.DEVICE_NOT_LOGIN_STATUS&&deviceStatus.getOnlineStatus()==DeviceOnlineStatus.ONLINE){
|
|
|
- //logger.info("DEVICE_NOT_LOGIN_STATUS");
|
|
|
- List<Device> collect1 = list.stream().filter(device -> device.getPileCode() .equals(deviceConnection.getDeviceId())) .collect(Collectors.toList());
|
|
|
- if (collect1.size()>0){
|
|
|
- logger.info("设备连接检查login>>>"+collect1.get(0).getDeviceSn());
|
|
|
- loginFrame.loginMsgSend(deviceConnection,collect1.get(0));
|
|
|
+ DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(deviceStatus.getPileCode());
|
|
|
+ //logger.info("deviceConnection");
|
|
|
+ if (deviceConnection.getLoginStatus() == Constant.DEVICE_NOT_LOGIN_STATUS && deviceStatus.getOnlineStatus() == DeviceOnlineStatus.ONLINE) {
|
|
|
+ //logger.info("DEVICE_NOT_LOGIN_STATUS");
|
|
|
+ List<Device> collect1 = list.stream().filter(device -> device.getPileCode().equals(deviceConnection.getDeviceId())).collect(Collectors.toList());
|
|
|
+ if (collect1.size() > 0) {
|
|
|
+ logger.info("设备连接检查login>>>" + collect1.get(0).getDeviceSn());
|
|
|
+ loginFrame.loginMsgSend(deviceConnection, collect1.get(0));
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|