SysLogAspectExtensionForSysUserAccountLogin.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.jtzx.crm.aspect.extension;
  2. import cc.uncarbon.framework.web.model.response.ApiResult;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.json.JSONUtil;
  5. import com.google.common.collect.Maps;
  6. import com.jtzx.crm.module.sys.annotation.SysLog;
  7. import com.jtzx.crm.module.sys.enums.SysLogStatusEnum;
  8. import com.jtzx.crm.module.sys.extension.impl.DefaultSysLogAspectExtension;
  9. import com.jtzx.crm.module.sys.model.request.AdminInsertSysLogDTO;
  10. import com.jtzx.crm.module.sys.model.request.SysUserLoginDTO;
  11. import lombok.NoArgsConstructor;
  12. import org.aspectj.lang.JoinPoint;
  13. import java.util.Map;
  14. import java.util.concurrent.atomic.AtomicInteger;
  15. /**
  16. * SysLog 切面实现类扩展 for 登录后台用户
  17. */
  18. @NoArgsConstructor
  19. public class SysLogAspectExtensionForSysUserAccountLogin extends DefaultSysLogAspectExtension {
  20. @Override
  21. public void beforeSaving(AdminInsertSysLogDTO insertSysLogDTO, JoinPoint joinPoint, SysLog annotation, Throwable e, Object ret) {
  22. String username = null;
  23. Map<String, Object> map = Maps.newHashMap();
  24. AtomicInteger code = new AtomicInteger(0);
  25. for (Object arg : joinPoint.getArgs()) {
  26. if (arg instanceof SysUserLoginDTO dto) {
  27. username = dto.getUsername();
  28. } else {
  29. code.getAndIncrement();
  30. if(code.get() == 1){
  31. username = (String) arg;
  32. }
  33. map.put("param" + code.get(), arg);
  34. }
  35. }
  36. insertSysLogDTO.setUsername(username);
  37. insertSysLogDTO.setLogType(0);
  38. if (CollUtil.isNotEmpty(map)) {
  39. insertSysLogDTO.setParams(JSONUtil.toJsonStr(map));
  40. }
  41. if (ret != null) {
  42. if (ret instanceof ApiResult apiResult) {
  43. insertSysLogDTO.setStatus(SysLogStatusEnum.SUCCESS);
  44. if (apiResult.getCode() != 200) {
  45. insertSysLogDTO.setStatus(SysLogStatusEnum.FAILED);
  46. }
  47. }
  48. }
  49. }
  50. }