Browse Source

集成调度框架

xieshengjie 3 years ago
parent
commit
2f85d025fd

+ 6 - 0
pom.xml

@@ -30,6 +30,7 @@
     <mybatis-plus.boot.starter.version>3.2.0</mybatis-plus.boot.starter.version>
     <mybatis-plus.generator.version>3.3.2</mybatis-plus.generator.version>
     <pgsql.version>42.2.5</pgsql.version>
+    <groovy.version>3.0.8</groovy.version>
   </properties>
 
   <!-- 子模块继承之后,提供作用:锁定版本+子modlue不用写groupId和version  -->
@@ -91,6 +92,11 @@
         <optional>true</optional>
       </dependency>
       <dependency>
+        <groupId>org.codehaus.groovy</groupId>
+        <artifactId>groovy</artifactId>
+        <version>${groovy.version}</version>
+      </dependency>
+      <dependency>
         <groupId>com.baomidou</groupId>
         <artifactId>mybatis-plus-boot-starter</artifactId>
         <version>${mybatis-plus.boot.starter.version}</version>

BIN
realtime/generation-service/lib/xxl-job-core-2.3.1-SNAPSHOT.jar


+ 23 - 0
realtime/generation-service/pom.xml

@@ -70,6 +70,29 @@
             <version>1.2.17</version>
             <scope>compile</scope>
         </dependency>
+        <!-- ********************** plugin ********************** -->
+        <!-- groovy-all -->
+        <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy</artifactId>
+        </dependency>
+        <!-- xxl-job-core -->
+        <dependency>
+            <groupId>com.xuxueli</groupId>
+            <artifactId>xxl-job-core</artifactId>
+            <version>2.3.1-SNAPSHOT</version>
+            <scope>system</scope>
+            <systemPath>${basedir}/lib/xxl-job-core-2.3.1-SNAPSHOT.jar</systemPath>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-all</artifactId>
+        </dependency>
+
 
     </dependencies>
     <build>

+ 68 - 0
realtime/generation-service/src/main/java/com/gyee/generation/config/XxlJobConfig.java

@@ -0,0 +1,68 @@
+package com.gyee.generation.config;
+
+
+import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.EnvironmentAware;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.env.Environment;
+
+/**
+ * xxl-job config
+ *
+ * @author xuxueli 2017-04-28
+ */
+
+
+@Configuration
+@PropertySource("classpath:xxl-job-executor.properties")
+public class XxlJobConfig implements EnvironmentAware {
+    private Environment env;
+
+
+    @Override
+    public void setEnvironment(Environment environment) {
+        this.env=environment;
+    }
+
+    private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
+
+
+
+    @Bean
+    public XxlJobSpringExecutor xxlJobExecutor() {
+    logger.info(">>>>>>>>>>> xxl-job config init.");
+    XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
+    xxlJobSpringExecutor.setAdminAddresses(env.getProperty("xxl.job.admin.addresses"));
+    xxlJobSpringExecutor.setAppname(env.getProperty("xxl.job.executor.appname"));
+    xxlJobSpringExecutor.setAddress(env.getProperty("xxl.job.executor.address"));
+    xxlJobSpringExecutor.setIp(env.getProperty("xxl.job.executor.ip"));
+    xxlJobSpringExecutor.setPort(Integer.parseInt(env.getProperty("xxl.job.executor.port")));
+    xxlJobSpringExecutor.setAccessToken(env.getProperty("xxl.job.accessToken"));
+    xxlJobSpringExecutor.setLogPath(env.getProperty("xxl.job.executor.logpath"));
+    xxlJobSpringExecutor.setLogRetentionDays(Integer.parseInt(env.getProperty("xxl.job.executor.logretentiondays")));
+    return xxlJobSpringExecutor;
+    }
+
+    /**
+    * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
+    *
+    *      1、引入依赖:
+    *          <dependency>
+    *             <groupId>org.springframework.cloud</groupId>
+    *             <artifactId>spring-cloud-commons</artifactId>
+    *             <version>${version}</version>
+    *         </dependency>
+    *
+    *      2、配置文件,或者容器启动变量
+    *          spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
+    *
+    *      3、获取IP
+    *          String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
+    */
+
+
+}

+ 0 - 6
realtime/generation-service/src/main/java/com/gyee/generation/service/GenerationService.java

