From 25c3e74e23dc14d5ad0dccb0348e0570f4b74358 Mon Sep 17 00:00:00 2001 From: huangfeng Date: Tue, 22 Apr 2025 15:53:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=85=A8=E9=83=A8=E8=A3=85=E7=BD=AE=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8B=8D=E7=85=A7=E6=97=B6=E9=97=B4=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xymanager_common/constant/Constants.java | 3 +- .../timeTask/StoreCameraScheduleTask.java | 73 ++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/constant/Constants.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/constant/Constants.java index fda741a..8f9763f 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/constant/Constants.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/constant/Constants.java @@ -6,6 +6,7 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; /** @@ -214,7 +215,7 @@ public class Constants { public static final Integer NetType_M2M10086 = 3; public static final Integer NetType_LWWLKJ = 4; - public static HashMap scheduleRequestMap = new HashMap<>(); + public static ConcurrentHashMap scheduleRequestMap = new ConcurrentHashMap<>(); public static HashMap scheduleRequestDoneMap = new HashMap<>(); } \ No newline at end of file diff --git a/xymanager_framework/src/main/java/com/shxy/xymanager_framework/timeTask/StoreCameraScheduleTask.java b/xymanager_framework/src/main/java/com/shxy/xymanager_framework/timeTask/StoreCameraScheduleTask.java index a59db10..7351343 100644 --- a/xymanager_framework/src/main/java/com/shxy/xymanager_framework/timeTask/StoreCameraScheduleTask.java +++ b/xymanager_framework/src/main/java/com/shxy/xymanager_framework/timeTask/StoreCameraScheduleTask.java @@ -1,33 +1,56 @@ package com.shxy.xymanager_framework.timeTask; import com.shxy.xymanager_common.constant.Constants; +import com.shxy.xymanager_common.dto.TermAndChannelDto; +import com.shxy.xymanager_common.dto.TermChannelAndMapperDto; import com.shxy.xymanager_common.entity.CameraSchedule; import com.shxy.xymanager_common.entity.CameraScheduleExample; import com.shxy.xymanager_common.entity.RequestResults; +import com.shxy.xymanager_common.entity.Terminals; +import com.shxy.xymanager_common.vo.TermCtrlVo; import com.shxy.xymanager_dao.dao.CameraScheduleMapper; import com.shxy.xymanager_dao.dao.RequestResultsDao; +import com.shxy.xymanager_service.service.CacheService; +import com.shxy.xymanager_service.service.NewCacheService; +import com.shxy.xymanager_service.service.TermSetService; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import javax.annotation.PreDestroy; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Map; @Service @Slf4j public class StoreCameraScheduleTask { + @Resource + NewCacheService newCacheService; + @Resource + CacheService cacheService; @Resource RequestResultsDao requestResultsDao; @Resource CameraScheduleMapper cameraScheduleMapper; + @Resource + TermSetService termSetService; + + private int shutdown = 0; + + @PreDestroy + private void preDestroy() { + shutdown = 1; + } @Scheduled(initialDelay = 60000, fixedDelay = 60000) private void store() { Iterator it = Constants.scheduleRequestMap.keySet().iterator(); - while (it.hasNext()) { + while (shutdown == 0 && it.hasNext()) { Integer requestid = it.next(); RequestResults results = requestResultsDao.selectByRequestId(requestid); if (results != null) { @@ -63,6 +86,54 @@ public class StoreCameraScheduleTask { @Scheduled(cron = "0 1 3 * * ?") private void search() { + Map terminalMap = newCacheService.getTerminalMap(); + Map termAndChannelMap = cacheService.getTermAndChannelMap(); + Iterator it = terminalMap.keySet().iterator(); + while (shutdown == 0 && it.hasNext()) { + Integer termId = it.next(); + Terminals term = terminalMap.get(termId); + TermAndChannelDto termAndChannelDto = termAndChannelMap.get(termId); + this.searchOne(term, termAndChannelDto); + try { + Thread.sleep(500); + } catch (Exception ignore) { + } + } + } + private void searchOne(Terminals term, TermAndChannelDto termAndChannelDto) { + if (termAndChannelDto == null) { + return; + } + List channelList = termAndChannelDto.getList(); + if (CollectionUtils.isEmpty(channelList)) { + return; + } + for (TermChannelAndMapperDto item : channelList) { + TermCtrlVo vo = new TermCtrlVo(); + vo.setTermId(term.getId()); + List list = new ArrayList<>(); + TermCtrlVo.CtrlBean bean = new TermCtrlVo.CtrlBean(); + bean.setName("act"); + bean.setValue("schedule"); + list.add(bean); + bean = new TermCtrlVo.CtrlBean(); + bean.setName("udp"); + bean.setValue("1"); + list.add(bean); + bean = new TermCtrlVo.CtrlBean(); + bean.setName("flag"); + bean.setValue("0"); + list.add(bean); + bean = new TermCtrlVo.CtrlBean(); + bean.setName("channel"); + bean.setValue(String.valueOf(item.getChannelid())); + list.add(bean); + vo.setList(list); + try { + termSetService.setTermCamera(vo); + } catch (Exception ignore) { + } + } } }