parent
f3cfac58d5
commit
feb757b19c
@ -0,0 +1,37 @@
|
|||||||
|
package com.xjs.business.log.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务日志实体类
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TaskLog implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 主键id */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 任务名称 */
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 方法名 */
|
||||||
|
private String method;
|
||||||
|
|
||||||
|
/** 类路径 */
|
||||||
|
private String classPath;
|
||||||
|
|
||||||
|
/** 请求时间 */
|
||||||
|
private Long requestTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.xjs.job.aop;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务日志注解
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-01
|
||||||
|
*/
|
||||||
|
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface TaskLog {
|
||||||
|
/**
|
||||||
|
* 任务名称
|
||||||
|
*/
|
||||||
|
public String name() default "";
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
package com.xjs.job.aop;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.business.log.RemoteLogFeign;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.Signature;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务日志切面类
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-01
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Aspect
|
||||||
|
@Log4j2
|
||||||
|
public class taskLogAspect {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RemoteLogFeign remoteLogFeign;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 声明AOP签名
|
||||||
|
*/
|
||||||
|
@Pointcut("@annotation(com.xjs.job.aop.TaskLog)")
|
||||||
|
public void pointcut() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环绕切入
|
||||||
|
*/
|
||||||
|
@Around("pointcut()")
|
||||||
|
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
Object obj = null;
|
||||||
|
try {
|
||||||
|
//切入前-----
|
||||||
|
// 开始时间
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
obj = joinPoint.proceed();
|
||||||
|
|
||||||
|
//切入后-----
|
||||||
|
// 结束时间
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
long between = endTime - startTime;
|
||||||
|
log.info("调用定时任务耗费时间:{}ms", between);
|
||||||
|
|
||||||
|
this.handle(joinPoint, between);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理切面逻辑
|
||||||
|
*
|
||||||
|
* @param joinPoint 切入点
|
||||||
|
* @param between 请求时长
|
||||||
|
*/
|
||||||
|
private void handle(ProceedingJoinPoint joinPoint, Long between) {
|
||||||
|
//获取目标类名及方法名
|
||||||
|
Signature signature = joinPoint.getSignature();
|
||||||
|
String method = signature.getName();
|
||||||
|
Class aClass = signature.getDeclaringType();
|
||||||
|
Method[] methods = aClass.getMethods();
|
||||||
|
String className = aClass.getName();
|
||||||
|
|
||||||
|
com.xjs.business.log.domain.TaskLog taskLog = new com.xjs.business.log.domain.TaskLog();
|
||||||
|
|
||||||
|
taskLog.setMethod(method);
|
||||||
|
taskLog.setClassPath(className);
|
||||||
|
taskLog.setRequestTime(between);
|
||||||
|
|
||||||
|
//根据目标的方法名判断当前方法
|
||||||
|
for (Method thisMethod : methods) {
|
||||||
|
if (method.equals(thisMethod.getName())) {
|
||||||
|
Annotation[] declaredAnnotations = thisMethod.getDeclaredAnnotations();
|
||||||
|
for (Annotation annotation : declaredAnnotations) {
|
||||||
|
if (annotation instanceof TaskLog) {
|
||||||
|
String name = ((TaskLog) annotation).name();
|
||||||
|
taskLog.setName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
R<Object> r = remoteLogFeign.saveTaskLog(taskLog);
|
||||||
|
log.info(r.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<template>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "TaskLog"
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.xjs.tasklog.controller;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.tasklog.domain.TaskLog;
|
||||||
|
import com.xjs.tasklog.service.TaskLogService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务日志controller
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-01
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("taskLog")
|
||||||
|
@Api(tags = "业务模块-任务日志")
|
||||||
|
public class TaskLogController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskLogService taskLogService;
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------内部调用rpc------------------------
|
||||||
|
|
||||||
|
@PostMapping("saveForPRC")
|
||||||
|
@ApiOperation("供AOP切面RPC远程调用")
|
||||||
|
public R<Object> saveTaskLog(@RequestBody TaskLog taskLog) {
|
||||||
|
boolean save = taskLogService.save(taskLog);
|
||||||
|
return save ? R.ok() : R.fail();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.xjs.tasklog.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务日志实体类
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TaskLog implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 主键id */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 任务名称 */
|
||||||
|
@Excel(name = "任务名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 方法名 */
|
||||||
|
@Excel(name = "方法名")
|
||||||
|
private String method;
|
||||||
|
|
||||||
|
/** 类路径 */
|
||||||
|
@Excel(name = "类路径")
|
||||||
|
private String classPath;
|
||||||
|
|
||||||
|
/** 请求时间 */
|
||||||
|
@Excel(name = "请求时间")
|
||||||
|
private Long requestTime;
|
||||||
|
|
||||||
|
@Excel(name = "创建时间",dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.xjs.tasklog.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.xjs.tasklog.domain.TaskLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务日志mapper
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-01
|
||||||
|
*/
|
||||||
|
public interface TaskLogMapper extends BaseMapper<TaskLog> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.xjs.tasklog.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.xjs.tasklog.domain.TaskLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务日志service
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-01
|
||||||
|
*/
|
||||||
|
public interface TaskLogService extends IService<TaskLog> {
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.xjs.tasklog.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.xjs.tasklog.domain.TaskLog;
|
||||||
|
import com.xjs.tasklog.mapper.TaskLogMapper;
|
||||||
|
import com.xjs.tasklog.service.TaskLogService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务日志service实现
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-01
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TaskLogServiceImpl extends ServiceImpl<TaskLogMapper, TaskLog> implements TaskLogService {
|
||||||
|
}
|
Loading…
Reference in new issue