260825_01_ENH: 차트 문항별 색상지정 및 차트 하이라이트 모드 적용, 문항별 제목과 범례 사이에 문항 텍스트 삽입, gap 추가

This commit is contained in:
2026-08-25 14:48:54 +09:00
parent 58ca2011cf
commit 52649e98b2
32 changed files with 970 additions and 116 deletions

View File

@@ -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. - 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. - 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. - 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. - 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.
- 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. - Omit every auto-increment `_idx` column from Excel. Replacement imports regenerate identities.
- 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`. - 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. - 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. - 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.
- 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. - 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`. - 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`. - 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. - 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. - 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. - 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. - `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. - 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)`. - 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)`. - 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. - 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 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. - 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. - 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 ## 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. - 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. - 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 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 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. - 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. - 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.

View File

@@ -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. - 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. - 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. - 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. - 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.
- 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. - Omit every auto-increment `_idx` column from Excel. Replacement imports regenerate identities.
- 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`. - 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. - 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. - 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.
- 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. - 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`. - 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`. - 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. - 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. - 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. - 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. - `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. - 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)`. - 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)`. - 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. - 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 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. - 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. - 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 ## 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. - 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. - 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 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 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. - 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. - 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.

View File

@@ -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);
}
}

View File

@@ -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));
}
}

View File

@@ -1,7 +1,10 @@
package com.kri.epolicy.dash.back.controller; package com.kri.epolicy.dash.back.controller;
import com.kri.epolicy.dash.back.dto.response.ExcelImportResponse; 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.ExcelImportService;
import com.kri.epolicy.dash.back.service.ExcelResetService;
import com.kri.epolicy.dash.back.service.ExcelTemplateService; import com.kri.epolicy.dash.back.service.ExcelTemplateService;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -10,6 +13,8 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
@@ -23,6 +28,8 @@ public class ExcelController {
private final ExcelImportService excelImportService; private final ExcelImportService excelImportService;
private final ExcelTemplateService excelTemplateService; private final ExcelTemplateService excelTemplateService;
private final ExcelExportService excelExportService;
private final ExcelResetService excelResetService;
@PostMapping(value = "/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ExcelImportResponse importExcel(@RequestPart("file") MultipartFile file) { public ExcelImportResponse importExcel(@RequestPart("file") MultipartFile file) {
@@ -39,4 +46,23 @@ public class ExcelController {
.contentType(MediaType.parseMediaType(ExcelTemplateService.EXCEL_CONTENT_TYPE)) .contentType(MediaType.parseMediaType(ExcelTemplateService.EXCEL_CONTENT_TYPE))
.body(excelTemplateService.createTemplate()); .body(excelTemplateService.createTemplate());
} }
@GetMapping(
value = "/waves/{waveCd}/export",
produces = ExcelTemplateService.EXCEL_CONTENT_TYPE
)
public ResponseEntity<byte[]> 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);
}
} }

View File

