问题修复,功能优化等

jinan_dev
yaxin 7 months ago
parent e26a95b504
commit 4393f59212

@ -6,6 +6,11 @@
# Release Notes # Release Notes
# 发布时间 2024-12-03
# 变更
- 案件图谱优化,支持多种节点颜色样式,引力布局调整,交互体验优化
# 发布时间 2024-11-21 # 发布时间 2024-11-21
# 变更 # 变更

@ -1,9 +1,6 @@
SET NAMES utf8mb4; SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0; SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for conversation
-- ----------------------------
DROP TABLE IF EXISTS `conversation`; DROP TABLE IF EXISTS `conversation`;
CREATE TABLE `conversation` ( CREATE TABLE `conversation` (
`id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
@ -25,6 +22,8 @@ CREATE TABLE `conversation_qa` (
`complete_question` text CHARACTER SET utf8 COLLATE utf8_bin NULL, `complete_question` text CHARACTER SET utf8 COLLATE utf8_bin NULL,
`question_time` datetime NOT NULL, `question_time` datetime NOT NULL,
`answer` text CHARACTER SET utf8 COLLATE utf8_bin NULL, `answer` text CHARACTER SET utf8 COLLATE utf8_bin NULL,
`answer_map` text CHARACTER SET utf8 COLLATE utf8_bin NULL,
`segment_list` text CHARACTER SET utf8 COLLATE utf8_bin NULL COMMENT 'RAG片段',
`complete_answer` text CHARACTER SET utf8 COLLATE utf8_bin NULL, `complete_answer` text CHARACTER SET utf8 COLLATE utf8_bin NULL,
`answer_time` datetime NULL DEFAULT NULL, `answer_time` datetime NULL DEFAULT NULL,
`time_interval` int(11) NULL DEFAULT NULL, `time_interval` int(11) NULL DEFAULT NULL,
@ -38,3 +37,6 @@ CREATE TABLE `conversation_qa` (
alter table model_case alter table model_case
add knowledge_base_id varchar(64) null comment '知识库id' after id; add knowledge_base_id varchar(64) null comment '知识库id' after id;
ALTER TABLE `nx_llm`.`note_record_split`
ADD COLUMN `note_file_id` varchar(64) NULL COMMENT '笔录文件ID' AFTER `person_name`;

@ -26,8 +26,7 @@ public class ChatController {
@PostMapping("/chat") @PostMapping("/chat")
public R<ChatResVO> chat(@RequestBody ChatReqVO chatReqVO) { public R<ChatResVO> chat(@RequestBody ChatReqVO chatReqVO) {
ChatResVO chatResVO = chatService.chatNew(chatReqVO); return chatService.chatNew(chatReqVO);
return R.ok(chatResVO);
} }
/** /**

@ -3,14 +3,18 @@ package com.supervision.police.domain;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.supervision.police.handler.KnowledgeBaseSegmentVOTypeHandler;
import com.supervision.police.vo.dify.KnowledgeBaseSegmentVO;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import lombok.Data; import java.util.List;
/** /**
* *
*/ */
@TableName(value ="conversation_qa") @TableName(value = "conversation_qa", autoResultMap = true)
@Data @Data
public class ConversationQa implements Serializable { public class ConversationQa implements Serializable {
/** /**
@ -54,6 +58,12 @@ public class ConversationQa implements Serializable {
*/ */
private String answerMap; private String answerMap;
/**
*
*/
@TableField(typeHandler = KnowledgeBaseSegmentVOTypeHandler.class)
private List<KnowledgeBaseSegmentVO> segmentList;
/** /**
* *
*/ */

@ -33,6 +33,11 @@ public class NoteRecordSplit implements Serializable {
*/ */
private String personName; private String personName;
/**
* ID
*/
private String noteFileId;
/** /**
* *
*/ */

@ -0,0 +1,32 @@
package com.supervision.police.handler;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.supervision.police.dto.NotePromptExtractAttributesDto;
import com.supervision.police.vo.dify.KnowledgeBaseSegmentVO;
import java.util.List;
public class KnowledgeBaseSegmentVOTypeHandler extends AbstractJsonTypeHandler<List<KnowledgeBaseSegmentVO>> {
private static final ObjectMapper objectMapper = new ObjectMapper();
@Override
protected List<KnowledgeBaseSegmentVO> parse(String json) {
try {
return objectMapper.readValue(json, new TypeReference<List<KnowledgeBaseSegmentVO>>() {
});
} catch (Exception e) {
throw new RuntimeException("Failed to parse JSON to List<KnowledgeBaseSegmentVO>", e);
}
}
@Override
protected String toJson(List<KnowledgeBaseSegmentVO> obj) {
try {
return objectMapper.writeValueAsString(obj);
} catch (Exception e) {
throw new RuntimeException("Failed to convert List<KnowledgeBaseSegmentVO> to JSON", e);
}
}
}

@ -1,6 +1,7 @@
package com.supervision.police.service; package com.supervision.police.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.supervision.common.domain.R;
import com.supervision.police.vo.ChatReqVO; import com.supervision.police.vo.ChatReqVO;
import com.supervision.police.vo.ChatResVO; import com.supervision.police.vo.ChatResVO;
import com.supervision.police.vo.ConversationResVo; import com.supervision.police.vo.ConversationResVo;
@ -9,7 +10,7 @@ import java.util.List;
public interface ChatService { public interface ChatService {
ChatResVO chat(ChatReqVO chatReqVO); ChatResVO chat(ChatReqVO chatReqVO);
ChatResVO chatNew(ChatReqVO chatReqVO); R<ChatResVO> chatNew(ChatReqVO chatReqVO);
IPage<ChatResVO> queryConversationInfoList(String conversationId, int page, int size); IPage<ChatResVO> queryConversationInfoList(String conversationId, int page, int size);

@ -26,7 +26,7 @@ public interface NoteRecordSplitService extends IService<NoteRecordSplit> {
void delRecords(String id); void delRecords(String id);
NoteRecordSplit saveRecordSplit(NoteRecord record, String fileName, String question, String answer); NoteRecordSplit saveRecordSplit(NoteRecord record, String fileId, String fileName, String question, String answer);
List<NoteRecordSplit> batchSaveRecordSplit(NoteRecord record, String fileId); List<NoteRecordSplit> batchSaveRecordSplit(NoteRecord record, String fileId);
Map<String, Object> queryRecordList(NoteRecordReqVO noteRecord, Integer page, Integer size); Map<String, Object> queryRecordList(NoteRecordReqVO noteRecord, Integer page, Integer size);

@ -12,6 +12,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.supervision.chat.client.LangChainChatService; import com.supervision.chat.client.LangChainChatService;
import com.supervision.chat.client.dto.chat.ChatReqDTO; import com.supervision.chat.client.dto.chat.ChatReqDTO;
import com.supervision.chat.client.dto.chat.ChatResDTO; import com.supervision.chat.client.dto.chat.ChatResDTO;
import com.supervision.common.domain.R;
import com.supervision.constant.CaseAnalysisStatusEnum;
import com.supervision.police.domain.Conversation; import com.supervision.police.domain.Conversation;
import com.supervision.police.domain.ConversationQa; import com.supervision.police.domain.ConversationQa;
import com.supervision.police.domain.ModelCase; import com.supervision.police.domain.ModelCase;
@ -90,7 +92,7 @@ public class ChatServiceImpl implements ChatService {
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class) @Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
@Override @Override
public ChatResVO chatNew(ChatReqVO chatReqVO) { public R<ChatResVO> chatNew(ChatReqVO chatReqVO) {
ChatResVO chatResVO = new ChatResVO(); ChatResVO chatResVO = new ChatResVO();
Map<String, Object> answerMap = new HashMap<>(); Map<String, Object> answerMap = new HashMap<>();
String query = chatReqVO.getQuery(); String query = chatReqVO.getQuery();
@ -145,11 +147,11 @@ public class ChatServiceImpl implements ChatService {
difyChatReqVO.setUser(userId); difyChatReqVO.setUser(userId);
difyChatReqVO.setConversationId(chatReqVO.getConversationId()); difyChatReqVO.setConversationId(chatReqVO.getConversationId());
difyChatReqVO.setQuery(query); difyChatReqVO.setQuery(query);
difyChatReqVO.setInputs(Map.of("dataset_id", modelCase.getKnowledgeBaseId())); difyChatReqVO.setInputs(Map.of("dataset_id", modelCase.getKnowledgeBaseId(), "participator", modelCase.getLawActor()));
DifyChatResVO chat = difyApiUtil.chat(difyChatReqVO); DifyChatResVO chat = difyApiUtil.chat(difyChatReqVO);
JSONObject json = JSON.parseObject(chat.getAnswer()); JSONObject json = JSON.parseObject(chat.getAnswer());
chatResVO.setAnswer(json.getString("answerText")); chatResVO.setAnswer(json.getString("answerText"));
chatResVO.setSegmentVOList(JSONArray.parseArray(json.getString("quote"), KnowledgeBaseSegmentVO.class)); chatResVO.setSegmentList(JSONArray.parseArray(json.getString("quote"), KnowledgeBaseSegmentVO.class));
} }
break; break;
case QA_TYPE_NX_LLM: case QA_TYPE_NX_LLM:
@ -184,6 +186,10 @@ public class ChatServiceImpl implements ChatService {
default: default:
break; break;
} }
if (StringUtils.isEmpty(chatResVO.getAnswer()) && "{}".equals(JSON.toJSONString(answerMap))) {
log.error("chatNew: 未找到答案query:【{}】", query);
return R.fail("未找到答案");
}
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
ConversationQa qa = new ConversationQa(); ConversationQa qa = new ConversationQa();
qa.setId(UUID.randomUUID().toString()); qa.setId(UUID.randomUUID().toString());
@ -191,6 +197,7 @@ public class ChatServiceImpl implements ChatService {
qa.setQuestionTime(new Date(startTime)); qa.setQuestionTime(new Date(startTime));
qa.setAnswer(chatResVO.getAnswer()); qa.setAnswer(chatResVO.getAnswer());
qa.setAnswerMap(JSON.toJSONString(answerMap)); qa.setAnswerMap(JSON.toJSONString(answerMap));
qa.setSegmentList(chatResVO.getSegmentList());
qa.setAnswerTime(new Date(end)); qa.setAnswerTime(new Date(end));
qa.setType(type); qa.setType(type);
qa.setIntentType(intentType); qa.setIntentType(intentType);
@ -204,7 +211,7 @@ public class ChatServiceImpl implements ChatService {
chatResVO.setType(type); chatResVO.setType(type);
chatResVO.setIntentType(intentType); chatResVO.setIntentType(intentType);
chatResVO.setConversationId(chatReqVO.getConversationId()); chatResVO.setConversationId(chatReqVO.getConversationId());
return chatResVO; return R.ok(chatResVO);
} }
@Override @Override
@ -221,18 +228,18 @@ public class ChatServiceImpl implements ChatService {
public IPage<ConversationResVo> queryUserConversationList(String userId, int page, int size) { public IPage<ConversationResVo> queryUserConversationList(String userId, int page, int size) {
Assert.notEmpty(userId, "用户id不能为空"); Assert.notEmpty(userId, "用户id不能为空");
return conversationService.queryUserConversationList(userId, DateUtil.offsetDay(DateUtil.date(), -180),null, new Page<>(page,size)); return conversationService.queryUserConversationList(userId, DateUtil.offsetDay(DateUtil.date(), -180), null, new Page<>(page, size));
} }
@Override @Override
@Transactional(rollbackFor = Exception.class, transactionManager = "dataSourceTransactionManager") @Transactional(rollbackFor = Exception.class, transactionManager = "dataSourceTransactionManager")
public void deleteConversation(List<String> conversationIdList) { public void deleteConversation(List<String> conversationIdList) {
if (CollUtil.isEmpty(conversationIdList)){ if (CollUtil.isEmpty(conversationIdList)) {
return; return;
} }
for (String conversationId : conversationIdList) { for (String conversationId : conversationIdList) {
boolean success = conversationService.removeById(conversationId); boolean success = conversationService.removeById(conversationId);
if (success){ if (success) {
conversationQaService.lambdaUpdate().eq(ConversationQa::getConversationId, conversationId).remove(); conversationQaService.lambdaUpdate().eq(ConversationQa::getConversationId, conversationId).remove();
} }
} }
@ -247,12 +254,21 @@ public class ChatServiceImpl implements ChatService {
* @param answerMap map * @param answerMap map
*/ */
private void handleIndexResultQA(List<ModelIndex> modelIndices, String query, String caseId, Map<String, Object> answerMap) { private void handleIndexResultQA(List<ModelIndex> modelIndices, String query, String caseId, Map<String, Object> answerMap) {
//如果案件分析状态不是分析成功,则先执行案件分析
ModelCase modelCase = modelCaseService.getById(caseId);
ModelIndex modelIndex = modelIndices.stream().filter(index -> query.contains(index.getName())).findFirst().get(); ModelIndex modelIndex = modelIndices.stream().filter(index -> query.contains(index.getName())).findFirst().get();
IndexResultQuery indexResultQuery = new IndexResultQuery(); IndexResultQuery indexResultQuery = new IndexResultQuery();
indexResultQuery.setCaseId(caseId); indexResultQuery.setCaseId(caseId);
indexResultQuery.setIndexType(modelIndex.getIndexType()); indexResultQuery.setIndexType(modelIndex.getIndexType());
indexResultQuery.setIndexName(modelIndex.getName()); indexResultQuery.setIndexName(modelIndex.getName());
IPage<IndexDetail> indexDetailPage = modelCaseService.getIndexDetail(indexResultQuery, 1, 1); IPage<IndexDetail> indexDetailPage = modelCaseService.getIndexDetail(indexResultQuery, 1, 1);
if (indexDetailPage.getRecords().isEmpty() || (modelCase.getTotalScore() == null && modelCase.getCaseAnalysisStatus() != CaseAnalysisStatusEnum.ANALYZED.getCode())) {
log.info("案件【{}】尚未执行模型分析,现在开始执行", modelCase.getCaseName());
AnalyseCaseDTO analyseCaseDTO = new AnalyseCaseDTO();
analyseCaseDTO.setCaseId(caseId);
modelService.analyseCaseNew(analyseCaseDTO);
}
indexDetailPage = modelCaseService.getIndexDetail(indexResultQuery, 1, 1);
if (!indexDetailPage.getRecords().isEmpty()) { if (!indexDetailPage.getRecords().isEmpty()) {
IndexDetail indexDetail = indexDetailPage.getRecords().get(0); IndexDetail indexDetail = indexDetailPage.getRecords().get(0);
answerMap.put("indexName", modelIndex.getName()); answerMap.put("indexName", modelIndex.getName());
@ -267,8 +283,9 @@ public class ChatServiceImpl implements ChatService {
qaMap.put("question", split.getQuestion()); qaMap.put("question", split.getQuestion());
qaMap.put("answer", split.getAnswer()); qaMap.put("answer", split.getAnswer());
qaMap.put("noteRecordId", split.getNoteRecordId()); qaMap.put("noteRecordId", split.getNoteRecordId());
qaMap.put("fileIds", noteRecordService.getById(split.getNoteRecordId()).getFileIds()); qaMap.put("splitId", split.getId());
qaMap.put("noteRecordName", split.getNoteName()); qaMap.put("noteName", split.getNoteName());
qaMap.put("noteFileId", split.getNoteFileId());
qaSplitList.add(qaMap); qaSplitList.add(qaMap);
}); });
} }

@ -191,12 +191,12 @@ public class ModelServiceImpl implements ModelService {
return R.fail("未找到案件信息"); return R.fail("未找到案件信息");
} }
CasePerson casePerson = casePersonMapper.selectOne(new LambdaQueryWrapper<CasePerson>() CasePerson casePerson = casePersonMapper.selectOne(new LambdaQueryWrapper<CasePerson>()
.eq(CasePerson::getCaseId, analyseCaseDTO.getCaseId()) .eq(CasePerson::getCaseId, caseId)
.eq(CasePerson::getCaseActorFlag, 1) .eq(CasePerson::getCaseActorFlag, 1)
.eq(CasePerson::getRoleCode, "1") .eq(CasePerson::getRoleCode, "1")
.eq(StrUtil.isNotEmpty(analyseCaseDTO.getLawActorName()), CasePerson::getName, analyseCaseDTO.getLawActorName())); .eq(StrUtil.isNotEmpty(modelCase.getLawActor()), CasePerson::getName, modelCase.getLawActor()));
if (ObjectUtil.isEmpty(casePerson)) { if (ObjectUtil.isEmpty(casePerson)) {
log.error("未找到的行为人:【{}】", analyseCaseDTO.getLawActorName()); log.error("未找到的行为人:【{}】", modelCase.getLawActor());
return R.fail("未找到的行为人"); return R.fail("未找到的行为人");
} }
List<ModelIndex> modelIndices = modelIndexService.list(new LambdaQueryWrapper<ModelIndex>().eq(ModelIndex::getDataStatus, "1").eq(ModelIndex::getCaseType, modelCase.getCaseType())); List<ModelIndex> modelIndices = modelIndexService.list(new LambdaQueryWrapper<ModelIndex>().eq(ModelIndex::getDataStatus, "1").eq(ModelIndex::getCaseType, modelCase.getCaseType()));
@ -258,7 +258,7 @@ public class ModelServiceImpl implements ModelService {
ModelAtomicResult result = new ModelAtomicResult(); ModelAtomicResult result = new ModelAtomicResult();
result.setIndexId(modelIndex.getId()); result.setIndexId(modelIndex.getId());
result.setCasePersonId(casePerson.getId()); result.setCasePersonId(casePerson.getId());
result.setCaseId(analyseCaseDTO.getCaseId()); result.setCaseId(caseId);
result.setAtomicId(ruleCondition.getAtomicIndexId()); result.setAtomicId(ruleCondition.getAtomicIndexId());
result.setAtomicResult(JudgeResultEnum.NOT_EXIST.getCode()); result.setAtomicResult(JudgeResultEnum.NOT_EXIST.getCode());
ModelAtomicResult exist = modelAtomicResultMapper.selectByCaseIdAndAtomicId(caseId, casePerson.getId(), modelIndex.getId(), ruleCondition.getAtomicIndexId()); ModelAtomicResult exist = modelAtomicResultMapper.selectByCaseIdAndAtomicId(caseId, casePerson.getId(), modelIndex.getId(), ruleCondition.getAtomicIndexId());
@ -273,7 +273,7 @@ public class ModelServiceImpl implements ModelService {
operandUnitResultSet.add(relationSymbol == dbIndexAnalysis(caseId, modelAtomicIndex, evidenceDirectories, result)); operandUnitResultSet.add(relationSymbol == dbIndexAnalysis(caseId, modelAtomicIndex, evidenceDirectories, result));
break; break;
case OPERAND_TYPE_GRAPH: case OPERAND_TYPE_GRAPH:
operandUnitResultSet.add(relationSymbol == graphIndexAnalysis(casePerson.getName(), modelAtomicIndex.getQueryLang(), analyseCaseDTO.getCaseId(), ruleCondition, result)); operandUnitResultSet.add(relationSymbol == graphIndexAnalysis(casePerson.getName(), modelAtomicIndex.getQueryLang(), caseId, ruleCondition, result));
break; break;
case OPERAND_TYPE_STRUCTURE: case OPERAND_TYPE_STRUCTURE:
if (ruleCondition.getOperandUnitList().isEmpty()) { if (ruleCondition.getOperandUnitList().isEmpty()) {
@ -300,7 +300,7 @@ public class ModelServiceImpl implements ModelService {
modelIndexResult.setCaseId(caseId); modelIndexResult.setCaseId(caseId);
modelIndexResult.setIndexId(modelIndex.getId()); modelIndexResult.setIndexId(modelIndex.getId());
modelIndexResult.setAtomicIds(modelIndexAtomicRelations.stream().filter(relation -> relation.getModelIndexId().equals(modelIndex.getId())).map(ModelIndexAtomicRelation::getAtomicIndexId).collect(Collectors.joining(","))); modelIndexResult.setAtomicIds(modelIndexAtomicRelations.stream().filter(relation -> relation.getModelIndexId().equals(modelIndex.getId())).map(ModelIndexAtomicRelation::getAtomicIndexId).collect(Collectors.joining(",")));
ModelIndexResult exist = modelIndexResultMapper.selectByCaseIdAndIndexId(analyseCaseDTO.getCaseId(), modelIndex.getId()); ModelIndexResult exist = modelIndexResultMapper.selectByCaseIdAndIndexId(caseId, modelIndex.getId());
if (exist != null) { if (exist != null) {
modelIndexResult.setId(exist.getId()); modelIndexResult.setId(exist.getId());
} }
@ -327,7 +327,7 @@ public class ModelServiceImpl implements ModelService {
int max = Integer.max(gx + rz, gx + cz); int max = Integer.max(gx + rz, gx + cz);
modelCase.setTotalScore(max); modelCase.setTotalScore(max);
log.info("更新案件得分情况。最终得分:{}分(共性+入罪/共性+出罪 取最大值)。入罪:{}分。出罪:{}分。共性:{}分。", max, rz, cz, gx); log.info("更新案件得分情况。最终得分:{}分(共性+入罪/共性+出罪 取最大值)。入罪:{}分。出罪:{}分。共性:{}分。", max, rz, cz, gx);
caseStatusManageService.whenAnalyseCaseSuccess(analyseCaseDTO.getCaseId(), modelCase.getTotalScore()); caseStatusManageService.whenAnalyseCaseSuccess(caseId, modelCase.getTotalScore());
difyApiUtil.syncCaseFileToDifyKnowledgeBase(modelCase, modelCaseService.listCaseFileIds(caseId)); difyApiUtil.syncCaseFileToDifyKnowledgeBase(modelCase, modelCaseService.listCaseFileIds(caseId));
return R.ok(); return R.ok();
} }

@ -79,13 +79,13 @@ public class NoteRecordSplitServiceImpl extends ServiceImpl<NoteRecordSplitMappe
@Override @Override
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class) @Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
public String uploadRecords(NoteRecordReqVO records) throws IOException { public String uploadRecords(NoteRecordReqVO records) {
return uploadRecords(records, false); return uploadRecords(records, false);
} }
@Override @Override
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class) @Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
public String uploadRecords(NoteRecordReqVO records, boolean extractFlag) throws IOException { public String uploadRecords(NoteRecordReqVO records, boolean extractFlag) {
ModelCase modelCase = modelCaseService.getById(records.getCaseId()); ModelCase modelCase = modelCaseService.getById(records.getCaseId());
Assert.notEmpty(modelCase.getCaseNo(), "案件编号不能为空"); Assert.notEmpty(modelCase.getCaseNo(), "案件编号不能为空");
@ -246,10 +246,11 @@ public class NoteRecordSplitServiceImpl extends ServiceImpl<NoteRecordSplitMappe
} }
@Override @Override
public NoteRecordSplit saveRecordSplit(NoteRecord record, String fileName, String question, String answer) { public NoteRecordSplit saveRecordSplit(NoteRecord record, String fileId, String fileName, String question, String answer) {
NoteRecordSplit noteRecord = new NoteRecordSplit(); NoteRecordSplit noteRecord = new NoteRecordSplit();
noteRecord.setCaseId(record.getCaseId()); noteRecord.setCaseId(record.getCaseId());
noteRecord.setNoteRecordId(record.getId()); noteRecord.setNoteRecordId(record.getId());
noteRecord.setNoteFileId(fileId);
noteRecord.setNoteName(fileName); noteRecord.setNoteName(fileName);
noteRecord.setPersonName(record.getName()); noteRecord.setPersonName(record.getName());
noteRecord.setQuestion(question); noteRecord.setQuestion(question);
@ -276,7 +277,7 @@ public class NoteRecordSplitServiceImpl extends ServiceImpl<NoteRecordSplitMappe
List<NoteRecordSplit> splitList = new ArrayList<>(); List<NoteRecordSplit> splitList = new ArrayList<>();
for (QARecordNodeDTO qa : qaList) { for (QARecordNodeDTO qa : qaList) {
splitList.add( splitList.add(
saveRecordSplit(record, minioFile.getFilename(), qa.getQuestion(), qa.getAnswer()) saveRecordSplit(record, fileId, minioFile.getFilename(), qa.getQuestion(), qa.getAnswer())
); );
} }
return splitList; return splitList;

@ -16,7 +16,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
@ -35,6 +38,7 @@ public class OCRRecordServiceImpl implements OCRRecordService {
private final ModelRecordTypeService modelRecordTypeService; private final ModelRecordTypeService modelRecordTypeService;
private final CasePersonService casePersonService; private final CasePersonService casePersonService;
@Override @Override
public String saveRecord(NoteRecordReqVO noteRecordReqVO) { public String saveRecord(NoteRecordReqVO noteRecordReqVO) {
@ -42,7 +46,7 @@ public class OCRRecordServiceImpl implements OCRRecordService {
NoteRecord record = noteRecordReqVO.toNoteRecord(); NoteRecord record = noteRecordReqVO.toNoteRecord();
String recordId = noteRecordService.saveOrUpdRecord(record); String recordId = noteRecordService.saveOrUpdRecord(record);
if (CollUtil.isEmpty(noteRecordReqVO.getFileIdList())){ if (CollUtil.isEmpty(noteRecordReqVO.getFileIdList())) {
log.info("uploadRecords:文件内容为空...不进行笔录分析操作..."); log.info("uploadRecords:文件内容为空...不进行笔录分析操作...");
return recordId; return recordId;
} }
@ -56,7 +60,7 @@ public class OCRRecordServiceImpl implements OCRRecordService {
NoteRecord noteRecord = new NoteRecord(); NoteRecord noteRecord = new NoteRecord();
noteRecord.setId(recordId); noteRecord.setId(recordId);
List<NoteRecordDTO> noteRecordDTOS = noteRecordService.selectNoteRecordDTOList(noteRecord); List<NoteRecordDTO> noteRecordDTOS = noteRecordService.selectNoteRecordDTOList(noteRecord);
if (CollUtil.isEmpty(noteRecordDTOS)){ if (CollUtil.isEmpty(noteRecordDTOS)) {
return new NoteRecordDTO(); return new NoteRecordDTO();
} }
return CollUtil.getFirst(noteRecordDTOS); return CollUtil.getFirst(noteRecordDTOS);
@ -68,17 +72,17 @@ public class OCRRecordServiceImpl implements OCRRecordService {
NoteRecord noteRecord = noteRecordService.getById(recordId); NoteRecord noteRecord = noteRecordService.getById(recordId);
Assert.notNull(noteRecord, "笔录不存在,可能已经被删除!"); Assert.notNull(noteRecord, "笔录不存在,可能已经被删除!");
String fileIds = noteRecord.getFileIds(); String fileIds = noteRecord.getFileIds();
if (StrUtil.isEmpty(fileIds)){ if (StrUtil.isEmpty(fileIds)) {
log.info("queryFileList:笔录:{}对应的fileIds为空...",recordId); log.info("queryFileList:笔录:{}对应的fileIds为空...", recordId);
return CollUtil.newArrayList(); return CollUtil.newArrayList();
} }
List<String> fileIdList = Arrays.stream(fileIds.split(",")).toList(); List<String> fileIdList = Arrays.stream(fileIds.split(",")).toList();
List<RecordFileDTO> recordFileDTOS = fileOcrProcessService.queryFileListWithIdSort(fileIdList); List<RecordFileDTO> recordFileDTOS = fileOcrProcessService.queryFileListWithIdSort(fileIdList);
recordFileDTOS.forEach(record->{ recordFileDTOS.forEach(record -> {
record.formatFileSize(); record.formatFileSize();
record.setDefaultEvidenceTypeDesc(); record.setDefaultEvidenceTypeDesc();
if (StrUtil.isEmpty(record.getReviseText())){ if (StrUtil.isEmpty(record.getReviseText())) {
record.setReviseText(record.getOcrText()); record.setReviseText(record.getOcrText());
} }
}); });
@ -87,7 +91,7 @@ public class OCRRecordServiceImpl implements OCRRecordService {
} }
@Override @Override
public Boolean reviseOcrText(String id,String reviseText) { public Boolean reviseOcrText(String id, String reviseText) {
Assert.notEmpty(id, "id不能为空"); Assert.notEmpty(id, "id不能为空");
@ -98,7 +102,7 @@ public class OCRRecordServiceImpl implements OCRRecordService {
@Override @Override
public Boolean reviseOcrText(List<OCRTextDTO> ocrTextDTOList) { public Boolean reviseOcrText(List<OCRTextDTO> ocrTextDTOList) {
if (CollUtil.isEmpty(ocrTextDTOList)){ if (CollUtil.isEmpty(ocrTextDTOList)) {
return false; return false;
} }
ocrTextDTOList.forEach(ocrTextDTO -> this.reviseOcrText(ocrTextDTO.getOcrId(), ocrTextDTO.getReviseText())); ocrTextDTOList.forEach(ocrTextDTO -> this.reviseOcrText(ocrTextDTO.getOcrId(), ocrTextDTO.getReviseText()));
@ -119,8 +123,8 @@ public class OCRRecordServiceImpl implements OCRRecordService {
public Boolean submitRecordTask(String recordId) { public Boolean submitRecordTask(String recordId) {
Assert.notEmpty(recordId, "recordId不能为空"); Assert.notEmpty(recordId, "recordId不能为空");
NoteRecord noteRecord = noteRecordService.getById(recordId); NoteRecord noteRecord = noteRecordService.getById(recordId);
if (Objects.isNull(noteRecord) || StrUtil.isEmpty(noteRecord.getFileIds())){ if (Objects.isNull(noteRecord) || StrUtil.isEmpty(noteRecord.getFileIds())) {
log.info("submitRecordTask:笔录:{}对应的笔录文件为空...",recordId); log.info("submitRecordTask:笔录:{}对应的笔录文件为空...", recordId);
return false; return false;
} }
@ -131,14 +135,14 @@ public class OCRRecordServiceImpl implements OCRRecordService {
List<RecordFileDTO> recordFileDTOS = fileOcrProcessService.queryFileList(fileIdList); List<RecordFileDTO> recordFileDTOS = fileOcrProcessService.queryFileList(fileIdList);
recordFileDTOS = recordFileDTOS.stream() recordFileDTOS = recordFileDTOS.stream()
.filter(file->StrUtil.isAllNotEmpty(file.getOcrText(),file.getReviseText())).toList(); .filter(file -> StrUtil.isAllNotEmpty(file.getOcrText(), file.getReviseText())).toList();
if (CollUtil.isEmpty(recordFileDTOS)){ if (CollUtil.isEmpty(recordFileDTOS)) {
log.info("submitRecordTask:笔录:{}对应的笔录文件为空...",recordId); log.info("submitRecordTask:笔录:{}对应的笔录文件为空...", recordId);
return false; return false;
} }
if (StrUtil.isNotEmpty(noteRecord.getCasePersonId())){ if (StrUtil.isNotEmpty(noteRecord.getCasePersonId())) {
CasePerson casePerson = casePersonService.getById(noteRecord.getCasePersonId()); CasePerson casePerson = casePersonService.getById(noteRecord.getCasePersonId());
if (Objects.nonNull(casePerson)){ if (Objects.nonNull(casePerson)) {
noteRecord.setName(casePerson.getName()); noteRecord.setName(casePerson.getName());
} }
} }
@ -158,7 +162,7 @@ public class OCRRecordServiceImpl implements OCRRecordService {
public Boolean deleteFile(String recordId, String fileId) { public Boolean deleteFile(String recordId, String fileId) {
Assert.notEmpty(recordId, "recordId不能为空"); Assert.notEmpty(recordId, "recordId不能为空");
if (StrUtil.isEmpty(fileId)){ if (StrUtil.isEmpty(fileId)) {
return false; return false;
} }
@ -166,7 +170,7 @@ public class OCRRecordServiceImpl implements OCRRecordService {
Assert.notNull(noteRecord, "recordId:{}对应的笔录信息不存在", recordId); Assert.notNull(noteRecord, "recordId:{}对应的笔录信息不存在", recordId);
String fileIds = noteRecord.getFileIds(); String fileIds = noteRecord.getFileIds();
if (StrUtil.isEmpty(fileIds)){ if (StrUtil.isEmpty(fileIds)) {
return true; return true;
} }
@ -185,12 +189,12 @@ public class OCRRecordServiceImpl implements OCRRecordService {
List<QARecordNodeDTO> qaList = RecordRegexUtil.recordRegex( List<QARecordNodeDTO> qaList = RecordRegexUtil.recordRegex(
StrUtil.isEmpty(reviseText) ? ocrText : reviseText, noteRecord.getName()); StrUtil.isEmpty(reviseText) ? ocrText : reviseText, noteRecord.getName());
log.info("文件:{}拆分问答对:{}",recordFileDTO.getFileName(), qaList.size()); log.info("文件:{}拆分问答对:{}", recordFileDTO.getFileName(), qaList.size());
List<NoteRecordSplit> splitList = new ArrayList<>(); List<NoteRecordSplit> splitList = new ArrayList<>();
for (QARecordNodeDTO qa : qaList) { for (QARecordNodeDTO qa : qaList) {
splitList.add( splitList.add(
noteRecordSplitService.saveRecordSplit(noteRecord, noteRecordSplitService.saveRecordSplit(noteRecord, recordFileDTO.getFileId(),
recordFileDTO.getFileName(), qa.getQuestion(), qa.getAnswer()) recordFileDTO.getFileName(), qa.getQuestion(), qa.getAnswer())
); );
} }

@ -29,7 +29,7 @@ public class ChatResVO {
private String type; private String type;
private String intentType; private String intentType;
private List<String> docs; private List<String> docs;
private List<KnowledgeBaseSegmentVO> segmentVOList = new ArrayList<>(); private List<KnowledgeBaseSegmentVO> segmentList = new ArrayList<>();
public ChatResVO() { public ChatResVO() {
} }
@ -52,6 +52,7 @@ public class ChatResVO {
if (StrUtil.isNotEmpty(conversationQa.getAnswerMap())){ if (StrUtil.isNotEmpty(conversationQa.getAnswerMap())){
this.answwerMap = JSONUtil.toBean(conversationQa.getAnswerMap(), Map.class); this.answwerMap = JSONUtil.toBean(conversationQa.getAnswerMap(), Map.class);
} }
this.setSegmentList(conversationQa.getSegmentList());
this.setType(conversationQa.getType()); this.setType(conversationQa.getType());
this.setQuestionTime(conversationQa.getQuestionTime()); this.setQuestionTime(conversationQa.getQuestionTime());
this.setIntentType(conversationQa.getIntentType()); this.setIntentType(conversationQa.getIntentType());

@ -1,13 +1,25 @@
package com.supervision.demo; package com.supervision.demo;
import com.supervision.demo.dto.QARecordNodeDTO; import com.supervision.demo.dto.QARecordNodeDTO;
import com.supervision.minio.domain.MinioFile;
import com.supervision.minio.service.MinioService;
import com.supervision.police.domain.NoteRecord;
import com.supervision.police.service.NoteRecordService;
import com.supervision.police.service.NoteRecordSplitService;
import com.supervision.utils.RecordRegexUtil; import com.supervision.utils.RecordRegexUtil;
import com.supervision.utils.WordReadUtil; import com.supervision.utils.WordReadUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.List; import java.util.List;
@SpringBootTest
@Slf4j
public class RecordSplitTest { public class RecordSplitTest {
public static void main(String[] args) throws FileNotFoundException { public static void main(String[] args) throws FileNotFoundException {
@ -27,4 +39,26 @@ public class RecordSplitTest {
System.out.println(qaRecordNodeDTO.getAnswer()); System.out.println(qaRecordNodeDTO.getAnswer());
} }
} }
@Autowired
private NoteRecordSplitService noteRecordSplitService;
@Autowired
private NoteRecordService noteRecordService;
@Autowired
private MinioService minioService;
@Test
public void test() {
noteRecordSplitService.list().forEach(split -> {
NoteRecord noteRecord = noteRecordService.getById(split.getNoteRecordId());
List<MinioFile> minioFiles = minioService.listMinioFile(Arrays.stream(noteRecord.getFileIds().split(",")).toList());
minioFiles.forEach(minioFile -> {
if (minioFile.getFilename().equals(split.getNoteName())) {
split.setNoteFileId(minioFile.getId());
noteRecordSplitService.updateById(split);
log.info("问答对【{}】fileId已更新", split.getId());
}
});
});
}
} }

Loading…
Cancel
Save