| | |
| | | package com.ycl.task; |
| | | |
| | | |
| | | import com.mongodb.client.result.DeleteResult; |
| | | import com.ycl.api.DH.lib.NetSDKLib; |
| | | import com.ycl.api.DH.lib.structure.NET_CFG_GBMODE_INFO; |
| | | import com.ycl.api.DH.lib.structure.NET_GBMODE_CUSTOMTITLE_INFO; |
| | | import com.ycl.api.DH.lib.structure.NET_TITLE_OSD_INFO; |
| | | import com.ycl.api.DH.module.LoginModule; |
| | | 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.BaseResult; |
| | | 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.platform.service.YwPointService; |
| | | import com.ycl.thread.OSDCheckThread; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.StringUtils; |
| | | import constant.ApiConstants; |
| | | import constant.CheckConstants; |
| | | 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 java.nio.charset.StandardCharsets; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | 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; |
| | | |
| | | import static com.ycl.api.DH.lib.enumeration.NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_GBMODE; |
| | | |
| | | @Slf4j |
| | | @Component("OsdTask") |
| | | public class OsdTask { |
| | | public void getOSD() { |
| | | HKApi.getOsdByIP("51.95.68.80"); |
| | | 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; |
| | | @Autowired |
| | | private YwPointService pointService; |
| | | @Value("${HK.userName}") |
| | | public String HKUserName; |
| | | @Value("${HK.password}") |
| | | public String HKPassword; |
| | | @Value("${DH.userName}") |
| | | public String DHUserName; |
| | | @Value("${DH.password}") |
| | | public String DHPassword; |
| | | @Value("${YS.userName}") |
| | | public String YSUserName; |
| | | @Value("${YS.password}") |
| | | public String YSPassword; |
| | | |
| | | /** |
| | | * 通过查mongoDB每日一机一档数据获取设备ip |
| | | * 筛选视频设备 |
| | | * 通过设备ip、品牌调用不同api获取osd信息 |
| | | * 比对mongoDB一机一档信息,整理成result存入mongo |
| | | * 同步品牌到mysql |
| | | */ |
| | | public void getOSD() throws ExecutionException, InterruptedException { |
| | | log.info("开始获取OSD"); |
| | | // //海康设备测试 |
| | | // //全景 |
| | | // OSDResult osd1 = HKApi.getOsdByIP("51031140001320359101","51.95.99.112", HKUserName, HKPassword); |
| | | // log.info("海康全景:{}",osd1); |
| | | // //细节 |
| | | // OSDResult osd2 = HKApi.getOsdByIP("51031140001321359101","51.95.99.112", HKUserName, HKPassword); |
| | | // log.info("海康细节:{}",osd2); |
| | | // //大华设备测试 |
| | | // OSDResult osd3 = DHApi.getOsd("51030244001320120201","51.95.4.3", DHUserName, DHPassword); |
| | | // log.info("大华全景:{}",osd3); |
| | | // OSDResult osd4 = DHApi.getOsd("51030244001321120201","51.95.4.3", DHUserName, DHPassword); |
| | | // log.info("大华细节:{}",osd4); |
| | | //查一机一档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) { |
| | | if (osdResult != null) { |
| | | TMonitor monitor = monitorMap.get(osdResult.getSerialNumber()); |
| | | //封装OsdCheckResult |
| | | OsdCheckResult osdCheckResult = getOsdCheckResult(osdResult, monitor); |
| | | checkCorrect(osdResult, monitor, 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()))); |
| | | List<OsdCheckResult> osdCheckResults = mongoTemplate.find(pyQuery, OsdCheckResult.class); |
| | | pointService.setDeviceTagByGB(checkResults, CheckConstants.Rule_Category_Video); |
| | | //添加旧数据进去 |
| | | List<String> resultNos = checkResults.stream().map(BaseResult::getNo).collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(osdCheckResults)) { |
| | | for (OsdCheckResult mongoResult : osdCheckResults) { |
| | | //如果新的结果中没有旧数据那么加进去 |
| | | if (!resultNos.contains(mongoResult.getNo())) { |
| | | checkResults.add(mongoResult); |
| | | } |
| | | } |
| | | } |
| | | 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.setNo(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 = Math.abs((checkTime - osdTime) / 1000); |
| | | if (timeDiff <= 60) { |
| | | osdCheckResult.setOsdTimeCorrect(ApiConstants.OSD_Correct); |
| | | } else { |
| | | osdCheckResult.setOsdTimeCorrect(ApiConstants.OSD_Error); |
| | | } |
| | | } else { |
| | | osdCheckResult.setOsdTimeCorrect(ApiConstants.OSD_Unknown); |
| | | } |
| | | //检查通道名是否正确 |
| | | if (!StringUtils.isEmpty(osdResult.getName()) && !StringUtils.isEmpty(monitor.getName())) { |
| | | if (monitor.getName().equals(osdResult.getName())) { |
| | | osdCheckResult.setOsdNameCorrect(ApiConstants.OSD_Correct); |
| | | osdCheckResult.setOsdName(osdResult.getName()); |
| | | } else { |
| | | osdCheckResult.setOsdNameCorrect(ApiConstants.OSD_Error); |
| | | } |
| | | } else { |
| | | osdCheckResult.setOsdNameCorrect(ApiConstants.OSD_Unknown); |
| | | } |
| | | //检查省是否正确 |
| | | if (!StringUtils.isEmpty(osdResult.getOSD1())) { |
| | | if ("四川".equals(osdResult.getOSD1())) { |
| | | osdCheckResult.setOsdProvinceCorrect(ApiConstants.OSD_Correct); |
| | | } else { |
| | | osdCheckResult.setOsdProvinceCorrect(ApiConstants.OSD_Error); |
| | | } |
| | | } else { |
| | | osdCheckResult.setOsdProvinceCorrect(ApiConstants.OSD_Unknown); |
| | | } |
| | | //检查市是否正确 |
| | | if (!StringUtils.isEmpty(osdResult.getOSD2())) { |
| | | if ("自贡".equals(osdResult.getOSD2())) { |
| | | osdCheckResult.setOsdCityCorrect(ApiConstants.OSD_Correct); |
| | | } else { |
| | | osdCheckResult.setOsdCityCorrect(ApiConstants.OSD_Error); |
| | | } |
| | | } else { |
| | | osdCheckResult.setOsdCityCorrect(ApiConstants.OSD_Unknown); |
| | | } |
| | | //检查区县是否正确 |
| | | if (!StringUtils.isEmpty(osdResult.getOSD3())) { |
| | | AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromCode(monitor.getSerialNumber().substring(0, 6)); |
| | | if (areaDeptEnum != null && osdResult.getOSD3().equals(areaDeptEnum.getOsdName())) { |
| | | osdCheckResult.setOsdPartCorrect(ApiConstants.OSD_Correct); |
| | | } else { |
| | | osdCheckResult.setOsdPartCorrect(ApiConstants.OSD_Error); |
| | | } |
| | | } else { |
| | | osdCheckResult.setOsdPartCorrect(ApiConstants.OSD_Unknown); |
| | | } |
| | | } |
| | | |
| | | |
| | | public void test() throws ExecutionException, InterruptedException { |
| | | log.info("测试获取OSD"); |
| | | OSDResult osd3 = DHApi.getOsdOld("51030340001320207201", "51.95.34.20", DHUserName, DHPassword); |
| | | log.info("osd3:{}", osd3); |
| | | OSDResult osd4 = DHApi.getOsdOld("51030342001320173201", "51.95.33.174", DHUserName, DHPassword); |
| | | log.info("osd4:{}", osd4); |
| | | } |
| | | } |