261016_01_ENH: 1차 마이그레이션 완료

This commit is contained in:
2026-10-16 12:21:37 +09:00
parent 7ca665397e
commit 26088f6fd0
188 changed files with 10522 additions and 573 deletions

View File

@@ -2,12 +2,20 @@ package com.kri.kart.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
@SpringBootApplication
// Common owns the isolated API Key JPA configuration.
@SpringBootApplication(
exclude = {
DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class,
JpaRepositoriesAutoConfiguration.class
})
@ConfigurationPropertiesScan
public class KartServerApplication {
public static void main(String[] args) {
SpringApplication.run(KartServerApplication.class, args);
}

View File

@@ -1,9 +0,0 @@
package com.kri.kart.server.common.consts;
public final class ExampleConstant {
public static final int DEFAULT_BATCH_SIZE = 1_000;
private ExampleConstant() {
}
}

View File

@@ -1,6 +0,0 @@
package com.kri.kart.server.common.enums;
public enum ExampleStatus {
ACTIVE,
INACTIVE
}

View File

@@ -0,0 +1,31 @@
package com.kri.kart.server.common.enums;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.kri.common.feature.enums.CodeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter(onMethod_ = @JsonValue)
@RequiredArgsConstructor
@Schema(description = "프로젝트 유형: 0=KON, 1=KIWI")
public enum ProjectType implements CodeEnum<Integer> {
KON(0),
KIWI(1);
private final Integer code;
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static ProjectType fromCode(Integer code) {
if (code == null) {
return null;
}
for (ProjectType s : values()) {
if (s.code.equals(code)) {
return s;
}
}
throw new IllegalArgumentException("Unknown ProjectType code: " + code);
}
}

View File

@@ -0,0 +1,105 @@
package com.kri.kart.server.common.external.intranet;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kri.common.feature.http.ExternalApiClient;
import com.kri.common.feature.http.ExternalApiResponse;
import com.kri.common.feature.web.BusinessException;
import com.kri.kart.server.dto.auth.LoginRequestDto;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
@Component
public class IntranetExtensionApiClient {
private final ExternalApiClient externalApiClient;
private final ObjectMapper objectMapper;
private final String intranetExtensionBaseUrl;
private final String apiKey;
private final String apiKeyHeaderName;
public IntranetExtensionApiClient(
ExternalApiClient externalApiClient,
ObjectMapper objectMapper,
@Value("${kri.api-url.intranet-extension}") String intranetExtensionBaseUrl,
@Value("${kri.auth.apikey.key}") String apiKey,
@Value("${kri.auth.apikey.header-name:X-API-Key}") String apiKeyHeaderName) {
this.externalApiClient = externalApiClient;
this.objectMapper = objectMapper;
this.intranetExtensionBaseUrl = intranetExtensionBaseUrl;
this.apiKey = apiKey;
this.apiKeyHeaderName = apiKeyHeaderName;
}
public IntranetUserDto searchLoginInfo(LoginRequestDto request) {
try {
ExternalApiResponse response =
externalApiClient.post(
url("/user/login-info"), headers(), objectMapper.writeValueAsString(request));
if (response.getStatusCode() != 200) {
return null;
}
IntranetUserDto intranetUser =
objectMapper.readValue(response.getBody(), IntranetUserDto.class);
if (intranetUser == null
|| intranetUser.getUserId() == null
|| intranetUser.getUserId().isBlank()
|| intranetUser.getUserRole() == null) return null;
return intranetUser;
} catch (Exception ignored) {
// Failed authentication, HTTP errors, timeouts and malformed responses all fall back.
// Never log the request password, headers or upstream response body.
return null;
}
}
public List<String> getExcludedOwnerIds() {
try {
ExternalApiResponse response = externalApiClient.get(url("/user/list"), headers());
if (response.getStatusCode() != 200) {
throw new IllegalStateException("Upstream unavailable");
}
List<IntranetUserDto> users =
objectMapper.readValue(response.getBody(), new TypeReference<>() {});
if (users == null
|| users.stream()
.anyMatch(u -> u == null || u.getUserId() == null || u.getUserId().isBlank())) {
throw new IllegalStateException("Invalid upstream response");
}
return users.stream()
.filter(u -> "S101".equals(u.getUserTeam()) || "S201".equals(u.getUserTeam()))
.map(IntranetUserDto::getUserId)
.map(
id -> {
if (id == null || id.isBlank()) {
throw new IllegalStateException("Missing upstream ID");
}
return id;
})
.distinct()
.toList();
} catch (Exception ignored) {
// Do not silently broaden the project list when the exclusion source is unavailable.
throw BusinessException.of(
HttpStatus.SERVICE_UNAVAILABLE,
"INTRANET_USER_LIST_UNAVAILABLE",
"프로젝트 제외 대상 사용자 목록을 조회할 수 없습니다.");
}
}
private String url(String path) {
if (intranetExtensionBaseUrl == null || intranetExtensionBaseUrl.isBlank()) {
throw new IllegalStateException("Intranet base URL is not configured");
}
return intranetExtensionBaseUrl.replaceAll("/+$", "") + path;
}
private Map<String, String> headers() {
if (apiKey == null || apiKey.isBlank()) {
throw new IllegalStateException("Intranet API key is not configured");
}
return Map.of(apiKeyHeaderName, apiKey);
}
}

View File

@@ -0,0 +1,16 @@
package com.kri.kart.server.common.external.intranet;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class IntranetUserDto {
private String userId;
private String userCmpn;
private String userNm;
private String userTeam;
private Integer userRole;
}

View File

@@ -0,0 +1,21 @@
package com.kri.kart.server.common.util;
import java.util.Locale;
public final class DateTimeUtil {
private DateTimeUtil() {}
public static String formatSeconds(String seconds) {
if (seconds == null || seconds.isBlank()) {
return "";
}
try {
int value = Integer.parseInt(seconds);
return String.format(
Locale.ROOT, "%02d:%02d:%02d", value / 3600, value % 3600 / 60, value % 3600 % 60);
} catch (NumberFormatException ignored) {
return "";
}
}
}

View File

@@ -1,13 +0,0 @@
package com.kri.kart.server.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;
}
}

View File

@@ -1,4 +1,2 @@
/**
* 프로젝트 전용 Bean Validation annotation과 validator를 배치합니다.
*/
/** 프로젝트 전용 Bean Validation annotation과 validator를 배치합니다. */
package com.kri.kart.server.common.validation;

View File

@@ -0,0 +1,17 @@
package com.kri.kart.server.config;
import com.kri.common.feature.http.ExternalApiClient;
import java.net.http.HttpClient;
import java.time.Duration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class IntranetClientConfig {
@Bean
public ExternalApiClient intranetHttpClient() {
return new ExternalApiClient(
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build(),
Duration.ofSeconds(15));
}
}

View File

@@ -1,15 +0,0 @@
package com.kri.kart.server.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);
}
}

View File

@@ -0,0 +1,32 @@
package com.kri.kart.server.config;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Getter
@Setter
@ConfigurationProperties(prefix = "kri.kart.database")
public class KartDatabaseProperties {
private boolean enabled;
@Valid private Source kon = new Source();
@Valid private Source konkiwi = new Source();
@Valid private Source kart = new Source();
// No toString: credentials must not appear in logs.
@Getter
@Setter
public static class Source {
@NotBlank private String url;
@NotBlank private String username;
@NotBlank private String password;
@Min(1)
@Max(50)
private int maximumPoolSize = 5;
}
}

View File

