huliguo
15 小时以前 affd7e9f1cc591be36102299cac45b35d9536a17
src/main/java/com/linghu/controller/CollectController.java
@@ -683,7 +683,7 @@
                                questionsToUpdate.add(question);
                                List<Reference> references =
                               /* List<Reference> references =
                                        Optional.ofNullable(questionResult.getReferences())
                                                .orElse(Collections.emptyList())
                                                .stream()
@@ -727,8 +727,60 @@
                                                    }
                                                    return reference;
                                                })
                                                .collect(Collectors.toList());
                                                .collect(Collectors.toList());*/
// 初始化引用列表(避免null)
                                List<Reference> references = new ArrayList<>();
                                List<TaskResultResponse.Reference> originalReferences = questionResult.getReferences();
                                if (originalReferences == null) {
                                    originalReferences = Collections.emptyList();
                                }
// 遍历原始引用列表,转换为Reference对象
                                for (TaskResultResponse.Reference ref : originalReferences) { // 注意:需将“原引用类型”替换为实际类型(如QuestionResult中的引用类型)
                                    Reference reference = new Reference();
                                    // 设置基本字段
                                    reference.setQuestion_id(question.getQuestion_id());
                                    reference.setTitle(ref.getTitle());
                                    reference.setUrl(ref.getUrl());
                                    reference.setDomain(ref.getDomain());
                                    reference.setNum(keyword.getNum());
                                    reference.setTask_id(result.getTask_id());
                                    reference.setKeyword_id(keyword.getKeyword_id());
                                    reference.setCreate_time(LocalDateTime.now());
                                    // 处理平台和类型关联
                                    Platform platform = platformService.getPlatformByDomain(reference.getDomain());
                                    if (platform == null) {
                                        // 平台不存在,创建新平台(类型默认为“默认”)
                                        Type type = typeService.getOne(new LambdaQueryWrapper<Type>().eq(Type::getType_name, "默认"));
                                        if (type == null) {
                                            Type newType = new Type();
                                            newType.setType_name("默认");
                                            typeService.save(newType);
                                            type = newType;
                                        }
                                        Platform platform1 = new Platform();
                                        platform1.setDomain(reference.getDomain());
                                        platform1.setPlatform_name(reference.getDomain());
                                        platform1.setType_id(type.getType_id());
                                        platform1.setCreate_time(LocalDateTime.now());
                                        platformService.save(platform1);
                                        // 关联新平台和类型
                                        reference.setType_id(type.getType_id());
                                        reference.setPlatform_id(platform1.getPlatform_id());
                                    } else {
                                        // 平台已存在,直接关联
                                        reference.setPlatform_id(platform.getPlatform_id());
                                        Type type = typeService.getById(platform.getType_id());
                                        if (type != null) {
                                            reference.setType_id(type.getType_id());
                                        }
                                    }
                                    // 添加到结果列表
                                    references.add(reference);
                                }
                                // 添加到总引用列表
                                if (!references.isEmpty()) {
                                    allReferences.addAll(references);
@@ -763,18 +815,18 @@
                                    int repetitionCount = refGroup.size() - 1;
                                    // 3.3 决定最终保留的记录
                                    Reference recordToSave;
                                    Reference recordToSave = new Reference();
                                    if (existingRecord.isPresent()) {
                                        // 使用已有ID的记录并更新重复次数
                                        recordToSave = existingRecord.get();
                                        recordToSave.setRepetition_num(
                                                (recordToSave.getRepetition_num() == null ? 0 : recordToSave.getRepetition_num())
                                                (recordToSave.getRepetition_num() == null ? 1 : recordToSave.getRepetition_num())
                                                        + repetitionCount
                                        );
                                    } else {
                                        // 没有ID记录则取第一条并设置重复次数
                                        recordToSave = refGroup.get(0);
                                        recordToSave.setRepetition_num(repetitionCount);
                                        recordToSave.setRepetition_num(1+repetitionCount);
                                    }
                                    resultList.add(recordToSave);