修复工作

This commit is contained in:
2025-10-01 22:30:06 +08:00
parent 20f0481f3a
commit fc88a11af3
2 changed files with 29 additions and 37 deletions

View File

@@ -65,11 +65,10 @@ public class InspectionTaskEventListener {
Long taskId = event.getTaskId();
log.info("接收到任务完成事件: 任务ID={}", taskId);
try {
// 开始异步视频分析
videoAnalysisService.analyzeVideo(taskId);
} catch (Exception e) {
log.error("处理任务完成事件失败: {}", e.getMessage());
}
// 注意:视频分析已经在 InspectionTaskServiceImpl.performVideoAnalysisWithRecord 中同步执行
// 因此这里不需要再次调用分析
log.info("任务完成处理完毕: 任务ID={}", taskId);
// 如果未来需要在任务完成后执行其他操作,可以在这里添加
}
}

View File

@@ -33,6 +33,7 @@ import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@@ -118,7 +119,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
}
// 启用任务,使用新版实体类的方法
task.setStatus(0); // 0表示启用
task.setStatus("0"); // 0表示启用
task.setUpdateTime(DateUtils.getNowDate());
inspectionTaskMapper.updateInspectionTask(task);
@@ -137,7 +138,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
}
// 停用任务,使用新版实体类的方法
task.setStatus(1); // 1表示停用
task.setStatus("1"); // 1表示停用
task.setUpdateTime(DateUtils.getNowDate());
inspectionTaskMapper.updateInspectionTask(task);
@@ -151,7 +152,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
@Async
public void executeInspectionTask(Long taskId) {
InspectionTask task = inspectionTaskMapper.selectInspectionTaskById(taskId);
if (task == null || task.getStatus() != 0) { // 0表示启用状态
if (task == null || !"0".equals(task.getStatus())) { // 0表示启用状态
return;
}
@@ -169,7 +170,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
try {
// 更新任务状态为执行中
task.setStatus(1);
task.setStatus("1");
inspectionTaskMapper.updateInspectionTask(task);
// 获取设备信息
@@ -190,7 +191,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
inspectionTaskRecordMapper.updateInspectionTaskRecord(record);
// 更新任务状态为已完成
task.setStatus(2);
task.setStatus("2");
inspectionTaskMapper.updateInspectionTask(task);
} catch (Exception e) {
@@ -198,7 +199,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
updateRecordFailed(record, e.getMessage());
// 更新任务状态为已完成(虽然失败)
task.setStatus(2);
task.setStatus("2");
inspectionTaskMapper.updateInspectionTask(task);
}
}
@@ -281,12 +282,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
minioObject.setCreateTime(new Date());
Long objectId = vMinioObjectService.insertVMinioObject(minioObject);
// 7. 更新任务的视频ID和状态
task.setVideoOssId(objectId);
task.setVideoStatus(1); // 已录制未分析
inspectionTaskMapper.updateInspectionTask(task);
// 8. 更新记录的附件信息视频URL
// 7. 更新记录的附件信息视频URL
record.setAccessory(objectUrl);
inspectionTaskRecordMapper.updateInspectionTaskRecord(record);
@@ -454,18 +450,17 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
AlarmRecord alarm = new AlarmRecord();
alarm.setTaskId(task.getTaskId());
// 这些字段在新版实体类中可能不存在,需要调整
// alarm.setTaskName(task.getTaskName());
alarm.setTaskName(task.getTaskName());
alarm.setDeviceId(task.getDeviceId());
// alarm.setDeviceName(task.getDeviceName());
alarm.setDeviceName(task.getDeviceName());
alarm.setAlarmType(best.getLabel());
// 这里需要转换double为float
alarm.setAlarmLevel(getAlarmLevel((float)best.getConfidence()));
alarm.setAlarmContent(String.format("检测到%s置信度: %.2f", best.getLabel(), best.getConfidence()));
alarm.setConfidence(best.getConfidence());
alarm.setImageOssId(rec.getObjectId());
alarm.setCreateTime(new Date(now));
alarm.setStatus(0); // 0: 未处理
alarm.setAlarmDesc(String.format("检测到%s置信度: %.2f", best.getLabel(), best.getConfidence()));
alarm.setConfidence(BigDecimal.valueOf(best.getConfidence()));
alarm.setImagePath(up.getUrl());
alarm.setAlarmTime(new Date(now));
alarm.setHandleStatus("0"); // 0: 未处理
saveAlarmRecord(alarm);
currentAlarmId = alarm.getAlarmId();
@@ -546,8 +541,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
AlarmRecord patch = new AlarmRecord();
patch.setAlarmId(currentAlarmId);
// videoPath字段在新版实体类中可能不存在需要调整
// patch.setVideoPath(upv.getUrl());
patch.setVideoPath(upv.getUrl());
alarmRecordMapper.updateAlarmRecord(patch);
} catch (Exception ue) {
log.warn("巡检会话-上传/回填视频失败: {}", ue.getMessage());
@@ -673,19 +667,18 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
// 创建告警记录
AlarmRecord alarmRecord = new AlarmRecord();
alarmRecord.setTaskId(taskId);
// 这些字段在新版实体类中可能不存在,需要调整
// alarmRecord.setTaskName(task.getTaskName());
alarmRecord.setTaskName(task.getTaskName());
alarmRecord.setDeviceId(task.getDeviceId());
// alarmRecord.setDeviceName(task.getDeviceName());
alarmRecord.setDeviceName(task.getDeviceName());
alarmRecord.setAlarmType(detection.getLabel());
alarmRecord.setAlarmLevel(getAlarmLevel((float)detection.getConfidence()));
alarmRecord.setAlarmContent(String.format("检测到%s置信度: %.2f",
alarmRecord.setAlarmDesc(String.format("检测到%s置信度: %.2f",
detection.getLabel(), detection.getConfidence()));
alarmRecord.setConfidence(detection.getConfidence());
// 设置图片路径 - 需要调整为适合新实体类的方式
// alarmRecord.setImagePath(imagePath);
alarmRecord.setCreateTime(new Date());
alarmRecord.setStatus(0); // 0: 未处理
alarmRecord.setConfidence(BigDecimal.valueOf(detection.getConfidence()));
// 设置图片路径 - 使用正确的方法名
alarmRecord.setImagePath(imagePath);
alarmRecord.setAlarmTime(new Date());
alarmRecord.setHandleStatus("0"); // 0: 未处理
saveAlarmRecord(alarmRecord);