lyhzzz před 1 rokem
rodič
revize
450a30ff54

+ 22 - 0
src/main/java/com/fdkankan/manage/config/NacosScopeConfig.java

@@ -0,0 +1,22 @@
+package com.fdkankan.manage.config;
+
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class NacosScopeConfig {
+
+    public static String threshold = null;
+
+    @Bean
+    @RefreshScope
+    public void setThreshold(@Value("${dingtalk.threshold:0.2}")
+                           String threshold) {
+
+        NacosScopeConfig.threshold = threshold;
+    }
+
+}

+ 3 - 4
src/main/java/com/fdkankan/manage/task/DingdingService.java

@@ -1,6 +1,7 @@
 package com.fdkankan.manage.task;
 
 import com.fdkankan.dingtalk.DingTalkSendUtils;
+import com.fdkankan.manage.config.NacosScopeConfig;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -27,8 +28,6 @@ public class DingdingService {
 
     @Value("${main.url}")
     String mainUrl;
-    @Value("${dingtalk.threshold:0.2}")
-    String threshold;
 
     public void sendDingDingMsg(Integer count){
         try {
@@ -49,8 +48,8 @@ public class DingdingService {
             BigDecimal dbCount = new BigDecimal(size);
 
             BigDecimal divideCount = dbCount.divide(totalCount,2,RoundingMode.HALF_DOWN);
-            BigDecimal thresholdCount = new BigDecimal(threshold).setScale(2,RoundingMode.HALF_DOWN);
-            log.info("modelThreshold--{},{},{},{}",threshold,divideCount,thresholdCount,divideCount.compareTo(thresholdCount));
+            BigDecimal thresholdCount = new BigDecimal(NacosScopeConfig.threshold).setScale(2,RoundingMode.HALF_DOWN);
+            log.info("modelThreshold--{},{},{},{}",NacosScopeConfig.threshold,divideCount,thresholdCount,divideCount.compareTo(thresholdCount));
             if(divideCount.compareTo(thresholdCount) >= 0 ){
                 this.sendDingDingMsg(size);
             }

+ 1 - 1
src/main/resources/bootstrap.yml

@@ -5,4 +5,4 @@ logging:
   config: classpath:logback-spring.xml
 mybatis-plus:
   configuration:
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #开启sql日志
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #开启sql日志