|
|
@@ -51,120 +51,73 @@ public class MsgFreeRunner {
|
|
|
|
|
|
@Async("freeTaskAsyncPool")
|
|
|
public void freeMsg(Map<String, DeviceConnectionMsg> map) throws Exception {
|
|
|
- log.info("======Free status push task starting=====");
|
|
|
|
|
|
- //任务处理
|
|
|
- //redis取出在线设备集合
|
|
|
- Set<String> devicePileCodes = map.keySet();
|
|
|
- log.info("free.deviceConnectionSize>>"+devicePileCodes.size());
|
|
|
- devicePileCodes.stream().forEach(devicePileCode -> {
|
|
|
- try{
|
|
|
+ log.info("空闲上报>>"+map.size());
|
|
|
|
|
|
-
|
|
|
- if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_ONE)) {
|
|
|
- DeviceStatus deviceStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_ONE, devicePileCode);
|
|
|
- if (deviceStatus != null) {
|
|
|
- if (deviceStatus.getGunStatus() == StatusConstant.CHARGING) {
|
|
|
- log.info("freeMsg>>>deviceguns status>>"+deviceStatus.getGunStatus());
|
|
|
- }
|
|
|
-
|
|
|
- //标记最后订单时间 5分钟内不上报空闲状态 避免刚下单状态还没更新就被freeTask任务给顶掉了
|
|
|
- try{
|
|
|
- long ts = redisCache.getCacheMapValue(RedisConstant.PILE_GUN_PAY_TIME, devicePileCode+"_1");
|
|
|
- if(ts!=0){
|
|
|
- long ts1 = System.currentTimeMillis();
|
|
|
- if((ts1-ts)<300*1000){
|
|
|
- log.info("{}下单时间未超过5分钟不上报空闲状态",devicePileCode+"_1");
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //存在设备在线状态的上送空闲状态
|
|
|
- DeviceConnectionMsg deviceConnectionMsg = map.get(devicePileCode);
|
|
|
- if (deviceConnectionMsg.getLoginStatus()== Constant.DEVICE_NOT_LOGIN_STATUS){
|
|
|
- //
|
|
|
- QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
|
|
|
- deviceQueryWrapper.eq("pile_code", devicePileCode).eq("disabled", DeviceOnlineStatus.NORMAL);
|
|
|
- Device device = deviceService.getOne(deviceQueryWrapper);
|
|
|
- Long heartTime = deviceConnectionMsg.getHeartTime();
|
|
|
- if (deviceStatus.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
|
|
|
- log.info("heartTaskAsyncPool-1>not longin and heart normal>>" + devicePileCode);
|
|
|
- // loginFrame.loginMsgSend(deviceConnectionMsg,device);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
- if (deviceStatus.getGunStatus() != StatusConstant.CHARGING) {
|
|
|
- if (deviceConnectionMsg.getLoginStatus() == 1) {
|
|
|
- log.info("↑↑↑↑↑↑↑↑↑↑↑↑↑空闲实时状态上报1111↑↑↑↑↑↑↑↑↑↑↑↑↑ " + deviceStatus.getGunStatus() + "<>" + (deviceStatus.getGunStatus() == PortStatusConstant.EMERGENCY_STOP));
|
|
|
- if (deviceStatus.getGunStatus() == PortStatusConstant.EMERGENCY_STOP) {
|
|
|
- //急停中也是空闲状态上报
|
|
|
- deviceStatus.setGunStatus(StatusConstant.FREE);
|
|
|
- }
|
|
|
- realTimeStatusPushFrame.deviceStatusPush(deviceConnectionMsg, FrameDataSplicing.
|
|
|
- transactionNum(deviceStatus.getPileCode(), deviceConnectionMsg.getMessageCount()), deviceStatus.getPileCode(), deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), 0, 0, zero, zero, 0);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ map.forEach(( devicePileCode,deviceConnectionMsg)->{
|
|
|
+ try{
|
|
|
+ DeviceStatus deviceStatusOne = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_ONE, devicePileCode);
|
|
|
+ if(deviceStatusOne!=null){
|
|
|
+ handleOne(deviceStatusOne,deviceConnectionMsg);
|
|
|
}
|
|
|
- if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_TWO)) {
|
|
|
- DeviceStatus deviceStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_TWO, devicePileCode);
|
|
|
-
|
|
|
- if (deviceStatus != null) {
|
|
|
-
|
|
|
- try{
|
|
|
- long ts = redisCache.getCacheMapValue(RedisConstant.PILE_GUN_PAY_TIME, devicePileCode+"_2");
|
|
|
- if(ts!=0){
|
|
|
- long ts1 = System.currentTimeMillis();
|
|
|
- if((ts1-ts)<300*1000){
|
|
|
- log.info("{}下单时间未超过5分钟不主动上报空闲状态",devicePileCode+"_2");
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //标记最后订单时间 5分钟内不上报空闲状态 避免刚下单状态还没更新就被freeTask任务给顶掉了
|
|
|
- //存在设备在线状态的上送空闲状态
|
|
|
- DeviceConnectionMsg deviceConnectionMsg = map.get(devicePileCode);
|
|
|
- if (deviceConnectionMsg.getLoginStatus()== Constant.DEVICE_NOT_LOGIN_STATUS){
|
|
|
- //
|
|
|
- QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
|
|
|
- deviceQueryWrapper.eq("pile_code", devicePileCode).eq("disabled", DeviceOnlineStatus.NORMAL);
|
|
|
- Device device = deviceService.getOne(deviceQueryWrapper);
|
|
|
- Long heartTime = deviceConnectionMsg.getHeartTime();
|
|
|
- if (deviceStatus.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
|
|
|
- log.info("heartTaskAsyncPool-1>not longin and heart normal>>" + devicePileCode);
|
|
|
- loginFrame.loginMsgSend(deviceConnectionMsg,device);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
- if (deviceStatus.getGunStatus() != StatusConstant.CHARGING) {
|
|
|
- if (deviceConnectionMsg.getLoginStatus() == 1) {
|
|
|
- if (deviceStatus.getGunStatus() == PortStatusConstant.EMERGENCY_STOP) {
|
|
|
- //急停中也是空闲状态上报
|
|
|
- deviceStatus.setGunStatus(StatusConstant.FREE);
|
|
|
- }
|
|
|
- log.info("↑↑↑↑↑↑↑↑↑↑↑↑↑空闲实时状态上报2222↑↑↑↑↑↑↑↑↑↑↑↑↑ ");
|
|
|
- realTimeStatusPushFrame.deviceStatusPush(deviceConnectionMsg, FrameDataSplicing.
|
|
|
- transactionNum(deviceStatus.getPileCode(), deviceConnectionMsg.getMessageCount()), deviceStatus.getPileCode(), deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), 0, 0, zero, zero, 0);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ DeviceStatus deviceStatusTwo = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_TWO, devicePileCode);
|
|
|
+ if(deviceStatusTwo!=null){
|
|
|
+ handleOne(deviceStatusTwo,deviceConnectionMsg);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
- log.info("======Free msg exception ===="+e.toString());
|
|
|
e.printStackTrace();
|
|
|
+ log.info("上报空闲异常{},{}",devicePileCode,e.getMessage());
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
-
|
|
|
+ //任务处理
|
|
|
+ //redis取出在线设备集合
|
|
|
log.info("======Free status push task ending=====");
|
|
|
}
|
|
|
|
|
|
+ public void handleOne( DeviceStatus deviceStatus,DeviceConnectionMsg deviceConnectionMsg){
|
|
|
+
|
|
|
+ if(deviceStatus==null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ long ts = redisCache.getCacheMapValue(RedisConstant.PILE_GUN_PAY_TIME, deviceStatus.getPileCode()+"_"+deviceStatus.getGunPort());
|
|
|
+ if(ts!=0){
|
|
|
+ long ts1 = System.currentTimeMillis();
|
|
|
+ if((ts1-ts)<300*1000){
|
|
|
+ log.info("{}下单时间未超过5分钟不主动上报空闲状态",deviceStatus.getPileCode()+"_"+deviceStatus.getGunPort());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ }
|
|
|
+
|
|
|
+ //标记最后订单时间 5分钟内不上报空闲状态 避免刚下单状态还没更新就被freeTask任务给顶掉了
|
|
|
+ //存在设备在线状态的上送空闲状态
|
|
|
+ if (deviceConnectionMsg.getLoginStatus()== Constant.DEVICE_NOT_LOGIN_STATUS){
|
|
|
+ Long heartTime = deviceConnectionMsg.getHeartTime();
|
|
|
+ if (deviceStatus.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
|
|
|
+ log.info("heartTaskAsyncPool-1>not longin and heart normal>>" + deviceStatus.getPileCode());
|
|
|
+ QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
|
|
|
+ deviceQueryWrapper.eq("pile_code", deviceStatus.getPileCode()).eq("disabled", DeviceOnlineStatus.NORMAL);
|
|
|
+ Device device = deviceService.getOne(deviceQueryWrapper);
|
|
|
+ if(device!=null){
|
|
|
+ loginFrame.loginMsgSend(deviceConnectionMsg,device);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (deviceStatus.getGunStatus() != StatusConstant.CHARGING) {
|
|
|
+ if (deviceConnectionMsg.getLoginStatus() == 1) {
|
|
|
+ if (deviceStatus.getGunStatus() == PortStatusConstant.EMERGENCY_STOP) {
|
|
|
+ //急停中也是空闲状态上报
|
|
|
+ deviceStatus.setGunStatus(StatusConstant.FREE);
|
|
|
+ }
|
|
|
+ log.info("↑↑↑↑{}空闲实时状态上报",deviceStatus.getPileCode());
|
|
|
+ realTimeStatusPushFrame.deviceStatusPush(deviceConnectionMsg, FrameDataSplicing.
|
|
|
+ transactionNum(deviceStatus.getPileCode(), deviceConnectionMsg.getMessageCount()), deviceStatus.getPileCode(), deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), 0, 0, zero, zero, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|