Kaynağa Gözat

截图路径修改

wyyay 7 ay önce
ebeveyn
işleme
5356dc30f2

+ 9 - 0
business-service/src/main/java/com/ozs/service/entity/vo/BaseCameraVO.java

@@ -29,6 +29,15 @@ public class BaseCameraVO implements Serializable{
      */
     private String channel;
 
+    /**
+     *线路名称
+     */
+    private String railwayName;
+
+    /**
+     * 监控相机安装里程位置
+     */
+    private String installMiles;
 
     /**
      * 下次执行时间

+ 9 - 3
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/CaptureStreamListener.java

@@ -19,6 +19,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.time.LocalDate;
 
 @Component
 @Slf4j
@@ -66,7 +67,8 @@ public class CaptureStreamListener implements StreamListener<String, ObjectRecor
             Dict dataDict = JSONUtil.toBean(value, Dict.class);
 
             String cameraCode = dataDict.getStr("cameraCode");
-
+            String railwayName = dataDict.getStr("railwayName");
+            String installMiles = dataDict.getStr("installMiles");
             Boolean isAlarm = dataDict.getBool("isAlarm");
             String camera_type_hash = isAlarm ? ShotPictureTaskExecutors.CAMERA_ALARM_HASH : ShotPictureTaskExecutors.CAMERA_NORMAL_HASH;
 
@@ -82,11 +84,15 @@ public class CaptureStreamListener implements StreamListener<String, ObjectRecor
             if (StringUtils.isNotBlank(dataDict.getStr("nextExecuteTime"))) {
                 nextExecuteTime = DateTime.of(dataDict.getStr("nextExecuteTime"), "yyyy-MM-dd HH:mm:ss");
             }
-            String ymd = DateTime.now().toString("yyyy-MM-dd");
             DateTime now = DateTime.now();
+            StringBuilder fileName = new StringBuilder(cameraCode);
+            fileName.append("-");
+            fileName.append(DateTime.now().toString("yyyyMMddHHmmss"));
+            String isNormalPath = isAlarm ? "alarm" : "normal";
+            String filePath = dataDict.getStr("address")+"/"+isNormalPath+"/"+railwayName+"/"+installMiles+"/"+ LocalDate.now().getYear() +"/"+ LocalDate.now().getMonthValue() + "/" +fileName + ".jpeg";
             // 超过时间则进行抓拍
             if (now.isAfterOrEquals(nextExecuteTime) && nextExecuteTime.between(now, DateUnit.MINUTE) < 2) {
-                genPictureTaskService.getNormalPicture(cameraCode, dataDict.getStr("channel"), dataDict.getStr("address"), ymd);
+                genPictureTaskService.makePicture(cameraCode, dataDict.getStr("channel"), filePath);
             }
             // 通过RedisTemplate手动确认消息
             stringRedisTemplate.opsForStream().acknowledge(RedisPushService.STREAM_KEY, RedisPushService.STREAM_CONSUMER_GROUP_KEY, recordId.getValue());

+ 3 - 5
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/GenPictureTaskService.java

@@ -28,8 +28,7 @@ public class GenPictureTaskService {
     @Value("${shot.urlAddress}")
     private String urlAddress;
 
-    public boolean getNormalPicture(String cameraCode, String channel, String address, String ymd) {
-        String uuid = IdUtils.fastSimpleUUID();
+    public boolean makePicture(String cameraCode, String channel, String filePath) {
         long start = System.currentTimeMillis();
         if (!ObjectUtils.isEmpty(cameraCode)) {
             try {
@@ -37,11 +36,10 @@ public class GenPictureTaskService {
 //                    log.debug("请求url======" + urlAddress + cameraCode + "/" + channel);
 //                }
                 URL url = new URL(urlAddress + cameraCode + "/" + channel);
-                String fileName = address + "/" + "normal" + "/" + ymd + "/" + uuid + ".jpeg";
 //                if (log.isDebugEnabled()) {
-//                    log.debug("正常摄像头截图开始, url: " + url + ", fileName: " + fileName);
+//                    log.debug("正常摄像头截图开始, url: " + url + ", fileName: " + filePath);
 //                }
-                boolean capture = cameraCaptureService.getCapture(url, cameraCode, fileName);
+                boolean capture = cameraCaptureService.getCapture(url, cameraCode, filePath);
 //                if (log.isDebugEnabled()) {
 //                    log.debug("正常摄像头截图结束, url: " + url + (capture ? "" : ", 出现错误") + ", 共计耗时: " + ((System.currentTimeMillis() - start) / 1000) + "s");
 //                }

+ 23 - 6
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotPictureTaskExecutors.java

@@ -7,11 +7,14 @@ import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.ozs.common.core.domain.entity.SysDictData;
 import com.ozs.common.core.redis.RedisCache;
+import com.ozs.common.utils.AppendUtils;
 import com.ozs.common.utils.DictUtils;
 import com.ozs.service.entity.BaseCameraManagement;
+import com.ozs.service.entity.BaseRailwayManagement;
 import com.ozs.service.entity.MsgAlarm;
 import com.ozs.service.entity.vo.BaseCameraVO;
 import com.ozs.service.mapper.BaseCameraManagementMapper;
+import com.ozs.service.mapper.BaseRailwayManagementMapper;
 import com.ozs.service.mapper.MsgAlarmMapper;
 import com.ozs.service.service.RedisService;
 import com.ozs.system.service.ISysDictTypeService;
@@ -73,6 +76,9 @@ public class ShotPictureTaskExecutors {
 
     @Resource
     private BaseCameraManagementMapper baseCameraManagementMapper;
+
+    @Resource
+    private BaseRailwayManagementMapper baseRailwayManagementMapper;
     @Autowired
     RedisCache redisCache;
 
@@ -102,17 +108,23 @@ public class ShotPictureTaskExecutors {
                     .stream().map(f -> f.getCameraCode()).distinct().collect(Collectors.toList());
             try {
                 QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
-                queryWrapper.select("distinct camera_code, channel");
+                queryWrapper.select("distinct camera_code, channel,railway_code,install_mile");
                 // 获取数据库中最新摄像头相关内容
                 List<BaseCameraManagement> dbAlarms = baseCameraManagementMapper.selectList(queryWrapper).stream().collect(Collectors.toList());
+                List<BaseRailwayManagement> dbRailways = baseRailwayManagementMapper.selectList(null);
                 if (!CollectionUtils.isEmpty(dbAlarms)) {
+                    for(BaseRailwayManagement dbRailway:dbRailways){
+                        redisCache.setCacheObject(dbRailway.getRailwayCode(),dbRailway.getRailwayName());
+                    }
                     Set<Object> hashAlarmKeys = redisService.redisTemplate.opsForHash().keys(CAMERA_ALARM_HASH);
                     Set<Object> hashNormalKeys = redisService.redisTemplate.opsForHash().keys(CAMERA_NORMAL_HASH);
                     // 数据库中存在的数据, 但是缓存中不存在, 则进行补全
                     for (BaseCameraManagement dbAlarm : dbAlarms) {
-                        BaseCameraVO vo = new BaseCameraVO();
+                        BaseCameraVO  vo = new BaseCameraVO();
                         vo.setCameraCode(dbAlarm.getCameraCode());
                         vo.setChannel(dbAlarm.getChannel());
+                        vo.setInstallMiles(AppendUtils.stringAppend(dbAlarm.getInstallMile()));
+                        vo.setRailwayName(redisCache.getCacheObject(dbAlarm.getRailwayCode()));
                         vo.setNextExecuteTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
                         if (lockedMsgAlarmCameraCodes.contains(vo.getCameraCode()) && !hashAlarmKeys.contains(vo.getCameraCode())) {
                             vo.setIsAlarm(true);
@@ -165,12 +177,13 @@ public class ShotPictureTaskExecutors {
                 status = redisCache.getCacheObject("shot_switch");
             }
         }
-         //判断开关是否执行
-        if (status != 1) return;
-
+        // 判断开关是否执行
+        if (status != 1) {
+            return;
+        }
         // 获取字典值: 截图存放路径
         List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
-        if(CollectionUtils.isEmpty(addressDataList)){
+        if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
             DictUtils.setDictCache("shot_address", addressDataList = iSysDictTypeService.selectDictDataByType("shot_address"));
         }
         if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
@@ -194,6 +207,8 @@ public class ShotPictureTaskExecutors {
                     dict.put("cameraCode", item.getCameraCode());
                     dict.put("channel", item.getChannel());
                     dict.put("address", finalAddress);
+                    dict.put("railwayName", item.getRailwayName());
+                    dict.put("installMiles", item.getInstallMiles());
                     dict.put("isAlarm", false);
                     dict.put("nextExecuteTime", item.getNextExecuteTime());
                     redisPushService.pushMsg(JSONUtil.toJsonStr(dict));
@@ -217,6 +232,8 @@ public class ShotPictureTaskExecutors {
                     dict.put("cameraCode", item.getCameraCode());
                     dict.put("channel", item.getChannel());
                     dict.put("address", finalAddress);
+                    dict.put("railwayName", item.getRailwayName());
+                    dict.put("installMiles", item.getInstallMiles());
                     dict.put("isAlarm", true);
                     dict.put("nextExecuteTime", item.getNextExecuteTime());
                     redisPushService.pushMsg(JSONUtil.toJsonStr(dict));