| | |
| | | package com.ld.igds.timer; |
| | | |
| | | import com.bstek.bdf2.core.model.DefaultCompany; |
| | | import com.ld.igds.camera.ApiCameraManager; |
| | | import com.ld.igds.camera.CameraUtil; |
| | | import com.ld.igds.camera.data.ApiCameraResp; |
| | | import com.ld.igds.camera.data.ApiSnapReq; |
| | | import com.ld.igds.common.CoreCommonService; |
| | | import com.ld.igds.data.ConfigData; |
| | | import com.ld.igds.file.CoreFileService; |
| | | import com.ld.igds.models.SecCamera; |
| | | import com.ld.igds.models.SecSnapConf; |
| | | import com.ld.igds.models.SecSnapDepot; |
| | | import com.ld.igds.models.SnapSer; |
| | | import com.ld.igds.sec.service.CoreSecCameraService; |
| | | import com.ld.igds.sec.service.SecSnapService; |
| | | import com.ld.igds.sec.service.SecurityService; |
| | | import com.ld.igds.sec.service.SecSnapDepotService; |
| | | import com.ld.igds.util.ContextUtil; |
| | | import com.ld.igds.util.DateUtil; |
| | | import com.ld.igds.view.manager.TempManager; |
| | | import com.ld.igds.view.service.SnapSerService; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.time.DateUtils; |
| | | |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | @Component(ScheduledSec.BEAN_ID) |
| | | public class ScheduledSec { |
| | | |
| | | public static final String BEAN_ID = "sec.scheduled"; |
| | | public static final String BEAN_ID = "sec.scheduled"; |
| | | |
| | | @Resource |
| | | private ConfigData configData; |
| | | @Resource |
| | | private SecSnapService secSnapService; |
| | | @Resource |
| | | private CoreSecCameraService coreSecCameraService; |
| | | @Resource |
| | | private SnapSerService snapSerService; |
| | | @Resource |
| | | private CoreFileService fileService; |
| | | @Resource |
| | | private ApiCameraManager apiCameraManager; |
| | | @Resource |
| | | private ConfigData configData; |
| | | @Resource |
| | | private SecSnapDepotService secSnapService; |
| | | @Resource |
| | | private CoreSecCameraService coreSecCameraService; |
| | | @Resource |
| | | private SnapSerService snapSerService; |
| | | @Resource |
| | | private CoreFileService fileService; |
| | | @Resource |
| | | private ApiCameraManager apiCameraManager; |
| | | |
| | | /** |
| | | * 每间隔30分钟执行一次 |
| | | */ |
| | | @Scheduled(cron = "0 0/30 * * * ?") |
| | | public void scheduled30() { |
| | | /** |
| | | * 从6-18点开始执行 |
| | | */ |
| | | @Scheduled(cron = "0 0 6,7,8,9,10,11,12,13,14,15,16,17,18 * * ? ") |
| | | public void scheduled30() { |
| | | |
| | | //执行抓拍判断 |
| | | doExeSnap(new Date()); |
| | | } |
| | | Date exeDate = new Date(); |
| | | |
| | | /** |
| | | * 定时执行抓拍 |
| | | */ |
| | | private void doExeSnap(Date date) { |
| | | // 执行抓拍判断 |
| | | doExeSnap(exeDate); |
| | | } |
| | | |
| | | if (configData.getSnapTime() < 0) return; |
| | | /** |
| | | * 定时执行抓拍 |
| | | */ |
| | | private void doExeSnap(Date date) { |
| | | try { |
| | | // 获取所有配置抓拍摄像头 |
| | | List<SecSnapConf> list = secSnapService.listSnapConf( |
| | | configData.getDefaultCompanyId(), null); |
| | | |
| | | //获取当前系统时间 |
| | | int curHour = DateUtil.getHour(date); |
| | | if (curHour != configData.getSnapTime()) return; |
| | | if (null == list || list.isEmpty()) { |
| | | return; |
| | | } |
| | | SecSnapConf exeConf = list.get(0); |
| | | |
| | | log.info("===================系统执行定时仓内视频抓拍=================="); |
| | | // 获取抓拍时间 |
| | | int exeHour1 = exeConf.getActHour1(); |
| | | int exeHour2 = exeConf.getActHour2(); |
| | | int exeHour3 = exeConf.getActHour3(); |
| | | |
| | | if (exeHour1 == 0 && exeHour1 == 0 && exeHour1 == 0) |
| | | return; |
| | | |
| | | try { |
| | | // 获取当前系统时间 |
| | | int curHour = DateUtil.getHour(date); |
| | | |
| | | if(curHour != exeHour1 && curHour != exeHour2 && curHour !=exeHour3){ |
| | | return; |
| | | } |
| | | |
| | | List<SecSnapConf> list = secSnapService.listSnapConf(configData.getDefaultCompanyId(), null); |
| | | log.info("===================系统执行定时仓内视频抓拍=================="); |
| | | |
| | | if (null == list || list.isEmpty()) return; |
| | | SecCamera secCamera; |
| | | Map<String, SnapSer> snapSerMap = new HashMap<>(); |
| | | SnapSer snapSer; |
| | | for (SecSnapConf snapConf : list) { |
| | | |
| | | SecCamera secCamera; |
| | | Map<String, SnapSer> snapSerMap = new HashMap<>(); |
| | | SnapSer snapSer; |
| | | for (SecSnapConf snapConf : list) { |
| | | secCamera = coreSecCameraService.getCameraById( |
| | | snapConf.getCompanyId(), snapConf.getCameraId()); |
| | | |
| | | if (null == secCamera) continue; |
| | | |
| | | if (null == snapConf.getDepotId()) continue; |
| | | snapSer = snapSerMap.get(snapConf.getDeptId()); |
| | | if (null == snapSer) { |
| | | snapSer = snapSerService.getCacheByDeptId(snapConf.getDeptId()); |
| | | snapSerMap.put(snapConf.getDeptId(), snapSer); |
| | | } |
| | | |
| | | secCamera = coreSecCameraService.getCameraById(snapConf.getCompanyId(), snapConf.getCameraId()); |
| | | if (null == snapSer) { |
| | | log.error("------------抓拍为配置抓拍分机----------"); |
| | | continue; |
| | | } |
| | | |
| | | if (null == secCamera) continue; |
| | | doExeSnapToData(secCamera, snapSer, snapConf); |
| | | |
| | | snapSer = snapSerMap.get(snapConf.getDeptId()); |
| | | if (null == snapSer) { |
| | | snapSer = snapSerService.getCacheByDeptId(snapConf.getDeptId()); |
| | | snapSerMap.put(snapConf.getDeptId(), snapSer); |
| | | } |
| | | Thread.sleep(500); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("----------抓拍后台出错---------{}", e); |
| | | } |
| | | } |
| | | |
| | | if (null == snapSer) { |
| | | log.error("------------抓拍为配置抓拍分机----------"); |
| | | continue; |
| | | } |
| | | private void doExeSnapToData(SecCamera secCamera, SnapSer snapSer,SecSnapConf snapConf) { |
| | | ApiSnapReq req = new ApiSnapReq(); |
| | | req.setCompanyId(secCamera.getCompanyId()); |
| | | req.setDeptId(secCamera.getDeptId()); |
| | | req.setSn(secCamera.getSn()); |
| | | req.setSnapType(secCamera.getSnapType()); |
| | | req.setPlayType(secCamera.getPlayType()); |
| | | req.setSerSn(snapSer.getSn()); |
| | | req.setCameraName(secCamera.getName()); |
| | | req.setBizId(null); |
| | | |
| | | doExeSnapToData(secCamera, snapSer, snapConf); |
| | | req.setMediaAddr(CameraUtil.updateMediaAddr(secCamera.getMediaAddr(), |
| | | secCamera.getLoginId(), secCamera.getPwd(), |
| | | secCamera.getIpIn(), secCamera.getPortInC(), |
| | | secCamera.getChanNum())); |
| | | |
| | | Thread.sleep(500); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("----------抓拍后台出错---------{}", e); |
| | | } |
| | | } |
| | | String filePath = fileService.getSnapFilePath(new Date()); |
| | | |
| | | private void doExeSnapToData(SecCamera secCamera, SnapSer snapSer, SecSnapConf snapConf) { |
| | | ApiSnapReq req = new ApiSnapReq(); |
| | | req.setCompanyId(secCamera.getCompanyId()); |
| | | req.setDeptId(secCamera.getDeptId()); |
| | | req.setSn(secCamera.getSn()); |
| | | req.setSnapType(secCamera.getSnapType()); |
| | | req.setPlayType(secCamera.getPlayType()); |
| | | req.setSerSn(snapSer.getSn()); |
| | | req.setCameraName(secCamera.getName()); |
| | | req.setBizId(null); |
| | | req.setFilePath(filePath); |
| | | |
| | | req.setMediaAddr(CameraUtil.updateMediaAddr(secCamera.getMediaAddr(), secCamera.getLoginId(), |
| | | secCamera.getPwd(), secCamera.getIpIn(), secCamera.getPortInC(), secCamera.getChanNum())); |
| | | // 调整附件名称,避免出现中文 |
| | | String fileName = snapConf.getDeptId() + "_" + ContextUtil.getTimeId(1000) + ".jpg"; |
| | | req.setFileName(fileName); |
| | | |
| | | String filePath = fileService.getSnapFilePath(new Date()); |
| | | // 执行抓拍 |
| | | ApiCameraResp resp = apiCameraManager.getApiCameraService(secCamera.getPlayType()).snapImg(req); |
| | | resp.setFileName(fileName); |
| | | |
| | | req.setFilePath(filePath); |
| | | |
| | | //调整附件名称,避免出现中文 |
| | | String fileName = snapConf.getDepotId() + "_" + ContextUtil.getTimeId(1000) + ".jpg"; |
| | | req.setFileName(fileName); |
| | | |
| | | //执行抓拍 |
| | | ApiCameraResp resp = apiCameraManager.getApiCameraService(secCamera.getPlayType()).snapImg(req); |
| | | resp.setFileName(fileName); |
| | | |
| | | //执行记录保存 |
| | | secSnapService.addData(snapConf, fileName, resp.getCode()); |
| | | } |
| | | // 执行记录保存 |
| | | secSnapService.addData(snapConf, fileName, resp.getCode()); |
| | | } |
| | | } |