260915_01_ENH: 리스트 다운로드 최신 결과 및 컨택 이력 엑셀 개선

This commit is contained in:
2026-09-15 12:31:31 +09:00
parent 11c80579e5
commit 17f69cf0fe
7 changed files with 497 additions and 15 deletions

View File

@@ -0,0 +1,9 @@
package com.kri.contact.server.common.enums;
import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "컨택 이력 다운로드 정렬 순서")
public enum ListEventHistoryOrder {
ASC,
DESC
}

View File

@@ -118,10 +118,15 @@ public class ListController {
@PostMapping("/excel/download/{prjctIdx}")
public ResponseEntity<byte[]> downloadList(
@PathVariable Long prjctIdx,
@RequestParam(defaultValue = "true") boolean includeResult,
@Valid @RequestBody(required = false) ListFilterDto listFilter
) {
ProjectInfoDto projectInfoDto = getProjectOrThrow(prjctIdx);
byte[] bytes = listDownloadService.downloadList(prjctIdx, listFilter);
byte[] bytes = listDownloadService.downloadList(
prjctIdx,
listFilter,
includeResult
);
return buildExcelResponse(projectInfoDto.getPrjctName() + " list.xlsx", bytes);
}

View File

@@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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
@@ -65,6 +66,7 @@ public class ListHistoryController {
@PostMapping("/excel/download/event/{prjctIdx}")
public ResponseEntity<byte[]> downloadListWithEventHistory(
@PathVariable Long prjctIdx,
@RequestParam(defaultValue = "true") boolean includeResult,
@Valid @RequestBody ListEventHistDownloadRequestDto request
) {
ProjectInfoDto projectInfoDto = getProjectOrThrow(prjctIdx);
@@ -73,7 +75,9 @@ public class ListHistoryController {
request.getListFilter(),
request.getResultCodeTypes(),
request.getSearchBase(),
request.getDateRange()
request.getDateRange(),
request.getHistoryOrder(),
includeResult
);
return buildExcelResponse(projectInfoDto.getPrjctName() + " 컨택 이력.xlsx", bytes);
}

View File

@@ -1,6 +1,7 @@
package com.kri.contact.server.dto.list;
import com.kri.contact.server.common.enums.ListEventHistoryBase;
import com.kri.contact.server.common.enums.ListEventHistoryOrder;
import com.kri.contact.server.common.enums.ResultCodeType;
import com.kri.contact.server.dto.common.DateRangeDto;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -31,7 +32,14 @@ public class ListEventHistDownloadRequestDto {
@Schema(description = "조회 기준")
private ListEventHistoryBase searchBase;
@Schema(description = "이력 정렬 순서. ASC=오래된 이력 우선, DESC=최근 이력 우선", defaultValue = "ASC")
private ListEventHistoryOrder historyOrder = ListEventHistoryOrder.ASC;
@Valid
@Schema(description = "조회 기간")
private DateRangeDto dateRange;
public ListEventHistoryOrder getHistoryOrder() {
return historyOrder == null ? ListEventHistoryOrder.ASC : historyOrder;
}
}

View File

@@ -6,6 +6,7 @@ import com.kri.common.feature.datetime.DateTimeUtil;
import com.kri.common.feature.excel.ExcelMapper;
import com.kri.common.feature.web.BusinessException;
import com.kri.contact.server.common.enums.ListEventHistoryBase;
import com.kri.contact.server.common.enums.ListEventHistoryOrder;
import com.kri.contact.server.common.enums.ListHeaderType;
import com.kri.contact.server.common.enums.ListIsUse;
import com.kri.contact.server.common.enums.ResultCodeType;
@@ -15,9 +16,11 @@ import com.kri.contact.server.dto.list.ListHeaderDto;
import com.kri.contact.server.dto.list.ListUploadFileInfoDto;
import com.kri.contact.server.persistence.entity.TListItemFileEntity;
import com.kri.contact.server.persistence.entity.id.TListItemFileEntityId;
import com.kri.contact.server.persistence.entity.TPrjctEntity;
import com.kri.contact.server.persistence.entity.TPrjctSurveyEntity;
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
import com.kri.contact.server.persistence.repository.ListItemFileRepository;
import com.kri.contact.server.persistence.repository.ProjectRepository;
import com.kri.contact.server.persistence.repository.ProjectSurveyRepository;
import com.kri.contact.server.persistence.repository.ResultCodeRepository;
import com.kri.contact.server.service.file.ListItemFileService;
@@ -25,8 +28,10 @@ import java.io.ByteArrayOutputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -35,6 +40,14 @@ import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.stereotype.Service;
@Service
@@ -47,8 +60,13 @@ public class ListDownloadService {
private static final String HEADER_USER = "사용자";
private static final String HEADER_RESULT = "결과";
private static final String HEADER_MEMO = "메모";
private static final String HEADER_CONTACT_RESULT = "컨택 결과";
private static final String HEADER_INTERVIEW_RESULT = "현장면접 결과";
private static final String HEADER_SURVEY_RESULT_PREFIX = "설문 결과 - ";
private static final String HEADER_BEFORE = "변경전";
private static final String HEADER_AFTER = "변경후";
private static final String EXCEL_SHEET_NAME = "Sheet1";
private static final int EVENT_HISTORY_HEADER_ROW_INDEX = 2;
private static final String ZERO_WIDTH_SPACE = String.valueOf(Character.toChars(0x200B));
private static final List<String> EVENT_HISTORY_HEADERS = List.of(
@@ -59,6 +77,17 @@ public class ListDownloadService {
HEADER_RESULT,
HEADER_MEMO
);
private static final List<String> LATEST_CONTACT_HISTORY_HEADERS = List.of(
HEADER_DATE,
HEADER_USER,
HEADER_RESULT,
HEADER_MEMO
);
private static final List<String> LATEST_SURVEY_HISTORY_HEADERS = List.of(
HEADER_DATE,
HEADER_RESULT,
HEADER_MEMO
);
private static final List<String> UPDATE_HISTORY_HEADERS = List.of(
HEADER_DATE,
HEADER_USER,
@@ -71,14 +100,30 @@ public class ListDownloadService {
private final ListItemFileRepository listItemFileRepository;
private final ListItemFileService listItemFileService;
private final ResultCodeRepository resultCodeRepository;
private final ProjectRepository projectRepository;
private final ProjectSurveyRepository projectSurveyRepository;
private final ObjectMapper objectMapper;
public byte[] downloadList(Long prjctIdx, ListFilterDto listFilter) {
public byte[] downloadList(
Long prjctIdx,
ListFilterDto listFilter,
boolean includeResult
) {
List<ListHeaderDto> headers = getSortedHeaders(prjctIdx);
List<String> baseHeaderNames = toBaseHeaderNames(headers);
List<LatestResultColumn> latestResultColumns = includeResult
? createLatestResultColumns(prjctIdx, baseHeaderNames)
: List.of();
Map<EventResultKey, String> resultLabelMap = includeResult
? createResultLabelMap(prjctIdx)
: Map.of();
List<String> excelHeaders = new ArrayList<>(baseHeaderNames);
latestResultColumns.stream()
.map(LatestResultColumn::headerName)
.forEach(excelHeaders::add);
try (
ExcelMapper.StreamingMapWriter writer = ExcelMapper.openStreamingMapWriter(toBaseHeaderNames(headers), 100);
ExcelMapper.StreamingMapWriter writer = ExcelMapper.openStreamingMapWriter(excelHeaders, 100);
ByteArrayOutputStream out = new ByteArrayOutputStream()
) {
String lastSid = null;
@@ -88,8 +133,18 @@ public class ListDownloadService {
break;
}
Map<String, List<ListSearchService.LatestResultRow>> latestResultMap = includeResult
? findLatestResultMap(prjctIdx, rows)
: Map.of();
for (ListSearchService.DownloadListRow row : rows) {
writer.append(createBaseRow(headers, row));
writer.append(createListRow(
headers,
row,
latestResultColumns,
latestResultMap.getOrDefault(row.sid(), List.of()),
resultLabelMap
));
lastSid = row.sid();
}
}
@@ -108,7 +163,9 @@ public class ListDownloadService {
ListFilterDto listFilter,
Collection<ResultCodeType> resultCodeTypes,
ListEventHistoryBase searchBase,
DateRangeDto dateRange
DateRangeDto dateRange,
ListEventHistoryOrder historyOrder,
boolean includeResult
) {
if (searchBase == null) {
throw BusinessException.internalError("이력 기준은 필수입니다.");
@@ -117,15 +174,39 @@ public class ListDownloadService {
validateDateRange(dateRange);
List<ListHeaderDto> headers = getSortedHeaders(prjctIdx);
Map<EventResultKey, String> resultLabelMap = createResultLabelMap(prjctIdx);
Map<Long, String> surveyNameMap = createSurveyNameMap(prjctIdx);
int maxHistoryCount = findMaxEventHistoryCount(prjctIdx, listFilter, resultCodeTypes, searchBase, dateRange);
List<String> excelHeaders = new ArrayList<>(toBaseHeaderNames(headers));
appendRepeatedHeaders(excelHeaders, EVENT_HISTORY_HEADERS, maxHistoryCount);
Map<Long, String> surveyNameMap = searchBase == ListEventHistoryBase.ALL
? createSurveyNameMap(prjctIdx)
: Map.of();
List<String> baseHeaderNames = toBaseHeaderNames(headers);
List<LatestResultColumn> latestResultColumns = includeResult
? createLatestResultColumns(prjctIdx, baseHeaderNames)
: List.of();
int maxHistoryCount = searchBase == ListEventHistoryBase.ALL
? findMaxEventHistoryCount(prjctIdx, listFilter, resultCodeTypes, searchBase, dateRange)
: 0;
List<String> excelHeaders = new ArrayList<>(baseHeaderNames);
latestResultColumns.stream()
.map(LatestResultColumn::headerName)
.forEach(excelHeaders::add);
EventHistoryLayout eventHistoryLayout = createEventHistoryLayout(
prjctIdx,
resultCodeTypes,
searchBase,
excelHeaders,
maxHistoryCount
);
try (
ExcelMapper.StreamingMapWriter writer = ExcelMapper.openStreamingMapWriter(excelHeaders, 100);
SXSSFWorkbook workbook = ExcelMapper.createStreamingWorkbook(100);
ExcelMapper.StreamingMapWriter writer = ExcelMapper.openStreamingMapWriter(
workbook,
excelHeaders,
EXCEL_SHEET_NAME,
EVENT_HISTORY_HEADER_ROW_INDEX
);
ByteArrayOutputStream out = new ByteArrayOutputStream()
) {
appendEventHistorySectionHeaders(workbook, eventHistoryLayout.sections());
String lastSid = null;
while (true) {
List<ListSearchService.DownloadListRow> rows = listSearchService.findDownloadListRows(prjctIdx, listFilter, lastSid);
@@ -141,6 +222,9 @@ public class ListDownloadService {
searchBase,
dateRange
);
Map<String, List<ListSearchService.LatestResultRow>> latestResultMap = includeResult
? findLatestResultMap(prjctIdx, rows)
: Map.of();
for (ListSearchService.DownloadListRow row : rows) {
writer.append(createEventHistoryRow(
@@ -149,7 +233,12 @@ public class ListDownloadService {
historyMap.getOrDefault(row.sid(), List.of()),
resultLabelMap,
surveyNameMap,
maxHistoryCount
maxHistoryCount,
searchBase,
historyOrder,
eventHistoryLayout.latestSections(),
latestResultColumns,
latestResultMap.getOrDefault(row.sid(), List.of())
));
lastSid = row.sid();
}
@@ -374,17 +463,51 @@ public class ListDownloadService {
return excelRow;
}
private Map<String, Object> createListRow(
List<ListHeaderDto> headers,
ListSearchService.DownloadListRow row,
List<LatestResultColumn> latestResultColumns,
List<ListSearchService.LatestResultRow> latestResults,
Map<EventResultKey, String> resultLabelMap
) {
Map<String, Object> excelRow = createBaseRow(headers, row);
appendLatestResults(excelRow, latestResultColumns, latestResults, resultLabelMap);
return excelRow;
}
private Map<String, Object> createEventHistoryRow(
List<ListHeaderDto> headers,
ListSearchService.DownloadListRow row,
List<ListSearchService.EventHistoryRow> histories,
Map<EventResultKey, String> resultLabelMap,
Map<Long, String> surveyNameMap,
int maxHistoryCount
int maxHistoryCount,
ListEventHistoryBase searchBase,
ListEventHistoryOrder historyOrder,
List<LatestHistorySection> latestHistorySections,
List<LatestResultColumn> latestResultColumns,
List<ListSearchService.LatestResultRow> latestResults
) {
Map<String, Object> excelRow = createBaseRow(headers, row);
appendLatestResults(excelRow, latestResultColumns, latestResults, resultLabelMap);
if (searchBase == ListEventHistoryBase.LATEST) {
appendLatestEventHistories(
excelRow,
latestHistorySections,
histories,
resultLabelMap
);
return excelRow;
}
List<ListSearchService.EventHistoryRow> orderedHistories = orderEventHistories(
histories,
historyOrder
);
for (int index = 0; index < maxHistoryCount; index++) {
ListSearchService.EventHistoryRow history = index < histories.size() ? histories.get(index) : null;
ListSearchService.EventHistoryRow history = index < orderedHistories.size()
? orderedHistories.get(index)
: null;
excelRow.put(createRepeatedHeaderName(HEADER_TYPE, index), history == null ? "" : resolveEventTypeLabel(history.eventTy()));
excelRow.put(createRepeatedHeaderName(HEADER_SURVEY, index), history == null ? "" : resolveSurveyName(history, surveyNameMap));
excelRow.put(createRepeatedHeaderName(HEADER_DATE, index), history == null ? "" : formatDateTime(history.regDt()));
@@ -395,6 +518,273 @@ public class ListDownloadService {
return excelRow;
}
private EventHistoryLayout createEventHistoryLayout(
Long prjctIdx,
Collection<ResultCodeType> resultCodeTypes,
ListEventHistoryBase searchBase,
List<String> excelHeaders,
int maxHistoryCount
) {
if (searchBase == ListEventHistoryBase.LATEST) {
List<LatestHistorySection> latestSections = appendLatestHistoryHeaders(
prjctIdx,
resultCodeTypes,
excelHeaders
);
return new EventHistoryLayout(
latestSections.stream().map(LatestHistorySection::headerSection).toList(),
latestSections
);
}
int firstHistoryColumn = excelHeaders.size();
appendRepeatedHeaders(excelHeaders, EVENT_HISTORY_HEADERS, maxHistoryCount);
List<HistoryHeaderSection> sections = new ArrayList<>();
for (int index = 0; index < maxHistoryCount; index++) {
int startColumn = firstHistoryColumn + index * EVENT_HISTORY_HEADERS.size();
sections.add(new HistoryHeaderSection(
String.valueOf(index + 1),
startColumn,
startColumn + EVENT_HISTORY_HEADERS.size() - 1
));
}
return new EventHistoryLayout(sections, List.of());
}
private List<LatestHistorySection> appendLatestHistoryHeaders(
Long prjctIdx,
Collection<ResultCodeType> resultCodeTypes,
List<String> excelHeaders
) {
Set<ResultCodeType> selectedTypes = resultCodeTypes.stream()
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Set<String> usedHeaderNames = new LinkedHashSet<>(excelHeaders);
List<LatestHistorySection> sections = new ArrayList<>();
if (selectedTypes.contains(ResultCodeType.CONTACT)) {
sections.add(appendLatestHistorySection(
excelHeaders,
usedHeaderNames,
"컨택",
ResultCodeType.CONTACT.getCode(),
null,
LATEST_CONTACT_HISTORY_HEADERS
));
}
if (selectedTypes.contains(ResultCodeType.INTERVIEW) && isFieldInterviewProject(prjctIdx)) {
sections.add(appendLatestHistorySection(
excelHeaders,
usedHeaderNames,
"현장 면접",
ResultCodeType.INTERVIEW.getCode(),
null,
LATEST_CONTACT_HISTORY_HEADERS
));
}
if (selectedTypes.contains(ResultCodeType.SURVEY)) {
for (TPrjctSurveyEntity survey
: projectSurveyRepository.findByPrjctIdxOrderBySurveyOrderAscPrjctSurveyIdxAsc(prjctIdx)) {
sections.add(appendLatestHistorySection(
excelHeaders,
usedHeaderNames,
"설문 - " + survey.getSurveyNm(),
ResultCodeType.SURVEY.getCode(),
survey.getPrjctSurveyIdx(),
LATEST_SURVEY_HISTORY_HEADERS
));
}
}
return sections;
}
private LatestHistorySection appendLatestHistorySection(
List<String> excelHeaders,
Set<String> usedHeaderNames,
String title,
Short eventTy,
Long prjctSurveyIdx,
List<String> displayHeaders
) {
int startColumn = excelHeaders.size();
Map<String, String> headerNames = new LinkedHashMap<>();
for (String displayHeader : displayHeaders) {
String headerName = createUniqueHeaderName(displayHeader, usedHeaderNames);
excelHeaders.add(headerName);
headerNames.put(displayHeader, headerName);
}
return new LatestHistorySection(
new HistoryHeaderSection(title, startColumn, excelHeaders.size() - 1),
eventTy,
prjctSurveyIdx,
headerNames.get(HEADER_DATE),
headerNames.get(HEADER_USER),
headerNames.get(HEADER_RESULT),
headerNames.get(HEADER_MEMO)
);
}
private void appendLatestEventHistories(
Map<String, Object> excelRow,
List<LatestHistorySection> sections,
List<ListSearchService.EventHistoryRow> histories,
Map<EventResultKey, String> resultLabelMap
) {
Map<LatestResultKey, ListSearchService.EventHistoryRow> historyMap = histories.stream()
.collect(Collectors.toMap(
history -> new LatestResultKey(history.eventTy(), history.prjctSurveyIdx()),
history -> history,
(left, right) -> right,
LinkedHashMap::new
));
for (LatestHistorySection section : sections) {
ListSearchService.EventHistoryRow history = historyMap.get(
new LatestResultKey(section.eventTy(), section.prjctSurveyIdx())
);
excelRow.put(section.dateHeader(), history == null ? "" : formatDateTime(history.regDt()));
if (section.userHeader() != null) {
excelRow.put(section.userHeader(), history == null ? "" : defaultString(history.regUser()));
}
excelRow.put(
section.resultHeader(),
history == null ? "" : resolveResultLabel(history, resultLabelMap)
);
excelRow.put(section.memoHeader(), history == null ? "" : defaultString(history.memo()));
}
}
private void appendEventHistorySectionHeaders(
SXSSFWorkbook workbook,
List<HistoryHeaderSection> sections
) {
Sheet sheet = workbook.getSheet(EXCEL_SHEET_NAME);
Row row = sheet.createRow(0);
CellStyle style = createSectionHeaderStyle(workbook);
for (HistoryHeaderSection section : sections) {
for (int column = section.startColumn(); column <= section.endColumn(); column++) {
row.createCell(column).setCellStyle(style);
}
row.getCell(section.startColumn()).setCellValue(section.title());
sheet.addMergedRegion(new CellRangeAddress(
0,
0,
section.startColumn(),
section.endColumn()
));
}
}
private CellStyle createSectionHeaderStyle(SXSSFWorkbook workbook) {
CellStyle style = workbook.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
Font font = workbook.createFont();
font.setBold(true);
style.setFont(font);
return style;
}
private boolean isFieldInterviewProject(Long prjctIdx) {
TPrjctEntity project = projectRepository.findByPrjctIdxAndDelFalse(prjctIdx);
if (project == null) {
throw BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
.with("prjctIdx", prjctIdx);
}
return Boolean.TRUE.equals(project.getFf());
}
private void appendLatestResults(
Map<String, Object> excelRow,
List<LatestResultColumn> columns,
List<ListSearchService.LatestResultRow> latestResults,
Map<EventResultKey, String> resultLabelMap
) {
Map<LatestResultKey, Integer> resultCodeMap = latestResults.stream()
.collect(Collectors.toMap(
result -> new LatestResultKey(result.eventTy(), result.prjctSurveyIdx()),
ListSearchService.LatestResultRow::resultCd,
(left, right) -> right,
LinkedHashMap::new
));
for (LatestResultColumn column : columns) {
Integer resultCode = resultCodeMap.get(new LatestResultKey(column.eventTy(), column.prjctSurveyIdx()));
String resultLabel = resultLabelMap.get(new EventResultKey(column.eventTy(), resultCode));
excelRow.put(column.headerName(), resultCode == null ? "" : defaultString(resultLabel == null ? resultCode : resultLabel));
}
}
private Map<String, List<ListSearchService.LatestResultRow>> findLatestResultMap(
Long prjctIdx,
List<ListSearchService.DownloadListRow> rows
) {
List<String> sids = rows.stream()
.map(ListSearchService.DownloadListRow::sid)
.toList();
return listSearchService.findLatestResultsForDownload(prjctIdx, sids);
}
private List<LatestResultColumn> createLatestResultColumns(
Long prjctIdx,
Collection<String> baseHeaderNames
) {
TPrjctEntity project = projectRepository.findByPrjctIdxAndDelFalse(prjctIdx);
if (project == null) {
throw BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
.with("prjctIdx", prjctIdx);
}
List<LatestResultColumn> columns = new ArrayList<>();
Set<String> usedHeaderNames = new LinkedHashSet<>(baseHeaderNames);
columns.add(new LatestResultColumn(
createUniqueHeaderName(HEADER_CONTACT_RESULT, usedHeaderNames),
ResultCodeType.CONTACT.getCode(),
null
));
if (Boolean.TRUE.equals(project.getFf())) {
columns.add(new LatestResultColumn(
createUniqueHeaderName(HEADER_INTERVIEW_RESULT, usedHeaderNames),
ResultCodeType.INTERVIEW.getCode(),
null
));
}
for (TPrjctSurveyEntity survey
: projectSurveyRepository.findByPrjctIdxOrderBySurveyOrderAscPrjctSurveyIdxAsc(prjctIdx)) {
columns.add(new LatestResultColumn(
createUniqueHeaderName(
HEADER_SURVEY_RESULT_PREFIX + survey.getSurveyNm(),
usedHeaderNames
),
ResultCodeType.SURVEY.getCode(),
survey.getPrjctSurveyIdx()
));
}
return columns;
}
private String createUniqueHeaderName(String headerName, Set<String> usedHeaderNames) {
String uniqueHeaderName = headerName;
while (!usedHeaderNames.add(uniqueHeaderName)) {
uniqueHeaderName += ZERO_WIDTH_SPACE;
}
return uniqueHeaderName;
}
private List<ListSearchService.EventHistoryRow> orderEventHistories(
List<ListSearchService.EventHistoryRow> histories,
ListEventHistoryOrder historyOrder
) {
if (historyOrder != ListEventHistoryOrder.DESC || histories.size() < 2) {
return histories;
}
List<ListSearchService.EventHistoryRow> orderedHistories = new ArrayList<>(histories);
Collections.reverse(orderedHistories);
return orderedHistories;
}
private Map<String, Object> createUpdateHistoryRow(
String sid,
List<ListSearchService.UpdateHistoryGroupRow> histories,
@@ -559,4 +949,37 @@ public class ListDownloadService {
Short eventTy,
Integer resultCd
) {}
private record LatestResultKey(
Short eventTy,
Long prjctSurveyIdx
) {}
private record LatestResultColumn(
String headerName,
Short eventTy,
Long prjctSurveyIdx
) {}
private record HistoryHeaderSection(
String title,
int startColumn,
int endColumn
) {}
private record LatestHistorySection(
HistoryHeaderSection headerSection,
Short eventTy,
Long prjctSurveyIdx,
String dateHeader,
String userHeader,
String resultHeader,
String memoHeader
) {}
private record EventHistoryLayout(
List<HistoryHeaderSection> sections,
List<LatestHistorySection> latestSections
) {}
}

View File

@@ -193,6 +193,32 @@ public class ListSearchService {
.toList();
}
@Transactional(readOnly = true)
public Map<String, List<LatestResultRow>> findLatestResultsForDownload(
Long prjctIdx,
Collection<String> sids
) {
if (sids == null || sids.isEmpty()) {
return Collections.emptyMap();
}
return listEventHistRepository
.findLatestListByEventTyFromLatest(prjctIdx, new ArrayList<>(sids))
.stream()
.collect(Collectors.groupingBy(
TListEventHistEntity::getSid,
LinkedHashMap::new,
Collectors.mapping(
entity -> new LatestResultRow(
entity.getEventTy(),
entity.getPrjctSurveyIdx(),
entity.getResultCd()
),
Collectors.toList()
)
));
}
@Transactional(readOnly = true)
public List<String> findDownloadSids(
Long prjctIdx,
@@ -780,6 +806,12 @@ public class ListSearchService {
AssignValues assignValues
) {}
public record LatestResultRow(
Short eventTy,
Long prjctSurveyIdx,
Integer resultCd
) {}
public record EventHistoryRow(
Short eventTy,
Long prjctSurveyIdx,

View File

@@ -9,7 +9,8 @@ kri:
spring:
datasource:
#public 도메인
url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/test_kri_contact?characterEncoding=UTF-8&rewriteBatchedStatements=true
#url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/test_kri_contact?characterEncoding=UTF-8&rewriteBatchedStatements=true
url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/kri_contact?characterEncoding=UTF-8&rewriteBatchedStatements=true
username: kri_contact
password: contact#51304
driver-class-name: com.mysql.cj.jdbc.Driver