| | |
| | | package com.ycl.task; |
| | | |
| | | |
| | | import com.ycl.api.DH.frame.RealplayEx; |
| | | import com.ycl.api.DH.module.LoginModule; |
| | | import com.mongodb.client.result.DeleteResult; |
| | | import com.ycl.api.DH.utils.DHApi; |
| | | import com.ycl.api.HK.HKApi; |
| | | import com.ycl.api.YS.YSApi; |
| | | import com.ycl.platform.domain.entity.TMonitor; |
| | | import com.ycl.platform.domain.result.OSDResult; |
| | | import com.ycl.platform.domain.result.UY.MonitorQualifyResult; |
| | | import com.ycl.platform.domain.result.UY.OsdCheckResult; |
| | | import com.ycl.platform.domain.vo.OnlineThreadVO; |
| | | import com.ycl.platform.mapper.TMonitorMapper; |
| | | import com.ycl.platform.service.UYErrorTypeCheckService; |
| | | import com.ycl.thread.OSDCheckThread; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.StringUtils; |
| | | import constant.ApiConstants; |
| | | import enumeration.DeviceType; |
| | | import enumeration.general.AreaDeptEnum; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import static com.ycl.api.DH.lib.enumeration.NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_CUSTOMTITLE; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Component("OsdTask") |
| | | public class OsdTask { |
| | | public void test() { |
| | | // HKApi.test(); |
| | | long loginId = LoginModule.login("51.95.67.189", 80, "admin", "zg@2024dx"); |
| | | String osdTime = LoginModule.getOsdTime(); |
| | | LoginModule.logout(); |
| | | @Autowired |
| | | private MongoTemplate mongoTemplate; |
| | | @Autowired |
| | | private TMonitorMapper monitorMapper; |
| | | @Autowired |
| | | private UYErrorTypeCheckService uyErrorTypeCheckService; |
| | | |
| | | /** |
| | | * 通过查mongoDB每日一机一档数据获取设备ip |
| | | * 通过设备ip、品牌调用不同api获取osd信息 |
| | | * 比对mongoDB一机一档信息,整理成result存入mongo |
| | | * 同步品牌到mysql |
| | | */ |
| | | //TODO:大华动态库linux换位置 |
| | | public void getOSD() throws ExecutionException, InterruptedException { |
| | | log.info("开始获取OSD"); |
| | | //查一机一档monitor |
| | | Query query = new Query(Criteria.where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | List<MonitorQualifyResult> oneMachineFileResults = mongoTemplate.find(query, MonitorQualifyResult.class); |
| | | //需要考核的数据 |
| | | List<String> serialNumbers = oneMachineFileResults.stream().map(result -> result.getSerialNumber().getValue()).collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(serialNumbers)) { |
| | | ExecutorService executorService = new ThreadPoolExecutor(16, |
| | | 128, |
| | | 5000, |
| | | TimeUnit.SECONDS, |
| | | new ArrayBlockingQueue<>(1000), |
| | | new ThreadPoolExecutor.CallerRunsPolicy() |
| | | ); |
| | | List<TMonitor> monitors = monitorMapper.selectByNumbers(serialNumbers); |
| | | //过滤ip |
| | | monitors = monitors.stream().filter(monitor -> !StringUtils.isEmpty(monitor.getIp()) && !"127.0.0.1".equals(monitor.getIp())).collect(Collectors.toList()); |
| | | List<Future<OSDResult>> futureList = new ArrayList<>(48); |
| | | List<OSDResult> osdResultList = new ArrayList<>(); |
| | | for (TMonitor monitor : monitors) { |
| | | OSDCheckThread thread = new OSDCheckThread(monitor); |
| | | Future<OSDResult> future = executorService.submit(thread); |
| | | futureList.add(future); |
| | | } |
| | | for (Future<OSDResult> future : futureList) { |
| | | osdResultList.add(future.get()); |
| | | } |
| | | executorService.shutdown(); |
| | | |
| | | //结束api执行,开始校验 |
| | | List<OsdCheckResult> checkResults = new ArrayList<>(); |
| | | Map<String, TMonitor> monitorMap = monitors.stream().collect(Collectors.toMap(TMonitor::getSerialNumber, Function.identity())); |
| | | for (OSDResult osdResult : osdResultList) { |
| | | TMonitor monitor = monitorMap.get(osdResult.getSerialNumber()); |
| | | //封装OsdCheckResult |
| | | OsdCheckResult osdCheckResult = getOsdCheckResult(osdResult, monitor); |
| | | checkCorrect(osdResult, monitor, osdCheckResult); |
| | | log.info("校验结果:{}",osdCheckResult); |
| | | checkResults.add(osdCheckResult); |
| | | } |
| | | log.info("结果数据大小:{}", checkResults.size()); |
| | | //结果存入mongo |
| | | if (!CollectionUtils.isEmpty(checkResults)) { |
| | | log.info("存入mongo"); |
| | | //如果今天存在之前的数据先删除 |
| | | Query pyQuery = new Query(Criteria |
| | | .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | DeleteResult result = mongoTemplate.remove(pyQuery, OsdCheckResult.class); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(checkResults); |
| | | // 工单生成 |
| | | uyErrorTypeCheckService.osdCheck(checkResults); |
| | | } |
| | | } |
| | | log.info("结束获取OSD"); |
| | | } |
| | | |
| | | private OsdCheckResult getOsdCheckResult(OSDResult osdResult, TMonitor monitor) { |
| | | OsdCheckResult osdCheckResult = new OsdCheckResult(); |
| | | osdCheckResult.setDeviceNo(osdResult.getSerialNumber()); |
| | | osdCheckResult.setIp(monitor.getIp()); |
| | | osdCheckResult.setDeviceType(monitor.getCameraFunType()); |
| | | osdCheckResult.setCheckTime(osdResult.getCheckTime()); |
| | | osdCheckResult.setSetTime(osdResult.getOsdTime()); |
| | | osdCheckResult.setOsdProvince(osdResult.getOSD1()); |
| | | osdCheckResult.setOsdCity(osdResult.getOSD2()); |
| | | osdCheckResult.setOsdPart(osdResult.getOSD3()); |
| | | osdCheckResult.setOsdLB(osdResult.getOSD4()); |
| | | osdCheckResult.setOsdName(osdResult.getName()); |
| | | osdCheckResult.setDeviceBrand(osdResult.getDeviceBrand()); |
| | | return osdCheckResult; |
| | | } |
| | | |
| | | private void checkCorrect(OSDResult osdResult, TMonitor monitor, OsdCheckResult osdCheckResult) { |
| | | //检查时间是否正确 |
| | | if (osdResult.getCheckTime() != null && osdResult.getOsdTime() != null) { |
| | | long checkTime = osdResult.getCheckTime().getTime(); |
| | | long osdTime = osdResult.getOsdTime().getTime(); |
| | | long timeDiff = (checkTime - osdTime) / 1000; |
| | | if (timeDiff <= 60) { |
| | | osdCheckResult.setOsdTimeCorrect(ApiConstants.OSD_Correct); |
| | | } else { |
| | | osdCheckResult.setOsdTimeCorrect(ApiConstants.OSD_Error); |
| | | } |
| | | } |
| | | //检查通道名是否正确 |
| | | //校验规则,这里暂时不比较全景和细节两字。 |
| | | if (!StringUtils.isEmpty(osdResult.getName()) && !StringUtils.isEmpty(monitor.getName())) { |
| | | if (monitor.getName().equals(osdResult.getName()) || monitor.getName().replace("全景", "细节").equals(osdResult.getName()) || monitor.getName().replace("细节", "全景").equals(osdResult.getName())) { |
| | | osdCheckResult.setOsdNameCorrect(ApiConstants.OSD_Correct); |
| | | osdCheckResult.setOsdName(osdResult.getName()); |
| | | } else { |
| | | osdCheckResult.setOsdNameCorrect(ApiConstants.OSD_Error); |
| | | } |
| | | } |
| | | //检查省是否正确 |
| | | if (!StringUtils.isEmpty(osdResult.getOSD1())) { |
| | | if ("四川".equals(osdResult.getOSD1())) { |
| | | osdCheckResult.setOsdProvinceCorrect(ApiConstants.OSD_Correct); |
| | | } else { |
| | | osdCheckResult.setOsdProvinceCorrect(ApiConstants.OSD_Error); |
| | | } |
| | | } |
| | | //检查市是否正确 |
| | | if (!StringUtils.isEmpty(osdResult.getOSD2())) { |
| | | if ("自贡".equals(osdResult.getOSD2())) { |
| | | osdCheckResult.setOsdCityCorrect(ApiConstants.OSD_Correct); |
| | | } else { |
| | | osdCheckResult.setOsdCityCorrect(ApiConstants.OSD_Error); |
| | | } |
| | | } |
| | | //检查区县是否正确 |
| | | if (!StringUtils.isEmpty(osdResult.getOSD3())) { |
| | | AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromCode(monitor.getSerialNumber().substring(0, 6)); |
| | | if (areaDeptEnum != null && osdResult.getOSD3().equals(areaDeptEnum.getName())) { |
| | | osdCheckResult.setOsdPartCorrect(ApiConstants.OSD_Correct); |
| | | } else { |
| | | osdCheckResult.setOsdPartCorrect(ApiConstants.OSD_Error); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |