Ver código fonte

修改代码

wanghc 3 anos atrás
pai
commit
477c496746

+ 1 - 1
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/job/ReceiveDataJob.java

@@ -23,7 +23,7 @@ public class ReceiveDataJob {
   private ReceiveDataService receiveDataService;
 
 
-  @Scheduled(cron = "0 0/1 * * * *")
+  @Scheduled(fixedDelay = 60000)
   public void receiveData() {
 
     log.info("开始向绿能数据中心请求数据");

+ 19 - 1
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/ReceiveDataService.java

@@ -22,6 +22,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
@@ -240,7 +241,6 @@ public class ReceiveDataService {
       }else {
         log.info(electricField.getStationCode()+ "-" +equipmentType.getMessage() + "-" + equipmentId+"无数据,不进行任何操作");
       }
-
     } catch (Exception e) {
       log.info(electricField.getName()+equipmentType.getMessage()+"接数程序异常");
       e.printStackTrace();
@@ -269,6 +269,10 @@ public class ReceiveDataService {
       body = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
     }catch (RuntimeException | IOException e){
       e.printStackTrace();
+      log.info("请求异常");
+      log.info("所用线程"+Thread.currentThread().getName());
+      log.info("停止请求数据");
+      Thread.currentThread().stop();
     }
     return body;
   }
@@ -309,4 +313,18 @@ public class ReceiveDataService {
       e.printStackTrace();
     }
   }
+  public  void stop(){
+    Thread thread = new Thread(() -> {
+      while (Thread.currentThread().isInterrupted()) {
+        log.info("停止请求数据");
+      }
+    });
+    thread.start();
+    try {
+      Thread.sleep(1);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+    thread.interrupt();
+  }
 }