@@ -0,0 +1,130 @@
package com.kri.kart.server.config;
import com.zaxxer.hikari.HikariDataSource;
import jakarta.validation.Validator;
import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(KartDatabaseProperties.class)
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class KartMyBatisConfig {
@Bean(destroyMethod = "close")
public HikariDataSource konDataSource(KartDatabaseProperties properties, Validator validator) {
return dataSource("kon", properties.getKon(), validator);
}
@Bean(destroyMethod = "close")
public HikariDataSource konkiwiDataSource(
KartDatabaseProperties properties, Validator validator) {
return dataSource("konkiwi", properties.getKonkiwi(), validator);
}
@Bean(destroyMethod = "close")
@Primary
public HikariDataSource kartDataSource(KartDatabaseProperties properties, Validator validator) {
return dataSource("kart", properties.getKart(), validator);
}
private HikariDataSource dataSource(
String name, KartDatabaseProperties.Source source, Validator validator) {
if (source == null
|| !validator.validate(source).isEmpty()
|| !source.getUrl().startsWith("jdbc:sqlserver://")) {
throw new IllegalArgumentException("Invalid " + name + " database configuration");
}
// Lazy pool: creating beans and SqlSessionFactory never opens a real connection.
HikariDataSource dataSource = new HikariDataSource();
dataSource.setPoolName("kart".equals(name) ? name : "kart-" + name);
dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
dataSource.setJdbcUrl(source.getUrl());
dataSource.setUsername(source.getUsername());
dataSource.setPassword(source.getPassword());
dataSource.setMaximumPoolSize(source.getMaximumPoolSize());
dataSource.setMinimumIdle(0);
dataSource.setConnectionTimeout(10000);
dataSource.setInitializationFailTimeout(-1);
return dataSource;
}
@Bean
public SqlSessionFactory konSqlSessionFactory(@Qualifier("konDataSource") DataSource dataSource)
throws Exception {
return sessionFactory(dataSource, "survey");
}
@Bean
public SqlSessionFactory konkiwiSqlSessionFactory(
@Qualifier("konkiwiDataSource") DataSource dataSource) throws Exception {
return sessionFactory(dataSource, "survey");
}
@Bean
@Primary
public SqlSessionFactory kartSqlSessionFactory(
@Qualifier("kartDataSource") DataSource dataSource) throws Exception {
return sessionFactory(dataSource, "kart");
}
private SqlSessionFactory sessionFactory(DataSource dataSource, String mapperGroup)
throws Exception {
SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
factory.setDataSource(dataSource);
org.apache.ibatis.session.Configuration configuration =
new org.apache.ibatis.session.Configuration();
configuration.setMapUnderscoreToCamelCase(true);
configuration.setDatabaseId(mapperGroup);
factory.setConfiguration(configuration);
factory.setMapperLocations(
new PathMatchingResourcePatternResolver().getResources("classpath*:mybatis/mapper/*.xml"));
return factory.getObject();
}
@Bean
public SqlSessionTemplate konSqlSessionTemplate(
@Qualifier("konSqlSessionFactory") SqlSessionFactory factory) {
return new SqlSessionTemplate(factory);
}
@Bean
public SqlSessionTemplate konkiwiSqlSessionTemplate(
@Qualifier("konkiwiSqlSessionFactory") SqlSessionFactory factory) {
return new SqlSessionTemplate(factory);
}
@Bean
@Primary
public SqlSessionTemplate kartSqlSessionTemplate(
@Qualifier("kartSqlSessionFactory") SqlSessionFactory factory) {
return new SqlSessionTemplate(factory);
}
@Bean
public DataSourceTransactionManager konTransactionManager(
@Qualifier("konDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
public DataSourceTransactionManager konkiwiTransactionManager(
@Qualifier("konkiwiDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
@Primary
public DataSourceTransactionManager kartTransactionManager(
@Qualifier("kartDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}

View File

@@ -1,19 +0,0 @@
package com.kri.kart.server.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);
}
}

View File

@@ -0,0 +1,23 @@
package com.kri.kart.server.config;
import com.kri.kart.server.service.ShareLinkService;
import com.kri.kart.server.service.share.ExternalAccessInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(ShareLinkProperties.class)
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class ShareLinkConfig implements WebMvcConfigurer {
private final ShareLinkService shareLinkService;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new ExternalAccessInterceptor(shareLinkService)).addPathPatterns("/**");
}
}

View File

@@ -0,0 +1,14 @@
package com.kri.kart.server.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Getter
@Setter
@ConfigurationProperties("kri.kart.share")
public class ShareLinkProperties {
private String publicOrigin = "https://kart.kric.com";
private String legacyKey;
private String legacyIv;
}

View File

@@ -14,13 +14,11 @@ public class WebResourceConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String location = Path.of(fileStorageProperties.getBaseDir())
.toAbsolutePath()
.normalize()
.toUri()
.toString();
String location =
Path.of(fileStorageProperties.getBaseDir()).toAbsolutePath().normalize().toUri().toString();
registry.addResourceHandler(fileStorageProperties.getResourcePattern())
registry
.addResourceHandler(fileStorageProperties.getResourcePattern())
.addResourceLocations(location.endsWith("/") ? location : location + "/");
}
}

View File

@@ -0,0 +1,27 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.dto.auth.LoginRequestDto;
import com.kri.kart.server.dto.auth.LoginResponseDto;
import com.kri.kart.server.service.AuthService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
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
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class AuthController {
private final AuthService authService;
@PostMapping("/login")
public LoginResponseDto login(
@Valid @RequestBody LoginRequestDto request, RequestUserContext ctx) {
return authService.login(request, ctx.getClientIp());
}
}

View File

@@ -0,0 +1,71 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.common.enums.ProjectType;
import com.kri.kart.server.dto.bookmark.BookmarkDto;
import com.kri.kart.server.dto.bookmark.BookmarkSaveRequestDto;
import com.kri.kart.server.dto.project.ProjectRefDto;
import com.kri.kart.server.service.BookmarkService;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;
import jakarta.validation.groups.Default;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/v1/project/{projectType}/{pkey}/bookmark")
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class BookmarkController {
private final BookmarkService bookmarkService;
@GetMapping("/list")
public List<BookmarkDto> list(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@RequestParam String page,
@Parameter(hidden = true) RequestUserContext ctx) {
return bookmarkService.list(new ProjectRefDto(projectType, pkey), page, ctx.getUserId());
}
@PostMapping(produces = MediaType.TEXT_PLAIN_VALUE)
public String create(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Validated({Default.class, BookmarkSaveRequestDto.Create.class}) @RequestBody
BookmarkSaveRequestDto request,
@Parameter(hidden = true) RequestUserContext ctx) {
return bookmarkService.create(new ProjectRefDto(projectType, pkey), request, ctx);
}
@PutMapping(value = "/{bookmarkId}", produces = MediaType.TEXT_PLAIN_VALUE)
public String update(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@PathVariable String bookmarkId,
@Valid @RequestBody BookmarkSaveRequestDto request,
@Parameter(hidden = true) RequestUserContext ctx) {
return bookmarkService.update(new ProjectRefDto(projectType, pkey), bookmarkId, request, ctx);
}
@DeleteMapping(value = "/{bookmarkId}", produces = MediaType.APPLICATION_JSON_VALUE)
public boolean delete(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@PathVariable String bookmarkId,
@Parameter(hidden = true) RequestUserContext ctx) {
return bookmarkService.delete(new ProjectRefDto(projectType, pkey), bookmarkId, ctx);
}
}

View File

