251202_01_ENH: User 관련 기능 구현
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.contact.server.dto.UserInfoDto;
|
||||
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 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);
|
||||
}
|
||||
|
||||
private <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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user