feat: 新增按状态批量删除链接功能
主要修改: 1. 在LinkController中新增按状态批量删除链接的接口,允许用户根据指定状态批量删除自己创建的链接。 2. 在LinkStatusService中实现批量删除逻辑,确保用户只能删除自己的链接,并进行状态验证。 3. 更新LinkTaskMapper和对应的XML文件,增加查询和删除链接任务的相关方法。 技术细节: - 通过新增的批量删除功能,提升了用户对链接的管理能力,确保操作的安全性和有效性,同时优化了数据库操作的灵活性。
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.gameplatform.server.controller.link;
|
||||
|
||||
import com.gameplatform.server.model.dto.link.BatchDeleteByStatusRequest;
|
||||
import com.gameplatform.server.model.dto.link.BatchDeleteRequest;
|
||||
import com.gameplatform.server.model.dto.link.BatchDeleteResponse;
|
||||
import com.gameplatform.server.model.dto.link.LinkGenerateRequest;
|
||||
@@ -296,6 +297,58 @@ public Mono<Boolean> deleteLink(@PathVariable("codeNo") String codeNo, Authentic
|
||||
});
|
||||
}
|
||||
|
||||
@PostMapping("/batch-delete-by-status")
|
||||
@Operation(summary = "按状态批量删除链接", description = "根据指定的状态批量删除链接,用户只能删除自己创建的链接,支持删除的状态:NEW、USING、LOGGED_IN、COMPLETED、REFUNDED、EXPIRED")
|
||||
public Mono<BatchDeleteResponse> batchDeleteLinksByStatus(@Valid @RequestBody BatchDeleteByStatusRequest request, Authentication authentication) {
|
||||
log.info("=== 开始按状态批量删除链接 ===");
|
||||
log.info("要删除的状态列表: {}", request.getStatusList());
|
||||
log.info("是否确认删除: {}", request.getConfirmDelete());
|
||||
|
||||
if (authentication == null) {
|
||||
log.error("=== 认证失败:Authentication为空 ===");
|
||||
return Mono.error(new IllegalArgumentException("用户未认证:Authentication为空"));
|
||||
}
|
||||
|
||||
// 检查是否确认删除
|
||||
if (!Boolean.TRUE.equals(request.getConfirmDelete())) {
|
||||
log.error("=== 未确认删除操作 ===");
|
||||
return Mono.error(new IllegalArgumentException("必须确认删除操作,请设置confirmDelete为true"));
|
||||
}
|
||||
|
||||
// 获取用户ID
|
||||
Claims claims = (Claims) authentication.getDetails();
|
||||
if (claims == null) {
|
||||
log.error("=== 认证失败:Claims为空 ===");
|
||||
log.error("Authentication details: {}", authentication.getDetails());
|
||||
return Mono.error(new IllegalArgumentException("用户未认证:Claims为空"));
|
||||
}
|
||||
|
||||
Long agentId = claims.get("userId", Long.class);
|
||||
String userType = claims.get("userType", String.class);
|
||||
|
||||
log.info("用户信息: agentId={}, userType={}", agentId, userType);
|
||||
|
||||
if (agentId == null) {
|
||||
log.error("=== 无法获取用户ID ===");
|
||||
return Mono.error(new IllegalArgumentException("无法获取用户ID"));
|
||||
}
|
||||
|
||||
return linkStatusService.batchDeleteLinksByStatus(request.getStatusList(), agentId)
|
||||
.doOnSuccess(response -> {
|
||||
log.info("按状态批量删除链接完成: 总数={}, 成功={}, 失败={}, agentId={}",
|
||||
response.getTotalCount(), response.getSuccessCount(),
|
||||
response.getFailedCount(), agentId);
|
||||
if (!response.isAllSuccess()) {
|
||||
log.warn("部分链接删除失败: 失败的链接={}, 失败原因={}",
|
||||
response.getFailedCodeNos(), response.getFailedReasons());
|
||||
}
|
||||
})
|
||||
.doOnError(error -> {
|
||||
log.error("按状态批量删除链接时发生错误: agentId={}, statusList={}, error={}",
|
||||
agentId, request.getStatusList(), error.getMessage(), error);
|
||||
});
|
||||
}
|
||||
|
||||
@PostMapping("/batch-delete")
|
||||
@Operation(summary = "批量删除链接", description = "批量删除指定的链接,用户只能删除自己创建的链接,最多一次删除100个")
|
||||
public Mono<BatchDeleteResponse> batchDeleteLinks(@RequestBody BatchDeleteRequest request, Authentication authentication) {
|
||||
|
||||
Reference in New Issue
Block a user