@@ -160,12 +160,6 @@ public class GenerationService {
 
         List<String> days = DateUtils.getDays(beginDate, endDate);
 
-        if (hour == 0 && days.size()==1 && DateUtils.isToday(DateUtils.parseDate(days.get(0)))){
-            beginDate = DateUtils.toDate1(DateUtils.addDays(DateUtils.parseDate(beginDate),-1));
-            days = DateUtils.getDays(beginDate, endDate);
-        }
-
-
         days.stream().forEach(day->{
             List<Meterpointvalue> resultList = new ArrayList<>();
             Date date = DateUtils.parseDate(day);

+ 88 - 0
realtime/generation-service/src/main/java/com/gyee/generation/task/SaticScheduleTask.java

@@ -0,0 +1,88 @@
+package com.gyee.generation.task;
+
+
+import com.gyee.common.util.DateUtils;
+import com.gyee.generation.service.GenerationService;
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+/**
+ * @ClassName : SaticScheduleTask
+ * @Description : 调度
+ */
+
+
+@Component
+public class SaticScheduleTask {
+
+    private static Logger logger = LoggerFactory.getLogger(SaticScheduleTask.class);
+
+    @Resource
+    private GenerationService generationService;
+    //3.添加定时任务
+    /**
+     * 电计量实时计算计算(电量,上网,购网,场用)
+     * 每15分钟执行一次
+     */
+
+    @XxlJob("electricityMetering-realtime")
+    public void configureTasks1()  {
+
+
+        XxlJobHelper.log("电计量实时调度程序执行开始!........");
+
+        try {
+//                System.out.println(11111111);
+            generationService.saveGenerationDatas();
+                 } catch (Exception e) {
+
+            e.printStackTrace();
+        }
+
+        XxlJobHelper.log("电计量实时调度任务处理完成!........");
+    }
+
+    /**
+     * 存储meterpointvalue
+     * 每10分钟执行一次
+     */
+    @XxlJob("electricityMetering-history1")
+    public void history1()  {
+
+        XxlJobHelper.log("电计量历史1调度程序执行开始!........");
+        String yesterdayStr = DateUtils.getYesterdayStr("yyyy-MM-dd");
+        String date = DateUtils.toDate1(DateUtils.getCurrentDate());
+        try {
+            generationService.saveMeterpointValue(date,date);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        XxlJobHelper.log("电计量历史1调度任务处理完成!........");
+    }
+
+    /**
+     * 存储meterpointvalue(处理每天最后一个值,保证是第二天0点值)
+     * 每天0:30执行
+     */
+    @XxlJob("electricityMetering-history2")
+    public void history2()  {
+
+        XxlJobHelper.log("电计量历史1调度程序执行开始!........");
+        String yesterdayStr = DateUtils.getYesterdayStr("yyyy-MM-dd");
+        try {
+            generationService.saveMeterpointValue(yesterdayStr,yesterdayStr);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        XxlJobHelper.log("电计量历史1调度任务处理完成!........");
+    }
+
+
+
+}

+ 1 - 1
realtime/generation-service/src/main/java/com/gyee/generation/util/realtimesource/EdosUtil.java

@@ -27,7 +27,7 @@ import java.util.*;
 public class EdosUtil implements IEdosUtil {
 
     private RestTemplate restTemplate =new RestTemplate();
-    @Value("${golden.baseURL}")
+    @Value("${db.url}")
     private String baseURL;
 //    private static String baseURL = "http://10.155.32.4:8011/ts";
 //    private static String baseURL = "http://10.65.79.30:8019/ts";

+ 18 - 0
realtime/generation-service/src/main/resources/xxl-job-executor.properties

@@ -0,0 +1,18 @@
+### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
+xxl.job.admin.addresses=http://10.83.68.159:8175/xxl-job-admin
+
+### xxl-job, access token
+xxl.job.accessToken=
+
+### xxl-job executor appname
+xxl.job.executor.appname=generation-job
+### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
+xxl.job.executor.address=
+### xxl-job executor server-info
+xxl.job.executor.ip=
+xxl.job.executor.port=9102
+### xxl-job executor log-path
+xxl.job.executor.logpath=d:\\jobs\\generation-job
+### xxl-job executor log-retention-days
+xxl.job.executor.logretentiondays=30
+

+ 1 - 1
realtime/generation-service/src/test/java/com/gyee/generation/GenerationTest.java

@@ -6,6 +6,7 @@ import org.junit.runner.RunWith;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.boot.test.context.SpringBootTest;
+
 import org.springframework.test.context.junit4.SpringRunner;
 
 import javax.annotation.Resource;
@@ -24,6 +25,5 @@ public class GenerationTest {
     private GenerationService generationService;
     @Test
     public void test1() throws Exception {
-        generationService.saveGenerationDatas();
     }
 }

+ 1 - 1
web/pom.xml

@@ -29,7 +29,7 @@
         <module>health-hb</module>
         <module>analysis-hb</module>
         <module>admin-hb</module>
-        <module>monitor-web-hf</module>
+<!--        <module>monitor-web-hf</module>-->
         <module>monitor-web-sxjn</module>
         <module>initialpoint</module>
     </modules>