|
@@ -0,0 +1,127 @@
|
|
|
+package com.ozs.web.controller.shotschedule;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.ozs.common.utils.MinioUtils;
|
|
|
+import com.ozs.common.utils.uuid.IdUtils;
|
|
|
+import com.ozs.service.entity.BaseCameraManagement;
|
|
|
+import com.ozs.service.entity.MsgAlarm;
|
|
|
+import com.ozs.service.service.BaseCameraManagementService;
|
|
|
+import com.ozs.service.service.MsgAlarmService;
|
|
|
+import com.ozs.service.service.impl.CameraCaptureService;
|
|
|
+import com.ozs.system.service.ISysDictDataService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.MalformedURLException;
|
|
|
+import java.net.URL;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.concurrent.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wyy
|
|
|
+ * @subject
|
|
|
+ * @creat 2024/3/1
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class TaskService {
|
|
|
+ private static ExecutorService executorService = Executors.newFixedThreadPool(5);
|
|
|
+ private static ExecutorService alarmExecutorService = Executors.newFixedThreadPool(5);
|
|
|
+ @Resource
|
|
|
+ BaseCameraManagementService baseCameraManagementService;
|
|
|
+ @Resource
|
|
|
+ MsgAlarmService msgAlarmService;
|
|
|
+ @Resource
|
|
|
+ CameraCaptureService cameraCaptureService;
|
|
|
+ @Autowired
|
|
|
+ private ISysDictDataService dictDataService;
|
|
|
+ private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ @Value("${shot.urlAddress}")
|
|
|
+ private String urlAddress;
|
|
|
+
|
|
|
+ public void getNormalPicture() {
|
|
|
+ List<BaseCameraManagement> list = msgAlarmService.getBaseCameraManagements();
|
|
|
+ if (!CollectionUtils.isEmpty(list) && Objects.nonNull(list.get(0))) {
|
|
|
+ list.forEach(l -> {
|
|
|
+ String uuid = IdUtils.fastSimpleUUID();
|
|
|
+ if (!ObjectUtils.isEmpty(l.getCameraCode()) && !ObjectUtils.isEmpty(l.getChannel())) {
|
|
|
+ try {
|
|
|
+ System.out.println(urlAddress + l.getCameraCode() + "/" + l.getChannel());
|
|
|
+ log.info("请求url======" + urlAddress + l.getCameraCode() + "/" + l.getChannel());
|
|
|
+ URL url = new URL(urlAddress + l.getCameraCode() + "/" + l.getChannel());
|
|
|
+ String root = dictDataService.selectDictLabel("shot_address", String.valueOf(0));
|
|
|
+ String dateString = format.format(new Date());
|
|
|
+ String fileName = root + "/" + "normal" + "/" + dateString + "/" + uuid + ".jpeg";
|
|
|
+ log.info("fileName======" + fileName);
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ log.info("调用图片生成服务开始");
|
|
|
+ try {
|
|
|
+ cameraCaptureService.getCapture(url, fileName);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ log.info("调用图片生成服务结束");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Throwable e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getAlarmPicture() {
|
|
|
+ List<BaseCameraManagement> msgAlarmList = msgAlarmService.getBaseCameraManagementsByLockedMsgAlarms(2);
|
|
|
+ if(!CollectionUtils.isEmpty(msgAlarmList) && Objects.nonNull(msgAlarmList.get(0))){
|
|
|
+ msgAlarmList.forEach(l -> {
|
|
|
+ String uuid = IdUtils.fastSimpleUUID();
|
|
|
+ QueryWrapper<BaseCameraManagement> wrapper = new QueryWrapper<BaseCameraManagement>();
|
|
|
+ wrapper.lambda().eq(BaseCameraManagement::getCameraCode,l.getCameraCode());
|
|
|
+ BaseCameraManagement baseCameraManagement = baseCameraManagementService.getOne(wrapper);
|
|
|
+ if(!ObjectUtils.isEmpty(l.getCameraCode()) &&!ObjectUtils.isEmpty(baseCameraManagement)){
|
|
|
+ try {
|
|
|
+ System.out.println(urlAddress+l.getCameraCode()+"/"+baseCameraManagement.getChannel());
|
|
|
+ log.info("请求url======"+urlAddress+l.getCameraCode()+"/"+baseCameraManagement.getChannel());
|
|
|
+ URL url = new URL(urlAddress+l.getCameraCode()+"/"+baseCameraManagement.getChannel());
|
|
|
+ String root = dictDataService.selectDictLabel("shot_address", String.valueOf(0));
|
|
|
+ String dateString = format.format(new Date());
|
|
|
+ String fileName = root + "/" + "alarm" + "/" + dateString + "/" + uuid + ".jpeg";
|
|
|
+ log.info("fileName======"+fileName);
|
|
|
+ alarmExecutorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ log.info("报警摄像头截图开始");
|
|
|
+ try {
|
|
|
+ cameraCaptureService.getCapture(url, fileName);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ log.info("报警摄像头截图结束");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Throwable e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|