|
@@ -0,0 +1,58 @@
|
|
|
+package cn.com.qmth.examcloud.task.starter.config;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.ApplicationArguments;
|
|
|
+import org.springframework.boot.ApplicationRunner;
|
|
|
+import org.springframework.cloud.client.ServiceInstance;
|
|
|
+import org.springframework.cloud.client.discovery.DiscoveryClient;
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
|
|
|
+import cn.com.qmth.examcloud.task.service.ReportsComputeService;
|
|
|
+import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 系统启动
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2018年11月29日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Order(101)
|
|
|
+public class SystemStartup implements ApplicationRunner {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DiscoveryClient discoveryClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ReportsComputeService reportsComputeService;
|
|
|
+
|
|
|
+ public void start() {
|
|
|
+
|
|
|
+ String appName = PropertyHolder.getString("spring.application.name");
|
|
|
+ if (StringUtils.isNotBlank(appName)) {
|
|
|
+ List<ServiceInstance> instances = discoveryClient.getInstances(appName);
|
|
|
+ if (!instances.isEmpty()) {
|
|
|
+ throw new ExamCloudRuntimeException("multiple task instances!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 初始化任务数据
|
|
|
+ initJobData();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(ApplicationArguments args) throws Exception {
|
|
|
+ start();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initJobData() {
|
|
|
+ // 成绩统计报表计算任务数据状态重置
|
|
|
+ reportsComputeService.initReportsCompute();
|
|
|
+ }
|
|
|
+}
|