|
|
|
@ -51,12 +51,17 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
|
|
|
|
|
|
|
|
|
|
private final OllamaChatClient chatClient;
|
|
|
|
|
|
|
|
|
|
private final CaseTaskRecordService caseTaskRecordService;
|
|
|
|
|
|
|
|
|
|
private final NotePromptTypeRelService notePromptTypeRelService;
|
|
|
|
|
|
|
|
|
|
private final CaseTaskRecordService caseTaskRecordService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private NoteRecordSplitService noteRecordSplitService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ExtractTripleInfoService extractTripleInfo;
|
|
|
|
|
private RecordSplitProcessService recordSplitProcessService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ModelRecordTypeService modelRecordTypeService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TypeDTO> queryTypeListChoose() {
|
|
|
|
@ -154,7 +159,7 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
|
|
|
|
|
boolean save;
|
|
|
|
|
if (StringUtils.isEmpty(prompt.getId())) {
|
|
|
|
|
// 新增的时候,校验是否已经存在相同的三元组关系,如果已经存在了相同的三元组关系,不允许添加
|
|
|
|
|
checkHasSameTriple(prompt.getStartEntityType(), prompt.getRelType(),prompt.getEndEntityType(),null);
|
|
|
|
|
checkHasSameTriple(prompt.getStartEntityType(), prompt.getRelType(), prompt.getEndEntityType(), null);
|
|
|
|
|
save = notePromptService.save(prompt);
|
|
|
|
|
// 新增prompt绑定的分类信息
|
|
|
|
|
for (String typeId : typeList) {
|
|
|
|
@ -164,7 +169,7 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
|
|
|
|
|
notePromptTypeRelService.save(rel);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
checkHasSameTriple(prompt.getStartEntityType(), prompt.getRelType(),prompt.getEndEntityType(),prompt.getId());
|
|
|
|
|
checkHasSameTriple(prompt.getStartEntityType(), prompt.getRelType(), prompt.getEndEntityType(), prompt.getId());
|
|
|
|
|
save = notePromptService.updateById(prompt);
|
|
|
|
|
// 更新prompt绑定的分类信息
|
|
|
|
|
// 首先查询已经有的,如果都存在,就不变,如果数据库有,前端没有,就删除,如果前端有,数据库没有,就新增
|
|
|
|
@ -222,15 +227,15 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkHasSameTriple(String startEntityType, String relType, String endEntityType,String promptId) {
|
|
|
|
|
private void checkHasSameTriple(String startEntityType, String relType, String endEntityType, String promptId) {
|
|
|
|
|
List<NotePrompt> list = notePromptService.lambdaQuery().eq(NotePrompt::getStartEntityType, startEntityType)
|
|
|
|
|
.eq(NotePrompt::getRelType, relType).eq(NotePrompt::getEndEntityType, endEntityType).list();
|
|
|
|
|
if (CollUtil.isNotEmpty(list) ) {
|
|
|
|
|
if (StrUtil.isBlank(promptId)){
|
|
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
if (StrUtil.isBlank(promptId)) {
|
|
|
|
|
throw new RuntimeException("该三元组关系已经存在,请勿重复添加");
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
// 校验list查出来的是不是和promptId相等,如果不想等,也报错
|
|
|
|
|
if (!list.get(0).getId().equals(promptId)){
|
|
|
|
|
if (!list.get(0).getId().equals(promptId)) {
|
|
|
|
|
throw new RuntimeException("该三元组关系已经存在,请勿重复添加");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -252,70 +257,39 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 异步提交的任务,不回滚
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class, noRollbackFor = BusinessException.class)
|
|
|
|
|
public List<TripleInfo> getThreeInfo(String caseId, String name, String recordId) {
|
|
|
|
|
if (StrUtil.isBlank(recordId)) {
|
|
|
|
|
throw new RuntimeException("笔录ID不能为空");
|
|
|
|
|
}
|
|
|
|
|
boolean taskStatus = taskExtractStatusCheck(caseId, recordId);
|
|
|
|
|
// 如果校验结果为false,则说明需要进行提取三元组操作
|
|
|
|
|
if (!taskStatus) {
|
|
|
|
|
extractTripleInfo.extractTripleInfo(caseId, name, recordId);
|
|
|
|
|
}
|
|
|
|
|
// 这里进行查询
|
|
|
|
|
return tripleInfoService.lambdaQuery().eq(TripleInfo::getRecordId, recordId).list();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提取任务校验,校验是否已经存在相关的人物,如果存在相关的任务,就不再继续执行了,直接告诉任务正在执行中
|
|
|
|
|
*/
|
|
|
|
|
private boolean taskExtractStatusCheck(String caseId, String recordId) {
|
|
|
|
|
// 首先查询是否存在任务,如果不存在,就新建
|
|
|
|
|
Optional<CaseTaskRecord> caseTaskRecordOpt = caseTaskRecordService.lambdaQuery()
|
|
|
|
|
.eq(CaseTaskRecord::getType, 2).eq(CaseTaskRecord::getCaseId, caseId).eq(CaseTaskRecord::getRecordId, recordId).oneOpt();
|
|
|
|
|
if (caseTaskRecordOpt.isEmpty()) {
|
|
|
|
|
CaseTaskRecord newCaseTaskRecord = new CaseTaskRecord();
|
|
|
|
|
newCaseTaskRecord.setType(2);
|
|
|
|
|
newCaseTaskRecord.setCaseId(caseId);
|
|
|
|
|
newCaseTaskRecord.setRecordId(recordId);
|
|
|
|
|
newCaseTaskRecord.setStatus(1);
|
|
|
|
|
newCaseTaskRecord.setSubmitTime(LocalDateTime.now());
|
|
|
|
|
caseTaskRecordService.save(newCaseTaskRecord);
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// 如果存在,则校验时间是否已经超过1天,如果超过了1天还没有执行完毕,就重新提交这个任务
|
|
|
|
|
// 这里查询任务是否完成,如果完成了,就给结果
|
|
|
|
|
Optional<CaseTaskRecord> caseTaskRecordOpt = caseTaskRecordService.lambdaQuery().eq(CaseTaskRecord::getCaseId, caseId)
|
|
|
|
|
.eq(CaseTaskRecord::getRecordId, recordId).oneOpt();
|
|
|
|
|
if (caseTaskRecordOpt.isPresent()) {
|
|
|
|
|
CaseTaskRecord caseTaskRecord = caseTaskRecordOpt.get();
|
|
|
|
|
// 如果未执行,则提交执行
|
|
|
|
|
if (caseTaskRecordOpt.get().getStatus() == 0) {
|
|
|
|
|
caseTaskRecord.setStatus(1);
|
|
|
|
|
caseTaskRecord.setSubmitTime(LocalDateTime.now());
|
|
|
|
|
caseTaskRecordService.updateById(caseTaskRecord);
|
|
|
|
|
return false;
|
|
|
|
|
// 0未执行 1正在执行 2执行成功 3执行超时
|
|
|
|
|
if (caseTaskRecord.getStatus() == 1) {
|
|
|
|
|
throw new BusinessException("笔录解析任务未完成,请等待");
|
|
|
|
|
}
|
|
|
|
|
if (caseTaskRecordOpt.get().getStatus() == 1 && LocalDateTime.now().isAfter(caseTaskRecord.getSubmitTime().plusDays(1))) {
|
|
|
|
|
// 如果已经超过1天,则重新提交任务
|
|
|
|
|
caseTaskRecord.setStatus(1);
|
|
|
|
|
caseTaskRecord.setSubmitTime(LocalDateTime.now());
|
|
|
|
|
caseTaskRecordService.updateById(caseTaskRecord);
|
|
|
|
|
return false;
|
|
|
|
|
} else if (caseTaskRecordOpt.get().getStatus() == 2) {
|
|
|
|
|
// 如果执行成功,就返回true,取反之后就可以返回三元组信息了
|
|
|
|
|
return true;
|
|
|
|
|
} else if (caseTaskRecordOpt.get().getStatus() == 3) {
|
|
|
|
|
caseTaskRecord.setStatus(1);
|
|
|
|
|
caseTaskRecord.setSubmitTime(LocalDateTime.now());
|
|
|
|
|
caseTaskRecordService.updateById(caseTaskRecord);
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
// 如果没有超过1天,则返回正在执行中
|
|
|
|
|
throw new BusinessException("笔录拆分及三元组提取任务正在执行中,请稍后");
|
|
|
|
|
|
|
|
|
|
if (caseTaskRecord.getStatus() == 0 || caseTaskRecord.getStatus() == 3) {
|
|
|
|
|
// 重新提交
|
|
|
|
|
List<ModelRecordType> allTypeList = modelRecordTypeService.lambdaQuery().list();
|
|
|
|
|
// 根据recordId查询所有的分割后的笔录
|
|
|
|
|
List<NoteRecordSplit> list = noteRecordSplitService.lambdaQuery().eq(NoteRecordSplit::getNoteRecordId, recordId).list();
|
|
|
|
|
recordSplitProcessService.process(allTypeList, list);
|
|
|
|
|
// 更新为1执行中
|
|
|
|
|
throw new BusinessException("笔录解析任务未完成,请等待");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 这里进行查询
|
|
|
|
|
return tripleInfoService.lambdaQuery().eq(TripleInfo::getRecordId, recordId).list();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void testExtractThreeInfo() {
|
|
|
|
|
// -------------------------
|
|
|
|
@ -428,7 +402,7 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String addNeo4j(List<String> ids) {
|
|
|
|
|
if (CollUtil.isEmpty(ids)){
|
|
|
|
|
if (CollUtil.isEmpty(ids)) {
|
|
|
|
|
return "成功插入0条信息";
|
|
|
|
|
}
|
|
|
|
|
List<TripleInfo> tripleInfos = tripleInfoService.listByIds(ids);
|
|
|
|
|