Makedown的常用

Makedown的常用

标题

三级标题

总共有六级标题

字体

HelloWorld! 加粗

HelloWorld! 斜体

HelloWorld! 加粗斜体

HelloWorld! 波浪线

引用

面试还在继续,加油,继续努力!!!

分割线



图片

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-59BuRkqe-1624073199703)(C:\Users\luxun\Pictures\Screenshots\屏幕截图(1)].png)

截图

超链接

点击跳到布道师

列表

  1. A
  2. C
  • A
  • B
  • C

表格

姓名性别生日
张三1997.1.1

代码

‘hello’

package com.isportsx.common.aspect;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.gson.Gson;
import com.isportsx.common.annotation.SysLog;
import com.isportsx.common.utils.DateUtils;
import com.isportsx.common.utils.HttpContextUtils;
import com.isportsx.common.utils.IPUtils;
import com.isportsx.modules.sys.domain.TsysLog;
import com.isportsx.modules.sys.domain.TsysUserinfo;
import com.isportsx.modules.sys.service.TsysLogService;
/**
 * Title:系统日志,切面处理类 Copyright: Copyright (c) 2017
 * Company:creatorblue.co.,ltd
 * 修改系统日志切面,调到服务层统一处理
 * @author creatorblue.co.,ltd
 * @version 1.0
 */
@Aspect
@Component
public class SysLogAspect {
    //本地异常日志记录对象
    private ThreadLocal<Long> startTime = new ThreadLocal<Long>();

    private ThreadLocal<TsysLog> localLog = new ThreadLocal<TsysLog>();
	@Autowired
	private TsysLogService sysLogService;
	
	//定义日志切入点
	@Pointcut("@annotation(com.isportsx.common.annotation.SysLog)")
	public void logPointCut() { 
		
	}
	
	@Around("logPointCut()")
	public Object around(ProceedingJoinPoint point) throws Throwable {
		long beginTime = System.currentTimeMillis();
		//执行方法
		Object result = point.proceed();
		//执行时长(毫秒)
		long time = System.currentTimeMillis() - beginTime;

		//保存日志
		saveSysLog(point, time);

		return result;
	}
	 /**
     * 后置通知 用于拦截service层记录用户的操作
     *
     * @param joinPoint 切点
     */
	
	private void saveSysLog(ProceedingJoinPoint joinPoint,long time) {
		MethodSignature signature = (MethodSignature) joinPoint.getSignature();
		Method method = signature.getMethod();
	    TsysLog sysLog = new TsysLog();
		SysLog syslog = method.getAnnotation(SysLog.class);
		if(syslog != null){
			//注解上的描述 
			sysLog.setOperation(syslog.value());
		}
		
		//请求的方法名
		String className = joinPoint.getTarget().getClass().getName();
		String methodName = signature.getName();
		sysLog.setMethod(className + "." + methodName + "()");
		
		//请求的参数
		Object[] args = joinPoint.getArgs();
		String params = new Gson().toJson(args[0]);
		sysLog.setParams(params);
		
		//获取request
		HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
		//设置IP地址
		sysLog.setIp(IPUtils.getIpAddr(request));
		
		//用户名
		String username = ((TsysUserinfo) SecurityUtils.getSubject().getPrincipal()).getUserRealname();
		sysLog.setUsername(username);	
		sysLog.setCreateDate(DateUtils.getNowTimeStamp());
		sysLog.setAppid("");
		//耗时
		sysLog.setTimeConsuming(time);
		sysLog.setRequestUri(request.getRequestURI());
		sysLog.setLogType(0);
		sysLog.setUserAgent(request.getHeader("User-Agent"));
		sysLog.setExceptionCode(null);
		sysLog.setExceptionDetail(null);
		//保存系统日志
		sysLogService.save(sysLog);
	}
	
	
	 /**
     * 异常通知 用于拦截service层记录异常日志
     *
     * @param joinPoint
     * @param e
     */
    @AfterThrowing(pointcut = "logPointCut()", throwing = "e")
    public void doAfterThrowing(JoinPoint joinPoint, Throwable e) {
        //Map<String,String[]> requestParams = new HashMap<>();
        //请求的参数
       // Object[] args = joinPoint.getArgs();

        try {
            /*==========数据库日志=========*/
            TsysLog log = localLog.get();

            log.setTimeConsuming(System.currentTimeMillis() - startTime.get());
            log.setLogType(1);

            log.setExceptionCode(e.getClass().getName());
            log.setExceptionDetail(e.getMessage());

            //保存数据库
            sysLogService.save(log);
        }  catch (Exception ex) {
        	ex.printStackTrace();
            //记录本地异常日志
           // log.error("异常方法全路径:{},异常信息:{},请求参数:{}", getFullMethodName(joinPoint), e.getMessage(), JSONUtil.toJsonStr(args));
        }
    }
	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值