Commit 156ef31a99bd6bc9c87280020084116741511366
1 parent
aeea98bd
增加配置参数 通过IP地址限制定时任务执行
Showing
5 changed files
with
77 additions
and
6 deletions
huaheng-wms-core/src/main/java/org/jeecg/JeecgSystemApplication.java
... | ... | @@ -6,6 +6,10 @@ import java.util.Enumeration; |
6 | 6 | import javax.transaction.SystemException; |
7 | 7 | |
8 | 8 | import org.jeecg.common.util.oConvertUtils; |
9 | +import org.jeecg.modules.wms.monitor.job.MyTriggerListener; | |
10 | +import org.jeecg.utils.SpringUtils; | |
11 | +import org.quartz.Scheduler; | |
12 | +import org.springframework.boot.CommandLineRunner; | |
9 | 13 | import org.springframework.boot.SpringApplication; |
10 | 14 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
11 | 15 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
... | ... | @@ -14,6 +18,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; |
14 | 18 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
15 | 19 | import org.springframework.cache.annotation.EnableCaching; |
16 | 20 | import org.springframework.context.ConfigurableApplicationContext; |
21 | +import org.springframework.context.annotation.Bean; | |
17 | 22 | import org.springframework.context.annotation.ComponentScan; |
18 | 23 | import org.springframework.context.annotation.ComponentScan.Filter; |
19 | 24 | import org.springframework.context.annotation.FilterType; |
... | ... | @@ -53,6 +58,7 @@ public class JeecgSystemApplication extends SpringBootServletInitializer { |
53 | 58 | + "WEB External: \thttp://" + ip + ":" + port + path + "/index.html\n\t" + "API External: \thttp://" + ip + ":" + port + path + "/\n\n\t" |
54 | 59 | + "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n\n\t" + "The following profiles are active: [" + profiles + "]\n" |
55 | 60 | + "----------------------------------------------------------"); |
61 | + | |
56 | 62 | } |
57 | 63 | |
58 | 64 | public static InetAddress getLocalHostExactAddress() { |
... | ... | @@ -76,4 +82,14 @@ public class JeecgSystemApplication extends SpringBootServletInitializer { |
76 | 82 | } |
77 | 83 | return null; |
78 | 84 | } |
85 | + | |
86 | + @Bean | |
87 | + public CommandLineRunner run() { | |
88 | + return args -> { | |
89 | + // 在这里编写启动时需要执行的代码 | |
90 | + MyTriggerListener myTriggerListener = new MyTriggerListener(); | |
91 | + SpringUtils.getBean(Scheduler.class).getListenerManager().addTriggerListener(myTriggerListener); | |
92 | + System.out.println("Spring Boot 已启动完成,可以在这里执行自定义的启动逻辑..."); | |
93 | + }; | |
94 | + } | |
79 | 95 | } |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/quartz/service/impl/QuartzJobServiceImpl.java
1 | 1 | package org.jeecg.modules.quartz.service.impl; |
2 | 2 | |
3 | -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |
4 | -import lombok.extern.slf4j.Slf4j; | |
3 | +import java.util.Date; | |
4 | +import java.util.List; | |
5 | + | |
5 | 6 | import org.jeecg.common.constant.CommonConstant; |
6 | 7 | import org.jeecg.common.exception.JeecgBootException; |
7 | 8 | import org.jeecg.common.util.DateUtils; |
... | ... | @@ -13,8 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired; |
13 | 14 | import org.springframework.stereotype.Service; |
14 | 15 | import org.springframework.transaction.annotation.Transactional; |
15 | 16 | |
16 | -import java.util.Date; | |
17 | -import java.util.List; | |
17 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |
18 | + | |
19 | +import lombok.extern.slf4j.Slf4j; | |
18 | 20 | |
19 | 21 | /** |
20 | 22 | * @Description: 定时任务在线管理 |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/monitor/job/MyTriggerListener.java
0 → 100644
1 | +package org.jeecg.modules.wms.monitor.job; | |
2 | + | |
3 | +import org.jeecg.JeecgSystemApplication; | |
4 | +import org.jeecg.modules.wms.config.parameterConfiguration.service.IParameterConfigurationService; | |
5 | +import org.jeecg.utils.SpringUtils; | |
6 | +import org.jeecg.utils.StringUtils; | |
7 | +import org.jeecg.utils.constant.QuantityConstant; | |
8 | +import org.quartz.JobExecutionContext; | |
9 | +import org.quartz.Trigger; | |
10 | +import org.quartz.TriggerListener; | |
11 | + | |
12 | +import lombok.extern.slf4j.Slf4j; | |
13 | + | |
14 | +/** | |
15 | + * @author 游杰 | |
16 | + */ | |
17 | +@Slf4j | |
18 | +public class MyTriggerListener implements TriggerListener { | |
19 | + | |
20 | + @Override | |
21 | + public String getName() { | |
22 | + return "MyTriggerListener"; | |
23 | + } | |
24 | + | |
25 | + @Override | |
26 | + public void triggerFired(Trigger trigger, JobExecutionContext context) { | |
27 | + | |
28 | + } | |
29 | + | |
30 | + @Override | |
31 | + public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) { | |
32 | + String localIp = JeecgSystemApplication.getLocalHostExactAddress().getHostAddress(); | |
33 | + String ip = SpringUtils.getBean(IParameterConfigurationService.class).getValueByCode(QuantityConstant.RULE_JOB_IP); | |
34 | + if (StringUtils.isNotEmpty(ip)) { | |
35 | + if (!ip.equals(localIp)) { | |
36 | + return true; | |
37 | + } | |
38 | + } | |
39 | + return false; | |
40 | + } | |
41 | + | |
42 | + @Override | |
43 | + public void triggerMisfired(Trigger trigger) { | |
44 | + | |
45 | + } | |
46 | + | |
47 | + @Override | |
48 | + public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) { | |
49 | + | |
50 | + } | |
51 | + | |
52 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/utils/constant/QuantityConstant.java
... | ... | @@ -535,6 +535,7 @@ public class QuantityConstant { |
535 | 535 | public static final String RULE_SHIPMENT_ZONE = "shipmentZoneRule"; |
536 | 536 | public static final String SHIPMENT_WHOLE_TASK_CLEAR_INVENTORY = "shipmentWholeTaskClearInventory"; |
537 | 537 | public static final String RULE_SHIPMENT_CONTAINER_ADVICE = "shipmentContainerAdvice"; |
538 | + public static final String RULE_JOB_IP = "jobIp"; | |
538 | 539 | |
539 | 540 | public static final int STATUS_CLOSE = 0; |
540 | 541 | public static final int STATUS_OPEN = 1; |
... | ... |
huaheng-wms-core/src/main/resources/application.yml
... | ... | @@ -2,11 +2,11 @@ spring: |
2 | 2 | application: |
3 | 3 | name: huaheng-wms-core |
4 | 4 | profiles: |
5 | - active: test | |
5 | + active: dev | |
6 | 6 | |
7 | 7 | |
8 | 8 | huaheng: |
9 | 9 | system: |
10 | 10 | version: '@project.version@' |
11 | 11 | artifactId: '@project.artifactId@' |
12 | - checkSystemActivationCode: true | |
12 | + checkSystemActivationCode: false | |
... | ... |