|
@@ -1,33 +1,29 @@
|
|
|
package com.ozs.web.controller.shotschedule;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.ozs.common.utils.MinioUtils;
|
|
|
+import com.ozs.common.constant.Constants;
|
|
|
+import com.ozs.common.core.domain.entity.SysDictData;
|
|
|
+import com.ozs.common.utils.DictUtils;
|
|
|
import com.ozs.common.utils.uuid.IdUtils;
|
|
|
-import com.ozs.service.entity.BaseCameraManagement;
|
|
|
-import com.ozs.service.entity.MsgAlarm;
|
|
|
+import com.ozs.service.entity.vo.BaseCameraVO;
|
|
|
import com.ozs.service.service.BaseCameraManagementService;
|
|
|
import com.ozs.service.service.MsgAlarmService;
|
|
|
+import com.ozs.service.service.RedisService;
|
|
|
import com.ozs.service.service.impl.CameraCaptureService;
|
|
|
-import com.ozs.system.service.ISysDictDataService;
|
|
|
+import com.ozs.system.service.ISysDictTypeService;
|
|
|
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;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* @author wyy
|
|
@@ -37,50 +33,66 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class TaskService {
|
|
|
- private static ExecutorService executorService = Executors.newFixedThreadPool(50);
|
|
|
- private static ExecutorService alarmExecutorService = Executors.newFixedThreadPool(10);
|
|
|
- @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;
|
|
|
+ @Value("${shot.storeAddress}")
|
|
|
+ private String storeAddress;
|
|
|
+ @Autowired
|
|
|
+ private ISysDictTypeService iSysDictTypeService;
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
|
|
|
public void getNormalPicture() {
|
|
|
- List<BaseCameraManagement> list = msgAlarmService.getBaseCameraManagements();
|
|
|
- if (!CollectionUtils.isEmpty(list) && Objects.nonNull(list.get(0))) {
|
|
|
- list.forEach(l -> {
|
|
|
+ String address = storeAddress;
|
|
|
+ List<SysDictData> dataList = DictUtils.getDictCache("shot_switch");
|
|
|
+ if(CollectionUtils.isEmpty(dataList) || Objects.isNull(dataList.get(0))){
|
|
|
+ dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
|
|
|
+ DictUtils.setDictCache("shot_switch",dataList);
|
|
|
+ }
|
|
|
+ List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
|
|
|
+ if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
|
|
|
+ addressDataList = iSysDictTypeService.selectDictDataByType("shot_address");
|
|
|
+ DictUtils.setDictCache("shot_address",addressDataList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
|
|
|
+ if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
|
|
|
+ if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
|
|
|
+ address = addressDataList.get(0).getDictLabel();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ boolean isHasKeyNormal = redisService.hasKey(Constants.NORMAL_SET);
|
|
|
+ if(!isHasKeyNormal){
|
|
|
+ msgAlarmService.initializationCameraCache();
|
|
|
+ }
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Set<BaseCameraVO> normalSet = redisService.getSetMembers(Constants.NORMAL_SET);
|
|
|
+ if (!CollectionUtils.isEmpty(normalSet)) {
|
|
|
+ String finalAddress = address;
|
|
|
+ normalSet.forEach(item -> {
|
|
|
String uuid = IdUtils.fastSimpleUUID();
|
|
|
- if (!ObjectUtils.isEmpty(l.getCameraCode()) && !ObjectUtils.isEmpty(l.getChannel())) {
|
|
|
+ if (!ObjectUtils.isEmpty(item.getCameraCode())) {
|
|
|
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 {
|
|
|
- System.out.println("fileName"+fileName+"正常图片开始截图时间"+new Date());
|
|
|
- cameraCaptureService.getCapture(url, fileName);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- log.info("调用图片生成服务结束");
|
|
|
- }
|
|
|
- });
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
+ log.debug("请求url======" + urlAddress + item.getCameraCode() + "/" + item.getChannel());
|
|
|
+ }
|
|
|
+ URL url = new URL(urlAddress + item.getCameraCode() + "/" + item.getChannel());
|
|
|
+ String dateString = sdf.format(new Date());
|
|
|
+ String fileName = finalAddress + "/" + "normal" + "/" + dateString + "/" + uuid + ".jpeg";
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
+ log.debug("fileName======" + fileName);
|
|
|
+ log.debug("正常摄像头截图开始");
|
|
|
+ }
|
|
|
+ cameraCaptureService.getCapture(url, fileName);
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
+ log.debug("正常摄像头截图结束");
|
|
|
+ }
|
|
|
} catch (Throwable e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error(e.getMessage());
|
|
|
+ log.error("正常摄像头截图异常",e);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -88,37 +100,53 @@ public class TaskService {
|
|
|
}
|
|
|
|
|
|
public void getAlarmPicture() {
|
|
|
- List<BaseCameraManagement> msgAlarmList = msgAlarmService.getBaseCameraManagementsByLockedMsgAlarms(2);
|
|
|
- if(!CollectionUtils.isEmpty(msgAlarmList) && Objects.nonNull(msgAlarmList.get(0))){
|
|
|
- msgAlarmList.forEach(l -> {
|
|
|
+ String address = storeAddress;
|
|
|
+ List<SysDictData> dataList = DictUtils.getDictCache("shot_switch");
|
|
|
+ if(CollectionUtils.isEmpty(dataList) || Objects.isNull(dataList.get(0))){
|
|
|
+ dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
|
|
|
+ DictUtils.setDictCache("shot_switch",dataList);
|
|
|
+ }
|
|
|
+ List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
|
|
|
+ if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
|
|
|
+ addressDataList = iSysDictTypeService.selectDictDataByType("shot_address");
|
|
|
+ DictUtils.setDictCache("shot_address",addressDataList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
|
|
|
+ if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
|
|
|
+ if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
|
|
|
+ address = addressDataList.get(0).getDictLabel();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ boolean isHasKeyAlarm = redisService.hasKey(Constants.ALARM_SET);
|
|
|
+ if(!isHasKeyAlarm){
|
|
|
+ msgAlarmService.initializationCameraCache();
|
|
|
+ }
|
|
|
+ Set<BaseCameraVO> alarmSet = redisService.getSetMembers(Constants.ALARM_SET);
|
|
|
+ if(!CollectionUtils.isEmpty(alarmSet)){
|
|
|
+ String finalAddress = address;
|
|
|
+ alarmSet.forEach(item -> {
|
|
|
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)){
|
|
|
+ if(!ObjectUtils.isEmpty(item.getCameraCode())) {
|
|
|
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("报警摄像头截图结束");
|
|
|
- }
|
|
|
- });
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
+ log.debug("请求url======" + urlAddress + item.getCameraCode() + "/" + item.getChannel());
|
|
|
+ }
|
|
|
+ URL url = new URL(urlAddress + item.getCameraCode() + "/" + item.getChannel());
|
|
|
+ String dateString = sdf.format(new Date());
|
|
|
+ String fileName = finalAddress + "/" + "alarm" + "/" + dateString + "/" + uuid + ".jpeg";
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
+ log.debug("fileName======" + fileName);
|
|
|
+ log.debug("报警摄像头截图开始");
|
|
|
+ }
|
|
|
+ cameraCaptureService.getCapture(url, fileName);
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
+ log.debug("报警摄像头截图结束");
|
|
|
+ }
|
|
|
+
|
|
|
} catch (Throwable e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error(e.getMessage());
|
|
|
+ log.error("报警摄像头截图异常",e);
|
|
|
}
|
|
|
}
|
|
|
});
|