From 7ec9311df2c8dd9058684fd4ac06596fc624e4b8 Mon Sep 17 00:00:00 2001 From: WrBug Date: Sat, 14 Feb 2026 13:13:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(cryptotail):=20=E5=88=9B=E5=BB=BA/?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AD=96=E7=95=A5=E6=97=B6=E6=9C=AA=E5=A1=AB?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E5=88=99=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=B9=B6=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - create: name 为空时生成「尾盘策略-{marketSlugPrefix}-{yyyyMMddHHmmss}」 - update: 未填且原无标题时同样生成并更新 Co-authored-by: Cursor --- .../cryptotail/CryptoTailStrategyService.kt | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailStrategyService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailStrategyService.kt index cb28211..05398f1 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailStrategyService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailStrategyService.kt @@ -14,6 +14,9 @@ import org.springframework.data.domain.PageRequest import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.math.BigDecimal +import java.time.Instant +import java.time.ZoneId +import java.time.format.DateTimeFormatter @Service class CryptoTailStrategyService( @@ -60,9 +63,12 @@ class CryptoTailStrategyService( return Result.failure(IllegalArgumentException(ErrorCode.PARAM_ERROR.messageKey)) } + val nameToSave = request.name?.takeIf { it.isNotBlank() } + ?: generateStrategyName(request.marketSlugPrefix.trim()) + val entity = CryptoTailStrategy( accountId = request.accountId, - name = request.name?.takeIf { it.isNotBlank() }, + name = nameToSave, marketSlugPrefix = request.marketSlugPrefix.trim(), intervalSeconds = interval, windowStartSeconds = request.windowStartSeconds, @@ -101,8 +107,12 @@ class CryptoTailStrategyService( request.windowStartSeconds?.let { if (it > (request.windowEndSeconds ?: existing.windowEndSeconds)) return Result.failure(IllegalArgumentException(ErrorCode.CRYPTO_TAIL_STRATEGY_WINDOW_INVALID.messageKey)) } request.windowEndSeconds?.let { if (it > maxWindow) return Result.failure(IllegalArgumentException(ErrorCode.CRYPTO_TAIL_STRATEGY_WINDOW_EXCEED.messageKey)) } + val nameToSave = request.name?.takeIf { it.isNotBlank() } + ?: existing.name?.takeIf { it.isNotBlank() } + ?: generateStrategyName(existing.marketSlugPrefix) + val updated = existing.copy( - name = request.name?.takeIf { it.isNotBlank() } ?: existing.name, + name = nameToSave, windowStartSeconds = request.windowStartSeconds ?: existing.windowStartSeconds, windowEndSeconds = request.windowEndSeconds ?: existing.windowEndSeconds, minPrice = request.minPrice?.toSafeBigDecimal() ?: existing.minPrice, @@ -187,6 +197,12 @@ class CryptoTailStrategyService( fun getStrategy(strategyId: Long): CryptoTailStrategy? = strategyRepository.findById(strategyId).orElse(null) + private fun generateStrategyName(marketSlugPrefix: String): String { + val suffix = Instant.now().atZone(ZoneId.systemDefault()) + .format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + return "尾盘策略-${marketSlugPrefix}-$suffix" + } + private fun entityToDto(e: CryptoTailStrategy, lastTriggerAt: Long?): CryptoTailStrategyDto { val strategyId = e.id ?: 0L val totalPnl = triggerRepository.sumRealizedPnlByStrategyId(strategyId)