feat(video): 新增报警批量处理功能并优化任务执行逻辑
- 新增 alarmBatchBo 类用于批量处理报警记录 - 移除报警记录控制器中的权限注解 - 批量处理接口改为接收 alarmBatchBo 对象 - 引入 ruoyi-quartz 依赖用于定时任务处理- 恢复并优化 InspectionTaskServiceImpl 中设备信息设置 - 更新任务执行时更新最后执行时间与下次执行时间- 视频分析服务中增加报警记录时更新任务报警次数
This commit is contained in:
@@ -109,6 +109,10 @@
|
|||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-framework</artifactId>
|
<artifactId>ruoyi-framework</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-quartz</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.ruoyi.common.enums.BusinessType;
|
|||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
import com.ruoyi.video.domain.AlarmRecord;
|
import com.ruoyi.video.domain.AlarmRecord;
|
||||||
|
import com.ruoyi.video.domain.bo.alarmBatchBo;
|
||||||
import com.ruoyi.video.service.InspectionTaskService;
|
import com.ruoyi.video.service.InspectionTaskService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@@ -34,7 +35,6 @@ public class AlarmRecordController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 查询报警记录列表
|
* 查询报警记录列表
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('video:alarm:list')")
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo list(AlarmRecord alarmRecord) {
|
public TableDataInfo list(AlarmRecord alarmRecord) {
|
||||||
startPage();
|
startPage();
|
||||||
@@ -45,7 +45,6 @@ public class AlarmRecordController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 导出报警记录列表
|
* 导出报警记录列表
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('video:alarm:export')")
|
|
||||||
@Log(title = "报警记录", businessType = BusinessType.EXPORT)
|
@Log(title = "报警记录", businessType = BusinessType.EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(HttpServletResponse response, AlarmRecord alarmRecord) {
|
public void export(HttpServletResponse response, AlarmRecord alarmRecord) {
|
||||||
@@ -57,7 +56,6 @@ public class AlarmRecordController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 处理报警记录
|
* 处理报警记录
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('video:alarm:handle')")
|
|
||||||
@Log(title = "处理报警记录", businessType = BusinessType.UPDATE)
|
@Log(title = "处理报警记录", businessType = BusinessType.UPDATE)
|
||||||
@PostMapping("/handle")
|
@PostMapping("/handle")
|
||||||
public AjaxResult handle(@RequestParam Long alarmId,
|
public AjaxResult handle(@RequestParam Long alarmId,
|
||||||
@@ -71,12 +69,12 @@ public class AlarmRecordController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 批量处理报警记录
|
* 批量处理报警记录
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('video:alarm:handle')")
|
|
||||||
@Log(title = "批量处理报警记录", businessType = BusinessType.UPDATE)
|
@Log(title = "批量处理报警记录", businessType = BusinessType.UPDATE)
|
||||||
@PostMapping("/batchHandle")
|
@PostMapping("/batchHandle")
|
||||||
public AjaxResult batchHandle(@RequestParam Long[] alarmIds,
|
public AjaxResult batchHandle(@RequestBody alarmBatchBo alarmBatchBo) {
|
||||||
@RequestParam String handleStatus,
|
Long[] alarmIds = alarmBatchBo.getAlarmIds();
|
||||||
@RequestParam(required = false) String handleRemark) {
|
String handleStatus = alarmBatchBo.getHandleStatus();
|
||||||
|
String handleRemark = alarmBatchBo.getHandleRemark();
|
||||||
String handleBy = SecurityUtils.getUsername();
|
String handleBy = SecurityUtils.getUsername();
|
||||||
int successCount = 0;
|
int successCount = 0;
|
||||||
for (Long alarmId : alarmIds) {
|
for (Long alarmId : alarmIds) {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.ruoyi.video.domain.bo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class alarmBatchBo {
|
||||||
|
private Long[] alarmIds;
|
||||||
|
private String handleStatus;
|
||||||
|
private String handleRemark;
|
||||||
|
}
|
||||||
@@ -64,6 +64,8 @@ public class VideoAnalysisService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private com.ruoyi.video.mapper.InspectionTaskRecordMapper inspectionTaskRecordMapper;
|
private com.ruoyi.video.mapper.InspectionTaskRecordMapper inspectionTaskRecordMapper;
|
||||||
|
@Autowired
|
||||||
|
private InspectionTaskMapper inspectionTaskMapper;
|
||||||
|
|
||||||
// 检测器配置 - 支持环境变量配置
|
// 检测器配置 - 支持环境变量配置
|
||||||
private static final String PYTHON_API_URL = System.getenv().getOrDefault("PYTHON_API_URL", "http://localhost:8000") + "/api/detect/file";
|
private static final String PYTHON_API_URL = System.getenv().getOrDefault("PYTHON_API_URL", "http://localhost:8000") + "/api/detect/file";
|
||||||
@@ -225,6 +227,9 @@ public class VideoAnalysisService {
|
|||||||
*/
|
*/
|
||||||
private void createAlarmRecordForRecord(InspectionTask task, com.ruoyi.video.domain.InspectionTaskRecord record,
|
private void createAlarmRecordForRecord(InspectionTask task, com.ruoyi.video.domain.InspectionTaskRecord record,
|
||||||
Detection detection, Mat frame, long frameCount) throws Exception {
|
Detection detection, Mat frame, long frameCount) throws Exception {
|
||||||
|
//创建记录之前应该给task加上报警次数
|
||||||
|
task.setAlarmCount(task.getAlarmCount() + 1);
|
||||||
|
inspectionTaskMapper.updateInspectionTask(task);
|
||||||
// 创建告警图像临时文件
|
// 创建告警图像临时文件
|
||||||
File alarmImageFile = File.createTempFile("alarm_", ".jpg");
|
File alarmImageFile = File.createTempFile("alarm_", ".jpg");
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.ruoyi.video.service.impl;
|
|||||||
|
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
|
import com.ruoyi.quartz.util.CronUtils;
|
||||||
import com.ruoyi.video.domain.*;
|
import com.ruoyi.video.domain.*;
|
||||||
import com.ruoyi.video.domain.dto.CameraDto;
|
import com.ruoyi.video.domain.dto.CameraDto;
|
||||||
import com.ruoyi.video.mapper.InspectionTaskMapper;
|
import com.ruoyi.video.mapper.InspectionTaskMapper;
|
||||||
@@ -83,16 +84,15 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
|
|||||||
@Override
|
@Override
|
||||||
public int insertInspectionTask(InspectionTask inspectionTask) {
|
public int insertInspectionTask(InspectionTask inspectionTask) {
|
||||||
inspectionTask.setCreateTime(DateUtils.getNowDate());
|
inspectionTask.setCreateTime(DateUtils.getNowDate());
|
||||||
// 这些字段在新版实体类中可能不存在,需要进行调整
|
inspectionTask.setExecuteCount(0L);
|
||||||
// inspectionTask.setExecuteCount(0L);
|
inspectionTask.setAlarmCount(0L);
|
||||||
// inspectionTask.setAlarmCount(0L);
|
|
||||||
|
|
||||||
// 获取设备信息
|
// 获取设备信息
|
||||||
Device device = deviceService.selectDeviceByDeviceId(inspectionTask.getDeviceId());
|
Device device = deviceService.selectDeviceByDeviceId(inspectionTask.getDeviceId());
|
||||||
// 新版实体类可能不需要设备名称
|
|
||||||
// if (device != null) {
|
if (device != null) {
|
||||||
// inspectionTask.setDeviceName(device.getIp());
|
inspectionTask.setDeviceName(device.getIp());
|
||||||
// }
|
}
|
||||||
|
|
||||||
return inspectionTaskMapper.insertInspectionTask(inspectionTask);
|
return inspectionTaskMapper.insertInspectionTask(inspectionTask);
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,12 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
|
|||||||
try {
|
try {
|
||||||
// 更新任务状态为执行中
|
// 更新任务状态为执行中
|
||||||
// task.setStatus("1");
|
// task.setStatus("1");
|
||||||
// inspectionTaskMapper.updateInspectionTask(task);
|
// 更新最后执行时间和下次执行时间
|
||||||
|
task.setLastExecuteTime(new Date());
|
||||||
|
task.setNextExecuteTime(CronUtils.getNextExecution(task.getCronExpression()));
|
||||||
|
//更新执行次数
|
||||||
|
task.setExecuteCount(task.getExecuteCount() + 1);
|
||||||
|
inspectionTaskMapper.updateInspectionTask(task);
|
||||||
|
|
||||||
// 获取设备信息
|
// 获取设备信息
|
||||||
Device device = deviceService.selectDeviceByDeviceId(task.getDeviceId());
|
Device device = deviceService.selectDeviceByDeviceId(task.getDeviceId());
|
||||||
|
|||||||
Reference in New Issue
Block a user