95 lines
3.9 KiB
Java
95 lines
3.9 KiB
Java
package com.kri.contact.server.service;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.kri.contact.server.dto.ProjectCreateRequestDto;
|
|
import com.kri.contact.server.dto.ProjectInfoDto;
|
|
import com.kri.contact.server.dto.UserInfoDto;
|
|
import com.kri.contact.server.dto.systemlog.ProjectIdxContentDto;
|
|
import com.kri.contact.server.dto.systemlog.UploadUserContentDto;
|
|
import com.kri.contact.server.dto.systemlog.UserIdContentDto;
|
|
import com.kri.contact.server.common.enums.SystemEventType;
|
|
import com.kri.contact.server.persistence.entity.TSysEventLogEntity;
|
|
import com.kri.contact.server.persistence.repository.SystemEventLogRepository;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import static com.kri.common.json.JsonUtil.toMap;
|
|
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class SystemEventLogService {
|
|
private final ObjectMapper objectMapper;
|
|
private final SystemEventLogRepository systemEventLogRepository;
|
|
|
|
public void writeLoginLog(String userId, String clientIp) {
|
|
UserIdContentDto content = new UserIdContentDto(userId);
|
|
writeSystemLog(SystemEventType.LOGIN, "Login", null, userId, clientIp, content);
|
|
}
|
|
|
|
public void writeLogoutLog(String userId, String clientIp) {
|
|
UserIdContentDto content = new UserIdContentDto(userId);
|
|
writeSystemLog(SystemEventType.LOGOUT, "Logout", null, userId, clientIp, content);
|
|
}
|
|
|
|
public void writeCreatUserLog(String regId, String clientIp, UserInfoDto userInfo){
|
|
writeSystemLog(SystemEventType.CREAT_USER, "Create User", null, regId, clientIp, userInfo);
|
|
}
|
|
|
|
public void writeUploadUserLog(String regId, String clientIp, UploadUserContentDto content){
|
|
writeSystemLog(SystemEventType.UPLOAD_USER, "Upload User", null, regId, clientIp, content);
|
|
}
|
|
|
|
public void writeUpdateUserLog(String regId, String clientIp, UserInfoDto userInfo){
|
|
writeSystemLog(SystemEventType.UPDATE_USER, "Update User", null, regId, clientIp, userInfo);
|
|
}
|
|
|
|
public void writeDeleteUserLog(String regId, String clientIp, String userId){
|
|
UserIdContentDto content = new UserIdContentDto(userId);
|
|
writeSystemLog(SystemEventType.DELETE_USER, "Delete User", null, regId, clientIp, content);
|
|
}
|
|
|
|
public void writeCreateProject(String regId, String clientIp, Long prjctIdx, ProjectCreateRequestDto req){
|
|
writeSystemLog(SystemEventType.CREAT_PROJECT, "Create Project", prjctIdx, regId, clientIp, req);
|
|
}
|
|
|
|
public void writeUpdateProject(String regId, String clientIp, Long prjctIdx, ProjectInfoDto req){
|
|
writeSystemLog(SystemEventType.UPDATE_PROJECT, "Update Project", prjctIdx, regId, clientIp, req);
|
|
}
|
|
|
|
public void writeDeleteProject(String regId, String clientIp, Long prjctIdx){
|
|
ProjectIdxContentDto content = new ProjectIdxContentDto(prjctIdx);
|
|
writeSystemLog(SystemEventType.DELETE_PROJECT, "Delete Project", prjctIdx, regId, clientIp, content);
|
|
}
|
|
|
|
public void writeAssignProjectOutsource(String regId, String clientIp, Long prjctIdx, List<String> assignUserIdList){
|
|
writeSystemLog(SystemEventType.ASSIGN_PROJECT_OUTSOURCE, "Assign Project Outsource User", prjctIdx, regId, clientIp, assignUserIdList);
|
|
}
|
|
|
|
@Transactional
|
|
protected <T> void writeSystemLog(
|
|
SystemEventType eventType,
|
|
String title,
|
|
Long prjctIdx,
|
|
String regId,
|
|
String clientIp,
|
|
T content
|
|
) {
|
|
Map<String, Object> contentMap = toMap(objectMapper, content);
|
|
|
|
TSysEventLogEntity log = TSysEventLogEntity.builder()
|
|
.eventTy(eventType.getCode())
|
|
.logTitle(title)
|
|
.logContent(contentMap)
|
|
.prjctIdx(prjctIdx)
|
|
.ip(clientIp)
|
|
.regUser(regId)
|
|
.build();
|
|
|
|
systemEventLogRepository.save(log);
|
|
}
|
|
}
|