261023_01_ENH: 파생변수 동일 ID 수정 시 중복 검사 제외 및 데이터 Import 파생변수 열 제외·업로드 후 재계산
This commit is contained in:
@@ -68,7 +68,9 @@ public class DerivedManagementService {
|
||||
if (original != null) {
|
||||
requireTeam(original, ctx);
|
||||
}
|
||||
if (derivedRepository.duplicate(project, definition.getQid(), originId)) {
|
||||
// An update that keeps its ID cannot collide; raw DATA keys with that ID are ignored.
|
||||
boolean sameId = originId != null && originId.equalsIgnoreCase(definition.getQid());
|
||||
if (!sameId && derivedRepository.duplicate(project, definition.getQid(), originId)) {
|
||||
throw BusinessException.conflict("DERIVED_ID_DUPLICATE", "이미 사용 중인 변수 ID입니다.");
|
||||
}
|
||||
if (derivedRepository.save(
|
||||
@@ -79,7 +81,7 @@ public class DerivedManagementService {
|
||||
if (original != null && !original.getQid().equals(definition.getQid())) {
|
||||
derivedRepository.clearData(project, original.getQid());
|
||||
}
|
||||
calculate(project, definition);
|
||||
calculate(project, definition, null, derivedIds(derivedRepository.definitions(project)));
|
||||
var content = objectMapper.createObjectNode();
|
||||
content.set("NEW", objectMapper.valueToTree(definition));
|
||||
if (original != null) {
|
||||
@@ -129,9 +131,11 @@ public class DerivedManagementService {
|
||||
qid == null
|
||||
? derivedRepository.definitions(project)
|
||||
: List.of(requireDefinition(project, qid));
|
||||
var derivedIds =
|
||||
derivedIds(qid == null ? definitions : derivedRepository.definitions(project));
|
||||
int matched = 0;
|
||||
for (var definition : definitions) {
|
||||
matched += calculate(project, definition);
|
||||
matched += calculate(project, definition, null, derivedIds);
|
||||
}
|
||||
if (qid == null) {
|
||||
logService.writeSiteLog(
|
||||
@@ -156,19 +160,47 @@ public class DerivedManagementService {
|
||||
// response.
|
||||
derivedRepository.ensureRespondent(project, idkey);
|
||||
var definitions = derivedRepository.definitions(project);
|
||||
var derivedIds = derivedIds(definitions);
|
||||
int matched = 0;
|
||||
for (var definition : definitions) {
|
||||
matched += calculate(project, definition, idkey);
|
||||
matched += calculate(project, definition, idkey, derivedIds);
|
||||
}
|
||||
return new DerivedCalculationDto(definitions.size(), matched);
|
||||
});
|
||||
}
|
||||
|
||||
private int calculate(ProjectRefDto project, DerivedDefinitionDto definition) {
|
||||
return calculate(project, definition, null);
|
||||
/** Stored derived variable IDs; uploaded response columns with these IDs are not imported. */
|
||||
public List<String> derivedIds(ProjectRefDto project) {
|
||||
return derivedIds(derivedRepository.definitions(project));
|
||||
}
|
||||
|
||||
private int calculate(ProjectRefDto project, DerivedDefinitionDto definition, String idkey) {
|
||||
/**
|
||||
* Recalculates every definition after a data upload. It joins the caller's KON/KONKIWI
|
||||
* transaction, so a failure rolls back the upload; no role check or extra audit log applies.
|
||||
*/
|
||||
public DerivedCalculationDto recalculateAfterImport(ProjectRefDto project) {
|
||||
return transaction(
|
||||
project,
|
||||
() -> {
|
||||
var definitions = derivedRepository.definitions(project);
|
||||
var derivedIds = derivedIds(definitions);
|
||||
int matched = 0;
|
||||
for (var definition : definitions) {
|
||||
matched += calculate(project, definition, null, derivedIds);
|
||||
}
|
||||
return new DerivedCalculationDto(definitions.size(), matched);
|
||||
});
|
||||
}
|
||||
|
||||
private List<String> derivedIds(List<DerivedDefinitionDto> definitions) {
|
||||
return definitions.stream().map(DerivedDefinitionDto::getQid).toList();
|
||||
}
|
||||
|
||||
private int calculate(
|
||||
ProjectRefDto project,
|
||||
DerivedDefinitionDto definition,
|
||||
String idkey,
|
||||
List<String> derivedIds) {
|
||||
validateId(definition.getQid());
|
||||
if (idkey == null) {
|
||||
derivedRepository.clearData(project, definition.getQid());
|
||||
@@ -181,7 +213,7 @@ public class DerivedManagementService {
|
||||
: derivedRepository.respondentResponses(project, idkey);
|
||||
var results =
|
||||
derivedComputationService.calculate(
|
||||
definition, questionService.list(project, idkey == null ? 0 : 1001), data);
|
||||
definition, questionService.list(project, idkey == null ? 0 : 1001), data, derivedIds);
|
||||
int matched = 0;
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
var group = results.get(i);
|
||||
|
||||
Reference in New Issue
Block a user