| | |
| | | package com.ycl.utils; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.ycl.platform.domain.entity.DeviceInfo; |
| | | import com.ycl.platform.domain.entity.TMonitor; |
| | | import com.ycl.platform.domain.result.SYS.TMonitorResult; |
| | | import com.ycl.platform.domain.vo.CheckResult; |
| | | import com.ycl.platform.domain.vo.CheckUtil; |
| | | import com.ycl.platform.mapper.DeviceInfoMapper; |
| | | import com.ycl.platform.mapper.TMonitorMapper; |
| | | import com.ycl.platform.service.WorkOrderService; |
| | | import com.ycl.utils.http.SelfHttpUtil; |
| | | import com.ycl.utils.uuid.IdUtils; |
| | | import constant.RedisConstant; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | import java.io.IOException; |
| | | import java.net.InetAddress; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.net.UnknownHostException; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author xp |
| | |
| | | public class CheckPointUtil { |
| | | |
| | | private final RedisTemplate redisTemplate; |
| | | |
| | | private final SelfHttpUtil selfHttpUtil; |
| | | private final DeviceInfoMapper deviceInfoMapper; |
| | | private final WorkOrderService workOrderService; |
| | | private final TMonitorMapper monitorMapper; |
| | | |
| | | /** |
| | | * 监测点位在线工具类 |
| | |
| | | monitor.setOffLineCount(offLineTimes); |
| | | return monitor; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 监测点位在线 |
| | | * @return |
| | | */ |
| | | public CheckResult webCheck(CheckUtil checkUtil) { |
| | | CheckResult result = new CheckResult(); |
| | | List<TMonitor> ips = new LambdaQueryChainWrapper<>(monitorMapper) |
| | | .eq(TMonitor::getSerialNumber, checkUtil.getSerialNumber()) |
| | | .list(); |
| | | if (ips.size() < 1) { |
| | | result.setStatus("国标码未查找到IP"); |
| | | return result; |
| | | } |
| | | checkUtil.setIp(ips.get(0).getIp()); |
| | | |
| | | log.info("监测IP:" + checkUtil.getIp()); |
| | | String prefix = "http://"; |
| | | if ("127.0.0.1".equals(checkUtil.getIp())) { |
| | | result.setStatus("ip异常"); |
| | | return result; |
| | | } |
| | | boolean webReachable = false; |
| | | try { |
| | | ResponseEntity<Object> res = selfHttpUtil.get(prefix + checkUtil.getIp(), null, null); |
| | | webReachable = Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode(); |
| | | } catch (Exception e) { |
| | | webReachable = Boolean.FALSE; |
| | | } |
| | | // ping |
| | | boolean pingReachable = false; |
| | | try { |
| | | InetAddress inet = InetAddress.getByName(checkUtil.getIp()); |
| | | pingReachable = inet.isReachable(5000); // 5000毫秒超时时间 |
| | | } catch (UnknownHostException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | String imgUrl = ""; |
| | | // 查出国标设备,就一条数据 |
| | | List<DeviceInfo> gbDevices = new LambdaQueryChainWrapper<>(deviceInfoMapper) |
| | | .orderByDesc(DeviceInfo::getUpdateTime) |
| | | .last("limit 1") |
| | | .list(); |
| | | if (! CollectionUtils.isEmpty(gbDevices)) { |
| | | try { |
| | | imgUrl = workOrderService.getFrameImgByDevice(gbDevices.get(0).getDeviceId(), checkUtil.getSerialNumber(), IdUtils.workOrderNO(new Date(), "99999")); |
| | | result.setImg(imgUrl); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | String status = ""; |
| | | if (! webReachable) { |
| | | status += "设备web访问失败;"; |
| | | } |
| | | if (! pingReachable) { |
| | | status += "设备ip未ping通;"; |
| | | } |
| | | if (StringUtils.isEmpty(imgUrl)) { |
| | | status += "未获取到图片"; |
| | | } |
| | | result.setStatus(status); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * ping |
| | | * |
| | | * @return |
| | | */ |
| | | public CheckResult ping(CheckUtil checkUtil) { |
| | | CheckResult result = new CheckResult(); |
| | | |
| | | log.info("监测IP:" + checkUtil.getIp()); |
| | | String prefix = "http://"; |
| | | if ("127.0.0.1".equals(checkUtil.getIp())) { |
| | | result.setStatus("ip异常"); |
| | | return result; |
| | | } |
| | | // ping |
| | | boolean pingReachable = false; |
| | | try { |
| | | InetAddress inet = InetAddress.getByName(checkUtil.getIp()); |
| | | pingReachable = inet.isReachable(5000); // 5000毫秒超时时间 |
| | | } catch (UnknownHostException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String status = ""; |
| | | if (! pingReachable) { |
| | | status += "ip未ping通;"; |
| | | } |
| | | result.setStatus(status); |
| | | return result; |
| | | } |
| | | } |