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) { + } + } } }