feat(cost-guard): 代理/LLM 损耗监控与账号级任务暂停

- 每分钟扫描用量增量/日累计,异常置暂停闸并推站内通知
- 品牌补测、跟价派发、外观激活、品牌检测与两个 LLM 客户端统一接闸
- 同一代理/LLM 密钥被 3 个以上账号共用时给出用户提示
- 品牌检测出口拒绝批级熔断;LLM 同 key 共享并发/间隔/429 惩罚
- V170 新增 biz_user_task_guard
This commit is contained in:
2026-10-24 10:50:20 +08:00
parent 052f2bd4a5
commit 9c4905c94e
32 changed files with 1625 additions and 5 deletions
@@ -58,6 +58,10 @@ public class PriceTrackLoopRunService {
private final PriceTrackLoopRunMapper loopRunMapper;
private final FileTaskMapper fileTaskMapper;
private final ObjectMapper objectMapper;
/** 损耗闸:字段注入避免改动手工 new 的 7 处测试构造器;null=未启用(单测)。 */
@org.springframework.beans.factory.annotation.Autowired(required = false)
private com.nanri.aiimage.modules.usersecret.service.UserTaskGuardService taskGuard;
private final ZiniaoShopSwitchService ziniaoShopSwitchService;
@Transactional
@@ -104,6 +108,11 @@ public class PriceTrackLoopRunService {
@Transactional
public PriceTrackLoopRunDispatchVo dispatchNext(Long loopRunId, Long userId) {
if (taskGuard != null && taskGuard.isPaused(userId)) {
// 不把循环标成 STOPPED:暂停只停派发,恢复后同一条循环还能接着跑
throw new BusinessException(com.nanri.aiimage.modules.usersecret.service
.UserTaskGuardService.PAUSED_MESSAGE);
}
PriceTrackLoopRunEntity entity = getOwnedLoopRun(loopRunId, userId);
reconcileWithTerminalChild(entity);
if (isTerminal(entity.getStatus())) {