260813_01_FST: First Commit
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.kri.epolicy.dash.back;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ConfigurationPropertiesScan
|
||||
public class EpolicyDashBackApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EpolicyDashBackApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.kri.epolicy.dash.back.common.enums;
|
||||
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum ChartType implements CodeEnum<String> {
|
||||
BAR("BAR", "bar");
|
||||
|
||||
private final String code;
|
||||
private final String label;
|
||||
|
||||
ChartType(String code, String label) {
|
||||
this.code = code;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public static ChartType fromLabel(String label) {
|
||||
return Arrays.stream(values())
|
||||
.filter(type -> type.label.equalsIgnoreCase(label))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException("지원하지 않는 차트 유형입니다: " + label));
|
||||
}
|
||||
|
||||
public static ChartType fromCode(String code) {
|
||||
return Arrays.stream(values())
|
||||
.filter(type -> type.code.equalsIgnoreCase(code))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException("지원하지 않는 차트 코드입니다: " + code));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.kri.epolicy.dash.back.common.enums;
|
||||
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
@Schema(description = "시스템 이벤트 타입")
|
||||
public enum SystemEventType implements CodeEnum<Short> {
|
||||
//1의 자리 1 insert, 2 update, 3 delete, 4 upload
|
||||
//100의 자리 대분류, 10의 자리 소분류
|
||||
|
||||
LOGIN((short) 111), // 로그인
|
||||
LOGOUT((short) 121), // 로그 아웃
|
||||
|
||||
DUMMY((short) 9999);
|
||||
|
||||
private final Short code;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.kri.epolicy.dash.back.common.util;
|
||||
|
||||
public final class StringNormalizer {
|
||||
|
||||
private StringNormalizer() {
|
||||
}
|
||||
|
||||
public static String trimToNull(String value) {
|
||||
if (value == null) return null;
|
||||
String normalized = value.trim();
|
||||
return normalized.isEmpty() ? null : normalized;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 프로젝트 전용 Bean Validation annotation과 validator를 배치합니다.
|
||||
*/
|
||||
package com.kri.epolicy.dash.back.common.validation;
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.kri.epolicy.dash.back.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigurationProperties(prefix = "kri.file")
|
||||
public class FileStorageProperties {
|
||||
|
||||
private String baseDir = "./upload-file";
|
||||
private String resourcePattern = "/files/**";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.kri.epolicy.dash.back.config;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
@Configuration
|
||||
public class JdbcConfig {
|
||||
|
||||
@Bean
|
||||
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
|
||||
return new JdbcTemplate(dataSource);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.kri.epolicy.dash.back.config;
|
||||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class QueryDSLConfig {
|
||||
|
||||
private final EntityManager entityManager;
|
||||
|
||||
@Bean
|
||||
public JPAQueryFactory jpaQueryFactory() {
|
||||
return new JPAQueryFactory(entityManager);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.kri.epolicy.dash.back.config;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class WebResourceConfig implements WebMvcConfigurer {
|
||||
|
||||
private final FileStorageProperties fileStorageProperties;
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
String location = Path.of(fileStorageProperties.getBaseDir())
|
||||
.toAbsolutePath()
|
||||
.normalize()
|
||||
.toUri()
|
||||
.toString();
|
||||
|
||||
registry.addResourceHandler(fileStorageProperties.getResourcePattern())
|
||||
.addResourceLocations(location.endsWith("/") ? location : location + "/");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.kri.epolicy.dash.back.controller;
|
||||
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.epolicy.dash.back.dto.auth.LoginRequestDto;
|
||||
import com.kri.epolicy.dash.back.dto.auth.LoginResponseDto;
|
||||
import com.kri.epolicy.dash.back.service.AuthService;
|
||||
import com.kri.epolicy.dash.back.service.common.SystemEventLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/auth")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Auth", description = "인증 API")
|
||||
public class AuthController {
|
||||
|
||||
private final AuthService authService;
|
||||
private final SystemEventLogService systemEventLogService;
|
||||
|
||||
@Operation(summary = "로그인 요청")
|
||||
@PostMapping("/login")
|
||||
public LoginResponseDto tryLogin(
|
||||
@Valid @RequestBody LoginRequestDto request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
|
||||
LoginResponseDto response = authService.tryLogin(request);
|
||||
systemEventLogService.writeLoginLog(response.getUser().getUserId(), now, ctx.getClientIp());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Operation(summary = "로그아웃 요청")
|
||||
@PostMapping("/logout/{userId}")
|
||||
public boolean logout(@PathVariable String userId, RequestUserContext ctx) {
|
||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
|
||||
systemEventLogService.writeLogoutLog(userId, now, ctx.getClientIp());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.kri.epolicy.dash.back.controller;
|
||||
|
||||
import com.kri.epolicy.dash.back.dto.response.ExcelImportResponse;
|
||||
import com.kri.epolicy.dash.back.service.ExcelImportService;
|
||||
import com.kri.epolicy.dash.back.service.ExcelTemplateService;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ContentDisposition;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/v1/excel")
|
||||
public class ExcelController {
|
||||
|
||||
private final ExcelImportService excelImportService;
|
||||
private final ExcelTemplateService excelTemplateService;
|
||||
|
||||
@PostMapping(value = "/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ExcelImportResponse importExcel(@RequestPart("file") MultipartFile file) {
|
||||
return excelImportService.importWorkbook(file);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/template", produces = ExcelTemplateService.EXCEL_CONTENT_TYPE)
|
||||
public ResponseEntity<byte[]> exportTemplate() {
|
||||
ContentDisposition disposition = ContentDisposition.attachment()
|
||||
.filename(ExcelTemplateService.TEMPLATE_FILENAME, StandardCharsets.UTF_8)
|
||||
.build();
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, disposition.toString())
|
||||
.contentType(MediaType.parseMediaType(ExcelTemplateService.EXCEL_CONTENT_TYPE))
|
||||
.body(excelTemplateService.createTemplate());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.kri.epolicy.dash.back.controller;
|
||||
|
||||
import com.kri.epolicy.dash.back.dto.response.ReferenceFileUploadResponse;
|
||||
import com.kri.epolicy.dash.back.service.ReferenceFileStorageService;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Validated
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/v1/references")
|
||||
public class ReferenceFileController {
|
||||
|
||||
private final ReferenceFileStorageService referenceFileStorageService;
|
||||
|
||||
@PostMapping(value = "/{waveCd}/files", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ReferenceFileUploadResponse upload(
|
||||
@PathVariable @Positive Short waveCd,
|
||||
@RequestParam("fileTitle") @NotBlank @Size(max = 128) String fileTitle,
|
||||
@RequestParam("fileOrder") @Positive Short fileOrder,
|
||||
@RequestPart("file") MultipartFile file
|
||||
) {
|
||||
return referenceFileStorageService.store(waveCd, fileTitle, fileOrder, file);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.kri.epolicy.dash.back.controller;
|
||||
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.epolicy.dash.back.dto.response.PartDetailResponse;
|
||||
import com.kri.epolicy.dash.back.dto.response.WaveDetailResponse;
|
||||
import com.kri.epolicy.dash.back.dto.response.WaveSummaryResponse;
|
||||
import com.kri.epolicy.dash.back.service.WaveQueryService;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/v1/waves")
|
||||
public class WaveController {
|
||||
|
||||
private final WaveQueryService waveQueryService;
|
||||
|
||||
@GetMapping
|
||||
public List<WaveSummaryResponse> findWaves(RequestUserContext userContext) {
|
||||
return waveQueryService.findWaves(userContext);
|
||||
}
|
||||
|
||||
@GetMapping("/{waveCd}")
|
||||
public WaveDetailResponse findWave(
|
||||
@PathVariable Short waveCd,
|
||||
RequestUserContext userContext
|
||||
) {
|
||||
return waveQueryService.findWave(waveCd, userContext);
|
||||
}
|
||||
|
||||
@GetMapping("/{waveCd}/parts/{partCd}")
|
||||
public PartDetailResponse findPart(
|
||||
@PathVariable Short waveCd,
|
||||
@PathVariable Short partCd,
|
||||
RequestUserContext userContext
|
||||
) {
|
||||
return waveQueryService.findPart(waveCd, partCd, userContext);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.kri.epolicy.dash.back.dto.auth;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "사용자 로그인 요청")
|
||||
public class LoginRequestDto {
|
||||
|
||||
@Schema(description = "사용자 ID")
|
||||
private String userId;
|
||||
|
||||
@Schema(description = "사용자 PW")
|
||||
private String userPw;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.kri.epolicy.dash.back.dto.auth;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@Schema(description = "로그인 응답")
|
||||
public class LoginResponseDto {
|
||||
|
||||
@Schema(description = "jwt access 토큰")
|
||||
private String accessToken;
|
||||
|
||||
@Schema(description = "사용자 정보")
|
||||
private UserDto user;
|
||||
|
||||
public static LoginResponseDto from(String accessToken, UserDto user) {
|
||||
return LoginResponseDto.builder()
|
||||
.accessToken(accessToken)
|
||||
.user(user)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.kri.epolicy.dash.back.dto.auth;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TUserEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserDto {
|
||||
|
||||
@Schema(description = "사용자 ID")
|
||||
private String userId;
|
||||
|
||||
@Schema(description = "사용자 소속 회사")
|
||||
private String userCmpn;
|
||||
|
||||
@Schema(description = "팀 코드")
|
||||
private String userTeam;
|
||||
|
||||
@Schema(description = "사용자 이름")
|
||||
private String userName;
|
||||
|
||||
@Schema(description = "권한 코드")
|
||||
private Integer userRole;
|
||||
|
||||
public static UserDto from(TUserEntity entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return UserDto.builder()
|
||||
.userId(entity.getUserId())
|
||||
.userName(entity.getUserName())
|
||||
.userCmpn(entity.getUserCmpn())
|
||||
.userTeam(entity.getUserTeam())
|
||||
.userRole(entity.getUserRole())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.kri.epolicy.dash.back.dto.excel;
|
||||
|
||||
import com.kri.common.feature.excel.ExcelColumn;
|
||||
import lombok.Getter;
|
||||
|
||||
public final class ExcelTemplateRows {
|
||||
|
||||
public static final String WAVE_SHEET = "t_wave";
|
||||
public static final String WAVE_INFO_SHEET = "t_wave_info";
|
||||
public static final String SURVEY_SHEET = "t_survey";
|
||||
public static final String SURVEY_ITEM_SHEET = "t_survey_item";
|
||||
public static final String PART_SHEET = "t_part";
|
||||
public static final String PART_ITEM_SHEET = "t_part_item";
|
||||
public static final String PART_ITEM_SUB_SHEET = "t_part_item_sub";
|
||||
public static final String PART_ITEM_BASE_SHEET = "t_part_item_base";
|
||||
public static final String PART_ITEM_DATA_SHEET = "t_part_item_data";
|
||||
|
||||
private ExcelTemplateRows() {
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class Wave {
|
||||
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
|
||||
@ExcelColumn(header = "year", order = 1) private String year;
|
||||
@ExcelColumn(header = "wave", order = 2) private String wave;
|
||||
@ExcelColumn(header = "label", order = 3) private String label;
|
||||
@ExcelColumn(header = "is_open (1, 0)", order = 4) private String isOpen;
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class WaveInfo {
|
||||
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
|
||||
@ExcelColumn(header = "wave_info_order", order = 1) private String waveInfoOrder;
|
||||
@ExcelColumn(header = "wave_info_title", order = 2) private String waveInfoTitle;
|
||||
@ExcelColumn(header = "wave_info_content", order = 3) private String waveInfoContent;
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class Survey {
|
||||
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
|
||||
@ExcelColumn(header = "survey_cd", order = 1) private String surveyCd;
|
||||
@ExcelColumn(header = "survey_order", order = 2) private String surveyOrder;
|
||||
@ExcelColumn(header = "survey_title", order = 3) private String surveyTitle;
|
||||
@ExcelColumn(header = "survey_alias", order = 4) private String surveyAlias;
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class SurveyItem {
|
||||
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
|
||||
@ExcelColumn(header = "survey_cd", order = 1) private String surveyCd;
|
||||
@ExcelColumn(header = "survey_item_order", order = 2) private String surveyItemOrder;
|
||||
@ExcelColumn(header = "survey_item_title", order = 3) private String surveyItemTitle;
|
||||
@ExcelColumn(header = "survey_item_content", order = 4) private String surveyItemContent;
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class Part {
|
||||
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
|
||||
@ExcelColumn(header = "part_cd", order = 1) private String partCd;
|
||||
@ExcelColumn(header = "part_order", order = 2) private String partOrder;
|
||||
@ExcelColumn(header = "part_title", order = 3) private String partTitle;
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class PartItem {
|
||||
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
|
||||
@ExcelColumn(header = "part_cd", order = 1) private String partCd;
|
||||
@ExcelColumn(header = "part_item_cd", order = 2) private String partItemCd;
|
||||
@ExcelColumn(header = "part_item_order", order = 3) private String partItemOrder;
|
||||
@ExcelColumn(header = "part_item_title", order = 4) private String partItemTitle;
|
||||
@ExcelColumn(header = "chart_type (bar)", order = 5) private String chartType;
|
||||
@ExcelColumn(header = "part_item_comment", order = 6) private String partItemComment;
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class PartItemSub {
|
||||
@ExcelColumn(header = "wave_cd", order = 0) private String waveCd;
|
||||
@ExcelColumn(header = "part_cd", order = 1) private String partCd;
|
||||
@ExcelColumn(header = "part_item_cd", order = 2) private String partItemCd;
|
||||
@ExcelColumn(header = "part_item_sub_cd", order = 3) private String partItemSubCd;
|
||||
@ExcelColumn(header = "part_item_sub_title", order = 4) private String partItemSubTitle;
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class PartItemBase {
|
||||
@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 = "base_count", order = 5) private String baseCount;
|
||||
@ExcelColumn(header = "base_pre_text", order = 6) private String basePreText;
|
||||
@ExcelColumn(header = "base_post_text", order = 7) private String basePostText;
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class PartItemData {
|
||||
@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 = "part_item_data_order", order = 5) private String partItemDataOrder;
|
||||
@ExcelColumn(header = "part_item_data_label", order = 6) private String partItemDataLabel;
|
||||
@ExcelColumn(header = "part_item_data_value", order = 7) private String partItemDataValue;
|
||||
@ExcelColumn(header = "is_chart_visible (1, 0)", order = 8) private String isChartVisible;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.kri.epolicy.dash.back.dto.request;
|
||||
|
||||
import com.kri.epolicy.dash.back.common.enums.ChartType;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public record ExcelData(
|
||||
List<WaveRow> waves,
|
||||
List<WaveInfoRow> waveInfos,
|
||||
List<SurveyRow> surveys,
|
||||
List<SurveyItemRow> surveyItems,
|
||||
List<PartRow> parts,
|
||||
List<PartItemRow> partItems,
|
||||
List<PartItemSubRow> partItemSubs,
|
||||
List<PartItemBaseRow> partItemBases,
|
||||
List<PartItemDataRow> partItemData
|
||||
) {
|
||||
|
||||
public record WaveRow(
|
||||
Short waveCd,
|
||||
Short year,
|
||||
Short wave,
|
||||
String label,
|
||||
Boolean isOpen
|
||||
) {
|
||||
}
|
||||
|
||||
public record WaveInfoRow(
|
||||
Short waveCd,
|
||||
Short waveInfoOrder,
|
||||
String waveInfoTitle,
|
||||
String waveInfoContent
|
||||
) {
|
||||
}
|
||||
|
||||
public record SurveyRow(
|
||||
Short waveCd,
|
||||
Short surveyCd,
|
||||
Short surveyOrder,
|
||||
String surveyTitle,
|
||||
String surveyAlias
|
||||
) {
|
||||
}
|
||||
|
||||
public record SurveyItemRow(
|
||||
Short waveCd,
|
||||
Short surveyCd,
|
||||
Short surveyItemOrder,
|
||||
String surveyItemTitle,
|
||||
String surveyItemContent
|
||||
) {
|
||||
}
|
||||
|
||||
public record PartRow(
|
||||
Short waveCd,
|
||||
Short partCd,
|
||||
Short partOrder,
|
||||
String partTitle
|
||||
) {
|
||||
}
|
||||
|
||||
public record PartItemRow(
|
||||
Short waveCd,
|
||||
Short partCd,
|
||||
Short partItemCd,
|
||||
Short partItemOrder,
|
||||
String partItemTitle,
|
||||
ChartType chartType,
|
||||
String partItemComment
|
||||
) {
|
||||
}
|
||||
|
||||
public record PartItemSubRow(
|
||||
Short waveCd,
|
||||
Short partCd,
|
||||
Short partItemCd,
|
||||
Short partItemSubCd,
|
||||
String partItemSubTitle
|
||||
) {
|
||||
}
|
||||
|
||||
public record PartItemBaseRow(
|
||||
Short waveCd,
|
||||
Short partCd,
|
||||
Short partItemCd,
|
||||
Short surveyCd,
|
||||
Short partItemSubCd,
|
||||
Integer baseCount,
|
||||
String basePreText,
|
||||
String basePostText
|
||||
) {
|
||||
}
|
||||
|
||||
public record PartItemDataRow(
|
||||
Short waveCd,
|
||||
Short partCd,
|
||||
Short partItemCd,
|
||||
Short surveyCd,
|
||||
Short partItemSubCd,
|
||||
Short partItemDataOrder,
|
||||
String partItemDataLabel,
|
||||
BigDecimal partItemDataValue,
|
||||
Boolean isChartVisible
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.kri.epolicy.dash.back.dto.response;
|
||||
|
||||
public record ExcelImportResponse(
|
||||
int waveCount,
|
||||
int waveInfoCount,
|
||||
int surveyCount,
|
||||
int surveyItemCount,
|
||||
int partCount,
|
||||
int partItemCount,
|
||||
int partItemSubCount,
|
||||
int partItemBaseCount,
|
||||
int partItemDataCount
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.kri.epolicy.dash.back.dto.response;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public record PartDetailResponse(
|
||||
Short waveCd,
|
||||
Short partCd,
|
||||
String title,
|
||||
List<Item> items
|
||||
) {
|
||||
|
||||
public record Item(
|
||||
Short partItemCd,
|
||||
Short order,
|
||||
String title,
|
||||
String chartType,
|
||||
String comment,
|
||||
Audience audience,
|
||||
List<ResultGroup> resultGroups
|
||||
) {
|
||||
}
|
||||
|
||||
public record Audience(String type, String label) {
|
||||
}
|
||||
|
||||
public record ResultGroup(
|
||||
SubItem subItem,
|
||||
List<Category> categories,
|
||||
List<Series> series
|
||||
) {
|
||||
}
|
||||
|
||||
public record Category(
|
||||
Short order,
|
||||
String label,
|
||||
Boolean chartVisible
|
||||
) {
|
||||
}
|
||||
|
||||
public record SubItem(Short partItemSubCd, String title) {
|
||||
}
|
||||
|
||||
public record Series(
|
||||
Short surveyCd,
|
||||
String label,
|
||||
Integer baseCount,
|
||||
String baseText,
|
||||
List<BigDecimal> values
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.kri.epolicy.dash.back.dto.response;
|
||||
|
||||
public record ReferenceFileUploadResponse(
|
||||
Integer fileIdx,
|
||||
Short waveCd,
|
||||
Short fileOrder,
|
||||
String fileTitle,
|
||||
String fileType,
|
||||
String originalFilename,
|
||||
long size,
|
||||
String relativePath
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.kri.epolicy.dash.back.dto.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record WaveDetailResponse(
|
||||
WaveSummaryResponse wave,
|
||||
List<OverviewItem> overview,
|
||||
List<Survey> surveys,
|
||||
List<PartMenu> parts,
|
||||
List<FileDownload> files
|
||||
) {
|
||||
|
||||
public record OverviewItem(String title, String content) {
|
||||
}
|
||||
|
||||
public record Survey(
|
||||
Short surveyCd,
|
||||
String title,
|
||||
String alias,
|
||||
List<SurveyItem> items
|
||||
) {
|
||||
}
|
||||
|
||||
public record SurveyItem(String title, String content) {
|
||||
}
|
||||
|
||||
public record PartMenu(
|
||||
Short partCd,
|
||||
String title,
|
||||
int itemCount,
|
||||
List<PartItemMenu> items
|
||||
) {
|
||||
}
|
||||
|
||||
public record PartItemMenu(Short partItemCd, String title) {
|
||||
}
|
||||
|
||||
public record FileDownload(
|
||||
Integer fileIdx,
|
||||
String title,
|
||||
String type,
|
||||
String fileName,
|
||||
String downloadUrl
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.kri.epolicy.dash.back.dto.response;
|
||||
|
||||
public record WaveSummaryResponse(
|
||||
Short waveCd,
|
||||
Short year,
|
||||
Short wave,
|
||||
String label,
|
||||
Boolean isOpen,
|
||||
boolean accessible
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.kri.epolicy.dash.back.persistence.converter;
|
||||
|
||||
import com.kri.common.feature.jpa.AbstractCodeEnumConverter;
|
||||
import com.kri.epolicy.dash.back.common.enums.ChartType;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
@Converter
|
||||
public class ChartTypeConverter extends AbstractCodeEnumConverter<ChartType, String> {
|
||||
|
||||
public ChartTypeConverter() {
|
||||
super(ChartType.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
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_file")
|
||||
public class TFileEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "file_idx", nullable = false, updatable = false)
|
||||
private Integer id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "wave_cd", nullable = false)
|
||||
private Short waveCd;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "file_order", nullable = false)
|
||||
private Short fileOrder;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "file_title", nullable = false, length = 128)
|
||||
private String fileTitle;
|
||||
|
||||
@Size(max = 16)
|
||||
@NotNull
|
||||
@Column(name = "file_type", nullable = false, length = 16)
|
||||
private String fileType;
|
||||
|
||||
@Size(max = 64)
|
||||
@NotNull
|
||||
@Column(name = "file_name", nullable = false, length = 64)
|
||||
private String fileName;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TPartEntityId;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
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")
|
||||
public class TPartEntity {
|
||||
|
||||
@EmbeddedId
|
||||
private TPartEntityId id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "part_order", nullable = false)
|
||||
private Short partOrder;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "part_title", nullable = false, length = 128)
|
||||
private String partTitle;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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_base")
|
||||
public class TPartItemBaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "part_item_base_idx", nullable = false, updatable = 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;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "base_count", nullable = false)
|
||||
private Integer baseCount;
|
||||
|
||||
@Size(max = 128)
|
||||
@Column(name = "base_pre_text", length = 128)
|
||||
private String basePreText;
|
||||
|
||||
@Size(max = 128)
|
||||
@Column(name = "base_post_text", length = 128)
|
||||
private String basePostText;
|
||||
|
||||
|
||||
}
|
||||
@@ -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 java.math.BigDecimal;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "t_part_item_data")
|
||||
public class TPartItemDataEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "t_part_item_data_idx", nullable = false, updatable = 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;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "part_item_data_order", nullable = false)
|
||||
private Short partItemDataOrder;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "part_item_data_label", nullable = false, length = 128)
|
||||
private String partItemDataLabel;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "part_item_data_value", nullable = false, precision = 14, scale = 10)
|
||||
private BigDecimal partItemDataValue;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "is_chart_visible", nullable = false)
|
||||
private Boolean isChartVisible;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemEntityId;
|
||||
import com.kri.epolicy.dash.back.common.enums.ChartType;
|
||||
import com.kri.epolicy.dash.back.persistence.converter.ChartTypeConverter;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Convert;
|
||||
import jakarta.persistence.Lob;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "t_part_item")
|
||||
public class TPartItemEntity {
|
||||
|
||||
@EmbeddedId
|
||||
private TPartItemEntityId id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "part_item_order", nullable = false)
|
||||
private Short partItemOrder;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "part_item_title", nullable = false, length = 128)
|
||||
private String partItemTitle;
|
||||
|
||||
@NotNull
|
||||
@Convert(converter = ChartTypeConverter.class)
|
||||
@Column(name = "chart_type", nullable = false, length = 32)
|
||||
private ChartType chartType;
|
||||
|
||||
@NotNull
|
||||
@Lob
|
||||
@Column(name = "part_item_comment", nullable = false)
|
||||
private String partItemComment;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemSubEntityId;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.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_sub")
|
||||
public class TPartItemSubEntity {
|
||||
|
||||
@EmbeddedId
|
||||
private TPartItemSubEntityId id;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "part_item_sub_title", nullable = false, length = 128)
|
||||
private String partItemSubTitle;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TSurveyEntityId;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
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_survey")
|
||||
public class TSurveyEntity {
|
||||
|
||||
@EmbeddedId
|
||||
private TSurveyEntityId id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "survey_order", nullable = false)
|
||||
private Short surveyOrder;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "survey_title", nullable = false, length = 128)
|
||||
private String surveyTitle;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "survey_alias", nullable = false, length = 32)
|
||||
private String surveyAlias;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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.Lob;
|
||||
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_survey_item")
|
||||
public class TSurveyItemEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "survey_item_idx", nullable = false, updatable = false)
|
||||
private Integer id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "wave_cd", nullable = false)
|
||||
private Short waveCd;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "survey_cd", nullable = false)
|
||||
private Short surveyCd;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "survey_item_order", nullable = false)
|
||||
private Short surveyItemOrder;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "survey_item_title", nullable = false, length = 128)
|
||||
private String surveyItemTitle;
|
||||
|
||||
@NotNull
|
||||
@Lob
|
||||
@Column(name = "survey_item_content", nullable = false)
|
||||
private String surveyItemContent;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity;
|
||||
|
||||
import com.kri.epolicy.dash.back.common.enums.SystemEventType;
|
||||
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 java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.JdbcTypeCode;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
|
||||
@Getter @Setter @Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "t_sys_event_log")
|
||||
public class TSysEventLogEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "sys_event_log_idx", nullable = false, updatable = false)
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "event_ty", nullable = false)
|
||||
private Short eventTy;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "log_title", nullable = false, length = 128)
|
||||
private String logTitle;
|
||||
|
||||
@NotNull
|
||||
@JdbcTypeCode(SqlTypes.JSON)
|
||||
@Column(name = "log_content", nullable = false)
|
||||
private Map<String, Object> logContent;
|
||||
|
||||
@Size(max = 16)
|
||||
@NotNull
|
||||
@Column(name = "ip", nullable = false, length = 16)
|
||||
private String ip;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "reg_user", nullable = false, length = 32, updatable = false)
|
||||
private String regUser;
|
||||
|
||||
@NotNull
|
||||
@ColumnDefault("CURRENT_TIMESTAMP")
|
||||
@Column(name = "reg_dt", nullable = false, updatable = false)
|
||||
private LocalDateTime regDt;
|
||||
|
||||
public static TSysEventLogEntity of(
|
||||
SystemEventType eventType,
|
||||
String title,
|
||||
Map<String, Object> logContent,
|
||||
String clientIp,
|
||||
String regId,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
return TSysEventLogEntity.builder()
|
||||
.eventTy(eventType.getCode())
|
||||
.logTitle(title)
|
||||
.logContent(logContent)
|
||||
.ip(clientIp)
|
||||
.regUser(regId)
|
||||
.regDt(regDt)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Lob;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.time.Instant;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "t_user")
|
||||
public class TUserEntity {
|
||||
|
||||
@Id
|
||||
@Size(max = 32)
|
||||
@Column(name = "user_id", nullable = false, length = 32)
|
||||
private String userId;
|
||||
|
||||
@Size(max = 64)
|
||||
@NotNull
|
||||
@Column(name = "user_pw", nullable = false, length = 64)
|
||||
private String userPw;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "user_name", nullable = false, length = 32)
|
||||
private String userName;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "user_cmpn", nullable = false, length = 32)
|
||||
private String userCmpn;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "user_team", nullable = false, length = 32)
|
||||
private String userTeam;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "user_role", nullable = false)
|
||||
private Integer userRole;
|
||||
|
||||
@NotNull
|
||||
@Lob
|
||||
@Column(name = "memo", nullable = false)
|
||||
private String memo;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "reg_user", nullable = false, length = 32)
|
||||
private String regUser;
|
||||
|
||||
@NotNull
|
||||
@ColumnDefault("CURRENT_TIMESTAMP")
|
||||
@Column(name = "reg_dt", nullable = false)
|
||||
private Instant regDt;
|
||||
|
||||
@Size(max = 32)
|
||||
@Column(name = "mod_user", length = 32)
|
||||
private String modUser;
|
||||
|
||||
@Column(name = "mod_dt")
|
||||
private Instant modDt;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
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_wave")
|
||||
public class TWaveEntity {
|
||||
|
||||
@Id
|
||||
@Column(name = "wave_cd", nullable = false)
|
||||
private Short id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "year", nullable = false)
|
||||
private Short year;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "wave", nullable = false)
|
||||
private Short wave;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "label", nullable = false, length = 32)
|
||||
private String label;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "is_open", nullable = false)
|
||||
private Boolean isOpen;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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.Lob;
|
||||
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_wave_info")
|
||||
public class TWaveInfoEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "wave_info_idx", nullable = false, updatable = false)
|
||||
private Integer id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "wave_cd", nullable = false)
|
||||
private Short waveCd;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "wave_info_order", nullable = false)
|
||||
private Short waveInfoOrder;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "wave_info_title", nullable = false, length = 128)
|
||||
private String waveInfoTitle;
|
||||
|
||||
@NotNull
|
||||
@Lob
|
||||
@Column(name = "wave_info_content", nullable = false)
|
||||
private String waveInfoContent;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
@Embeddable
|
||||
public class TPartEntityId implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = -7363909224374172180L;
|
||||
@NotNull
|
||||
@Column(name = "wave_cd", nullable = false)
|
||||
private Short waveCd;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "part_cd", nullable = false)
|
||||
private Short partCd;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
@Embeddable
|
||||
public class TPartItemEntityId implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 6976667477724981830L;
|
||||
@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;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
@Embeddable
|
||||
public class TPartItemSubEntityId implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = -4801875494665947942L;
|
||||
@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 = "part_item_sub_cd", nullable = false)
|
||||
private Short partItemSubCd;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.kri.epolicy.dash.back.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
@Embeddable
|
||||
public class TSurveyEntityId implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = -5862749272106811476L;
|
||||
@NotNull
|
||||
@Column(name = "wave_cd", nullable = false)
|
||||
private Short waveCd;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "survey_cd", nullable = false)
|
||||
private Short surveyCd;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TFileEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface FileRepository extends JpaRepository<TFileEntity, Integer> {
|
||||
|
||||
List<TFileEntity> findByWaveCdOrderByFileOrderAsc(Short waveCd);
|
||||
|
||||
Optional<TFileEntity> findFirstByWaveCdAndFileName(Short waveCd, String fileName);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartItemBaseEntity;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PartItemBaseRepository extends JpaRepository<TPartItemBaseEntity, Integer> {
|
||||
|
||||
List<TPartItemBaseEntity> findByWaveCdAndPartCd(Short waveCd, Short partCd);
|
||||
|
||||
List<TPartItemBaseEntity> findByWaveCdIn(Collection<Short> waveCodes);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartItemDataEntity;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PartItemDataRepository extends JpaRepository<TPartItemDataEntity, Integer> {
|
||||
|
||||
List<TPartItemDataEntity> findByWaveCdAndPartCdOrderByPartItemDataOrderAsc(
|
||||
Short waveCd,
|
||||
Short partCd
|
||||
);
|
||||
|
||||
List<TPartItemDataEntity> findByWaveCdIn(Collection<Short> waveCodes);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartItemEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemEntityId;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.List;
|
||||
|
||||
public interface PartItemRepository
|
||||
extends JpaRepository<TPartItemEntity, TPartItemEntityId> {
|
||||
|
||||
List<TPartItemEntity> findByIdWaveCdOrderByPartItemOrderAsc(Short waveCd);
|
||||
|
||||
List<TPartItemEntity> findByIdWaveCdAndIdPartCdOrderByPartItemOrderAsc(
|
||||
Short waveCd,
|
||||
Short partCd
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartItemSubEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemSubEntityId;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.List;
|
||||
|
||||
public interface PartItemSubRepository
|
||||
extends JpaRepository<TPartItemSubEntity, TPartItemSubEntityId> {
|
||||
|
||||
List<TPartItemSubEntity> findByIdWaveCdAndIdPartCdOrderByIdPartItemCdAscIdPartItemSubCdAsc(
|
||||
Short waveCd,
|
||||
Short partCd
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TPartEntityId;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.List;
|
||||
|
||||
public interface PartRepository extends JpaRepository<TPartEntity, TPartEntityId> {
|
||||
|
||||
List<TPartEntity> findByIdWaveCdOrderByPartOrderAsc(Short waveCd);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TSurveyItemEntity;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface SurveyItemRepository
|
||||
extends JpaRepository<TSurveyItemEntity, Integer> {
|
||||
|
||||
List<TSurveyItemEntity> findByWaveCdOrderBySurveyItemOrderAsc(Short waveCd);
|
||||
|
||||
List<TSurveyItemEntity> findByWaveCdIn(Collection<Short> waveCodes);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TSurveyEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TSurveyEntityId;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.List;
|
||||
|
||||
public interface SurveyRepository extends JpaRepository<TSurveyEntity, TSurveyEntityId> {
|
||||
|
||||
List<TSurveyEntity> findByIdWaveCdOrderBySurveyOrderAsc(Short waveCd);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TSysEventLogEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface SysEventLogRepository extends JpaRepository<TSysEventLogEntity, Long> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TUserEntity;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UserRepository extends JpaRepository<TUserEntity, String> {
|
||||
Optional<TUserEntity> findByUserIdAndUserPw(String userId, String userPw);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TWaveInfoEntity;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface WaveInfoRepository extends JpaRepository<TWaveInfoEntity, Integer> {
|
||||
|
||||
List<TWaveInfoEntity> findByWaveCdOrderByWaveInfoOrderAsc(Short waveCd);
|
||||
|
||||
List<TWaveInfoEntity> findByWaveCdIn(Collection<Short> waveCodes);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.kri.epolicy.dash.back.persistence.repository;
|
||||
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TWaveEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.List;
|
||||
|
||||
public interface WaveRepository extends JpaRepository<TWaveEntity, Short> {
|
||||
|
||||
List<TWaveEntity> findAllByOrderByYearDescWaveDesc();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.kri.epolicy.dash.back.service;
|
||||
|
||||
import com.kri.common.feature.auth.dto.JwtUserClaimsDto;
|
||||
import com.kri.common.feature.auth.jwt.JwtService;
|
||||
|
||||
import com.kri.epolicy.dash.back.dto.auth.LoginRequestDto;
|
||||
import com.kri.epolicy.dash.back.dto.auth.LoginResponseDto;
|
||||
import com.kri.epolicy.dash.back.dto.auth.UserDto;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AuthService {
|
||||
|
||||
private final JwtService jwtService;
|
||||
private final UserService userService;
|
||||
|
||||
public LoginResponseDto tryLogin(LoginRequestDto req) {
|
||||
UserDto user = userService.getUserWithLoginRequest(req);
|
||||
|
||||
JwtUserClaimsDto claims = JwtUserClaimsDto.builder()
|
||||
.userId(user.getUserId())
|
||||
.userCmpn(user.getUserCmpn())
|
||||
.userName(user.getUserName())
|
||||
.userTeam(user.getUserTeam())
|
||||
.userRole(user.getUserRole())
|
||||
.build();
|
||||
|
||||
String accessToken = jwtService.generateAccessToken(claims);
|
||||
|
||||
return LoginResponseDto.from(accessToken, user);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
package com.kri.epolicy.dash.back.service;
|
||||
|
||||
import com.kri.epolicy.dash.back.dto.request.ExcelData;
|
||||
import com.kri.epolicy.dash.back.dto.response.ExcelImportResponse;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartItemBaseEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartItemDataEntity;
|
||||
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.TSurveyEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TSurveyItemEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TWaveEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TWaveInfoEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TPartEntityId;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemEntityId;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TPartItemSubEntityId;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TSurveyEntityId;
|
||||
import com.kri.epolicy.dash.back.persistence.repository.PartItemBaseRepository;
|
||||
import com.kri.epolicy.dash.back.persistence.repository.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.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ExcelImportService {
|
||||
|
||||
private final ExcelImportValidator excelImportValidator;
|
||||
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 PartItemDataRepository partItemDataRepository;
|
||||
|
||||
@Transactional
|
||||
public ExcelImportResponse importWorkbook(MultipartFile file) {
|
||||
ExcelData data = excelImportValidator.validateAndConvert(file);
|
||||
Set<Short> waveCodes = data.waves().stream()
|
||||
.map(ExcelData.WaveRow::waveCd)
|
||||
.collect(Collectors.toSet());
|
||||
Map<WaveInfoKey, Integer> waveInfoIds = waveInfoRepository.findByWaveCdIn(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 -> {
|
||||
TWaveEntity entity = new TWaveEntity();
|
||||
entity.setId(row.waveCd());
|
||||
entity.setYear(row.year());
|
||||
entity.setWave(row.wave());
|
||||
entity.setLabel(row.label());
|
||||
entity.setIsOpen(row.isOpen());
|
||||
return entity;
|
||||
}).toList());
|
||||
|
||||
waveInfoRepository.saveAll(data.waveInfos().stream().map(row -> {
|
||||
TWaveInfoEntity entity = new TWaveInfoEntity();
|
||||
entity.setId(waveInfoIds.get(new WaveInfoKey(row.waveCd(), row.waveInfoOrder())));
|
||||
entity.setWaveCd(row.waveCd());
|
||||
entity.setWaveInfoOrder(row.waveInfoOrder());
|
||||
entity.setWaveInfoTitle(row.waveInfoTitle());
|
||||
entity.setWaveInfoContent(row.waveInfoContent());
|
||||
return entity;
|
||||
}).toList());
|
||||
|
||||
surveyRepository.saveAll(data.surveys().stream().map(row -> {
|
||||
TSurveyEntity entity = new TSurveyEntity();
|
||||
entity.setId(surveyId(row.waveCd(), row.surveyCd()));
|
||||
entity.setSurveyOrder(row.surveyOrder());
|
||||
entity.setSurveyTitle(row.surveyTitle());
|
||||
entity.setSurveyAlias(row.surveyAlias());
|
||||
return entity;
|
||||
}).toList());
|
||||
|
||||
surveyItemRepository.saveAll(data.surveyItems().stream().map(row -> {
|
||||
TSurveyItemEntity entity = new TSurveyItemEntity();
|
||||
entity.setId(surveyItemIds.get(
|
||||
new SurveyItemKey(row.waveCd(), row.surveyCd(), row.surveyItemOrder())));
|
||||
entity.setWaveCd(row.waveCd());
|
||||
entity.setSurveyCd(row.surveyCd());
|
||||
entity.setSurveyItemOrder(row.surveyItemOrder());
|
||||
entity.setSurveyItemTitle(row.surveyItemTitle());
|
||||
entity.setSurveyItemContent(row.surveyItemContent());
|
||||
return entity;
|
||||
}).toList());
|
||||
|
||||
partRepository.saveAll(data.parts().stream().map(row -> {
|
||||
TPartEntity entity = new TPartEntity();
|
||||
entity.setId(partId(row.waveCd(), row.partCd()));
|
||||
entity.setPartOrder(row.partOrder());
|
||||
entity.setPartTitle(row.partTitle());
|
||||
return entity;
|
||||
}).toList());
|
||||
|
||||
partItemRepository.saveAll(data.partItems().stream().map(row -> {
|
||||
TPartItemEntity entity = new TPartItemEntity();
|
||||
entity.setId(partItemId(row.waveCd(), row.partCd(), row.partItemCd()));
|
||||
entity.setPartItemOrder(row.partItemOrder());
|
||||
entity.setPartItemTitle(row.partItemTitle());
|
||||
entity.setChartType(row.chartType());
|
||||
entity.setPartItemComment(row.partItemComment());
|
||||
return entity;
|
||||
}).toList());
|
||||
|
||||
partItemSubRepository.saveAll(data.partItemSubs().stream().map(row -> {
|
||||
TPartItemSubEntity entity = new TPartItemSubEntity();
|
||||
entity.setId(partItemSubId(
|
||||
row.waveCd(), row.partCd(), row.partItemCd(), row.partItemSubCd()));
|
||||
entity.setPartItemSubTitle(row.partItemSubTitle());
|
||||
return entity;
|
||||
}).toList());
|
||||
|
||||
partItemBaseRepository.saveAll(data.partItemBases().stream().map(row -> {
|
||||
TPartItemBaseEntity entity = new TPartItemBaseEntity();
|
||||
entity.setId(partItemBaseIds.get(new ResultSeriesKey(
|
||||
row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(), row.partItemSubCd())));
|
||||
entity.setWaveCd(row.waveCd());
|
||||
entity.setPartCd(row.partCd());
|
||||
entity.setPartItemCd(row.partItemCd());
|
||||
entity.setSurveyCd(row.surveyCd());
|
||||
entity.setPartItemSubCd(row.partItemSubCd());
|
||||
entity.setBaseCount(row.baseCount());
|
||||
entity.setBasePreText(row.basePreText());
|
||||
entity.setBasePostText(row.basePostText());
|
||||
return entity;
|
||||
}).toList());
|
||||
|
||||
partItemDataRepository.saveAll(data.partItemData().stream().map(row -> {
|
||||
TPartItemDataEntity entity = new TPartItemDataEntity();
|
||||
entity.setId(partItemDataIds.get(new ResultCategoryKey(
|
||||
row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(), row.partItemSubCd(),
|
||||
row.partItemDataOrder())));
|
||||
entity.setWaveCd(row.waveCd());
|
||||
entity.setPartCd(row.partCd());
|
||||
entity.setPartItemCd(row.partItemCd());
|
||||
entity.setSurveyCd(row.surveyCd());
|
||||
entity.setPartItemSubCd(row.partItemSubCd());
|
||||
entity.setPartItemDataOrder(row.partItemDataOrder());
|
||||
entity.setPartItemDataLabel(row.partItemDataLabel());
|
||||
entity.setPartItemDataValue(row.partItemDataValue());
|
||||
entity.setIsChartVisible(row.isChartVisible());
|
||||
return entity;
|
||||
}).toList());
|
||||
|
||||
return new ExcelImportResponse(
|
||||
data.waves().size(),
|
||||
data.waveInfos().size(),
|
||||
data.surveys().size(),
|
||||
data.surveyItems().size(),
|
||||
data.parts().size(),
|
||||
data.partItems().size(),
|
||||
data.partItemSubs().size(),
|
||||
data.partItemBases().size(),
|
||||
data.partItemData().size()
|
||||
);
|
||||
}
|
||||
|
||||
private TSurveyEntityId surveyId(Short waveCd, Short surveyCd) {
|
||||
TSurveyEntityId id = new TSurveyEntityId();
|
||||
id.setWaveCd(waveCd);
|
||||
id.setSurveyCd(surveyCd);
|
||||
return id;
|
||||
}
|
||||
|
||||
private TPartEntityId partId(Short waveCd, Short partCd) {
|
||||
TPartEntityId id = new TPartEntityId();
|
||||
id.setWaveCd(waveCd);
|
||||
id.setPartCd(partCd);
|
||||
return id;
|
||||
}
|
||||
|
||||
private TPartItemEntityId partItemId(Short waveCd, Short partCd, Short partItemCd) {
|
||||
TPartItemEntityId id = new TPartItemEntityId();
|
||||
id.setWaveCd(waveCd);
|
||||
id.setPartCd(partCd);
|
||||
id.setPartItemCd(partItemCd);
|
||||
return id;
|
||||
}
|
||||
|
||||
private TPartItemSubEntityId partItemSubId(
|
||||
Short waveCd,
|
||||
Short partCd,
|
||||
Short partItemCd,
|
||||
Short partItemSubCd
|
||||
) {
|
||||
TPartItemSubEntityId id = new TPartItemSubEntityId();
|
||||
id.setWaveCd(waveCd);
|
||||
id.setPartCd(partCd);
|
||||
id.setPartItemCd(partItemCd);
|
||||
id.setPartItemSubCd(partItemSubCd);
|
||||
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
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,653 @@
|
||||
package com.kri.epolicy.dash.back.service;
|
||||
|
||||
import com.kri.common.feature.excel.ExcelColumn;
|
||||
import com.kri.common.feature.excel.ExcelMapper;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.epolicy.dash.back.common.enums.ChartType;
|
||||
import com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows;
|
||||
import com.kri.epolicy.dash.back.dto.request.ExcelData;
|
||||
import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemBaseRow;
|
||||
import com.kri.epolicy.dash.back.dto.request.ExcelData.PartItemDataRow;
|
||||
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.PartRow;
|
||||
import com.kri.epolicy.dash.back.dto.request.ExcelData.SurveyItemRow;
|
||||
import com.kri.epolicy.dash.back.dto.request.ExcelData.SurveyRow;
|
||||
import com.kri.epolicy.dash.back.dto.request.ExcelData.WaveInfoRow;
|
||||
import com.kri.epolicy.dash.back.dto.request.ExcelData.WaveRow;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Component
|
||||
public class ExcelImportValidator {
|
||||
|
||||
private static final int HEADER_ROW_NUMBER = 1;
|
||||
|
||||
public ExcelData validateAndConvert(MultipartFile file) {
|
||||
validateFile(file);
|
||||
try (InputStream inputStream = file.getInputStream();
|
||||
Workbook workbook = WorkbookFactory.create(inputStream)) {
|
||||
ExcelData data = new ExcelData(
|
||||
readRows(workbook, ExcelTemplateRows.WAVE_SHEET, ExcelTemplateRows.Wave.class,
|
||||
row -> allBlank(row.getWaveCd(), row.getYear(), row.getWave(), row.getLabel(),
|
||||
row.getIsOpen()), this::toWaveRow),
|
||||
readRows(workbook, ExcelTemplateRows.WAVE_INFO_SHEET, ExcelTemplateRows.WaveInfo.class,
|
||||
row -> allBlank(row.getWaveCd(), row.getWaveInfoOrder(), row.getWaveInfoTitle(),
|
||||
row.getWaveInfoContent()), this::toWaveInfoRow),
|
||||
readRows(workbook, ExcelTemplateRows.SURVEY_SHEET, ExcelTemplateRows.Survey.class,
|
||||
row -> allBlank(row.getWaveCd(), row.getSurveyCd(), row.getSurveyOrder(),
|
||||
row.getSurveyTitle(), row.getSurveyAlias()), this::toSurveyRow),
|
||||
readRows(workbook, ExcelTemplateRows.SURVEY_ITEM_SHEET,
|
||||
ExcelTemplateRows.SurveyItem.class,
|
||||
row -> allBlank(row.getWaveCd(), row.getSurveyCd(), row.getSurveyItemOrder(),
|
||||
row.getSurveyItemTitle(), row.getSurveyItemContent()), this::toSurveyItemRow),
|
||||
readRows(workbook, ExcelTemplateRows.PART_SHEET, ExcelTemplateRows.Part.class,
|
||||
row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartOrder(),
|
||||
row.getPartTitle()), this::toPartRow),
|
||||
readRows(workbook, ExcelTemplateRows.PART_ITEM_SHEET, ExcelTemplateRows.PartItem.class,
|
||||
row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(),
|
||||
row.getPartItemOrder(), row.getPartItemTitle(), row.getChartType(),
|
||||
row.getPartItemComment()), this::toPartItemRow),
|
||||
readRows(workbook, ExcelTemplateRows.PART_ITEM_SUB_SHEET,
|
||||
ExcelTemplateRows.PartItemSub.class,
|
||||
row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(),
|
||||
row.getPartItemSubCd(), row.getPartItemSubTitle()), this::toPartItemSubRow),
|
||||
readRows(workbook, ExcelTemplateRows.PART_ITEM_BASE_SHEET,
|
||||
ExcelTemplateRows.PartItemBase.class,
|
||||
row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(),
|
||||
row.getSurveyCd(), row.getPartItemSubCd(), row.getBaseCount(),
|
||||
row.getBasePreText(), row.getBasePostText()), this::toPartItemBaseRow),
|
||||
readRows(workbook, ExcelTemplateRows.PART_ITEM_DATA_SHEET,
|
||||
ExcelTemplateRows.PartItemData.class,
|
||||
row -> allBlank(row.getWaveCd(), row.getPartCd(), row.getPartItemCd(),
|
||||
row.getSurveyCd(), row.getPartItemSubCd(), row.getPartItemDataOrder(),
|
||||
row.getPartItemDataLabel(), row.getPartItemDataValue(),
|
||||
row.getIsChartVisible()), this::toPartItemDataRow)
|
||||
);
|
||||
if (data.waves().isEmpty()) {
|
||||
throw sheetError(ExcelTemplateRows.WAVE_SHEET,
|
||||
"한 개 이상의 Wave 데이터가 필요합니다.");
|
||||
}
|
||||
validateRelationships(data);
|
||||
return data;
|
||||
} catch (BusinessException exception) {
|
||||
throw exception;
|
||||
} catch (IOException | RuntimeException exception) {
|
||||
BusinessException businessException = findBusinessException(exception);
|
||||
if (businessException != null) {
|
||||
throw businessException;
|
||||
}
|
||||
throw BusinessException.validationError(
|
||||
"EXCEL_IMPORT_FAILED", "Excel 파일을 읽을 수 없습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private <T, R> List<R> readRows(
|
||||
Workbook workbook,
|
||||
String sheetName,
|
||||
Class<T> rowType,
|
||||
Predicate<T> emptyRow,
|
||||
BiFunction<T, RowContext, R> converter
|
||||
) {
|
||||
validateHeaders(workbook, sheetName, rowType);
|
||||
List<T> sourceRows = ExcelMapper.readFromWorkbook(
|
||||
workbook, rowType, sheetName, HEADER_ROW_NUMBER);
|
||||
List<R> result = new ArrayList<>();
|
||||
for (int index = 0; index < sourceRows.size(); index++) {
|
||||
T row = sourceRows.get(index);
|
||||
if (!emptyRow.test(row)) {
|
||||
result.add(converter.apply(row, new RowContext(sheetName, index + 2)));
|
||||
}
|
||||
}
|
||||
return List.copyOf(result);
|
||||
}
|
||||
|
||||
private <T> void validateHeaders(Workbook workbook, String sheetName, Class<T> rowType) {
|
||||
Sheet sheet = workbook.getSheet(sheetName);
|
||||
if (sheet == null) {
|
||||
throw sheetError(sheetName, "필수 시트가 없습니다.");
|
||||
}
|
||||
Row headerRow = sheet.getRow(HEADER_ROW_NUMBER - 1);
|
||||
if (headerRow == null) {
|
||||
throw sheetError(sheetName, "헤더 행이 없습니다.");
|
||||
}
|
||||
DataFormatter formatter = new DataFormatter();
|
||||
List<String> actualHeaders = new ArrayList<>();
|
||||
for (int column = 0; column < headerRow.getLastCellNum(); column++) {
|
||||
actualHeaders.add(formatter.formatCellValue(headerRow.getCell(column)));
|
||||
}
|
||||
Set<String> uniqueHeaders = new HashSet<>();
|
||||
for (String actualHeader : actualHeaders) {
|
||||
String header = actualHeader == null ? "" : actualHeader.trim();
|
||||
if (!uniqueHeaders.add(header)) {
|
||||
throw sheetError(sheetName, "중복된 헤더가 있습니다: " + header);
|
||||
}
|
||||
}
|
||||
List<String> expectedHeaders = expectedHeaders(rowType);
|
||||
if (!actualHeaders.equals(expectedHeaders)) {
|
||||
throw sheetError(sheetName,
|
||||
"헤더가 올바르지 않습니다. 예상 헤더: " + String.join(", ", expectedHeaders));
|
||||
}
|
||||
}
|
||||
|
||||
private <T> List<String> expectedHeaders(Class<T> rowType) {
|
||||
return Arrays.stream(rowType.getDeclaredFields())
|
||||
.map(field -> new AnnotatedField(field, field.getAnnotation(ExcelColumn.class)))
|
||||
.filter(field -> field.column() != null)
|
||||
.sorted(Comparator.comparingInt(field -> field.column().order()))
|
||||
.map(field -> field.column().header())
|
||||
.toList();
|
||||
}
|
||||
|
||||
private WaveRow toWaveRow(ExcelTemplateRows.Wave row, RowContext context) {
|
||||
return new WaveRow(
|
||||
requiredShort(row.getWaveCd(), "wave_cd", context),
|
||||
requiredShort(row.getYear(), "year", context),
|
||||
requiredShort(row.getWave(), "wave", context),
|
||||
requiredString(row.getLabel(), "label", 32, context),
|
||||
requiredBoolean(row.getIsOpen(), "is_open", context)
|
||||
);
|
||||
}
|
||||
|
||||
private WaveInfoRow toWaveInfoRow(ExcelTemplateRows.WaveInfo row, RowContext context) {
|
||||
return new WaveInfoRow(
|
||||
requiredShort(row.getWaveCd(), "wave_cd", context),
|
||||
requiredShort(row.getWaveInfoOrder(), "wave_info_order", context),
|
||||
requiredString(row.getWaveInfoTitle(), "wave_info_title", 128, context),
|
||||
requiredString(row.getWaveInfoContent(), "wave_info_content", null, context)
|
||||
);
|
||||
}
|
||||
|
||||
private SurveyRow toSurveyRow(ExcelTemplateRows.Survey row, RowContext context) {
|
||||
return new SurveyRow(
|
||||
requiredShort(row.getWaveCd(), "wave_cd", context),
|
||||
requiredShort(row.getSurveyCd(), "survey_cd", context),
|
||||
requiredShort(row.getSurveyOrder(), "survey_order", context),
|
||||
requiredString(row.getSurveyTitle(), "survey_title", 128, context),
|
||||
requiredString(row.getSurveyAlias(), "survey_alias", 32, context)
|
||||
);
|
||||
}
|
||||
|
||||
private SurveyItemRow toSurveyItemRow(
|
||||
ExcelTemplateRows.SurveyItem row,
|
||||
RowContext context
|
||||
) {
|
||||
return new SurveyItemRow(
|
||||
requiredShort(row.getWaveCd(), "wave_cd", context),
|
||||
requiredShort(row.getSurveyCd(), "survey_cd", context),
|
||||
requiredShort(row.getSurveyItemOrder(), "survey_item_order", context),
|
||||
requiredString(row.getSurveyItemTitle(), "survey_item_title", 128, context),
|
||||
requiredString(row.getSurveyItemContent(), "survey_item_content", null, context)
|
||||
);
|
||||
}
|
||||
|
||||
private PartRow toPartRow(ExcelTemplateRows.Part row, RowContext context) {
|
||||
return new PartRow(
|
||||
requiredShort(row.getWaveCd(), "wave_cd", context),
|
||||
requiredShort(row.getPartCd(), "part_cd", context),
|
||||
requiredShort(row.getPartOrder(), "part_order", context),
|
||||
requiredString(row.getPartTitle(), "part_title", 128, context)
|
||||
);
|
||||
}
|
||||
|
||||
private PartItemRow toPartItemRow(ExcelTemplateRows.PartItem row, RowContext context) {
|
||||
return new PartItemRow(
|
||||
requiredShort(row.getWaveCd(), "wave_cd", context),
|
||||
requiredShort(row.getPartCd(), "part_cd", context),
|
||||
requiredShort(row.getPartItemCd(), "part_item_cd", context),
|
||||
requiredShort(row.getPartItemOrder(), "part_item_order", context),
|
||||
requiredString(row.getPartItemTitle(), "part_item_title", 128, context),
|
||||
requiredChartType(row.getChartType(), "chart_type", context),
|
||||
Objects.requireNonNullElse(
|
||||
optionalString(row.getPartItemComment(), "part_item_comment", null, context), "")
|
||||
);
|
||||
}
|
||||
|
||||
private PartItemSubRow toPartItemSubRow(
|
||||
ExcelTemplateRows.PartItemSub row,
|
||||
RowContext context
|
||||
) {
|
||||
return new PartItemSubRow(
|
||||
requiredShort(row.getWaveCd(), "wave_cd", context),
|
||||
requiredShort(row.getPartCd(), "part_cd", context),
|
||||
requiredShort(row.getPartItemCd(), "part_item_cd", context),
|
||||
requiredShort(row.getPartItemSubCd(), "part_item_sub_cd", context),
|
||||
requiredString(row.getPartItemSubTitle(), "part_item_sub_title", 128, context)
|
||||
);
|
||||
}
|
||||
|
||||
private PartItemBaseRow toPartItemBaseRow(
|
||||
ExcelTemplateRows.PartItemBase row,
|
||||
RowContext context
|
||||
) {
|
||||
return new PartItemBaseRow(
|
||||
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),
|
||||
requiredInteger(row.getBaseCount(), "base_count", context),
|
||||
optionalString(row.getBasePreText(), "base_pre_text", 128, context),
|
||||
optionalString(row.getBasePostText(), "base_post_text", 128, context)
|
||||
);
|
||||
}
|
||||
|
||||
private PartItemDataRow toPartItemDataRow(
|
||||
ExcelTemplateRows.PartItemData row,
|
||||
RowContext context
|
||||
) {
|
||||
return new PartItemDataRow(
|
||||
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),
|
||||
requiredShort(row.getPartItemDataOrder(), "part_item_data_order", context),
|
||||
requiredString(row.getPartItemDataLabel(), "part_item_data_label", 128, context),
|
||||
requiredDecimal(row.getPartItemDataValue(), "part_item_data_value", context),
|
||||
requiredBoolean(row.getIsChartVisible(), "is_chart_visible", context)
|
||||
);
|
||||
}
|
||||
|
||||
private void validateRelationships(ExcelData data) {
|
||||
Set<Short> waveKeys = uniqueKeys(
|
||||
data.waves(), WaveRow::waveCd, ExcelTemplateRows.WAVE_SHEET);
|
||||
uniqueKeys(data.waveInfos(),
|
||||
row -> new WaveInfoKey(row.waveCd(), row.waveInfoOrder()),
|
||||
ExcelTemplateRows.WAVE_INFO_SHEET);
|
||||
Set<SurveyKey> surveyKeys = uniqueKeys(data.surveys(),
|
||||
row -> new SurveyKey(row.waveCd(), row.surveyCd()), ExcelTemplateRows.SURVEY_SHEET);
|
||||
uniqueKeys(data.surveyItems(),
|
||||
row -> new SurveyItemKey(row.waveCd(), row.surveyCd(), row.surveyItemOrder()),
|
||||
ExcelTemplateRows.SURVEY_ITEM_SHEET);
|
||||
Set<PartKey> partKeys = uniqueKeys(data.parts(),
|
||||
row -> new PartKey(row.waveCd(), row.partCd()), ExcelTemplateRows.PART_SHEET);
|
||||
Set<ItemKey> itemKeys = uniqueKeys(data.partItems(),
|
||||
row -> new ItemKey(row.waveCd(), row.partCd(), row.partItemCd()),
|
||||
ExcelTemplateRows.PART_ITEM_SHEET);
|
||||
Set<SubKey> subKeys = uniqueKeys(data.partItemSubs(),
|
||||
row -> new SubKey(row.waveCd(), row.partCd(), row.partItemCd(), row.partItemSubCd()),
|
||||
ExcelTemplateRows.PART_ITEM_SUB_SHEET);
|
||||
|
||||
requireParents(data.waveInfos(), WaveInfoRow::waveCd, waveKeys,
|
||||
ExcelTemplateRows.WAVE_INFO_SHEET, "wave_cd");
|
||||
requireParents(data.surveys(), SurveyRow::waveCd, waveKeys,
|
||||
ExcelTemplateRows.SURVEY_SHEET, "wave_cd");
|
||||
requireParents(data.surveyItems(),
|
||||
row -> new SurveyKey(row.waveCd(), row.surveyCd()), surveyKeys,
|
||||
ExcelTemplateRows.SURVEY_ITEM_SHEET, "wave_cd, survey_cd");
|
||||
requireParents(data.parts(), PartRow::waveCd, waveKeys,
|
||||
ExcelTemplateRows.PART_SHEET, "wave_cd");
|
||||
requireParents(data.partItems(),
|
||||
row -> new PartKey(row.waveCd(), row.partCd()), partKeys,
|
||||
ExcelTemplateRows.PART_ITEM_SHEET, "wave_cd, part_cd");
|
||||
requireParents(data.partItemSubs(),
|
||||
row -> new ItemKey(row.waveCd(), row.partCd(), row.partItemCd()), itemKeys,
|
||||
ExcelTemplateRows.PART_ITEM_SUB_SHEET, "wave_cd, part_cd, part_item_cd");
|
||||
|
||||
Set<ItemKey> itemsWithSubs = data.partItemSubs().stream()
|
||||
.map(row -> new ItemKey(row.waveCd(), row.partCd(), row.partItemCd()))
|
||||
.collect(Collectors.toSet());
|
||||
for (PartItemBaseRow row : data.partItemBases()) {
|
||||
validateResultRelationship(row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(),
|
||||
row.partItemSubCd(), itemKeys, surveyKeys, subKeys, itemsWithSubs,
|
||||
ExcelTemplateRows.PART_ITEM_BASE_SHEET);
|
||||
}
|
||||
for (PartItemDataRow row : data.partItemData()) {
|
||||
validateResultRelationship(row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(),
|
||||
row.partItemSubCd(), itemKeys, surveyKeys, subKeys, itemsWithSubs,
|
||||
ExcelTemplateRows.PART_ITEM_DATA_SHEET);
|
||||
}
|
||||
validateResultBases(data.partItemBases(), data.partItemData());
|
||||
validateCategoryConsistency(data.partItemData());
|
||||
}
|
||||
|
||||
private void validateResultBases(List<PartItemBaseRow> bases, List<PartItemDataRow> data) {
|
||||
Set<ResultSeriesKey> baseKeys = uniqueKeys(bases,
|
||||
row -> new ResultSeriesKey(
|
||||
row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(), row.partItemSubCd()),
|
||||
ExcelTemplateRows.PART_ITEM_BASE_SHEET);
|
||||
for (PartItemDataRow row : data) {
|
||||
ResultSeriesKey key = new ResultSeriesKey(
|
||||
row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(), row.partItemSubCd());
|
||||
if (!baseKeys.contains(key)) {
|
||||
throw relationshipError(ExcelTemplateRows.PART_ITEM_DATA_SHEET,
|
||||
"결과 데이터에 대응하는 Base가 없습니다: " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateCategoryConsistency(List<PartItemDataRow> rows) {
|
||||
uniqueKeys(rows,
|
||||
row -> new ResultCategoryKey(
|
||||
row.waveCd(), row.partCd(), row.partItemCd(), row.surveyCd(),
|
||||
row.partItemSubCd(), row.partItemDataOrder()),
|
||||
ExcelTemplateRows.PART_ITEM_DATA_SHEET);
|
||||
Map<ResultGroupKey, Map<Short, List<CategoryKey>>> grouped = rows.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
row -> new ResultGroupKey(
|
||||
row.waveCd(), row.partCd(), row.partItemCd(), row.partItemSubCd()),
|
||||
Collectors.groupingBy(
|
||||
PartItemDataRow::surveyCd,
|
||||
Collectors.mapping(
|
||||
row -> new CategoryKey(
|
||||
row.partItemDataOrder(), row.partItemDataLabel(), row.isChartVisible()),
|
||||
Collectors.toList()))));
|
||||
|
||||
for (Map.Entry<ResultGroupKey, Map<Short, List<CategoryKey>>> group : grouped.entrySet()) {
|
||||
List<CategoryKey> expected = null;
|
||||
for (List<CategoryKey> categories : group.getValue().values()) {
|
||||
categories.sort(Comparator.comparing(CategoryKey::order));
|
||||
if (expected == null) {
|
||||
expected = List.copyOf(categories);
|
||||
} else if (!Objects.equals(expected, categories)) {
|
||||
throw relationshipError(ExcelTemplateRows.PART_ITEM_DATA_SHEET,
|
||||
"조사대상별 항목명, 표시 순서 및 차트 노출 여부가 일치하지 않습니다: "
|
||||
+ group.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateResultRelationship(
|
||||
Short waveCd,
|
||||
Short partCd,
|
||||
Short partItemCd,
|
||||
Short surveyCd,
|
||||
Short partItemSubCd,
|
||||
Set<ItemKey> itemKeys,
|
||||
Set<SurveyKey> surveyKeys,
|
||||
Set<SubKey> subKeys,
|
||||
Set<ItemKey> itemsWithSubs,
|
||||
String sheetName
|
||||
) {
|
||||
ItemKey itemKey = new ItemKey(waveCd, partCd, partItemCd);
|
||||
if (!itemKeys.contains(itemKey)) {
|
||||
throw relationshipError(sheetName, "존재하지 않는 문항을 참조합니다: " + itemKey);
|
||||
}
|
||||
if (!surveyKeys.contains(new SurveyKey(waveCd, surveyCd))) {
|
||||
throw relationshipError(sheetName,
|
||||
"동일 Wave에 존재하지 않는 조사대상을 참조합니다: " + surveyCd);
|
||||
}
|
||||
if (itemsWithSubs.contains(itemKey)) {
|
||||
if (partItemSubCd == null) {
|
||||
throw relationshipError(sheetName,
|
||||
"Sub가 있는 문항의 part_item_sub_cd는 필수입니다: " + itemKey);
|
||||
}
|
||||
if (!subKeys.contains(new SubKey(waveCd, partCd, partItemCd, partItemSubCd))) {
|
||||
throw relationshipError(sheetName, "존재하지 않는 Sub를 참조합니다: " + partItemSubCd);
|
||||
}
|
||||
} else if (partItemSubCd != null) {
|
||||
throw relationshipError(sheetName,
|
||||
"일반 문항의 part_item_sub_cd는 NULL이어야 합니다: " + itemKey);
|
||||
}
|
||||
}
|
||||
|
||||
private <T, K> Set<K> uniqueKeys(
|
||||
List<T> rows,
|
||||
Function<T, K> keyExtractor,
|
||||
String sheetName
|
||||
) {
|
||||
Set<K> keys = new LinkedHashSet<>();
|
||||
for (T row : rows) {
|
||||
K key = keyExtractor.apply(row);
|
||||
if (!keys.add(key)) {
|
||||
throw relationshipError(sheetName, "중복된 논리 식별자가 있습니다: " + key);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
private <T, K> void requireParents(
|
||||
List<T> rows,
|
||||
Function<T, K> parentKeyExtractor,
|
||||
Set<K> parentKeys,
|
||||
String sheetName,
|
||||
String columns
|
||||
) {
|
||||
for (T row : rows) {
|
||||
K key = parentKeyExtractor.apply(row);
|
||||
if (!parentKeys.contains(key)) {
|
||||
throw relationshipError(sheetName,
|
||||
"Excel 안에 부모 데이터가 없습니다 (" + columns + "): " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateFile(MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw invalidFile("업로드할 XLSX 파일이 비어 있습니다.");
|
||||
}
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
if (originalFilename == null
|
||||
|| !originalFilename.toLowerCase(Locale.ROOT).endsWith(".xlsx")) {
|
||||
throw invalidFile("XLSX 파일만 업로드할 수 있습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allBlank(String... values) {
|
||||
return Arrays.stream(values).allMatch(value -> value == null || value.isBlank());
|
||||
}
|
||||
|
||||
private String requiredString(
|
||||
String rawValue,
|
||||
String column,
|
||||
Integer maxLength,
|
||||
RowContext context
|
||||
) {
|
||||
String value = requiredRaw(rawValue, column, context);
|
||||
validateLength(value, column, maxLength, context);
|
||||
return value;
|
||||
}
|
||||
|
||||
private String optionalString(
|
||||
String rawValue,
|
||||
String column,
|
||||
Integer maxLength,
|
||||
RowContext context
|
||||
) {
|
||||
String value = normalized(rawValue);
|
||||
if (value != null) {
|
||||
validateLength(value, column, maxLength, context);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private void validateLength(
|
||||
String value,
|
||||
String column,
|
||||
Integer maxLength,
|
||||
RowContext context
|
||||
) {
|
||||
if (maxLength != null && value.length() > maxLength) {
|
||||
throw cellError(context, column, "최대 길이는 " + maxLength + "자입니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private Short requiredShort(String rawValue, String column, RowContext context) {
|
||||
String value = requiredRaw(rawValue, column, context);
|
||||
try {
|
||||
return Short.valueOf(value);
|
||||
} catch (NumberFormatException exception) {
|
||||
throw cellError(context, column, "SMALLINT 범위의 정수여야 합니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private Short optionalShort(String rawValue, String column, RowContext context) {
|
||||
String value = normalized(rawValue);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Short.valueOf(value);
|
||||
} catch (NumberFormatException exception) {
|
||||
throw cellError(context, column, "SMALLINT 범위의 정수여야 합니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private Integer requiredInteger(String rawValue, String column, RowContext context) {
|
||||
String value = requiredRaw(rawValue, column, context);
|
||||
try {
|
||||
return Integer.valueOf(value);
|
||||
} catch (NumberFormatException exception) {
|
||||
throw cellError(context, column, "정수여야 합니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private BigDecimal requiredDecimal(String rawValue, String column, RowContext context) {
|
||||
String value = requiredRaw(rawValue, column, context);
|
||||
try {
|
||||
BigDecimal rounded = new BigDecimal(value).setScale(10, RoundingMode.HALF_UP);
|
||||
if (rounded.precision() > 14) {
|
||||
throw cellError(context, column,
|
||||
"소수점 10자리 반올림 후 DECIMAL(14,10) 범위를 벗어났습니다.");
|
||||
}
|
||||
return rounded;
|
||||
} catch (NumberFormatException exception) {
|
||||
throw cellError(context, column, "숫자여야 합니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean requiredBoolean(String rawValue, String column, RowContext context) {
|
||||
String value = requiredRaw(rawValue, column, context).toLowerCase(Locale.ROOT);
|
||||
return switch (value) {
|
||||
case "1" -> true;
|
||||
case "0" -> false;
|
||||
default -> throw cellError(context, column, "1 또는 0이어야 합니다.");
|
||||
};
|
||||
}
|
||||
|
||||
private ChartType requiredChartType(String rawValue, String column, RowContext context) {
|
||||
String label = requiredRaw(rawValue, column, context);
|
||||
try {
|
||||
return ChartType.fromLabel(label);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
throw cellError(context, column, "지원하는 label은 bar입니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private String requiredRaw(String rawValue, String column, RowContext context) {
|
||||
String value = normalized(rawValue);
|
||||
if (value == null) {
|
||||
throw cellError(context, column, "필수 값입니다.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private String normalized(String value) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
private BusinessException findBusinessException(Throwable throwable) {
|
||||
Throwable current = throwable;
|
||||
while (current != null) {
|
||||
if (current instanceof BusinessException businessException) {
|
||||
return businessException;
|
||||
}
|
||||
current = current.getCause();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private BusinessException invalidFile(String message) {
|
||||
return BusinessException.validationError("INVALID_EXCEL_FILE", message);
|
||||
}
|
||||
|
||||
private BusinessException sheetError(String sheetName, String message) {
|
||||
return BusinessException.validationError("INVALID_EXCEL_SHEET", message)
|
||||
.with("sheet", sheetName);
|
||||
}
|
||||
|
||||
private BusinessException relationshipError(String sheetName, String message) {
|
||||
return BusinessException.validationError("INVALID_EXCEL_RELATIONSHIP", message)
|
||||
.with("sheet", sheetName);
|
||||
}
|
||||
|
||||
private BusinessException cellError(RowContext context, String column, String message) {
|
||||
return BusinessException.validationError("INVALID_EXCEL_CELL", message)
|
||||
.with("sheet", context.sheetName())
|
||||
.with("row", context.rowNumber())
|
||||
.with("column", column);
|
||||
}
|
||||
|
||||
private record AnnotatedField(Field field, ExcelColumn column) {
|
||||
}
|
||||
|
||||
private record RowContext(String sheetName, int rowNumber) {
|
||||
}
|
||||
|
||||
private record WaveInfoKey(Short waveCd, Short order) {
|
||||
}
|
||||
|
||||
private record SurveyKey(Short waveCd, Short surveyCd) {
|
||||
}
|
||||
|
||||
private record SurveyItemKey(Short waveCd, Short surveyCd, Short order) {
|
||||
}
|
||||
|
||||
private record PartKey(Short waveCd, Short partCd) {
|
||||
}
|
||||
|
||||
private record ItemKey(Short waveCd, Short partCd, Short partItemCd) {
|
||||
}
|
||||
|
||||
private record SubKey(Short waveCd, Short partCd, Short partItemCd, Short partItemSubCd) {
|
||||
}
|
||||
|
||||
private record ResultGroupKey(
|
||||
Short waveCd,
|
||||
Short partCd,
|
||||
Short partItemCd,
|
||||
Short partItemSubCd
|
||||
) {
|
||||
}
|
||||
|
||||
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
|
||||
) {
|
||||
}
|
||||
|
||||
private record CategoryKey(Short order, String label, Boolean chartVisible) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.kri.epolicy.dash.back.service;
|
||||
|
||||
import com.kri.common.feature.excel.ExcelMapper;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows;
|
||||
import 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_DATA_SHEET;
|
||||
import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.PART_ITEM_SHEET;
|
||||
import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.PART_ITEM_SUB_SHEET;
|
||||
import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.PART_SHEET;
|
||||
import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.SURVEY_ITEM_SHEET;
|
||||
import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.SURVEY_SHEET;
|
||||
import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.WAVE_INFO_SHEET;
|
||||
import static com.kri.epolicy.dash.back.dto.excel.ExcelTemplateRows.WAVE_SHEET;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ExcelTemplateService {
|
||||
|
||||
public static final String EXCEL_CONTENT_TYPE =
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
public static final String TEMPLATE_FILENAME = "epolicy-data-template.xlsx";
|
||||
|
||||
public byte[] createTemplate() {
|
||||
try (Workbook workbook = ExcelMapper.writeToWorkbook(
|
||||
List.<ExcelTemplateRows.Wave>of(), ExcelTemplateRows.Wave.class, WAVE_SHEET);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||
append(workbook, WAVE_INFO_SHEET, ExcelTemplateRows.WaveInfo.class);
|
||||
append(workbook, SURVEY_SHEET, ExcelTemplateRows.Survey.class);
|
||||
append(workbook, SURVEY_ITEM_SHEET, ExcelTemplateRows.SurveyItem.class);
|
||||
append(workbook, PART_SHEET, ExcelTemplateRows.Part.class);
|
||||
append(workbook, PART_ITEM_SHEET, ExcelTemplateRows.PartItem.class);
|
||||
append(workbook, PART_ITEM_SUB_SHEET, ExcelTemplateRows.PartItemSub.class);
|
||||
append(workbook, PART_ITEM_BASE_SHEET, ExcelTemplateRows.PartItemBase.class);
|
||||
append(workbook, PART_ITEM_DATA_SHEET, ExcelTemplateRows.PartItemData.class);
|
||||
workbook.write(outputStream);
|
||||
return outputStream.toByteArray();
|
||||
} catch (IOException | RuntimeException exception) {
|
||||
throw BusinessException.internalError(
|
||||
"EXCEL_TEMPLATE_EXPORT_FAILED", "Excel 양식 파일을 생성할 수 없습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void append(Workbook workbook, String sheetName, Class<T> rowType) {
|
||||
ExcelMapper.appendSheetToWorkbook(workbook, List.of(), rowType, sheetName, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
package com.kri.epolicy.dash.back.service;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.epolicy.dash.back.config.FileStorageProperties;
|
||||
import com.kri.epolicy.dash.back.dto.response.ReferenceFileUploadResponse;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TFileEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.repository.FileRepository;
|
||||
import com.kri.epolicy.dash.back.persistence.repository.WaveRepository;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.AtomicMoveNotSupportedException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Locale;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ReferenceFileStorageService {
|
||||
|
||||
private static final String REFERENCES_DIRECTORY = "References";
|
||||
private static final int MAX_FILENAME_LENGTH = 64;
|
||||
private static final int MAX_FILE_TITLE_LENGTH = 128;
|
||||
private static final int MAX_FILE_TYPE_LENGTH = 16;
|
||||
|
||||
private final FileStorageProperties fileStorageProperties;
|
||||
private final FileRepository fileRepository;
|
||||
private final WaveRepository waveRepository;
|
||||
|
||||
@Transactional
|
||||
public ReferenceFileUploadResponse store(
|
||||
Short waveCd,
|
||||
String fileTitle,
|
||||
Short fileOrder,
|
||||
MultipartFile file
|
||||
) {
|
||||
validateRequest(waveCd, fileTitle, fileOrder, file);
|
||||
if (!waveRepository.existsById(waveCd)) {
|
||||
throw BusinessException.validationError(
|
||||
"WAVE_NOT_FOUND", "존재하지 않는 waveCd입니다.").with("waveCd", waveCd);
|
||||
}
|
||||
|
||||
String normalizedTitle = fileTitle.trim();
|
||||
String originalFilename = validateFilename(file.getOriginalFilename());
|
||||
String fileType = extractFileType(originalFilename);
|
||||
Path baseDirectory = Path.of(fileStorageProperties.getBaseDir()).toAbsolutePath().normalize();
|
||||
Path targetDirectory = baseDirectory
|
||||
.resolve(REFERENCES_DIRECTORY)
|
||||
.resolve(waveCd.toString())
|
||||
.normalize();
|
||||
Path target = targetDirectory.resolve(originalFilename).normalize();
|
||||
if (!target.startsWith(targetDirectory) || !targetDirectory.startsWith(baseDirectory)) {
|
||||
throw invalidFilename("허용되지 않는 파일 경로입니다.");
|
||||
}
|
||||
|
||||
Path stagedFile = stageFile(targetDirectory, file);
|
||||
try {
|
||||
TFileEntity entity = fileRepository.findFirstByWaveCdAndFileName(waveCd, originalFilename)
|
||||
.orElseGet(TFileEntity::new);
|
||||
entity.setWaveCd(waveCd);
|
||||
entity.setFileOrder(fileOrder);
|
||||
entity.setFileTitle(normalizedTitle);
|
||||
entity.setFileType(fileType);
|
||||
entity.setFileName(originalFilename);
|
||||
TFileEntity saved = fileRepository.saveAndFlush(entity);
|
||||
|
||||
replaceFileWithRollbackProtection(stagedFile, target);
|
||||
stagedFile = null;
|
||||
|
||||
String relativePath = REFERENCES_DIRECTORY + "/" + waveCd + "/" + originalFilename;
|
||||
return new ReferenceFileUploadResponse(
|
||||
saved.getId(),
|
||||
waveCd,
|
||||
fileOrder,
|
||||
normalizedTitle,
|
||||
fileType,
|
||||
originalFilename,
|
||||
file.getSize(),
|
||||
relativePath
|
||||
);
|
||||
} finally {
|
||||
deleteQuietly(stagedFile, "임시 업로드 파일을 삭제하지 못했습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateRequest(
|
||||
Short waveCd,
|
||||
String fileTitle,
|
||||
Short fileOrder,
|
||||
MultipartFile file
|
||||
) {
|
||||
if (waveCd == null || waveCd <= 0) {
|
||||
throw BusinessException.validationError(
|
||||
"INVALID_WAVE_CD", "waveCd는 1 이상의 값이어야 합니다.");
|
||||
}
|
||||
if (fileTitle == null || fileTitle.isBlank()) {
|
||||
throw BusinessException.validationError(
|
||||
"INVALID_FILE_TITLE", "fileTitle은 필수 값입니다.");
|
||||
}
|
||||
if (fileTitle.trim().length() > MAX_FILE_TITLE_LENGTH) {
|
||||
throw BusinessException.validationError(
|
||||
"INVALID_FILE_TITLE", "fileTitle은 128자 이하여야 합니다.");
|
||||
}
|
||||
if (fileOrder == null || fileOrder <= 0) {
|
||||
throw BusinessException.validationError(
|
||||
"INVALID_FILE_ORDER", "fileOrder는 1 이상의 값이어야 합니다.");
|
||||
}
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw BusinessException.validationError(
|
||||
"EMPTY_REFERENCE_FILE", "업로드할 파일이 비어 있습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private String validateFilename(String originalFilename) {
|
||||
if (originalFilename == null || originalFilename.isBlank()) {
|
||||
throw invalidFilename("원본 파일명이 필요합니다.");
|
||||
}
|
||||
if (originalFilename.length() > MAX_FILENAME_LENGTH) {
|
||||
throw invalidFilename("원본 파일명은 64자 이하여야 합니다.");
|
||||
}
|
||||
if (originalFilename.indexOf('\0') >= 0
|
||||
|| originalFilename.contains("/")
|
||||
|| originalFilename.contains("\\")
|
||||
|| originalFilename.matches(".*[<>:\"|?*].*")
|
||||
|| originalFilename.endsWith(".")
|
||||
|| originalFilename.endsWith(" ")
|
||||
|| originalFilename.equals(".")
|
||||
|| originalFilename.equals("..")
|
||||
|| !Path.of(originalFilename).getFileName().toString().equals(originalFilename)) {
|
||||
throw invalidFilename("허용되지 않는 파일명입니다.");
|
||||
}
|
||||
return originalFilename;
|
||||
}
|
||||
|
||||
private String extractFileType(String filename) {
|
||||
int separator = filename.lastIndexOf('.');
|
||||
if (separator <= 0 || separator == filename.length() - 1) {
|
||||
throw BusinessException.validationError(
|
||||
"INVALID_REFERENCE_FILE_TYPE", "확장자가 있는 파일만 업로드할 수 있습니다.");
|
||||
}
|
||||
String fileType = filename.substring(separator + 1).toLowerCase(Locale.ROOT);
|
||||
if (fileType.length() > MAX_FILE_TYPE_LENGTH) {
|
||||
throw BusinessException.validationError(
|
||||
"INVALID_REFERENCE_FILE_TYPE", "파일 확장자는 16자 이하여야 합니다.");
|
||||
}
|
||||
return fileType;
|
||||
}
|
||||
|
||||
private Path stageFile(Path targetDirectory, MultipartFile file) {
|
||||
Path stagedFile = null;
|
||||
try {
|
||||
Files.createDirectories(targetDirectory);
|
||||
stagedFile = Files.createTempFile(targetDirectory, ".upload-", ".tmp");
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
Files.copy(inputStream, stagedFile, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
return stagedFile;
|
||||
} catch (IOException exception) {
|
||||
deleteQuietly(stagedFile, "임시 업로드 파일을 삭제하지 못했습니다.");
|
||||
throw storageError();
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceFileWithRollbackProtection(Path stagedFile, Path target) {
|
||||
boolean targetExisted = Files.exists(target);
|
||||
Path backupFile = null;
|
||||
try {
|
||||
if (targetExisted) {
|
||||
Path pendingBackup = Files.createTempFile(target.getParent(), ".backup-", ".tmp");
|
||||
try {
|
||||
Files.copy(target, pendingBackup,
|
||||
StandardCopyOption.REPLACE_EXISTING,
|
||||
StandardCopyOption.COPY_ATTRIBUTES);
|
||||
backupFile = pendingBackup;
|
||||
} catch (IOException exception) {
|
||||
deleteQuietly(pendingBackup, "완성되지 않은 파일 백업을 삭제하지 못했습니다.");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
moveReplacing(stagedFile, target);
|
||||
registerFileSynchronization(target, backupFile, targetExisted);
|
||||
} catch (IOException | RuntimeException exception) {
|
||||
restoreFile(target, backupFile, targetExisted);
|
||||
throw storageError();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerFileSynchronization(
|
||||
Path target,
|
||||
Path backupFile,
|
||||
boolean targetExisted
|
||||
) {
|
||||
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
restoreFile(target, backupFile, targetExisted);
|
||||
throw BusinessException.internalError(
|
||||
"REFERENCE_FILE_TRANSACTION_REQUIRED", "파일 저장 트랜잭션을 시작할 수 없습니다.");
|
||||
}
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
public void afterCompletion(int status) {
|
||||
if (status == STATUS_COMMITTED) {
|
||||
deleteQuietly(backupFile, "파일 백업을 삭제하지 못했습니다.");
|
||||
return;
|
||||
}
|
||||
restoreFile(target, backupFile, targetExisted);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void restoreFile(Path target, Path backupFile, boolean targetExisted) {
|
||||
try {
|
||||
if (targetExisted && backupFile != null && Files.exists(backupFile)) {
|
||||
moveReplacing(backupFile, target);
|
||||
} else if (!targetExisted) {
|
||||
Files.deleteIfExists(target);
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
log.error("트랜잭션 롤백 중 기존 파일을 복구하지 못했습니다: {}", target, exception);
|
||||
} finally {
|
||||
deleteQuietly(backupFile, "파일 백업을 삭제하지 못했습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private void moveReplacing(Path source, Path target) throws IOException {
|
||||
try {
|
||||
Files.move(source, target,
|
||||
StandardCopyOption.ATOMIC_MOVE,
|
||||
StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (AtomicMoveNotSupportedException exception) {
|
||||
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteQuietly(Path path, String failureMessage) {
|
||||
if (path == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Files.deleteIfExists(path);
|
||||
} catch (IOException exception) {
|
||||
log.warn("{} path={}", failureMessage, path, exception);
|
||||
}
|
||||
}
|
||||
|
||||
private BusinessException invalidFilename(String message) {
|
||||
return BusinessException.validationError("INVALID_REFERENCE_FILENAME", message);
|
||||
}
|
||||
|
||||
private BusinessException storageError() {
|
||||
return BusinessException.internalError(
|
||||
"REFERENCE_FILE_STORAGE_FAILED", "파일을 저장할 수 없습니다.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.kri.epolicy.dash.back.service;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.epolicy.dash.back.dto.auth.LoginRequestDto;
|
||||
import com.kri.epolicy.dash.back.dto.auth.UserDto;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TUserEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.repository.UserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserDto getUserWithLoginRequest(LoginRequestDto req){
|
||||
TUserEntity userEntity = userRepository.findByUserIdAndUserPw(req.getUserId(), req.getUserPw())
|
||||
.orElseThrow(() ->
|
||||
BusinessException
|
||||
.notFound("USER_NOT_FOUND", "사용자가 없습니다.")
|
||||
.with("userId", req.getUserId())
|
||||
);
|
||||
return UserDto.from(userEntity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.kri.epolicy.dash.back.service;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TWaveEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class WaveAccessPolicy {
|
||||
|
||||
static final int OPEN_WAVE_ONLY_ROLE = 2010;
|
||||
|
||||
public boolean canAccess(TWaveEntity wave, RequestUserContext userContext) {
|
||||
Integer userRole = userContext == null ? null : userContext.getUserRole();
|
||||
return Boolean.TRUE.equals(wave.getIsOpen())
|
||||
|| (userRole != null && userRole < OPEN_WAVE_ONLY_ROLE);
|
||||
}
|
||||
|
||||
public void validate(TWaveEntity wave, RequestUserContext userContext) {
|
||||
if (!canAccess(wave, userContext)) {
|
||||
throw BusinessException.forbidden(
|
||||
"WAVE_ACCESS_DENIED", "공개되지 않은 조사 차수에는 접근할 수 없습니다.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
package com.kri.epolicy.dash.back.service;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.epolicy.dash.back.config.FileStorageProperties;
|
||||
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.Category;
|
||||
import com.kri.epolicy.dash.back.dto.response.PartDetailResponse.Item;
|
||||
import com.kri.epolicy.dash.back.dto.response.PartDetailResponse.ResultGroup;
|
||||
import com.kri.epolicy.dash.back.dto.response.PartDetailResponse.Series;
|
||||
import com.kri.epolicy.dash.back.dto.response.PartDetailResponse.SubItem;
|
||||
import com.kri.epolicy.dash.back.dto.response.WaveDetailResponse;
|
||||
import com.kri.epolicy.dash.back.dto.response.WaveSummaryResponse;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TFileEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartItemBaseEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TPartItemDataEntity;
|
||||
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.TSurveyEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TSurveyItemEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TWaveEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.id.TPartEntityId;
|
||||
import com.kri.epolicy.dash.back.persistence.repository.FileRepository;
|
||||
import com.kri.epolicy.dash.back.persistence.repository.PartItemBaseRepository;
|
||||
import com.kri.epolicy.dash.back.persistence.repository.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.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.util.UriUtils;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
public class WaveQueryService {
|
||||
|
||||
private final WaveRepository waveRepository;
|
||||
private final WaveInfoRepository waveInfoRepository;
|
||||
private final SurveyRepository surveyRepository;
|
||||
private final SurveyItemRepository surveyItemRepository;
|
||||
private final FileRepository fileRepository;
|
||||
private final PartRepository partRepository;
|
||||
private final PartItemRepository partItemRepository;
|
||||
private final PartItemSubRepository partItemSubRepository;
|
||||
private final PartItemBaseRepository partItemBaseRepository;
|
||||
private final PartItemDataRepository partItemDataRepository;
|
||||
private final WaveAccessPolicy waveAccessPolicy;
|
||||
private final FileStorageProperties fileStorageProperties;
|
||||
|
||||
public List<WaveSummaryResponse> findWaves(RequestUserContext userContext) {
|
||||
return waveRepository.findAllByOrderByYearDescWaveDesc().stream()
|
||||
.map(wave -> toSummary(wave, userContext))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public WaveDetailResponse findWave(Short waveCd, RequestUserContext userContext) {
|
||||
TWaveEntity wave = findAccessibleWave(waveCd, userContext);
|
||||
List<TSurveyEntity> surveys = surveyRepository.findByIdWaveCdOrderBySurveyOrderAsc(waveCd);
|
||||
Map<Short, List<TSurveyItemEntity>> surveyItems = surveyItemRepository
|
||||
.findByWaveCdOrderBySurveyItemOrderAsc(waveCd).stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
TSurveyItemEntity::getSurveyCd, LinkedHashMap::new, Collectors.toList()));
|
||||
List<TPartEntity> parts = partRepository.findByIdWaveCdOrderByPartOrderAsc(waveCd);
|
||||
Map<Short, List<TPartItemEntity>> partItems = partItemRepository
|
||||
.findByIdWaveCdOrderByPartItemOrderAsc(waveCd).stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
item -> item.getId().getPartCd(), LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
return new WaveDetailResponse(
|
||||
toSummary(wave, userContext),
|
||||
waveInfoRepository.findByWaveCdOrderByWaveInfoOrderAsc(waveCd).stream()
|
||||
.map(info -> new WaveDetailResponse.OverviewItem(
|
||||
info.getWaveInfoTitle(), info.getWaveInfoContent()))
|
||||
.toList(),
|
||||
surveys.stream().map(survey -> new WaveDetailResponse.Survey(
|
||||
survey.getId().getSurveyCd(),
|
||||
survey.getSurveyTitle(),
|
||||
survey.getSurveyAlias(),
|
||||
surveyItems.getOrDefault(survey.getId().getSurveyCd(), List.of()).stream()
|
||||
.map(item -> new WaveDetailResponse.SurveyItem(
|
||||
item.getSurveyItemTitle(), item.getSurveyItemContent()))
|
||||
.toList()
|
||||
)).toList(),
|
||||
parts.stream().map(part -> {
|
||||
List<TPartItemEntity> items = partItems.getOrDefault(part.getId().getPartCd(), List.of());
|
||||
return new WaveDetailResponse.PartMenu(
|
||||
part.getId().getPartCd(),
|
||||
part.getPartTitle(),
|
||||
items.size(),
|
||||
items.stream().map(item -> new WaveDetailResponse.PartItemMenu(
|
||||
item.getId().getPartItemCd(), item.getPartItemTitle())).toList()
|
||||
);
|
||||
}).toList(),
|
||||
fileRepository.findByWaveCdOrderByFileOrderAsc(waveCd).stream()
|
||||
.map(file -> toFileDownload(waveCd, file))
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
|
||||
public PartDetailResponse findPart(
|
||||
Short waveCd,
|
||||
Short partCd,
|
||||
RequestUserContext userContext
|
||||
) {
|
||||
findAccessibleWave(waveCd, userContext);
|
||||
TPartEntity part = partRepository.findById(partId(waveCd, partCd)).orElseThrow(() ->
|
||||
BusinessException.notFound(
|
||||
"PART_NOT_FOUND", "요청한 Part를 찾을 수 없습니다."));
|
||||
|
||||
List<TSurveyEntity> surveys = surveyRepository.findByIdWaveCdOrderBySurveyOrderAsc(waveCd);
|
||||
Map<Short, TSurveyEntity> surveyByCode = surveys.stream().collect(Collectors.toMap(
|
||||
survey -> survey.getId().getSurveyCd(), Function.identity(), (left, right) -> left,
|
||||
LinkedHashMap::new));
|
||||
List<TPartItemEntity> items = partItemRepository
|
||||
.findByIdWaveCdAndIdPartCdOrderByPartItemOrderAsc(waveCd, partCd);
|
||||
List<TPartItemSubEntity> subs = partItemSubRepository
|
||||
.findByIdWaveCdAndIdPartCdOrderByIdPartItemCdAscIdPartItemSubCdAsc(waveCd, partCd);
|
||||
List<TPartItemBaseEntity> bases = partItemBaseRepository.findByWaveCdAndPartCd(waveCd, partCd);
|
||||
List<TPartItemDataEntity> data = partItemDataRepository
|
||||
.findByWaveCdAndPartCdOrderByPartItemDataOrderAsc(waveCd, partCd);
|
||||
|
||||
Map<Short, List<TPartItemSubEntity>> subsByItem = subs.stream().collect(Collectors.groupingBy(
|
||||
sub -> sub.getId().getPartItemCd(), LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
return new PartDetailResponse(
|
||||
waveCd,
|
||||
partCd,
|
||||
part.getPartTitle(),
|
||||
items.stream().map(item -> toItem(item, surveys, surveyByCode, subsByItem, bases, data))
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
|
||||
private Item toItem(
|
||||
TPartItemEntity item,
|
||||
List<TSurveyEntity> surveys,
|
||||
Map<Short, TSurveyEntity> surveyByCode,
|
||||
Map<Short, List<TPartItemSubEntity>> subsByItem,
|
||||
List<TPartItemBaseEntity> allBases,
|
||||
List<TPartItemDataEntity> allData
|
||||
) {
|
||||
Short itemCd = item.getId().getPartItemCd();
|
||||
List<TPartItemBaseEntity> bases = allBases.stream()
|
||||
.filter(base -> base.getPartItemCd().equals(itemCd)).toList();
|
||||
List<TPartItemDataEntity> data = allData.stream()
|
||||
.filter(value -> value.getPartItemCd().equals(itemCd)).toList();
|
||||
List<TPartItemSubEntity> subs = subsByItem.getOrDefault(itemCd, List.of());
|
||||
List<ResultGroup> groups = new ArrayList<>();
|
||||
|
||||
if (subs.isEmpty()) {
|
||||
groups.add(toResultGroup(null, bases, data, surveyByCode));
|
||||
} else {
|
||||
for (TPartItemSubEntity sub : subs) {
|
||||
Short subCd = sub.getId().getPartItemSubCd();
|
||||
groups.add(toResultGroup(
|
||||
new SubItem(subCd, sub.getPartItemSubTitle()),
|
||||
bases.stream().filter(base -> subCd.equals(base.getPartItemSubCd())).toList(),
|
||||
data.stream().filter(value -> subCd.equals(value.getPartItemSubCd())).toList(),
|
||||
surveyByCode));
|
||||
}
|
||||
}
|
||||
|
||||
Set<Short> audienceCodes = bases.stream()
|
||||
.map(TPartItemBaseEntity::getSurveyCd)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
return new Item(
|
||||
itemCd,
|
||||
item.getPartItemOrder(),
|
||||
item.getPartItemTitle(),
|
||||
item.getChartType().getCode(),
|
||||
item.getPartItemComment(),
|
||||
toAudience(audienceCodes, surveys, surveyByCode),
|
||||
List.copyOf(groups)
|
||||
);
|
||||
}
|
||||
|
||||
private ResultGroup toResultGroup(
|
||||
SubItem subItem,
|
||||
List<TPartItemBaseEntity> bases,
|
||||
List<TPartItemDataEntity> data,
|
||||
Map<Short, TSurveyEntity> surveyByCode
|
||||
) {
|
||||
Map<Short, TPartItemBaseEntity> baseBySurvey = bases.stream().collect(Collectors.toMap(
|
||||
TPartItemBaseEntity::getSurveyCd, Function.identity(), (left, right) -> left,
|
||||
LinkedHashMap::new));
|
||||
Map<Short, List<TPartItemDataEntity>> dataBySurvey = data.stream().collect(
|
||||
Collectors.groupingBy(TPartItemDataEntity::getSurveyCd,
|
||||
LinkedHashMap::new, Collectors.toList()));
|
||||
List<Short> surveyCodes = dataBySurvey.keySet().stream()
|
||||
.sorted(Comparator.comparing(code -> surveyByCode.get(code).getSurveyOrder()))
|
||||
.toList();
|
||||
List<Category> categories = surveyCodes.isEmpty() ? List.of()
|
||||
: dataBySurvey.get(surveyCodes.get(0)).stream()
|
||||
.sorted(Comparator.comparing(TPartItemDataEntity::getPartItemDataOrder))
|
||||
.map(value -> new Category(
|
||||
value.getPartItemDataOrder(),
|
||||
value.getPartItemDataLabel(),
|
||||
value.getIsChartVisible()))
|
||||
.toList();
|
||||
List<Series> series = surveyCodes.stream().map(surveyCd -> {
|
||||
TPartItemBaseEntity base = baseBySurvey.get(surveyCd);
|
||||
TSurveyEntity survey = surveyByCode.get(surveyCd);
|
||||
return new Series(
|
||||
surveyCd,
|
||||
survey.getSurveyAlias(),
|
||||
base == null ? null : base.getBaseCount(),
|
||||
base == null ? null : formatBase(base),
|
||||
dataBySurvey.get(surveyCd).stream()
|
||||
.sorted(Comparator.comparing(TPartItemDataEntity::getPartItemDataOrder))
|
||||
.map(TPartItemDataEntity::getPartItemDataValue)
|
||||
.toList()
|
||||
);
|
||||
}).toList();
|
||||
return new ResultGroup(subItem, categories, series);
|
||||
}
|
||||
|
||||
private Audience toAudience(
|
||||
Set<Short> audienceCodes,
|
||||
List<TSurveyEntity> surveys,
|
||||
Map<Short, TSurveyEntity> surveyByCode
|
||||
) {
|
||||
if (!surveys.isEmpty() && audienceCodes.size() == surveys.size()
|
||||
&& audienceCodes.containsAll(surveyByCode.keySet())) {
|
||||
return new Audience("COMMON", "공통");
|
||||
}
|
||||
String label = audienceCodes.stream()
|
||||
.map(surveyByCode::get)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.sorted(Comparator.comparing(TSurveyEntity::getSurveyOrder))
|
||||
.map(TSurveyEntity::getSurveyAlias)
|
||||
.collect(Collectors.joining(", "));
|
||||
return new Audience("SURVEY", label);
|
||||
}
|
||||
|
||||
private String formatBase(TPartItemBaseEntity base) {
|
||||
String prefix = base.getBasePreText() == null ? "" : base.getBasePreText();
|
||||
String suffix = base.getBasePostText() == null ? "" : base.getBasePostText();
|
||||
String count = NumberFormat.getIntegerInstance(Locale.KOREA).format(base.getBaseCount());
|
||||
return prefix + count + suffix;
|
||||
}
|
||||
|
||||
private WaveDetailResponse.FileDownload toFileDownload(Short waveCd, TFileEntity file) {
|
||||
String encodedFilename = UriUtils.encodePathSegment(file.getFileName(), java.nio.charset.StandardCharsets.UTF_8);
|
||||
String resourcePath = fileStorageProperties.getResourcePattern().replace("/**", "");
|
||||
if (resourcePath.endsWith("/")) {
|
||||
resourcePath = resourcePath.substring(0, resourcePath.length() - 1);
|
||||
}
|
||||
return new WaveDetailResponse.FileDownload(
|
||||
file.getId(),
|
||||
file.getFileTitle(),
|
||||
file.getFileType(),
|
||||
file.getFileName(),
|
||||
resourcePath + "/References/" + waveCd + "/" + encodedFilename
|
||||
);
|
||||
}
|
||||
|
||||
private TWaveEntity findAccessibleWave(Short waveCd, RequestUserContext userContext) {
|
||||
TWaveEntity wave = waveRepository.findById(waveCd).orElseThrow(() ->
|
||||
BusinessException.notFound("WAVE_NOT_FOUND", "요청한 조사 차수를 찾을 수 없습니다."));
|
||||
waveAccessPolicy.validate(wave, userContext);
|
||||
return wave;
|
||||
}
|
||||
|
||||
private TPartEntityId partId(Short waveCd, Short partCd) {
|
||||
TPartEntityId id = new TPartEntityId();
|
||||
id.setWaveCd(waveCd);
|
||||
id.setPartCd(partCd);
|
||||
return id;
|
||||
}
|
||||
|
||||
private WaveSummaryResponse toSummary(TWaveEntity wave, RequestUserContext userContext) {
|
||||
return new WaveSummaryResponse(
|
||||
wave.getId(),
|
||||
wave.getYear(),
|
||||
wave.getWave(),
|
||||
wave.getLabel(),
|
||||
wave.getIsOpen(),
|
||||
waveAccessPolicy.canAccess(wave, userContext)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.kri.epolicy.dash.back.service.common;
|
||||
|
||||
import static com.kri.common.feature.json.JsonUtil.toMap;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import com.kri.epolicy.dash.back.common.enums.SystemEventType;
|
||||
import com.kri.epolicy.dash.back.persistence.entity.TSysEventLogEntity;
|
||||
import com.kri.epolicy.dash.back.persistence.repository.SysEventLogRepository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemEventLogService {
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
private final SysEventLogRepository sysEventLogRepository;
|
||||
|
||||
public void writeLoginLog(String userId, LocalDateTime regDt, String clientIp) {
|
||||
writeSystemLog(
|
||||
SystemEventType.LOGIN,
|
||||
"Login",
|
||||
userId,
|
||||
regDt,
|
||||
clientIp,
|
||||
"userId",
|
||||
userId
|
||||
);
|
||||
}
|
||||
|
||||
public void writeLogoutLog(String userId, LocalDateTime regDt, String clientIp) {
|
||||
writeSystemLog(
|
||||
SystemEventType.LOGOUT,
|
||||
"Logout",
|
||||
userId,
|
||||
regDt,
|
||||
clientIp,
|
||||
"userId",
|
||||
userId
|
||||
);
|
||||
}
|
||||
protected <T> void writeSystemLog(
|
||||
SystemEventType eventType,
|
||||
String title,
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
T content
|
||||
) {
|
||||
Map<String, Object> contentMap = toMap(objectMapper, content);
|
||||
|
||||
saveLog(eventType, title, regId, regDt, clientIp, contentMap);
|
||||
}
|
||||
|
||||
protected <T> void writeSystemLog(
|
||||
SystemEventType eventType,
|
||||
String title,
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
String contentKey,
|
||||
T content
|
||||
) {
|
||||
Map<String, Object> contentMap = Map.of(contentKey, content);
|
||||
saveLog(eventType, title, regId, regDt, clientIp, contentMap);
|
||||
}
|
||||
|
||||
private void saveLog(
|
||||
SystemEventType eventType,
|
||||
String title,
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
Map<String, Object> contentMap
|
||||
) {
|
||||
TSysEventLogEntity log = TSysEventLogEntity.of(
|
||||
eventType,
|
||||
title,
|
||||
contentMap,
|
||||
clientIp,
|
||||
regId,
|
||||
regDt
|
||||
);
|
||||
|
||||
sysEventLogRepository.save(log);
|
||||
}
|
||||
}
|
||||
6
src/main/resources/application-dev.yml
Normal file
6
src/main/resources/application-dev.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://db-md87m.vpc-cdb.ntruss.com:3306/test_epolicy_dash?characterEncoding=UTF-8&rewriteBatchedStatements=true
|
||||
username: pjrct_epolicy
|
||||
password: epolicy#260813
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
6
src/main/resources/application-local.yml
Normal file
6
src/main/resources/application-local.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/test_epolicy_dash?characterEncoding=UTF-8&rewriteBatchedStatements=true
|
||||
username: pjrct_epolicy
|
||||
password: epolicy#260813
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
6
src/main/resources/application-prod.yml
Normal file
6
src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://db-md87m.vpc-cdb.ntruss.com:3306/prjct_epolicy_dash?characterEncoding=UTF-8&rewriteBatchedStatements=true
|
||||
username: pjrct_epolicy
|
||||
password: epolicy#260813
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
63
src/main/resources/application.yml
Normal file
63
src/main/resources/application.yml
Normal file
@@ -0,0 +1,63 @@
|
||||
server:
|
||||
port: 6107
|
||||
forward-headers-strategy: framework
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: epolicy-dash-back
|
||||
profiles:
|
||||
default: local
|
||||
jpa:
|
||||
open-in-view: false
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
properties:
|
||||
hibernate:
|
||||
jdbc:
|
||||
batch_size: 1000
|
||||
order_inserts: true
|
||||
order_updates: true
|
||||
format_sql: true
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB
|
||||
max-request-size: 20MB
|
||||
|
||||
logging:
|
||||
file:
|
||||
path: ./logs
|
||||
|
||||
springdoc:
|
||||
writer-with-order-by-keys: true
|
||||
swagger-ui:
|
||||
tags-sorter: alpha
|
||||
operations-sorter: method
|
||||
|
||||
kri:
|
||||
auth:
|
||||
apikey:
|
||||
enabled: false
|
||||
security:
|
||||
enabled: true
|
||||
public-paths:
|
||||
- /v3/api-docs/**
|
||||
- /swagger-ui.html
|
||||
- /swagger-ui/**
|
||||
- /api/v1/auth/login
|
||||
- /files/**
|
||||
swagger:
|
||||
enabled: true
|
||||
title: "epolicy-dash-back API"
|
||||
description: "epolicy-dash-back Spring Boot application"
|
||||
version: "v1.0.0"
|
||||
base-package: "com.kri.epolicy.dash.back"
|
||||
allowed-ips: []
|
||||
file:
|
||||
base-dir: ./upload-file
|
||||
resource-pattern: /files/**
|
||||
web:
|
||||
enabled: true
|
||||
redis:
|
||||
enabled: false
|
||||
scheduling:
|
||||
enabled: false
|
||||
Reference in New Issue
Block a user