|
|
|
@ -6,6 +6,7 @@ import com.project.base.config.CustomIdGenerator; |
|
|
|
import com.project.base.domain.result.Result; |
|
|
|
import com.project.information.application.DraftReviewApplicationService; |
|
|
|
import com.project.information.domain.dto.DraftSaveDTO; |
|
|
|
import com.project.information.domain.dto.KnowledgePointDTO; |
|
|
|
import com.project.information.domain.entity.InformationEntity; |
|
|
|
import com.project.information.domain.entity.KnowledgeClusterEntity; |
|
|
|
import com.project.information.domain.entity.KnowledgePointDraftEntity; |
|
|
|
@ -225,13 +226,7 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication |
|
|
|
|
|
|
|
/** |
|
|
|
* 触发语义聚类 |
|
|
|
* 当前为 mock 实现(均分2个簇),算法服务就绪后替换为真实调用 |
|
|
|
* |
|
|
|
* 替换方式:将方法体改为: |
|
|
|
* List<KnowledgePointDTO> kpList = knowledgePoints.stream() |
|
|
|
* .map(entity -> entity.toDTO(KnowledgePointDTO::new)) |
|
|
|
* .toList(); |
|
|
|
* algorithmApplicationService.postToClusteringByInformationId(informationId, kpList); |
|
|
|
* 调用算法服务进行真实聚类,回调结果由 saveClusterByInformationId 处理 |
|
|
|
*/ |
|
|
|
private void triggerClustering(Long informationId, List<KnowledgePointEntity> knowledgePoints) { |
|
|
|
// 清理旧聚类数据
|
|
|
|
@ -246,35 +241,12 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 均分为2个簇
|
|
|
|
int mid = (int) Math.ceil(knowledgePoints.size() / 2.0); |
|
|
|
List<List<KnowledgePointEntity>> groups = List.of( |
|
|
|
knowledgePoints.subList(0, mid), |
|
|
|
knowledgePoints.subList(mid, knowledgePoints.size()) |
|
|
|
); |
|
|
|
|
|
|
|
String[] topics = {"前端框架核心概念", "后端基础设施"}; |
|
|
|
for (int i = 0; i < groups.size(); i++) { |
|
|
|
List<KnowledgePointEntity> group = groups.get(i); |
|
|
|
if (group.isEmpty()) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
KnowledgeClusterEntity cluster = new KnowledgeClusterEntity(); |
|
|
|
cluster.setInformationId(informationId); |
|
|
|
cluster.setClusterTopic(topics[i % topics.length]); |
|
|
|
cluster.setClusterSize(group.size()); |
|
|
|
knowledgeClusterBaseService.save(cluster); |
|
|
|
|
|
|
|
// 回写 clusterId 到知识点
|
|
|
|
List<Long> kpIds = group.stream().map(KnowledgePointEntity::getId).toList(); |
|
|
|
knowledgePointBaseService.lambdaUpdate() |
|
|
|
.in(KnowledgePointEntity::getId, kpIds) |
|
|
|
.set(KnowledgePointEntity::getClusterId, cluster.getId()) |
|
|
|
.update(); |
|
|
|
} |
|
|
|
// 转换为 DTO 并调用算法服务聚类
|
|
|
|
List<KnowledgePointDTO> kpList = knowledgePoints.stream() |
|
|
|
.map(entity -> entity.toDTO(KnowledgePointDTO::new)) |
|
|
|
.toList(); |
|
|
|
algorithmApplicationService.postToClusteringByInformationId(informationId, kpList); |
|
|
|
|
|
|
|
log.info(">>> [Mock聚类] 完成, informationId={}, 知识点数={}, 簇数={}", |
|
|
|
informationId, knowledgePoints.size(), groups.stream().filter(g -> !g.isEmpty()).count()); |
|
|
|
log.info(">>> [聚类] 已请求算法服务聚类, informationId={}, 知识点数={}", informationId, knowledgePoints.size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|