@@ -0,0 +1,91 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.common.enums.ProjectType;
import com.kri.kart.server.dto.derived.DerivedCalculationDto;
import com.kri.kart.server.dto.derived.DerivedSaveRequestDto;
import com.kri.kart.server.dto.derived.DerivedVariableDto;
import com.kri.kart.server.dto.project.ProjectRefDto;
import com.kri.kart.server.service.DerivedManagementService;
import com.kri.kart.server.service.DerivedService;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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/project/{projectType}/{pkey}/derived")
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class DerivedController {
private final DerivedService derivedService;
private final DerivedManagementService derivedManagementService;
@GetMapping("/list")
public List<DerivedVariableDto> list(
@PathVariable ProjectType projectType, @PathVariable String pkey, RequestUserContext ctx) {
return derivedService.list(new ProjectRefDto(projectType, pkey), ctx);
}
@PostMapping
public String create(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Valid @RequestBody DerivedSaveRequestDto request,
RequestUserContext ctx) {
return derivedManagementService.save(new ProjectRefDto(projectType, pkey), null, request, ctx);
}
@PutMapping("/{variableId}")
public String update(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@PathVariable String variableId,
@Valid @RequestBody DerivedSaveRequestDto request,
RequestUserContext ctx) {
return derivedManagementService.save(
new ProjectRefDto(projectType, pkey), variableId, request, ctx);
}
@DeleteMapping("/{variableId}")
public boolean delete(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@PathVariable String variableId,
RequestUserContext ctx) {
return derivedManagementService.delete(new ProjectRefDto(projectType, pkey), variableId, ctx);
}
@PostMapping("/{variableId}/recalculate")
public DerivedCalculationDto recalculate(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@PathVariable String variableId,
RequestUserContext ctx) {
return derivedManagementService.recalculate(
new ProjectRefDto(projectType, pkey), variableId, ctx);
}
@PostMapping("/respondent/{respondentId}/recalculate")
public DerivedCalculationDto recalculateRespondent(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@PathVariable String respondentId) {
return derivedManagementService.recalculateRespondent(
new ProjectRefDto(projectType, pkey), respondentId);
}
@PostMapping("/recalculate")
public DerivedCalculationDto recalculateAll(
@PathVariable ProjectType projectType, @PathVariable String pkey, RequestUserContext ctx) {
return derivedManagementService.recalculate(new ProjectRefDto(projectType, pkey), null, ctx);
}
}

View File

