use of com.topcom.cms.domain.OperationLog in project topcom-cloud by 545314690.
the class OperationLogService method doBasicProfiling.
@AfterReturning("anyMethod()")
public void doBasicProfiling(JoinPoint pjp) throws Throwable {
HttpServletRequest request = SubjectUtil.getRequest();
Object[] args = pjp.getArgs();
OperationLog ol = new OperationLog();
Object obj = args[0];
// 拦截的实体类 Object target = pjp.getTarget();
Class<?> entityClazz = (Class<?>) ((ParameterizedType) pjp.getTarget().getClass().getGenericSuperclass()).getActualTypeArguments()[0];
ol.setEntity(entityClazz.getName());
if (obj instanceof Long) {
ol.setOperation(OperationLog.Operation.DELETE);
} else if (obj instanceof BaseEntityModel) {
BaseEntityModel objModel = (BaseEntityModel) obj;
if (objModel.getId() == null || objModel.getId() == 0) {
ol.setOperation(OperationLog.Operation.CREATE);
} else {
ol.setOperation(OperationLog.Operation.MODIFY);
}
ol.setEntity(objModel.getEntityName());
} else {
return;
}
// 拦截的方法名称
String methodName = pjp.getSignature().getName();
/**
* request是null,说明是系统调用save,否则是用户调用
*/
if (request == null) {
ol.setUsername("系统操作");
} else {
User user = SubjectUtil.getCurrentUser();
ol.setHost(request.getRemoteHost());
if (user != null) {
ol.setUserId(user.getId());
ol.setUsername(user.getUsername());
}
}
ol.setMethod(methodName);
/**
* 不使用save方法,更改了操作日志的保存方法,否则会造成无限循环调用
*/
// TODO:写一个注解,在方法名上标注不被拦截的方法
operationLogManager.persist(ol);
}
Aggregations