update 每秒事件,动态配置工具类
parent
5154a08a0e
commit
1b89eda79c
@ -0,0 +1,53 @@
|
||||
package com.ruoyi.common.event;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* - 每秒都会触发的事件
|
||||
* Author : J.L.Zhou
|
||||
* E-Mail : 2233875735@qq.com
|
||||
* Tel : 151 1104 7708
|
||||
* Date : 2022年12月27日 下午3:10:39
|
||||
* Version : 1.0
|
||||
* Copyright 2022 jlzhou.top Inc. All rights reserved.
|
||||
* Warning: this content is only for internal circulation of the company.
|
||||
* It is forbidden to divulge it or use it for other commercial purposes.
|
||||
* </pre>
|
||||
*/
|
||||
public class PerSecondEvent extends ApplicationEvent {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1752655123185832181L;
|
||||
private static AtomicInteger globalCount = new AtomicInteger(0);
|
||||
private static final int MAX = 24*365*60*60;
|
||||
|
||||
private int count;
|
||||
|
||||
public PerSecondEvent() {
|
||||
super(0);
|
||||
if(globalCount.incrementAndGet()>MAX) {
|
||||
globalCount.set(0);
|
||||
}
|
||||
count=globalCount.get();
|
||||
super.source= count;
|
||||
}
|
||||
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return " 每秒都会触发的事件: " + count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.ruoyi.common.runner;
|
||||
|
||||
import com.ruoyi.common.event.PerSecondEvent;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
@Configuration
|
||||
public class PerSecondRunner {
|
||||
|
||||
@Scheduled(fixedRate = 1000)
|
||||
public void PerSecondRunner() {
|
||||
SpringUtils.publishEvent(new PerSecondEvent());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
|
||||
public class DynConfigUtils {
|
||||
|
||||
/**
|
||||
* 将动态配置类转换为普通bean
|
||||
* @param config 动态配置bean
|
||||
* @return 普通bean
|
||||
* @param <T>
|
||||
*/
|
||||
public static <T> T toBean(T config) {
|
||||
return (T)BeanUtil.toBean(config, config.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将普通bean非空属性设置到动态配置config中
|
||||
* @param bean 普通bean
|
||||
* @param config 动态配置bean
|
||||
*/
|
||||
public static void setBean(Object bean, Object config) {
|
||||
BeanUtil.copyProperties(bean,config, CopyOptions.create(config.getClass(),true));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="refresh" content="0; URL=/admin/">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue