|
@@ -0,0 +1,107 @@
|
|
|
+package com.dc.datachange.remote;
|
|
|
+
|
|
|
+import com.dc.datachange.core.exchange.DataManager;
|
|
|
+import com.dc.datachange.core.exchange.SendExecutor;
|
|
|
+import com.dc.datachange.exception.InitialFailedException;
|
|
|
+import com.dc.datachange.utils.R;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.cloud.client.ServiceInstance;
|
|
|
+import org.springframework.cloud.client.discovery.DiscoveryClient;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class SDRManager {
|
|
|
+ @Autowired
|
|
|
+ private SDRClient SDRClient;
|
|
|
+ @Autowired
|
|
|
+ private SendExecutor sendExecutor;
|
|
|
+ @Autowired
|
|
|
+ private DiscoveryClient discoveryClient;
|
|
|
+ @Autowired
|
|
|
+ private DataManager dataManager;
|
|
|
+ private String SDRStatus="离线";
|
|
|
+ private String ServiceStatus="无法提供";
|
|
|
+ @Value("${remote.client-name}")
|
|
|
+ private String clientName;
|
|
|
+
|
|
|
+ public String getSDRStatus(){
|
|
|
+ return this.SDRStatus;
|
|
|
+ }
|
|
|
+ public String getServiceStatus(){
|
|
|
+ return this.ServiceStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Bean
|
|
|
+ @Scheduled(fixedDelay = 6000)
|
|
|
+ public void checkRemoteOnline(){
|
|
|
+ try {
|
|
|
+ List<ServiceInstance> instances = discoveryClient.getInstances(clientName);
|
|
|
+ if(instances!=null && !instances.isEmpty()) {
|
|
|
+ this.SDRStatus = "上线";
|
|
|
+ try {
|
|
|
+ checkStatus();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.SDRStatus="离线";
|
|
|
+ this.ServiceStatus="无法提供";
|
|
|
+ }
|
|
|
+ }catch (RuntimeException e){
|
|
|
+ log.error(e.getMessage());
|
|
|
+ this.SDRStatus="离线";
|
|
|
+ this.ServiceStatus="无法提供";
|
|
|
+ }finally {
|
|
|
+ sendExecutor.sendSDRStatusMsg();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> getInfo() {
|
|
|
+ Map<String, String> o = new HashMap<>();
|
|
|
+ o.put("onlineStatus",SDRStatus);
|
|
|
+ o.put("serviceStatus",ServiceStatus);
|
|
|
+ return o;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkStatus(){
|
|
|
+ Map<String, Object> statusData = SDRClient.status();
|
|
|
+ Map<String,Object> data = (Map<String, Object>) statusData.get("data");
|
|
|
+ Integer status = (Integer) data.get("status");
|
|
|
+ if(status == 0){
|
|
|
+ ServiceStatus="无法提供";
|
|
|
+ throw new InitialFailedException((String)statusData.get("message")+ data.get("Error"));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ServiceStatus="正常提供";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public R initialize(){
|
|
|
+ Map<String, Object> initialize = SDRClient.status();
|
|
|
+ Map<String,Object> data = (Map<String, Object>) initialize.get("data");
|
|
|
+ Integer status = (Integer) data.get("status");
|
|
|
+ if(status == 1){
|
|
|
+ return R.ok("启动成功");
|
|
|
+ }else {
|
|
|
+ return R.error((String)initialize.get("message")+ data.get("Error"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String,Object> getData(){
|
|
|
+ return (Map<String, Object>) SDRClient.getData(new RequestData(dataManager.getPhysicalInterferPlat().getStrategy(),
|
|
|
+ dataManager.getPhysicalRadarPlat().getStrategy())).get("data");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|