Browse Source

bug修复

master
luoweijian 2 months ago
parent
commit
082b90b32c
  1. 9
      src/main/java/com/project/interaction/domain/service/impl/SaveAiExtractDraftDomainServiceImpl.java
  2. 47
      src/main/java/com/project/interaction/domain/service/impl/SaveDataExtractResultDomainServiceImpl.java

9
src/main/java/com/project/interaction/domain/service/impl/SaveAiExtractDraftDomainServiceImpl.java

@ -4,6 +4,7 @@ import com.project.information.domain.entity.InformationEntity;
import com.project.information.domain.entity.KnowledgePointDraftEntity;
import com.project.information.domain.enums.AuditStatusEnum;
import com.project.information.domain.enums.DraftStatusEnum;
import com.project.information.domain.enums.InformationParseStatusEnum;
import com.project.information.domain.service.InformationBaseService;
import com.project.information.domain.service.KnowledgePointDraftBaseService;
import com.project.interaction.domain.dto.AiExtractCallbackDTO;
@ -57,7 +58,13 @@ public class SaveAiExtractDraftDomainServiceImpl implements SaveAiExtractDraftDo
}
knowledgePointDraftBaseService.saveBatch(draftEntities);
// 2. 更新虚拟资料 draftStatus = PENDING(1)
// 2. 更新虚拟资料解析状态 = 成功
informationBaseService.lambdaUpdate()
.eq(InformationEntity::getId, informationId)
.set(InformationEntity::getParseStatus, InformationParseStatusEnum.Success.getValue())
.update();
// 3. 更新虚拟资料 draftStatus = PENDING(1)
informationBaseService.lambdaUpdate()
.eq(InformationEntity::getId, informationId)
.set(InformationEntity::getDraftStatus, DraftStatusEnum.PENDING.getValue())

47
src/main/java/com/project/interaction/domain/service/impl/SaveDataExtractResultDomainServiceImpl.java

@ -83,17 +83,14 @@ public class SaveDataExtractResultDomainServiceImpl implements SaveDataExtractRe
boolean allSuccess = allFiles.stream()
.allMatch(f -> FileParseStatusEnum.Success.getValue().equals(f.getParseStatus()));
// 更新虚拟资料的解析状态(无论成功或失败都更新)
InformationEntity information = informationBaseService.getById(informationId);
if (information != null) {
information.setParseStatus(allSuccess
? InformationParseStatusEnum.Success.getValue()
: InformationParseStatusEnum.Fail.getValue());
informationBaseService.updateById(information);
log.info(">>> [数据服务回调] 虚拟资料 {} 解析状态已更新为: {}", informationId, information.getParseStatus());
}
if (!allSuccess) {
// 更新虚拟资料的解析状态为失败
InformationEntity information = informationBaseService.getById(informationId);
if (information != null) {
information.setParseStatus(InformationParseStatusEnum.Fail.getValue());
informationBaseService.updateById(information);
log.info(">>> [数据服务回调] 虚拟资料 {} 解析状态已更新为: 失败", informationId);
}
log.warn(">>> [数据服务回调] 虚拟资料 {} 下存在解析失败的子文件,跳过算法调用", informationId);
return;
}
@ -125,24 +122,26 @@ public class SaveDataExtractResultDomainServiceImpl implements SaveDataExtractRe
// 解析 parsed_text JSON: {"segments": [[{"content": "...", "supplement": "", "chapter": "...", "content_type": "..."}]]}
// segments 是双层数组:外层=每个子文件,内层=该文件的段落列表
try {
Map<String, List<List<Map<String, String>>>> parsed = objectMapper.readValue(
f.getParsedText(), new TypeReference<>() {
// 1. 将 TypeReference 改为单层 List: List<Map<String, String>>
Map<String, List<Map<String, String>>> parsed = objectMapper.readValue(
f.getParsedText(), new TypeReference<Map<String, List<Map<String, String>>>>() {
});
List<List<Map<String, String>>> fileGroups = parsed.get("segments");
if (fileGroups == null || fileGroups.isEmpty()) {
List<Map<String, String>> segments = parsed.get("segments");
if (segments == null || segments.isEmpty()) {
continue;
}
String fileName = f.getFileName();
for (List<Map<String, String>> group : fileGroups) {
for (Map<String, String> seg : group) {
AiExtractRequestDTO.Segment segment = new AiExtractRequestDTO.Segment();
segment.setContent(seg.get("content"));
segment.setSupplement(seg.get("supplement"));
segment.setChapter(seg.get("chapter"));
segment.setParseName(fileName);
segment.setContentType(seg.get("content_type"));
allSegments.add(segment);
}
// 2. 去掉双层循环,直接遍历单层 List
for (Map<String, String> seg : segments) {
AiExtractRequestDTO.Segment segment = new AiExtractRequestDTO.Segment();
segment.setContent(seg.get("content"));
segment.setSupplement(seg.get("supplement"));
segment.setChapter(seg.get("chapter"));
segment.setParseName(fileName);
segment.setContentType(seg.get("content_type"));
allSegments.add(segment);
}
} catch (Exception e) {
log.error(">>> [数据服务] 解析 parsedText 失败, fileId={}, error={}", f.getId(), e.getMessage());

Loading…
Cancel
Save