전략알림 수정

This commit is contained in:
Macbook
2026-05-27 16:51:57 +09:00
parent d7ceb8cbfd
commit aca895e9fd
13 changed files with 701 additions and 123 deletions
@@ -22,6 +22,7 @@ public class StrategyService {
private final ObjectMapper objectMapper;
private final StrategyConditionTimeframeService conditionTimeframes;
private final LiveStrategyEvaluator liveStrategyEvaluator;
private final StrategyDslTimeframeNormalizer dslTimeframeNormalizer;
// ── 조회 ──────────────────────────────────────────────────────────────────
@@ -56,9 +57,13 @@ public class StrategyService {
try {
entity.setBuyConditionJson(
dto.getBuyCondition() != null ? objectMapper.writeValueAsString(dto.getBuyCondition()) : null);
dto.getBuyCondition() != null
? dslTimeframeNormalizer.normalizeJson(objectMapper.writeValueAsString(dto.getBuyCondition()))
: null);
entity.setSellConditionJson(
dto.getSellCondition() != null ? objectMapper.writeValueAsString(dto.getSellCondition()) : null);
dto.getSellCondition() != null
? dslTimeframeNormalizer.normalizeJson(objectMapper.writeValueAsString(dto.getSellCondition()))
: null);
} catch (Exception e) {
log.warn("전략 DSL 직렬화 실패: {}", e.getMessage());
}
@@ -69,6 +74,37 @@ public class StrategyService {
return toDto(saved);
}
/**
* DB에 저장된 매수/매도 DSL에 TIMEFRAME 래핑이 없으면 보정 후 저장.
* (편집기 재저장 없이 기존 3분봉 전략 등을 즉시 수정할 때)
*/
@Transactional
public Optional<StrategyDto> repairTimeframeWrappers(Long id) {
return repository.findById(id).map(entity -> {
boolean changed = false;
if (entity.getBuyConditionJson() != null && !entity.getBuyConditionJson().isBlank()) {
String fixed = dslTimeframeNormalizer.normalizeJson(entity.getBuyConditionJson());
if (!fixed.equals(entity.getBuyConditionJson())) {
entity.setBuyConditionJson(fixed);
changed = true;
}
}
if (entity.getSellConditionJson() != null && !entity.getSellConditionJson().isBlank()) {
String fixed = dslTimeframeNormalizer.normalizeJson(entity.getSellConditionJson());
if (!fixed.equals(entity.getSellConditionJson())) {
entity.setSellConditionJson(fixed);
changed = true;
}
}
if (!changed) return toDto(entity);
GcStrategy saved = repository.save(entity);
conditionTimeframes.invalidate(saved.getId());
liveStrategyEvaluator.invalidateStrategy(saved.getId());
log.info("[Strategy] TIMEFRAME 래핑 보정 strategyId={}", id);
return toDto(saved);
});
}
// ── 삭제 ──────────────────────────────────────────────────────────────────
@Transactional