| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.mongodb.client.result.DeleteResult; |
| | | import com.ycl.feign.UYClient; |
| | | import com.ycl.platform.domain.entity.YwPoint; |
| | | import com.ycl.platform.domain.param.UY.*; |
| | | import com.ycl.platform.domain.result.HK.FaceDeviceInspectionResult; |
| | | import com.ycl.platform.domain.result.UY.OneMachineFileResult; |
| | | import com.ycl.platform.domain.result.UY.OsdMonitorResult; |
| | | import com.ycl.platform.domain.result.UY.RecordMetaDSumResult; |
| | | import com.ycl.platform.domain.result.UY.*; |
| | | import com.ycl.platform.service.ITMonitorService; |
| | | import com.ycl.platform.service.IYwThresholdService; |
| | | import com.ycl.platform.domain.vo.UpdateOnlineVO; |
| | | import com.ycl.platform.mapper.TMonitorMapper; |
| | | import com.ycl.platform.service.UYErrorTypeCheckService; |
| | | import com.ycl.platform.service.YwPointService; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.http.HttpUtils; |
| | | import com.ycl.utils.http.SelfHttpUtil; |
| | | import constant.ApiConstants; |
| | | import lombok.RequiredArgsConstructor; |
| | | 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.format.annotation.DateTimeFormat; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.HttpStatusCode; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.InetAddress; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.ArrayBlockingQueue; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | //优云对接数据任务 |
| | | @Slf4j |
| | | @Component("UYTask") |
| | | @RequiredArgsConstructor |
| | | public class UYTask { |
| | | |
| | | @Autowired |
| | | private MongoTemplate mongoTemplate; |
| | | @Autowired |
| | | private UYClient uyClient; |
| | | @Autowired |
| | | private IYwThresholdService ywThresholdService; |
| | | @Autowired |
| | | private ITMonitorService monitorService; |
| | | @Autowired |
| | | private UYErrorTypeCheckService uyErrorTypeCheckService; |
| | | private final MongoTemplate mongoTemplate; |
| | | private final UYClient uyClient; |
| | | private final UYErrorTypeCheckService uyErrorTypeCheckService; |
| | | private final YwPointService pointService; |
| | | private final TMonitorMapper monitorMapper; |
| | | private final SelfHttpUtil selfHttpUtil; |
| | | |
| | | @Value("${youYun.tenantId}") |
| | | private String tenantId; |
| | |
| | | @Value("${youYun.passwd}") |
| | | private String passwd; |
| | | |
| | | private static final ExecutorService executorService = new ThreadPoolExecutor(16, |
| | | 128, |
| | | 5000, |
| | | TimeUnit.SECONDS, |
| | | new ArrayBlockingQueue<>(1000), |
| | | new ThreadPoolExecutor.CallerRunsPolicy() |
| | | ); |
| | | |
| | | // 图像检测 |
| | | public void imageDetection() { |
| | | log.info("开始执行图像检测数据同步"); |
| | | // ImageDetectionParam param = new ImageDetectionParam(); |
| | | // param.setPageNum(ApiConstants.PageNo); |
| | | // param.setPageSize(ApiConstants.PageSize); |
| | | // param.setArealayerno(ApiConstants.AreaNo); |
| | | // JSONObject jsonObject = uyClient.imageDetection(param); |
| | | // if (jsonObject != null) { |
| | | // log.info("数据格式" + jsonObject); |
| | | // Integer statusCode = jsonObject.getInteger("statusCode"); |
| | | // if (ApiConstants.UYSuccessCode.equals(statusCode)) { |
| | | // JSONObject data = jsonObject.getJSONObject("data"); |
| | | // if (data != null) { |
| | | // List<ImageDetectionResult> records = data.getList("records", ImageDetectionResult.class); |
| | | // if (!CollectionUtils.isEmpty(records)) { |
| | | // //如果今天存在之前的数据先删除 |
| | | // Query query = new Query(Criteria |
| | | // .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | // DeleteResult result = mongoTemplate.remove(query, ImageDetectionResult.class); |
| | | // //存放在mongo中 |
| | | // mongoTemplate.insertAll(records); |
| | | // // 工单生成 |
| | | // uyErrorTypeCheckService.imageDetectionCheck(records); |
| | | // } else { |
| | | // log.error("图像监测数据为空{}", data); |
| | | // } |
| | | // } else { |
| | | // log.error("图像监测数据为空{}", jsonObject); |
| | | // } |
| | | // } else { |
| | | // log.error("图像监测请求失败{}", jsonObject); |
| | | // } |
| | | // } else { |
| | | // log.error("图像监测数据为空"); |
| | | // } |
| | | Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); |
| | | uyErrorTypeCheckService.imageDetectionCheck(mongoTemplate.find(query, ImageDetectionResult.class)); |
| | | ImageDetectionParam param = new ImageDetectionParam(); |
| | | param.setPageNum(ApiConstants.PageNo); |
| | | param.setPageSize(ApiConstants.PageSize); |
| | | param.setArealayerno(ApiConstants.AreaNo); |
| | | JSONObject jsonObject = uyClient.imageDetection(param); |
| | | if (jsonObject != null) { |
| | | log.info("数据格式" + jsonObject); |
| | | Integer statusCode = jsonObject.getInteger("statusCode"); |
| | | if (ApiConstants.UYSuccessCode.equals(statusCode)) { |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | if (data != null) { |
| | | List<ImageDetectionResult> records = data.getList("records", ImageDetectionResult.class); |
| | | if (!CollectionUtils.isEmpty(records)) { |
| | | //如果今天存在之前的数据先删除 |
| | | Query query = new Query(Criteria |
| | | .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | DeleteResult result = mongoTemplate.remove(query, ImageDetectionResult.class); |
| | | records.stream().forEach(item -> { |
| | | if (Objects.nonNull(item.getDeviceId())) { |
| | | item.setNo(item.getDeviceId()); |
| | | } |
| | | }); |
| | | pointService.setDeviceTagByGB(records); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(records); |
| | | // 工单生成 |
| | | uyErrorTypeCheckService.imageDetectionCheck(records); |
| | | } else { |
| | | log.error("图像监测数据为空{}", data); |
| | | } |
| | | } else { |
| | | log.error("图像监测数据为空{}", jsonObject); |
| | | } |
| | | } else { |
| | | log.error("图像监测请求失败{}", jsonObject); |
| | | } |
| | | } else { |
| | | log.error("图像监测数据为空"); |
| | | } |
| | | // 本地测试 |
| | | // Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); |
| | | // uyErrorTypeCheckService.imageDetectionCheck(mongoTemplate.find(query, ImageDetectionResult.class)); |
| | | log.info("结束执行图像监测数据同步"); |
| | | } |
| | | |
| | |
| | | // 一机一档注册率 |
| | | // 档案考核比 |
| | | log.info("开始执行一机一档合格率数据同步"); |
| | | // MonitorQualifyParam param = new MonitorQualifyParam(); |
| | | // param.setPageNum(ApiConstants.PageNo); |
| | | // param.setPageSize(ApiConstants.PageSize); |
| | | // JSONObject jsonObject = uyClient.monitorQualify(param); |
| | | // if (jsonObject != null) { |
| | | // String code = jsonObject.getString("code"); |
| | | // if (ApiConstants.UYSuccessCodeStr.equals(code)) { |
| | | // JSONObject data = jsonObject.getJSONObject("data"); |
| | | // if (data != null) { |
| | | // List<MonitorQualifyResult> records = data.getList("records", MonitorQualifyResult.class); |
| | | // if (!CollectionUtils.isEmpty(records)) { |
| | | // //如果今天存在之前的数据先删除 |
| | | // Query query = new Query(Criteria |
| | | // .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | // DeleteResult result = mongoTemplate.remove(query, MonitorQualifyResult.class); |
| | | // //存放在mongo中 |
| | | // mongoTemplate.insertAll(records); |
| | | // // 工单生成 |
| | | // uyErrorTypeCheckService.monitorQualifyCheck(records); |
| | | // } else { |
| | | // log.error("一机一档合格率数据为空{}", data); |
| | | // } |
| | | // } |
| | | // } else { |
| | | // log.error("一机一档合格率数据为空{}", jsonObject); |
| | | // } |
| | | // } else { |
| | | // log.error("一机一档合格率数据为空"); |
| | | // } |
| | | Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); |
| | | uyErrorTypeCheckService.monitorQualifyCheck(mongoTemplate.find(query, MonitorQualifyResult.class)); |
| | | MonitorQualifyParam param = new MonitorQualifyParam(); |
| | | param.setPageNum(ApiConstants.PageNo); |
| | | param.setPageSize(ApiConstants.PageSize); |
| | | JSONObject jsonObject = uyClient.monitorQualify(param); |
| | | if (jsonObject != null) { |
| | | String code = jsonObject.getString("code"); |
| | | if (ApiConstants.UYSuccessCodeStr.equals(code)) { |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | if (data != null) { |
| | | List<MonitorQualifyResult> records = data.getList("records", MonitorQualifyResult.class); |
| | | if (!CollectionUtils.isEmpty(records)) { |
| | | //如果今天存在之前的数据先删除 |
| | | Query query = new Query(Criteria |
| | | .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | DeleteResult result = mongoTemplate.remove(query, MonitorQualifyResult.class); |
| | | records.stream().forEach(item -> { |
| | | if (Objects.nonNull(item.getSerialNumber())) { |
| | | item.setNo(item.getSerialNumber().getShowValue()); |
| | | } |
| | | }); |
| | | pointService.setDeviceTagByGB(records); |
| | | pointService.setNew(records); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(records); |
| | | // 工单生成 |
| | | uyErrorTypeCheckService.monitorQualifyCheck(records); |
| | | } else { |
| | | log.error("一机一档合格率数据为空{}", data); |
| | | } |
| | | } |
| | | } else { |
| | | log.error("一机一档合格率数据为空{}", jsonObject); |
| | | } |
| | | } else { |
| | | log.error("一机一档合格率数据为空"); |
| | | } |
| | | // 本地测试 |
| | | // Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); |
| | | // uyErrorTypeCheckService.monitorQualifyCheck(mongoTemplate.find(query, MonitorQualifyResult.class)); |
| | | log.info("结束一机一档合格率数据同步"); |
| | | } |
| | | |
| | | /** |
| | | * 点位在线检测 |
| | | */ |
| | | public void pointOnline() { |
| | | log.info("开始检测点位在线"); |
| | | // 先查出设备IP集合 |
| | | List<String> ipList = monitorMapper.getDistinctIP(); |
| | | String prefix = "http://"; |
| | | Date now = new Date(); |
| | | for (String ip : ipList) { |
| | | executorService.submit(() -> { |
| | | // 先检测能否访问该ip的网页 |
| | | ResponseEntity<Object> res = null; |
| | | UpdateOnlineVO online = new UpdateOnlineVO(); |
| | | online.setIp(ip); |
| | | if ("127.0.0.1".equals(ip)) { |
| | | online.setOnline(Boolean.FALSE); |
| | | monitorMapper.updateOnline(online); |
| | | return; |
| | | } |
| | | try { |
| | | res = selfHttpUtil.get(prefix + ip, null, null); |
| | | online.setOnline(Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode()); |
| | | } catch (Exception e) { |
| | | online.setOnline(Boolean.FALSE); |
| | | } |
| | | online.setUpdateTime(now); |
| | | |
| | | // 如果http得到的不在线,那么再ping一下 |
| | | boolean reachable = false; |
| | | if (! online.getOnline()) { |
| | | try { |
| | | reachable = InetAddress.getByName(ip).isReachable(3000); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | online.setOnline(reachable); |
| | | } |
| | | monitorMapper.updateOnline(online); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | //点位在线率 |
| | |
| | | } else { |
| | | log.error("点位在线结果数据为空"); |
| | | } |
| | | Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); |
| | | uyErrorTypeCheckService.videoOnlineCheck(mongoTemplate.find(query, VideoOnlineResult.class)); |
| | | // 本地测试 |
| | | // Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); |
| | | // uyErrorTypeCheckService.videoOnlineCheck(mongoTemplate.find(query, VideoOnlineResult.class)); |
| | | log.info("结束执行点位在线数据同步"); |
| | | } |
| | | |
| | |
| | | public void recordMetaDSumTask() { |
| | | //录像可用率 |
| | | log.info("开始执行录像可用数据同步"); |
| | | // RecordMetaDSumParam param = new RecordMetaDSumParam(); |
| | | // param.setTenantId(tenantId); |
| | | // Calendar instance = Calendar.getInstance(); |
| | | // instance.setTime(new Date()); |
| | | // instance.add(Calendar.DAY_OF_MONTH, -1); |
| | | // SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // String yesterday = format.format(instance.getTime()); |
| | | // param.setStatTime(yesterday); |
| | | // JSONObject jsonObject = uyClient.recordMetaDSumList(param); |
| | | // if (jsonObject != null) { |
| | | // if (ApiConstants.UYSuccessCodeStr.equals(jsonObject.getString("code"))) { |
| | | // List<RecordMetaDSumResult> records = jsonObject.getList("data", RecordMetaDSumResult.class); |
| | | // if (!CollectionUtils.isEmpty(records)) { |
| | | // //如果今天存在之前的数据先删除 |
| | | // Query query = new Query(Criteria |
| | | // .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | // DeleteResult result = mongoTemplate.remove(query, RecordMetaDSumResult.class); |
| | | // //存放在mongo中 |
| | | // mongoTemplate.insertAll(records); |
| | | // // 工单生成 |
| | | // uyErrorTypeCheckService.recordMetaDSumCheck(records); |
| | | // } |
| | | // } else { |
| | | // log.error("录像可用数据为空{}", jsonObject); |
| | | // } |
| | | // } |
| | | Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); |
| | | uyErrorTypeCheckService.recordMetaDSumCheck(mongoTemplate.find(query, RecordMetaDSumResult.class)); |
| | | RecordMetaDSumParam param = new RecordMetaDSumParam(); |
| | | param.setTenantId(tenantId); |
| | | Calendar instance = Calendar.getInstance(); |
| | | instance.setTime(new Date()); |
| | | instance.add(Calendar.DAY_OF_MONTH, -1); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String yesterday = format.format(instance.getTime()); |
| | | param.setStatTime(yesterday); |
| | | JSONObject jsonObject = uyClient.recordMetaDSumList(param); |
| | | if (jsonObject != null) { |
| | | if (ApiConstants.UYSuccessCodeStr.equals(jsonObject.getString("code"))) { |
| | | List<RecordMetaDSumResult> records = jsonObject.getList("data", RecordMetaDSumResult.class); |
| | | if (!CollectionUtils.isEmpty(records)) { |
| | | //如果今天存在之前的数据先删除 |
| | | Query query = new Query(Criteria |
| | | .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | DeleteResult result = mongoTemplate.remove(query, RecordMetaDSumResult.class); |
| | | records.stream().forEach(item -> { |
| | | if (Objects.nonNull(item.getDeviceId())) { |
| | | item.setNo(item.getDeviceId()); |
| | | } |
| | | }); |
| | | pointService.setDeviceTagByGB(records); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(records); |
| | | // 工单生成 |
| | | uyErrorTypeCheckService.recordMetaDSumCheck(records); |
| | | } |
| | | } else { |
| | | log.error("录像可用数据为空{}", jsonObject); |
| | | } |
| | | } |
| | | // 本地测试 |
| | | // Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); |
| | | // uyErrorTypeCheckService.recordMetaDSumCheck(mongoTemplate.find(query, RecordMetaDSumResult.class)); |
| | | log.info("结束执行录像可用数据同步"); |
| | | } |
| | | |
| | | |
| | | //视频标注 |
| | | public void OsdMonitorTask() { |
| | | //视频标注 |
| | | log.info("开始执行视频标注数据同步"); |
| | | OsdMonitorParam param = new OsdMonitorParam(); |
| | | param.setPageNum(ApiConstants.PageNo); |
| | | param.setPageSize(ApiConstants.PageSize); |
| | | JSONObject jsonObject = uyClient.osdMonitorList(param, tenantId); |
| | | if (jsonObject != null) { |
| | | if (ApiConstants.UYSuccessCodeStr.equals(jsonObject.getString("code"))) { |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | if (data != null) { |
| | | List<OsdMonitorResult> records = data.getList("records", OsdMonitorResult.class); |
| | | if (!CollectionUtils.isEmpty(records)) { |
| | | //如果今天存在之前的数据先删除 |
| | | Query query = new Query(Criteria |
| | | .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | DeleteResult result = mongoTemplate.remove(query, OsdMonitorResult.class); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(records); |
| | | } else { |
| | | log.error("视频标注数据为空{}", data); |
| | | } |
| | | } else { |
| | | log.error("视频标注数据为空{}", jsonObject); |
| | | } |
| | | } else { |
| | | log.error("视频标注数据为空{}", jsonObject); |
| | | } |
| | | } else { |
| | | log.error("视频标注数据为空"); |
| | | } |
| | | log.info("结束执行视频标注数据同步"); |
| | | } |
| | | |
| | | } |