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

package com.dreamworks.boditech.service;
import com.dreamworks.boditech.entity.ActionLogEntry;
import com.dreamworks.boditech.mapper.ActionLogMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
@Service
public class ActionLogService {
@Resource
private ActionLogMapper actionLogMapper;
// user id
private Integer userId = 0;
// set user id
public void setUserId( Integer userId ) {
this.userId = userId;
}
// log action start
public void log( String name, Object ... params ) {
ActionLogEntry entry = new ActionLogEntry(this.actionLogMapper);
entry.userId = this.userId;
entry.action = name;
// join params to string
List<String> paramList = new ArrayList<>();
for ( Object param : params ) {
paramList.add(param.toString());
}
entry.params = String.join(",", paramList);
entry.startedAt = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
this.actionLogMapper.insert(entry);
}
}