|  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.lang.reflect.Method; | 
|---|
|  |  |  | import java.util.Collections; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 保存操作记录 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void saveLog(JoinPoint joinPoint, Object result, Exception e) { | 
|---|
|  |  |  | // 记录模块名、操作功能、请求方法、请求参数、返回结果 | 
|---|
|  |  |  | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | 
|---|
|  |  |  | Method method = signature.getMethod(); | 
|---|
|  |  |  | if (null == method) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OperationLog ol = method.getAnnotation(OperationLog.class); | 
|---|
|  |  |  | if (null == ol) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String desc = getDescription(method, ol); | 
|---|
|  |  |  | if (Cools.isEmpty(desc)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OperationRecord record = new OperationRecord(); | 
|---|
|  |  |  | Long endTime = startTime.get(); | 
|---|
|  |  |  | record.setCreateTime(new Date()); | 
|---|
|  |  |  | // 记录操作耗时 | 
|---|
|  |  |  | if (endTime != null) { | 
|---|
|  |  |  | record.setSpendTime((int) (System.currentTimeMillis() - endTime)); | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | record.setResult(1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 记录模块名、操作功能、请求方法、请求参数、返回结果 | 
|---|
|  |  |  | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | 
|---|
|  |  |  | Method method = signature.getMethod(); | 
|---|
|  |  |  | if (method != null) { | 
|---|
|  |  |  | OperationLog ol = method.getAnnotation(OperationLog.class); | 
|---|
|  |  |  | if (ol != null) { | 
|---|
|  |  |  | // 记录操作功能 | 
|---|
|  |  |  | record.setNamespace(getDescription(method, ol)); | 
|---|
|  |  |  | // 记录备注 | 
|---|
|  |  |  | if (!Cools.isEmpty(ol.comments())) { | 
|---|
|  |  |  | record.setMemo(ol.comments()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 记录请求参数 | 
|---|
|  |  |  | if (ol.param() && request != null) { | 
|---|
|  |  |  | record.setRequest(Utils.sub(getParams(joinPoint, request), MAX_LENGTH)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 记录请求结果 | 
|---|
|  |  |  | if (ol.result() && result != null) { | 
|---|
|  |  |  | record.setResponse(Utils.sub(JSON.toJSONString(result), MAX_LENGTH)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 记录操作功能 | 
|---|
|  |  |  | record.setNamespace(desc); | 
|---|
|  |  |  | // 记录备注 | 
|---|
|  |  |  | if (!Cools.isEmpty(ol.comments())) { | 
|---|
|  |  |  | record.setMemo(ol.comments()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | operationRecordService.save(record); | 
|---|
|  |  |  | // 记录请求参数 | 
|---|
|  |  |  | if (ol.param() && request != null) { | 
|---|
|  |  |  | record.setRequest(Utils.sub(getParams(joinPoint, request), MAX_LENGTH)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 记录请求结果 | 
|---|
|  |  |  | if (ol.result() && result != null) { | 
|---|
|  |  |  | record.setResponse(Utils.sub(JSON.toJSONString(result), MAX_LENGTH)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | operationRecordService.saveAsync(record); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|