mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-01-26 03:44:57 +08:00
Compare commits
3 Commits
34efcf4cd4
...
b51e62d646
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b51e62d646 | ||
|
|
a256618d5d | ||
|
|
93111d622a |
@@ -252,4 +252,8 @@ public class SysOperLog extends BaseEntity
|
||||
{
|
||||
this.costTime = costTime;
|
||||
}
|
||||
|
||||
public String toLogString(){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,25 +343,25 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36);
|
||||
// time_low
|
||||
builder.append(digits(mostSigBits >> 32, 8));
|
||||
if (false == isSimple)
|
||||
if (!isSimple)
|
||||
{
|
||||
builder.append('-');
|
||||
}
|
||||
// time_mid
|
||||
builder.append(digits(mostSigBits >> 16, 4));
|
||||
if (false == isSimple)
|
||||
if (!isSimple)
|
||||
{
|
||||
builder.append('-');
|
||||
}
|
||||
// time_high_and_version
|
||||
builder.append(digits(mostSigBits, 4));
|
||||
if (false == isSimple)
|
||||
if (!isSimple)
|
||||
{
|
||||
builder.append('-');
|
||||
}
|
||||
// variant_and_sequence
|
||||
builder.append(digits(leastSigBits >> 48, 4));
|
||||
if (false == isSimple)
|
||||
if (!isSimple)
|
||||
{
|
||||
builder.append('-');
|
||||
}
|
||||
|
||||
@@ -7,12 +7,17 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ruoyi.common.core.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.PageUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.sql.SqlUtil;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.core.web.page.TableSupport;
|
||||
|
||||
/**
|
||||
* web层通用数据处理
|
||||
@@ -48,6 +53,19 @@ public class BaseController
|
||||
PageUtils.startPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求排序数据
|
||||
*/
|
||||
protected void startOrderBy()
|
||||
{
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
if (StringUtils.isNotEmpty(pageDomain.getOrderBy()))
|
||||
{
|
||||
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
|
||||
PageHelper.orderBy(orderBy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理分页的线程变量
|
||||
*/
|
||||
|
||||
@@ -56,16 +56,8 @@ public class PreAuthorizeAspect
|
||||
// 注解鉴权
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
checkMethodAnnotation(signature.getMethod());
|
||||
try
|
||||
{
|
||||
// 执行原有逻辑
|
||||
Object obj = joinPoint.proceed();
|
||||
return obj;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
// 执行原有逻辑
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,7 +57,7 @@ public class GenController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改代码生成业务
|
||||
* 获取代码生成信息
|
||||
*/
|
||||
@RequiresPermissions("tool:gen:query")
|
||||
@GetMapping(value = "/{tableId}")
|
||||
|
||||
@@ -178,7 +178,7 @@ public class SysJobController extends BaseController
|
||||
@RequiresPermissions("monitor:job:remove")
|
||||
@Log(title = "定时任务", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{jobIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException
|
||||
public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException
|
||||
{
|
||||
jobService.deleteJobByIds(jobIds);
|
||||
return success();
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.ruoyi.job.util;
|
||||
import java.util.Date;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.ruoyi.common.core.constant.ScheduleConstants;
|
||||
@@ -30,7 +29,7 @@ public abstract class AbstractQuartzJob implements Job
|
||||
private static ThreadLocal<Date> threadLocal = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException
|
||||
public void execute(JobExecutionContext context)
|
||||
{
|
||||
SysJob sysJob = new SysJob();
|
||||
BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.ruoyi.system.log;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @Auther : qzy
|
||||
* @Date: 2024/1/24 16:55
|
||||
**/
|
||||
public class AccessAddressUtils {
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户真实IP地址,不使用request.getRemoteAddr();的原因是有可能用户使用了代理软件方式避免真实IP地址,
|
||||
* 参考文章: http://developer.51cto.com/art/201111/305181.htm
|
||||
*
|
||||
* 可是,如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值,究竟哪个才是真正的用户端的真实IP呢?
|
||||
* 答案是取X-Forwarded-For中第一个非unknown的有效IP字符串。
|
||||
*
|
||||
* 如:X-Forwarded-For:192.168.1.110, 192.168.1.120, 192.168.1.130,
|
||||
* 192.168.1.100
|
||||
*
|
||||
* 用户真实IP为: 192.168.1.110
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static String getIpAddress(HttpServletRequest request) {
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.ruoyi.system.log;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 日志记录所有请求 工具类
|
||||
* @Auther : qzy
|
||||
* @Date: 2024/1/24 16:55
|
||||
**/
|
||||
public final class LoggerUtils {
|
||||
|
||||
public static final String LOGGER_RETURN = "LOGGER_RETURN";
|
||||
|
||||
private LoggerUtils() {}
|
||||
|
||||
/**
|
||||
* 获取客户端ip地址
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static String getCliectIp(HttpServletRequest request)
|
||||
{
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
if (ip == null || Objects.equals(ip.trim(), "") || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || Objects.equals(ip.trim(), "") || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || Objects.equals(ip.trim(), "") || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
|
||||
// 多个路由时,取第一个非unknown的ip
|
||||
final String[] arr = ip.split(",");
|
||||
for (final String str : arr) {
|
||||
if (!"unknown".equalsIgnoreCase(str)) {
|
||||
ip = str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为ajax请求
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static String getRequestType(HttpServletRequest request) {
|
||||
return request.getHeader("X-Requested-With");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.ruoyi.system.log.aop;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.system.log.AccessAddressUtils;
|
||||
import com.ruoyi.system.log.LoggerUtils;
|
||||
import com.ruoyi.system.log.dto.LoggerEntity;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : qzy
|
||||
* @since : 2024/1/24 16:36
|
||||
* <p style='color:yellow'>
|
||||
* 通用请求日志打印处理类,方便联调/测试,生产环境视情况可选择是否保留
|
||||
*
|
||||
* </p>
|
||||
**/
|
||||
@Aspect
|
||||
@Component
|
||||
public class WebRequestLogAspect {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WebRequestLogAspect.class);
|
||||
|
||||
private final ThreadLocal<LoggerEntity> threadLocal = new ThreadLocal<>();
|
||||
|
||||
private final ThreadLocal<Long> startTimeLocal = new ThreadLocal<>();
|
||||
|
||||
|
||||
@Pointcut("within(com.ruoyi.*.controller.*)")
|
||||
public void webRequestLog() {
|
||||
}
|
||||
|
||||
@Before("webRequestLog()")
|
||||
public void doBefore(JoinPoint joinPoint) {
|
||||
try {
|
||||
// 接收到请求,记录请求内容
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
if (requestAttributes == null) {
|
||||
// 防止拦截的不是接口层,获取不到请求数据的情况
|
||||
threadLocal.remove();
|
||||
return;
|
||||
}
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) requestAttributes;
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
//处理特殊请求,直接返回
|
||||
// if (request.getRequestURI().contains("admin/sysLog")) {
|
||||
// threadLocal.remove();
|
||||
// return;
|
||||
// }
|
||||
|
||||
String method = request.getMethod();
|
||||
String params;
|
||||
String post_code = "POST";
|
||||
if (post_code.equals(method)) {
|
||||
Object[] paramsArray = joinPoint.getArgs();
|
||||
params = argsArrayToString(paramsArray);
|
||||
} else {
|
||||
//获取请求参数信息
|
||||
params = JSON.toJSONString(request.getParameterMap());
|
||||
}
|
||||
|
||||
LoggerEntity optLog = new LoggerEntity();
|
||||
//设置请求方法
|
||||
optLog.setId(RandomUtils.nextLong());
|
||||
optLog.setMethodCode(request.getMethod());
|
||||
//设置请求类型(json|普通请求)
|
||||
optLog.setTypeCode(LoggerUtils.getRequestType(request));
|
||||
//设置请求参数内容json字符串
|
||||
optLog.setParamData(params);
|
||||
//设置请求地址
|
||||
optLog.setUri(request.getRequestURI());
|
||||
//设置sessionId
|
||||
optLog.setSessionId(request.getSession().getId());
|
||||
//设置调用的java类
|
||||
optLog.setJavaBean(joinPoint.getSignature().getDeclaringTypeName());
|
||||
//设置调用的java方法
|
||||
optLog.setJavaMethod(joinPoint.getSignature().getName());
|
||||
// optLog.setParamData(params);
|
||||
//设置调用方ip
|
||||
optLog.setClientIp(AccessAddressUtils.getIpAddress(request));
|
||||
threadLocal.set(optLog);
|
||||
startTimeLocal.set(System.currentTimeMillis());
|
||||
LOGGER.info(optLog.toLogStr());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("***操作请求日志记录失败doBefore()***", e);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterReturning(returning = "result", pointcut = "webRequestLog()")
|
||||
public void doAfterReturning(Object result) {
|
||||
// 处理完请求,返回内容
|
||||
if (threadLocal.get() == null) {
|
||||
return;
|
||||
}
|
||||
LoggerEntity optLog = threadLocal.get();
|
||||
Long startTime = startTimeLocal.get();
|
||||
optLog.setReturnData(JSON.toJSONString(result));
|
||||
optLog.setTimeConsuming((int) (System.currentTimeMillis() - startTime));
|
||||
LOGGER.info(optLog.toLogStr());
|
||||
threadLocal.remove();
|
||||
startTimeLocal.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求参数拼装
|
||||
* @return String
|
||||
*/
|
||||
private String argsArrayToString(Object[] paramsArray) {
|
||||
StringBuilder params = new StringBuilder();
|
||||
if (paramsArray != null) {
|
||||
for (Object o : paramsArray) {
|
||||
if (o instanceof MultipartFile || o instanceof MultipartFile[]) {
|
||||
// 当导入文件时,不打印输出二进制
|
||||
params.append("上传文件 ");
|
||||
} else {
|
||||
try {
|
||||
Object jsonObj = JSON.toJSON(o);
|
||||
params.append(jsonObj.toString()).append(" ");
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug("参数json解析异常,{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return params.toString().trim();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package com.ruoyi.system.log.dto;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* 日志记录所有请求 实体类
|
||||
* @Auther : qzy
|
||||
* @Date: 2024/1/24 16:55
|
||||
**/
|
||||
public class LoggerEntity implements Serializable {
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 客户端请求ip
|
||||
*/
|
||||
private String clientIp;
|
||||
/**
|
||||
* 客户端请求路径
|
||||
*/
|
||||
private String uri;
|
||||
/**
|
||||
* 终端请求方式,普通请求,ajax请求
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 请求方式method,post,get等
|
||||
*/
|
||||
private String method;
|
||||
/**
|
||||
* 请求参数内容,json
|
||||
*/
|
||||
private String paramData;
|
||||
/**
|
||||
* 请求接口唯一session标识
|
||||
*/
|
||||
private String sessionId;
|
||||
/**
|
||||
* 请求时间
|
||||
*/
|
||||
private Timestamp time;
|
||||
/**
|
||||
* 接口返回时间
|
||||
*/
|
||||
private String returnTime;
|
||||
/**
|
||||
* 接口返回数据json
|
||||
*/
|
||||
private String returnData;
|
||||
/**
|
||||
* 请求时httpStatusCode代码,如:200,400,404等
|
||||
*/
|
||||
private String httpStatusCode;
|
||||
/**
|
||||
* 请求耗时秒单位
|
||||
*/
|
||||
private int timeConsuming;
|
||||
private String javaBean;
|
||||
private String javaMethod;
|
||||
private String operaAdmin;
|
||||
private String operaSource;
|
||||
private String typeCode;
|
||||
private String methodCode;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getClientIp() {
|
||||
return clientIp;
|
||||
}
|
||||
|
||||
public void setClientIp(String clientIp) {
|
||||
this.clientIp = clientIp;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getParamData() {
|
||||
return paramData;
|
||||
}
|
||||
|
||||
public void setParamData(String paramData) {
|
||||
this.paramData = paramData;
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(String sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
public Timestamp getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(Timestamp time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getReturnTime() {
|
||||
return returnTime;
|
||||
}
|
||||
|
||||
public void setReturnTime(String returnTime) {
|
||||
this.returnTime = returnTime;
|
||||
}
|
||||
|
||||
public String getReturnData() {
|
||||
return returnData;
|
||||
}
|
||||
|
||||
public void setReturnData(String returnData) {
|
||||
this.returnData = returnData;
|
||||
}
|
||||
|
||||
public String getHttpStatusCode() {
|
||||
return httpStatusCode;
|
||||
}
|
||||
|
||||
public void setHttpStatusCode(String httpStatusCode) {
|
||||
this.httpStatusCode = httpStatusCode;
|
||||
}
|
||||
|
||||
public int getTimeConsuming() {
|
||||
return timeConsuming;
|
||||
}
|
||||
|
||||
public void setTimeConsuming(int timeConsuming) {
|
||||
this.timeConsuming = timeConsuming;
|
||||
}
|
||||
|
||||
public void setJavaBean(String javaBean) {
|
||||
this.javaBean = javaBean;
|
||||
}
|
||||
|
||||
public String getJavaBean() {
|
||||
return javaBean;
|
||||
}
|
||||
|
||||
public void setJavaMethod(String javaMethod) {
|
||||
this.javaMethod = javaMethod;
|
||||
}
|
||||
|
||||
public String getJavaMethod() {
|
||||
return javaMethod;
|
||||
}
|
||||
|
||||
public void setOperaAdmin(String operaAdmin) {
|
||||
|
||||
this.operaAdmin = operaAdmin;
|
||||
}
|
||||
|
||||
public String getOperaAdmin() {
|
||||
return operaAdmin;
|
||||
}
|
||||
|
||||
public void setOperaSource(String operaSource) {
|
||||
this.operaSource = operaSource;
|
||||
}
|
||||
|
||||
public String getOperaSource() {
|
||||
return operaSource;
|
||||
}
|
||||
|
||||
public void setTypeCode(String typeCode) {
|
||||
this.typeCode = typeCode;
|
||||
}
|
||||
|
||||
public String getTypeCode() {
|
||||
return typeCode;
|
||||
}
|
||||
|
||||
public void setMethodCode(String methodCode) {
|
||||
this.methodCode = methodCode;
|
||||
}
|
||||
|
||||
public String getMethodCode() {
|
||||
return methodCode;
|
||||
}
|
||||
|
||||
public String toLogStr(){
|
||||
return String.format("\n==>请求IP:{%s},\n==>请求路径:{%s} - {%s},\n==>方法名:{%s},\n==>入参:{%s},\n==>出参:{%s}", this.clientIp, this.methodCode, this.uri, this.javaMethod, this.paramData,this.returnData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 统一请求日志处理工具
|
||||
*/
|
||||
package com.ruoyi.system.log;
|
||||
@@ -146,6 +146,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
insert into sys_user(
|
||||
<if test="userId != null and userId != 0">user_id,</if>
|
||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||
<if test="userName != null and userName != ''">user_name,</if>
|
||||
<if test="nickName != null and nickName != ''">nick_name,</if>
|
||||
<if test="email != null and email != ''">email,</if>
|
||||
<if test="avatar != null and avatar != ''">avatar,</if>
|
||||
@@ -177,7 +178,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
update sys_user
|
||||
<set>
|
||||
<if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
|
||||
<if test="userName != null and userName != ''">user_name = #{userName},</if>
|
||||
<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
|
||||
<if test="email != null ">email = #{email},</if>
|
||||
<if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
|
||||
|
||||
Reference in New Issue
Block a user