You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

  1. package com.dreamworks.boditech.service;
  2. import com.dreamworks.boditech.entity.ActionLogEntry;
  3. import com.dreamworks.boditech.mapper.ActionLogMapper;
  4. import jakarta.annotation.Resource;
  5. import org.springframework.stereotype.Service;
  6. import java.time.LocalDateTime;
  7. import java.time.format.DateTimeFormatter;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. @Service
  11. public class ActionLogService {
  12. @Resource
  13. private ActionLogMapper actionLogMapper;
  14. // user id
  15. private Integer userId = 0;
  16. // set user id
  17. public void setUserId( Integer userId ) {
  18. this.userId = userId;
  19. }
  20. // log action start
  21. public void log( String name, Object ... params ) {
  22. ActionLogEntry entry = new ActionLogEntry(this.actionLogMapper);
  23. entry.userId = this.userId;
  24. entry.action = name;
  25. // join params to string
  26. List<String> paramList = new ArrayList<>();
  27. for ( Object param : params ) {
  28. paramList.add(param.toString());
  29. }
  30. entry.params = String.join(",", paramList);
  31. entry.startedAt = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
  32. this.actionLogMapper.insert(entry);
  33. }
  34. }