From 9b7a05ddf02bd619e615eee275eefdbe8b964519 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Thu, 24 Oct 2024 21:33:56 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=94=B6=E8=B4=B9=E6=96=B9=E5=BC=8F=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/receive/ReceiveController.java | 55 ++++++++++++------- .../controller/system/EtModelController.java | 3 - .../com/ruoyi/system/domain/EtFeeRule.java | 3 + .../mapper/system/EtFeeRuleMapper.xml | 15 +++-- 4 files changed, 49 insertions(+), 27 deletions(-) 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 e698e92..6f28965 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 @@ -42,6 +42,7 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @@ -96,6 +97,9 @@ public class ReceiveController { private static AtomicLong lastCommandTime = new AtomicLong(0); private static final long COMMAND_COOLDOWN_MS = 5 * 60 * 1000; // 5分钟 + // 用于标记每个设备的状态 + private static Map noOrderMarkers = new ConcurrentHashMap<>(); + private static final Map commandCooldownMap = new ConcurrentHashMap<>(); private static final long COOLDOWN_PERIOD_MS = 10000; // 冷却时间为 10 秒 @@ -181,7 +185,11 @@ public class ReceiveController { /** 3.超出运营区外断电 包含靠近运营区播报 */ outAreaOutage(value, asDevice, lon, lat, area, isAdminUnlocking, noRidingArea); /** 4.锁同步关锁 */ - lockSynchronization(msg, asDevice, logEntry, value, asDevice, lon, lat); + if(asDevice.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NORMAL)){ + log.info("锁同步关锁:" +asDevice.getSn()); + lockSynchronization(msg, asDevice, logEntry, value, lon, lat); + } + /** 5.低电量 生成换电工单*/ replacementOrder(asDevice, area); } @@ -420,35 +428,44 @@ public class ReceiveController { return noRidingArea; } - private void lockSynchronization(String msg, AsDevice asDevice, LogEntry logEntry, LogEntry.LocationValue value, AsDevice device, BigDecimal lon, BigDecimal lat) { + private void lockSynchronization(String msg, AsDevice asDevice, LogEntry logEntry, LogEntry.LocationValue value, BigDecimal lon, BigDecimal lat) { Integer status = value.getStatus(); if(status == 1){//上电运行 log.info("上电运行:" + logEntry.getDevName()); if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){ //获取当前正在骑行中的订单 - boolean currentOrderNum = etOrderService.isInOrderBySn(device.getSn()); + boolean currentOrderNum = etOrderService.isInOrderBySn(asDevice.getSn()); + long currentTime = System.currentTimeMillis(); if(!currentOrderNum){ - long currentTime = System.currentTimeMillis(); - long lastTime = lastCommandTime.get();// 上一次命令时间,5分账内不再执行 ‘车辆锁同步关锁’ 命令 - long difference = System.currentTimeMillis() - logEntry.getAt(); - log.info("当前时间戳:【"+System.currentTimeMillis()+"】,消息时间:【"+ logEntry.getAt()+"】,时间差:【"+difference+"】"); - if (difference < 60 * 1000 && ServiceConstants.LOCK_STATUS_CLOSE.equals(device.getLockStatus())) {// 消息时间和当前时间,时间差在1分钟内,且锁状态为关闭,则发送命令 - if (currentTime - lastTime >= COMMAND_COOLDOWN_MS) { - try { - asDeviceService.sendCommand(asDevice.getMac(), Token.getToken(), IotConstants.COMMAND_CLOSE + IotConstants.COMMAND_FREQUENCY_3600, "车辆锁同步关锁", null, null, msg); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (InvalidKeyException e) { - e.printStackTrace(); - } + // 设备没有正在骑行中的订单 + String sn = asDevice.getSn(); + noOrderMarkers.put(sn, currentTime); // 设置标记时间 + + // 设置定时任务,5分钟后检查状态 + Executors.newSingleThreadScheduledExecutor().schedule(() -> { + if (!etOrderService.isInOrderBySn(sn)) { + // 5分钟后仍然没有正在骑行中的订单 + executeLockCommand(asDevice, msg); } - } + noOrderMarkers.remove(sn); // 清除标记 + }, COMMAND_COOLDOWN_MS, TimeUnit.MILLISECONDS); } } } } + private void executeLockCommand(AsDevice asDevice, String msg) { + long lastTime = lastCommandTime.get(); // 上一次命令时间 + long currentTime = System.currentTimeMillis(); + + if (currentTime - lastTime >= COMMAND_COOLDOWN_MS) { + try { + asDeviceService.sendCommand(asDevice.getMac(), Token.getToken(), IotConstants.COMMAND_CLOSE + IotConstants.COMMAND_FREQUENCY_3600, "车辆锁同步关锁", null, null, msg); + lastCommandTime.set(currentTime); // 更新上次发送命令时间 + } catch (UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException e) { + e.printStackTrace(); + } + } + } private void replacementOrder(AsDevice device, EtOperatingArea area) { diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtModelController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtModelController.java index 6b58530..dd74721 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtModelController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtModelController.java @@ -116,9 +116,6 @@ public class EtModelController extends BaseController if (etModel.getModel() == null || etModel.getModel().trim().isEmpty()) { return "车型为必填项"; } - if (etModel.getOperator() == null) { - return "代理商为必填项"; - } if (etModel.getAreaId() == null) { return "运营区为必填项"; } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtFeeRule.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtFeeRule.java index 0dbe51f..adaa6a2 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtFeeRule.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtFeeRule.java @@ -179,4 +179,7 @@ public class EtFeeRule extends BaseEntity @Excel(name = "描述") private String description; + + @Excel(name = "排序") + private Integer orderNum; } diff --git a/electripper-system/src/main/resources/mapper/system/EtFeeRuleMapper.xml b/electripper-system/src/main/resources/mapper/system/EtFeeRuleMapper.xml index c44ea8a..1e634c4 100644 --- a/electripper-system/src/main/resources/mapper/system/EtFeeRuleMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtFeeRuleMapper.xml @@ -26,20 +26,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + select rule_id, dept_id, dept_id, `name`, `explain`, status, auto_refund_deposit, order_exceed_minutes, order_exceed_warn, free_ride_time, rental_unit, riding_rule, riding_rule_json, charging_cycle, charging_cycle_value, - capped_amount, instructions, create_by, create_time from et_fee_rule + capped_amount, instructions, create_by, create_time, order_num from et_fee_rule @@ -80,6 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join et_model_rule mr on mr.rule_id = r.rule_id left join et_model m on m.model_id = mr.model_id where r.is_deleted = 0 and m.model_id = #{modelId} + order by r.order_num