| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package com.jtzx.crm.aspect.extension;
- import cc.uncarbon.framework.web.model.response.ApiResult;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.json.JSONUtil;
- import com.google.common.collect.Maps;
- import com.jtzx.crm.module.sys.annotation.SysLog;
- import com.jtzx.crm.module.sys.enums.SysLogStatusEnum;
- import com.jtzx.crm.module.sys.extension.impl.DefaultSysLogAspectExtension;
- import com.jtzx.crm.module.sys.model.request.AdminInsertSysLogDTO;
- import com.jtzx.crm.module.sys.model.request.SysUserLoginDTO;
- import lombok.NoArgsConstructor;
- import org.aspectj.lang.JoinPoint;
- import java.util.Map;
- import java.util.concurrent.atomic.AtomicInteger;
- /**
- * SysLog 切面实现类扩展 for 登录后台用户
- */
- @NoArgsConstructor
- public class SysLogAspectExtensionForSysUserAccountLogin extends DefaultSysLogAspectExtension {
- @Override
- public void beforeSaving(AdminInsertSysLogDTO insertSysLogDTO, JoinPoint joinPoint, SysLog annotation, Throwable e, Object ret) {
- String username = null;
- Map<String, Object> map = Maps.newHashMap();
- AtomicInteger code = new AtomicInteger(0);
- for (Object arg : joinPoint.getArgs()) {
- if (arg instanceof SysUserLoginDTO dto) {
- username = dto.getUsername();
- } else {
- code.getAndIncrement();
- if(code.get() == 1){
- username = (String) arg;
- }
- map.put("param" + code.get(), arg);
- }
- }
- insertSysLogDTO.setUsername(username);
- insertSysLogDTO.setLogType(0);
- if (CollUtil.isNotEmpty(map)) {
- insertSysLogDTO.setParams(JSONUtil.toJsonStr(map));
- }
- if (ret != null) {
- if (ret instanceof ApiResult apiResult) {
- insertSysLogDTO.setStatus(SysLogStatusEnum.SUCCESS);
- if (apiResult.getCode() != 200) {
- insertSysLogDTO.setStatus(SysLogStatusEnum.FAILED);
- }
- }
- }
- }
- }
|