API명별 요약 통계
This commit is contained in:
@@ -63,6 +63,12 @@ public class ApiStatsMonthController {
|
||||
return ResponseEntity.ok(chartData);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/onl/kjb/statistics/apiStatsMonthMan.json", params = "cmd=LIST_SUMMARY")
|
||||
public ResponseEntity<GridResponse<ApiStatsUI>> selectSummaryList(ApiStatsSearch search, Pageable pageable) {
|
||||
Page<ApiStatsUI> page = service.selectSummaryList(search, pageable);
|
||||
return ResponseEntity.ok(new GridResponse<>(page));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/onl/kjb/statistics/apiStatsMonthMan.json", params = "cmd=EXCEL_EXPORT")
|
||||
public void exportToExcel(ApiStatsSearch search, HttpServletResponse response) throws IOException {
|
||||
log.info("Excel export started - search: {}", search);
|
||||
@@ -106,10 +112,55 @@ public class ApiStatsMonthController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = "/onl/kjb/statistics/apiStatsMonthMan.json", params = "cmd=EXCEL_EXPORT_SUMMARY")
|
||||
public void exportSummaryToExcel(ApiStatsSearch search, HttpServletResponse response) throws IOException {
|
||||
log.info("Excel export (summary) started - search: {}", search);
|
||||
|
||||
try {
|
||||
List<ApiStatsUI> dataList = service.selectSummaryListForExcel(search);
|
||||
log.info("Summary data retrieved - count: {}", dataList.size());
|
||||
|
||||
if (dataList.isEmpty()) {
|
||||
log.warn("No data found for export");
|
||||
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
|
||||
response.setContentType("application/json; charset=UTF-8");
|
||||
response.getWriter().write("{\"message\":\"조회된 데이터가 없습니다.\"}");
|
||||
response.getWriter().flush();
|
||||
return;
|
||||
}
|
||||
|
||||
String fileName = generateSummaryFileName(search);
|
||||
log.info("Generating Excel file: {}", fileName);
|
||||
|
||||
excelExportService.exportApiStats(dataList, fileName, response);
|
||||
log.info("Excel export (summary) completed successfully");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Excel export (summary) failed - error: {}", e.getMessage(), e);
|
||||
|
||||
if (!response.isCommitted()) {
|
||||
response.reset();
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
response.setContentType("application/json; charset=UTF-8");
|
||||
response.getWriter().write("{\"message\":\"Excel 파일 생성 중 오류가 발생했습니다: " + e.getMessage() + "\"}");
|
||||
response.getWriter().flush();
|
||||
} else {
|
||||
log.error("Cannot send error response - response already committed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String generateFileName(ApiStatsSearch search) {
|
||||
String timeRange = StringUtils.isNotBlank(search.getSearchStartDateTime())
|
||||
? search.getSearchStartDateTime()
|
||||
: YearMonth.now().format(DateTimeFormatter.ofPattern("yyyyMM"));
|
||||
return "API월별통계_" + timeRange + ".xlsx";
|
||||
}
|
||||
|
||||
private String generateSummaryFileName(ApiStatsSearch search) {
|
||||
String timeRange = StringUtils.isNotBlank(search.getSearchStartDateTime())
|
||||
? search.getSearchStartDateTime()
|
||||
: YearMonth.now().format(DateTimeFormatter.ofPattern("yyyyMM"));
|
||||
return "API월별통계_요약_" + timeRange + ".xlsx";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user