251216_01_ENH : 프로젝트에 FW User 배정 구현 및 테스트 완료

This commit is contained in:
2025-12-16 16:56:03 +09:00
parent ae39b329a2
commit 62ce3e3f9e
11 changed files with 139 additions and 43 deletions

View File

@@ -9,6 +9,11 @@ spring:
# 아무 설정 없을 때 기본으로 쓸 프로파일 # 아무 설정 없을 때 기본으로 쓸 프로파일
default: local default: local
servlet:
multipart:
max-file-size: 20MB
max-request-size: 20MB
logging: logging:
file: file:
path: ./logs path: ./logs

View File

@@ -1 +1 @@
rootProject.name = 'server' rootProject.name = 'contact-server'

View File

@@ -3,6 +3,8 @@ package com.kri.contact.server.common.consts;
public final class AppConstant { public final class AppConstant {
private AppConstant(){} private AppConstant(){}
public static final String DEFAULT_COMPANY_NAME = "KRI";
public static final int OUTSOURCE_USER_ROLE = 4000; public static final int OUTSOURCE_USER_ROLE = 4000;
public static final int FIELDWORK_USER_ROLE = 9000; public static final int FIELDWORK_USER_ROLE = 9000;
} }

View File

@@ -21,7 +21,18 @@ public class AssignController {
private final AssignService assignService; private final AssignService assignService;
@GetMapping("/prjct-outsource/{prjctIdx}") @GetMapping("/prjct-outsource/{prjctIdx}")
public List<String> getPrjctOutsourceAssign(@PathVariable Long prjctIdx, RequestUserContext ctx){ public List<String> getPrjctOutsourceAssign(@PathVariable Long prjctIdx){
return assignService.getPrjctOutsourceAssign(prjctIdx); return assignService.getPrjctOutsourceAssign(prjctIdx);
} }
@GetMapping("/prjct-fieldwork/{prjctIdx}")
public List<String> getPrjctFieldworkAssign(@PathVariable Long prjctIdx){
return assignService.getPrjctFieldworkAssign(prjctIdx);
}
@PutMapping("/prjct-fieldwork/{prjctIdx}")
public void upsertPrjctFieldworkAssign(@PathVariable Long prjctIdx, @RequestBody List<String> assignUserIdList, RequestUserContext ctx){
assignService.upsertPrjctFieldworkAssign(prjctIdx, assignUserIdList, ctx.getUserId());
systemEventLogService.writeAssignUserProject(ctx.getUserId(), ctx.getClientIp(), prjctIdx, assignUserIdList);
}
} }

View File

