diff --git a/.agent/project.md b/.agent/project.md index 71fe693..a5f921f 100644 --- a/.agent/project.md +++ b/.agent/project.md @@ -13,12 +13,12 @@ - Do not implement a frontend administration page at this stage. Do not add create, update, or delete features for individual information records unless a future approved requirement explicitly expands the scope. - Supply and maintain the data required by this project through Excel-based bulk upload instead of individual administration features. - Keep user and file data outside the Excel bulk-import scope. Import the remaining project data from one Excel workbook containing multiple sheets. -- The Excel workbook contract uses nine required sheets named after their tables: `t_wave`, `t_wave_info`, `t_survey`, `t_survey_item`, `t_part`, `t_part_item`, `t_part_item_sub`, `t_part_item_base`, and `t_part_item_data`. Headers normally use database column names; append the complete allowed-value list in parentheses for constrained columns, such as `is_open (1, 0)`, `chart_type (bar)`, and `is_chart_visible (1, 0)`. The workbook must contain all logical parent rows referenced by its child rows. -- Treat every database column whose name ends with `_idx` as an auto-increment identity. Do not include these columns in Excel import or template sheets, and preserve an existing identity by matching the row's logical key during repeat imports. -- For identity-backed Excel tables, use these import logical keys: `(wave_cd, wave_info_order)` for `t_wave_info`, `(wave_cd, survey_cd, survey_item_order)` for `t_survey_item`, `(wave_cd, part_cd, part_item_cd, survey_cd, part_item_sub_cd)` for `t_part_item_base`, and that same result-series key plus `part_item_data_order` for `t_part_item_data`. +- The Excel workbook has eleven required table-named sheets: `t_wave`, `t_wave_info`, `t_survey`, `t_survey_item`, `t_part`, `t_part_item`, `t_part_item_sub`, `t_part_item_base`, `t_part_item_chart`, `t_part_item_chart_highlight`, and `t_part_item_data`. Headers use database names and constrained headers list every allowed value in parentheses. The workbook must contain all referenced logical parents. +- Omit every auto-increment `_idx` column from Excel. Replacement imports regenerate identities. +- Reject duplicate workbook logical keys: `(wave_cd, wave_info_order)` for Wave info; `(wave_cd, survey_cd, survey_item_order)` for survey items; `(wave_cd, part_cd, part_item_cd, survey_cd, part_item_sub_cd)` for base, chart, and highlight rows; and that result-series key plus `part_item_data_order` for data rows. - Define the Excel import/export schema once with KriCommon `ExcelColumn` DTOs. Use KriCommon `ExcelMapper` for workbook mapping and keep only project-specific type, value, and cross-sheet relationship rules in a consumer-local validator; do not duplicate a general-purpose Excel parser. -- Use `POST /api/v1/excel/import` for workbook import and `GET /api/v1/excel/template` for downloading an empty XLSX template. The exported template must contain the same nine required sheets in dependency order and the exact headers accepted by the importer. -- Apply a valid workbook atomically using upsert semantics: insert new primary/logical keys, update matching keys, and retain existing database rows that are absent from the workbook. Do not use a bulk import to delete omitted rows unless a future approved requirement explicitly changes this policy. +- Excel endpoints are `POST /api/v1/excel/import`, `GET /api/v1/excel/template`, `GET /api/v1/excel/waves/{waveCd}/export`, and `DELETE /api/v1/excel/waves/{waveCd}`. Downloads use the same eleven sheets, order, and headers; a missing Wave exports an empty workbook. +- Imports atomically replace every included Wave: validate first, delete all eleven managed tables, then insert. Failures restore prior data. Standalone reset uses the same child-to-root deletion and retains `t_file` metadata and physical files, allowing temporary orphans until that `wave_cd` is reimported. - A reference-file upload writes both the physical file and its `t_file` metadata. Accept `fileTitle` and `fileOrder` as multipart request fields, derive `file_type` from the lowercase filename extension, and keep the original filename as `file_name`. - For reference-file uploads, accept `waveCd` as a path variable and store the file under `{kri.file.base-dir}/References/{waveCd}` using the original filename. Treat `(wave_cd, file_name)` as the upload logical key: uploading the same filename again preserves `file_idx`, replaces the physical file, and updates `file_title`, `file_order`, and `file_type`. - Reject a reference-file upload when its `waveCd` does not exist. Coordinate the database transaction and filesystem replacement so a database rollback restores the previous file or removes a newly created file. @@ -30,6 +30,7 @@ - Do not add physical database foreign keys. The backend must validate all logical parent-child relationships during Excel import and any future data mutation. - Treat `(wave_cd, part_cd, part_item_cd)` as the logical item key. Add `survey_cd` to identify a survey-specific result set and add `part_item_sub_cd` when a sub-item exists. - `t_part_item_sub` has no physical primary key in the planned schema. Treat `(wave_cd, part_cd, part_item_cd, part_item_sub_cd)` as its logical identifier and lookup key. +- Store the nullable `t_part_item_sub.part_item_sub_comment` value and expose it as `partItemSubComment` in Part-detail sub-item responses. - A normal item has no `t_part_item_sub` rows, and both base and data rows must use `part_item_sub_cd = NULL`. Never use `0` as a substitute for this `NULL` value. - An item with sub-items has one or more `t_part_item_sub` rows. Every non-null `part_item_sub_cd` in its base and data rows must reference a sub-item belonging to the same `(wave_cd, part_cd, part_item_cd)`. - Every survey code used by `t_part_item_base` or `t_part_item_data` must belong to the same Wave. Survey items must likewise belong to an existing `(wave_cd, survey_cd)`. @@ -38,6 +39,9 @@ - Store an optional display string in `t_part_item_base.base_text` (`VARCHAR(128)`). Do not reconstruct it from `base_count`, and do not retain the removed `base_pre_text` or `base_post_text` fields in entities, Excel contracts, or query assembly. - Use the corresponding `*_order` column for API and screen ordering: `wave_info_order`, `survey_order`, `survey_item_order`, `file_order`, `part_order`, `part_item_order`, and `part_item_data_order`. Use `part_item_sub_cd` as the default sub-item order because the schema has no separate sub-item order column. - Use the same `t_part_item_data` rows for both chart and statistical-table views. `is_chart_visible` is a required Boolean column with database default `1`; statistical tables use every row, while charts omit categories and matching values whose flag is false. Do not introduce a separate table-data source that could diverge from chart values. +- Resolve `chart_type`, `chart_color`, and `chart_gap_mode` per `(wave_cd, part_cd, part_item_cd, survey_cd, part_item_sub_cd)` from `t_part_item_chart`, not `t_part_item`. Defaults are `BAR`, `t_survey.survey_color`, and `NONE`; normalize null or unknown gap modes to `NONE`. Allowed gap modes are `NONE`, `ALL`, and `LAST_VISIBLE`. +- Resolve `t_part_item_chart_highlight` independently from `t_part_item_chart`; a highlight may exist without a chart-setting row. Return `chart_highlight_mode`, `chart_highlight_value`, and `chart_highlight_color` to the frontend without calculating highlighted categories in the backend. Supported modes are `MAX_VALUE`, `LAST_VISIBLE`, and `SPECIFIED`; only `SPECIFIED` accepts a non-null, comma-separated integer value with no spaces. +- Treat null `part_item_sub_cd` values as equal when matching normal-item chart and highlight settings. Validate at Excel import that chart and highlight logical keys are unique, normal items use null sub codes, and colors use `#RRGGBB` format. - Avoid N+1 query patterns when assembling a Wave dashboard. Fetch the required Part, Item, Sub, Base, and Data ranges in batches and assemble the response hierarchy in the backend. ## Frontend API Contract @@ -49,7 +53,8 @@ - Return categories as objects containing `order`, `label`, and `chartVisible`, alongside complete survey value series. The frontend uses all category/value indexes for statistical tables and filters matching indexes only for chart rendering. Reject Excel imports when category labels, display orders, or chart-visibility flags differ between survey series in the same Item/Sub result group. - Expose each survey's stored color as `color` in both Wave-detail survey objects and Part-detail series objects so the frontend uses one server-managed color mapping. - Return the stored nullable `t_part_item_base.base_text` value unchanged as Part-detail `series[].baseText`; `baseCount` remains a separate numeric field. +- Return `series[].chartGapMode`; the frontend applies `NONE`, `ALL`, or `LAST_VISIBLE`, where the last mode uses the greatest visible `part_item_data_order`. - When importing `part_item_data_value`, round to scale 10 with `RoundingMode.HALF_UP` before validating and storing it as `DECIMAL(14,10)`. Reject only values that still exceed precision 14 after rounding. - When `part_item_comment` is blank in Excel, store an empty string rather than `NULL` because the database column is required. Preserve the existing `NULL` semantics of other optional Excel fields. -- Manage chart types as code enums. The initial supported type is `BAR`; Excel accepts its label `bar` case-insensitively, the database stores code `BAR`, and frontend responses return code `BAR`. Reject unsupported labels during Excel validation. +- Manage chart types as code enums in `t_part_item_chart`. The initial supported type is `BAR`; Excel accepts its label `bar` case-insensitively, the database stores code `BAR`, and Part-detail series responses return code `BAR`. Reject unsupported labels during Excel validation. - Build file download URLs in the backend from the configured file resource path and the stored file metadata. Do not require the frontend to construct filesystem paths. diff --git a/AGENTS.md b/AGENTS.md index fedd166..dafca61 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -275,12 +275,12 @@ When implementation is complete, report in Korean: - Do not implement a frontend administration page at this stage. Do not add create, update, or delete features for individual information records unless a future approved requirement explicitly expands the scope. - Supply and maintain the data required by this project through Excel-based bulk upload instead of individual administration features. - Keep user and file data outside the Excel bulk-import scope. Import the remaining project data from one Excel workbook containing multiple sheets. -- The Excel workbook contract uses nine required sheets named after their tables: `t_wave`, `t_wave_info`, `t_survey`, `t_survey_item`, `t_part`, `t_part_item`, `t_part_item_sub`, `t_part_item_base`, and `t_part_item_data`. Headers normally use database column names; append the complete allowed-value list in parentheses for constrained columns, such as `is_open (1, 0)`, `chart_type (bar)`, and `is_chart_visible (1, 0)`. The workbook must contain all logical parent rows referenced by its child rows. -- Treat every database column whose name ends with `_idx` as an auto-increment identity. Do not include these columns in Excel import or template sheets, and preserve an existing identity by matching the row's logical key during repeat imports. -- For identity-backed Excel tables, use these import logical keys: `(wave_cd, wave_info_order)` for `t_wave_info`, `(wave_cd, survey_cd, survey_item_order)` for `t_survey_item`, `(wave_cd, part_cd, part_item_cd, survey_cd, part_item_sub_cd)` for `t_part_item_base`, and that same result-series key plus `part_item_data_order` for `t_part_item_data`. +- The Excel workbook has eleven required table-named sheets: `t_wave`, `t_wave_info`, `t_survey`, `t_survey_item`, `t_part`, `t_part_item`, `t_part_item_sub`, `t_part_item_base`, `t_part_item_chart`, `t_part_item_chart_highlight`, and `t_part_item_data`. Headers use database names and constrained headers list every allowed value in parentheses. The workbook must contain all referenced logical parents. +- Omit every auto-increment `_idx` column from Excel. Replacement imports regenerate identities. +- Reject duplicate workbook logical keys: `(wave_cd, wave_info_order)` for Wave info; `(wave_cd, survey_cd, survey_item_order)` for survey items; `(wave_cd, part_cd, part_item_cd, survey_cd, part_item_sub_cd)` for base, chart, and highlight rows; and that result-series key plus `part_item_data_order` for data rows. - Define the Excel import/export schema once with KriCommon `ExcelColumn` DTOs. Use KriCommon `ExcelMapper` for workbook mapping and keep only project-specific type, value, and cross-sheet relationship rules in a consumer-local validator; do not duplicate a general-purpose Excel parser. -- Use `POST /api/v1/excel/import` for workbook import and `GET /api/v1/excel/template` for downloading an empty XLSX template. The exported template must contain the same nine required sheets in dependency order and the exact headers accepted by the importer. -- Apply a valid workbook atomically using upsert semantics: insert new primary/logical keys, update matching keys, and retain existing database rows that are absent from the workbook. Do not use a bulk import to delete omitted rows unless a future approved requirement explicitly changes this policy. +- Excel endpoints are `POST /api/v1/excel/import`, `GET /api/v1/excel/template`, `GET /api/v1/excel/waves/{waveCd}/export`, and `DELETE /api/v1/excel/waves/{waveCd}`. Downloads use the same eleven sheets, order, and headers; a missing Wave exports an empty workbook. +- Imports atomically replace every included Wave: validate first, delete all eleven managed tables, then insert. Failures restore prior data. Standalone reset uses the same child-to-root deletion and retains `t_file` metadata and physical files, allowing temporary orphans until that `wave_cd` is reimported. - A reference-file upload writes both the physical file and its `t_file` metadata. Accept `fileTitle` and `fileOrder` as multipart request fields, derive `file_type` from the lowercase filename extension, and keep the original filename as `file_name`. - For reference-file uploads, accept `waveCd` as a path variable and store the file under `{kri.file.base-dir}/References/{waveCd}` using the original filename. Treat `(wave_cd, file_name)` as the upload logical key: uploading the same filename again preserves `file_idx`, replaces the physical file, and updates `file_title`, `file_order`, and `file_type`. - Reject a reference-file upload when its `waveCd` does not exist. Coordinate the database transaction and filesystem replacement so a database rollback restores the previous file or removes a newly created file. @@ -292,6 +292,7 @@ When implementation is complete, report in Korean: - Do not add physical database foreign keys. The backend must validate all logical parent-child relationships during Excel import and any future data mutation. - Treat `(wave_cd, part_cd, part_item_cd)` as the logical item key. Add `survey_cd` to identify a survey-specific result set and add `part_item_sub_cd` when a sub-item exists. - `t_part_item_sub` has no physical primary key in the planned schema. Treat `(wave_cd, part_cd, part_item_cd, part_item_sub_cd)` as its logical identifier and lookup key. +- Store the nullable `t_part_item_sub.part_item_sub_comment` value and expose it as `partItemSubComment` in Part-detail sub-item responses. - A normal item has no `t_part_item_sub` rows, and both base and data rows must use `part_item_sub_cd = NULL`. Never use `0` as a substitute for this `NULL` value. - An item with sub-items has one or more `t_part_item_sub` rows. Every non-null `part_item_sub_cd` in its base and data rows must reference a sub-item belonging to the same `(wave_cd, part_cd, part_item_cd)`. - Every survey code used by `t_part_item_base` or `t_part_item_data` must belong to the same Wave. Survey items must likewise belong to an existing `(wave_cd, survey_cd)`. @@ -300,6 +301,9 @@ When implementation is complete, report in Korean: - Store an optional display string in `t_part_item_base.base_text` (`VARCHAR(128)`). Do not reconstruct it from `base_count`, and do not retain the removed `base_pre_text` or `base_post_text` fields in entities, Excel contracts, or query assembly. - Use the corresponding `*_order` column for API and screen ordering: `wave_info_order`, `survey_order`, `survey_item_order`, `file_order`, `part_order`, `part_item_order`, and `part_item_data_order`. Use `part_item_sub_cd` as the default sub-item order because the schema has no separate sub-item order column. - Use the same `t_part_item_data` rows for both chart and statistical-table views. `is_chart_visible` is a required Boolean column with database default `1`; statistical tables use every row, while charts omit categories and matching values whose flag is false. Do not introduce a separate table-data source that could diverge from chart values. +- Resolve `chart_type`, `chart_color`, and `chart_gap_mode` per `(wave_cd, part_cd, part_item_cd, survey_cd, part_item_sub_cd)` from `t_part_item_chart`, not `t_part_item`. Defaults are `BAR`, `t_survey.survey_color`, and `NONE`; normalize null or unknown gap modes to `NONE`. Allowed gap modes are `NONE`, `ALL`, and `LAST_VISIBLE`. +- Resolve `t_part_item_chart_highlight` independently from `t_part_item_chart`; a highlight may exist without a chart-setting row. Return `chart_highlight_mode`, `chart_highlight_value`, and `chart_highlight_color` to the frontend without calculating highlighted categories in the backend. Supported modes are `MAX_VALUE`, `LAST_VISIBLE`, and `SPECIFIED`; only `SPECIFIED` accepts a non-null, comma-separated integer value with no spaces. +- Treat null `part_item_sub_cd` values as equal when matching normal-item chart and highlight settings. Validate at Excel import that chart and highlight logical keys are unique, normal items use null sub codes, and colors use `#RRGGBB` format. - Avoid N+1 query patterns when assembling a Wave dashboard. Fetch the required Part, Item, Sub, Base, and Data ranges in batches and assemble the response hierarchy in the backend. ## Frontend API Contract @@ -311,7 +315,8 @@ When implementation is complete, report in Korean: - Return categories as objects containing `order`, `label`, and `chartVisible`, alongside complete survey value series. The frontend uses all category/value indexes for statistical tables and filters matching indexes only for chart rendering. Reject Excel imports when category labels, display orders, or chart-visibility flags differ between survey series in the same Item/Sub result group. - Expose each survey's stored color as `color` in both Wave-detail survey objects and Part-detail series objects so the frontend uses one server-managed color mapping. - Return the stored nullable `t_part_item_base.base_text` value unchanged as Part-detail `series[].baseText`; `baseCount` remains a separate numeric field. +- Return `series[].chartGapMode`; the frontend applies `NONE`, `ALL`, or `LAST_VISIBLE`, where the last mode uses the greatest visible `part_item_data_order`. - When importing `part_item_data_value`, round to scale 10 with `RoundingMode.HALF_UP` before validating and storing it as `DECIMAL(14,10)`. Reject only values that still exceed precision 14 after rounding. - When `part_item_comment` is blank in Excel, store an empty string rather than `NULL` because the database column is required. Preserve the existing `NULL` semantics of other optional Excel fields. -- Manage chart types as code enums. The initial supported type is `BAR`; Excel accepts its label `bar` case-insensitively, the database stores code `BAR`, and frontend responses return code `BAR`. Reject unsupported labels during Excel validation. +- Manage chart types as code enums in `t_part_item_chart`. The initial supported type is `BAR`; Excel accepts its label `bar` case-insensitively, the database stores code `BAR`, and Part-detail series responses return code `BAR`. Reject unsupported labels during Excel validation. - Build file download URLs in the backend from the configured file resource path and the stored file metadata. Do not require the frontend to construct filesystem paths. diff --git a/src/main/java/com/kri/epolicy/dash/back/common/enums/ChartGapMode.java b/src/main/java/com/kri/epolicy/dash/back/common/enums/ChartGapMode.java new file mode 100644 index 0000000..aeb7403 --- /dev/null +++ b/src/main/java/com/kri/epolicy/dash/back/common/enums/ChartGapMode.java @@ -0,0 +1,19 @@ +package com.kri.epolicy.dash.back.common.enums; + +import java.util.Arrays; + +public enum ChartGapMode { + NONE, + ALL, + LAST_VISIBLE; + + public static ChartGapMode fromCodeOrDefault(String code) { + if (code == null) { + return NONE; + } + return Arrays.stream(values()) + .filter(mode -> mode.name().equalsIgnoreCase(code.trim())) + .findFirst() + .orElse(NONE); + } +} diff --git a/src/main/java/com/kri/epolicy/dash/back/common/enums/ChartHighlightMode.java b/src/main/java/com/kri/epolicy/dash/back/common/enums/ChartHighlightMode.java new file mode 100644 index 0000000..4a716e4 --- /dev/null +++ b/src/main/java/com/kri/epolicy/dash/back/common/enums/ChartHighlightMode.java @@ -0,0 +1,16 @@ +package com.kri.epolicy.dash.back.common.enums; + +import java.util.Arrays; + +public enum ChartHighlightMode { + MAX_VALUE, + LAST_VISIBLE, + SPECIFIED; + + public static ChartHighlightMode fromCode(String code) { + return Arrays.stream(values()) + .filter(mode -> mode.name().equalsIgnoreCase(code)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("지원하지 않는 차트 강조 모드입니다: " + code)); + } +} diff --git a/src/main/java/com/kri/epolicy/dash/back/controller/ExcelController.java b/src/main/java/com/kri/epolicy/dash/back/controller/ExcelController.java index 6ead28a..24e7c3d 100644 --- a/src/main/java/com/kri/epolicy/dash/back/controller/ExcelController.java +++ b/src/main/java/com/kri/epolicy/dash/back/controller/ExcelController.java @@ -1,7 +1,10 @@ package com.kri.epolicy.dash.back.controller; import com.kri.epolicy.dash.back.dto.response.ExcelImportResponse; +import com.kri.epolicy.dash.back.dto.response.ExcelResetResponse; +import com.kri.epolicy.dash.back.service.ExcelExportService; import com.kri.epolicy.dash.back.service.ExcelImportService; +import com.kri.epolicy.dash.back.service.ExcelResetService; import com.kri.epolicy.dash.back.service.ExcelTemplateService; import java.nio.charset.StandardCharsets; import lombok.RequiredArgsConstructor; @@ -10,6 +13,8 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestPart; @@ -23,6 +28,8 @@ public class ExcelController { private final ExcelImportService excelImportService; private final ExcelTemplateService excelTemplateService; + private final ExcelExportService excelExportService; + private final ExcelResetService excelResetService; @PostMapping(value = "/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ExcelImportResponse importExcel(@RequestPart("file") MultipartFile file) { @@ -39,4 +46,23 @@ public class ExcelController { .contentType(MediaType.parseMediaType(ExcelTemplateService.EXCEL_CONTENT_TYPE)) .body(excelTemplateService.createTemplate()); } + + @GetMapping( + value = "/waves/{waveCd}/export", + produces = ExcelTemplateService.EXCEL_CONTENT_TYPE + ) + public ResponseEntity exportWave(@PathVariable Short waveCd) { + ContentDisposition disposition = ContentDisposition.attachment() + .filename("epolicy-wave-" + waveCd + ".xlsx", StandardCharsets.UTF_8) + .build(); + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_DISPOSITION, disposition.toString()) + .contentType(MediaType.parseMediaType(ExcelTemplateService.EXCEL_CONTENT_TYPE)) + .body(excelExportService.exportWave(waveCd)); + } + + @DeleteMapping("/waves/{waveCd}") + public ExcelResetResponse resetWave(@PathVariable Short waveCd) { + return excelResetService.resetWave(waveCd); + } } diff --git a/src/main/java/com/kri/epolicy/dash/back/dto/excel/ExcelTemplateRows.java b/src/main/java/com/kri/epolicy/dash/back/dto/excel/ExcelTemplateRows.java index 2020a3a..4e21f8e 100644 --- a/src/main/java/com/kri/epolicy/dash/back/dto/excel/ExcelTemplateRows.java +++ b/src/main/java/com/kri/epolicy/dash/back/dto/excel/ExcelTemplateRows.java @@ -1,7 +1,9 @@ package com.kri.epolicy.dash.back.dto.excel; import com.kri.common.feature.excel.ExcelColumn; +import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; public final class ExcelTemplateRows { @@ -13,12 +15,16 @@ public final class ExcelTemplateRows { public static final String PART_ITEM_SHEET = "t_part_item"; public static final String PART_ITEM_SUB_SHEET = "t_part_item_sub"; public static final String PART_ITEM_BASE_SHEET = "t_part_item_base"; + public static final String PART_ITEM_CHART_SHEET = "t_part_item_chart"; + public static final String PART_ITEM_CHART_HIGHLIGHT_SHEET = "t_part_item_chart_highlight"; public static final String PART_ITEM_DATA_SHEET = "t_part_item_data"; private ExcelTemplateRows() { } @Getter + @NoArgsConstructor + @AllArgsConstructor public static final class Wave { @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "year", order = 1) private String year; @@ -28,6 +34,8 @@ public final class ExcelTemplateRows { } @Getter + @NoArgsConstructor + @AllArgsConstructor public static final class WaveInfo { @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "wave_info_order", order = 1) private String waveInfoOrder; @@ -36,6 +44,8 @@ public final class ExcelTemplateRows { } @Getter + @NoArgsConstructor + @AllArgsConstructor public static final class Survey { @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "survey_cd", order = 1) private String surveyCd; @@ -46,6 +56,8 @@ public final class ExcelTemplateRows { } @Getter + @NoArgsConstructor + @AllArgsConstructor public static final class SurveyItem { @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "survey_cd", order = 1) private String surveyCd; @@ -55,6 +67,8 @@ public final class ExcelTemplateRows { } @Getter + @NoArgsConstructor + @AllArgsConstructor public static final class Part { @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "part_cd", order = 1) private String partCd; @@ -63,26 +77,32 @@ public final class ExcelTemplateRows { } @Getter + @NoArgsConstructor + @AllArgsConstructor public static final class PartItem { @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "part_cd", order = 1) private String partCd; @ExcelColumn(header = "part_item_cd", order = 2) private String partItemCd; @ExcelColumn(header = "part_item_order", order = 3) private String partItemOrder; @ExcelColumn(header = "part_item_title", order = 4) private String partItemTitle; - @ExcelColumn(header = "chart_type (bar)", order = 5) private String chartType; - @ExcelColumn(header = "part_item_comment", order = 6) private String partItemComment; + @ExcelColumn(header = "part_item_comment", order = 5) private String partItemComment; } @Getter + @NoArgsConstructor + @AllArgsConstructor public static final class PartItemSub { @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "part_cd", order = 1) private String partCd; @ExcelColumn(header = "part_item_cd", order = 2) private String partItemCd; @ExcelColumn(header = "part_item_sub_cd", order = 3) private String partItemSubCd; @ExcelColumn(header = "part_item_sub_title", order = 4) private String partItemSubTitle; + @ExcelColumn(header = "part_item_sub_comment", order = 5) private String partItemSubComment; } @Getter + @NoArgsConstructor + @AllArgsConstructor public static final class PartItemBase { @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "part_cd", order = 1) private String partCd; @@ -94,6 +114,8 @@ public final class ExcelTemplateRows { } @Getter + @NoArgsConstructor + @AllArgsConstructor public static final class PartItemData { @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "part_cd", order = 1) private String partCd; @@ -105,4 +127,37 @@ public final class ExcelTemplateRows { @ExcelColumn(header = "part_item_data_value", order = 7) private String partItemDataValue; @ExcelColumn(header = "is_chart_visible (1, 0)", order = 8) private String isChartVisible; } + + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static final class PartItemChart { + @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; + @ExcelColumn(header = "part_cd", order = 1) private String partCd; + @ExcelColumn(header = "part_item_cd", order = 2) private String partItemCd; + @ExcelColumn(header = "survey_cd", order = 3) private String surveyCd; + @ExcelColumn(header = "part_item_sub_cd", order = 4) private String partItemSubCd; + @ExcelColumn(header = "chart_type (bar)", order = 5) private String chartType; + @ExcelColumn(header = "chart_color", order = 6) private String chartColor; + @ExcelColumn(header = "chart_gap_mode (NONE, ALL, LAST_VISIBLE)", order = 7) + private String chartGapMode; + } + + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static final class PartItemChartHighlight { + @ExcelColumn(header = "wave_cd", order = 0) private String waveCd; + @ExcelColumn(header = "part_cd", order = 1) private String partCd; + @ExcelColumn(header = "part_item_cd", order = 2) private String partItemCd; + @ExcelColumn(header = "survey_cd", order = 3) private String surveyCd; + @ExcelColumn(header = "part_item_sub_cd", order = 4) private String partItemSubCd; + @ExcelColumn( + header = "chart_highlight_mode (MAX_VALUE, LAST_VISIBLE, SPECIFIED)", order = 5) + private String chartHighlightMode; + @ExcelColumn(header = "chart_highlight_value", order = 6) + private String chartHighlightValue; + @ExcelColumn(header = "chart_highlight_color", order = 7) + private String chartHighlightColor; + } } diff --git a/src/main/java/com/kri/epolicy/dash/back/dto/excel/ExcelWorkbookData.java b/src/main/java/com/kri/epolicy/dash/back/dto/excel/ExcelWorkbookData.java new file mode 100644 index 0000000..7dd7289 --- /dev/null +++ b/src/main/java/com/kri/epolicy/dash/back/dto/excel/ExcelWorkbookData.java @@ -0,0 +1,24 @@ +package com.kri.epolicy.dash.back.dto.excel; + +import java.util.List; + +public record ExcelWorkbookData( + List waves, + List waveInfos, + List surveys, + List surveyItems, + List parts, + List partItems, + List partItemSubs, + List partItemBases, + List partItemCharts, + List partItemChartHighlights, + List partItemData +) { + + public static ExcelWorkbookData empty() { + return new ExcelWorkbookData( + List.of(), List.of(), List.of(), List.of(), List.of(), List.of(), + List.of(), List.of(), List.of(), List.of(), List.of()); + } +} diff --git a/src/main/java/com/kri/epolicy/dash/back/dto/request/ExcelData.java b/src/main/java/com/kri/epolicy/dash/back/dto/request/ExcelData.java index e10e36e..2878de7 100644 --- a/src/main/java/com/kri/epolicy/dash/back/dto/request/ExcelData.java +++ b/src/main/java/com/kri/epolicy/dash/back/dto/request/ExcelData.java @@ -1,6 +1,7 @@ package com.kri.epolicy.dash.back.dto.request; import com.kri.epolicy.dash.back.common.enums.ChartType; +import com.kri.epolicy.dash.back.common.enums.ChartGapMode; import java.math.BigDecimal; import java.util.List; @@ -13,6 +14,8 @@ public record ExcelData( List partItems, List partItemSubs, List partItemBases, + List partItemCharts, + List partItemChartHighlights, List partItemData ) { @@ -66,7 +69,6 @@ public record ExcelData( Short partItemCd, Short partItemOrder, String partItemTitle, - ChartType chartType, String partItemComment ) { } @@ -76,7 +78,8 @@ public record ExcelData( Short partCd, Short partItemCd, Short partItemSubCd, - String partItemSubTitle + String partItemSubTitle, + String partItemSubComment ) { } @@ -103,4 +106,28 @@ public record ExcelData( Boolean isChartVisible ) { } + + public record PartItemChartRow( + Short waveCd, + Short partCd, + Short partItemCd, + Short surveyCd, + Short partItemSubCd, + ChartType chartType, + String chartColor, + ChartGapMode chartGapMode + ) { + } + + public record PartItemChartHighlightRow( + Short waveCd, + Short partCd, + Short partItemCd, + Short surveyCd, + Short partItemSubCd, + String chartHighlightMode, + String chartHighlightValue, + String chartHighlightColor + ) { + } } diff --git a/src/main/java/com/kri/epolicy/dash/back/dto/response/ExcelImportResponse.java b/src/main/java/com/kri/epolicy/dash/back/dto/response/ExcelImportResponse.java index c56e7c1..65cea0f 100644 --- a/src/main/java/com/kri/epolicy/dash/back/dto/response/ExcelImportResponse.java +++ b/src/main/java/com/kri/epolicy/dash/back/dto/response/ExcelImportResponse.java @@ -9,6 +9,8 @@ public record ExcelImportResponse( int partItemCount, int partItemSubCount, int partItemBaseCount, + int partItemChartCount, + int partItemChartHighlightCount, int partItemDataCount ) { } diff --git a/src/main/java/com/kri/epolicy/dash/back/dto/response/ExcelResetResponse.java b/src/main/java/com/kri/epolicy/dash/back/dto/response/ExcelResetResponse.java new file mode 100644 index 0000000..a4a7dc7 --- /dev/null +++ b/src/main/java/com/kri/epolicy/dash/back/dto/response/ExcelResetResponse.java @@ -0,0 +1,17 @@ +package com.kri.epolicy.dash.back.dto.response; + +public record ExcelResetResponse( + Short waveCd, + int waveCount, + int waveInfoCount, + int surveyCount, + int surveyItemCount, + int partCount, + int partItemCount, + int partItemSubCount, + int partItemBaseCount, + int partItemChartCount, + int partItemChartHighlightCount, + int partItemDataCount +) { +} diff --git a/src/main/java/com/kri/epolicy/dash/back/dto/response/PartDetailResponse.java b/src/main/java/com/kri/epolicy/dash/back/dto/response/PartDetailResponse.java index 2abb096..e7cc5a1 100644 --- a/src/main/java/com/kri/epolicy/dash/back/dto/response/PartDetailResponse.java +++ b/src/main/java/com/kri/epolicy/dash/back/dto/response/PartDetailResponse.java @@ -14,7 +14,6 @@ public record PartDetailResponse( Short partItemCd, Short order, String title, - String chartType, String comment, Audience audience, List resultGroups @@ -38,13 +37,22 @@ public record PartDetailResponse( ) { } - public record SubItem(Short partItemSubCd, String title) { + public record SubItem( + Short partItemSubCd, + String title, + String partItemSubComment + ) { } public record Series( Short surveyCd, String label, + String chartType, String color, + String chartGapMode, + String chartHighlightMode, + String chartHighlightValue, + String chartHighlightColor, Integer baseCount, String baseText, List values diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemChartEntity.java b/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemChartEntity.java new file mode 100644 index 0000000..24f8698 --- /dev/null +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemChartEntity.java @@ -0,0 +1,62 @@ +package com.kri.epolicy.dash.back.persistence.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.ColumnDefault; + +@Getter +@Setter +@Entity +@Table(name = "t_part_item_chart") +public class TPartItemChartEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "part_item_chart_idx", nullable = false) + private Integer id; + + @NotNull + @Column(name = "wave_cd", nullable = false) + private Short waveCd; + + @NotNull + @Column(name = "part_cd", nullable = false) + private Short partCd; + + @NotNull + @Column(name = "part_item_cd", nullable = false) + private Short partItemCd; + + @NotNull + @Column(name = "survey_cd", nullable = false) + private Short surveyCd; + + @Column(name = "part_item_sub_cd") + private Short partItemSubCd; + + @Size(max = 32) + @NotNull + @ColumnDefault("'BAR'") + @Column(name = "chart_type", nullable = false, length = 32) + private String chartType; + + @Size(max = 8) + @Column(name = "chart_color", length = 8) + private String chartColor; + + @Size(max = 32) + @NotNull + @ColumnDefault("'NONE'") + @Column(name = "chart_gap_mode", nullable = false, length = 32) + private String chartGapMode; + + +} diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemChartHighlightEntity.java b/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemChartHighlightEntity.java new file mode 100644 index 0000000..4aa7336 --- /dev/null +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemChartHighlightEntity.java @@ -0,0 +1,59 @@ +package com.kri.epolicy.dash.back.persistence.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@Entity +@Table(name = "t_part_item_chart_highlight") +public class TPartItemChartHighlightEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "chart_highlight_idx", nullable = false) + private Integer id; + + @NotNull + @Column(name = "wave_cd", nullable = false) + private Short waveCd; + + @NotNull + @Column(name = "part_cd", nullable = false) + private Short partCd; + + @NotNull + @Column(name = "part_item_cd", nullable = false) + private Short partItemCd; + + @NotNull + @Column(name = "survey_cd", nullable = false) + private Short surveyCd; + + @Column(name = "part_item_sub_cd") + private Short partItemSubCd; + + @Size(max = 32) + @NotNull + @Column(name = "chart_highlight_mode", nullable = false, length = 32) + private String chartHighlightMode; + + @Size(max = 32) + @Column(name = "chart_highlight_value", length = 32) + private String chartHighlightValue; + + @Size(max = 8) + @NotNull + @Column(name = "chart_highlight_color", nullable = false, length = 8) + private String chartHighlightColor; + + +} \ No newline at end of file diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemEntity.java b/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemEntity.java index 84e82b9..9cb428a 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemEntity.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemEntity.java @@ -1,12 +1,9 @@ package com.kri.epolicy.dash.back.persistence.entity; import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemEntityId; -import com.kri.epolicy.dash.back.common.enums.ChartType; -import com.kri.epolicy.dash.back.persistence.converter.ChartTypeConverter; import jakarta.persistence.Column; import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; -import jakarta.persistence.Convert; import jakarta.persistence.Lob; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; @@ -32,11 +29,6 @@ public class TPartItemEntity { @Column(name = "part_item_title", nullable = false, length = 128) private String partItemTitle; - @NotNull - @Convert(converter = ChartTypeConverter.class) - @Column(name = "chart_type", nullable = false, length = 32) - private ChartType chartType; - @NotNull @Lob @Column(name = "part_item_comment", nullable = false) diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemSubEntity.java b/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemSubEntity.java index c5a87dc..dd83a69 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemSubEntity.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/entity/TPartItemSubEntity.java @@ -4,6 +4,7 @@ import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemSubEntityId; import jakarta.persistence.Column; import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; +import jakarta.persistence.Lob; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; @@ -24,5 +25,9 @@ public class TPartItemSubEntity { @Column(name = "part_item_sub_title", nullable = false, length = 128) private String partItemSubTitle; + @Lob + @Column(name = "part_item_sub_comment") + private String partItemSubComment; -} \ No newline at end of file + +} diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemBaseRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemBaseRepository.java index 59ec459..de11b4f 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemBaseRepository.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemBaseRepository.java @@ -4,10 +4,17 @@ import com.kri.epolicy.dash.back.persistence.entity.TPartItemBaseEntity; import java.util.Collection; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface PartItemBaseRepository extends JpaRepository { List findByWaveCdAndPartCd(Short waveCd, Short partCd); List findByWaveCdIn(Collection waveCodes); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TPartItemBaseEntity e where e.waveCd = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); } diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemChartHighlightRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemChartHighlightRepository.java new file mode 100644 index 0000000..74d4b07 --- /dev/null +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemChartHighlightRepository.java @@ -0,0 +1,21 @@ +package com.kri.epolicy.dash.back.persistence.repository; + +import com.kri.epolicy.dash.back.persistence.entity.TPartItemChartHighlightEntity; +import java.util.Collection; +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface PartItemChartHighlightRepository + extends JpaRepository { + + List findByWaveCdAndPartCd(Short waveCd, Short partCd); + + List findByWaveCdIn(Collection waveCodes); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TPartItemChartHighlightEntity e where e.waveCd = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); +} diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemChartRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemChartRepository.java new file mode 100644 index 0000000..cf25a47 --- /dev/null +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemChartRepository.java @@ -0,0 +1,20 @@ +package com.kri.epolicy.dash.back.persistence.repository; + +import com.kri.epolicy.dash.back.persistence.entity.TPartItemChartEntity; +import java.util.Collection; +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface PartItemChartRepository extends JpaRepository { + + List findByWaveCdAndPartCd(Short waveCd, Short partCd); + + List findByWaveCdIn(Collection waveCodes); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TPartItemChartEntity e where e.waveCd = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); +} diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemDataRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemDataRepository.java index 7f77fcc..e4e2af2 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemDataRepository.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemDataRepository.java @@ -4,6 +4,9 @@ import com.kri.epolicy.dash.back.persistence.entity.TPartItemDataEntity; import java.util.Collection; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface PartItemDataRepository extends JpaRepository { @@ -13,4 +16,8 @@ public interface PartItemDataRepository extends JpaRepository findByWaveCdIn(Collection waveCodes); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TPartItemDataEntity e where e.waveCd = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); } diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemRepository.java index 16a3817..e3aee3c 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemRepository.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemRepository.java @@ -4,6 +4,9 @@ import com.kri.epolicy.dash.back.persistence.entity.TPartItemEntity; import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemEntityId; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface PartItemRepository extends JpaRepository { @@ -14,4 +17,8 @@ public interface PartItemRepository Short waveCd, Short partCd ); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TPartItemEntity e where e.id.waveCd = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); } diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemSubRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemSubRepository.java index ef9213e..f9ad519 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemSubRepository.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartItemSubRepository.java @@ -4,12 +4,21 @@ import com.kri.epolicy.dash.back.persistence.entity.TPartItemSubEntity; import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemSubEntityId; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface PartItemSubRepository extends JpaRepository { + List findByIdWaveCd(Short waveCd); + List findByIdWaveCdAndIdPartCdOrderByIdPartItemCdAscIdPartItemSubCdAsc( Short waveCd, Short partCd ); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TPartItemSubEntity e where e.id.waveCd = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); } diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartRepository.java index 7282fda..a689979 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartRepository.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/PartRepository.java @@ -4,8 +4,15 @@ import com.kri.epolicy.dash.back.persistence.entity.TPartEntity; import com.kri.epolicy.dash.back.persistence.entity.id.TPartEntityId; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface PartRepository extends JpaRepository { List findByIdWaveCdOrderByPartOrderAsc(Short waveCd); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TPartEntity e where e.id.waveCd = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); } diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/SurveyItemRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/SurveyItemRepository.java index 6187618..4d08772 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/SurveyItemRepository.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/SurveyItemRepository.java @@ -4,6 +4,9 @@ import com.kri.epolicy.dash.back.persistence.entity.TSurveyItemEntity; import java.util.Collection; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface SurveyItemRepository extends JpaRepository { @@ -11,4 +14,8 @@ public interface SurveyItemRepository List findByWaveCdOrderBySurveyItemOrderAsc(Short waveCd); List findByWaveCdIn(Collection waveCodes); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TSurveyItemEntity e where e.waveCd = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); } diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/SurveyRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/SurveyRepository.java index 1ee3a54..7f39909 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/SurveyRepository.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/SurveyRepository.java @@ -4,8 +4,15 @@ import com.kri.epolicy.dash.back.persistence.entity.TSurveyEntity; import com.kri.epolicy.dash.back.persistence.entity.id.TSurveyEntityId; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface SurveyRepository extends JpaRepository { List findByIdWaveCdOrderBySurveyOrderAsc(Short waveCd); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TSurveyEntity e where e.id.waveCd = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); } diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/WaveInfoRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/WaveInfoRepository.java index 4304c15..4b5f616 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/WaveInfoRepository.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/WaveInfoRepository.java @@ -4,10 +4,17 @@ import com.kri.epolicy.dash.back.persistence.entity.TWaveInfoEntity; import java.util.Collection; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface WaveInfoRepository extends JpaRepository { List findByWaveCdOrderByWaveInfoOrderAsc(Short waveCd); List findByWaveCdIn(Collection waveCodes); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TWaveInfoEntity e where e.waveCd = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); } diff --git a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/WaveRepository.java b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/WaveRepository.java index 193ad34..6ac050a 100644 --- a/src/main/java/com/kri/epolicy/dash/back/persistence/repository/WaveRepository.java +++ b/src/main/java/com/kri/epolicy/dash/back/persistence/repository/WaveRepository.java @@ -3,8 +3,15 @@ package com.kri.epolicy.dash.back.persistence.repository; import com.kri.epolicy.dash.back.persistence.entity.TWaveEntity; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface WaveRepository extends JpaRepository { List findAllByOrderByYearDescWaveDesc(); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete from TWaveEntity e where e.id = :waveCd") + int deleteForResetByWaveCd(@Param("waveCd") Short waveCd); } diff --git a/src/main/java/com/kri/epolicy/dash/back/service/ExcelExportService.java b/src/main/java/com/kri/epolicy/dash/back/service/ExcelExportService.java new file mode 100644 index 0000000..54e4536 --- /dev/null +++ b/src/main/java/com/kri/epolicy/dash/back/service/ExcelExportService.java @@ -0,0 +1,187 @@ +package com.kri.epolicy.dash.back.service; + +import com.kri.epolicy.dash.back.common.enums.ChartType; +import com.kri.epolicy.dash.back.common.enums.ChartGapMode; +import com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows; +import com.kri.epolicy.dash.back.dto.excel.ExcelWorkbookData; +import com.kri.epolicy.dash.back.persistence.entity.TPartItemBaseEntity; +import com.kri.epolicy.dash.back.persistence.entity.TPartItemChartEntity; +import com.kri.epolicy.dash.back.persistence.entity.TPartItemChartHighlightEntity; +import com.kri.epolicy.dash.back.persistence.entity.TPartItemDataEntity; +import com.kri.epolicy.dash.back.persistence.repository.PartItemBaseRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemChartHighlightRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemChartRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemDataRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemSubRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartRepository; +import com.kri.epolicy.dash.back.persistence.repository.SurveyItemRepository; +import com.kri.epolicy.dash.back.persistence.repository.SurveyRepository; +import com.kri.epolicy.dash.back.persistence.repository.WaveInfoRepository; +import com.kri.epolicy.dash.back.persistence.repository.WaveRepository; +import java.util.Comparator; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class ExcelExportService { + + private static final Comparator NULLABLE_SHORT = + Comparator.nullsFirst(Comparator.naturalOrder()); + + private final ExcelTemplateService excelTemplateService; + private final WaveRepository waveRepository; + private final WaveInfoRepository waveInfoRepository; + private final SurveyRepository surveyRepository; + private final SurveyItemRepository surveyItemRepository; + private final PartRepository partRepository; + private final PartItemRepository partItemRepository; + private final PartItemSubRepository partItemSubRepository; + private final PartItemBaseRepository partItemBaseRepository; + private final PartItemChartRepository partItemChartRepository; + private final PartItemChartHighlightRepository partItemChartHighlightRepository; + private final PartItemDataRepository partItemDataRepository; + + public byte[] exportWave(Short waveCd) { + var wave = waveRepository.findById(waveCd); + if (wave.isEmpty()) { + return excelTemplateService.createTemplate(); + } + List waveCodes = List.of(waveCd); + List bases = partItemBaseRepository.findByWaveCdIn(waveCodes).stream() + .sorted(resultSeriesComparator()) + .toList(); + List charts = partItemChartRepository.findByWaveCdIn(waveCodes).stream() + .sorted(resultSeriesComparatorForChart()) + .toList(); + List highlights = partItemChartHighlightRepository + .findByWaveCdIn(waveCodes).stream() + .sorted(resultSeriesComparatorForHighlight()) + .toList(); + List itemData = partItemDataRepository.findByWaveCdIn(waveCodes).stream() + .sorted(resultDataComparator()) + .toList(); + + ExcelWorkbookData data = new ExcelWorkbookData( + wave.stream() + .map(entity -> new ExcelTemplateRows.Wave( + value(entity.getId()), value(entity.getYear()), value(entity.getWave()), + entity.getLabel(), booleanValue(entity.getIsOpen()))) + .toList(), + waveInfoRepository.findByWaveCdOrderByWaveInfoOrderAsc(waveCd).stream() + .map(info -> new ExcelTemplateRows.WaveInfo( + value(info.getWaveCd()), value(info.getWaveInfoOrder()), + info.getWaveInfoTitle(), info.getWaveInfoContent())) + .toList(), + surveyRepository.findByIdWaveCdOrderBySurveyOrderAsc(waveCd).stream() + .map(survey -> new ExcelTemplateRows.Survey( + value(survey.getId().getWaveCd()), value(survey.getId().getSurveyCd()), + value(survey.getSurveyOrder()), survey.getSurveyTitle(), survey.getSurveyAlias(), + survey.getSurveyColor())) + .toList(), + surveyItemRepository.findByWaveCdOrderBySurveyItemOrderAsc(waveCd).stream() + .sorted(Comparator.comparing( + com.kri.epolicy.dash.back.persistence.entity.TSurveyItemEntity::getSurveyCd) + .thenComparing( + com.kri.epolicy.dash.back.persistence.entity.TSurveyItemEntity + ::getSurveyItemOrder)) + .map(item -> new ExcelTemplateRows.SurveyItem( + value(item.getWaveCd()), value(item.getSurveyCd()), + value(item.getSurveyItemOrder()), item.getSurveyItemTitle(), + item.getSurveyItemContent())) + .toList(), + partRepository.findByIdWaveCdOrderByPartOrderAsc(waveCd).stream() + .map(part -> new ExcelTemplateRows.Part( + value(part.getId().getWaveCd()), value(part.getId().getPartCd()), + value(part.getPartOrder()), part.getPartTitle())) + .toList(), + partItemRepository.findByIdWaveCdOrderByPartItemOrderAsc(waveCd).stream() + .sorted(Comparator.comparing( + (com.kri.epolicy.dash.back.persistence.entity.TPartItemEntity item) -> + item.getId().getPartCd()) + .thenComparing(item -> item.getPartItemOrder())) + .map(item -> new ExcelTemplateRows.PartItem( + value(item.getId().getWaveCd()), value(item.getId().getPartCd()), + value(item.getId().getPartItemCd()), value(item.getPartItemOrder()), + item.getPartItemTitle(), item.getPartItemComment())) + .toList(), + partItemSubRepository.findByIdWaveCd(waveCd).stream() + .sorted(Comparator.comparing( + (com.kri.epolicy.dash.back.persistence.entity.TPartItemSubEntity sub) -> + sub.getId().getPartCd()) + .thenComparing(sub -> sub.getId().getPartItemCd()) + .thenComparing(sub -> sub.getId().getPartItemSubCd())) + .map(sub -> new ExcelTemplateRows.PartItemSub( + value(sub.getId().getWaveCd()), value(sub.getId().getPartCd()), + value(sub.getId().getPartItemCd()), value(sub.getId().getPartItemSubCd()), + sub.getPartItemSubTitle(), sub.getPartItemSubComment())) + .toList(), + bases.stream().map(base -> new ExcelTemplateRows.PartItemBase( + value(base.getWaveCd()), value(base.getPartCd()), value(base.getPartItemCd()), + value(base.getSurveyCd()), value(base.getPartItemSubCd()), + value(base.getBaseCount()), base.getBaseText())).toList(), + charts.stream().map(chart -> new ExcelTemplateRows.PartItemChart( + value(chart.getWaveCd()), value(chart.getPartCd()), value(chart.getPartItemCd()), + value(chart.getSurveyCd()), value(chart.getPartItemSubCd()), + chartTypeLabel(chart.getChartType()), chart.getChartColor(), + ChartGapMode.fromCodeOrDefault(chart.getChartGapMode()).name())).toList(), + highlights.stream().map(highlight -> new ExcelTemplateRows.PartItemChartHighlight( + value(highlight.getWaveCd()), value(highlight.getPartCd()), + value(highlight.getPartItemCd()), value(highlight.getSurveyCd()), + value(highlight.getPartItemSubCd()), highlight.getChartHighlightMode(), + highlight.getChartHighlightValue(), highlight.getChartHighlightColor())).toList(), + itemData.stream().map(item -> new ExcelTemplateRows.PartItemData( + value(item.getWaveCd()), value(item.getPartCd()), value(item.getPartItemCd()), + value(item.getSurveyCd()), value(item.getPartItemSubCd()), + value(item.getPartItemDataOrder()), item.getPartItemDataLabel(), + item.getPartItemDataValue().toPlainString(), booleanValue(item.getIsChartVisible()))) + .toList() + ); + return excelTemplateService.createWorkbook(data); + } + + private Comparator resultSeriesComparator() { + return Comparator.comparing(TPartItemBaseEntity::getPartCd) + .thenComparing(TPartItemBaseEntity::getPartItemCd) + .thenComparing(TPartItemBaseEntity::getSurveyCd) + .thenComparing(TPartItemBaseEntity::getPartItemSubCd, NULLABLE_SHORT); + } + + private Comparator resultSeriesComparatorForChart() { + return Comparator.comparing(TPartItemChartEntity::getPartCd) + .thenComparing(TPartItemChartEntity::getPartItemCd) + .thenComparing(TPartItemChartEntity::getSurveyCd) + .thenComparing(TPartItemChartEntity::getPartItemSubCd, NULLABLE_SHORT); + } + + private Comparator resultSeriesComparatorForHighlight() { + return Comparator.comparing(TPartItemChartHighlightEntity::getPartCd) + .thenComparing(TPartItemChartHighlightEntity::getPartItemCd) + .thenComparing(TPartItemChartHighlightEntity::getSurveyCd) + .thenComparing(TPartItemChartHighlightEntity::getPartItemSubCd, NULLABLE_SHORT); + } + + private Comparator resultDataComparator() { + return Comparator.comparing(TPartItemDataEntity::getPartCd) + .thenComparing(TPartItemDataEntity::getPartItemCd) + .thenComparing(TPartItemDataEntity::getSurveyCd) + .thenComparing(TPartItemDataEntity::getPartItemSubCd, NULLABLE_SHORT) + .thenComparing(TPartItemDataEntity::getPartItemDataOrder); + } + + private String chartTypeLabel(String code) { + return code == null ? ChartType.BAR.getLabel() : ChartType.fromCode(code).getLabel(); + } + + private String booleanValue(Boolean value) { + return Boolean.TRUE.equals(value) ? "1" : "0"; + } + + private String value(Object value) { + return value == null ? null : value.toString(); + } +} diff --git a/src/main/java/com/kri/epolicy/dash/back/service/ExcelImportService.java b/src/main/java/com/kri/epolicy/dash/back/service/ExcelImportService.java index 8fc0efe..8075e6f 100644 --- a/src/main/java/com/kri/epolicy/dash/back/service/ExcelImportService.java +++ b/src/main/java/com/kri/epolicy/dash/back/service/ExcelImportService.java @@ -4,6 +4,8 @@ import com.kri.epolicy.dash.back.dto.request.ExcelData; import com.kri.epolicy.dash.back.dto.response.ExcelImportResponse; import com.kri.epolicy.dash.back.persistence.entity.TPartEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartItemBaseEntity; +import com.kri.epolicy.dash.back.persistence.entity.TPartItemChartEntity; +import com.kri.epolicy.dash.back.persistence.entity.TPartItemChartHighlightEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartItemDataEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartItemEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartItemSubEntity; @@ -16,6 +18,8 @@ import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemEntityId; import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemSubEntityId; import com.kri.epolicy.dash.back.persistence.entity.id.TSurveyEntityId; import com.kri.epolicy.dash.back.persistence.repository.PartItemBaseRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemChartHighlightRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemChartRepository; import com.kri.epolicy.dash.back.persistence.repository.PartItemDataRepository; import com.kri.epolicy.dash.back.persistence.repository.PartItemRepository; import com.kri.epolicy.dash.back.persistence.repository.PartItemSubRepository; @@ -24,7 +28,6 @@ import com.kri.epolicy.dash.back.persistence.repository.SurveyItemRepository; import com.kri.epolicy.dash.back.persistence.repository.SurveyRepository; import com.kri.epolicy.dash.back.persistence.repository.WaveInfoRepository; import com.kri.epolicy.dash.back.persistence.repository.WaveRepository; -import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -37,6 +40,7 @@ import org.springframework.web.multipart.MultipartFile; public class ExcelImportService { private final ExcelImportValidator excelImportValidator; + private final ExcelResetService excelResetService; private final WaveRepository waveRepository; private final WaveInfoRepository waveInfoRepository; private final SurveyRepository surveyRepository; @@ -45,6 +49,8 @@ public class ExcelImportService { private final PartItemRepository partItemRepository; private final PartItemSubRepository partItemSubRepository; private final PartItemBaseRepository partItemBaseRepository; + private final PartItemChartRepository partItemChartRepository; + private final PartItemChartHighlightRepository partItemChartHighlightRepository; private final PartItemDataRepository partItemDataRepository; @Transactional @@ -53,32 +59,7 @@ public class ExcelImportService { Set waveCodes = data.waves().stream() .map(ExcelData.WaveRow::waveCd) .collect(Collectors.toSet()); - Map waveInfoIds = waveInfoRepository.findByWaveCdIn(waveCodes) - .stream().collect(Collectors.toMap( - entity -> new WaveInfoKey(entity.getWaveCd(), entity.getWaveInfoOrder()), - TWaveInfoEntity::getId, - firstValue())); - Map surveyItemIds = surveyItemRepository - .findByWaveCdIn(waveCodes).stream().collect(Collectors.toMap( - entity -> new SurveyItemKey( - entity.getWaveCd(), entity.getSurveyCd(), entity.getSurveyItemOrder()), - TSurveyItemEntity::getId, - firstValue())); - Map partItemBaseIds = partItemBaseRepository - .findByWaveCdIn(waveCodes).stream().collect(Collectors.toMap( - entity -> new ResultSeriesKey( - entity.getWaveCd(), entity.getPartCd(), entity.getPartItemCd(), - entity.getSurveyCd(), entity.getPartItemSubCd()), - TPartItemBaseEntity::getId, - firstValue())); - Map partItemDataIds = partItemDataRepository - .findByWaveCdIn(waveCodes).stream().collect(Collectors.toMap( - entity -> new ResultCategoryKey( - entity.getWaveCd(), entity.getPartCd(), entity.getPartItemCd(), - entity.getSurveyCd(), entity.getPartItemSubCd(), - entity.getPartItemDataOrder()), - TPartItemDataEntity::getId, - firstValue())); + excelResetService.resetWaves(waveCodes); waveRepository.saveAll(data.waves().stream().map(row -> { TWaveEntity entity = new TWaveEntity(); @@ -92,7 +73,6 @@ public class ExcelImportService { waveInfoRepository.saveAll(data.waveInfos().stream().map(row -> { TWaveInfoEntity entity = new TWaveInfoEntity(); - entity.setId(waveInfoIds.get(new WaveInfoKey(row.waveCd(), row.waveInfoOrder()))); entity.setWaveCd(row.waveCd()); entity.setWaveInfoOrder(row.waveInfoOrder()); entity.setWaveInfoTitle(row.waveInfoTitle()); @@ -112,8 +92,6 @@ public class ExcelImportService { surveyItemRepository.saveAll(data.surveyItems().stream().map(row -> { TSurveyItemEntity entity = new TSurveyItemEntity(); - entity.setId(surveyItemIds.get( - new SurveyItemKey(row.waveCd(), row.surveyCd(), row.surveyItemOrder()))); entity.setWaveCd(row.waveCd()); entity.setSurveyCd(row.surveyCd()); entity.setSurveyItemOrder(row.surveyItemOrder()); @@ -135,7 +113,6 @@ public class ExcelImportService { entity.setId(partItemId(row.waveCd(), row.partCd(), row.partItemCd())); entity.setPartItemOrder(row.partItemOrder()); entity.setPartItemTitle(row.partItemTitle()); - entity.setChartType(row.chartType()); entity.setPartItemComment(row.partItemComment()); return entity; }).toList()); @@ -145,13 +122,12 @@ public class ExcelImportService { entity.setId(partItemSubId( row.waveCd(), row.partCd(), row.partItemCd(), row.partItemSubCd())); entity.setPartItemSubTitle(row.partItemSubTitle()); + entity.setPartItemSubComment(row.partItemSubComment()); return entity; }).toList()); partItemBaseRepository.saveAll(data.partItemBases().stream().map(row -> { TPartItemBaseEntity entity = new TPartItemBaseEntity(); - entity.setId(partItemBaseIds.get(new ResultSeriesKey( - row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(), row.partItemSubCd()))); entity.setWaveCd(row.waveCd()); entity.setPartCd(row.partCd()); entity.setPartItemCd(row.partItemCd()); @@ -162,11 +138,34 @@ public class ExcelImportService { return entity; }).toList()); + partItemChartRepository.saveAll(data.partItemCharts().stream().map(row -> { + TPartItemChartEntity entity = new TPartItemChartEntity(); + entity.setWaveCd(row.waveCd()); + entity.setPartCd(row.partCd()); + entity.setPartItemCd(row.partItemCd()); + entity.setSurveyCd(row.surveyCd()); + entity.setPartItemSubCd(row.partItemSubCd()); + entity.setChartType(row.chartType().getCode()); + entity.setChartColor(row.chartColor()); + entity.setChartGapMode(row.chartGapMode().name()); + return entity; + }).toList()); + + partItemChartHighlightRepository.saveAll(data.partItemChartHighlights().stream().map(row -> { + TPartItemChartHighlightEntity entity = new TPartItemChartHighlightEntity(); + entity.setWaveCd(row.waveCd()); + entity.setPartCd(row.partCd()); + entity.setPartItemCd(row.partItemCd()); + entity.setSurveyCd(row.surveyCd()); + entity.setPartItemSubCd(row.partItemSubCd()); + entity.setChartHighlightMode(row.chartHighlightMode()); + entity.setChartHighlightValue(row.chartHighlightValue()); + entity.setChartHighlightColor(row.chartHighlightColor()); + return entity; + }).toList()); + partItemDataRepository.saveAll(data.partItemData().stream().map(row -> { TPartItemDataEntity entity = new TPartItemDataEntity(); - entity.setId(partItemDataIds.get(new ResultCategoryKey( - row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(), row.partItemSubCd(), - row.partItemDataOrder()))); entity.setWaveCd(row.waveCd()); entity.setPartCd(row.partCd()); entity.setPartItemCd(row.partItemCd()); @@ -188,6 +187,8 @@ public class ExcelImportService { data.partItems().size(), data.partItemSubs().size(), data.partItemBases().size(), + data.partItemCharts().size(), + data.partItemChartHighlights().size(), data.partItemData().size() ); } @@ -228,32 +229,4 @@ public class ExcelImportService { return id; } - private java.util.function.BinaryOperator firstValue() { - return (first, ignored) -> first; - } - - private record WaveInfoKey(Short waveCd, Short order) { - } - - private record SurveyItemKey(Short waveCd, Short surveyCd, Short order) { - } - - private record ResultSeriesKey( - Short waveCd, - Short partCd, - Short partItemCd, - Short surveyCd, - Short partItemSubCd - ) { - } - - private record ResultCategoryKey( - Short waveCd, - Short partCd, - Short partItemCd, - Short surveyCd, - Short partItemSubCd, - Short order - ) { - } } diff --git a/src/main/java/com/kri/epolicy/dash/back/service/ExcelImportValidator.java b/src/main/java/com/kri/epolicy/dash/back/service/ExcelImportValidator.java index 1b29739..814ae90 100644 --- a/src/main/java/com/kri/epolicy/dash/back/service/ExcelImportValidator.java +++ b/src/main/java/com/kri/epolicy/dash/back/service/ExcelImportValidator.java @@ -4,9 +4,13 @@ import com.kri.common.feature.excel.ExcelColumn; import com.kri.common.feature.excel.ExcelMapper; import com.kri.common.feature.web.BusinessException; import com.kri.epolicy.dash.back.common.enums.ChartType; +import com.kri.epolicy.dash.back.common.enums.ChartHighlightMode; +import com.kri.epolicy.dash.back.common.enums.ChartGapMode; import com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows; import com.kri.epolicy.dash.back.dto.request.ExcelData; import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemBaseRow; +import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemChartHighlightRow; +import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemChartRow; import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemDataRow; import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemRow; import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemSubRow; @@ -34,6 +38,7 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.regex.Pattern; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -46,6 +51,8 @@ import org.springframework.web.multipart.MultipartFile; public class ExcelImportValidator { private static final int HEADER_ROW_NUMBER = 1; + private static final Pattern COLOR_PATTERN = Pattern.compile("#[0-9A-Fa-f]{6}"); + private static final Pattern SPECIFIED_VALUE_PATTERN = Pattern.compile("\\d+(,\\d+)*"); public ExcelData validateAndConvert(MultipartFile file) { validateFile(file); @@ -71,17 +78,29 @@ public class ExcelImportValidator { row.getPartTitle()), this::toPartRow), readRows(workbook, ExcelTemplateRows.PART_ITEM_SHEET, ExcelTemplateRows.PartItem.class, row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(), - row.getPartItemOrder(), row.getPartItemTitle(), row.getChartType(), - row.getPartItemComment()), this::toPartItemRow), + row.getPartItemOrder(), row.getPartItemTitle(), row.getPartItemComment()), + this::toPartItemRow), readRows(workbook, ExcelTemplateRows.PART_ITEM_SUB_SHEET, ExcelTemplateRows.PartItemSub.class, row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(), - row.getPartItemSubCd(), row.getPartItemSubTitle()), this::toPartItemSubRow), + row.getPartItemSubCd(), row.getPartItemSubTitle(), + row.getPartItemSubComment()), this::toPartItemSubRow), readRows(workbook, ExcelTemplateRows.PART_ITEM_BASE_SHEET, ExcelTemplateRows.PartItemBase.class, row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(), row.getSurveyCd(), row.getPartItemSubCd(), row.getBaseCount(), - row.getBaseText()), this::toPartItemBaseRow), + row.getBaseText()), this::toPartItemBaseRow), + readRows(workbook, ExcelTemplateRows.PART_ITEM_CHART_SHEET, + ExcelTemplateRows.PartItemChart.class, + row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(), + row.getSurveyCd(), row.getPartItemSubCd(), row.getChartType(), + row.getChartColor(), row.getChartGapMode()), this::toPartItemChartRow), + readRows(workbook, ExcelTemplateRows.PART_ITEM_CHART_HIGHLIGHT_SHEET, + ExcelTemplateRows.PartItemChartHighlight.class, + row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(), + row.getSurveyCd(), row.getPartItemSubCd(), row.getChartHighlightMode(), + row.getChartHighlightValue(), row.getChartHighlightColor()), + this::toPartItemChartHighlightRow), readRows(workbook, ExcelTemplateRows.PART_ITEM_DATA_SHEET, ExcelTemplateRows.PartItemData.class, row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(), @@ -190,7 +209,7 @@ public class ExcelImportValidator { requiredShort(row.getSurveyOrder(), "survey_order", context), requiredString(row.getSurveyTitle(), "survey_title", 128, context), requiredString(row.getSurveyAlias(), "survey_alias", 32, context), - requiredString(row.getSurveyColor(), "survey_color", 8, context) + requiredColor(row.getSurveyColor(), "survey_color", context) ); } @@ -223,7 +242,6 @@ public class ExcelImportValidator { requiredShort(row.getPartItemCd(), "part_item_cd", context), requiredShort(row.getPartItemOrder(), "part_item_order", context), requiredString(row.getPartItemTitle(), "part_item_title", 128, context), - requiredChartType(row.getChartType(), "chart_type", context), Objects.requireNonNullElse( optionalString(row.getPartItemComment(), "part_item_comment", null, context), "") ); @@ -238,7 +256,8 @@ public class ExcelImportValidator { requiredShort(row.getPartCd(), "part_cd", context), requiredShort(row.getPartItemCd(), "part_item_cd", context), requiredShort(row.getPartItemSubCd(), "part_item_sub_cd", context), - requiredString(row.getPartItemSubTitle(), "part_item_sub_title", 128, context) + requiredString(row.getPartItemSubTitle(), "part_item_sub_title", 128, context), + optionalString(row.getPartItemSubComment(), "part_item_sub_comment", null, context) ); } @@ -274,6 +293,43 @@ public class ExcelImportValidator { ); } + private PartItemChartRow toPartItemChartRow( + ExcelTemplateRows.PartItemChart row, + RowContext context + ) { + return new PartItemChartRow( + requiredShort(row.getWaveCd(), "wave_cd", context), + requiredShort(row.getPartCd(), "part_cd", context), + requiredShort(row.getPartItemCd(), "part_item_cd", context), + requiredShort(row.getSurveyCd(), "survey_cd", context), + optionalShort(row.getPartItemSubCd(), "part_item_sub_cd", context), + requiredChartType(row.getChartType(), "chart_type", context), + optionalColor(row.getChartColor(), "chart_color", context), + ChartGapMode.fromCodeOrDefault(normalized(row.getChartGapMode())) + ); + } + + private PartItemChartHighlightRow toPartItemChartHighlightRow( + ExcelTemplateRows.PartItemChartHighlight row, + RowContext context + ) { + ChartHighlightMode mode = requiredChartHighlightMode( + row.getChartHighlightMode(), "chart_highlight_mode", context); + String value = optionalString( + row.getChartHighlightValue(), "chart_highlight_value", 32, context); + validateHighlightValue(mode, value, context); + return new PartItemChartHighlightRow( + requiredShort(row.getWaveCd(), "wave_cd", context), + requiredShort(row.getPartCd(), "part_cd", context), + requiredShort(row.getPartItemCd(), "part_item_cd", context), + requiredShort(row.getSurveyCd(), "survey_cd", context), + optionalShort(row.getPartItemSubCd(), "part_item_sub_cd", context), + mode.name(), + value, + requiredColor(row.getChartHighlightColor(), "chart_highlight_color", context) + ); + } + private void validateRelationships(ExcelData data) { Set waveKeys = uniqueKeys( data.waves(), WaveRow::waveCd, ExcelTemplateRows.WAVE_SHEET); @@ -293,6 +349,10 @@ public class ExcelImportValidator { Set subKeys = uniqueKeys(data.partItemSubs(), row -> new SubKey(row.waveCd(), row.partCd(), row.partItemCd(), row.partItemSubCd()), ExcelTemplateRows.PART_ITEM_SUB_SHEET); + uniqueKeys(data.partItemCharts(), this::resultSeriesKey, + ExcelTemplateRows.PART_ITEM_CHART_SHEET); + uniqueKeys(data.partItemChartHighlights(), this::resultSeriesKey, + ExcelTemplateRows.PART_ITEM_CHART_HIGHLIGHT_SHEET); requireParents(data.waveInfos(), WaveInfoRow::waveCd, waveKeys, ExcelTemplateRows.WAVE_INFO_SHEET, "wave_cd"); @@ -323,10 +383,30 @@ public class ExcelImportValidator { row.partItemSubCd(), itemKeys, surveyKeys, subKeys, itemsWithSubs, ExcelTemplateRows.PART_ITEM_DATA_SHEET); } + for (PartItemChartRow row : data.partItemCharts()) { + validateResultRelationship(row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(), + row.partItemSubCd(), itemKeys, surveyKeys, subKeys, itemsWithSubs, + ExcelTemplateRows.PART_ITEM_CHART_SHEET); + } + for (PartItemChartHighlightRow row : data.partItemChartHighlights()) { + validateResultRelationship(row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(), + row.partItemSubCd(), itemKeys, surveyKeys, subKeys, itemsWithSubs, + ExcelTemplateRows.PART_ITEM_CHART_HIGHLIGHT_SHEET); + } validateResultBases(data.partItemBases(), data.partItemData()); validateCategoryConsistency(data.partItemData()); } + private ResultSeriesKey resultSeriesKey(PartItemChartRow row) { + return new ResultSeriesKey( + row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(), row.partItemSubCd()); + } + + private ResultSeriesKey resultSeriesKey(PartItemChartHighlightRow row) { + return new ResultSeriesKey( + row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(), row.partItemSubCd()); + } + private void validateResultBases(List bases, List data) { Set baseKeys = uniqueKeys(bases, row -> new ResultSeriesKey( @@ -400,7 +480,7 @@ public class ExcelImportValidator { "Sub가 있는 문항의 part_item_sub_cd는 필수입니다: " + itemKey); } if (!subKeys.contains(new SubKey(waveCd, partCd, partItemCd, partItemSubCd))) { - throw relationshipError(sheetName, "존재하지 않는 Sub를 참조합니다: " + partItemSubCd); + throw relationshipError(sheetName, "존재하지 않는 Sub를 참조합니다: " + partItemCd + "/" + partItemSubCd); } } else if (partItemSubCd != null) { throw relationshipError(sheetName, @@ -551,6 +631,56 @@ public class ExcelImportValidator { } } + private ChartHighlightMode requiredChartHighlightMode( + String rawValue, + String column, + RowContext context + ) { + String code = requiredRaw(rawValue, column, context); + try { + return ChartHighlightMode.fromCode(code); + } catch (IllegalArgumentException exception) { + throw cellError(context, column, + "MAX_VALUE, LAST_VISIBLE 또는 SPECIFIED여야 합니다."); + } + } + + private String requiredColor(String rawValue, String column, RowContext context) { + String color = requiredString(rawValue, column, 8, context); + validateColor(color, column, context); + return color; + } + + private String optionalColor(String rawValue, String column, RowContext context) { + String color = optionalString(rawValue, column, 8, context); + if (color != null) { + validateColor(color, column, context); + } + return color; + } + + private void validateColor(String color, String column, RowContext context) { + if (!COLOR_PATTERN.matcher(color).matches()) { + throw cellError(context, column, "#RRGGBB 형식이어야 합니다."); + } + } + + private void validateHighlightValue( + ChartHighlightMode mode, + String value, + RowContext context + ) { + if (mode == ChartHighlightMode.SPECIFIED) { + if (value == null || !SPECIFIED_VALUE_PATTERN.matcher(value).matches()) { + throw cellError(context, "chart_highlight_value", + "SPECIFIED 모드는 공백 없는 정수 목록이어야 합니다. 예: 1,3,5"); + } + } else if (value != null) { + throw cellError(context, "chart_highlight_value", + mode.name() + " 모드에서는 NULL이어야 합니다."); + } + } + private String requiredRaw(String rawValue, String column, RowContext context) { String value = normalized(rawValue); if (value == null) { diff --git a/src/main/java/com/kri/epolicy/dash/back/service/ExcelResetService.java b/src/main/java/com/kri/epolicy/dash/back/service/ExcelResetService.java new file mode 100644 index 0000000..3133dc4 --- /dev/null +++ b/src/main/java/com/kri/epolicy/dash/back/service/ExcelResetService.java @@ -0,0 +1,70 @@ +package com.kri.epolicy.dash.back.service; + +import com.kri.epolicy.dash.back.dto.response.ExcelResetResponse; +import com.kri.epolicy.dash.back.persistence.repository.PartItemBaseRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemChartHighlightRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemChartRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemDataRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemSubRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartRepository; +import com.kri.epolicy.dash.back.persistence.repository.SurveyItemRepository; +import com.kri.epolicy.dash.back.persistence.repository.SurveyRepository; +import com.kri.epolicy.dash.back.persistence.repository.WaveInfoRepository; +import com.kri.epolicy.dash.back.persistence.repository.WaveRepository; +import java.util.Collection; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class ExcelResetService { + + private final WaveRepository waveRepository; + private final WaveInfoRepository waveInfoRepository; + private final SurveyRepository surveyRepository; + private final SurveyItemRepository surveyItemRepository; + private final PartRepository partRepository; + private final PartItemRepository partItemRepository; + private final PartItemSubRepository partItemSubRepository; + private final PartItemBaseRepository partItemBaseRepository; + private final PartItemChartRepository partItemChartRepository; + private final PartItemChartHighlightRepository partItemChartHighlightRepository; + private final PartItemDataRepository partItemDataRepository; + + @Transactional + public ExcelResetResponse resetWave(Short waveCd) { + int partItemDataCount = partItemDataRepository.deleteForResetByWaveCd(waveCd); + int partItemChartHighlightCount = + partItemChartHighlightRepository.deleteForResetByWaveCd(waveCd); + int partItemChartCount = partItemChartRepository.deleteForResetByWaveCd(waveCd); + int partItemBaseCount = partItemBaseRepository.deleteForResetByWaveCd(waveCd); + int partItemSubCount = partItemSubRepository.deleteForResetByWaveCd(waveCd); + int partItemCount = partItemRepository.deleteForResetByWaveCd(waveCd); + int partCount = partRepository.deleteForResetByWaveCd(waveCd); + int surveyItemCount = surveyItemRepository.deleteForResetByWaveCd(waveCd); + int surveyCount = surveyRepository.deleteForResetByWaveCd(waveCd); + int waveInfoCount = waveInfoRepository.deleteForResetByWaveCd(waveCd); + int waveCount = waveRepository.deleteForResetByWaveCd(waveCd); + return new ExcelResetResponse( + waveCd, + waveCount, + waveInfoCount, + surveyCount, + surveyItemCount, + partCount, + partItemCount, + partItemSubCount, + partItemBaseCount, + partItemChartCount, + partItemChartHighlightCount, + partItemDataCount + ); + } + + @Transactional + public void resetWaves(Collection waveCodes) { + waveCodes.forEach(this::resetWave); + } +} diff --git a/src/main/java/com/kri/epolicy/dash/back/service/ExcelTemplateService.java b/src/main/java/com/kri/epolicy/dash/back/service/ExcelTemplateService.java index b87d49d..509877a 100644 --- a/src/main/java/com/kri/epolicy/dash/back/service/ExcelTemplateService.java +++ b/src/main/java/com/kri/epolicy/dash/back/service/ExcelTemplateService.java @@ -3,7 +3,10 @@ package com.kri.epolicy.dash.back.service; import com.kri.common.feature.excel.ExcelMapper; import com.kri.common.feature.web.BusinessException; import com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows; +import com.kri.epolicy.dash.back.dto.excel.ExcelWorkbookData; import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.PART_ITEM_BASE_SHEET; +import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.PART_ITEM_CHART_HIGHLIGHT_SHEET; +import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.PART_ITEM_CHART_SHEET; import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.PART_ITEM_DATA_SHEET; import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.PART_ITEM_SHEET; import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.PART_ITEM_SUB_SHEET; @@ -26,17 +29,28 @@ public class ExcelTemplateService { public static final String TEMPLATE_FILENAME = "epolicy-data-template.xlsx"; public byte[] createTemplate() { + return createWorkbook(ExcelWorkbookData.empty()); + } + + public byte[] createWorkbook(ExcelWorkbookData data) { try (Workbook workbook = ExcelMapper.writeToWorkbook( - List.of(), ExcelTemplateRows.Wave.class, WAVE_SHEET); + data.waves(), ExcelTemplateRows.Wave.class, WAVE_SHEET); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { - append(workbook, WAVE_INFO_SHEET, ExcelTemplateRows.WaveInfo.class); - append(workbook, SURVEY_SHEET, ExcelTemplateRows.Survey.class); - append(workbook, SURVEY_ITEM_SHEET, ExcelTemplateRows.SurveyItem.class); - append(workbook, PART_SHEET, ExcelTemplateRows.Part.class); - append(workbook, PART_ITEM_SHEET, ExcelTemplateRows.PartItem.class); - append(workbook, PART_ITEM_SUB_SHEET, ExcelTemplateRows.PartItemSub.class); - append(workbook, PART_ITEM_BASE_SHEET, ExcelTemplateRows.PartItemBase.class); - append(workbook, PART_ITEM_DATA_SHEET, ExcelTemplateRows.PartItemData.class); + append(workbook, WAVE_INFO_SHEET, data.waveInfos(), ExcelTemplateRows.WaveInfo.class); + append(workbook, SURVEY_SHEET, data.surveys(), ExcelTemplateRows.Survey.class); + append(workbook, SURVEY_ITEM_SHEET, data.surveyItems(), ExcelTemplateRows.SurveyItem.class); + append(workbook, PART_SHEET, data.parts(), ExcelTemplateRows.Part.class); + append(workbook, PART_ITEM_SHEET, data.partItems(), ExcelTemplateRows.PartItem.class); + append(workbook, PART_ITEM_SUB_SHEET, data.partItemSubs(), + ExcelTemplateRows.PartItemSub.class); + append(workbook, PART_ITEM_BASE_SHEET, data.partItemBases(), + ExcelTemplateRows.PartItemBase.class); + append(workbook, PART_ITEM_CHART_SHEET, data.partItemCharts(), + ExcelTemplateRows.PartItemChart.class); + append(workbook, PART_ITEM_CHART_HIGHLIGHT_SHEET, + data.partItemChartHighlights(), ExcelTemplateRows.PartItemChartHighlight.class); + append(workbook, PART_ITEM_DATA_SHEET, data.partItemData(), + ExcelTemplateRows.PartItemData.class); workbook.write(outputStream); return outputStream.toByteArray(); } catch (IOException | RuntimeException exception) { @@ -45,7 +59,12 @@ public class ExcelTemplateService { } } - private void append(Workbook workbook, String sheetName, Class rowType) { - ExcelMapper.appendSheetToWorkbook(workbook, List.of(), rowType, sheetName, 1); + private void append( + Workbook workbook, + String sheetName, + List rows, + Class rowType + ) { + ExcelMapper.appendSheetToWorkbook(workbook, rows, rowType, sheetName, 1); } } diff --git a/src/main/java/com/kri/epolicy/dash/back/service/WaveQueryService.java b/src/main/java/com/kri/epolicy/dash/back/service/WaveQueryService.java index 95835ae..65bfd40 100644 --- a/src/main/java/com/kri/epolicy/dash/back/service/WaveQueryService.java +++ b/src/main/java/com/kri/epolicy/dash/back/service/WaveQueryService.java @@ -2,6 +2,8 @@ package com.kri.epolicy.dash.back.service; import com.kri.common.feature.web.BusinessException; import com.kri.common.feature.web.RequestUserContext; +import com.kri.epolicy.dash.back.common.enums.ChartType; +import com.kri.epolicy.dash.back.common.enums.ChartGapMode; import com.kri.epolicy.dash.back.config.FileStorageProperties; import com.kri.epolicy.dash.back.dto.response.PartDetailResponse; import com.kri.epolicy.dash.back.dto.response.PartDetailResponse.Audience; @@ -15,6 +17,8 @@ import com.kri.epolicy.dash.back.dto.response.WaveSummaryResponse; import com.kri.epolicy.dash.back.persistence.entity.TFileEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartItemBaseEntity; +import com.kri.epolicy.dash.back.persistence.entity.TPartItemChartEntity; +import com.kri.epolicy.dash.back.persistence.entity.TPartItemChartHighlightEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartItemDataEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartItemEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartItemSubEntity; @@ -24,6 +28,8 @@ import com.kri.epolicy.dash.back.persistence.entity.TWaveEntity; import com.kri.epolicy.dash.back.persistence.entity.id.TPartEntityId; import com.kri.epolicy.dash.back.persistence.repository.FileRepository; import com.kri.epolicy.dash.back.persistence.repository.PartItemBaseRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemChartHighlightRepository; +import com.kri.epolicy.dash.back.persistence.repository.PartItemChartRepository; import com.kri.epolicy.dash.back.persistence.repository.PartItemDataRepository; import com.kri.epolicy.dash.back.persistence.repository.PartItemRepository; import com.kri.epolicy.dash.back.persistence.repository.PartItemSubRepository; @@ -38,6 +44,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -60,6 +67,8 @@ public class WaveQueryService { private final PartItemRepository partItemRepository; private final PartItemSubRepository partItemSubRepository; private final PartItemBaseRepository partItemBaseRepository; + private final PartItemChartRepository partItemChartRepository; + private final PartItemChartHighlightRepository partItemChartHighlightRepository; private final PartItemDataRepository partItemDataRepository; private final WaveAccessPolicy waveAccessPolicy; private final FileStorageProperties fileStorageProperties; @@ -134,6 +143,10 @@ public class WaveQueryService { List subs = partItemSubRepository .findByIdWaveCdAndIdPartCdOrderByIdPartItemCdAscIdPartItemSubCdAsc(waveCd, partCd); List bases = partItemBaseRepository.findByWaveCdAndPartCd(waveCd, partCd); + List charts = partItemChartRepository + .findByWaveCdAndPartCd(waveCd, partCd); + List highlights = partItemChartHighlightRepository + .findByWaveCdAndPartCd(waveCd, partCd); List data = partItemDataRepository .findByWaveCdAndPartCdOrderByPartItemDataOrderAsc(waveCd, partCd); @@ -144,7 +157,8 @@ public class WaveQueryService { waveCd, partCd, part.getPartTitle(), - items.stream().map(item -> toItem(item, surveys, surveyByCode, subsByItem, bases, data)) + items.stream().map(item -> toItem( + item, surveys, surveyByCode, subsByItem, bases, charts, highlights, data)) .toList() ); } @@ -155,6 +169,8 @@ public class WaveQueryService { Map surveyByCode, Map> subsByItem, List allBases, + List allCharts, + List allHighlights, List allData ) { Short itemCd = item.getId().getPartItemCd(); @@ -162,17 +178,30 @@ public class WaveQueryService { .filter(base -> base.getPartItemCd().equals(itemCd)).toList(); List data = allData.stream() .filter(value -> value.getPartItemCd().equals(itemCd)).toList(); + List charts = allCharts.stream() + .filter(chart -> chart.getPartItemCd().equals(itemCd)).toList(); + List highlights = allHighlights.stream() + .filter(highlight -> highlight.getPartItemCd().equals(itemCd)).toList(); List subs = subsByItem.getOrDefault(itemCd, List.of()); List groups = new ArrayList<>(); if (subs.isEmpty()) { - groups.add(toResultGroup(null, bases, data, surveyByCode)); + groups.add(toResultGroup( + null, + bases.stream().filter(base -> base.getPartItemSubCd() == null).toList(), + charts.stream().filter(chart -> chart.getPartItemSubCd() == null).toList(), + highlights.stream().filter(highlight -> highlight.getPartItemSubCd() == null).toList(), + data.stream().filter(value -> value.getPartItemSubCd() == null).toList(), + surveyByCode)); } else { for (TPartItemSubEntity sub : subs) { Short subCd = sub.getId().getPartItemSubCd(); groups.add(toResultGroup( - new SubItem(subCd, sub.getPartItemSubTitle()), + new SubItem(subCd, sub.getPartItemSubTitle(), sub.getPartItemSubComment()), bases.stream().filter(base -> subCd.equals(base.getPartItemSubCd())).toList(), + charts.stream().filter(chart -> subCd.equals(chart.getPartItemSubCd())).toList(), + highlights.stream() + .filter(highlight -> subCd.equals(highlight.getPartItemSubCd())).toList(), data.stream().filter(value -> subCd.equals(value.getPartItemSubCd())).toList(), surveyByCode)); } @@ -185,7 +214,6 @@ public class WaveQueryService { itemCd, item.getPartItemOrder(), item.getPartItemTitle(), - item.getChartType().getCode(), item.getPartItemComment(), toAudience(audienceCodes, surveys, surveyByCode), List.copyOf(groups) @@ -195,12 +223,21 @@ public class WaveQueryService { private ResultGroup toResultGroup( SubItem subItem, List bases, + List charts, + List highlights, List data, Map surveyByCode ) { Map baseBySurvey = bases.stream().collect(Collectors.toMap( TPartItemBaseEntity::getSurveyCd, Function.identity(), (left, right) -> left, LinkedHashMap::new)); + Map chartBySurvey = charts.stream().collect(Collectors.toMap( + TPartItemChartEntity::getSurveyCd, Function.identity(), (left, right) -> left, + LinkedHashMap::new)); + Map highlightBySurvey = highlights.stream() + .collect(Collectors.toMap( + TPartItemChartHighlightEntity::getSurveyCd, Function.identity(), + (left, right) -> left, LinkedHashMap::new)); Map> dataBySurvey = data.stream().collect( Collectors.groupingBy(TPartItemDataEntity::getSurveyCd, LinkedHashMap::new, Collectors.toList())); @@ -218,10 +255,20 @@ public class WaveQueryService { List series = surveyCodes.stream().map(surveyCd -> { TPartItemBaseEntity base = baseBySurvey.get(surveyCd); TSurveyEntity survey = surveyByCode.get(surveyCd); + TPartItemChartEntity chart = chartBySurvey.get(surveyCd); + TPartItemChartHighlightEntity highlight = highlightBySurvey.get(surveyCd); return new Series( surveyCd, survey.getSurveyAlias(), - survey.getSurveyColor(), + chart == null || chart.getChartType() == null + ? ChartType.BAR.getCode() : chart.getChartType(), + chart == null || chart.getChartColor() == null + ? survey.getSurveyColor() : chart.getChartColor(), + ChartGapMode.fromCodeOrDefault( + chart == null ? null : chart.getChartGapMode()).name(), + highlight == null ? null : highlight.getChartHighlightMode(), + highlight == null ? null : highlight.getChartHighlightValue(), + highlight == null ? null : highlight.getChartHighlightColor(), base == null ? null : base.getBaseCount(), base == null ? null : base.getBaseText(), dataBySurvey.get(surveyCd).stream() @@ -244,7 +291,7 @@ public class WaveQueryService { } String label = audienceCodes.stream() .map(surveyByCode::get) - .filter(java.util.Objects::nonNull) + .filter(Objects::nonNull) .sorted(Comparator.comparing(TSurveyEntity::getSurveyOrder)) .map(TSurveyEntity::getSurveyAlias) .collect(Collectors.joining(", "));