diff --git a/project/src/main/java/com/sdm/project/controller/SimulationNodeController.java b/project/src/main/java/com/sdm/project/controller/SimulationNodeController.java index caeabc43..0ca193d5 100644 --- a/project/src/main/java/com/sdm/project/controller/SimulationNodeController.java +++ b/project/src/main/java/com/sdm/project/controller/SimulationNodeController.java @@ -424,14 +424,14 @@ public class SimulationNodeController implements ISimulationNodeFeignClient { @PostMapping("/followProject") @Operation(summary = "关注项目", description = "关注项目") public SdmResponse followProject(@RequestBody SpdmProjectFollowReq req) { - return nodeService.followProject(req.getNodeId(), req.getUserIdList()); + return nodeService.followProject(req.getNodeId()); } @SysLog("取消关注项目") @PostMapping("/unFollowProject") @Operation(summary = "关注项目", description = "关注项目") public SdmResponse unFollowProject(@RequestBody SpdmProjectFollowReq req) { - return nodeService.unFollowProject(req.getNodeId(), req.getUserIdList()); + return nodeService.unFollowProject(req.getNodeId()); } diff --git a/project/src/main/java/com/sdm/project/model/req/SpdmProjectFollowReq.java b/project/src/main/java/com/sdm/project/model/req/SpdmProjectFollowReq.java index f94a90ae..b33f195f 100644 --- a/project/src/main/java/com/sdm/project/model/req/SpdmProjectFollowReq.java +++ b/project/src/main/java/com/sdm/project/model/req/SpdmProjectFollowReq.java @@ -13,9 +13,4 @@ public class SpdmProjectFollowReq extends BaseEntity { */ private String nodeId; - /** - * 关注项目的用户id集合 - */ - List userIdList; - } diff --git a/project/src/main/java/com/sdm/project/service/INodeService.java b/project/src/main/java/com/sdm/project/service/INodeService.java index e75e4418..31019b20 100644 --- a/project/src/main/java/com/sdm/project/service/INodeService.java +++ b/project/src/main/java/com/sdm/project/service/INodeService.java @@ -96,18 +96,16 @@ public interface INodeService extends IService { * 关注项目(批量为多个用户添加项目关注关系) * * @param nodeId 项目节点ID(uuid) - * @param userIdList 要关注项目的用户ID列表 * @return 统一响应结果 */ - SdmResponse followProject(String nodeId, List userIdList); + SdmResponse followProject(String nodeId); /** * 取消关注项目(批量为多个用户删除项目关注关系) * * @param nodeId 项目节点ID(uuid) - * @param userIdList 要关注项目的用户ID列表 * @return 统一响应结果 */ - SdmResponse unFollowProject(String nodeId, List userIdList); + SdmResponse unFollowProject(String nodeId); } diff --git a/project/src/main/java/com/sdm/project/service/impl/NodeServiceImpl.java b/project/src/main/java/com/sdm/project/service/impl/NodeServiceImpl.java index f251b528..e88657f6 100644 --- a/project/src/main/java/com/sdm/project/service/impl/NodeServiceImpl.java +++ b/project/src/main/java/com/sdm/project/service/impl/NodeServiceImpl.java @@ -175,7 +175,6 @@ public class NodeServiceImpl extends ServiceImpl userIdList) { - // 1. 参数校验 - if (StringUtils.isEmpty(nodeId) || CollectionUtils.isEmpty(userIdList)) { - log.warn("关注项目参数异常,nodeId:{},userIdList:{}", nodeId, userIdList); - return SdmResponse.failed(PARAM_ERROR_MSG); - } - - // 2. 查询项目节点是否存在 + public SdmResponse followProject(String nodeId) { + // 1. 查询项目节点是否存在 SimulationNode projectNode = this.lambdaQuery() .eq(SimulationNode::getUuid, nodeId) .one(); @@ -4034,38 +4027,31 @@ public class NodeServiceImpl extends ServiceImpl validUserIdList = userIdList.stream() - .filter(userId -> userId != null && userId > 0) - .collect(Collectors.toList()); - if (CollectionUtils.isEmpty(validUserIdList)) { - log.info("无有效用户ID需要关注项目,nodeId:{}", nodeId); - return SdmResponse.success(); - } + List validUserIdList = Collections.singletonList(ThreadLocalContext.getUserId()); - // 4. 校验幂等性,防止重复关注 + // 2. 校验幂等性,防止重复关注 Set existedFollowedUserIdSet = queryExistedFollowedUserIds(nodeId, validUserIdList); - // 5. 过滤出未关注的用户ID + // 3. 过滤出未关注的用户ID List toFollowUserIdList = validUserIdList.stream() .filter(userId -> !existedFollowedUserIdSet.contains(userId)) .collect(Collectors.toList()); - // 6. 处理已全部关注的情况 + // 4. 处理已全部关注的情况 if (CollectionUtils.isEmpty(toFollowUserIdList)) { log.info("所有用户均已关注项目,nodeId:{},用户列表:{}", nodeId, validUserIdList); return SdmResponse.success(ALL_FOLLOWED_MSG); } - // 7. 记录重复关注的用户 + // 5. 记录重复关注的用户 List repeatedUserIdList = validUserIdList.stream() .filter(existedFollowedUserIdSet::contains) .collect(Collectors.toList()); - if (!CollectionUtils.isEmpty(repeatedUserIdList)) { + if (CollectionUtils.isNotEmpty(repeatedUserIdList)) { log.error("部分用户已关注项目,跳过重复关注,nodeId:{},重复用户ID:{}", nodeId, repeatedUserIdList); } - // 8. 构建批量插入的关注关系列表(仅处理未关注用户) + // 6. 构建批量插入的关注关系列表(仅处理未关注用户) LocalDateTime currentTime = LocalDateTime.now(); Long currentUserId = ThreadLocalContext.getUserId(); List attentionList = new ArrayList<>(toFollowUserIdList.size()); @@ -4080,7 +4066,7 @@ public class NodeServiceImpl extends ServiceImpl userIdList) { - // 1. 参数校验 - if (StringUtils.isEmpty(nodeId) || CollectionUtils.isEmpty(userIdList)) { - log.warn("取消关注项目参数异常,nodeId:{},userIdList:{}", nodeId, userIdList); - return SdmResponse.failed(PARAM_ERROR_MSG); - } - - // 2. 校验项目是否存在 + public SdmResponse unFollowProject(String nodeId) { + // 1. 校验项目是否存在 SimulationNode projectNode = this.lambdaQuery().eq(SimulationNode::getUuid, nodeId).one(); if (projectNode == null) { log.error("取消关注项目失败,根据nodeId:{} 未查询到项目节点", nodeId); return SdmResponse.failed(UN_FOLLOW_PROJECT_NOT_FOUND_MSG); } - // 3. 过滤无效用户ID(null/负数),避免无效SQL条件 - List validUserIdList = userIdList.stream().filter(userId -> userId != null && userId > 0).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(validUserIdList)) { - log.info("取消关注项目无有效用户ID,nodeId:{}", nodeId); - return SdmResponse.success(NO_UNFOLLOW_DATA_MSG); - } + List validUserIdList = Collections.singletonList(ThreadLocalContext.getUserId()); - // 4. 幂等性核心:先查询已存在的关注关系(仅查询需要删除的记录) + + // 2. 幂等:先查询已存在的关注关系(仅查询需要删除的记录) Set existedFollowedUserIdSet = queryExistedFollowedUserIds(nodeId, validUserIdList); if (CollectionUtils.isEmpty(existedFollowedUserIdSet)) { log.info("取消关注项目失败,无已关注的用户记录,nodeId:{},用户列表:{}", nodeId, validUserIdList); return SdmResponse.success(NO_UNFOLLOW_DATA_MSG); } - // 5. 仅删除已存在的关注关系(避免无效删除操作) + // 3. 仅删除已存在的关注关系(避免无效删除操作) try { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() .eq(SimulationNodeMember::getNodeId, nodeId) @@ -4149,25 +4123,10 @@ public class NodeServiceImpl extends ServiceImpl userIdList) { -// if (StringUtils.isBlank(nodeId) || CollectionUtils.isEmpty(userIdList)) { -// return SdmResponse.failed("参数不正确"); -// } -// SimulationNode projectNode = this.lambdaQuery().eq(SimulationNode::getUuid, nodeId).one(); -// if (ObjectUtils.isEmpty(projectNode)) { -// log.error("followProject根据nodeId:{},未查询到项目", nodeId); -// return SdmResponse.failed("取消关注项目失败,原因为:未查询到项目"); -// } -// simulationNodeMemberService.lambdaUpdate().eq(SimulationNodeMember::getNodeId,nodeId).in(SimulationNodeMember::getUserId,userIdList).remove(); -// return SdmResponse.success(); -// } - /** * 批量查询已关注指定项目的用户ID * @@ -4194,35 +4153,6 @@ public class NodeServiceImpl extends ServiceImpl userIdList) { -// if (StringUtils.isBlank(nodeId) || CollectionUtils.isEmpty(userIdList)) { -// return SdmResponse.failed("参数不正确"); -// } -// SimulationNode projectNode = this.lambdaQuery().eq(SimulationNode::getUuid, nodeId).one(); -// if (ObjectUtils.isEmpty(projectNode)) { -// log.error("followProject根据nodeId:{},未查询到项目", nodeId); -// return SdmResponse.failed("关注项目失败,原因为:未查询到项目"); -// } -// if (CollectionUtils.isNotEmpty(userIdList)) { -// List attentionList = new ArrayList<>(); -// String curDateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); -// Long jobNumber = ThreadLocalContext.getUserId(); -// // 关注 -// for (Long userId : userIdList) { -// SimulationNodeMember simulationNodeMember = new SimulationNodeMember(); -// simulationNodeMember.setNodeId(nodeId); -// simulationNodeMember.setUserId(userId); -// simulationNodeMember.setType(NodeMemberTypeEnum.ATTENTION.getCode()); -// simulationNodeMember.setCreateTime(curDateStr); -// simulationNodeMember.setCreator(jobNumber); -// attentionList.add(simulationNodeMember); -// } -// simulationNodeMemberService.saveBatch(attentionList); -// } -// return SdmResponse.success(); -// } - /** * 通用分组统计方法 - 按指定键分组统计状态数量 *