In the recent project, logs need to be stored in ES. Therefore, I re-started a service and packaged it into a toolkit for reference by other business systems.

/ * *

  • Created by LIUXIANGQIAN202 on 2020-7-29.
  • Event occurrence time, event type, client IP, client machine name, current user id, affected individuals (data, resources),
  • A success or failure identification, the identification of the process that started the event, and a detailed description of the event.
  • When SpringBoot starts, it automatically creates a mapping. If the same index already exists, you must delete it first

* /

@Data @Document(indexName = “user”) public class UserBehaviorDTO implements Serializable{ @Id private String Id;

@Field(type = FieldType.Long)
private Long userId;

@Field(type = FieldType.String)
private String eventType;

@Field(type = FieldType.String)
private String eventProcessId;

@Field(type = FieldType.String)
private String eventTime;

@Field(type = FieldType.String)
private String eventDesc;

@Field(type = FieldType.String)
private String content;
Copy the code

}

@Aspect @Service public class UserBehaviorLogAspect extends BaseController {

@Autowired private UserBehaviorService userBehaviorService; /** * @around, You can also use @before (pre-notification) @after (post-notification) * * @param point * @return * @throws Throwable */ @Around("@annotation(userBehaviorLog)") public Object around(ProceedingJoinPoint point, UserBehaviorLog userBehaviorLog) throws Throwable { HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.getRequestAttributes())).getRequest(); UserContext userContext = this.getCurrentUserContext(); UserBehaviorDTO userBehaviorDTO = new UserBehaviorDTO(); userBehaviorDTO.setUserId(userContext.getUserId()); userBehaviorDTO.setEventType(userBehaviorLog.eventValue().toString()); Date date = new Date(); SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); userBehaviorDTO.setEventTime(formatter.format(date)); userBehaviorDTO.setEventDesc(userBehaviorLog.eventDesc()); //Arrays.stream(params).collect(Collectors.toList()); //JsonUtil.toJson(Arrays.stream(params).collect(Collectors.toList())); //userBehaviorLog.appId(); userBehaviorLog.value(); //user.setConent( JsonUtil.toJson(Arrays.stream(params).collect(Collectors.toList()))); long beginTime = System.currentTimeMillis(); try { Object result = point.proceed(); return request; } catch (Throwable e) { throw e; } finally { userBehaviorService.saveUserBehavior(userBehaviorDTO); System.out.print("aaaaaaaaa"); }}Copy the code

Problem-solving thinking

  • When you encounter problems, try to solve their own first, Baidu can solve 80% of the problems
  • When you first get an assignment, do a quick search of the technical blogs you’re using
  • When we are solving problems, we will learn the underlying technology and understand its principle
  • Learn from excellent colleagues and learn how they behave when they encounter problems
  • How do you usually work and study

Reference:

  • Blog.csdn.net/u011066470/…

Blog.csdn.net/u011066470/…

  • Blog.csdn.net/qq_28364999… @Documnet and @Field annotations for Spring Data ElasticSearch
  • www.cnblogs.com/zs-notes/p/…
  • Blog.csdn.net/weixin_3942… Spring Boot1. x management.security.enables =false
  • Blog.csdn.net/besto229/ar… Springboot – Actuator Monitoring &401 Authorization