261022_01_ENH: 문항등록 오류 수정
This commit is contained in:
@@ -20,6 +20,8 @@ import com.kri.kart.server.persistence.repository.ExportRepository;
|
||||
import com.kri.kart.server.persistence.repository.QuestionRepository;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -28,18 +30,16 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.util.HtmlUtils;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
|
||||
public class ExportService {
|
||||
private static final DateTimeFormatter FILE_TIMESTAMP =
|
||||
@@ -49,10 +49,24 @@ public class ExportService {
|
||||
private final ExportRepository exportRepository;
|
||||
private final QuestionRepository questionRepository;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final Path formDirectory;
|
||||
|
||||
public ExportService(
|
||||
ExportRepository exportRepository,
|
||||
QuestionRepository questionRepository,
|
||||
ObjectMapper objectMapper,
|
||||
@Value("${kri.kart.export.form-directory:./file_forms}") String formDirectory) {
|
||||
this.exportRepository = exportRepository;
|
||||
this.questionRepository = questionRepository;
|
||||
this.objectMapper = objectMapper;
|
||||
this.formDirectory = Path.of(formDirectory).toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
public ExportFileDto questionForm() {
|
||||
try (var input = new ClassPathResource("file_forms/" + KartConstant.QUESTION_FORM_FILE_NAME).getInputStream()) {
|
||||
return new ExportFileDto(KartConstant.QUESTION_FORM_FILE_NAME, input.readAllBytes());
|
||||
try {
|
||||
return new ExportFileDto(
|
||||
KartConstant.QUESTION_FORM_FILE_NAME,
|
||||
Files.readAllBytes(formDirectory.resolve(KartConstant.QUESTION_FORM_FILE_NAME)));
|
||||
} catch (IOException exception) {
|
||||
throw new IllegalStateException("문항 등록 양식을 읽을 수 없습니다.", exception);
|
||||
}
|
||||
|
||||
@@ -55,15 +55,19 @@ public class QuestionImportService {
|
||||
continue;
|
||||
}
|
||||
String title = labelRow.get(5);
|
||||
boolean etc = title.toLowerCase(Locale.ROOT).contains("{t}");
|
||||
String cleaned = title.replace("{t}", "").replace("{T}", "");
|
||||
String lowerTitle = title.toLowerCase(Locale.ROOT);
|
||||
boolean etc = lowerTitle.contains("{t}");
|
||||
boolean none = lowerTitle.contains("{n}");
|
||||
boolean except = lowerTitle.contains("{e}");
|
||||
String cleaned = title.replaceAll("(?i)\\{[tne]\\}", "");
|
||||
if (!labelRow.get(3).isEmpty()) {
|
||||
attrs.set(
|
||||
Integer.toString(attrs.size() + 1),
|
||||
objectMapper
|
||||
.createObjectNode()
|
||||
.put("etc", etc ? "1" : "0")
|
||||
.put("except", "0")
|
||||
.put("none", none ? "1" : "0")
|
||||
.put("except", except ? "1" : "0")
|
||||
.put("label", cleaned)
|
||||
.put("value", labelRow.get(3)));
|
||||
} else if (!title.isEmpty()) {
|
||||
@@ -71,9 +75,12 @@ public class QuestionImportService {
|
||||
if (itemType.equals("open")) {
|
||||
label.put("option", type.equals("n") ? "num" : "all").put("must", "1");
|
||||
} else {
|
||||
label.put("value", labelRow.get(4));
|
||||
label
|
||||
.put("value", labelRow.get(4))
|
||||
.put("none", none ? "1" : "0")
|
||||
.put("except", except ? "1" : "0");
|
||||
if (!itemType.equals("scale")) {
|
||||
label.put("etc", etc ? "1" : "0").put("except", "0");
|
||||
label.put("etc", etc ? "1" : "0");
|
||||
}
|
||||
}
|
||||
labels.set(Integer.toString(labels.size() + 1), label);
|
||||
@@ -131,7 +138,7 @@ public class QuestionImportService {
|
||||
if (option.isEmpty()) {
|
||||
question.put("option", "");
|
||||
} else {
|
||||
question.set("option", objectMapper.createObjectNode().set("option", option));
|
||||
question.set("option", option);
|
||||
}
|
||||
String qid = "Q" + (result.size() + 1);
|
||||
var structure = structure(qid, type.equals("r") ? "rank" : itemType, labels, attrs, rankCount);
|
||||
@@ -206,14 +213,9 @@ public class QuestionImportService {
|
||||
for (var label : labels) {
|
||||
if (label.path("etc").asText().equals("1")) {
|
||||
String value = label.get("value").asText();
|
||||
// Original lookup uses the value as the ordinal key; do not silently reinterpret it.
|
||||
var etcLabel = labels.get(value);
|
||||
if (etcLabel == null) {
|
||||
throw BusinessException.badRequest("단일 문항 기타 보기의 값과 순서를 확인해 주세요.");
|
||||
}
|
||||
String key = "T" + qid + "_" + value + suffix;
|
||||
keys.add(key);
|
||||
info.put(key, etcLabel.get("label").asText() + "(기타)");
|
||||
info.put(key, label.get("label").asText() + "(기타)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user