删除长时间(超过30分钟)的卡主的任务

This commit is contained in:
guoshengxiong 2024-07-25 16:07:48 +08:00
parent 1f36f5716d
commit b2513eb68e
2 changed files with 82 additions and 0 deletions

View File

@ -33,6 +33,7 @@ import com.zhgd.xmgl.modules.xz.mapper.XzHikvisionCompareDataMapper;
import com.zhgd.xmgl.modules.xz.service.IXzHikvisionCompareDataService;
import com.zhgd.xmgl.modules.xz.service.impl.XzHikvisionSyncServiceImpl;
import com.zhgd.xmgl.util.HikvisionUtil;
import com.zhgd.xmgl.util.JoBuilder;
import com.zhgd.xmgl.util.MapBuilder;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
@ -96,6 +97,40 @@ public class HikvisionTask {
@Autowired
private AsyncHikvision asyncHikvision;
/**
* 删除长时间超过30分钟的卡主的任务设备不支持并发多个任务下权限如果你同时往同一个设备下了多个任务会导致设备堵住任务一直处于下载中这些任务就释放不了
*
* @throws Exception
*/
@SchedulerLock(name = "deleteLongTask", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
@Scheduled(cron = "0 0/30 * * * ?")
@RequestMapping("deleteLongTask")
public void deleteLongTask() throws Exception {
List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>()
.eq(Project::getSyncHikvision, 1));
for (Project project : projects) {
try {
JSONObject joRt = HikvisionUtil.getTasks(project, new JoBuilder().put("pageNo", 1).put("pageSize", 1000).put("authTaskStatusList", Arrays.asList(0, 1)).build());
JSONObject dataJo = HikvisionUtil.getJsonObjectData(joRt);
JSONArray listJa = dataJo.getJSONArray("list");
for (int i = 0; i < listJa.size(); i++) {
JSONObject jo = listJa.getJSONObject(i);
if (DateUtil.compare(DateUtil.parse(jo.getString("createTime")), DateUtil.offsetMinute(new Date(), -30)) < 0) {
if (jo.getInteger("taskStatus").equals(1)) {
HikvisionUtil.stopTask(project, new JoBuilder().put("taskId", jo.getString("authTaskId")).build());
} else {
HikvisionUtil.deleteTask(project, new JoBuilder().put("taskId", jo.getString("authTaskId")).build());
}
}
}
} catch (Exception e) {
log.error("" + e);
}
}
}
/**
* 定时一分钟获取海康数据
*/

View File

@ -910,4 +910,51 @@ public class HikvisionUtil {
}
return null;
}
/**
* 查询任务信息列表
*
* @param project
* @param param
* @return
* @throws Exception
*/
public static JSONObject getTasks(Project project, JSONObject param) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/acps/v1/authDownload/task/search";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, JSONArray.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 删除未开始的下载任务
*
* @param project
* @param param
* @return
* @throws Exception
*/
public static JSONObject deleteTask(Project project, JSONObject param) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/acps/v1/authDownload/task/deletion";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, JSONArray.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 终止正在下载的任务
*
* @param project
* @param param
* @return
* @throws Exception
*/
public static JSONObject stopTask(Project project, JSONObject param) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/acps/v1/authDownload/task/stop";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, JSONArray.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
}