251216_01_ENH : 프로젝트에 FW User 배정 구현 및 테스트 완료
This commit is contained in:
@@ -3,6 +3,8 @@ package com.kri.contact.server.common.consts;
|
||||
public final class AppConstant {
|
||||
private AppConstant(){}
|
||||
|
||||
public static final String DEFAULT_COMPANY_NAME = "KRI";
|
||||
|
||||
public static final int OUTSOURCE_USER_ROLE = 4000;
|
||||
public static final int FIELDWORK_USER_ROLE = 9000;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,18 @@ public class AssignController {
|
||||
private final AssignService assignService;
|
||||
|
||||
@GetMapping("/prjct-outsource/{prjctIdx}")
|
||||
public List<String> getPrjctOutsourceAssign(@PathVariable Long prjctIdx, RequestUserContext ctx){
|
||||
public List<String> getPrjctOutsourceAssign(@PathVariable Long 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,16 +40,27 @@ public class UserController {
|
||||
|
||||
@GetMapping()
|
||||
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();
|
||||
if(ctx.getUserRole() < AppConstant.OUTSOURCE_USER_ROLE){
|
||||
searchCmpn = "";
|
||||
}
|
||||
|
||||
return userService.getUserListWithCmpn(searchCmpn);
|
||||
return userService.getFieldworkUserListWithCmpn(searchCmpn);
|
||||
}
|
||||
|
||||
@GetMapping("outsource")
|
||||
List<UserInfoDto> getOutsourceList(RequestUserContext ctx){
|
||||
List<UserInfoDto> getOutsourceList(){
|
||||
return userService.getOutsourceList();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -17,6 +17,8 @@ public interface UserRepository extends JpaRepository<TUserEntity, Long>, JpaSpe
|
||||
|
||||
List<TUserEntity> findByDelFalse();
|
||||
|
||||
List<TUserEntity> findByUserRoleGreaterThanEqualAndDelFalse(Integer userRoleCd);
|
||||
|
||||
List<TUserEntity> findByUserCmpnAndUserRoleGreaterThanEqualAndDelFalse(String userCmpn, Integer userRoleCd);
|
||||
|
||||
@Query("""
|
||||
|
||||
@@ -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
|
||||
public void upsertPrjctOutsourceAssign(Long prjctIdx, List<String> assignUserIdList, String regUser){
|
||||
projectAssignRepository.deleteAssignByPrjctIdxAndRoleRange(
|
||||
@@ -34,6 +42,21 @@ public class AssignService {
|
||||
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()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,15 +2,12 @@ package com.kri.contact.server.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.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;
|
||||
@@ -24,13 +21,27 @@ public class SystemEventLogService {
|
||||
private final SystemEventLogRepository systemEventLogRepository;
|
||||
|
||||
public void writeLoginLog(String userId, String clientIp) {
|
||||
UserIdContentDto content = new UserIdContentDto(userId);
|
||||
writeSystemLog(SystemEventType.LOGIN, "Login", null, userId, clientIp, content);
|
||||
writeSystemLog(
|
||||
SystemEventType.LOGIN,
|
||||
"Login",
|
||||
null,
|
||||
userId,
|
||||
clientIp,
|
||||
"userId",
|
||||
userId
|
||||
);
|
||||
}
|
||||
|
||||
public void writeLogoutLog(String userId, String clientIp) {
|
||||
UserIdContentDto content = new UserIdContentDto(userId);
|
||||
writeSystemLog(SystemEventType.LOGOUT, "Logout", null, userId, clientIp, content);
|
||||
writeSystemLog(
|
||||
SystemEventType.LOGOUT,
|
||||
"Logout",
|
||||
null,
|
||||
userId,
|
||||
clientIp,
|
||||
"userId",
|
||||
userId
|
||||
);
|
||||
}
|
||||
|
||||
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){
|
||||
UserIdContentDto content = new UserIdContentDto(userId);
|
||||
writeSystemLog(SystemEventType.DELETE_USER, "Delete User", null, regId, clientIp, content);
|
||||
writeSystemLog(
|
||||
SystemEventType.DELETE_USER,
|
||||
"Delete User",
|
||||
null,
|
||||
regId,
|
||||
clientIp,
|
||||
"userId",
|
||||
userId
|
||||
);
|
||||
}
|
||||
|
||||
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){
|
||||
ProjectIdxContentDto content = new ProjectIdxContentDto(prjctIdx);
|
||||
writeSystemLog(SystemEventType.DELETE_PROJECT, "Delete Project", prjctIdx, regId, clientIp, content);
|
||||
writeSystemLog(
|
||||
SystemEventType.DELETE_PROJECT,
|
||||
"Delete Project",
|
||||
prjctIdx,
|
||||
regId,
|
||||
clientIp,
|
||||
"prjctIdx",
|
||||
prjctIdx
|
||||
);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected <T> void writeSystemLog(
|
||||
public void writeAssignUserProject(String regId, String clientIp, Long prjctIdx, List<String> assignUserIdList){
|
||||
writeSystemLog(
|
||||
SystemEventType.ASSIGN_PROJECT_USER,
|
||||
"Assign Project FW User",
|
||||
prjctIdx,
|
||||
regId,
|
||||
clientIp,
|
||||
"assignUserIdList",
|
||||
assignUserIdList
|
||||
);
|
||||
}
|
||||
|
||||
protected <T> void writeSystemLog(
|
||||
SystemEventType eventType,
|
||||
String title,
|
||||
Long prjctIdx,
|
||||
@@ -74,6 +110,30 @@ public class SystemEventLogService {
|
||||
) {
|
||||
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()
|
||||
.eventTy(eventType.getCode())
|
||||
.logTitle(title)
|
||||
|
||||
@@ -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;
|
||||
if(searchCmpn == null || searchCmpn.isBlank()){
|
||||
userList = userRepository.findByDelFalse();
|
||||
userList = userRepository.findByUserRoleGreaterThanEqualAndDelFalse(AppConstant.FIELDWORK_USER_ROLE);
|
||||
}
|
||||
else{
|
||||
userList = userRepository.findByUserCmpnAndUserRoleGreaterThanEqualAndDelFalse(searchCmpn, AppConstant.FIELDWORK_USER_ROLE);
|
||||
|
||||
Reference in New Issue
Block a user