@@ -1,7 +1,9 @@
package com.kri.epolicy.dash.back.dto.excel; package com.kri.epolicy.dash.back.dto.excel;
import com.kri.common.feature.excel.ExcelColumn; import com.kri.common.feature.excel.ExcelColumn;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
public final class ExcelTemplateRows { 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_SHEET = "t_part_item";
public static final String PART_ITEM_SUB_SHEET = "t_part_item_sub"; 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_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"; public static final String PART_ITEM_DATA_SHEET = "t_part_item_data";
private ExcelTemplateRows() { private ExcelTemplateRows() {
} }
@Getter @Getter
@NoArgsConstructor
@AllArgsConstructor
public static final class Wave { public static final class Wave {
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
@ExcelColumn(header = "year", order = 1) private String year; @ExcelColumn(header = "year", order = 1) private String year;
@@ -28,6 +34,8 @@ public final class ExcelTemplateRows {
} }
@Getter @Getter
@NoArgsConstructor
@AllArgsConstructor
public static final class WaveInfo { public static final class WaveInfo {
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
@ExcelColumn(header = "wave_info_order", order = 1) private String waveInfoOrder; @ExcelColumn(header = "wave_info_order", order = 1) private String waveInfoOrder;
@@ -36,6 +44,8 @@ public final class ExcelTemplateRows {
} }
@Getter @Getter
@NoArgsConstructor
@AllArgsConstructor
public static final class Survey { public static final class Survey {
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
@ExcelColumn(header = "survey_cd", order = 1) private String surveyCd; @ExcelColumn(header = "survey_cd", order = 1) private String surveyCd;
@@ -46,6 +56,8 @@ public final class ExcelTemplateRows {
} }
@Getter @Getter
@NoArgsConstructor
@AllArgsConstructor
public static final class SurveyItem { public static final class SurveyItem {
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
@ExcelColumn(header = "survey_cd", order = 1) private String surveyCd; @ExcelColumn(header = "survey_cd", order = 1) private String surveyCd;
@@ -55,6 +67,8 @@ public final class ExcelTemplateRows {
} }
@Getter @Getter
@NoArgsConstructor
@AllArgsConstructor
public static final class Part { public static final class Part {
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
@ExcelColumn(header = "part_cd", order = 1) private String partCd; @ExcelColumn(header = "part_cd", order = 1) private String partCd;
@@ -63,26 +77,32 @@ public final class ExcelTemplateRows {
} }
@Getter @Getter
@NoArgsConstructor
@AllArgsConstructor
public static final class PartItem { public static final class PartItem {
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
@ExcelColumn(header = "part_cd", order = 1) private String partCd; @ExcelColumn(header = "part_cd", order = 1) private String partCd;
@ExcelColumn(header = "part_item_cd", order = 2) private String partItemCd; @ExcelColumn(header = "part_item_cd", order = 2) private String partItemCd;
@ExcelColumn(header = "part_item_order", order = 3) private String partItemOrder; @ExcelColumn(header = "part_item_order", order = 3) private String partItemOrder;
@ExcelColumn(header = "part_item_title", order = 4) private String partItemTitle; @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 = 5) private String partItemComment;
@ExcelColumn(header = "part_item_comment", order = 6) private String partItemComment;
} }
@Getter @Getter
@NoArgsConstructor
@AllArgsConstructor
public static final class PartItemSub { public static final class PartItemSub {
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
@ExcelColumn(header = "part_cd", order = 1) private String partCd; @ExcelColumn(header = "part_cd", order = 1) private String partCd;
@ExcelColumn(header = "part_item_cd", order = 2) private String partItemCd; @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_cd", order = 3) private String partItemSubCd;
@ExcelColumn(header = "part_item_sub_title", order = 4) private String partItemSubTitle; @ExcelColumn(header = "part_item_sub_title", order = 4) private String partItemSubTitle;
@ExcelColumn(header = "part_item_sub_comment", order = 5) private String partItemSubComment;
} }
@Getter @Getter
@NoArgsConstructor
@AllArgsConstructor
public static final class PartItemBase { public static final class PartItemBase {
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
@ExcelColumn(header = "part_cd", order = 1) private String partCd; @ExcelColumn(header = "part_cd", order = 1) private String partCd;
@@ -94,6 +114,8 @@ public final class ExcelTemplateRows {
} }
@Getter @Getter
@NoArgsConstructor
@AllArgsConstructor
public static final class PartItemData { public static final class PartItemData {
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd; @ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
@ExcelColumn(header = "part_cd", order = 1) private String partCd; @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 = "part_item_data_value", order = 7) private String partItemDataValue;
@ExcelColumn(header = "is_chart_visible (1, 0)", order = 8) private String isChartVisible; @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;
}
} }

View File

@@ -0,0 +1,24 @@
package com.kri.epolicy.dash.back.dto.excel;
import java.util.List;
public record ExcelWorkbookData(
List<ExcelTemplateRows.Wave> waves,
List<ExcelTemplateRows.WaveInfo> waveInfos,
List<ExcelTemplateRows.Survey> surveys,
List<ExcelTemplateRows.SurveyItem> surveyItems,
List<ExcelTemplateRows.Part> parts,
List<ExcelTemplateRows.PartItem> partItems,
List<ExcelTemplateRows.PartItemSub> partItemSubs,
List<ExcelTemplateRows.PartItemBase> partItemBases,
List<ExcelTemplateRows.PartItemChart> partItemCharts,
List<ExcelTemplateRows.PartItemChartHighlight> partItemChartHighlights,
List<ExcelTemplateRows.PartItemData> 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());
}
}

View File

@@ -1,6 +1,7 @@
package com.kri.epolicy.dash.back.dto.request; 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.ChartType;
import com.kri.epolicy.dash.back.common.enums.ChartGapMode;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
@@ -13,6 +14,8 @@ public record ExcelData(
List<PartItemRow> partItems, List<PartItemRow> partItems,
List<PartItemSubRow> partItemSubs, List<PartItemSubRow> partItemSubs,
List<PartItemBaseRow> partItemBases, List<PartItemBaseRow> partItemBases,
List<PartItemChartRow> partItemCharts,
List<PartItemChartHighlightRow> partItemChartHighlights,
List<PartItemDataRow> partItemData List<PartItemDataRow> partItemData
) { ) {
@@ -66,7 +69,6 @@ public record ExcelData(
Short partItemCd, Short partItemCd,
Short partItemOrder, Short partItemOrder,
String partItemTitle, String partItemTitle,
ChartType chartType,
String partItemComment String partItemComment
) { ) {
} }
@@ -76,7 +78,8 @@ public record ExcelData(
Short partCd, Short partCd,
Short partItemCd, Short partItemCd,
Short partItemSubCd, Short partItemSubCd,
String partItemSubTitle String partItemSubTitle,
String partItemSubComment
) { ) {
} }
@@ -103,4 +106,28 @@ public record ExcelData(
Boolean isChartVisible 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
) {
}
} }

View File

@@ -9,6 +9,8 @@ public record ExcelImportResponse(
int partItemCount, int partItemCount,
int partItemSubCount, int partItemSubCount,
int partItemBaseCount, int partItemBaseCount,
int partItemChartCount,
int partItemChartHighlightCount,
int partItemDataCount int partItemDataCount
) { ) {
} }

View File

@@ -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
) {
}

View File

