parent
857fb53fa1
commit
a6b6e7c9d4
@ -0,0 +1,23 @@
|
|||||||
|
package org.jeecg.common.constant.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户终端类型
|
||||||
|
*/
|
||||||
|
public enum ClientTerminalTypeEnum {
|
||||||
|
|
||||||
|
PC("pc", "电脑终端"),
|
||||||
|
H5("h5", "移动网页端"),
|
||||||
|
APP("app", "手机app端");
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
ClientTerminalTypeEnum(String value, String text) {
|
||||||
|
this.key = value;
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return this.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package org.jeecg.common.constant.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期预设范围枚举
|
||||||
|
*/
|
||||||
|
public enum DateRangeEnum {
|
||||||
|
// 今天
|
||||||
|
TODAY,
|
||||||
|
// 昨天
|
||||||
|
YESTERDAY,
|
||||||
|
// 明天
|
||||||
|
TOMORROW,
|
||||||
|
// 本周
|
||||||
|
THIS_WEEK,
|
||||||
|
// 上周
|
||||||
|
LAST_WEEK,
|
||||||
|
// 下周
|
||||||
|
NEXT_WEEK,
|
||||||
|
// 过去七天
|
||||||
|
LAST_7_DAYS,
|
||||||
|
// 本月
|
||||||
|
THIS_MONTH,
|
||||||
|
// 上月
|
||||||
|
LAST_MONTH,
|
||||||
|
// 下月
|
||||||
|
NEXT_MONTH,
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package org.jeecg.common.exception;
|
||||||
|
|
||||||
|
import org.jeecg.common.constant.CommonConstant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 业务提醒异常(用于操作业务提醒)
|
||||||
|
* @date: 2024-04-26
|
||||||
|
* @author: scott
|
||||||
|
*/
|
||||||
|
public class JeecgBootBizTipException extends RuntimeException {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回给前端的错误code
|
||||||
|
*/
|
||||||
|
private int errCode = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
|
||||||
|
|
||||||
|
public JeecgBootBizTipException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JeecgBootBizTipException(String message, int errCode){
|
||||||
|
super(message);
|
||||||
|
this.errCode = errCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getErrCode() {
|
||||||
|
return errCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JeecgBootBizTipException(Throwable cause)
|
||||||
|
{
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JeecgBootBizTipException(String message, Throwable cause)
|
||||||
|
{
|
||||||
|
super(message,cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package org.jeecg.common.system.enhance;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户增强
|
||||||
|
*/
|
||||||
|
public interface UserFilterEnhance {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户id
|
||||||
|
* @param loginUserId 当前登录的用户id
|
||||||
|
*
|
||||||
|
* @return List<String> 返回多个用户id
|
||||||
|
*/
|
||||||
|
default List<String> getUserIds(String loginUserId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
package org.jeecg.test.sqlparse;
|
||||||
|
|
||||||
|
import net.sf.jsqlparser.JSQLParserException;
|
||||||
|
import org.jeecg.common.util.IpUtils;
|
||||||
|
import org.jeecg.common.util.oConvertUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: scott
|
||||||
|
* @date: 2024年04月29日 16:48
|
||||||
|
*/
|
||||||
|
public class TestIpUtil {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Map<String, String[]> map = new HashMap<>();
|
||||||
|
map.put("key1", new String[]{"value1", "value2", "value3"});
|
||||||
|
map.put("key4", null);
|
||||||
|
map.put("key2", new String[]{"value4", "value5"});
|
||||||
|
map.put("key3", new String[]{"value6"});
|
||||||
|
System.out.println(oConvertUtils.mapToString(map));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
String ip = "2408:8207:1851:10e0:50bd:1a50:60c8:b030, 115.231.101.180";
|
||||||
|
String[] ipAddresses = ip.split(",");
|
||||||
|
for (String ipAddress : ipAddresses) {
|
||||||
|
System.out.println(ipAddress);
|
||||||
|
ipAddress = ipAddress.trim();
|
||||||
|
if (IpUtils.isValidIpAddress(ipAddress)) {
|
||||||
|
System.out.println("ipAddress= " + ipAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package org.jeecg.modules.monitor.actuator;
|
||||||
|
|
||||||
|
import org.jeecg.modules.monitor.actuator.httptrace.CustomInMemoryHttpTraceRepository;
|
||||||
|
import org.springframework.boot.actuate.autoconfigure.trace.http.HttpTraceAutoConfiguration;
|
||||||
|
import org.springframework.boot.actuate.autoconfigure.trace.http.HttpTraceProperties;
|
||||||
|
import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义健康监控配置类
|
||||||
|
*
|
||||||
|
* @Author: chenrui
|
||||||
|
* @Date: 2024/5/13 17:20
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties(HttpTraceProperties.class)
|
||||||
|
@AutoConfigureBefore(HttpTraceAutoConfiguration.class)
|
||||||
|
public class CustomActuatorConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求追踪
|
||||||
|
* @return
|
||||||
|
* @author chenrui
|
||||||
|
* @date 2024/5/14 14:52
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(prefix = "management.trace.http", name = "enabled", matchIfMissing = true)
|
||||||
|
@ConditionalOnMissingBean(HttpTraceRepository.class)
|
||||||
|
public CustomInMemoryHttpTraceRepository traceRepository() {
|
||||||
|
return new CustomInMemoryHttpTraceRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package org.jeecg.modules.monitor.actuator.httptrace;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||||
|
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||||
|
import org.springframework.boot.actuate.endpoint.annotation.Selector;
|
||||||
|
import org.springframework.boot.actuate.trace.http.HttpTrace;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.springframework.boot.actuate.endpoint.annotation.Selector.Match.ALL_REMAINING;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: ENDPOINT: 请求追踪(新),支持通过responseCode筛选
|
||||||
|
* @Author: chenrui
|
||||||
|
* @Date: 2024/5/13 17:02
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Endpoint(id = "httptrace-new")
|
||||||
|
public class CustomHttpTraceEndpoint{
|
||||||
|
private final CustomInMemoryHttpTraceRepository repository;
|
||||||
|
|
||||||
|
public CustomHttpTraceEndpoint(CustomInMemoryHttpTraceRepository repository) {
|
||||||
|
Assert.notNull(repository, "Repository must not be null");
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReadOperation
|
||||||
|
public HttpTraceDescriptor traces(@Selector(match = ALL_REMAINING) String query) {
|
||||||
|
return new CustomHttpTraceEndpoint.HttpTraceDescriptor(this.repository.findAll(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static final class HttpTraceDescriptor {
|
||||||
|
private final List<HttpTrace> traces;
|
||||||
|
|
||||||
|
private HttpTraceDescriptor(List<HttpTrace> traces) {
|
||||||
|
this.traces = traces;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,94 @@
|
|||||||
|
package org.jeecg.modules.monitor.actuator.httptrace;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.trace.http.HttpTrace;
|
||||||
|
import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 自定义内存请求追踪存储
|
||||||
|
* @Author: chenrui
|
||||||
|
* @Date: 2024/5/13 17:02
|
||||||
|
*/
|
||||||
|
public class CustomInMemoryHttpTraceRepository extends InMemoryHttpTraceRepository {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<HttpTrace> findAll() {
|
||||||
|
return super.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HttpTrace> findAll(String query) {
|
||||||
|
List<HttpTrace> allTrace = super.findAll();
|
||||||
|
if (null != allTrace && !allTrace.isEmpty()) {
|
||||||
|
Stream<HttpTrace> stream = allTrace.stream();
|
||||||
|
String[] params = query.split(",");
|
||||||
|
stream = filter(params, stream);
|
||||||
|
stream = sort(params, stream);
|
||||||
|
allTrace = stream.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
return allTrace;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream<HttpTrace> sort(String[] params, Stream<HttpTrace> stream) {
|
||||||
|
if (params.length < 2) {
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
String sortBy = params[1];
|
||||||
|
String order;
|
||||||
|
if (params.length > 2) {
|
||||||
|
order = params[2];
|
||||||
|
} else {
|
||||||
|
order = "desc";
|
||||||
|
}
|
||||||
|
return stream.sorted((o1, o2) -> {
|
||||||
|
int i = 0;
|
||||||
|
if("timeTaken".equalsIgnoreCase(sortBy)) {
|
||||||
|
i = o1.getTimeTaken().compareTo(o2.getTimeTaken());
|
||||||
|
}else if("timestamp".equalsIgnoreCase(sortBy)){
|
||||||
|
i = o1.getTimestamp().compareTo(o2.getTimestamp());
|
||||||
|
}
|
||||||
|
if("desc".equalsIgnoreCase(order)){
|
||||||
|
i *=-1;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Stream<HttpTrace> filter(String[] params, Stream<HttpTrace> stream) {
|
||||||
|
if (params.length == 0) {
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
String statusQuery = params[0];
|
||||||
|
if (null != statusQuery && !statusQuery.isEmpty()) {
|
||||||
|
statusQuery = statusQuery.toLowerCase().trim();
|
||||||
|
switch (statusQuery) {
|
||||||
|
case "error":
|
||||||
|
stream = stream.filter(httpTrace -> {
|
||||||
|
int status = httpTrace.getResponse().getStatus();
|
||||||
|
return status >= 404 && status < 501;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "warn":
|
||||||
|
stream = stream.filter(httpTrace -> {
|
||||||
|
int status = httpTrace.getResponse().getStatus();
|
||||||
|
return status >= 201 && status < 404;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "success":
|
||||||
|
stream = stream.filter(httpTrace -> {
|
||||||
|
int status = httpTrace.getResponse().getStatus();
|
||||||
|
return status == 200;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "all":
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
package org.jeecg.modules.monitor.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.NumberUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.lang.management.OperatingSystemMXBean;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 内存健康检查
|
||||||
|
* @author: chenrui
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/sys/actuator/memory")
|
||||||
|
public class ActuatorMemoryController {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内存详情
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@GetMapping("/info")
|
||||||
|
public Result<?> getRedisInfo() throws Exception {
|
||||||
|
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
|
||||||
|
JSONObject operatingSystemJson = JSONObject.parseObject(JSONObject.toJSONString(operatingSystemMXBean));
|
||||||
|
long totalPhysicalMemory = operatingSystemJson.getLongValue("totalPhysicalMemorySize");
|
||||||
|
long freePhysicalMemory = operatingSystemJson.getLongValue("freePhysicalMemorySize");
|
||||||
|
long usedPhysicalMemory = totalPhysicalMemory - freePhysicalMemory;
|
||||||
|
Runtime runtime = Runtime.getRuntime();
|
||||||
|
Map<String,Number> result = new HashMap<>();
|
||||||
|
result.put("memory.physical.total", totalPhysicalMemory);
|
||||||
|
result.put("memory.physical.used", freePhysicalMemory);
|
||||||
|
result.put("memory.physical.free", usedPhysicalMemory);
|
||||||
|
result.put("memory.physical.usage", NumberUtil.div(usedPhysicalMemory, totalPhysicalMemory));
|
||||||
|
result.put("memory.runtime.total", runtime.totalMemory());
|
||||||
|
result.put("memory.runtime.used", runtime.freeMemory());
|
||||||
|
result.put("memory.runtime.max", runtime.totalMemory() - runtime.freeMemory());
|
||||||
|
result.put("memory.runtime.free", runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory());
|
||||||
|
result.put("memory.runtime.usage", NumberUtil.div(runtime.totalMemory() - runtime.freeMemory(), runtime.totalMemory()));
|
||||||
|
return Result.ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package org.jeecg.modules.system.config;
|
||||||
|
|
||||||
|
import me.zhyd.oauth.cache.AuthStateCache;
|
||||||
|
import org.jeecg.modules.system.cache.AuthStateRedisCache;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class AuthStateConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AuthStateCache authStateCache() {
|
||||||
|
return new AuthStateRedisCache();
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue