From 1eb1ae6b785210727812ed5f6ce9ccaaf09cc458 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期五, 15 十二月 2023 20:59:27 +0800
Subject: [PATCH] 案件池查询修改 定时任务加环境判断

---
 ycl-platform/src/main/java/com/ycl/timer/GetDingToken.java |   37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/ycl-platform/src/main/java/com/ycl/timer/GetDingToken.java b/ycl-platform/src/main/java/com/ycl/timer/GetDingToken.java
index 7ae7888..b78dbd0 100644
--- a/ycl-platform/src/main/java/com/ycl/timer/GetDingToken.java
+++ b/ycl-platform/src/main/java/com/ycl/timer/GetDingToken.java
@@ -8,6 +8,7 @@
 import com.ycl.config.DingConfig;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.data.redis.core.StringRedisTemplate;
@@ -25,7 +26,7 @@
  */
 @Slf4j
 @Component
-public class GetDingToken implements  ApplicationListener<ContextRefreshedEvent> {
+public class GetDingToken implements ApplicationListener<ContextRefreshedEvent> {
     private static GetClient getTokenClient;
     @Autowired
     private StringRedisTemplate redisTemplate;
@@ -37,17 +38,17 @@
     private DingConfig dingConfig;
 
 
-    private  String getToken() {
+    private String getToken() {
         //璋冪敤API
         getTokenClient = executableClient.newGetClient(GET_TOKEN);
         //璁剧疆鍙傛暟
-        getTokenClient.addParameter("appkey",  dingConfig.getAppKey());
+        getTokenClient.addParameter("appkey", dingConfig.getAppKey());
         getTokenClient.addParameter("appsecret", dingConfig.getAppSecret());
         String apiResult = getTokenClient.get();
         return parsingResult(apiResult);
     }
 
-    private  String getTiker(String accToken) {
+    private String getTiker(String accToken) {
         //璋冪敤API
         PostClient postClient = executableClient.newPostClient(GET_TIKER);
         //璁剧疆鍙傛暟
@@ -91,16 +92,24 @@
 //            runAction();
         }
     }
-//    @Scheduled(cron ="0 0/2 * * * ? ")
+
+    @Value("${spring.profiles.active}")
+    private String env;
+
+        @Scheduled(cron ="0 0/2 * * * ? ")
+//    @Scheduled(cron = "0/1 * * * * ?")   // 姣忕鎵ц
     public void runAction() {
-         //gettoken
-         String getToken = getToken();
-         //jsApi
-         String jsapiToken = getTiker(getToken);
-         //瀛樺偍鍒皉edis
-         JSONObject dingObj = new JSONObject();
-         dingObj.put("token", getToken);
-         dingObj.put("jsApiTiker", jsapiToken);
-         redisTemplate.opsForValue().set("ding", dingObj.toJSONString(), 2L, TimeUnit.HOURS);
+//        System.out.println("鐜锛�" + env);
+        if ("online".equals(env)) {
+            //gettoken
+            String getToken = getToken();
+            //jsApi
+            String jsapiToken = getTiker(getToken);
+            //瀛樺偍鍒皉edis
+            JSONObject dingObj = new JSONObject();
+            dingObj.put("token", getToken);
+            dingObj.put("jsApiTiker", jsapiToken);
+            redisTemplate.opsForValue().set("ding", dingObj.toJSONString(), 2L, TimeUnit.HOURS);
+        }
     }
 }

--
Gitblit v1.8.0