You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
191 lines
6.9 KiB
191 lines
6.9 KiB
/* */ package com.archive.framework.aspectj;
|
|
/* */
|
|
/* */ import com.alibaba.fastjson.JSONObject;
|
|
/* */ import com.alibaba.fastjson.serializer.SerializeFilter;
|
|
/* */ import com.alibaba.fastjson.support.spring.PropertyPreFilters;
|
|
/* */ import com.archive.common.utils.ServletUtils;
|
|
/* */ import com.archive.common.utils.StringUtils;
|
|
/* */ import com.archive.common.utils.security.ShiroUtils;
|
|
/* */ import com.archive.framework.aspectj.lang.annotation.Log;
|
|
/* */ import com.archive.framework.aspectj.lang.enums.BusinessStatus;
|
|
/* */ import com.archive.framework.manager.AsyncManager;
|
|
/* */ import com.archive.framework.manager.factory.AsyncFactory;
|
|
/* */ import com.archive.project.monitor.operlog.domain.OperLog;
|
|
/* */ import com.archive.project.system.user.domain.User;
|
|
/* */ import java.lang.reflect.Method;
|
|
/* */ import java.util.Map;
|
|
/* */ import org.aspectj.lang.JoinPoint;
|
|
/* */ import org.aspectj.lang.Signature;
|
|
/* */ import org.aspectj.lang.annotation.AfterReturning;
|
|
/* */ import org.aspectj.lang.annotation.AfterThrowing;
|
|
/* */ import org.aspectj.lang.annotation.Aspect;
|
|
/* */ import org.aspectj.lang.annotation.Pointcut;
|
|
/* */ import org.aspectj.lang.reflect.MethodSignature;
|
|
/* */ import org.slf4j.Logger;
|
|
/* */ import org.slf4j.LoggerFactory;
|
|
/* */ import org.springframework.stereotype.Component;
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ @Aspect
|
|
/* */ @Component
|
|
/* */ public class LogAspect
|
|
/* */ {
|
|
/* 36 */ private static final Logger log = LoggerFactory.getLogger(com.archive.framework.aspectj.LogAspect.class);
|
|
/* */
|
|
/* */
|
|
/* 39 */ public static final String[] EXCLUDE_PROPERTIES = new String[] { "password", "oldPassword", "newPassword", "confirmPassword" };
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ @Pointcut("@annotation(com.archive.framework.aspectj.lang.annotation.Log)")
|
|
/* */ public void logPointCut() {}
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ @AfterReturning(pointcut = "logPointCut()", returning = "jsonResult")
|
|
/* */ public void doAfterReturning(JoinPoint joinPoint, Object jsonResult) {
|
|
/* 55 */ handleLog(joinPoint, null, jsonResult);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ @AfterThrowing(value = "logPointCut()", throwing = "e")
|
|
/* */ public void doAfterThrowing(JoinPoint joinPoint, Exception e) {
|
|
/* 67 */ handleLog(joinPoint, e, null);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ protected void handleLog(JoinPoint joinPoint, Exception e, Object jsonResult) {
|
|
/* */ try {
|
|
/* 75 */ Log controllerLog = getAnnotationLog(joinPoint);
|
|
/* 76 */ if (controllerLog == null) {
|
|
/* */ return;
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* 82 */ User currentUser = ShiroUtils.getSysUser();
|
|
/* */
|
|
/* */
|
|
/* 85 */ OperLog operLog = new OperLog();
|
|
/* 86 */ operLog.setStatus(Integer.valueOf(BusinessStatus.SUCCESS.ordinal()));
|
|
/* */
|
|
/* 88 */ String ip = ShiroUtils.getIp();
|
|
/* 89 */ operLog.setOperIp(ip);
|
|
/* */
|
|
/* 91 */ operLog.setJsonResult(StringUtils.substring(JSONObject.toJSONString(jsonResult), 0, 2000));
|
|
/* */
|
|
/* 93 */ operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
|
|
/* 94 */ if (currentUser != null) {
|
|
/* */
|
|
/* 96 */ operLog.setOperName(currentUser.getLoginName());
|
|
/* 97 */ if (StringUtils.isNotNull(currentUser.getDept()) &&
|
|
/* 98 */ StringUtils.isNotEmpty(currentUser.getDept().getDeptName()))
|
|
/* */ {
|
|
/* 100 */ operLog.setDeptName(currentUser.getDept().getDeptName());
|
|
/* */ }
|
|
/* */ }
|
|
/* */
|
|
/* 104 */ if (e != null) {
|
|
/* */
|
|
/* 106 */ operLog.setStatus(Integer.valueOf(BusinessStatus.FAIL.ordinal()));
|
|
/* 107 */ operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
|
|
/* */ }
|
|
/* */
|
|
/* 110 */ String className = joinPoint.getTarget().getClass().getName();
|
|
/* 111 */ String methodName = joinPoint.getSignature().getName();
|
|
/* 112 */ operLog.setMethod(className + "." + methodName + "()");
|
|
/* */
|
|
/* 114 */ operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
|
/* */
|
|
/* 116 */ getControllerMethodDescription(controllerLog, operLog);
|
|
/* */
|
|
/* 118 */ AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
|
|
/* */ }
|
|
/* 120 */ catch (Exception exp) {
|
|
/* */
|
|
/* */
|
|
/* 123 */ log.error("==前置通知异常==");
|
|
/* 124 */ log.error("异常信息:{}", exp.getMessage());
|
|
/* 125 */ exp.printStackTrace();
|
|
/* */ }
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public void getControllerMethodDescription(Log log, OperLog operLog) throws Exception {
|
|
/* 139 */ operLog.setBusinessType(Integer.valueOf(log.businessType().ordinal()));
|
|
/* */
|
|
/* 141 */ operLog.setTitle(log.title());
|
|
/* */
|
|
/* 143 */ operLog.setOperatorType(Integer.valueOf(log.operatorType().ordinal()));
|
|
/* */
|
|
/* 145 */ if (log.isSaveRequestData())
|
|
/* */ {
|
|
/* */
|
|
/* 148 */ setRequestValue(operLog);
|
|
/* */ }
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ private void setRequestValue(OperLog operLog) {
|
|
/* 160 */ Map<String, String[]> map = ServletUtils.getRequest().getParameterMap();
|
|
/* 161 */ if (StringUtils.isNotEmpty(map)) {
|
|
/* */
|
|
/* 163 */ PropertyPreFilters.MySimplePropertyPreFilter excludefilter = (new PropertyPreFilters()).addFilter();
|
|
/* 164 */ excludefilter.addExcludes(EXCLUDE_PROPERTIES);
|
|
/* 165 */ String params = JSONObject.toJSONString(map, (SerializeFilter)excludefilter, new com.alibaba.fastjson.serializer.SerializerFeature[0]);
|
|
/* 166 */ operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
|
/* */ }
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ private Log getAnnotationLog(JoinPoint joinPoint) throws Exception {
|
|
/* 175 */ Signature signature = joinPoint.getSignature();
|
|
/* 176 */ MethodSignature methodSignature = (MethodSignature)signature;
|
|
/* 177 */ Method method = methodSignature.getMethod();
|
|
/* */
|
|
/* 179 */ if (method != null)
|
|
/* */ {
|
|
/* 181 */ return method.<Log>getAnnotation(Log.class);
|
|
/* */ }
|
|
/* 183 */ return null;
|
|
/* */ }
|
|
/* */ }
|
|
|
|
|
|
/* Location: C:\Users\Administrator\Desktop\extracted.zip!\extracted\BOOT-INF\classes\com\archive\framework\aspectj\LogAspect.class
|
|
* Java compiler version: 8 (52.0)
|
|
* JD-Core Version: 1.1.3
|
|
*/ |