@@ -14,7 +14,6 @@ public record PartDetailResponse(
Short partItemCd, Short partItemCd,
Short order, Short order,
String title, String title,
String chartType,
String comment, String comment,
Audience audience, Audience audience,
List<ResultGroup> resultGroups List<ResultGroup> 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( public record Series(
Short surveyCd, Short surveyCd,
String label, String label,
String chartType,
String color, String color,
String chartGapMode,
String chartHighlightMode,
String chartHighlightValue,
String chartHighlightColor,
Integer baseCount, Integer baseCount,
String baseText, String baseText,
List<BigDecimal> values List<BigDecimal> values

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -1,12 +1,9 @@
package com.kri.epolicy.dash.back.persistence.entity; package com.kri.epolicy.dash.back.persistence.entity;
import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemEntityId; 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.Column;
import jakarta.persistence.EmbeddedId; import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Convert;
import jakarta.persistence.Lob; import jakarta.persistence.Lob;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@@ -32,11 +29,6 @@ public class TPartItemEntity {
@Column(name = "part_item_title", nullable = false, length = 128) @Column(name = "part_item_title", nullable = false, length = 128)
private String partItemTitle; private String partItemTitle;
@NotNull
@Convert(converter = ChartTypeConverter.class)
@Column(name = "chart_type", nullable = false, length = 32)
private ChartType chartType;
@NotNull @NotNull
@Lob @Lob
@Column(name = "part_item_comment", nullable = false) @Column(name = "part_item_comment", nullable = false)

View File

@@ -4,6 +4,7 @@ import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemSubEntityId;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.EmbeddedId; import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Lob;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
@@ -24,5 +25,9 @@ public class TPartItemSubEntity {
@Column(name = "part_item_sub_title", nullable = false, length = 128) @Column(name = "part_item_sub_title", nullable = false, length = 128)
private String partItemSubTitle; private String partItemSubTitle;
@Lob
@Column(name = "part_item_sub_comment")
private String partItemSubComment;
}
}

View File

@@ -4,10 +4,17 @@ import com.kri.epolicy.dash.back.persistence.entity.TPartItemBaseEntity;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; 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<TPartItemBaseEntity, Integer> { public interface PartItemBaseRepository extends JpaRepository<TPartItemBaseEntity, Integer> {
List<TPartItemBaseEntity> findByWaveCdAndPartCd(Short waveCd, Short partCd); List<TPartItemBaseEntity> findByWaveCdAndPartCd(Short waveCd, Short partCd);
List<TPartItemBaseEntity> findByWaveCdIn(Collection<Short> waveCodes); List<TPartItemBaseEntity> findByWaveCdIn(Collection<Short> waveCodes);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TPartItemBaseEntity e where e.waveCd = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
} }

View File

@@ -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<TPartItemChartHighlightEntity, Integer> {
List<TPartItemChartHighlightEntity> findByWaveCdAndPartCd(Short waveCd, Short partCd);
List<TPartItemChartHighlightEntity> findByWaveCdIn(Collection<Short> waveCodes);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TPartItemChartHighlightEntity e where e.waveCd = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
}

View File

@@ -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<TPartItemChartEntity, Integer> {
List<TPartItemChartEntity> findByWaveCdAndPartCd(Short waveCd, Short partCd);
List<TPartItemChartEntity> findByWaveCdIn(Collection<Short> waveCodes);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TPartItemChartEntity e where e.waveCd = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
}

View File

@@ -4,6 +4,9 @@ import com.kri.epolicy.dash.back.persistence.entity.TPartItemDataEntity;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; 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<TPartItemDataEntity, Integer> { public interface PartItemDataRepository extends JpaRepository<TPartItemDataEntity, Integer> {
@@ -13,4 +16,8 @@ public interface PartItemDataRepository extends JpaRepository<TPartItemDataEntit
); );
List<TPartItemDataEntity> findByWaveCdIn(Collection<Short> waveCodes); List<TPartItemDataEntity> findByWaveCdIn(Collection<Short> waveCodes);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TPartItemDataEntity e where e.waveCd = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
} }

View File

@@ -4,6 +4,9 @@ import com.kri.epolicy.dash.back.persistence.entity.TPartItemEntity;
import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemEntityId; import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemEntityId;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List; 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 public interface PartItemRepository
extends JpaRepository<TPartItemEntity, TPartItemEntityId> { extends JpaRepository<TPartItemEntity, TPartItemEntityId> {
@@ -14,4 +17,8 @@ public interface PartItemRepository
Short waveCd, Short waveCd,
Short partCd Short partCd
); );
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TPartItemEntity e where e.id.waveCd = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
} }

View File

@@ -4,12 +4,21 @@ import com.kri.epolicy.dash.back.persistence.entity.TPartItemSubEntity;
import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemSubEntityId; import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemSubEntityId;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List; 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 public interface PartItemSubRepository
extends JpaRepository<TPartItemSubEntity, TPartItemSubEntityId> { extends JpaRepository<TPartItemSubEntity, TPartItemSubEntityId> {
List<TPartItemSubEntity> findByIdWaveCd(Short waveCd);
List<TPartItemSubEntity> findByIdWaveCdAndIdPartCdOrderByIdPartItemCdAscIdPartItemSubCdAsc( List<TPartItemSubEntity> findByIdWaveCdAndIdPartCdOrderByIdPartItemCdAscIdPartItemSubCdAsc(
Short waveCd, Short waveCd,
Short partCd Short partCd
); );
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TPartItemSubEntity e where e.id.waveCd = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
} }

View File

@@ -4,8 +4,15 @@ import com.kri.epolicy.dash.back.persistence.entity.TPartEntity;
import com.kri.epolicy.dash.back.persistence.entity.id.TPartEntityId; import com.kri.epolicy.dash.back.persistence.entity.id.TPartEntityId;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List; 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<TPartEntity, TPartEntityId> { public interface PartRepository extends JpaRepository<TPartEntity, TPartEntityId> {
List<TPartEntity> findByIdWaveCdOrderByPartOrderAsc(Short waveCd); List<TPartEntity> findByIdWaveCdOrderByPartOrderAsc(Short waveCd);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TPartEntity e where e.id.waveCd = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
} }

View File

@@ -4,6 +4,9 @@ import com.kri.epolicy.dash.back.persistence.entity.TSurveyItemEntity;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; 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 public interface SurveyItemRepository
extends JpaRepository<TSurveyItemEntity, Integer> { extends JpaRepository<TSurveyItemEntity, Integer> {
@@ -11,4 +14,8 @@ public interface SurveyItemRepository
List<TSurveyItemEntity> findByWaveCdOrderBySurveyItemOrderAsc(Short waveCd); List<TSurveyItemEntity> findByWaveCdOrderBySurveyItemOrderAsc(Short waveCd);
List<TSurveyItemEntity> findByWaveCdIn(Collection<Short> waveCodes); List<TSurveyItemEntity> findByWaveCdIn(Collection<Short> waveCodes);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TSurveyItemEntity e where e.waveCd = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
} }

View File

@@ -4,8 +4,15 @@ import com.kri.epolicy.dash.back.persistence.entity.TSurveyEntity;
import com.kri.epolicy.dash.back.persistence.entity.id.TSurveyEntityId; import com.kri.epolicy.dash.back.persistence.entity.id.TSurveyEntityId;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List; 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<TSurveyEntity, TSurveyEntityId> { public interface SurveyRepository extends JpaRepository<TSurveyEntity, TSurveyEntityId> {
List<TSurveyEntity> findByIdWaveCdOrderBySurveyOrderAsc(Short waveCd); List<TSurveyEntity> findByIdWaveCdOrderBySurveyOrderAsc(Short waveCd);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TSurveyEntity e where e.id.waveCd = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
} }

View File

@@ -4,10 +4,17 @@ import com.kri.epolicy.dash.back.persistence.entity.TWaveInfoEntity;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; 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<TWaveInfoEntity, Integer> { public interface WaveInfoRepository extends JpaRepository<TWaveInfoEntity, Integer> {
List<TWaveInfoEntity> findByWaveCdOrderByWaveInfoOrderAsc(Short waveCd); List<TWaveInfoEntity> findByWaveCdOrderByWaveInfoOrderAsc(Short waveCd);
List<TWaveInfoEntity> findByWaveCdIn(Collection<Short> waveCodes); List<TWaveInfoEntity> findByWaveCdIn(Collection<Short> waveCodes);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TWaveInfoEntity e where e.waveCd = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
} }