@@ -40,16 +40,27 @@ public class UserController {
@GetMapping() @GetMapping()
public List<UserInfoDto> getUserList(RequestUserContext ctx){ public List<UserInfoDto> getUserList(RequestUserContext ctx){
String searchCmpn = ctx.getUserCmpn();
if(ctx.getUserRole() < AppConstant.OUTSOURCE_USER_ROLE){
return userService.getUserList();
}
else{
return userService.getFieldworkUserListWithCmpn(searchCmpn);
}
}
@GetMapping("fieldwork")
public List<UserInfoDto> getFiledoworkUserList(RequestUserContext ctx){
String searchCmpn = ctx.getUserCmpn(); String searchCmpn = ctx.getUserCmpn();
if(ctx.getUserRole() < AppConstant.OUTSOURCE_USER_ROLE){ if(ctx.getUserRole() < AppConstant.OUTSOURCE_USER_ROLE){
searchCmpn = ""; searchCmpn = "";
} }
return userService.getUserListWithCmpn(searchCmpn); return userService.getFieldworkUserListWithCmpn(searchCmpn);
} }
@GetMapping("outsource") @GetMapping("outsource")
List<UserInfoDto> getOutsourceList(RequestUserContext ctx){ List<UserInfoDto> getOutsourceList(){
return userService.getOutsourceList(); return userService.getOutsourceList();
} }

View File

@@ -1,12 +0,0 @@
package com.kri.contact.server.dto.systemlog;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@AllArgsConstructor
public class ProjectIdxContentDto {
public Long prjctIdx;
}

View File

@@ -1,12 +0,0 @@
package com.kri.contact.server.dto.systemlog;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@AllArgsConstructor
public class UserIdContentDto {
private String userId;
}

View File

@@ -17,6 +17,8 @@ public interface UserRepository extends JpaRepository<TUserEntity, Long>, JpaSpe
List<TUserEntity> findByDelFalse(); List<TUserEntity> findByDelFalse();
List<TUserEntity> findByUserRoleGreaterThanEqualAndDelFalse(Integer userRoleCd);
List<TUserEntity> findByUserCmpnAndUserRoleGreaterThanEqualAndDelFalse(String userCmpn, Integer userRoleCd); List<TUserEntity> findByUserCmpnAndUserRoleGreaterThanEqualAndDelFalse(String userCmpn, Integer userRoleCd);
@Query(""" @Query("""

View File

@@ -26,6 +26,14 @@ public class AssignService {
); );
} }
public List<String> getPrjctFieldworkAssign(Long prjctIdx){
return projectAssignRepository.findAssignUserIdByPrjctIdxAndRoleRange(
prjctIdx,
AppConstant.FIELDWORK_USER_ROLE,
AppConstant.FIELDWORK_USER_ROLE + 1000
);
}
@Transactional @Transactional
public void upsertPrjctOutsourceAssign(Long prjctIdx, List<String> assignUserIdList, String regUser){ public void upsertPrjctOutsourceAssign(Long prjctIdx, List<String> assignUserIdList, String regUser){
projectAssignRepository.deleteAssignByPrjctIdxAndRoleRange( projectAssignRepository.deleteAssignByPrjctIdxAndRoleRange(
@@ -34,6 +42,21 @@ public class AssignService {
AppConstant.OUTSOURCE_USER_ROLE + 1000 AppConstant.OUTSOURCE_USER_ROLE + 1000
); );
insertPrjctAssign(prjctIdx, assignUserIdList, regUser);
}
@Transactional
public void upsertPrjctFieldworkAssign(Long prjctIdx, List<String> assignUserIdList, String regUser){
projectAssignRepository.deleteAssignByPrjctIdxAndRoleRange(
prjctIdx,
AppConstant.FIELDWORK_USER_ROLE,
AppConstant.FIELDWORK_USER_ROLE + 1000
);
insertPrjctAssign(prjctIdx, assignUserIdList, regUser);
}
private void insertPrjctAssign(Long prjctIdx, List<String> assignUserIdList, String regUser){
if (assignUserIdList == null || assignUserIdList.isEmpty()) { if (assignUserIdList == null || assignUserIdList.isEmpty()) {
return; return;
} }

View File

@@ -2,15 +2,12 @@ package com.kri.contact.server.service;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.kri.contact.server.dto.*; import com.kri.contact.server.dto.*;
import com.kri.contact.server.dto.systemlog.ProjectIdxContentDto;
import com.kri.contact.server.dto.systemlog.UploadUserContentDto; 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.common.enums.SystemEventType;
import com.kri.contact.server.persistence.entity.TSysEventLogEntity; import com.kri.contact.server.persistence.entity.TSysEventLogEntity;
import com.kri.contact.server.persistence.repository.SystemEventLogRepository; import com.kri.contact.server.persistence.repository.SystemEventLogRepository;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -24,13 +21,27 @@ public class SystemEventLogService {
private final SystemEventLogRepository systemEventLogRepository; private final SystemEventLogRepository systemEventLogRepository;
public void writeLoginLog(String userId, String clientIp) { public void writeLoginLog(String userId, String clientIp) {
UserIdContentDto content = new UserIdContentDto(userId); writeSystemLog(
writeSystemLog(SystemEventType.LOGIN, "Login", null, userId, clientIp, content); SystemEventType.LOGIN,
"Login",
null,
userId,
clientIp,
"userId",
userId
);
} }
public void writeLogoutLog(String userId, String clientIp) { public void writeLogoutLog(String userId, String clientIp) {
UserIdContentDto content = new UserIdContentDto(userId); writeSystemLog(
writeSystemLog(SystemEventType.LOGOUT, "Logout", null, userId, clientIp, content); SystemEventType.LOGOUT,
"Logout",
null,
userId,
clientIp,
"userId",
userId
);
} }
public void writeCreatUserLog(String regId, String clientIp, UserInfoDto userInfo){ public void writeCreatUserLog(String regId, String clientIp, UserInfoDto userInfo){
@@ -46,8 +57,15 @@ public class SystemEventLogService {
} }
public void writeDeleteUserLog(String regId, String clientIp, String userId){ public void writeDeleteUserLog(String regId, String clientIp, String userId){
UserIdContentDto content = new UserIdContentDto(userId); writeSystemLog(
writeSystemLog(SystemEventType.DELETE_USER, "Delete User", null, regId, clientIp, content); SystemEventType.DELETE_USER,
"Delete User",
null,
regId,
clientIp,
"userId",
userId
);
} }
public void writeCreateProject(String regId, String clientIp, Long prjctIdx, ProjectCreateRequestDto req){ public void writeCreateProject(String regId, String clientIp, Long prjctIdx, ProjectCreateRequestDto req){
@@ -59,12 +77,30 @@ public class SystemEventLogService {
} }
public void writeDeleteProject(String regId, String clientIp, Long prjctIdx){ public void writeDeleteProject(String regId, String clientIp, Long prjctIdx){
ProjectIdxContentDto content = new ProjectIdxContentDto(prjctIdx); writeSystemLog(
writeSystemLog(SystemEventType.DELETE_PROJECT, "Delete Project", prjctIdx, regId, clientIp, content); SystemEventType.DELETE_PROJECT,
"Delete Project",
prjctIdx,
regId,
clientIp,
"prjctIdx",
prjctIdx
);
} }
@Transactional public void writeAssignUserProject(String regId, String clientIp, Long prjctIdx, List<String> assignUserIdList){
protected <T> void writeSystemLog( writeSystemLog(
SystemEventType.ASSIGN_PROJECT_USER,
"Assign Project FW User",
prjctIdx,
regId,
clientIp,
"assignUserIdList",
assignUserIdList
);
}
protected <T> void writeSystemLog(
SystemEventType eventType, SystemEventType eventType,
String title, String title,
Long prjctIdx, Long prjctIdx,
@@ -74,6 +110,30 @@ public class SystemEventLogService {
) { ) {
Map<String, Object> contentMap = toMap(objectMapper, content); Map<String, Object> contentMap = toMap(objectMapper, content);
saveLog(eventType, title, prjctIdx, regId, clientIp, contentMap);
}
protected <T> void writeSystemLog(
SystemEventType eventType,
String title,
Long prjctIdx,
String regId,
String clientIp,
String contentKey,
T content
) {
Map<String, Object> contentMap = Map.of(contentKey, content);
saveLog(eventType, title, prjctIdx, regId, clientIp, contentMap);
}
private void saveLog(
SystemEventType eventType,
String title,
Long prjctIdx,
String regId,
String clientIp,
Map<String, Object> contentMap
){
TSysEventLogEntity log = TSysEventLogEntity.builder() TSysEventLogEntity log = TSysEventLogEntity.builder()
.eventTy(eventType.getCode()) .eventTy(eventType.getCode())
.logTitle(title) .logTitle(title)

View File

@@ -155,10 +155,16 @@ public class UserService {
); );
} }
public List<UserInfoDto> getUserListWithCmpn(String searchCmpn){ public List<UserInfoDto> getUserList(){
return userRepository.findByDelFalse().stream()
.map(UserInfoDto::from)
.toList();
}
public List<UserInfoDto> getFieldworkUserListWithCmpn(String searchCmpn){
List<TUserEntity> userList; List<TUserEntity> userList;
if(searchCmpn == null || searchCmpn.isBlank()){ if(searchCmpn == null || searchCmpn.isBlank()){
userList = userRepository.findByDelFalse(); userList = userRepository.findByUserRoleGreaterThanEqualAndDelFalse(AppConstant.FIELDWORK_USER_ROLE);
} }
else{ else{
userList = userRepository.findByUserCmpnAndUserRoleGreaterThanEqualAndDelFalse(searchCmpn, AppConstant.FIELDWORK_USER_ROLE); userList = userRepository.findByUserCmpnAndUserRoleGreaterThanEqualAndDelFalse(searchCmpn, AppConstant.FIELDWORK_USER_ROLE);