|
|
|
@@ -6,6 +6,7 @@ import com.kri.common.feature.datetime.DateTimeUtil;
|
|
|
|
import com.kri.common.feature.excel.ExcelMapper;
|
|
|
|
import com.kri.common.feature.excel.ExcelMapper;
|
|
|
|
import com.kri.common.feature.web.BusinessException;
|
|
|
|
import com.kri.common.feature.web.BusinessException;
|
|
|
|
import com.kri.contact.server.common.enums.ListEventHistoryBase;
|
|
|
|
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.ListHeaderType;
|
|
|
|
import com.kri.contact.server.common.enums.ListIsUse;
|
|
|
|
import com.kri.contact.server.common.enums.ListIsUse;
|
|
|
|
import com.kri.contact.server.common.enums.ResultCodeType;
|
|
|
|
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.dto.list.ListUploadFileInfoDto;
|
|
|
|
import com.kri.contact.server.persistence.entity.TListItemFileEntity;
|
|
|
|
import com.kri.contact.server.persistence.entity.TListItemFileEntity;
|
|
|
|
import com.kri.contact.server.persistence.entity.id.TListItemFileEntityId;
|
|
|
|
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.TPrjctSurveyEntity;
|
|
|
|
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
|
|
|
|
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
|
|
|
|
import com.kri.contact.server.persistence.repository.ListItemFileRepository;
|
|
|
|
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.ProjectSurveyRepository;
|
|
|
|
import com.kri.contact.server.persistence.repository.ResultCodeRepository;
|
|
|
|
import com.kri.contact.server.persistence.repository.ResultCodeRepository;
|
|
|
|
import com.kri.contact.server.service.file.ListItemFileService;
|
|
|
|
import com.kri.contact.server.service.file.ListItemFileService;
|
|
|
|
@@ -25,8 +28,10 @@ import java.io.ByteArrayOutputStream;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Objects;
|
|
|
|
@@ -35,6 +40,14 @@ import java.util.stream.Collectors;
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
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;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
@@ -47,8 +60,13 @@ public class ListDownloadService {
|
|
|
|
private static final String HEADER_USER = "사용자";
|
|
|
|
private static final String HEADER_USER = "사용자";
|
|
|
|
private static final String HEADER_RESULT = "결과";
|
|
|
|
private static final String HEADER_RESULT = "결과";
|
|
|
|
private static final String HEADER_MEMO = "메모";
|
|
|
|
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_BEFORE = "변경전";
|
|
|
|
private static final String HEADER_AFTER = "변경후";
|
|
|
|
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 String ZERO_WIDTH_SPACE = String.valueOf(Character.toChars(0x200B));
|
|
|
|
|
|
|
|
|
|
|
|
private static final List<String> EVENT_HISTORY_HEADERS = List.of(
|
|
|
|
private static final List<String> EVENT_HISTORY_HEADERS = List.of(
|
|
|
|
@@ -59,6 +77,17 @@ public class ListDownloadService {
|
|
|
|
HEADER_RESULT,
|
|
|
|
HEADER_RESULT,
|
|
|
|
HEADER_MEMO
|
|
|
|
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(
|
|
|
|
private static final List<String> UPDATE_HISTORY_HEADERS = List.of(
|
|
|
|
HEADER_DATE,
|
|
|
|
HEADER_DATE,
|
|
|
|
HEADER_USER,
|
|
|
|
HEADER_USER,
|
|
|
|
@@ -71,14 +100,30 @@ public class ListDownloadService {
|
|
|
|
private final ListItemFileRepository listItemFileRepository;
|
|
|
|
private final ListItemFileRepository listItemFileRepository;
|
|
|
|
private final ListItemFileService listItemFileService;
|
|
|
|
private final ListItemFileService listItemFileService;
|
|
|
|
private final ResultCodeRepository resultCodeRepository;
|
|
|
|
private final ResultCodeRepository resultCodeRepository;
|
|
|
|
|
|
|
|
private final ProjectRepository projectRepository;
|
|
|
|
private final ProjectSurveyRepository projectSurveyRepository;
|
|
|
|
private final ProjectSurveyRepository projectSurveyRepository;
|
|
|
|
private final ObjectMapper objectMapper;
|
|
|
|
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<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 (
|
|
|
|
try (
|
|
|
|
ExcelMapper.StreamingMapWriter writer = ExcelMapper.openStreamingMapWriter(toBaseHeaderNames(headers), 100);
|
|
|
|
ExcelMapper.StreamingMapWriter writer = ExcelMapper.openStreamingMapWriter(excelHeaders, 100);
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream()
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream()
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
String lastSid = null;
|
|
|
|
String lastSid = null;
|
|
|
|
@@ -88,8 +133,18 @@ public class ListDownloadService {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, List<ListSearchService.LatestResultRow>> latestResultMap = includeResult
|
|
|
|
|
|
|
|
? findLatestResultMap(prjctIdx, rows)
|
|
|
|
|
|
|
|
: Map.of();
|
|
|
|
|
|
|
|
|
|
|
|
for (ListSearchService.DownloadListRow row : rows) {
|
|
|
|
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();
|
|
|
|
lastSid = row.sid();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -108,7 +163,9 @@ public class ListDownloadService {
|
|
|
|
ListFilterDto listFilter,
|
|
|
|
ListFilterDto listFilter,
|
|
|
|
Collection<ResultCodeType> resultCodeTypes,
|
|
|
|
Collection<ResultCodeType> resultCodeTypes,
|
|
|
|
ListEventHistoryBase searchBase,
|
|
|
|
ListEventHistoryBase searchBase,
|
|
|
|
DateRangeDto dateRange
|
|
|
|
DateRangeDto dateRange,
|
|
|
|
|
|
|
|
ListEventHistoryOrder historyOrder,
|
|
|
|
|
|
|
|
boolean includeResult
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
if (searchBase == null) {
|
|
|
|
if (searchBase == null) {
|
|
|
|
throw BusinessException.internalError("이력 기준은 필수입니다.");
|
|
|
|
throw BusinessException.internalError("이력 기준은 필수입니다.");
|
|
|
|
@@ -117,15 +174,39 @@ public class ListDownloadService {
|
|
|
|
validateDateRange(dateRange);
|
|
|
|
validateDateRange(dateRange);
|
|
|
|
List<ListHeaderDto> headers = getSortedHeaders(prjctIdx);
|
|
|
|
List<ListHeaderDto> headers = getSortedHeaders(prjctIdx);
|
|
|
|
Map<EventResultKey, String> resultLabelMap = createResultLabelMap(prjctIdx);
|
|
|
|
Map<EventResultKey, String> resultLabelMap = createResultLabelMap(prjctIdx);
|
|
|
|
Map<Long, String> surveyNameMap = createSurveyNameMap(prjctIdx);
|
|
|
|
Map<Long, String> surveyNameMap = searchBase == ListEventHistoryBase.ALL
|
|
|
|
int maxHistoryCount = findMaxEventHistoryCount(prjctIdx, listFilter, resultCodeTypes, searchBase, dateRange);
|
|
|
|
? createSurveyNameMap(prjctIdx)
|
|
|
|
List<String> excelHeaders = new ArrayList<>(toBaseHeaderNames(headers));
|
|
|
|
: Map.of();
|
|
|
|
appendRepeatedHeaders(excelHeaders, EVENT_HISTORY_HEADERS, maxHistoryCount);
|
|
|
|
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 (
|
|
|
|
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()
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream()
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
appendEventHistorySectionHeaders(workbook, eventHistoryLayout.sections());
|
|
|
|
String lastSid = null;
|
|
|
|
String lastSid = null;
|
|
|
|
while (true) {
|
|
|
|
while (true) {
|
|
|
|
List<ListSearchService.DownloadListRow> rows = listSearchService.findDownloadListRows(prjctIdx, listFilter, lastSid);
|
|
|
|
List<ListSearchService.DownloadListRow> rows = listSearchService.findDownloadListRows(prjctIdx, listFilter, lastSid);
|
|
|
|
@@ -141,6 +222,9 @@ public class ListDownloadService {
|
|
|
|
searchBase,
|
|
|
|
searchBase,
|
|
|
|
dateRange
|
|
|
|
dateRange
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
Map<String, List<ListSearchService.LatestResultRow>> latestResultMap = includeResult
|
|
|
|
|
|
|
|
? findLatestResultMap(prjctIdx, rows)
|
|
|
|
|
|
|
|
: Map.of();
|
|
|
|
|
|
|
|
|
|
|
|
for (ListSearchService.DownloadListRow row : rows) {
|
|
|
|
for (ListSearchService.DownloadListRow row : rows) {
|
|
|
|
writer.append(createEventHistoryRow(
|
|
|
|
writer.append(createEventHistoryRow(
|
|
|
|
@@ -149,7 +233,12 @@ public class ListDownloadService {
|
|
|
|
historyMap.getOrDefault(row.sid(), List.of()),
|
|
|
|
historyMap.getOrDefault(row.sid(), List.of()),
|
|
|
|
resultLabelMap,
|
|
|
|
resultLabelMap,
|
|
|
|
surveyNameMap,
|
|
|
|
surveyNameMap,
|
|
|
|
maxHistoryCount
|
|
|
|
maxHistoryCount,
|
|
|
|
|
|
|
|
searchBase,
|
|
|
|
|
|
|
|
historyOrder,
|
|
|
|
|
|
|
|
eventHistoryLayout.latestSections(),
|
|
|
|
|
|
|
|
latestResultColumns,
|
|
|
|
|
|
|
|
latestResultMap.getOrDefault(row.sid(), List.of())
|
|
|
|
));
|
|
|
|
));
|
|
|
|
lastSid = row.sid();
|
|
|
|
lastSid = row.sid();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -374,17 +463,51 @@ public class ListDownloadService {
|
|
|
|
return excelRow;
|
|
|
|
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(
|
|
|
|
private Map<String, Object> createEventHistoryRow(
|
|
|
|
List<ListHeaderDto> headers,
|
|
|
|
List<ListHeaderDto> headers,
|
|
|
|
ListSearchService.DownloadListRow row,
|
|
|
|
ListSearchService.DownloadListRow row,
|
|
|
|
List<ListSearchService.EventHistoryRow> histories,
|
|
|
|
List<ListSearchService.EventHistoryRow> histories,
|
|
|
|
Map<EventResultKey, String> resultLabelMap,
|
|
|
|
Map<EventResultKey, String> resultLabelMap,
|
|
|
|
Map<Long, String> surveyNameMap,
|
|
|
|
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);
|
|
|
|
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++) {
|
|
|
|
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_TYPE, index), history == null ? "" : resolveEventTypeLabel(history.eventTy()));
|
|
|
|
excelRow.put(createRepeatedHeaderName(HEADER_SURVEY, index), history == null ? "" : resolveSurveyName(history, surveyNameMap));
|
|
|
|
excelRow.put(createRepeatedHeaderName(HEADER_SURVEY, index), history == null ? "" : resolveSurveyName(history, surveyNameMap));
|
|
|
|
excelRow.put(createRepeatedHeaderName(HEADER_DATE, index), history == null ? "" : formatDateTime(history.regDt()));
|
|
|
|
excelRow.put(createRepeatedHeaderName(HEADER_DATE, index), history == null ? "" : formatDateTime(history.regDt()));
|
|
|
|
@@ -395,6 +518,273 @@ public class ListDownloadService {
|
|
|
|
return excelRow;
|
|
|
|
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(
|
|
|
|
private Map<String, Object> createUpdateHistoryRow(
|
|
|
|
String sid,
|
|
|
|
String sid,
|
|
|
|
List<ListSearchService.UpdateHistoryGroupRow> histories,
|
|
|
|
List<ListSearchService.UpdateHistoryGroupRow> histories,
|
|
|
|
@@ -559,4 +949,37 @@ public class ListDownloadService {
|
|
|
|
Short eventTy,
|
|
|
|
Short eventTy,
|
|
|
|
Integer resultCd
|
|
|
|
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
|
|
|
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|