View File

@@ -3,8 +3,15 @@ package com.kri.epolicy.dash.back.persistence.repository;
import com.kri.epolicy.dash.back.persistence.entity.TWaveEntity; import com.kri.epolicy.dash.back.persistence.entity.TWaveEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List; 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<TWaveEntity, Short> { public interface WaveRepository extends JpaRepository<TWaveEntity, Short> {
List<TWaveEntity> findAllByOrderByYearDescWaveDesc(); List<TWaveEntity> findAllByOrderByYearDescWaveDesc();
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("delete from TWaveEntity e where e.id = :waveCd")
int deleteForResetByWaveCd(@Param("waveCd") Short waveCd);
} }

View File

@@ -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<Short> 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<Short> waveCodes = List.of(waveCd);
List<TPartItemBaseEntity> bases = partItemBaseRepository.findByWaveCdIn(waveCodes).stream()
.sorted(resultSeriesComparator())
.toList();
List<TPartItemChartEntity> charts = partItemChartRepository.findByWaveCdIn(waveCodes).stream()
.sorted(resultSeriesComparatorForChart())
.toList();
List<TPartItemChartHighlightEntity> highlights = partItemChartHighlightRepository
.findByWaveCdIn(waveCodes).stream()
.sorted(resultSeriesComparatorForHighlight())
.toList();
List<TPartItemDataEntity> 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<TPartItemBaseEntity> resultSeriesComparator() {
return Comparator.comparing(TPartItemBaseEntity::getPartCd)
.thenComparing(TPartItemBaseEntity::getPartItemCd)
.thenComparing(TPartItemBaseEntity::getSurveyCd)
.thenComparing(TPartItemBaseEntity::getPartItemSubCd, NULLABLE_SHORT);
}
private Comparator<TPartItemChartEntity> resultSeriesComparatorForChart() {
return Comparator.comparing(TPartItemChartEntity::getPartCd)
.thenComparing(TPartItemChartEntity::getPartItemCd)
.thenComparing(TPartItemChartEntity::getSurveyCd)
.thenComparing(TPartItemChartEntity::getPartItemSubCd, NULLABLE_SHORT);
}
private Comparator<TPartItemChartHighlightEntity> resultSeriesComparatorForHighlight() {
return Comparator.comparing(TPartItemChartHighlightEntity::getPartCd)
.thenComparing(TPartItemChartHighlightEntity::getPartItemCd)
.thenComparing(TPartItemChartHighlightEntity::getSurveyCd)
.thenComparing(TPartItemChartHighlightEntity::getPartItemSubCd, NULLABLE_SHORT);
}
private Comparator<TPartItemDataEntity> 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();
}
}

View File

