261022_01_ENH: 문항등록 오류 수정
This commit is contained in:
@@ -99,7 +99,7 @@
|
|||||||
## Upload forms and variable guide downloads
|
## Upload forms and variable guide downloads
|
||||||
|
|
||||||
- Implement only GET /export/form/question and GET /project/{projectType}/{pkey}/export/form/data, /export/form/title and /export/guide in this phase. Keep existing octet-stream and file/sheet names.
|
- Implement only GET /export/form/question and GET /project/{projectType}/{pkey}/export/form/data, /export/form/title and /export/guide in this phase. Keep existing octet-stream and file/sheet names.
|
||||||
- Bundle the existing KON question-upload workbook unchanged. Its SHA-256 is DC557EC7E3296AA629589FE3BAAC9C4BFF1750205078D8E9CEFD5D71C477E584. Never regenerate it from metadata.
|
- Keep the KON question-upload workbook as an external file under kri.kart.export.form-directory (default ./file_forms, beside ./upload_data relative to the process working directory). Read it on every download so file replacement needs no restart. Deploy file_forms separately from the JAR, preserve the supplied workbook bytes, and do not regenerate it from metadata or fall back to a bundled copy.
|
||||||
- Header order is the fixed seven columns, add_column, userRole=1001 derived dataset headers, then STRUCTURE QINFO/question headers. Preserve legacy splitting, qid-to-variable replacement and duplicate-key position. Existing missing-project behavior returns the fixed header; actual persistence errors use common error handling.
|
- Header order is the fixed seven columns, add_column, userRole=1001 derived dataset headers, then STRUCTURE QINFO/question headers. Preserve legacy splitting, qid-to-variable replacement and duplicate-key position. Existing missing-project behavior returns the fixed header; actual persistence errors use common error handling.
|
||||||
- Title form uses four original columns and Qorder, excludes description/MM_FILE and does not substitute empty explanation with title.
|
- Title form uses four original columns and Qorder, excludes description/MM_FILE and does not substitute empty explanation with title.
|
||||||
- Guide uses raw QuestionRepository metadata with includeProfiles=false, not organized/expanded question rows. Preserve original attribute values, multi/open/rank ranges and labels, HTML decoding/tag removal, CR/LF conversion and negative zero-padded labels.
|
- Guide uses raw QuestionRepository metadata with includeProfiles=false, not organized/expanded question rows. Preserve original attribute values, multi/open/rank ranges and labels, HTML decoding/tag removal, CR/LF conversion and negative zero-padded labels.
|
||||||
|
|||||||
BIN
file_forms/KON 문항 등록 양식.xlsx
Normal file
BIN
file_forms/KON 문항 등록 양식.xlsx
Normal file
Binary file not shown.
@@ -20,6 +20,8 @@ import com.kri.kart.server.persistence.repository.ExportRepository;
|
|||||||
import com.kri.kart.server.persistence.repository.QuestionRepository;
|
import com.kri.kart.server.persistence.repository.QuestionRepository;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@@ -28,18 +30,16 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.CellType;
|
import org.apache.poi.ss.usermodel.CellType;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
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.stereotype.Service;
|
||||||
import org.springframework.web.util.HtmlUtils;
|
import org.springframework.web.util.HtmlUtils;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
|
||||||
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
|
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
|
||||||
public class ExportService {
|
public class ExportService {
|
||||||
private static final DateTimeFormatter FILE_TIMESTAMP =
|
private static final DateTimeFormatter FILE_TIMESTAMP =
|
||||||
@@ -49,10 +49,24 @@ public class ExportService {
|
|||||||
private final ExportRepository exportRepository;
|
private final ExportRepository exportRepository;
|
||||||
private final QuestionRepository questionRepository;
|
private final QuestionRepository questionRepository;
|
||||||
private final ObjectMapper objectMapper;
|
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() {
|
public ExportFileDto questionForm() {
|
||||||
try (var input = new ClassPathResource("file_forms/" + KartConstant.QUESTION_FORM_FILE_NAME).getInputStream()) {
|
try {
|
||||||
return new ExportFileDto(KartConstant.QUESTION_FORM_FILE_NAME, input.readAllBytes());
|
return new ExportFileDto(
|
||||||
|
KartConstant.QUESTION_FORM_FILE_NAME,
|
||||||
|
Files.readAllBytes(formDirectory.resolve(KartConstant.QUESTION_FORM_FILE_NAME)));
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
throw new IllegalStateException("문항 등록 양식을 읽을 수 없습니다.", exception);
|
throw new IllegalStateException("문항 등록 양식을 읽을 수 없습니다.", exception);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,15 +55,19 @@ public class QuestionImportService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String title = labelRow.get(5);
|
String title = labelRow.get(5);
|
||||||
boolean etc = title.toLowerCase(Locale.ROOT).contains("{t}");
|
String lowerTitle = title.toLowerCase(Locale.ROOT);
|
||||||
String cleaned = title.replace("{t}", "").replace("{T}", "");
|
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()) {
|
if (!labelRow.get(3).isEmpty()) {
|
||||||
attrs.set(
|
attrs.set(
|
||||||
Integer.toString(attrs.size() + 1),
|
Integer.toString(attrs.size() + 1),
|
||||||
objectMapper
|
objectMapper
|
||||||
.createObjectNode()
|
.createObjectNode()
|
||||||
.put("etc", etc ? "1" : "0")
|
.put("etc", etc ? "1" : "0")
|
||||||
.put("except", "0")
|
.put("none", none ? "1" : "0")
|
||||||
|
.put("except", except ? "1" : "0")
|
||||||
.put("label", cleaned)
|
.put("label", cleaned)
|
||||||
.put("value", labelRow.get(3)));
|
.put("value", labelRow.get(3)));
|
||||||
} else if (!title.isEmpty()) {
|
} else if (!title.isEmpty()) {
|
||||||
@@ -71,9 +75,12 @@ public class QuestionImportService {
|
|||||||
if (itemType.equals("open")) {
|
if (itemType.equals("open")) {
|
||||||
label.put("option", type.equals("n") ? "num" : "all").put("must", "1");
|
label.put("option", type.equals("n") ? "num" : "all").put("must", "1");
|
||||||
} else {
|
} 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")) {
|
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);
|
labels.set(Integer.toString(labels.size() + 1), label);
|
||||||
@@ -131,7 +138,7 @@ public class QuestionImportService {
|
|||||||
if (option.isEmpty()) {
|
if (option.isEmpty()) {
|
||||||
question.put("option", "");
|
question.put("option", "");
|
||||||
} else {
|
} else {
|
||||||
question.set("option", objectMapper.createObjectNode().set("option", option));
|
question.set("option", option);
|
||||||
}
|
}
|
||||||
String qid = "Q" + (result.size() + 1);
|
String qid = "Q" + (result.size() + 1);
|
||||||
var structure = structure(qid, type.equals("r") ? "rank" : itemType, labels, attrs, rankCount);
|
var structure = structure(qid, type.equals("r") ? "rank" : itemType, labels, attrs, rankCount);
|
||||||
@@ -206,14 +213,9 @@ public class QuestionImportService {
|
|||||||
for (var label : labels) {
|
for (var label : labels) {
|
||||||
if (label.path("etc").asText().equals("1")) {
|
if (label.path("etc").asText().equals("1")) {
|
||||||
String value = label.get("value").asText();
|
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;
|
String key = "T" + qid + "_" + value + suffix;
|
||||||
keys.add(key);
|
keys.add(key);
|
||||||
info.put(key, etcLabel.get("label").asText() + "(기타)");
|
info.put(key, label.get("label").asText() + "(기타)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ kri:
|
|||||||
model-directory: ./nlp_model/v0.24.0
|
model-directory: ./nlp_model/v0.24.0
|
||||||
upload:
|
upload:
|
||||||
directory: ./upload_data
|
directory: ./upload_data
|
||||||
|
export:
|
||||||
|
form-directory: ./file_forms
|
||||||
progress:
|
progress:
|
||||||
append-directory: ../report_append
|
append-directory: ../report_append
|
||||||
database:
|
database:
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user