package com.landtool.lanbase.common.aspect;
|
|
import java.lang.reflect.Method;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.apache.shiro.SecurityUtils;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
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.landtool.lanbase.common.utils.HttpContextUtils;
|
import com.landtool.lanbase.common.utils.IPUtils;
|
import com.landtool.lanbase.config.LoginConfigProperties;
|
import com.landtool.lanbase.modules.log.entity.LogAction;
|
import com.landtool.lanbase.modules.log.service.LogActionService;
|
import com.landtool.lanbase.modules.org.entity.OrgUser;
|
import com.landtool.lanbase.modules.res.entity.Res_Ext3D;
|
import com.landtool.lanbase.modules.res.entity.Res_ExtBaseMap;
|
import com.landtool.lanbase.modules.res.entity.Res_ExtBusinessLayer;
|
import com.landtool.lanbase.modules.res.entity.Res_ExtDataBase;
|
import com.landtool.lanbase.modules.res.entity.Res_ExtIntegrate;
|
import com.landtool.lanbase.modules.res.entity.Res_ExtInterFaceService;
|
import com.landtool.lanbase.modules.res.entity.Res_ExtSpaceServerWithBLOBs;
|
import com.landtool.lanbase.modules.res.entity.Res_ExtThemeMap;
|
import com.landtool.lanbase.modules.res.entity.Res_MainInfo;
|
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
|
|
@Aspect
|
@Component
|
public class LogActionAspect {
|
@Autowired
|
private LogActionService logActionService;
|
|
@Autowired
|
private LoginConfigProperties loginConfig;
|
|
@Autowired
|
private ResMainInfoService resMainInfoService;
|
|
@Pointcut("@annotation(com.landtool.lanbase.common.annotation.LogAction)")
|
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;
|
//System.out.println("time"+time);
|
|
//保存日志
|
saveLogAction(point, time);
|
|
return result;
|
}
|
|
private void saveLogAction(ProceedingJoinPoint joinPoint, long time) {
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
Method method = signature.getMethod();
|
LogAction logAction = new LogAction();
|
com.landtool.lanbase.common.annotation.LogAction log = method.getAnnotation(com.landtool.lanbase.common.annotation.LogAction.class);
|
if(log != null){
|
//注解上的描述
|
String[] list = log.value().split(",");
|
logAction.setLargemodel(list[0]); //大模块
|
logAction.setSmallmodel(list[1]);//小模块
|
logAction.setRemark(list[2]); //备注
|
//记录资源id和标题
|
if(list[3].indexOf("|")!=-1){
|
logAction.setActiontype(list[3].substring(0,list[3].indexOf("|")));//操作类型
|
if(joinPoint.getArgs() != null && joinPoint.getArgs()[0] != null && joinPoint.getArgs().length > 0 ){
|
Integer resourceid = 0;
|
String title = "";
|
try{
|
resourceid = Integer.parseInt(joinPoint.getArgs()[0].toString());
|
}catch(Exception ex){
|
String className = joinPoint.getArgs()[0].getClass().getName().substring(joinPoint.getArgs()[0].getClass().getName().lastIndexOf(".")+1,joinPoint.getArgs()[0].getClass().getName().length());
|
switch (className){
|
case "Res_MainInfo":
|
Res_MainInfo mainInfo = (Res_MainInfo)joinPoint.getArgs()[0];
|
if(mainInfo != null && mainInfo.getResourceid() != null) resourceid = mainInfo.getResourceid();
|
break;
|
case "Res_ExtDataBase":
|
Res_ExtDataBase resExtDataBase = (Res_ExtDataBase)joinPoint.getArgs()[0];
|
if(resExtDataBase != null && resExtDataBase.getResourceid() != null) resourceid = resExtDataBase.getResourceid();
|
break;
|
case "Res_ExtInterFaceService":
|
Res_ExtInterFaceService resExtInterFaceService = (Res_ExtInterFaceService)joinPoint.getArgs()[0];
|
if(resExtInterFaceService != null && resExtInterFaceService.getResourceid() != null) resourceid = resExtInterFaceService.getResourceid();
|
break;
|
case "Res_ExtIntegrate":
|
Res_ExtIntegrate resExtIntegrate = (Res_ExtIntegrate)joinPoint.getArgs()[0];
|
if(resExtIntegrate != null && resExtIntegrate.getResourceid() != null) resourceid = resExtIntegrate.getResourceid();
|
break;
|
case "Res_ExtBaseMap":
|
Res_ExtBaseMap resExtBaseMap = (Res_ExtBaseMap)joinPoint.getArgs()[0];
|
if(resExtBaseMap != null && resExtBaseMap.getResourceid() != null) resourceid = resExtBaseMap.getResourceid();
|
break;
|
case "Res_ExtThemeMap":
|
Res_ExtThemeMap resExtThemeMap = (Res_ExtThemeMap)joinPoint.getArgs()[0];
|
if(resExtThemeMap != null && resExtThemeMap.getResourceid() != null) resourceid = resExtThemeMap.getResourceid();
|
break;
|
case "Res_ExtSpaceServerWithBLOBs":
|
Res_ExtSpaceServerWithBLOBs resExtSpaceServerWithBLOBs = (Res_ExtSpaceServerWithBLOBs)joinPoint.getArgs()[0];
|
if(resExtSpaceServerWithBLOBs != null && resExtSpaceServerWithBLOBs.getResourceid() != null) resourceid = resExtSpaceServerWithBLOBs.getResourceid();
|
break;
|
case "Res_Ext3D":
|
Res_Ext3D resExt3D = (Res_Ext3D)joinPoint.getArgs()[0];
|
if(resExt3D != null && resExt3D.getResourceid() != null) resourceid = resExt3D.getResourceid();
|
break;
|
case "Res_ExtBusinessLayer":
|
Res_ExtBusinessLayer resExtBusinessLayer = (Res_ExtBusinessLayer)joinPoint.getArgs()[0];
|
if(resExtBusinessLayer != null && resExtBusinessLayer.getResourceid() != null) resourceid = resExtBusinessLayer.getResourceid();
|
break;
|
}
|
}
|
logAction.setResourceid(resourceid);
|
if(list[3].indexOf("删除") != -1) {
|
title = joinPoint.getArgs()[1].toString();
|
}else{
|
if (resourceid != null && resourceid != 0) {
|
title = resMainInfoService.selectByPrimaryKey(resourceid) != null ? resMainInfoService.selectByPrimaryKey(resourceid).getTitle() : "";
|
}
|
}
|
logAction.setTitle(title);
|
}
|
}else{
|
logAction.setActiontype(list[3]);//操作类型
|
}
|
}
|
|
//获取request
|
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
String url=request.getServletPath();
|
logAction.setRequesturl(url);
|
//设置IP地址
|
logAction.setRequestip(IPUtils.getIpAddr(request));
|
|
//用户名
|
Long userid = ((OrgUser) SecurityUtils.getSubject().getPrincipal()).getUserid();
|
logAction.setUserid(userid);
|
|
logAction.setAppid(loginConfig.getAppId());
|
|
// logAction.setLargemodel(loginConfig.getAppFullName());
|
|
|
//保存系统日志
|
logActionService.save(logAction);
|
}
|
}
|