2025-11-04 16:51:41 +08:00

85 lines
3.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.zhgd.xmgl.task;
import cn.hutool.core.date.DateUtil;
import com.zhgd.xmgl.call.api.PoliceCameraManufacturer;
import com.zhgd.xmgl.call.factory.PoliceCameraManufacturerFactory;
import com.zhgd.xmgl.modules.policecamera.service.IProjectPoliceCameraConfigService;
import com.zhgd.xmgl.modules.project.entity.Project;
import com.zhgd.xmgl.modules.project.service.IProjectService;
import com.zhgd.xmgl.util.AsyncTaskUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("xmgl/task")
@Transactional(rollbackFor = Exception.class)
public class Mcs8Task {
@Lazy
@Autowired
IProjectService projectService;
@Lazy
@Autowired
private IProjectPoliceCameraConfigService projectPoliceCameraConfigService;
@Lazy
@Autowired
private PoliceCameraManufacturerFactory policeCameraManufacturerFactory;
@Autowired
@Qualifier("doubleCarbonExecutor")
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
/**
* 定时从Mcs8获取执法记录仪文件
*/
@Scheduled(cron = "0 */5 * * * ?")
@RequestMapping("getPoliceCameraItemFile")
public void getPoliceCameraItemFile() {
Date now = new Date();
List<Project> projects = projectService.list();
for (Project project : projects) {
try {
PoliceCameraManufacturer manufacturer = policeCameraManufacturerFactory.getPoliceCameraManufacturer(project.getProjectSn());
if (manufacturer != null) {
AsyncTaskUtil.runAsync(() -> {
manufacturer.pullFile(DateUtil.offsetDay(now, -7), now);
});
}
} catch (Exception e) {
log.error("定时从Mcs8获取执法记录仪文件err{}", project.getProjectName(), e);
}
}
}
/**
* 定时更新执法仪设备状态
*/
@Scheduled(cron = "*/5 * * * * ?")
@RequestMapping("updateStatus")
public void updateStatus() {
List<Project> projects = projectService.list();
for (Project project : projects) {
try {
PoliceCameraManufacturer manufacturer = policeCameraManufacturerFactory.getPoliceCameraManufacturer(project.getProjectSn());
if (manufacturer != null) {
manufacturer.updateStatus(3L);
}
} catch (Exception e) {
log.error("定时更新执法仪设备状态err{}", project.getProjectName(), e);
}
}
}
}