| | |
| | | package com.ruoyi.alarm.globalAlarm.domain; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.PriorityQueue; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.PriorityBlockingQueue; |
| | | |
| | | /** |
| | |
| | | public static Comparator<GuideTask> getComparator() { |
| | | Comparator<GuideTask> PriorityDescCom = Comparator.comparingInt(GuideTask::getPriority).reversed(); |
| | | Comparator<GuideTask> NumDescCom = Comparator.comparingInt(GuideTask::getNum).reversed(); |
| | | Comparator<GuideTask> alarmTimeAscCom = Comparator.comparing(GuideTask::getAlarmTime); |
| | | Comparator<GuideTask> Comparator = PriorityDescCom.thenComparing(NumDescCom).thenComparing(alarmTimeAscCom); |
| | | Comparator<GuideTask> receiveTimeAscCom = Comparator.comparing(GuideTask::getReceiveTime); |
| | | Comparator<GuideTask> Comparator = PriorityDescCom.thenComparing(NumDescCom).thenComparing(receiveTimeAscCom); |
| | | return Comparator; |
| | | } |
| | | |
| | |
| | | public static void printPriorityQueue() { |
| | | for (String cameraId : GuidePriorityQueue.cameraQueueMap.keySet()) { |
| | | PriorityBlockingQueue<GuideTask> priorityQueue = GuidePriorityQueue.cameraQueueMap.get(cameraId); |
| | | for (GuideTask task : priorityQueue) { |
| | | log.info("alarmId:" + task.getAlarmId() + " alarmTime:" + task.getAlarmTime() + " priority:" + task.getPriority() + " num:" + task.getNum() + " cameraId:" + task.getCameraId()); |
| | | // for (GuideTask task : priorityQueue) { |
| | | // |
| | | // log.info("【alarmId】" + task.getAlarmId() + "【receiveTime】" + task.getReceiveTime() |
| | | // + "【priority】" + task.getPriority() + "【num】" + task.getNum() |
| | | // + "【chan】" + task.getChanNum() + "【recordSn】" + task.getRecordSn() + "【cameraId】" + task.getCameraId()); |
| | | // } |
| | | while (priorityQueue.size() > 0) { |
| | | GuideTask task = priorityQueue.poll(); |
| | | log.info("【alarmId】" + task.getAlarmId() + "【receiveTime】" + task.getReceiveTime() |
| | | + "【priority】" + task.getPriority() + "【num】" + task.getNum() |
| | | + "【chan】" + task.getChanNum() + "【recordSn】" + task.getRecordSn() + "【cameraId】" + task.getCameraId());; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | Comparator<obj> com1 = Comparator.comparingInt(obj::getNUM1).reversed(); |
| | | Comparator<obj> com2 = Comparator.comparingInt(obj::getNUM2).reversed(); |
| | | Comparator<obj> com3 = Comparator.comparingInt(obj::getNUM3).reversed(); |
| | | Comparator<obj> objComparator = com1.thenComparing(com2).thenComparing(com3); |
| | | PriorityQueue<obj> priorityQueue = new PriorityQueue<>(objComparator); |
| | | priorityQueue.add(new obj(1, 1, 65)); |
| | | priorityQueue.add(new obj(1, 4, 21)); |
| | | priorityQueue.add(new obj(1, 4, 33)); |
| | | priorityQueue.add(new obj(1, 4, 44)); |
| | | priorityQueue.add(new obj(1, 4, 51)); |
| | | |
| | | while (priorityQueue.size() > 0) { |
| | | obj task = priorityQueue.poll(); |
| | | log.info("【num1】" + task.getNUM1() + "【num2】" + task.getNUM2() + "【num3】" + task.getNUM3()); |
| | | } |
| | | log.info("======================================================================="); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Data |
| | | @AllArgsConstructor |
| | | class obj { |
| | | Integer NUM1; |
| | | Integer NUM2; |
| | | Integer NUM3; |
| | | } |