|
|
|
@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.StopWatch;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
@ -70,14 +71,14 @@ public class TaskRecordServiceImpl extends ServiceImpl<TaskRecordMapper, TaskRec
|
|
|
|
|
taskRecord.setName(this.generateTaskName(taskRecord.getType()));
|
|
|
|
|
super.save(taskRecord);
|
|
|
|
|
try {
|
|
|
|
|
NotePrompt prompt = notePromptService.getById(taskRecordVo.getPromptId());
|
|
|
|
|
List<ModelCase> modelCases = this.getModelCases(taskRecordVo, taskRecord);
|
|
|
|
|
NotePrompt prompt = notePromptService.getById(taskRecord.getPromptId());
|
|
|
|
|
List<ModelCase> modelCases = this.getModelCases(taskRecord);
|
|
|
|
|
if (!CollUtil.isEmpty(modelCases)) {
|
|
|
|
|
for (ModelCase modelCase : modelCases) {
|
|
|
|
|
String caseId = modelCase.getId();
|
|
|
|
|
List<String> ids = this.getIds(taskRecordVo, taskRecord, prompt, caseId);
|
|
|
|
|
List<String> ids = this.getIds(taskRecord, caseId, prompt.getType());
|
|
|
|
|
if (!ids.isEmpty()) {
|
|
|
|
|
this.invokeXxlJob(taskRecordVo, taskRecord, caseId, ids);
|
|
|
|
|
this.invokeXxlJob(taskRecord, prompt.getId(), caseId, ids);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("案件【{}】没有笔录", caseId);
|
|
|
|
|
}
|
|
|
|
@ -92,6 +93,48 @@ public class TaskRecordServiceImpl extends ServiceImpl<TaskRecordMapper, TaskRec
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void executeAllPromptExtractTask() {
|
|
|
|
|
//查出所有图谱推理和结构化推理的提示词
|
|
|
|
|
log.info("开始触发一键提取任务");
|
|
|
|
|
StopWatch stopWatch = new StopWatch("One-click extraction stopwatch");
|
|
|
|
|
stopWatch.start();
|
|
|
|
|
TaskRecord taskRecord = new TaskRecord();
|
|
|
|
|
taskRecord.setType(TASK_TYPE_ONE_CLICK);
|
|
|
|
|
taskRecord.setName(this.generateTaskName(taskRecord.getType()));
|
|
|
|
|
super.save(taskRecord);
|
|
|
|
|
notePromptService.list(new LambdaQueryWrapper<NotePrompt>().eq(NotePrompt::getType, TYPE_GRAPH_REASONING).or().eq(NotePrompt::getType, TYPE_STRUCTURAL_REASONING)).forEach(notePrompt -> {
|
|
|
|
|
try {
|
|
|
|
|
NotePrompt prompt = notePromptService.getById(notePrompt.getId());
|
|
|
|
|
List<ModelCase> modelCases = this.getModelCases(taskRecord);
|
|
|
|
|
if (!CollUtil.isEmpty(modelCases)) {
|
|
|
|
|
//异步调用xxl-job执行任务
|
|
|
|
|
Thread thread = new Thread(() -> {
|
|
|
|
|
for (ModelCase modelCase : modelCases) {
|
|
|
|
|
String caseId = modelCase.getId();
|
|
|
|
|
List<String> ids = this.getIds(taskRecord, caseId, prompt.getType());
|
|
|
|
|
if (!ids.isEmpty()) {
|
|
|
|
|
taskRecord.setPromptId(prompt.getId());
|
|
|
|
|
this.invokeXxlJob(taskRecord, prompt.getId(), caseId, ids);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("案件【{}】没有笔录或证据", caseId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
thread.start();
|
|
|
|
|
} else {
|
|
|
|
|
log.info("查无案件");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
taskRecord.setStatus(TASK_STATUS_FAIL);
|
|
|
|
|
super.updateById(taskRecord);
|
|
|
|
|
log.error("任务执行失败", e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
stopWatch.stop();
|
|
|
|
|
log.info("一键提取任务触发完成。耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void graphExtract(NotePrompt prompt, String caseId, String executeId) {
|
|
|
|
|
List<TripleInfo> tripleInfos = extractTripleInfoService.extractTripleInfo(prompt, caseId, executeId);
|
|
|
|
@ -113,25 +156,24 @@ public class TaskRecordServiceImpl extends ServiceImpl<TaskRecordMapper, TaskRec
|
|
|
|
|
/**
|
|
|
|
|
* 根据任务类型获取笔录或证据ID
|
|
|
|
|
*
|
|
|
|
|
* @param taskRecordVo 任务记录
|
|
|
|
|
* @param taskRecord 任务
|
|
|
|
|
* @param prompt 提示词
|
|
|
|
|
* @param caseId 案件ID
|
|
|
|
|
* @param taskRecord 任务
|
|
|
|
|
* @param caseId 案件ID
|
|
|
|
|
* @param promptType 提示词类型
|
|
|
|
|
* @return 笔录或证据ID
|
|
|
|
|
*/
|
|
|
|
|
private @NotNull List<String> getIds(TaskRecordVo taskRecordVo, TaskRecord taskRecord, NotePrompt prompt, String caseId) {
|
|
|
|
|
private @NotNull List<String> getIds(TaskRecord taskRecord, String caseId, String promptType) {
|
|
|
|
|
//查出当前案件相关笔录或证据
|
|
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
|
|
//如果类型为指定笔录或证据,直接取传入的id
|
|
|
|
|
if (TASK_TYPE_SPECIFIED_RECORD.equals(taskRecord.getType())) {
|
|
|
|
|
ids = List.of(taskRecordVo.getRecordId().split(","));
|
|
|
|
|
ids = List.of(taskRecord.getRecordId().split(","));
|
|
|
|
|
} else if (TASK_TYPE_SPECIFIED_EVIDENCE.equals(taskRecord.getType())) {
|
|
|
|
|
ids = List.of(taskRecordVo.getEvidenceId().split(","));
|
|
|
|
|
ids = List.of(taskRecord.getEvidenceId().split(","));
|
|
|
|
|
} else {
|
|
|
|
|
//如果是案件维度,根据案件ID查找笔录或证据
|
|
|
|
|
if (TYPE_GRAPH_REASONING.equals(prompt.getType())) {
|
|
|
|
|
if (TYPE_GRAPH_REASONING.equals(promptType)) {
|
|
|
|
|
ids = noteRecordService.lambdaQuery().eq(NoteRecord::getCaseId, caseId).eq(NoteRecord::getDataStatus, DataStatus.AVAILABLE.getCode()).list().stream().map(NoteRecord::getId).toList();
|
|
|
|
|
} else if (TYPE_STRUCTURAL_REASONING.equals(prompt.getType())) {
|
|
|
|
|
} else if (TYPE_STRUCTURAL_REASONING.equals(promptType)) {
|
|
|
|
|
ids = caseEvidenceService.lambdaQuery().eq(CaseEvidence::getCaseId, caseId).list().stream().map(CaseEvidence::getId).toList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -141,15 +183,15 @@ public class TaskRecordServiceImpl extends ServiceImpl<TaskRecordMapper, TaskRec
|
|
|
|
|
/**
|
|
|
|
|
* 调用xxl-job执行任务
|
|
|
|
|
*
|
|
|
|
|
* @param taskRecordVo 任务记录
|
|
|
|
|
* @param taskRecord 任务
|
|
|
|
|
* @param caseId 案件ID
|
|
|
|
|
* @param ids 笔录或证据ID
|
|
|
|
|
* @param taskRecord 任务
|
|
|
|
|
* @param caseId 案件ID
|
|
|
|
|
* @param ids 笔录或证据ID
|
|
|
|
|
*/
|
|
|
|
|
private void invokeXxlJob(TaskRecordVo taskRecordVo, TaskRecord taskRecord, String caseId, List<String> ids) {
|
|
|
|
|
private void invokeXxlJob(TaskRecord taskRecord, String promptId, String caseId, List<String> ids) {
|
|
|
|
|
TaskCaseRecord taskCaseRecord = new TaskCaseRecord();
|
|
|
|
|
taskCaseRecord.setTaskRecordId(taskRecord.getId());
|
|
|
|
|
taskCaseRecord.setCaseId(caseId);
|
|
|
|
|
taskCaseRecord.setPromptId(promptId);
|
|
|
|
|
taskCaseRecord.setWaitingId(ids.stream().reduce((a, b) -> a + "," + b).orElse(""));
|
|
|
|
|
taskCaseRecord.setStatus(TASK_STATUS_WAITING);
|
|
|
|
|
taskCaseRecordService.save(taskCaseRecord);
|
|
|
|
@ -158,7 +200,7 @@ public class TaskRecordServiceImpl extends ServiceImpl<TaskRecordMapper, TaskRec
|
|
|
|
|
params.put("taskId", taskRecord.getId());
|
|
|
|
|
params.put("caseId", caseId);
|
|
|
|
|
params.put("executeId", id);
|
|
|
|
|
params.put("promptId", taskRecordVo.getPromptId());
|
|
|
|
|
params.put("promptId", taskRecord.getPromptId());
|
|
|
|
|
//map转String作为参数
|
|
|
|
|
xxlJobService.executeTaskByJobHandler(TASK_NAME_PROMPT_EXTRACT_TASK, new JSONObject(params).toString());
|
|
|
|
|
}
|
|
|
|
@ -167,17 +209,16 @@ public class TaskRecordServiceImpl extends ServiceImpl<TaskRecordMapper, TaskRec
|
|
|
|
|
/**
|
|
|
|
|
* 根据任务类型查找案件
|
|
|
|
|
*
|
|
|
|
|
* @param taskRecordVo 任务记录
|
|
|
|
|
* @param taskRecord 任务
|
|
|
|
|
* @param taskRecord 任务
|
|
|
|
|
* @return 案件列表
|
|
|
|
|
*/
|
|
|
|
|
private List<ModelCase> getModelCases(TaskRecordVo taskRecordVo, TaskRecord taskRecord) {
|
|
|
|
|
private List<ModelCase> getModelCases(TaskRecord taskRecord) {
|
|
|
|
|
List<ModelCase> modelCases;
|
|
|
|
|
LambdaQueryWrapper<ModelCase> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
queryWrapper.eq(ModelCase::getDataStatus, DataStatus.AVAILABLE.getCode());
|
|
|
|
|
//根据任务类型查找案件
|
|
|
|
|
if (TASK_TYPE_SPECIFIED_CASE.equals(taskRecord.getType())) {
|
|
|
|
|
queryWrapper.in(ModelCase::getId, List.of(taskRecordVo.getCaseId().split(",")));
|
|
|
|
|
queryWrapper.in(ModelCase::getId, List.of(taskRecord.getCaseId().split(",")));
|
|
|
|
|
} else if (TASK_TYPE_SPECIFIED_RECORD.equals(taskRecord.getType()) || TASK_TYPE_SPECIFIED_EVIDENCE.equals(taskRecord.getType())) {
|
|
|
|
|
queryWrapper.eq(ModelCase::getId, taskRecord.getCaseId());
|
|
|
|
|
}
|
|
|
|
@ -298,13 +339,16 @@ public class TaskRecordServiceImpl extends ServiceImpl<TaskRecordMapper, TaskRec
|
|
|
|
|
Boolean success = taskCaseRecordService.updateStatus(taskId, List.of(TASK_STATUS_WAITING, TASK_STATUS_PROCESSING), TASK_STATUS_CANCELED);
|
|
|
|
|
log.info("completeTask:任务状态更新完成,task_case数据任务状态【{}】变动,任务ID: 【{}】", taskId, success ? "产生" : "无");
|
|
|
|
|
taskRecord.setStatus(TASK_STATUS_CANCELED);
|
|
|
|
|
this.updateById(taskRecord);
|
|
|
|
|
|
|
|
|
|
if (!StrUtil.equals(TASK_STATUS_CANCELED, taskRecord.getStatus())) {
|
|
|
|
|
this.updateById(taskRecord);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.equalsAny(taskRecord.getStatus(), TASK_STATUS_WAITING, TASK_STATUS_PROCESSING)) {
|
|
|
|
|
List<TaskCaseRecord> taskCaseRecords = taskCaseRecordService.queryByTaskId(taskId);
|
|
|
|
|
String taskStatus = this.determineStatus(taskCaseRecords);
|
|
|
|
|
log.info("completeTask:任务ID:【{}】,初始任务状态:【{}】,计算后任务状态:【{}】", taskId, taskCaseRecord.getStatus(), taskStatus);
|
|
|
|
|
log.info("completeTask:任务ID:【{}】,初始任务案件状态:【{}】,计算后任务状态:【{}】", taskId, taskCaseRecord.getStatus(), taskStatus);
|
|
|
|
|
if (!StrUtil.equals(taskStatus, taskRecord.getStatus())) {
|
|
|
|
|
taskRecord.setStatus(taskStatus);
|
|
|
|
|
super.updateById(taskRecord);
|
|
|
|
|