@@ -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.dto.response.ExcelImportResponse;
import com.kri.epolicy.dash.back.persistence.entity.TPartEntity; 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.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.TPartItemDataEntity;
import com.kri.epolicy.dash.back.persistence.entity.TPartItemEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartItemEntity;
import com.kri.epolicy.dash.back.persistence.entity.TPartItemSubEntity; 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.TPartItemSubEntityId;
import com.kri.epolicy.dash.back.persistence.entity.id.TSurveyEntityId; 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.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.PartItemDataRepository;
import com.kri.epolicy.dash.back.persistence.repository.PartItemRepository; 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.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.SurveyRepository;
import com.kri.epolicy.dash.back.persistence.repository.WaveInfoRepository; import com.kri.epolicy.dash.back.persistence.repository.WaveInfoRepository;
import com.kri.epolicy.dash.back.persistence.repository.WaveRepository; import com.kri.epolicy.dash.back.persistence.repository.WaveRepository;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -37,6 +40,7 @@ import org.springframework.web.multipart.MultipartFile;
public class ExcelImportService { public class ExcelImportService {
private final ExcelImportValidator excelImportValidator; private final ExcelImportValidator excelImportValidator;
private final ExcelResetService excelResetService;
private final WaveRepository waveRepository; private final WaveRepository waveRepository;
private final WaveInfoRepository waveInfoRepository; private final WaveInfoRepository waveInfoRepository;
private final SurveyRepository surveyRepository; private final SurveyRepository surveyRepository;
@@ -45,6 +49,8 @@ public class ExcelImportService {
private final PartItemRepository partItemRepository; private final PartItemRepository partItemRepository;
private final PartItemSubRepository partItemSubRepository; private final PartItemSubRepository partItemSubRepository;
private final PartItemBaseRepository partItemBaseRepository; private final PartItemBaseRepository partItemBaseRepository;
private final PartItemChartRepository partItemChartRepository;
private final PartItemChartHighlightRepository partItemChartHighlightRepository;
private final PartItemDataRepository partItemDataRepository; private final PartItemDataRepository partItemDataRepository;
@Transactional @Transactional
@@ -53,32 +59,7 @@ public class ExcelImportService {
Set<Short> waveCodes = data.waves().stream() Set<Short> waveCodes = data.waves().stream()
.map(ExcelData.WaveRow::waveCd) .map(ExcelData.WaveRow::waveCd)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
Map<WaveInfoKey, Integer> waveInfoIds = waveInfoRepository.findByWaveCdIn(waveCodes) excelResetService.resetWaves(waveCodes);
.stream().collect(Collectors.toMap(
entity -> new WaveInfoKey(entity.getWaveCd(), entity.getWaveInfoOrder()),
TWaveInfoEntity::getId,
firstValue()));
Map<SurveyItemKey, Integer> surveyItemIds = surveyItemRepository
.findByWaveCdIn(waveCodes).stream().collect(Collectors.toMap(
entity -> new SurveyItemKey(
entity.getWaveCd(), entity.getSurveyCd(), entity.getSurveyItemOrder()),
TSurveyItemEntity::getId,
firstValue()));
Map<ResultSeriesKey, Integer> 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<ResultCategoryKey, Integer> 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()));
waveRepository.saveAll(data.waves().stream().map(row -> { waveRepository.saveAll(data.waves().stream().map(row -> {
TWaveEntity entity = new TWaveEntity(); TWaveEntity entity = new TWaveEntity();
@@ -92,7 +73,6 @@ public class ExcelImportService {
waveInfoRepository.saveAll(data.waveInfos().stream().map(row -> { waveInfoRepository.saveAll(data.waveInfos().stream().map(row -> {
TWaveInfoEntity entity = new TWaveInfoEntity(); TWaveInfoEntity entity = new TWaveInfoEntity();
entity.setId(waveInfoIds.get(new WaveInfoKey(row.waveCd(), row.waveInfoOrder())));
entity.setWaveCd(row.waveCd()); entity.setWaveCd(row.waveCd());
entity.setWaveInfoOrder(row.waveInfoOrder()); entity.setWaveInfoOrder(row.waveInfoOrder());
entity.setWaveInfoTitle(row.waveInfoTitle()); entity.setWaveInfoTitle(row.waveInfoTitle());
@@ -112,8 +92,6 @@ public class ExcelImportService {
surveyItemRepository.saveAll(data.surveyItems().stream().map(row -> { surveyItemRepository.saveAll(data.surveyItems().stream().map(row -> {
TSurveyItemEntity entity = new TSurveyItemEntity(); TSurveyItemEntity entity = new TSurveyItemEntity();
entity.setId(surveyItemIds.get(
new SurveyItemKey(row.waveCd(), row.surveyCd(), row.surveyItemOrder())));
entity.setWaveCd(row.waveCd()); entity.setWaveCd(row.waveCd());
entity.setSurveyCd(row.surveyCd()); entity.setSurveyCd(row.surveyCd());
entity.setSurveyItemOrder(row.surveyItemOrder()); entity.setSurveyItemOrder(row.surveyItemOrder());
@@ -135,7 +113,6 @@ public class ExcelImportService {
entity.setId(partItemId(row.waveCd(), row.partCd(), row.partItemCd())); entity.setId(partItemId(row.waveCd(), row.partCd(), row.partItemCd()));
entity.setPartItemOrder(row.partItemOrder()); entity.setPartItemOrder(row.partItemOrder());
entity.setPartItemTitle(row.partItemTitle()); entity.setPartItemTitle(row.partItemTitle());
entity.setChartType(row.chartType());
entity.setPartItemComment(row.partItemComment()); entity.setPartItemComment(row.partItemComment());
return entity; return entity;
}).toList()); }).toList());
@@ -145,13 +122,12 @@ public class ExcelImportService {
entity.setId(partItemSubId( entity.setId(partItemSubId(
row.waveCd(), row.partCd(), row.partItemCd(), row.partItemSubCd())); row.waveCd(), row.partCd(), row.partItemCd(), row.partItemSubCd()));
entity.setPartItemSubTitle(row.partItemSubTitle()); entity.setPartItemSubTitle(row.partItemSubTitle());
entity.setPartItemSubComment(row.partItemSubComment());
return entity; return entity;
}).toList()); }).toList());
partItemBaseRepository.saveAll(data.partItemBases().stream().map(row -> { partItemBaseRepository.saveAll(data.partItemBases().stream().map(row -> {
TPartItemBaseEntity entity = new TPartItemBaseEntity(); 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.setWaveCd(row.waveCd());
entity.setPartCd(row.partCd()); entity.setPartCd(row.partCd());
entity.setPartItemCd(row.partItemCd()); entity.setPartItemCd(row.partItemCd());
@@ -162,11 +138,34 @@ public class ExcelImportService {
return entity; return entity;
}).toList()); }).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 -> { partItemDataRepository.saveAll(data.partItemData().stream().map(row -> {
TPartItemDataEntity entity = new TPartItemDataEntity(); 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.setWaveCd(row.waveCd());
entity.setPartCd(row.partCd()); entity.setPartCd(row.partCd());
entity.setPartItemCd(row.partItemCd()); entity.setPartItemCd(row.partItemCd());
@@ -188,6 +187,8 @@ public class ExcelImportService {
data.partItems().size(), data.partItems().size(),
data.partItemSubs().size(), data.partItemSubs().size(),
data.partItemBases().size(), data.partItemBases().size(),
data.partItemCharts().size(),
data.partItemChartHighlights().size(),
data.partItemData().size() data.partItemData().size()
); );
} }
@@ -228,32 +229,4 @@ public class ExcelImportService {
return id; return id;
} }
private <T> java.util.function.BinaryOperator<T> 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
) {
}
} }

View File

@@ -4,9 +4,13 @@ import com.kri.common.feature.excel.ExcelColumn;
import com.kri.common.feature.excel.ExcelMapper; import com.kri.common.feature.excel.ExcelMapper;
import com.kri.common.feature.web.BusinessException; import com.kri.common.feature.web.BusinessException;
import com.kri.epolicy.dash.back.common.enums.ChartType; 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.excel.ExcelTemplateRows;
import com.kri.epolicy.dash.back.dto.request.ExcelData; 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.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.PartItemDataRow;
import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemRow; import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemRow;
import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemSubRow; 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.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.regex.Pattern;
import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
@@ -46,6 +51,8 @@ import org.springframework.web.multipart.MultipartFile;
public class ExcelImportValidator { public class ExcelImportValidator {
private static final int HEADER_ROW_NUMBER = 1; 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) { public ExcelData validateAndConvert(MultipartFile file) {
validateFile(file); validateFile(file);
@@ -71,17 +78,29 @@ public class ExcelImportValidator {
row.getPartTitle()), this::toPartRow), row.getPartTitle()), this::toPartRow),
readRows(workbook, ExcelTemplateRows.PART_ITEM_SHEET, ExcelTemplateRows.PartItem.class, readRows(workbook, ExcelTemplateRows.PART_ITEM_SHEET, ExcelTemplateRows.PartItem.class,
row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(), row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(),
row.getPartItemOrder(), row.getPartItemTitle(), row.getChartType(), row.getPartItemOrder(), row.getPartItemTitle(), row.getPartItemComment()),
row.getPartItemComment()), this::toPartItemRow), this::toPartItemRow),
readRows(workbook, ExcelTemplateRows.PART_ITEM_SUB_SHEET, readRows(workbook, ExcelTemplateRows.PART_ITEM_SUB_SHEET,
ExcelTemplateRows.PartItemSub.class, ExcelTemplateRows.PartItemSub.class,
row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(), 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, readRows(workbook, ExcelTemplateRows.PART_ITEM_BASE_SHEET,
ExcelTemplateRows.PartItemBase.class, ExcelTemplateRows.PartItemBase.class,
row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(), row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(),
row.getSurveyCd(), row.getPartItemSubCd(), row.getBaseCount(), 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, readRows(workbook, ExcelTemplateRows.PART_ITEM_DATA_SHEET,
ExcelTemplateRows.PartItemData.class, ExcelTemplateRows.PartItemData.class,
row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(), row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(),
@@ -190,7 +209,7 @@ public class ExcelImportValidator {
requiredShort(row.getSurveyOrder(), "survey_order", context), requiredShort(row.getSurveyOrder(), "survey_order", context),
requiredString(row.getSurveyTitle(), "survey_title", 128, context), requiredString(row.getSurveyTitle(), "survey_title", 128, context),
requiredString(row.getSurveyAlias(), "survey_alias", 32, 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.getPartItemCd(), "part_item_cd", context),
requiredShort(row.getPartItemOrder(), "part_item_order", context), requiredShort(row.getPartItemOrder(), "part_item_order", context),
requiredString(row.getPartItemTitle(), "part_item_title", 128, context), requiredString(row.getPartItemTitle(), "part_item_title", 128, context),
requiredChartType(row.getChartType(), "chart_type", context),
Objects.requireNonNullElse( Objects.requireNonNullElse(
optionalString(row.getPartItemComment(), "part_item_comment", null, context), "") optionalString(row.getPartItemComment(), "part_item_comment", null, context), "")
); );
@@ -238,7 +256,8 @@ public class ExcelImportValidator {
requiredShort(row.getPartCd(), "part_cd", context), requiredShort(row.getPartCd(), "part_cd", context),
requiredShort(row.getPartItemCd(), "part_item_cd", context), requiredShort(row.getPartItemCd(), "part_item_cd", context),
requiredShort(row.getPartItemSubCd(), "part_item_sub_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) { private void validateRelationships(ExcelData data) {
Set<Short> waveKeys = uniqueKeys( Set<Short> waveKeys = uniqueKeys(
data.waves(), WaveRow::waveCd, ExcelTemplateRows.WAVE_SHEET); data.waves(), WaveRow::waveCd, ExcelTemplateRows.WAVE_SHEET);
@@ -293,6 +349,10 @@ public class ExcelImportValidator {
Set<SubKey> subKeys = uniqueKeys(data.partItemSubs(), Set<SubKey> subKeys = uniqueKeys(data.partItemSubs(),
row -> new SubKey(row.waveCd(), row.partCd(), row.partItemCd(), row.partItemSubCd()), row -> new SubKey(row.waveCd(), row.partCd(), row.partItemCd(), row.partItemSubCd()),
ExcelTemplateRows.PART_ITEM_SUB_SHEET); 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, requireParents(data.waveInfos(), WaveInfoRow::waveCd, waveKeys,
ExcelTemplateRows.WAVE_INFO_SHEET, "wave_cd"); ExcelTemplateRows.WAVE_INFO_SHEET, "wave_cd");
@@ -323,10 +383,30 @@ public class ExcelImportValidator {
row.partItemSubCd(), itemKeys, surveyKeys, subKeys, itemsWithSubs, row.partItemSubCd(), itemKeys, surveyKeys, subKeys, itemsWithSubs,
ExcelTemplateRows.PART_ITEM_DATA_SHEET); 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()); validateResultBases(data.partItemBases(), data.partItemData());
validateCategoryConsistency(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<PartItemBaseRow> bases, List<PartItemDataRow> data) { private void validateResultBases(List<PartItemBaseRow> bases, List<PartItemDataRow> data) {
Set<ResultSeriesKey> baseKeys = uniqueKeys(bases, Set<ResultSeriesKey> baseKeys = uniqueKeys(bases,
row -> new ResultSeriesKey( row -> new ResultSeriesKey(
@@ -400,7 +480,7 @@ public class ExcelImportValidator {
"Sub가 있는 문항의 part_item_sub_cd는 필수입니다: " + itemKey); "Sub가 있는 문항의 part_item_sub_cd는 필수입니다: " + itemKey);
} }
if (!subKeys.contains(new SubKey(waveCd, partCd, partItemCd, partItemSubCd))) { if (!subKeys.contains(new SubKey(waveCd, partCd, partItemCd, partItemSubCd))) {
throw relationshipError(sheetName, "존재하지 않는 Sub를 참조합니다: " + partItemSubCd); throw relationshipError(sheetName, "존재하지 않는 Sub를 참조합니다: " + partItemCd + "/" + partItemSubCd);
} }
} else if (partItemSubCd != null) { } else if (partItemSubCd != null) {
throw relationshipError(sheetName, 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) { private String requiredRaw(String rawValue, String column, RowContext context) {
String value = normalized(rawValue); String value = normalized(rawValue);
if (value == null) { if (value == null) {

View File

@@ -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<Short> waveCodes) {
waveCodes.forEach(this::resetWave);
}
}

View File

@@ -3,7 +3,10 @@ package com.kri.epolicy.dash.back.service;
import com.kri.common.feature.excel.ExcelMapper; import com.kri.common.feature.excel.ExcelMapper;
import com.kri.common.feature.web.BusinessException; import com.kri.common.feature.web.BusinessException;
import com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows; 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_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_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_SHEET;
import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.PART_ITEM_SUB_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 static final String TEMPLATE_FILENAME = "epolicy-data-template.xlsx";
public byte[] createTemplate() { public byte[] createTemplate() {
return createWorkbook(ExcelWorkbookData.empty());
}
public byte[] createWorkbook(ExcelWorkbookData data) {
try (Workbook workbook = ExcelMapper.writeToWorkbook( try (Workbook workbook = ExcelMapper.writeToWorkbook(
List.<ExcelTemplateRows.Wave>of(), ExcelTemplateRows.Wave.class, WAVE_SHEET); data.waves(), ExcelTemplateRows.Wave.class, WAVE_SHEET);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
append(workbook, WAVE_INFO_SHEET, ExcelTemplateRows.WaveInfo.class); append(workbook, WAVE_INFO_SHEET, data.waveInfos(), ExcelTemplateRows.WaveInfo.class);
append(workbook, SURVEY_SHEET, ExcelTemplateRows.Survey.class); append(workbook, SURVEY_SHEET, data.surveys(), ExcelTemplateRows.Survey.class);
append(workbook, SURVEY_ITEM_SHEET, ExcelTemplateRows.SurveyItem.class); append(workbook, SURVEY_ITEM_SHEET, data.surveyItems(), ExcelTemplateRows.SurveyItem.class);
append(workbook, PART_SHEET, ExcelTemplateRows.Part.class); append(workbook, PART_SHEET, data.parts(), ExcelTemplateRows.Part.class);
append(workbook, PART_ITEM_SHEET, ExcelTemplateRows.PartItem.class); append(workbook, PART_ITEM_SHEET, data.partItems(), ExcelTemplateRows.PartItem.class);
append(workbook, PART_ITEM_SUB_SHEET, ExcelTemplateRows.PartItemSub.class); append(workbook, PART_ITEM_SUB_SHEET, data.partItemSubs(),
append(workbook, PART_ITEM_BASE_SHEET, ExcelTemplateRows.PartItemBase.class); ExcelTemplateRows.PartItemSub.class);
append(workbook, PART_ITEM_DATA_SHEET, ExcelTemplateRows.PartItemData.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); workbook.write(outputStream);
return outputStream.toByteArray(); return outputStream.toByteArray();
} catch (IOException | RuntimeException exception) { } catch (IOException | RuntimeException exception) {
@@ -45,7 +59,12 @@ public class ExcelTemplateService {
} }
} }
private <T> void append(Workbook workbook, String sheetName, Class<T> rowType) { private <T> void append(
ExcelMapper.appendSheetToWorkbook(workbook, List.of(), rowType, sheetName, 1); Workbook workbook,
String sheetName,
List<T> rows,
Class<T> rowType
) {
ExcelMapper.appendSheetToWorkbook(workbook, rows, rowType, sheetName, 1);
} }
} }

View File

@@ -2,6 +2,8 @@ package com.kri.epolicy.dash.back.service;
import com.kri.common.feature.web.BusinessException; import com.kri.common.feature.web.BusinessException;
import com.kri.common.feature.web.RequestUserContext; 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.config.FileStorageProperties;
import com.kri.epolicy.dash.back.dto.response.PartDetailResponse; import com.kri.epolicy.dash.back.dto.response.PartDetailResponse;
import com.kri.epolicy.dash.back.dto.response.PartDetailResponse.Audience; 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.TFileEntity;
import com.kri.epolicy.dash.back.persistence.entity.TPartEntity; 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.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.TPartItemDataEntity;
import com.kri.epolicy.dash.back.persistence.entity.TPartItemEntity; import com.kri.epolicy.dash.back.persistence.entity.TPartItemEntity;
import com.kri.epolicy.dash.back.persistence.entity.TPartItemSubEntity; 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.entity.id.TPartEntityId;
import com.kri.epolicy.dash.back.persistence.repository.FileRepository; 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.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.PartItemDataRepository;
import com.kri.epolicy.dash.back.persistence.repository.PartItemRepository; 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.PartItemSubRepository;
@@ -38,6 +44,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -60,6 +67,8 @@ public class WaveQueryService {
private final PartItemRepository partItemRepository; private final PartItemRepository partItemRepository;
private final PartItemSubRepository partItemSubRepository; private final PartItemSubRepository partItemSubRepository;
private final PartItemBaseRepository partItemBaseRepository; private final PartItemBaseRepository partItemBaseRepository;
private final PartItemChartRepository partItemChartRepository;
private final PartItemChartHighlightRepository partItemChartHighlightRepository;
private final PartItemDataRepository partItemDataRepository; private final PartItemDataRepository partItemDataRepository;
private final WaveAccessPolicy waveAccessPolicy; private final WaveAccessPolicy waveAccessPolicy;
private final FileStorageProperties fileStorageProperties; private final FileStorageProperties fileStorageProperties;
@@ -134,6 +143,10 @@ public class WaveQueryService {
List<TPartItemSubEntity> subs = partItemSubRepository List<TPartItemSubEntity> subs = partItemSubRepository
.findByIdWaveCdAndIdPartCdOrderByIdPartItemCdAscIdPartItemSubCdAsc(waveCd, partCd); .findByIdWaveCdAndIdPartCdOrderByIdPartItemCdAscIdPartItemSubCdAsc(waveCd, partCd);
List<TPartItemBaseEntity> bases = partItemBaseRepository.findByWaveCdAndPartCd(waveCd, partCd); List<TPartItemBaseEntity> bases = partItemBaseRepository.findByWaveCdAndPartCd(waveCd, partCd);
List<TPartItemChartEntity> charts = partItemChartRepository
.findByWaveCdAndPartCd(waveCd, partCd);
List<TPartItemChartHighlightEntity> highlights = partItemChartHighlightRepository
.findByWaveCdAndPartCd(waveCd, partCd);
List<TPartItemDataEntity> data = partItemDataRepository List<TPartItemDataEntity> data = partItemDataRepository
.findByWaveCdAndPartCdOrderByPartItemDataOrderAsc(waveCd, partCd); .findByWaveCdAndPartCdOrderByPartItemDataOrderAsc(waveCd, partCd);
@@ -144,7 +157,8 @@ public class WaveQueryService {
waveCd, waveCd,
partCd, partCd,
part.getPartTitle(), 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() .toList()
); );
} }
@@ -155,6 +169,8 @@ public class WaveQueryService {
Map<Short, TSurveyEntity> surveyByCode, Map<Short, TSurveyEntity> surveyByCode,
Map<Short, List<TPartItemSubEntity>> subsByItem, Map<Short, List<TPartItemSubEntity>> subsByItem,
List<TPartItemBaseEntity> allBases, List<TPartItemBaseEntity> allBases,
List<TPartItemChartEntity> allCharts,
List<TPartItemChartHighlightEntity> allHighlights,
List<TPartItemDataEntity> allData List<TPartItemDataEntity> allData
) { ) {
Short itemCd = item.getId().getPartItemCd(); Short itemCd = item.getId().getPartItemCd();
@@ -162,17 +178,30 @@ public class WaveQueryService {
.filter(base -> base.getPartItemCd().equals(itemCd)).toList(); .filter(base -> base.getPartItemCd().equals(itemCd)).toList();
List<TPartItemDataEntity> data = allData.stream() List<TPartItemDataEntity> data = allData.stream()
.filter(value -> value.getPartItemCd().equals(itemCd)).toList(); .filter(value -> value.getPartItemCd().equals(itemCd)).toList();
List<TPartItemChartEntity> charts = allCharts.stream()
.filter(chart -> chart.getPartItemCd().equals(itemCd)).toList();
List<TPartItemChartHighlightEntity> highlights = allHighlights.stream()
.filter(highlight -> highlight.getPartItemCd().equals(itemCd)).toList();
List<TPartItemSubEntity> subs = subsByItem.getOrDefault(itemCd, List.of()); List<TPartItemSubEntity> subs = subsByItem.getOrDefault(itemCd, List.of());
List<ResultGroup> groups = new ArrayList<>(); List<ResultGroup> groups = new ArrayList<>();
if (subs.isEmpty()) { 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 { } else {
for (TPartItemSubEntity sub : subs) { for (TPartItemSubEntity sub : subs) {
Short subCd = sub.getId().getPartItemSubCd(); Short subCd = sub.getId().getPartItemSubCd();
groups.add(toResultGroup( groups.add(toResultGroup(
new SubItem(subCd, sub.getPartItemSubTitle()), new SubItem(subCd, sub.getPartItemSubTitle(), sub.getPartItemSubComment()),
bases.stream().filter(base -> subCd.equals(base.getPartItemSubCd())).toList(), 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(), data.stream().filter(value -> subCd.equals(value.getPartItemSubCd())).toList(),
surveyByCode)); surveyByCode));
} }
@@ -185,7 +214,6 @@ public class WaveQueryService {
itemCd, itemCd,
item.getPartItemOrder(), item.getPartItemOrder(),
item.getPartItemTitle(), item.getPartItemTitle(),
item.getChartType().getCode(),
item.getPartItemComment(), item.getPartItemComment(),
toAudience(audienceCodes, surveys, surveyByCode), toAudience(audienceCodes, surveys, surveyByCode),
List.copyOf(groups) List.copyOf(groups)
@@ -195,12 +223,21 @@ public class WaveQueryService {
private ResultGroup toResultGroup( private ResultGroup toResultGroup(
SubItem subItem, SubItem subItem,
List<TPartItemBaseEntity> bases, List<TPartItemBaseEntity> bases,
List<TPartItemChartEntity> charts,
List<TPartItemChartHighlightEntity> highlights,
List<TPartItemDataEntity> data, List<TPartItemDataEntity> data,
Map<Short, TSurveyEntity> surveyByCode Map<Short, TSurveyEntity> surveyByCode
) { ) {
Map<Short, TPartItemBaseEntity> baseBySurvey = bases.stream().collect(Collectors.toMap( Map<Short, TPartItemBaseEntity> baseBySurvey = bases.stream().collect(Collectors.toMap(
TPartItemBaseEntity::getSurveyCd, Function.identity(), (left, right) -> left, TPartItemBaseEntity::getSurveyCd, Function.identity(), (left, right) -> left,
LinkedHashMap::new)); LinkedHashMap::new));
Map<Short, TPartItemChartEntity> chartBySurvey = charts.stream().collect(Collectors.toMap(
TPartItemChartEntity::getSurveyCd, Function.identity(), (left, right) -> left,
LinkedHashMap::new));
Map<Short, TPartItemChartHighlightEntity> highlightBySurvey = highlights.stream()
.collect(Collectors.toMap(
TPartItemChartHighlightEntity::getSurveyCd, Function.identity(),
(left, right) -> left, LinkedHashMap::new));
Map<Short, List<TPartItemDataEntity>> dataBySurvey = data.stream().collect( Map<Short, List<TPartItemDataEntity>> dataBySurvey = data.stream().collect(
Collectors.groupingBy(TPartItemDataEntity::getSurveyCd, Collectors.groupingBy(TPartItemDataEntity::getSurveyCd,
LinkedHashMap::new, Collectors.toList())); LinkedHashMap::new, Collectors.toList()));
@@ -218,10 +255,20 @@ public class WaveQueryService {
List<Series> series = surveyCodes.stream().map(surveyCd -> { List<Series> series = surveyCodes.stream().map(surveyCd -> {
TPartItemBaseEntity base = baseBySurvey.get(surveyCd); TPartItemBaseEntity base = baseBySurvey.get(surveyCd);
TSurveyEntity survey = surveyByCode.get(surveyCd); TSurveyEntity survey = surveyByCode.get(surveyCd);
TPartItemChartEntity chart = chartBySurvey.get(surveyCd);
TPartItemChartHighlightEntity highlight = highlightBySurvey.get(surveyCd);
return new Series( return new Series(
surveyCd, surveyCd,
survey.getSurveyAlias(), 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.getBaseCount(),
base == null ? null : base.getBaseText(), base == null ? null : base.getBaseText(),
dataBySurvey.get(surveyCd).stream() dataBySurvey.get(surveyCd).stream()
@@ -244,7 +291,7 @@ public class WaveQueryService {
} }
String label = audienceCodes.stream() String label = audienceCodes.stream()
.map(surveyByCode::get) .map(surveyByCode::get)
.filter(java.util.Objects::nonNull) .filter(Objects::nonNull)
.sorted(Comparator.comparing(TSurveyEntity::getSurveyOrder)) .sorted(Comparator.comparing(TSurveyEntity::getSurveyOrder))
.map(TSurveyEntity::getSurveyAlias) .map(TSurveyEntity::getSurveyAlias)
.collect(Collectors.joining(", ")); .collect(Collectors.joining(", "));