|
|
@@ -1,19 +1,12 @@
|
|
|
package com.xunmei.host.server.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import com.alibaba.nacos.api.exception.NacosException;
|
|
|
-import com.alibaba.nacos.api.naming.NamingService;
|
|
|
-import com.alibaba.nacos.api.naming.pojo.Instance;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.Constants;
|
|
|
-import com.xunmei.common.core.constant.ServiceNameConstants;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotServerInfo;
|
|
|
import com.xunmei.common.core.enums.iot.IotServerConnectStatus;
|
|
|
-import com.xunmei.common.core.utils.JacksonUtils;
|
|
|
import com.xunmei.common.core.utils.uuid.UUID;
|
|
|
import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.host.server.mapper.IotServerInfoMapper;
|
|
|
@@ -24,15 +17,10 @@ import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.web.client.RestClientException;
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -45,11 +33,11 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, IotServerInfo> implements IotServerInfoService {
|
|
|
|
|
|
- @Resource
|
|
|
+/* @Autowired
|
|
|
private NamingService namingService;
|
|
|
|
|
|
- @Resource
|
|
|
- private RestTemplate restTemplate;
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;*/
|
|
|
|
|
|
@Override
|
|
|
public IotServerInfo getToken(String registerCode) {
|
|
|
@@ -141,9 +129,8 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
public void checkWsOnLine() {
|
|
|
- List<Instance> instanceList = new ArrayList<>();
|
|
|
+ /* List<Instance> instanceList = new ArrayList<>();
|
|
|
try {
|
|
|
instanceList = namingService.getAllInstances(ServiceNameConstants.HOST);
|
|
|
} catch (NacosException e) {
|
|
|
@@ -159,19 +146,19 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
|
|
|
} catch (RuntimeException e) {
|
|
|
LogUtils.SOCKET_CONNECT_STATUS_CHECK.error("获取服务上WS链接状态时异常", e);
|
|
|
throw new RuntimeException(e);
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
- private List<String> getOnlineWs(List<Instance> instanceList) throws RuntimeException {
|
|
|
+ /*private List<String> getOnlineWs(List<Instance> instanceList) throws RuntimeException {
|
|
|
//多线程远程调用获取服务状态
|
|
|
List<String> onlineWS = new ArrayList<>();
|
|
|
for (Instance instance : instanceList) {
|
|
|
List<String> list = null;
|
|
|
try {
|
|
|
list = restTemplate.getForObject(instance.getIp() + ":" + instance.getPort() + "/getOnlineWs", List.class);
|
|
|
- LogUtils.SOCKET_CONNECT_STATUS_CHECK.error("获取当前系统在线的WS链接:{}", JacksonUtils.toJSONString(list));
|
|
|
+ LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("获取当前系统在线的WS链接:{}", JacksonUtils.toJSONString(list));
|
|
|
} catch (RestClientException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
@@ -183,8 +170,10 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
|
|
|
return onlineWS;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private void updateWsOnlineStatus(List<String> onlineIotCode) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void updateWsOnlineStatus(List<String> onlineIotCode) {
|
|
|
+ //获取当前在线的WS
|
|
|
+ final List<IotServerInfo> infoList = selectOnlineServer(null);
|
|
|
if (ObjectUtil.isEmpty(onlineIotCode)) {
|
|
|
final LambdaUpdateWrapper<IotServerInfo> wrapper = new LambdaUpdateWrapper<IotServerInfo>();
|
|
|
wrapper.set(IotServerInfo::getIotStatus, IotServerConnectStatus.OFFLINE.getIdx());
|
|
|
@@ -194,8 +183,7 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
|
|
|
LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("检测WS链接状态时,发现没有在线的链接,修改所有链接为离线");
|
|
|
return;
|
|
|
}
|
|
|
- //获取当前在线的WS
|
|
|
- final List<IotServerInfo> infoList = selectOnlineServer(null);
|
|
|
+
|
|
|
//获取唯一标识
|
|
|
final List<String> collect = infoList.stream().map(IotServerInfo::getIotCode).collect(Collectors.toList());
|
|
|
//如果数据库中标识为当前在线的WS链接 并不存在于从所有实例汇总到的在线的WS链接中 则更新为离线
|
|
|
@@ -218,5 +206,5 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
|
|
|
wrapper.in(IotServerInfo::getIotCode, onlineIotCode);
|
|
|
baseMapper.update(null, wrapper);
|
|
|
LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("修改在线的WS连接的检测时间:{}", JacksonUtils.toJSONString(onlineIotCode));
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|