| | |
| | | package com.ycl.task; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.ycl.platform.domain.entity.Platform; |
| | | import com.ycl.platform.domain.entity.PlatformOnline; |
| | | import com.ycl.platform.mapper.PlatformMapper; |
| | | import com.ycl.platform.service.PlatformOnlineService; |
| | | import com.ycl.system.entity.SysDictData; |
| | | import com.ycl.system.service.impl.SysDictTypeServiceImpl; |
| | |
| | | public class PlatformTask { |
| | | |
| | | private final RedisTemplate redisTemplate; |
| | | private final SysDictTypeServiceImpl dictTypeService; |
| | | private final PlatformMapper platformMapper; |
| | | private final PlatformOnlineService platformOnlineService; |
| | | |
| | | /** |
| | |
| | | * @throws IOException |
| | | */ |
| | | public void ping() { |
| | | List<SysDictData> platformList = dictTypeService.selectDictDataByType(DICT_TYPE); |
| | | for (SysDictData platform : platformList) { |
| | | List<Platform> platformList = new LambdaQueryChainWrapper<>(platformMapper) |
| | | .isNotNull(Platform::getPlatformIP) |
| | | .list(); |
| | | for (Platform platform : platformList) { |
| | | executorService.submit(() -> { |
| | | try { |
| | | Boolean reachable = Boolean.FALSE; |
| | | for (int tryTimes = 1; tryTimes < 3; tryTimes++) { |
| | | // 三秒未ping通重试一次,如果不行才扣分 |
| | | reachable = InetAddress.getByName(platform.getDictValue()).isReachable(3000); |
| | | reachable = InetAddress.getByName(platform.getPlatformIP()).isReachable(3000); |
| | | if (! reachable && tryTimes == 0) { |
| | | continue; |
| | | } |
| | | if (! reachable) { |
| | | // 如果ping不通,离线时长加5秒 |
| | | redisTemplate.opsForValue().increment(REDIS_KEY_PREFIX + platform.getDictValue(), 5); |
| | | log.warn(platform.getDictLabel() + "平台未ping通"); |
| | | redisTemplate.opsForValue().increment(REDIS_KEY_PREFIX + platform.getPlatformIP(), 5); |
| | | log.warn(platform.getPlatformName() + "平台未ping通"); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | * |
| | | */ |
| | | public void synToMySQL() { |
| | | List<SysDictData> platformList = dictTypeService.selectDictDataByType(DICT_TYPE); |
| | | List<Platform> platformList = new LambdaQueryChainWrapper<>(platformMapper) |
| | | .isNotNull(Platform::getPlatformIP) |
| | | .list(); |
| | | // 将java.util.Date转换为java.sql.Date |
| | | java.sql.Date sqlDate = new java.sql.Date(new Date().getTime()); |
| | | |
| | | for (SysDictData platform : platformList) { |
| | | Object outLineTime = redisTemplate.opsForValue().get(REDIS_KEY_PREFIX + platform.getDictValue()); |
| | | for (Platform platform : platformList) { |
| | | Object outLineTime = redisTemplate.opsForValue().get(REDIS_KEY_PREFIX + platform.getPlatformIP()); |
| | | Integer outlineTimeSed = Objects.isNull(outLineTime) ? 0 : (Integer) outLineTime; |
| | | PlatformOnline one = new LambdaQueryChainWrapper<>(platformOnlineService.getBaseMapper()) |
| | | .eq(PlatformOnline::getPlatformIp, platform.getDictValue()) |
| | | .eq(PlatformOnline::getPlatformIp, platform.getPlatformIP()) |
| | | .eq(PlatformOnline::getCreateDate, sqlDate) |
| | | .one(); |
| | | if (Objects.isNull(one)) { |
| | | one = new PlatformOnline(); |
| | | one.setPlatformIp(platform.getDictValue()); |
| | | one.setPlatformName(platform.getDictLabel()); |
| | | one.setPlatformIp(platform.getPlatformIP()); |
| | | one.setPlatformName(platform.getPlatformName()); |
| | | one.setCreateDate(sqlDate); |
| | | one.setTodayOutlineSed(outlineTimeSed); |
| | | } else { |
| | | one.setTodayOutlineSed(one.getTodayOutlineSed() + outlineTimeSed); |
| | | } |
| | | one.setPlatformIp(platform.getDictValue()); |
| | | one.setPlatformName(platform.getDictLabel()); |
| | | one.setPlatformIp(platform.getPlatformIP()); |
| | | one.setPlatformName(platform.getPlatformName()); |
| | | one.setCreateDate(sqlDate); |
| | | |
| | | platformOnlineService.saveOrUpdate(one); |