Merge pull request '260805_01_ENH: 외부 설문에서 리스트 단건 조회, 리스트 헤더조회, 리스트 단건 수정 기능 사용할수 있도록 기능 생성' (#14) from develop into master
Reviewed-on: #14
This commit is contained in:
@@ -38,7 +38,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "com.kri.common:starter:beta.1.4.0"
|
implementation "com.kri.common:starter:beta.1.5.0"
|
||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Schema(description = "시스템 이벤트 타입")
|
@Schema(description = "시스템 이벤트 타입")
|
||||||
public enum SystemEventType implements CodeEnum<Short> {
|
public enum SystemEventType implements CodeEnum<Short> {
|
||||||
//1의 자리 1 insert, 2 update, 3 delete, 4 upload
|
//1의 자리 0: select, 1 insert, 2 update, 3 delete, 4 upload
|
||||||
//100의 자리 대분류, 10의 자리 소분류
|
//100의 자리 대분류, 10의 자리 소분류
|
||||||
|
|
||||||
LOGIN((short) 111), // 로그인
|
LOGIN((short) 111), // 로그인
|
||||||
@@ -18,13 +18,15 @@ public enum SystemEventType implements CodeEnum<Short> {
|
|||||||
CREATE_PROJECT((short) 211), // 프로젝트 생성
|
CREATE_PROJECT((short) 211), // 프로젝트 생성
|
||||||
UPDATE_PROJECT((short) 212), // 프로젝트 수정
|
UPDATE_PROJECT((short) 212), // 프로젝트 수정
|
||||||
DELETE_PROJECT((short) 213), // 프로젝트 삭제
|
DELETE_PROJECT((short) 213), // 프로젝트 삭제
|
||||||
|
|
||||||
ASSIGN_PROJECT((short) 222), // 프로젝트 배정
|
ASSIGN_PROJECT((short) 222), // 프로젝트 배정
|
||||||
|
|
||||||
UPDATE_PROJECT_DEFAULT_TEMPLATE((short) 232), // 기본 템플릿 수정
|
UPDATE_PROJECT_DEFAULT_TEMPLATE((short) 232), // 기본 템플릿 수정
|
||||||
|
|
||||||
CREATE_USER((short) 311), // 사용자 생성
|
CREATE_USER((short) 311), // 사용자 생성
|
||||||
UPDATE_USER((short) 312), // 사용자 수정
|
UPDATE_USER((short) 312), // 사용자 수정
|
||||||
DELETE_USER((short) 313), // 사용자 삭제
|
DELETE_USER((short) 313), // 사용자 삭제
|
||||||
UPLOAD_USER((short) 314), // 사용자 삭제
|
UPLOAD_USER((short) 314), // 사용자 UPLOAD
|
||||||
|
|
||||||
CREATE_ROLE((short) 411), // 권한 생성
|
CREATE_ROLE((short) 411), // 권한 생성
|
||||||
UPDATE_ROLE((short) 412), // 권한 수정
|
UPDATE_ROLE((short) 412), // 권한 수정
|
||||||
@@ -32,12 +34,18 @@ public enum SystemEventType implements CodeEnum<Short> {
|
|||||||
|
|
||||||
UPSERT_LIST_HEADER((short) 1012), //리스트 헤더 수정
|
UPSERT_LIST_HEADER((short) 1012), //리스트 헤더 수정
|
||||||
|
|
||||||
UPLOAD_LIST((short) 1111), //리스트 업로드
|
|
||||||
UPDATE_LIST((short) 1112), //리스트 수정
|
UPDATE_LIST((short) 1112), //리스트 수정
|
||||||
RESET_LIST((short) 1113), //리스트 삭제
|
RESET_LIST((short) 1113), //리스트 삭제
|
||||||
|
UPLOAD_LIST((short) 1114), //리스트 업로드
|
||||||
|
|
||||||
LIST_ASSIGN((short) 1122), //리스트 배정
|
LIST_ASSIGN((short) 1122), //리스트 배정
|
||||||
LIST_ASSIGN_RESET((short) 1123), //리스트 배정 초기화
|
LIST_ASSIGN_RESET((short) 1123), //리스트 배정 초기화
|
||||||
UPLOAD_LIST_ITEM_FILE((short) 1211), //리스트별 파일 업로드
|
|
||||||
|
SEARCH_LIST_HEADER_FROM_EXTERNAL((short) 1180), //외부에서 리스트 헤더 조회
|
||||||
|
SEARCH_LIST_FROM_EXTERNAL((short) 1190), //외부에서 리스트 조회
|
||||||
|
UPDATE_LIST_FROM_EXTERNAL((short) 1192), //외부에서 리스트 수정
|
||||||
|
|
||||||
|
UPLOAD_LIST_ITEM_FILE((short) 1214), //리스트별 파일 업로드
|
||||||
|
|
||||||
DUMMY((short) 9999);
|
DUMMY((short) 9999);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.kri.contact.server.config;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableTransactionManagement
|
||||||
|
public class DefaultTxConfig {
|
||||||
|
|
||||||
|
@Bean(name = "transactionManager")
|
||||||
|
@Primary
|
||||||
|
public PlatformTransactionManager transactionManager(
|
||||||
|
@Qualifier("entityManagerFactory") EntityManagerFactory emf
|
||||||
|
) {
|
||||||
|
return new JpaTransactionManager(emf);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -159,8 +159,6 @@ public class ListController {
|
|||||||
@Valid @RequestBody ListUpdateRequestDto request,
|
@Valid @RequestBody ListUpdateRequestDto request,
|
||||||
RequestUserContext ctx
|
RequestUserContext ctx
|
||||||
) {
|
) {
|
||||||
validateListUpdateRequest(request);
|
|
||||||
|
|
||||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
int updateCount = listUpdateService.updateList(prjctIdx, request, ctx.getUserRole(), ctx.getUserId(), now);
|
int updateCount = listUpdateService.updateList(prjctIdx, request, ctx.getUserRole(), ctx.getUserId(), now);
|
||||||
systemEventLogService.writeUpdateList(ctx.getUserId(), now, ctx.getClientIp(), prjctIdx, request);
|
systemEventLogService.writeUpdateList(ctx.getUserId(), now, ctx.getClientIp(), prjctIdx, request);
|
||||||
@@ -238,15 +236,6 @@ public class ListController {
|
|||||||
return projectInfoDto;
|
return projectInfoDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateListUpdateRequest(ListUpdateRequestDto request){
|
|
||||||
if(
|
|
||||||
CollectionUtil.isEmpty(request.getUpdateContents()) &&
|
|
||||||
CollectionUtil.isEmpty(request.getUpdateResultCodes())
|
|
||||||
){
|
|
||||||
throw BusinessException.badRequest("EMPTY_UPDATE_CONTENT","리스트 수정내용이 없습니다.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResponseEntity<byte[]> buildZipResponse(String fileName, byte[] bytes) {
|
private ResponseEntity<byte[]> buildZipResponse(String fileName, byte[] bytes) {
|
||||||
String contentDisposition = "attachment; filename*=UTF-8''" +
|
String contentDisposition = "attachment; filename*=UTF-8''" +
|
||||||
URLEncoder.encode(fileName, StandardCharsets.UTF_8).replace("+", "%20");
|
URLEncoder.encode(fileName, StandardCharsets.UTF_8).replace("+", "%20");
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package com.kri.contact.server.controller;
|
||||||
|
|
||||||
|
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||||
|
import com.kri.common.feature.web.RequestUserContext;
|
||||||
|
import com.kri.contact.server.dto.list.ListSearchExternalDto;
|
||||||
|
import com.kri.contact.server.dto.list.ListUpdateRequestDto;
|
||||||
|
import com.kri.contact.server.service.ListHeaderService;
|
||||||
|
import com.kri.contact.server.service.ListSearchService;
|
||||||
|
import com.kri.contact.server.service.ListUpdateService;
|
||||||
|
import com.kri.contact.server.service.common.SystemEventLogService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PatchMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/list-external")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Tag(name = "ListExternal", description = "외부 공개용 리스트 API")
|
||||||
|
public class ListExternalController {
|
||||||
|
|
||||||
|
private final ListHeaderService listHeaderService;
|
||||||
|
private final ListSearchService listSearchService;
|
||||||
|
private final ListUpdateService listUpdateService;
|
||||||
|
private final SystemEventLogService systemEventLogService;
|
||||||
|
|
||||||
|
@Operation(summary = "리스트 헤더 조회")
|
||||||
|
@GetMapping("/header/{prjctIdx}")
|
||||||
|
public List<String> searchListHeader(
|
||||||
|
@PathVariable Long prjctIdx,
|
||||||
|
RequestUserContext ctx
|
||||||
|
) {
|
||||||
|
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
List<String> headerNames = listHeaderService.getHeaderName(prjctIdx);
|
||||||
|
systemEventLogService.writeSearchListHeaderFromExternal(ctx.getUserId(), now, ctx.getClientIp(), prjctIdx);
|
||||||
|
|
||||||
|
return headerNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "리스트 정보 조회")
|
||||||
|
@GetMapping("/search/{prjctIdx}/{sid}")
|
||||||
|
public ListSearchExternalDto searchListWithSid(
|
||||||
|
@PathVariable Long prjctIdx,
|
||||||
|
@PathVariable String sid,
|
||||||
|
RequestUserContext ctx
|
||||||
|
) {
|
||||||
|
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
ListSearchExternalDto listInfo = listSearchService.searchListWithSidFromExternal(prjctIdx, sid);
|
||||||
|
systemEventLogService.writeSearchListFromExternal(ctx.getUserId(), now, ctx.getClientIp(), prjctIdx, sid);
|
||||||
|
|
||||||
|
return listInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "리스트 수정 sid기반")
|
||||||
|
@PatchMapping("/update/{prjctIdx}/{sid}")
|
||||||
|
public int updateListWithSid(
|
||||||
|
@PathVariable Long prjctIdx,
|
||||||
|
@PathVariable String sid,
|
||||||
|
@RequestBody Map<String, String> updateContents,
|
||||||
|
RequestUserContext ctx
|
||||||
|
) {
|
||||||
|
Map<Integer, String> contentsByHeaderId = listHeaderService.convertHeaderNamesToIds(
|
||||||
|
prjctIdx,
|
||||||
|
updateContents
|
||||||
|
);
|
||||||
|
ListUpdateRequestDto request = ListUpdateRequestDto.from(contentsByHeaderId, sid);
|
||||||
|
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
int updateCount = listUpdateService.updateList(prjctIdx, request, ctx.getUserRole(), ctx.getUserId(), now);
|
||||||
|
systemEventLogService.writeUpdateListFromExternal(ctx.getUserId(), now, ctx.getClientIp(), prjctIdx, updateContents);
|
||||||
|
|
||||||
|
return updateCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,7 +31,7 @@ public class ListHeaderController {
|
|||||||
@Operation(summary = "리스트 헤더 조회")
|
@Operation(summary = "리스트 헤더 조회")
|
||||||
@GetMapping("/{prjctIdx}")
|
@GetMapping("/{prjctIdx}")
|
||||||
public List<ListHeaderWithFilterContentDto> getListHeader (@PathVariable Long prjctIdx) {
|
public List<ListHeaderWithFilterContentDto> getListHeader (@PathVariable Long prjctIdx) {
|
||||||
return listHeaderService.getHeader(prjctIdx);
|
return listHeaderService.getHeaderWithFilterContent(prjctIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "리스트 헤더 수정")
|
@Operation(summary = "리스트 헤더 수정")
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.kri.contact.server.dto.list;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(description = "외부에서 리스트 조회")
|
||||||
|
public class ListSearchExternalDto {
|
||||||
|
@Schema(description = "프로젝트 고유키")
|
||||||
|
private Long prjctIdx;
|
||||||
|
|
||||||
|
@Schema(description = "SID")
|
||||||
|
private String sid;
|
||||||
|
|
||||||
|
@Schema(description = "리스트 값 정보(헤더 네임 기반)")
|
||||||
|
private Map<String, String> itemList;
|
||||||
|
}
|
||||||
@@ -5,13 +5,17 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Builder
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Schema(description = "리스트 정보 수정 요청 DTO")
|
@Schema(description = "리스트 정보 수정 요청 DTO")
|
||||||
public class ListUpdateRequestDto {
|
public class ListUpdateRequestDto {
|
||||||
|
|
||||||
@@ -25,4 +29,11 @@ public class ListUpdateRequestDto {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "리스트 필터")
|
@Schema(description = "리스트 필터")
|
||||||
private ListFilterDto listFilter;
|
private ListFilterDto listFilter;
|
||||||
|
|
||||||
|
public static ListUpdateRequestDto from(Map<Integer, String> updateContents, String sid) {
|
||||||
|
return ListUpdateRequestDto.builder()
|
||||||
|
.updateContents(updateContents)
|
||||||
|
.listFilter(ListFilterDto.onlyOneSid(sid))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import com.kri.contact.server.persistence.repository.ListHeaderRepository;
|
|||||||
import com.kri.contact.server.persistence.repository.ListItemRepository;
|
import com.kri.contact.server.persistence.repository.ListItemRepository;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@@ -53,7 +54,23 @@ public class ListHeaderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<ListHeaderWithFilterContentDto> getHeader(Long prjctIdx) {
|
public List<String> getHeaderName(Long prjctIdx) {
|
||||||
|
return listHeaderRepository.findByIdPrjctIdx(prjctIdx)
|
||||||
|
.stream()
|
||||||
|
.map(TListHeaderEntity::getListHderNm)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<ListHeaderDto> getHeader(Long prjctIdx) {
|
||||||
|
return listHeaderRepository.findByIdPrjctIdx(prjctIdx)
|
||||||
|
.stream()
|
||||||
|
.map(ListHeaderDto::fromEntity)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<ListHeaderWithFilterContentDto> getHeaderWithFilterContent(Long prjctIdx) {
|
||||||
List<TListHeaderEntity> headerEntityList = listHeaderRepository.findByIdPrjctIdx(prjctIdx);
|
List<TListHeaderEntity> headerEntityList = listHeaderRepository.findByIdPrjctIdx(prjctIdx);
|
||||||
|
|
||||||
if (headerEntityList.isEmpty()) {
|
if (headerEntityList.isEmpty()) {
|
||||||
@@ -194,6 +211,8 @@ public class ListHeaderService {
|
|||||||
.with("invalidHeaderList", invalidHeaderList);
|
.with("invalidHeaderList", invalidHeaderList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validateUniqueHeaderNames(headerList);
|
||||||
|
|
||||||
// headerList에 없는 헤더는 삭제
|
// headerList에 없는 헤더는 삭제
|
||||||
List<Integer> headerIdList = headerList.stream()
|
List<Integer> headerIdList = headerList.stream()
|
||||||
.map(ListHeaderDto::getListHderId)
|
.map(ListHeaderDto::getListHderId)
|
||||||
@@ -258,6 +277,95 @@ public class ListHeaderService {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<Integer, String> createHeaderNameByIdMap(
|
||||||
|
Collection<? extends ListHeaderDto> headers
|
||||||
|
) {
|
||||||
|
validateUniqueHeaderNames(headers);
|
||||||
|
|
||||||
|
Map<Integer, String> headerNameById = new LinkedHashMap<>();
|
||||||
|
headers.stream()
|
||||||
|
.sorted(Comparator.comparing(ListHeaderDto::getListHderOrder))
|
||||||
|
.forEach(header -> headerNameById.put(header.getListHderId(), header.getListHderNm()));
|
||||||
|
return headerNameById;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Integer> createHeaderIdByNameMap(
|
||||||
|
Collection<? extends ListHeaderDto> headers
|
||||||
|
) {
|
||||||
|
validateUniqueHeaderNames(headers);
|
||||||
|
|
||||||
|
Map<String, Integer> headerIdByName = new LinkedHashMap<>();
|
||||||
|
headers.stream()
|
||||||
|
.sorted(Comparator.comparing(ListHeaderDto::getListHderOrder))
|
||||||
|
.forEach(header -> headerIdByName.put(header.getListHderNm(), header.getListHderId()));
|
||||||
|
return headerIdByName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Integer, String> convertHeaderNamesToIds(
|
||||||
|
Long prjctIdx,
|
||||||
|
Map<String, String> contentsByHeaderName
|
||||||
|
) {
|
||||||
|
return convertHeaderNamesToIds(prjctIdx, contentsByHeaderName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Integer, String> convertHeaderNamesToIds(
|
||||||
|
Long prjctIdx,
|
||||||
|
Map<String, String> contentsByHeaderName,
|
||||||
|
boolean ignoreUnknownHeaders
|
||||||
|
) {
|
||||||
|
if (contentsByHeaderName == null || contentsByHeaderName.isEmpty()) {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Integer> headerIdByName = createHeaderIdByNameMap(getHeader(prjctIdx));
|
||||||
|
if (!ignoreUnknownHeaders) {
|
||||||
|
Set<String> missingHeaderNames = contentsByHeaderName.keySet().stream()
|
||||||
|
.filter(name -> !headerIdByName.containsKey(name))
|
||||||
|
.collect(LinkedHashSet::new, LinkedHashSet::add, LinkedHashSet::addAll);
|
||||||
|
|
||||||
|
if (!missingHeaderNames.isEmpty()) {
|
||||||
|
throw BusinessException.badRequest("HEADER_NOT_FOUND", "대상 헤더를 찾을 수 없습니다.")
|
||||||
|
.with("headerNames", missingHeaderNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, String> contentsByHeaderId = new LinkedHashMap<>();
|
||||||
|
contentsByHeaderName.forEach((name, value) -> {
|
||||||
|
Integer headerId = headerIdByName.get(name);
|
||||||
|
if (headerId != null) {
|
||||||
|
contentsByHeaderId.put(headerId, value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return contentsByHeaderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> Map<String, T> convertHeaderIdsToNames(
|
||||||
|
Collection<? extends ListHeaderDto> headers,
|
||||||
|
Map<Integer, T> contentsByHeaderId
|
||||||
|
) {
|
||||||
|
if (contentsByHeaderId == null || contentsByHeaderId.isEmpty()) {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, String> headerNameById = createHeaderNameByIdMap(headers);
|
||||||
|
Set<Integer> missingHeaderIds = contentsByHeaderId.keySet().stream()
|
||||||
|
.filter(id -> !headerNameById.containsKey(id))
|
||||||
|
.collect(LinkedHashSet::new, LinkedHashSet::add, LinkedHashSet::addAll);
|
||||||
|
|
||||||
|
if (!missingHeaderIds.isEmpty()) {
|
||||||
|
throw BusinessException.badRequest("HEADER_NOT_FOUND", "조회 대상 헤더를 찾을 수 없습니다.")
|
||||||
|
.with("headerIds", missingHeaderIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, T> contentsByHeaderName = new LinkedHashMap<>();
|
||||||
|
headerNameById.forEach((id, name) -> {
|
||||||
|
if (contentsByHeaderId.containsKey(id)) {
|
||||||
|
contentsByHeaderName.put(name, contentsByHeaderId.get(id));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return contentsByHeaderName;
|
||||||
|
}
|
||||||
|
|
||||||
private ListHeaderType resolveType(Integer headerId, Map<String, ListHeaderTypeSpecific> specificHeader) {
|
private ListHeaderType resolveType(Integer headerId, Map<String, ListHeaderTypeSpecific> specificHeader) {
|
||||||
if (specificHeader == null || specificHeader.isEmpty()) {
|
if (specificHeader == null || specificHeader.isEmpty()) {
|
||||||
return ListHeaderType.TEXT;
|
return ListHeaderType.TEXT;
|
||||||
@@ -287,4 +395,19 @@ public class ListHeaderService {
|
|||||||
}
|
}
|
||||||
return maxListHderId;
|
return maxListHderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateUniqueHeaderNames(Collection<? extends ListHeaderDto> headers) {
|
||||||
|
Set<String> uniqueHeaderNames = new LinkedHashSet<>();
|
||||||
|
Set<String> duplicateHeaderNames = new LinkedHashSet<>();
|
||||||
|
for (ListHeaderDto header : headers) {
|
||||||
|
if (!uniqueHeaderNames.add(header.getListHderNm())) {
|
||||||
|
duplicateHeaderNames.add(header.getListHderNm());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!duplicateHeaderNames.isEmpty()) {
|
||||||
|
throw BusinessException.badRequest("DUPLICATE_HEADER_NAME", "중복된 헤더명이 있습니다.")
|
||||||
|
.with("duplicateHeaderList", duplicateHeaderNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.kri.contact.server.dto.list.ListFilterDto;
|
|||||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||||
import com.kri.contact.server.dto.list.ListResultBaseDto;
|
import com.kri.contact.server.dto.list.ListResultBaseDto;
|
||||||
import com.kri.contact.server.dto.list.ListSearchBaseDto;
|
import com.kri.contact.server.dto.list.ListSearchBaseDto;
|
||||||
|
import com.kri.contact.server.dto.list.ListSearchExternalDto;
|
||||||
import com.kri.contact.server.dto.list.ListSearchRequestDto;
|
import com.kri.contact.server.dto.list.ListSearchRequestDto;
|
||||||
import com.kri.contact.server.dto.list.ListSearchWithFullResultDto;
|
import com.kri.contact.server.dto.list.ListSearchWithFullResultDto;
|
||||||
import com.kri.contact.server.dto.list.ListSearchWithResultDto;
|
import com.kri.contact.server.dto.list.ListSearchWithResultDto;
|
||||||
@@ -86,6 +87,41 @@ public class ListSearchService {
|
|||||||
return result.get(0);
|
return result.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public ListSearchExternalDto searchListWithSidFromExternal(Long prjctIdx, String sid) {
|
||||||
|
ListFilterDto filterDto = ListFilterDto.onlyOneSid(sid);
|
||||||
|
List<ListSearchBaseDto> result = createListSearchBase(
|
||||||
|
prjctIdx,
|
||||||
|
findAllListEntities(prjctIdx, filterDto)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.isEmpty()) {
|
||||||
|
throw BusinessException.notFound("LIST_NOT_FOUND", "해당하는 리스트가 없습니다.")
|
||||||
|
.with("sid", sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
ListSearchBaseDto list = result.get(0);
|
||||||
|
List<? extends ListHeaderDto> listHeaders = listHeaderService.getHeader(prjctIdx);
|
||||||
|
Map<Integer, String> itemListByHeaderId = listHeaders.stream()
|
||||||
|
.filter(header -> header.getListHderTy() != ListHeaderType.SID)
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
ListHeaderDto::getListHderId,
|
||||||
|
header -> resolveExternalHeaderValue(list, header),
|
||||||
|
(left, right) -> right,
|
||||||
|
LinkedHashMap::new
|
||||||
|
));
|
||||||
|
Map<String, String> itemList = listHeaderService.convertHeaderIdsToNames(
|
||||||
|
listHeaders,
|
||||||
|
itemListByHeaderId
|
||||||
|
);
|
||||||
|
|
||||||
|
return ListSearchExternalDto.builder()
|
||||||
|
.prjctIdx(list.getPrjctIdx())
|
||||||
|
.sid(list.getSid())
|
||||||
|
.itemList(itemList)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public <T extends ListSearchBaseDto> PageResponseDto<T> searchListWithPaging(
|
public <T extends ListSearchBaseDto> PageResponseDto<T> searchListWithPaging(
|
||||||
Long prjctIdx,
|
Long prjctIdx,
|
||||||
@@ -658,6 +694,38 @@ public class ListSearchService {
|
|||||||
return defaultString(value);
|
return defaultString(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String resolveExternalHeaderValue(ListSearchBaseDto list, ListHeaderDto header) {
|
||||||
|
return switch (header.getListHderTy()) {
|
||||||
|
case SID -> defaultString(list.getSid());
|
||||||
|
case IS_USE -> toExternalUseValue(list.getUse());
|
||||||
|
case OUTSOURCE -> resolveAssignValue(list, ListHeaderTypeAssign.OUTSOURCE);
|
||||||
|
case CONTACT_INTERVIEWER -> resolveAssignValue(list, ListHeaderTypeAssign.CONTACT_INTERVIEWER);
|
||||||
|
case FIELD_INTERVIEWER -> resolveAssignValue(list, ListHeaderTypeAssign.FIELD_INTERVIEWER);
|
||||||
|
case MEMO -> defaultString(list.getMemo());
|
||||||
|
default -> list.getItemList() == null
|
||||||
|
? ""
|
||||||
|
: defaultString(list.getItemList().get(header.getListHderId()));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveAssignValue(ListSearchBaseDto list, ListHeaderTypeAssign assignType) {
|
||||||
|
if (list.getAssignList() == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return defaultString(list.getAssignList().get(assignType));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String toExternalUseValue(ListIsUse use) {
|
||||||
|
if (use == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return switch (use) {
|
||||||
|
case UNUSABLE -> "X";
|
||||||
|
case USABLE -> "O";
|
||||||
|
case TEST -> "TEST";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private String toUseValue(String value) {
|
private String toUseValue(String value) {
|
||||||
String trimmedValue = defaultString(value).trim();
|
String trimmedValue = defaultString(value).trim();
|
||||||
if (Objects.equals(trimmedValue, String.valueOf(ListIsUse.USABLE.getCode()))) {
|
if (Objects.equals(trimmedValue, String.valueOf(ListIsUse.USABLE.getCode()))) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import static com.kri.common.feature.util.StringUtil.normalizeBlank;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.kri.common.feature.util.CollectionUtil;
|
||||||
import com.kri.common.feature.web.BusinessException;
|
import com.kri.common.feature.web.BusinessException;
|
||||||
import com.kri.contact.server.common.consts.ContactConstant;
|
import com.kri.contact.server.common.consts.ContactConstant;
|
||||||
import com.kri.contact.server.common.enums.ListHeaderGrade;
|
import com.kri.contact.server.common.enums.ListHeaderGrade;
|
||||||
@@ -77,6 +78,8 @@ public class ListUpdateService {
|
|||||||
String regUser,
|
String regUser,
|
||||||
LocalDateTime regDt
|
LocalDateTime regDt
|
||||||
) {
|
) {
|
||||||
|
validateListUpdateRequest(request);
|
||||||
|
|
||||||
Map<Integer, String> updateContents = request.getUpdateContents();
|
Map<Integer, String> updateContents = request.getUpdateContents();
|
||||||
Map<ResultCodeType, Integer> updateResultCodes = request.getUpdateResultCodes();
|
Map<ResultCodeType, Integer> updateResultCodes = request.getUpdateResultCodes();
|
||||||
if (isEmpty(updateContents) && isEmpty(updateResultCodes)) {
|
if (isEmpty(updateContents) && isEmpty(updateResultCodes)) {
|
||||||
@@ -154,6 +157,15 @@ public class ListUpdateService {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateListUpdateRequest(ListUpdateRequestDto request){
|
||||||
|
if(
|
||||||
|
CollectionUtil.isEmpty(request.getUpdateContents()) &&
|
||||||
|
CollectionUtil.isEmpty(request.getUpdateResultCodes())
|
||||||
|
){
|
||||||
|
throw BusinessException.badRequest("EMPTY_UPDATE_CONTENT","리스트 수정내용이 없습니다.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void validateResultCodes(Long prjctIdx, Map<ResultCodeType, Integer> resultCodes) {
|
private void validateResultCodes(Long prjctIdx, Map<ResultCodeType, Integer> resultCodes) {
|
||||||
if (isEmpty(resultCodes)) {
|
if (isEmpty(resultCodes)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -205,6 +205,24 @@ public class SystemEventLogService {
|
|||||||
"Assign List Reset", prjctIdx, regId, regDt, clientIp, req);
|
"Assign List Reset", prjctIdx, regId, regDt, clientIp, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeSearchListHeaderFromExternal(String regId, LocalDateTime regDt, String clientIp,
|
||||||
|
Long prjctIdx){
|
||||||
|
writeSystemLog(SystemEventType.SEARCH_LIST_HEADER_FROM_EXTERNAL,
|
||||||
|
"Search List Header From External", prjctIdx, regId, regDt, clientIp, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeSearchListFromExternal(String regId, LocalDateTime regDt, String clientIp,
|
||||||
|
Long prjctIdx, String sid){
|
||||||
|
writeSystemLog(SystemEventType.SEARCH_LIST_FROM_EXTERNAL,
|
||||||
|
"Search List From External", prjctIdx, regId, regDt, clientIp, "SID", sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeUpdateListFromExternal(String regId, LocalDateTime regDt, String clientIp,
|
||||||
|
Long prjctIdx, Map<String, String> updateContents){
|
||||||
|
writeSystemLog(SystemEventType.UPDATE_LIST_FROM_EXTERNAL,
|
||||||
|
"Update List Info From External", prjctIdx, regId, regDt, clientIp, updateContents);
|
||||||
|
}
|
||||||
|
|
||||||
protected <T> void writeSystemLog(
|
protected <T> void writeSystemLog(
|
||||||
SystemEventType eventType,
|
SystemEventType eventType,
|
||||||
String title,
|
String title,
|
||||||
|
|||||||
@@ -26,12 +26,26 @@ logging:
|
|||||||
file:
|
file:
|
||||||
path: ./logs
|
path: ./logs
|
||||||
|
|
||||||
kri:
|
springdoc:
|
||||||
|
writer-with-order-by-keys: true
|
||||||
|
swagger-ui:
|
||||||
|
tags-sorter: alpha
|
||||||
|
operations-sorter: method
|
||||||
|
|
||||||
|
kri:
|
||||||
auth:
|
auth:
|
||||||
apikey:
|
apikey:
|
||||||
key: "4B726963-436F6E74616374-53657276696365-402531213230"
|
key: "4B726963-436F6E74616374-53657276696365-402531213230"
|
||||||
header-name: "X-API-Key" # API Key 헤더
|
header-name: "X-API-Key" # API Key 헤더
|
||||||
|
enabled: true # API Key 인증 허용 여부
|
||||||
|
service-code: kric-contact-service
|
||||||
|
allowed-paths:
|
||||||
|
- /api/v1/list-external/**
|
||||||
|
preload-on-startup: true
|
||||||
|
# 내부 운영용(원하면)
|
||||||
|
admin-api-enabled: true
|
||||||
|
admin-allow-ips:
|
||||||
|
- 211.254.145.130
|
||||||
|
|
||||||
security:
|
security:
|
||||||
enabled: true
|
enabled: true
|
||||||
@@ -40,6 +54,7 @@ kri:
|
|||||||
- /swagger-ui.html
|
- /swagger-ui.html
|
||||||
- /swagger-ui/**
|
- /swagger-ui/**
|
||||||
- /ping
|
- /ping
|
||||||
|
- /internal/apikey/**
|
||||||
- /api/v1/auth/login
|
- /api/v1/auth/login
|
||||||
- /api/v1/list-hist/survey/**
|
- /api/v1/list-hist/survey/**
|
||||||
- /contact-senario/**
|
- /contact-senario/**
|
||||||
|
|||||||
Reference in New Issue
Block a user