| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.mongodb.client.result.DeleteResult; |
| | | import com.ycl.feign.UYClient; |
| | | import com.ycl.platform.domain.entity.TMonitor; |
| | | import com.ycl.platform.domain.entity.WorkOrder; |
| | | 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.OnlineThreadVO; |
| | | import com.ycl.platform.domain.vo.UpdateOnlineVO; |
| | | import com.ycl.platform.mapper.TMonitorMapper; |
| | | import com.ycl.platform.service.UYErrorTypeCheckService; |
| | | import com.ycl.platform.service.WorkOrderService; |
| | | import com.ycl.platform.service.YwPointService; |
| | | import com.ycl.system.domain.SysConfig; |
| | | import com.ycl.system.mapper.SysConfigMapper; |
| | | import com.ycl.thread.OnlineCheckThread; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.http.HttpUtils; |
| | | import com.ycl.utils.http.SelfHttpUtil; |
| | | import constant.ApiConstants; |
| | | import constant.RedisConstant; |
| | | 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.data.redis.core.RedisTemplate; |
| | | 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.*; |
| | | import java.util.concurrent.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | //优云对接数据任务 |
| | | @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; |
| | | private final RedisTemplate redisTemplate; |
| | | private final WorkOrderService workOrderService; |
| | | private final SysConfigMapper sysConfigMapper; |
| | | |
| | | @Value("${youYun.tenantId}") |
| | | private String tenantId; |
| | |
| | | private String email; |
| | | @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() { |
| | |
| | | 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); |
| | | // 工单生成 |
| | |
| | | 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); |
| | | // 工单生成 |
| | |
| | | // Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); |
| | | // uyErrorTypeCheckService.monitorQualifyCheck(mongoTemplate.find(query, MonitorQualifyResult.class)); |
| | | log.info("结束一机一档合格率数据同步"); |
| | | } |
| | | |
| | | /** |
| | | * 点位在线检测 |
| | | */ |
| | | public void pointOnline() throws ExecutionException, InterruptedException { |
| | | log.info("开始检测点位在线"); |
| | | Integer times = 2; |
| | | SysConfig config = new SysConfig(); |
| | | config.setConfigKey("DAY_OF_POINT_OUTLINE_TIMES"); |
| | | SysConfig sysConfig = sysConfigMapper.selectConfig(config); |
| | | if (Objects.nonNull(sysConfig)) { |
| | | times = Integer.valueOf(sysConfig.getConfigValue()); |
| | | } else { |
| | | log.error("请配置离线次数,此次设置为默认值2"); |
| | | } |
| | | // 先查出设备IP集合 |
| | | List<TMonitor> monitorList = monitorMapper.getDistinctIP(); |
| | | List<Future<OnlineThreadVO>> futureList = new ArrayList<>(48); |
| | | List<OnlineThreadVO> dataList = new ArrayList<>(48); |
| | | for (TMonitor monitor : monitorList) { |
| | | OnlineCheckThread thread = new OnlineCheckThread(monitor, redisTemplate, selfHttpUtil, times); |
| | | Future<OnlineThreadVO> future = executorService.submit(thread); |
| | | futureList.add(future); |
| | | } |
| | | for (Future<OnlineThreadVO> future : futureList) { |
| | | dataList.add(future.get()); // get方法会阻塞,知道拿到结果才继续执行for |
| | | } |
| | | |
| | | // 更新point表的在线标识 |
| | | Date now = new Date(); |
| | | List<UpdateOnlineVO> willUpdateList = dataList.stream().map(item -> { |
| | | UpdateOnlineVO vo = new UpdateOnlineVO(); |
| | | vo.setOnline(item.getOnline()); |
| | | vo.setIp(item.getIp()); |
| | | vo.setUpdateTime(now); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | monitorMapper.updateOnline(willUpdateList); |
| | | |
| | | // 工单 |
| | | List<WorkOrder> workOrderList = dataList.stream() |
| | | .filter(item -> Objects.nonNull(item.getWorkOrder())) |
| | | .map(OnlineThreadVO::getWorkOrder) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(workOrderList)) { |
| | | return; |
| | | } |
| | | workOrderService.innerAddWorkOrder(workOrderList); |
| | | log.info("点位在线监测完成"); |
| | | } |
| | | |
| | | //点位在线率 |
| | |
| | | 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); |
| | | // 工单生成 |
| | |
| | | log.info("结束执行录像可用数据同步"); |
| | | } |
| | | |
| | | |
| | | |
| | | } |