9 changed files with 254 additions and 22 deletions
@ -0,0 +1,17 @@ |
|||||
|
package com.project.interaction.application; |
||||
|
|
||||
|
import com.project.interaction.domain.dto.AiExtractTriggerResultDTO; |
||||
|
|
||||
|
/** |
||||
|
* 手动触发知识点提取应用服务 |
||||
|
*/ |
||||
|
public interface TriggerAiExtractApplicationService { |
||||
|
|
||||
|
/** |
||||
|
* 手动触发知识点提取 |
||||
|
* 校验子文件是否全部解析完成,完成则调用算法服务 |
||||
|
* @param informationId 虚拟资料ID |
||||
|
* @return 触发结果(含各文件解析状态) |
||||
|
*/ |
||||
|
AiExtractTriggerResultDTO trigger(Long informationId); |
||||
|
} |
||||
@ -0,0 +1,110 @@ |
|||||
|
package com.project.interaction.application.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.project.information.domain.entity.InformationFileEntity; |
||||
|
import com.project.information.domain.enums.FileParseStatusEnum; |
||||
|
import com.project.information.domain.service.InformationFileBaseService; |
||||
|
import com.project.interaction.application.TriggerAiExtractApplicationService; |
||||
|
import com.project.interaction.domain.dto.AiExtractRequestDTO; |
||||
|
import com.project.interaction.domain.dto.AiExtractTriggerResultDTO; |
||||
|
import com.project.interaction.domain.service.PostToAiExtractDomainService; |
||||
|
import com.project.interaction.domain.service.SaveDataExtractResultDomainService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 手动触发知识点提取应用服务实现 |
||||
|
*/ |
||||
|
@Service |
||||
|
@Slf4j |
||||
|
public class TriggerAiExtractApplicationServiceImpl implements TriggerAiExtractApplicationService { |
||||
|
|
||||
|
@Autowired |
||||
|
private InformationFileBaseService informationFileBaseService; |
||||
|
|
||||
|
@Autowired |
||||
|
private PostToAiExtractDomainService postToAiExtractDomainService; |
||||
|
|
||||
|
@Autowired |
||||
|
private SaveDataExtractResultDomainService saveDataExtractResultDomainService; |
||||
|
|
||||
|
@Override |
||||
|
public AiExtractTriggerResultDTO trigger(Long informationId) { |
||||
|
|
||||
|
// 1. 查询该虚拟资料下所有子文件
|
||||
|
List<InformationFileEntity> allFiles = informationFileBaseService.list( |
||||
|
new LambdaQueryWrapper<InformationFileEntity>() |
||||
|
.eq(InformationFileEntity::getInformationId, informationId) |
||||
|
.orderByAsc(InformationFileEntity::getCreateTime)); |
||||
|
|
||||
|
if (allFiles.isEmpty()) { |
||||
|
return new AiExtractTriggerResultDTO(true, null, "该虚拟资料下没有子文件", new ArrayList<>()); |
||||
|
} |
||||
|
|
||||
|
// 2. 构建各文件状态
|
||||
|
List<AiExtractTriggerResultDTO.FileStatus> fileStatuses = new ArrayList<>(); |
||||
|
boolean allDone = true; |
||||
|
boolean allSuccess = true; |
||||
|
|
||||
|
for (InformationFileEntity f : allFiles) { |
||||
|
Integer parseStatus = f.getParseStatus(); |
||||
|
String statusText = getStatusText(parseStatus); |
||||
|
|
||||
|
AiExtractTriggerResultDTO.FileStatus fs = |
||||
|
new AiExtractTriggerResultDTO.FileStatus(f.getId(), f.getFileName(), parseStatus, statusText); |
||||
|
fileStatuses.add(fs); |
||||
|
|
||||
|
if (!FileParseStatusEnum.Success.getValue().equals(parseStatus) |
||||
|
&& !FileParseStatusEnum.Failed.getValue().equals(parseStatus)) { |
||||
|
allDone = false; |
||||
|
} |
||||
|
if (!FileParseStatusEnum.Success.getValue().equals(parseStatus)) { |
||||
|
allSuccess = false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 3. 未全部完成
|
||||
|
if (!allDone) { |
||||
|
String message = "子文件尚未全部解析完成,共 " + allFiles.size() + " 个文件," |
||||
|
+ allFiles.stream().filter(f -> FileParseStatusEnum.Success.getValue().equals(f.getParseStatus())).count() |
||||
|
+ " 个已完成"; |
||||
|
return new AiExtractTriggerResultDTO(false, null, message, fileStatuses); |
||||
|
} |
||||
|
|
||||
|
// 4. 全部完成但有失败
|
||||
|
if (!allSuccess) { |
||||
|
String message = "存在解析失败的子文件,无法调用算法服务"; |
||||
|
return new AiExtractTriggerResultDTO(true, false, message, fileStatuses); |
||||
|
} |
||||
|
|
||||
|
// 5. 全部成功 → 调用算法服务
|
||||
|
log.info(">>> [手动触发] 虚拟资料 {} 下所有子文件解析完成,开始调用算法服务", informationId); |
||||
|
|
||||
|
AiExtractRequestDTO extractRequest = saveDataExtractResultDomainService.buildExtractRequest(informationId); |
||||
|
if (extractRequest == null) { |
||||
|
return new AiExtractTriggerResultDTO(true, true, "所有子文件解析成功,但无有效文本内容", fileStatuses); |
||||
|
} |
||||
|
|
||||
|
postToAiExtractDomainService.postToAiExtract(extractRequest); |
||||
|
|
||||
|
String message = "已成功触发算法服务,共 " + extractRequest.getSegments().size() + " 个文本片段"; |
||||
|
return new AiExtractTriggerResultDTO(true, true, message, fileStatuses); |
||||
|
} |
||||
|
|
||||
|
private String getStatusText(Integer status) { |
||||
|
if (status == null) { |
||||
|
return "未知"; |
||||
|
} |
||||
|
return switch (status) { |
||||
|
case 0 -> "未开始"; |
||||
|
case 1 -> "进行中"; |
||||
|
case 2 -> "成功"; |
||||
|
case -1 -> "失败"; |
||||
|
default -> "未知"; |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
package com.project.interaction.domain.dto; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 手动触发知识点提取结果 DTO |
||||
|
*/ |
||||
|
@Data |
||||
|
@AllArgsConstructor |
||||
|
public class AiExtractTriggerResultDTO { |
||||
|
|
||||
|
/** 是否全部解析完成 */ |
||||
|
private Boolean allDone; |
||||
|
|
||||
|
/** 是否全部成功(allDone 为 true 时有效) */ |
||||
|
private Boolean allSuccess; |
||||
|
|
||||
|
/** 提示信息 */ |
||||
|
private String message; |
||||
|
|
||||
|
/** 各子文件解析状态 */ |
||||
|
private List<FileStatus> fileStatuses; |
||||
|
|
||||
|
@Data |
||||
|
public static class FileStatus { |
||||
|
/** 子文件ID */ |
||||
|
private Long fileId; |
||||
|
|
||||
|
/** 文件名 */ |
||||
|
private String fileName; |
||||
|
|
||||
|
/** 解析状态:0-未开始,1-进行中,2-成功,-1-失败 */ |
||||
|
private Integer parseStatus; |
||||
|
|
||||
|
/** 状态文本 */ |
||||
|
private String statusText; |
||||
|
|
||||
|
public FileStatus(Long fileId, String fileName, Integer parseStatus, String statusText) { |
||||
|
this.fileId = fileId; |
||||
|
this.fileName = fileName; |
||||
|
this.parseStatus = parseStatus; |
||||
|
this.statusText = statusText; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,11 +1,20 @@ |
|||||
package com.project.interaction.domain.service; |
package com.project.interaction.domain.service; |
||||
|
|
||||
|
import com.project.interaction.domain.dto.AiExtractRequestDTO; |
||||
import com.project.interaction.domain.dto.DataExtractCallbackDTO; |
import com.project.interaction.domain.dto.DataExtractCallbackDTO; |
||||
|
|
||||
|
|
||||
/** |
/** |
||||
* 保存数据服务解析结果域服务 |
* 保存数据服务解析结果域服务 |
||||
* 更新子文件解析状态和文本,检查批次完成,触发算法服务 |
* 更新子文件解析状态和文本,检查批次完成,触发算法服务 |
||||
*/ |
*/ |
||||
public interface SaveDataExtractResultDomainService { |
public interface SaveDataExtractResultDomainService { |
||||
void handleCallback(DataExtractCallbackDTO callback); |
void handleCallback(DataExtractCallbackDTO callback); |
||||
|
|
||||
|
/** |
||||
|
* 构建知识点提取请求(从已解析完成的子文件列表) |
||||
|
* @param informationId 虚拟资料ID |
||||
|
* @return 请求 DTO,null 表示无有效数据 |
||||
|
*/ |
||||
|
AiExtractRequestDTO buildExtractRequest(Long informationId); |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue