Commit 7ff74ee3 authored by 杨钧's avatar 杨钧

客服系统增加记录操作日志注解

parent 571f32b7
package cn.quantgroup.customer.aop;
import java.lang.annotation.*;
/**
* @author yangjun
* @Date 2020/4/14 13:28
* @Desc
* @Update
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface OperateLog {
String moduleName() default "";
}
package cn.quantgroup.customer.aop;
import cn.quantgroup.customer.entity.User;
import cn.quantgroup.customer.model.user.OperateLogModel;
import cn.quantgroup.customer.service.IKaService;
import cn.quantgroup.customer.util.DateUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
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.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.Objects;
/**
* @author yangjun
* @Date 2020/4/14 13:33
* @Desc
* @Update
*/
@Aspect
@Component
@Slf4j
public class OperateLogAspect {
@Autowired
private IKaService kaService;
@Pointcut("@annotation(cn.quantgroup.customer.aop.OperateLog)")
public void operateLog() {
}
@Around(value = "operateLog()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
String logPre = "OperateLogAspect.around";
log.info("{} 进入切面", logPre);
Object[] args = pjp.getArgs();
log.info("{} 请求参数 {}", logPre,args);
Object result = pjp.proceed(args);
log.info("{} 请求参数 {},返回结果 {} ", logPre,args,result);
dealOperateLog(pjp,result);
return result;
}
private void dealOperateLog(ProceedingJoinPoint pjp,Object result){
String logPre = "OperateLogAspect.dealOperateLog";
Object[] args = pjp.getArgs();
StringBuffer reqStrBuffer = new StringBuffer();
String userNo = null;
String userName = null;
for(Object obj:args){
reqStrBuffer.append(String.valueOf(obj));
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(obj));
if(Objects.nonNull(jsonObject)){
if(jsonObject.containsKey("userNo")){
userNo = jsonObject.getString("userNo");
}
if(jsonObject.containsKey("userName")){
userName = jsonObject.getString("userName");
}
}
}
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method method = methodSignature.getMethod();
OperateLog oplog = method.getAnnotation(OperateLog.class);
log.info("{} 获得注解 oplog={}", logPre, oplog);
String className = pjp.getTarget().getClass().getName().substring(pjp.getTarget().getClass().getName().lastIndexOf(".")+1);
String methodName = method.getName();
String moduleName = oplog.moduleName();
String module = className.concat("|").concat(methodName);
if(StringUtils.isBlank(moduleName)){
// 类名 + 方法签名为 moduleName
moduleName = module;
}
log.info("{} 处理结果:{}",logPre,String.valueOf(result));
if(!StringUtils.isAnyBlank(userNo,userName)){
return;
}
OperateLogModel model = OperateLogModel.builder()
.userName(userName)
.userNo(userNo)
.module(module)
.moduleName(moduleName)
.request(reqStrBuffer.toString())
.response(String.valueOf(result))
.createAt(DateUtil.getCurrentTimestamp())
.build();
kaService.saveOperateLog(model);
}
}
package cn.quantgroup.customer.model.user;
import lombok.Builder;
import lombok.Data;
import java.sql.Timestamp;
/**
* @author yangjun
* @Date 2020/4/14 18:51
* @Desc
* @Update
*/
@Data
@Builder
public class OperateLogModel {
private String userNo;
private String userName;
private String module;
private String moduleName;
private String request;
private String response;
private Timestamp createAt;
}
package cn.quantgroup.customer.rest; package cn.quantgroup.customer.rest;
import cn.quantgroup.customer.aop.OperateLog;
import cn.quantgroup.customer.rest.param.ordermapping.EarlySettleUpOrderQueryParam; import cn.quantgroup.customer.rest.param.ordermapping.EarlySettleUpOrderQueryParam;
import cn.quantgroup.customer.rest.param.ordermapping.OperateEntryParam; import cn.quantgroup.customer.rest.param.ordermapping.OperateEntryParam;
import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam; import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
...@@ -66,6 +67,7 @@ public class OrderRest { ...@@ -66,6 +67,7 @@ public class OrderRest {
* @return * @return
*/ */
@PostMapping("/operateEntry") @PostMapping("/operateEntry")
@OperateLog(moduleName = "修改显示结清入口操作")
public JsonResult operateEntry(OperateEntryParam operateEntryParam) { public JsonResult operateEntry(OperateEntryParam operateEntryParam) {
log.info("[显示/隐藏结清入口操作],请求参数:operateEntryParam={}", operateEntryParam); log.info("[显示/隐藏结清入口操作],请求参数:operateEntryParam={}", operateEntryParam);
return orderService.operateEntry(operateEntryParam); return orderService.operateEntry(operateEntryParam);
......
...@@ -18,4 +18,8 @@ public class OperateEntryParam { ...@@ -18,4 +18,8 @@ public class OperateEntryParam {
*/ */
private Integer opState; private Integer opState;
private String userNo;
private String userName;
} }
...@@ -4,6 +4,7 @@ import cn.quantgroup.customer.model.kaordermapping.ApplyRequestHistory; ...@@ -4,6 +4,7 @@ import cn.quantgroup.customer.model.kaordermapping.ApplyRequestHistory;
import cn.quantgroup.customer.model.kaordermapping.ChannelConfigurationResult; import cn.quantgroup.customer.model.kaordermapping.ChannelConfigurationResult;
import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping; import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping;
import cn.quantgroup.customer.model.order.CallbackRecordList; import cn.quantgroup.customer.model.order.CallbackRecordList;
import cn.quantgroup.customer.model.user.OperateLogModel;
import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam; import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
...@@ -45,4 +46,10 @@ public interface IKaService { ...@@ -45,4 +46,10 @@ public interface IKaService {
* @return * @return
*/ */
JsonResult<ApplyRequestHistory> queryLatestChannelRequestFlows(String applyNo, Long channelId); JsonResult<ApplyRequestHistory> queryLatestChannelRequestFlows(String applyNo, Long channelId);
/**
* 保存操作记录
* @param model
*/
void saveOperateLog(OperateLogModel model);
} }
...@@ -6,6 +6,7 @@ import cn.quantgroup.customer.model.kaordermapping.ApplyRequestHistory; ...@@ -6,6 +6,7 @@ import cn.quantgroup.customer.model.kaordermapping.ApplyRequestHistory;
import cn.quantgroup.customer.model.kaordermapping.ChannelConfigurationResult; import cn.quantgroup.customer.model.kaordermapping.ChannelConfigurationResult;
import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping; import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping;
import cn.quantgroup.customer.model.order.CallbackRecordList; import cn.quantgroup.customer.model.order.CallbackRecordList;
import cn.quantgroup.customer.model.user.OperateLogModel;
import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam; import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IKaService; import cn.quantgroup.customer.service.IKaService;
...@@ -238,4 +239,26 @@ public class KaServiceImpl implements IKaService { ...@@ -238,4 +239,26 @@ public class KaServiceImpl implements IKaService {
throw new BusinessException(ErrorCodeEnum.NET_ERROR); throw new BusinessException(ErrorCodeEnum.NET_ERROR);
} }
} }
@Override
public void saveOperateLog(OperateLogModel model) {
String logPre = "[KaServiceImpl.saveOperateLog] 保存用户操作记录";
log.info("{}, model={}", logPre, model);
String url = kaSysUrl + "/external/saveOperateLog";
try {
Map<String, Object> param = JSONTools.toMap(model);
String result = null;
try {
result = httpService.get(url, param);
} catch (Exception e) {
log.error(" {} http请求异常 url={},param={}", logPre, url, param, e);
}
log.info("{} 请求ka系统返回值:{}", logPre, result);
} catch (Exception e) {
log.error("{} 网络通讯异常,model={},ex:{}", model, ExceptionUtils.getStackTrace(e));
throw new BusinessException(ErrorCodeEnum.NET_ERROR);
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment