Browse Source

定时任务-更正修改字典不生效

wyyay 1 year ago
parent
commit
a239322054

+ 40 - 11
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotExecutors.java

@@ -3,9 +3,15 @@ package com.ozs.web.controller.shotschedule;
 import com.ozs.system.service.ISysDictDataService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
+import java.util.UUID;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -15,11 +21,13 @@ import java.util.concurrent.TimeUnit;
  * @subject
  * @creat 2023/5/6
  */
-@Component
+@Configuration
+@EnableScheduling
+@EnableAsync
 @Slf4j
 public class ShotExecutors {
 
-    private  static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
+   // private  static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
     @Autowired
     private ISysDictDataService dictDataService;
     @Autowired
@@ -27,16 +35,37 @@ public class ShotExecutors {
     @Autowired
     private TaskAlarmService taskAlarmService;//定时任务-报警摄像头
 
-    @PostConstruct
-    public void init() {
-        try{
-            boolean shotSwitch = Boolean.parseBoolean(dictDataService.selectDictLabel("shot_switch", String.valueOf(0)));
-            if(shotSwitch){
-                scheduledExecutorService.scheduleAtFixedRate(taskNormalService, 0, 500, TimeUnit.MILLISECONDS);
-                scheduledExecutorService.scheduleAtFixedRate(taskAlarmService, 0, 200, TimeUnit.MILLISECONDS);
+    /**
+     * 处理非预警摄像头截图
+     */
+    @Async
+    @Scheduled(fixedRate = 500)
+    public void handleNormalPicture() {
+        boolean shotSwitch = Boolean.parseBoolean(dictDataService.selectDictLabel("shot_switch", String.valueOf(0)));
+        try {
+            if (shotSwitch) {
+                taskNormalService.getNormalPicture();
             }
-        }catch (Throwable throwable){
-            log.error(throwable.getMessage());
+        } catch (Exception e) {
+            e.getMessage();
+            log.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 处理预警摄像头截图
+     */
+    @Async
+    @Scheduled(fixedRate = 200)
+    public void handleAlarmPicture() {
+        boolean shotSwitch = Boolean.parseBoolean(dictDataService.selectDictLabel("shot_switch", String.valueOf(0)));
+        try {
+            if (shotSwitch) {
+                taskAlarmService.getAlarmPicture();
+            }
+        } catch (Exception e) {
+            e.getMessage();
+            log.error(e.getMessage());
         }
     }
 }

+ 4 - 3
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/TaskAlarmService.java

@@ -31,7 +31,7 @@ import java.util.Objects;
  */
 @Slf4j
 @Service
-public class TaskAlarmService implements Runnable{
+public class TaskAlarmService {
     @Resource
     BaseCameraManagementService baseCameraManagementService;
     @Resource
@@ -44,8 +44,8 @@ public class TaskAlarmService implements Runnable{
     @Value("${shot.urlAddress}")
     private String urlAddress;
 
-    @Override
-    public void run() {
+
+    public void getAlarmPicture() {
         QueryWrapper<MsgAlarm> queryWrapper = new QueryWrapper<MsgAlarm>();
         queryWrapper.lambda().eq(MsgAlarm::getIsLock,2);
         List<MsgAlarm> msgAlarmList = msgAlarmService.list(queryWrapper);
@@ -63,6 +63,7 @@ public class TaskAlarmService implements Runnable{
                         String root = dictDataService.selectDictLabel("shot_address", String.valueOf(0));
                         String dateString = format.format(new Date());
                         String fileName = root + "/" + dateString + "/" + uuid + ".jpeg";
+                        //String fileName = root + "/" + dateString + "/alarm/"+ l.getCameraCode()+"_"+ uuid + ".jpeg";
                         log.info("fileName======"+fileName);
                         log.info("报警摄像头截图开始");
                         cameraCaptureService.getCapture(url, fileName);

+ 4 - 3
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/TaskNormalService.java

@@ -31,7 +31,7 @@ import java.util.Objects;
  */
 @Slf4j
 @Service
-public class TaskNormalService implements Runnable{
+public class TaskNormalService{
     @Resource
     BaseCameraManagementService baseCameraManagementService;
     @Resource
@@ -44,8 +44,8 @@ public class TaskNormalService implements Runnable{
     @Value("${shot.urlAddress}")
     private String urlAddress;
 
-    @Override
-    public void run() {
+
+    public void getNormalPicture() {
         List<BaseCameraManagement> list = baseCameraManagementService.list();
         QueryWrapper<MsgAlarm> queryWrapper = new QueryWrapper<MsgAlarm>();
         queryWrapper.lambda().eq(MsgAlarm::getIsLock,2);
@@ -66,6 +66,7 @@ public class TaskNormalService implements Runnable{
                     String root = dictDataService.selectDictLabel("shot_address", String.valueOf(0));
                     String dateString = format.format(new Date());
                     String fileName = root + "/" + dateString + "/" + uuid + ".jpeg";
+                    //String fileName = root + "/" + dateString + "/normal/"+ l.getCameraCode()+"_"+ uuid + ".jpeg";
                     log.info("fileName======" + fileName);
                     log.info("没有报警摄像头截图开始");
                     cameraCaptureService.getCapture(url, fileName);