@@ -1,38 +0,0 @@
package com.kri.kart.server.controller;
import com.kri.kart.server.dto.request.CreateExampleRequest;
import com.kri.kart.server.dto.response.ExampleResponse;
import com.kri.kart.server.service.ExampleService;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/examples")
public class ExampleController {
private final ExampleService exampleService;
@GetMapping
public List<ExampleResponse> search(
@RequestParam(defaultValue = "") String keyword,
@RequestParam(defaultValue = "20") int limit
) {
return exampleService.search(keyword, limit);
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ExampleResponse create(@Valid @RequestBody CreateExampleRequest request) {
return exampleService.create(request);
}
}

View File

@@ -0,0 +1,120 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.file.FileUtil;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.common.enums.ProjectType;
import com.kri.kart.server.dto.export.AggregateExcelRequestDto;
import com.kri.kart.server.dto.export.ExportFileDto;
import com.kri.kart.server.dto.export.RawDataExportRequestDto;
import com.kri.kart.server.dto.project.ProjectRefDto;
import com.kri.kart.server.service.AggregateExcelService;
import com.kri.kart.server.service.ExportService;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.validation.Valid;
import java.nio.charset.StandardCharsets;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
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.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")
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
@ApiResponse(
responseCode = "200",
content =
@Content(
mediaType = "application/octet-stream",
schema = @Schema(type = "string", format = "binary")))
public class ExportController {
private final ExportService exportService;
private final AggregateExcelService aggregateExcelService;
@PostMapping("/project/{projectType}/{pkey}/export/excel/table")
public ResponseEntity<byte[]> reportExcel(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Valid @RequestBody AggregateExcelRequestDto request) {
return download(aggregateExcelService.report(new ProjectRefDto(projectType, pkey), request));
}
@PostMapping("/quota/{projectType}/{pkey}/export/excel")
public ResponseEntity<byte[]> quotaExcel(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Valid @RequestBody AggregateExcelRequestDto request) {
return download(aggregateExcelService.quota(new ProjectRefDto(projectType, pkey), request));
}
@GetMapping(value = "/export/form/question", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<byte[]> questionForm() {
return download(exportService.questionForm());
}
@GetMapping(
value = "/project/{projectType}/{pkey}/export/form/data",
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<byte[]> dataForm(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Parameter(hidden = true) RequestUserContext ctx) {
return download(
exportService.dataForm(new ProjectRefDto(projectType, pkey), ctx.getUserRole()));
}
@GetMapping(
value = "/project/{projectType}/{pkey}/export/form/title",
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<byte[]> titleForm(
@PathVariable ProjectType projectType, @PathVariable String pkey) {
return download(exportService.titleForm(new ProjectRefDto(projectType, pkey)));
}
@GetMapping(
value = "/project/{projectType}/{pkey}/export/guide",
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<byte[]> guide(
@PathVariable ProjectType projectType, @PathVariable String pkey) {
return download(exportService.guide(new ProjectRefDto(projectType, pkey)));
}
@PostMapping(
value = "/project/{projectType}/{pkey}/export/data",
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<byte[]> data(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Valid @RequestBody RawDataExportRequestDto request,
@Parameter(hidden = true) RequestUserContext ctx) {
return download(
exportService.data(new ProjectRefDto(projectType, pkey), ctx.getUserRole(), request));
}
private ResponseEntity<byte[]> download(ExportFileDto file) {
String fileName =
FileUtil.extractFileNameFromPath(file.getFileName())
.replaceAll("[\\p{Cntrl}\\\\/:*?\"<>|]", "_");
String disposition =
ContentDisposition.attachment()
.filename(fileName, StandardCharsets.UTF_8)
.build()
.toString();
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.header(HttpHeaders.CONTENT_DISPOSITION, disposition)
.header(HttpHeaders.CACHE_CONTROL, "no-store")
.body(file.getContent());
}
}

View File

@@ -0,0 +1,28 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.dto.share.ExternalLoginResponseDto;
import com.kri.kart.server.service.ShareLinkService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class ExternalController {
private final ShareLinkService shareLinkService;
@PostMapping("/api/v1/external/{urlKey}/login")
@Operation(summary = "공유 링크 전용 인증 발급", description = "검증된 링크의 프로젝트·페이지 범위에 제한되는 24시간 인증")
public ResponseEntity<ExternalLoginResponseDto> login(
@PathVariable String urlKey, RequestUserContext ctx) {
return ResponseEntity.ok()
.header("Cache-Control", "no-store")
.body(shareLinkService.login(urlKey, ctx.getClientIp()));
}
}

View File

@@ -0,0 +1,52 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.common.enums.ProjectType;
import com.kri.kart.server.dto.project.ProjectRefDto;
import com.kri.kart.server.dto.upload.ImportResultDto;
import com.kri.kart.server.service.ImportService;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.MediaType;
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.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/project/{projectType}/{pkey}/import")
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class ImportController {
private final ImportService importService;
@PostMapping(value = "/title", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ImportResultDto titles(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@RequestPart(value = "file", required = false) MultipartFile file,
@Parameter(hidden = true) RequestUserContext ctx) {
return importService.titles(new ProjectRefDto(projectType, pkey), file, ctx);
}
@PostMapping(value = "/question", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ImportResultDto questions(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@RequestPart(value = "file", required = false) MultipartFile file,
@Parameter(hidden = true) RequestUserContext ctx) {
return importService.questions(new ProjectRefDto(projectType, pkey), file, ctx);
}
@PostMapping(value = "/data", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ImportResultDto data(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@RequestPart(value = "file", required = false) MultipartFile file,
@Parameter(hidden = true) RequestUserContext ctx) {
return importService.data(new ProjectRefDto(projectType, pkey), file, ctx);
}
}

View File

@@ -0,0 +1,43 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.BusinessException;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.dto.log.VisitLogRequestDto;
import com.kri.kart.server.dto.share.ShareLinkDto;
import com.kri.kart.server.service.LogService;
import com.kri.kart.server.service.ShareLinkService;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.MediaType;
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/log")
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class LogController {
private final LogService logService;
@PostMapping(value = "/visit", produces = MediaType.TEXT_PLAIN_VALUE)
public String visit(
@Valid @RequestBody VisitLogRequestDto request,
@Parameter(hidden = true) RequestUserContext ctx,
HttpServletRequest servletRequest) {
ShareLinkDto link =
(ShareLinkDto) servletRequest.getAttribute(ShareLinkService.REQUEST_LINK_ATTRIBUTE);
if (link != null
&& (link.getProjectType() != request.getProjectType()
|| !link.getPkey().equals(request.getPkey()))) {
throw BusinessException.forbidden("EXTERNAL_SCOPE_DENIED", "공유 프로젝트의 방문 로그만 기록할 수 있습니다.");
}
logService.writeVisitLog(
request.getProjectType(), request.getPkey(), request.getLogContent(), ctx);
return "PASS";
}
}

View File

@@ -1,14 +0,0 @@
package com.kri.kart.server.controller;
import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class PingController {
@GetMapping("/ping")
public Map<String, String> ping() {
return Map.of("status", "ok");
}
}

View File

@@ -0,0 +1,84 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.common.enums.ProjectType;
import com.kri.kart.server.dto.project.CustomProgressDto;
import com.kri.kart.server.dto.project.LoiDto;
import com.kri.kart.server.dto.project.ProgressDayDto;
import com.kri.kart.server.dto.project.ProgressScreenDto;
import com.kri.kart.server.dto.project.ProgressSearchDto;
import com.kri.kart.server.dto.project.ProgressTypeDto;
import com.kri.kart.server.dto.project.ProjectLinkSearchDto;
import com.kri.kart.server.dto.project.ProjectListDto;
import com.kri.kart.server.dto.project.ProjectRefDto;
import com.kri.kart.server.dto.project.ProjectSummaryDto;
import com.kri.kart.server.service.CustomProgressService;
import com.kri.kart.server.service.ProgressService;
import com.kri.kart.server.service.ProjectService;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/v1/project")
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class ProjectController {
private final ProjectService projectService;
private final ProgressService progressService;
private final CustomProgressService customProgressService;
@GetMapping("/list")
public List<ProjectListDto> list(
@Valid @ParameterObject @ModelAttribute ProjectLinkSearchDto search, RequestUserContext ctx) {
return projectService.list(search, ctx);
}
@GetMapping("/summary")
public List<ProjectSummaryDto> summary(RequestUserContext ctx) {
return projectService.summary(ctx);
}
@GetMapping("/{projectType}/{pkey}/progress/day")
public List<ProgressDayDto> daily(
@PathVariable ProjectType projectType, @PathVariable String pkey) {
return progressService.daily(new ProjectRefDto(projectType, pkey));
}
@GetMapping("/{projectType}/{pkey}/progress/type")
public List<ProgressTypeDto> type(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Valid @ParameterObject @ModelAttribute ProgressSearchDto search) {
return progressService.type(new ProjectRefDto(projectType, pkey), search);
}
@GetMapping("/{projectType}/{pkey}/progress/loi")
public List<LoiDto> loi(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Valid @ParameterObject @ModelAttribute ProgressSearchDto search) {
return progressService.loi(new ProjectRefDto(projectType, pkey), search);
}
@GetMapping("/{projectType}/{pkey}/progress/screen")
public List<ProgressScreenDto> screen(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Valid @ParameterObject @ModelAttribute ProgressSearchDto search) {
return progressService.screen(new ProjectRefDto(projectType, pkey), search);
}
@GetMapping("/{projectType}/{pkey}/progress/custom")
public List<CustomProgressDto> custom(
@PathVariable ProjectType projectType, @PathVariable String pkey) {
return customProgressService.list(new ProjectRefDto(projectType, pkey));
}
}

View File

@@ -0,0 +1,40 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.common.enums.ProjectType;
import com.kri.kart.server.dto.project.ProjectRefDto;
import com.kri.kart.server.dto.question.QuestionDto;
import com.kri.kart.server.service.QuestionService;
import io.swagger.v3.oas.annotations.Parameter;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
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
@RequestMapping("/api/v1/project/{projectType}/{pkey}/question")
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class QuestionController {
private final QuestionService questionService;
@GetMapping("/list")
public List<QuestionDto> list(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Parameter(hidden = true) RequestUserContext ctx) {
return questionService.list(new ProjectRefDto(projectType, pkey), ctx.getUserRole());
}
@GetMapping("/{qid}")
public List<QuestionDto> detail(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@PathVariable String qid,
@Parameter(hidden = true) RequestUserContext ctx) {
return questionService.detail(new ProjectRefDto(projectType, pkey), qid, ctx.getUserRole());
}
}

View File

@@ -0,0 +1,45 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.common.enums.ProjectType;
import com.kri.kart.server.dto.project.ProjectRefDto;
import com.kri.kart.server.dto.quota.QuotaResultDto;
import com.kri.kart.server.dto.quota.QuotaResultRequestDto;
import com.kri.kart.server.dto.quota.QuotaSetDto;
import com.kri.kart.server.service.QuotaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
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/quota")
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class QuotaController {
private final QuotaService quotaService;
@GetMapping("/{projectType}/{pkey}/list")
public List<QuotaSetDto> list(@PathVariable ProjectType projectType, @PathVariable String pkey) {
return quotaService.list(new ProjectRefDto(projectType, pkey));
}
@PostMapping("/{projectType}/{pkey}/{quotaOrder}/result")
@Operation(summary = "저장된 쿼터 설정의 집계 결과", description = "첫 ROW·COL·FILTER로 집계하고 완료수/목표수/달성률 반환")
public QuotaResultDto result(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@PathVariable int quotaOrder,
@Valid @RequestBody QuotaResultRequestDto request,
@Parameter(hidden = true) RequestUserContext ctx) {
return quotaService.result(new ProjectRefDto(projectType, pkey), quotaOrder, request, ctx);
}
}

View File

@@ -0,0 +1,40 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.common.enums.ProjectType;
import com.kri.kart.server.dto.project.ProjectRefDto;
import com.kri.kart.server.dto.share.ShareLinkDto;
import com.kri.kart.server.dto.share.ShareLinkRequestDto;
import com.kri.kart.server.service.ShareLinkService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
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.RestController;
@RestController
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class ShareLinkController {
private final ShareLinkService shareLinkService;
@PostMapping("/api/v1/project/{projectType}/{pkey}/share")
@Operation(summary = "공유 링크 발급 또는 재사용")
public ShareLinkDto create(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Valid @RequestBody ShareLinkRequestDto request,
RequestUserContext ctx) {
return shareLinkService.create(new ProjectRefDto(projectType, pkey), request, ctx);
}
@GetMapping("/api/v1/share/{urlKey}")
@Operation(summary = "공유 링크 정보 조회", description = "내부 인증 필요. 랜딩 횟수를 증가시키지 않는다.")
public ShareLinkDto lookup(@PathVariable String urlKey) {
return shareLinkService.lookup(urlKey);
}
}

View File

@@ -0,0 +1,93 @@
package com.kri.kart.server.controller;
import com.kri.common.feature.web.BusinessException;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.kart.server.common.enums.ProjectType;
import com.kri.kart.server.dto.project.ProjectRefDto;
import com.kri.kart.server.dto.share.ShareLinkDto;
import com.kri.kart.server.dto.statistics.StatisticsBatchDto;
import com.kri.kart.server.dto.statistics.StatisticsBatchRequestDto;
import com.kri.kart.server.dto.statistics.StatisticsStreamEventDto;
import com.kri.kart.server.service.ShareLinkService;
import com.kri.kart.server.service.StatisticsService;
import com.kri.kart.server.service.statistics.StatisticsStreamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.context.RequestAttributeSecurityContextRepository;
import org.springframework.security.web.context.SecurityContextRepository;
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;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;
@RestController
@RequestMapping("/api/v1/project/{projectType}/{pkey}/statistics")
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class StatisticsController {
private static final String STANDARD_MODE = "STANDARD";
private static final String CROSSTAB_PAGE = "/Report/Crosstab";
private final StatisticsService statisticsService;
private final StatisticsStreamService statisticsStreamService;
private final SecurityContextRepository securityContextRepository =
new RequestAttributeSecurityContextRepository();
@PostMapping(value = "/result", produces = "application/x-ndjson")
@Operation(
summary = "일반 보고서 배열 집계 스트림",
description = "공유 데이터를 한 번 조회하고 indexes 순서대로 result/error, 마지막 complete 전송")
@ApiResponse(
responseCode = "200",
content =
@Content(
mediaType = "application/x-ndjson",
schema = @Schema(implementation = StatisticsStreamEventDto.class)))
public ResponseEntity<ResponseBodyEmitter> result(
@PathVariable ProjectType projectType,
@PathVariable String pkey,
@Valid @RequestBody StatisticsBatchRequestDto request,
@Parameter(hidden = true) RequestUserContext ctx,
HttpServletRequest servletRequest,
HttpServletResponse servletResponse) {
if (isCrosstabPageLink(servletRequest) && !STANDARD_MODE.equals(request.getMode())) {
throw BusinessException.forbidden(
"EXTERNAL_SCOPE_DENIED", "Cross Tab 공유 링크에서는 Cross Tab 집계만 허용됩니다.");
}
StatisticsBatchDto statisticsBatch =
statisticsService.prepare(
new ProjectRefDto(projectType, pkey),
request.requests(),
ctx);
// Common authentication is stateless; retain only this request's identity for ASYNC dispatch.
securityContextRepository.saveContext(
SecurityContextHolder.getContext(), servletRequest, servletResponse);
return ResponseEntity.ok()
.header("Cache-Control", "no-store")
.header("X-Accel-Buffering", "no")
.header("Content-Type", "application/x-ndjson;charset=UTF-8")
.body(statisticsStreamService.stream(statisticsBatch));
}
/** A page-only Cross Tab share link may request Cross Tab (STANDARD) results only. */
private boolean isCrosstabPageLink(HttpServletRequest servletRequest) {
ShareLinkDto link =
(ShareLinkDto) servletRequest.getAttribute(ShareLinkService.REQUEST_LINK_ATTRIBUTE);
return link != null
&& link.isPageOnly()
&& URI.create(link.getRealUrl()).getPath().equals(CROSSTAB_PAGE);
}
}

View File

@@ -0,0 +1,17 @@
package com.kri.kart.server.dto.auth;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Schema(description = "로그인 요청")
public class LoginRequestDto {
@NotBlank private String userId;
@NotBlank
@Schema(accessMode = Schema.AccessMode.WRITE_ONLY)
private String userPw;
}

View File

@@ -0,0 +1,13 @@
package com.kri.kart.server.dto.auth;
import com.kri.common.feature.auth.dto.JwtUserClaimsDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class LoginResponseDto {
private final String accessToken;
private final JwtUserClaimsDto user;
private final String memberRedirect;
}

View File

@@ -0,0 +1,12 @@
package com.kri.kart.server.dto.auth;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ReportMemberDto {
private String userId;
private String userName;
private String memberRedirect;
}

View File

@@ -0,0 +1,17 @@
package com.kri.kart.server.dto.bookmark;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class BookmarkDto {
private String bookmarkId;
private String bookmarkTitle;
private String bookmarkInfo;
private String bookmarkJson;
private String gkey;
private String mkey;
private Integer isOpen;
private String isMine;
}

View File

@@ -0,0 +1,34 @@
package com.kri.kart.server.dto.bookmark;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class BookmarkSaveRequestDto {
public interface Create {}
@Schema(description = "생성 시 필수. 수정 시 페이지는 변경하지 않음")
@NotNull(groups = Create.class)
@Pattern(regexp = "TABULATION|CROSSTAB")
private String bookmarkPage;
@NotNull
private String bookmarkTitle;
@NotNull
private String bookmarkInfo;
@Schema(description = "기존 북마크 설정 JSON 문자열. 저장 시 원문 유지")
@NotNull
private String bookmarkJson;
@NotNull
@Min(0)
@Max(1)
private Integer isOpen;
}

View File

@@ -0,0 +1,9 @@
package com.kri.kart.server.dto.derived;
import lombok.Value;
@Value
public class DerivedCalculationDto {
int variableCount;
int matchedRespondents;
}

View File

@@ -0,0 +1,12 @@
package com.kri.kart.server.dto.derived;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class DerivedDataDto {
private String idkey;
private String datjson;
private String derivedJson;
}

View File

@@ -0,0 +1,13 @@
package com.kri.kart.server.dto.derived;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class DerivedDefinitionDto {
private String qid;
private String questionJson;
private String derivedJson;
private Integer qOrder;
}

View File

@@ -0,0 +1,28 @@
package com.kri.kart.server.dto.derived;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class DerivedSaveRequestDto {
@NotBlank
@Size(max = 128)
@Pattern(regexp = "[A-Za-z][A-Za-z0-9_]*")
private String variableId;
@NotBlank
@Size(max = 4000)
private String variableTitle;
@NotNull
@Pattern(regexp = "single|multi|num")
private String variableType;
@NotNull private JsonNode variableInfo;
}

View File

@@ -0,0 +1,31 @@
package com.kri.kart.server.dto.derived;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class DerivedVariableDto {
private String qid;
@Getter(onMethod_ = @JsonProperty("qOrder"))
private Integer qOrder;
private String variable;
private String title;
private String explain;
private String vtype;
private String qtype;
private String isNps;
private String attrInfo;
private String rankInfo;
private String labelInfo;
private String afterLogic;
private String isDerived;
private String derivedJson;
private String gkey;
private String mkey;
}

View File

@@ -0,0 +1,20 @@
package com.kri.kart.server.dto.export;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class AggregateExcelRequestDto {
@Valid
@NotEmpty
@Size(max = 1000)
private List<@NotNull AggregateExcelTableDto> tables;
private boolean turn;
}

View File

@@ -0,0 +1,35 @@
package com.kri.kart.server.dto.export;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.LinkedHashMap;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class AggregateExcelTableDto {
@NotNull
@Size(max = 4000)
private String head;
private String vname = "";
private String qtype = "";
@NotEmpty
@Size(min = 2, max = 10000)
private List<@NotNull LinkedHashMap<@NotBlank String, @NotNull @Size(max = 32767) String>> body;
@Size(max = 7000000)
private String imagePng;
@JsonAnySetter
public void rejectUnknownField(String name, JsonNode value) {
throw new IllegalArgumentException("지원하지 않는 Excel 표 속성입니다. 워드클라우드는 imagePng를 사용해 주세요.");
}
}

View File

@@ -0,0 +1,16 @@
package com.kri.kart.server.dto.export;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ExportDataDto {
private String dat;
private String status;
private String startDate;
private String endDate;
private String intervalMin;
private String interviewerInfo;
private String interviewerCode;
}

View File

@@ -0,0 +1,12 @@
package com.kri.kart.server.dto.export;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ExportDerivedHeaderDto {
private String qid;
private String qtype;
private String linfo;
}

View File

@@ -0,0 +1,11 @@
package com.kri.kart.server.dto.export;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public class ExportFileDto {
private final String fileName;
private final byte[] content;
}

View File

@@ -0,0 +1,24 @@
package com.kri.kart.server.dto.export;
import com.kri.common.feature.excel.ExcelColumn;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class ExportGuideDto {
@ExcelColumn(header = "문항 타입", order = 0)
private String questionType;
@ExcelColumn(header = "문항 / 보기번호", order = 1)
private String variable;
@ExcelColumn(header = "내용", order = 2)
private String content;
@ExcelColumn(header = "VALUE LABEL", order = 3)
private String valueLabel;
@ExcelColumn(header = "VARIABLE LABEL", order = 4)
private String variableLabel;
}

View File

@@ -0,0 +1,12 @@
package com.kri.kart.server.dto.export;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ExportHeaderDto {
private String qid;
private String variable;
private String value;
}

View File

@@ -0,0 +1,21 @@
package com.kri.kart.server.dto.export;
import com.kri.common.feature.excel.ExcelColumn;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ExportTitleDto {
@ExcelColumn(header = "QID", order = 0)
private String qid;
@ExcelColumn(header = "문번", order = 1)
private String variable;
@ExcelColumn(header = "문항", order = 2)
private String title;
@ExcelColumn(header = "Title", order = 3)
private String explain;
}

View File

@@ -0,0 +1,24 @@
package com.kri.kart.server.dto.export;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import java.time.LocalDate;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class RawDataExportRequestDto {
@NotNull
@Pattern(regexp = "COMPLETE|INCOMPLETE")
@Schema(description = "COMPLETE: 완료(Status=10), INCOMPLETE: 미완료(Status<>10). TEST 응답 제외")
private String type = "COMPLETE";
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate;
}

View File

@@ -0,0 +1,24 @@
package com.kri.kart.server.dto.log;
import com.kri.kart.server.common.enums.ProjectType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Schema(description = "화면 방문 로그. 프로젝트 정보는 둘 다 생략하거나 함께 지정한다.")
public class VisitLogRequestDto {
private ProjectType projectType;
@Size(max = 20)
@Pattern(regexp = "^[^|]*$")
private String pkey;
@NotBlank
@Schema(description = "방문한 화면 URL 또는 페이지 정보")
private String logContent;
}

View File

@@ -0,0 +1,18 @@
package com.kri.kart.server.dto.project;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class CustomProgressDto {
private Integer appendOrder;
private Integer appendType;
private String fileName;
}

View File

@@ -0,0 +1,14 @@
package com.kri.kart.server.dto.project;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class LoiDto {
private Integer cnt;
private String avgLoi;
private String avgLoiModify;
private String minLoi;
private String maxLoi;
}

View File

@@ -0,0 +1,15 @@
package com.kri.kart.server.dto.project;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ProgressDayDto {
// Legacy SQL returns style 112 in CHAR(10): yyyyMMdd plus two trailing spaces.
private String surveyDate;
private Integer totalCount;
private Integer completeCount;
private Integer screenCount;
private Integer quotaCount;
}

View File

@@ -0,0 +1,16 @@
package com.kri.kart.server.dto.project;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ProgressScreenDto {
@Getter(onMethod_ = @JsonProperty("qOrder"))
private Integer qOrder;
private String viewTitle;
private String pageName;
private Long cnt;
}

View File

@@ -0,0 +1,24 @@
package com.kri.kart.server.dto.project;
import com.kri.common.feature.web.BusinessException;
import java.time.LocalDate;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
@Getter
@Setter
public class ProgressSearchDto {
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate startDate;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate endDate;
public void validateRange() {
if ((startDate == null) != (endDate == null)
|| (startDate != null && startDate.isAfter(endDate))) {
throw BusinessException.badRequest("시작일과 종료일을 함께 입력하고 시작일을 종료일 이전으로 지정해 주세요.");
}
}
}

View File

@@ -0,0 +1,14 @@
package com.kri.kart.server.dto.project;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ProgressTypeDto {
private Integer totalCount;
private Integer completeCount;
private Integer screenCount;
private Integer quotaCount;
private Integer goingCount;
}

View File

@@ -0,0 +1,23 @@
package com.kri.kart.server.dto.project;
import com.kri.kart.server.common.enums.ProjectType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ProjectLinkSearchDto {
private ProjectType projectType;
@Size(max = 128)
@Schema(description = "서비스 연동 조회용 인트라넷 프로젝트 코드. 첫 _ 앞 부분으로 검색")
private String intranetCode;
@Size(max = 32)
private String userTeam;
@Size(max = 512)
private String keyword;
}

View File

@@ -0,0 +1,20 @@
package com.kri.kart.server.dto.project;
import com.kri.kart.server.common.enums.ProjectType;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ProjectListDto {
private ProjectType projectType;
private String rowNumber;
private String pkey;
private String title;
private String surveyType;
private String status;
private String gkey;
private String mkey;
private LocalDateTime createDate;
}

View File

@@ -0,0 +1,28 @@
package com.kri.kart.server.dto.project;
import com.kri.kart.server.common.enums.ProjectType;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Objects;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@Getter
@EqualsAndHashCode
@Schema(description = "프로젝트 유형과 프로젝트 키")
public final class ProjectRefDto {
@Schema(description = "프로젝트 유형: 0=KON, 1=KIWI")
private final ProjectType projectType;
@Schema(description = "프로젝트 키", maxLength = 20)
private final String pkey;
public ProjectRefDto(ProjectType projectType, String pkey) {
Objects.requireNonNull(projectType, "Project type is required");
if (pkey == null || pkey.isBlank() || pkey.length() > 20 || pkey.contains("|")) {
throw new IllegalArgumentException(
"Project key must be nonblank, at most 20 UTF-16 units, without legacy markers");
}
this.projectType = projectType;
this.pkey = pkey;
}
}

View File

@@ -0,0 +1,22 @@
package com.kri.kart.server.dto.project;
import com.kri.kart.server.common.enums.ProjectType;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ProjectSummaryDto {
private ProjectType projectType;
private String pkey;
private String title;
private String surveyType;
private String status;
private LocalDateTime createDate;
private Long allCount;
private Long ongoingCount;
private Long screenCount;
private Long quotaCount;
private Long completeCount;
}

View File

@@ -0,0 +1,37 @@
package com.kri.kart.server.dto.question;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class QuestionDto {
private String qid;
@Getter(onMethod_ = @JsonProperty("qOrder"))
private Integer qOrder;
private String variable;
private String title;
private String explain;
private String vtype;
private String qtype;
private String isNps;
private String isReverse;
private String missingValue;
private String attrInfo;
private String rankInfo;
private String labelInfo;
private String afterLogic;
private String isDerived;
private String derivedJson;
private String gkey;
private String mkey;
}

View File

@@ -0,0 +1,20 @@
package com.kri.kart.server.dto.quota;
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder
public class QuotaCellDto {
private int columnIndex;
private String kind;
private String textValue;
private Long complete;
private Long target;
private Double achievementPercent;
private String achievementState;
private String achievementDisplayText;
private String displayText;
private String isUsed;
private Long quotaId;
}

View File

@@ -0,0 +1,14 @@
package com.kri.kart.server.dto.quota;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class QuotaEntryDto {
private Long id;
private Long cnt;
private Long oriCnt;
private String quotaJson;
private String isUse;
}

View File

@@ -0,0 +1,20 @@
package com.kri.kart.server.dto.quota;
import com.kri.kart.server.dto.statistics.StatisticsColumnDto;
import com.kri.kart.server.dto.statistics.StatisticsRowDto;
import java.util.List;
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder
public class QuotaResultDto {
private Long quotaSetId;
private Integer quotaOrder;
private String title;
private String index;
private List<List<String>> banners;
private List<StatisticsColumnDto> columns;
private List<StatisticsRowDto> headerRows;
private List<QuotaRowDto> rows;
}

View File

@@ -0,0 +1,22 @@
package com.kri.kart.server.dto.quota;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import java.time.LocalDate;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class QuotaResultRequestDto {
@NotNull
@Pattern(regexp = "ACTUAL|TEST|ALL")
private String dataScope = "ACTUAL";
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate;
}

View File

@@ -0,0 +1,14 @@
package com.kri.kart.server.dto.quota;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class QuotaRowDto {
private int rowIndex;
private String rowId;
private String kind;
private List<QuotaCellDto> cells;
}

View File

@@ -0,0 +1,14 @@
package com.kri.kart.server.dto.quota;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class QuotaSetDto {
private Long id;
private Integer qsOrder;
private String qsTitle;
// Preserve saved configuration verbatim; quota result interprets it without modifying the DB.
private String qsJson;
}

View File

@@ -1,12 +0,0 @@
package com.kri.kart.server.dto.request;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
public record CreateExampleRequest(
@NotNull @Positive Long groupId,
@NotNull @Positive Integer sequence,
@NotBlank String name
) {
}

View File

@@ -1,19 +0,0 @@
package com.kri.kart.server.dto.response;
import com.kri.kart.server.persistence.entity.ExampleEntity;
public record ExampleResponse(
Long groupId,
Integer sequence,
String name,
String status
) {
public static ExampleResponse from(ExampleEntity entity) {
return new ExampleResponse(
entity.getId().getGroupId(),
entity.getId().getSequence(),
entity.getName(),
entity.getStatus().name()
);
}
}

View File

@@ -0,0 +1,9 @@
package com.kri.kart.server.dto.share;
import lombok.Value;
@Value
public class ExternalLoginResponseDto {
String accessToken;
ShareLinkDto link;
}

View File

@@ -0,0 +1,15 @@
package com.kri.kart.server.dto.share;
import com.kri.kart.server.common.enums.ProjectType;
import lombok.Value;
@Value
public class ShareLinkDto {
String urlKey;
String url;
String realUrl;
ProjectType projectType;
String pkey;
String projectTitle;
boolean pageOnly;
}

View File

@@ -0,0 +1,19 @@
package com.kri.kart.server.dto.share;
import lombok.Getter;
import lombok.Setter;
/** REPORT_URL 내부 저장 DTO. SKEY는 API 응답에 포함하지 않는다. */
@Getter
@Setter
public class ShareLinkRecordDto {
private Long id;
private String urlKey;
private String realUrl;
private Integer isPageOnly;
private String skey;
private String pkey;
private Integer projectType;
private String projectTitle;
private String urlOwner;
}

View File

@@ -0,0 +1,19 @@
package com.kri.kart.server.dto.share;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ShareLinkRequestDto {
@NotBlank
@Size(max = 4096)
private String realUrl;
@NotBlank
@Pattern(regexp = "P|U")
private String mode;
}

View File

@@ -0,0 +1,12 @@
package com.kri.kart.server.dto.statistics;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class NlpDictionaryWordDto {
private String wordText;
private String wordTag;
private Integer wordScore;
}

View File

@@ -0,0 +1,3 @@
package com.kri.kart.server.dto.statistics;
public record NlpTokenDto(String text, String tag) {}

View File

@@ -0,0 +1,12 @@
package com.kri.kart.server.dto.statistics;
import com.kri.kart.server.dto.project.ProjectRefDto;
import com.kri.kart.server.dto.question.QuestionDto;
import java.util.List;
/** Questions and filtered responses loaded once and shared by every index in one request. */
public record StatisticsBatchDto(
ProjectRefDto project,
List<StatisticsRequestDto> requests,
List<QuestionDto> questions,
List<SurveyResponseDto> responses) {}

View File

@@ -0,0 +1,29 @@
package com.kri.kart.server.dto.statistics;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;
@Getter
@Setter
public class StatisticsBatchRequestDto extends StatisticsOptionsDto {
@NotEmpty
@Schema(description = "요청 순서대로 집계할 QID 배열. TABULATION 모드는 [\"\"] 사용")
private List<@NotNull String> indexes;
public List<StatisticsRequestDto> requests() {
return indexes.stream()
.map(
index -> {
StatisticsRequestDto request = new StatisticsRequestDto();
BeanUtils.copyProperties(this, request);
request.setIndex(index);
return request;
})
.toList();
}
}

View File

@@ -0,0 +1,26 @@
package com.kri.kart.server.dto.statistics;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder(toBuilder = true)
public class StatisticsCellDto {
private int columnIndex;
@Builder.Default private int rowSpan = 1;
@Builder.Default private int colSpan = 1;
private String kind;
private String textValue;
private Long count;
private Double percent;
@Schema(description = "해당 셀의 백분율 분모")
private Long base;
private Double statisticValue;
private String measurement;
private String countDisplayText;
private String percentDisplayText;
private String statisticDisplayText;
}

View File

@@ -0,0 +1,13 @@
package com.kri.kart.server.dto.statistics;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class StatisticsColumnDto {
private final String columnId;
private final String kind;
private final List<String> labels;
}

View File

@@ -0,0 +1,12 @@
package com.kri.kart.server.dto.statistics;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class StatisticsDataDto {
private String idkey;
private String dat;
private String filterDat;
}

View File

@@ -0,0 +1,19 @@
package com.kri.kart.server.dto.statistics;
import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Schema(description = "AND/OR/NOT는 children, 조건은 dimensionId와 values 사용. 숫자 JSON 값은 수치 비교")
public class StatisticsFilterDto {
private String operator;
private String dimensionId;
private String reference = "QID";
private List<JsonNode> values = new ArrayList<>();
private List<StatisticsFilterDto> children = new ArrayList<>();
}

View File

@@ -0,0 +1,58 @@
package com.kri.kart.server.dto.statistics;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class StatisticsOptionsDto {
@NotNull
@Schema(description = "가로 배너 묶음과 묶음별 중첩 문항. 한 묶음 최대 5단계")
private List<@NotNull @Size(min = 1, max = 5) List<@NotNull String>> banners = new ArrayList<>();
@Valid private StatisticsFilterDto filter;
@NotNull
@Pattern(regexp = "STANDARD|TABULATION_0|TABULATION_1")
private String mode = "STANDARD";
@NotNull
@Pattern(regexp = "ACTUAL|TEST|ALL")
private String dataScope = "ACTUAL";
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate;
@Min(0)
@Max(14)
private int percentageDecimals = 14;
@Min(0)
@Max(14)
private int statisticDecimals = 14;
@NotNull
@Pattern(regexp = "NONE|FLAT|MERGED")
private String headerMode = "MERGED";
private boolean transpose;
private boolean showSubtotals = true;
private boolean showValueCodes;
private boolean showNumericSum;
@Valid @NotNull private List<StatisticsValueGroupDto> valueGroups = new ArrayList<>();
}

View File

@@ -0,0 +1,14 @@
package com.kri.kart.server.dto.statistics;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class StatisticsRequestDto extends StatisticsOptionsDto {
@NotNull
@Schema(description = "집계 문항 QID. 속성 투영은 #A. TABULATION 모드만 빈 값 허용", example = "Q1")
private String index;
}

View File

@@ -0,0 +1,18 @@
package com.kri.kart.server.dto.statistics;
import java.util.List;
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder
public class StatisticsResponseDto {
private String type;
private String questionId;
private String title;
private List<StatisticsColumnDto> columns;
private List<StatisticsRowDto> headerRows;
private List<StatisticsRowDto> rows;
private List<StatisticsWordDto> words;
private StatisticsRequestDto appliedOptions;
}

View File

@@ -0,0 +1,14 @@
package com.kri.kart.server.dto.statistics;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class StatisticsRowDto {
private final int rowIndex;
private final String rowId;
private final String kind;
private final List<StatisticsCellDto> cells;
}

View File

@@ -0,0 +1,23 @@
package com.kri.kart.server.dto.statistics;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "NDJSON 한 줄 이벤트. result/error는 문항별, complete는 스트림 완료")
public class StatisticsStreamEventDto {
private String type;
private Integer position;
private String index;
private StatisticsResponseDto result;
private Integer status;
private String code;
private String message;
private Integer total;
private Integer succeeded;
private Integer failed;
}

View File

@@ -0,0 +1,15 @@
package com.kri.kart.server.dto.statistics;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class StatisticsValueGroupDto {
@NotBlank private String label;
@NotEmpty private List<@NotBlank String> values;
}

View File

@@ -0,0 +1,12 @@
package com.kri.kart.server.dto.statistics;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class StatisticsWordDto {
private final String text;
private final String tag;
private final long count;
}

View File

@@ -0,0 +1,11 @@
package com.kri.kart.server.dto.statistics;
import java.util.Map;
/** Internal flattened survey response. Never returned by report APIs. */
public record SurveyResponseDto(
String idkey, Map<String, String> values, Map<String, String> filterValues) {
public SurveyResponseDto(String idkey, Map<String, String> values) {
this(idkey, values, values);
}
}

View File

@@ -0,0 +1,12 @@
package com.kri.kart.server.dto.upload;
import lombok.Value;
@Value
public class ImportQuestionDto {
String qid;
int qOrder;
String questionJson;
String qinfo;
String linfo;
}

View File

@@ -0,0 +1,12 @@
package com.kri.kart.server.dto.upload;
import lombok.Value;
@Value
public class ImportResponseDto {
String idkey;
String status;
String pageName;
String datjson;
String surveyDate;
}

View File

@@ -0,0 +1,11 @@
package com.kri.kart.server.dto.upload;
import lombok.Value;
@Value
public class ImportResultDto {
int processedRows;
int affectedRows;
int removedRows;
int archivedRows;
}

View File

@@ -0,0 +1,10 @@
package com.kri.kart.server.dto.upload;
import java.util.List;
import lombok.Value;
@Value
public class UploadTableDto {
List<String> headers;
List<List<String>> rows;
}

View File

@@ -0,0 +1,29 @@
package com.kri.kart.server.persistence;
import com.kri.kart.server.common.enums.ProjectType;
import java.util.Objects;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
@Component
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
public class SurveySessionProvider {
private final SqlSessionTemplate konSqlSessionTemplate;
private final SqlSessionTemplate konkiwiSqlSessionTemplate;
public SurveySessionProvider(
@Qualifier("konSqlSessionTemplate") SqlSessionTemplate konSqlSessionTemplate,
@Qualifier("konkiwiSqlSessionTemplate") SqlSessionTemplate konkiwiSqlSessionTemplate) {
this.konSqlSessionTemplate = konSqlSessionTemplate;
this.konkiwiSqlSessionTemplate = konkiwiSqlSessionTemplate;
}
public SqlSessionTemplate forProject(ProjectType type) {
return switch (Objects.requireNonNull(type, "Project type is required")) {
case KON -> konSqlSessionTemplate;
case KIWI -> konkiwiSqlSessionTemplate;
};
}
}

View File

@@ -1,42 +0,0 @@
package com.kri.kart.server.persistence.entity;
import com.kri.kart.server.common.enums.ExampleStatus;
import com.kri.kart.server.persistence.entity.id.ExampleEntityId;
import jakarta.persistence.Column;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@Entity
@Table(name = "t_example")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ExampleEntity {
@EmbeddedId
private ExampleEntityId id;
@Column(name = "name", nullable = false, length = 100)
private String name;
@Enumerated(EnumType.STRING)
@Column(name = "status", nullable = false, length = 20)
private ExampleStatus status;
@Builder
public ExampleEntity(ExampleEntityId id, String name, ExampleStatus status) {
this.id = id;
this.name = name;
this.status = status == null ? ExampleStatus.ACTIVE : status;
}
public void changeName(String name) {
this.name = name;
}
}

View File

@@ -1,28 +0,0 @@
package com.kri.kart.server.persistence.entity.id;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import java.io.Serial;
import java.io.Serializable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@Embeddable
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ExampleEntityId implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Column(name = "group_id", nullable = false)
private Long groupId;
@Column(name = "sequence", nullable = false)
private Integer sequence;
}

View File

@@ -1,9 +0,0 @@
package com.kri.kart.server.persistence.jdbc;
public record ExampleBulkItem(
Long groupId,
Integer sequence,
String name,
String status
) {
}

View File

@@ -1,47 +0,0 @@
package com.kri.kart.server.persistence.jdbc;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
@Repository
@RequiredArgsConstructor
public class ExampleBulkJdbcRepository {
private final JdbcTemplate jdbcTemplate;
public void insertAll(List<ExampleBulkItem> items, int batchSize) {
if (items == null || items.isEmpty()) return;
String sql = """
insert into t_example (group_id, sequence, name, status)
values (?, ?, ?, ?)
""";
int safeBatchSize = Math.max(batchSize, 1);
for (int from = 0; from < items.size(); from += safeBatchSize) {
int to = Math.min(from + safeBatchSize, items.size());
List<ExampleBulkItem> batch = items.subList(from, to);
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement statement, int index) throws SQLException {
ExampleBulkItem item = batch.get(index);
statement.setLong(1, item.groupId());
statement.setInt(2, item.sequence());
statement.setString(3, item.name());
statement.setString(4, item.status());
}
@Override
public int getBatchSize() {
return batch.size();
}
});
}
}
}

View File

@@ -1,11 +0,0 @@
package com.kri.kart.server.persistence.mapper;
import com.kri.kart.server.dto.response.ExampleResponse;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface ExampleMapper {
List<ExampleResponse> findByName(@Param("keyword") String keyword);
}

Some files were not shown because too many files have changed in this diff Show More