Ver código fonte

修改报警抓拍 暂写一条数据

hanzhiwei 2 anos atrás
pai
commit
32cffd0a93

Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 1
ArcFace64.dat


+ 1 - 1
zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/forward/feign/RemoteForwardService.java

@@ -32,7 +32,7 @@ public interface RemoteForwardService {
     Object saveData(@RequestBody Map<String, Object> data);
 
     @GetMapping("/alarm/photograph")
-    R<SysFile> photograph(@RequestParam("streamUrl") String streamUrl);
+    ResultData<SysFile> photograph(@RequestParam("streamUrl") String streamUrl);
 
     @PostMapping("/algorithm/warningCheck")
     ResultData warningCheck(@RequestBody AlgorithmWarningBo bo);

+ 2 - 2
zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/forward/feign/fallback/RemoteForwardFallbackFactory.java

@@ -40,8 +40,8 @@ public class RemoteForwardFallbackFactory implements FallbackFactory<RemoteForwa
             }
 
             @Override
-            public R<SysFile> photograph(String streamUrl) {
-                return R.fail("报警拍照服务调用失败:" + throwable.getMessage());
+            public ResultData<SysFile> photograph(String streamUrl) {
+                return ResultData.fail("报警拍照服务调用失败!");
             }
 
             @Override

+ 9 - 11
zd-modules/zd-algorithm/src/main/java/com/zd/alg/forward/controller/AlarmPhotoController.java

@@ -3,12 +3,12 @@ package com.zd.alg.forward.controller;
 
 import com.github.xiaoymin.knife4j.annotations.ApiSupport;
 import com.zd.alg.forward.serivce.ImageService;
-import com.zd.common.core.exception.ServiceException;
 import com.zd.common.swagger.config.Knife4jConfiguration;
-import com.zd.model.domain.R;
+import com.zd.model.domain.ResultData;
 import com.zd.model.entity.SysFile;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -24,6 +24,7 @@ import java.io.IOException;
 @ApiSupport(author = Knife4jConfiguration.Author.ZP)
 @RestController
 @RequestMapping("/alarm")
+@Slf4j
 public class AlarmPhotoController {
 
     @Resource
@@ -31,16 +32,13 @@ public class AlarmPhotoController {
 
     @ApiOperation(value = "拍照")
     @GetMapping("/photograph")
-    public R<SysFile> photograph(@RequestParam("streamUrl") String streamUrl) {
+    public ResultData<SysFile> photograph(@RequestParam("streamUrl") String streamUrl) {
+        log.info("进入拍照!");
         try {
-            R<SysFile> sysFile = imageService.photograph(streamUrl);
-            if (sysFile!=null){
-                return sysFile;
-            }
-            return R.fail("图片抓拍失败");
-        } catch (IOException|ServiceException e) {
-            e.printStackTrace();
+            ResultData<SysFile> photograph = imageService.photograph(streamUrl);
+            return photograph;
+        } catch (IOException e) {
+            return ResultData.fail("报警拍照异常!" + e);
         }
-        return R.fail();
     }
 }

+ 22 - 6
zd-modules/zd-algorithm/src/main/java/com/zd/alg/forward/serivce/ImageService.java

@@ -4,13 +4,16 @@ package com.zd.alg.forward.serivce;
 import com.zd.alg.forward.utils.VideoUtils;
 import com.zd.base.api.feign.RemoteFileService;
 import com.zd.common.core.exception.ServiceException;
+import com.zd.common.core.utils.DateUtils;
 import com.zd.model.constant.HttpStatus;
 import com.zd.model.domain.R;
+import com.zd.model.domain.ResultData;
 import com.zd.model.entity.SysFile;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.entity.ContentType;
 import org.bytedeco.javacv.FFmpegFrameGrabber;
 import org.bytedeco.javacv.Frame;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
@@ -22,6 +25,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.rmi.ServerException;
+import java.util.UUID;
 
 /**
  * @author hanson
@@ -33,17 +37,29 @@ public class ImageService {
     @Resource
     private RemoteFileService remoteFileService;
 
+    @Value("${file.path}")
+    private String rootPath;
+
     /**
      * 生成的图片的类型
      */
     private static final String IMAGE_FORMAT = "jpg";
 
-    public R<SysFile> photograph(String streamUrl) throws IOException {
+    private static final String IMAGE_SNAP="snap";
+
+    public ResultData<SysFile> photograph(String streamUrl) throws IOException {
+        log.info("进入抓帧环节!");
         try (FFmpegFrameGrabber grabber = VideoUtils.createGrabber(streamUrl)) {
             grabber.start();
-            String fileName = "test";
+            String fileName = UUID.randomUUID().toString();
+            log.info("fileName={}",fileName);
             //文件储存对象
-            File file = new File(fileName + "." + IMAGE_FORMAT);
+            String url=rootPath+File.separator+IMAGE_SNAP+File.separator + DateUtils.datePath()+File.separator;
+            log.info("url={}",url);
+            File file = new File(url+fileName + "." + IMAGE_FORMAT);
+            if(!file.exists()){
+                file.mkdirs();
+            }
             //获取第一帧
             Frame frame = grabber.grabImage();
             if (frame != null) {
@@ -58,13 +74,13 @@ public class ImageService {
                 MultipartFile multipartFile = getMultipartFile(file);
                 R<SysFile> upload = remoteFileService.upload(multipartFile);
                 if (upload.getCode() == HttpStatus.SUCCESS && upload.getData() != null) {
-                    return upload;
+                    return ResultData.success(upload.getData());
                 }else {
-                    throw new ServerException(upload.getMsg());
+                    return ResultData.fail(upload.getMsg());
                 }
             }
         }
-        return null;
+        return ResultData.fail("流地址抓帧失败!");
     }
 
     private MultipartFile getMultipartFile(File file) {

+ 6 - 5
zd-modules/zd-bottle-parent/zd-bottle/src/main/java/com/zd/bottle/service/impl/AlarmRecordServiceImpl.java

@@ -28,6 +28,7 @@ import com.zd.laboratory.api.feign.RemoteSubQueryService;
 import com.zd.model.constant.HttpStatus;
 import com.zd.model.domain.AjaxResult;
 import com.zd.model.domain.R;
+import com.zd.model.domain.ResultData;
 import com.zd.model.entity.HardwareRfidDto;
 import com.zd.model.entity.InventoryTag;
 import com.zd.model.entity.RemoteLabHardware;
@@ -153,7 +154,7 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
             List<UsegasApply> applies = applyService.list(lambdaQuery);
             if (applies.isEmpty()) {
                 Long id = bottleStorage.getId();
-                R<SysFile> fileR = getFileR(tag, hardwareRfidDto);
+                ResultData<SysFile> fileR = getFileR(tag, hardwareRfidDto);
                 String key = RFID_CODE + electronicTag + id;
                 String rfid = redisService.getCacheObject(key);
                 if (rfid != null) {
@@ -184,7 +185,7 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
     }
 
     @Nullable
-    private R<SysFile> getFileR(InventoryTag tag, HardwareRfidDto hardwareRfidDto) {
+    private ResultData<SysFile> getFileR(InventoryTag tag, HardwareRfidDto hardwareRfidDto) {
         //触发RFID警报
         if (hardwareRfidDto != null) {
             R<Boolean> alarm = remoteRfidService.alarm(hardwareRfidDto);//RFID设备报警
@@ -194,9 +195,9 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
         }
         String streamUrl = alarmProperties.getStreamUrl();
         if (StringUtils.hasLength(streamUrl)) {
-            R<SysFile> fileR = remoteForwardService.photograph(alarmProperties.getStreamUrl());
-            log.info("文件上传状态:{},接口返回消息:{},文件上传路径:{}", fileR.getCode(), fileR.getMsg(), fileR.getData());
-            return fileR;
+            ResultData<SysFile> resultData = remoteForwardService.photograph(alarmProperties.getStreamUrl());
+            log.info("文件上传状态:{},接口返回消息:{},文件上传路径:{}", resultData.getCode(), resultData.getMsg(), resultData.getData());
+            return resultData;
         }
         return null;
     }

+ 11 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/LabRiskPlanAbnormalDesc.java

@@ -51,6 +51,9 @@ public class LabRiskPlanAbnormalDesc extends BaseEntity {
     @ApiModelProperty("现场记录(视频)")
     private String recordVideo;
 
+    @ApiModelProperty("现场记录(图片)")
+    private String recordPhoto;
+
     public Long getDescId() {
         return descId;
     }
@@ -115,6 +118,14 @@ public class LabRiskPlanAbnormalDesc extends BaseEntity {
         this.recordVideo = recordVideo;
     }
 
+    public String getRecordPhoto() {
+        return recordPhoto;
+    }
+
+    public void setRecordPhoto(String recordPhoto) {
+        this.recordPhoto = recordPhoto;
+    }
+
     public String getHandledPerson() {
         return handledPerson;
     }

+ 1 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/event/RedisExpiredPhotographListener.java

@@ -111,7 +111,7 @@ public class RedisExpiredPhotographListener extends KeyExpirationEventMessageLis
             if (labHardware != null && StringUtils.isNotBlank(labHardware.getIpAddress())) {
                 //拼装StreamUrl
                 String streamUrl = StrUtil.format(streamUrlFormat,labHardware.getIpAddress());
-                R<SysFile>  fileR = remoteForwardService.photograph(streamUrl);
+                ResultData<SysFile> fileR = remoteForwardService.photograph(streamUrl);
                 log.info("文件上传状态:{},接口返回消息:{},文件上传路径:{}", fileR.getCode(), fileR.getMsg(), fileR.getData());
                 //调用照片到算法服务,返回结果
                 AlgorithmWarningBo algorithmWarningBo = new AlgorithmWarningBo();

+ 8 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/ILabRiskPlanAbnormalDescService.java

@@ -69,4 +69,12 @@ public interface ILabRiskPlanAbnormalDescService {
      * @return
      */
     int updateLabRiskPlanAbnormalDesc(long groupId, String handledPerson, String recordVideo);
+
+    /**
+     * 更新风险概况
+     * @param groupId
+     * @param recordPhoto
+     * @return
+     */
+    int updateLabRiskPlanAbnormalDesc(long groupId, String recordPhoto);
 }

+ 16 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabRiskPlanAbnormalDescServiceImpl.java

@@ -129,4 +129,20 @@ public class LabRiskPlanAbnormalDescServiceImpl implements ILabRiskPlanAbnormalD
         }
         return 0;
     }
+
+    @Override
+    public int updateLabRiskPlanAbnormalDesc(long groupId, String recordPhoto) {
+        LabRiskPlanAbnormalDesc query = new LabRiskPlanAbnormalDesc();
+        query.setGroupId(groupId);
+        List<LabRiskPlanAbnormalDesc> list = labRiskPlanAbnormalDescMapper.selectByList(query);
+        if (list != null && list.size() > 0) {
+            LabRiskPlanAbnormalDesc desc = list.get(0);
+            desc.setRecordPhoto(recordPhoto);
+            desc.setUpdateTime(new Date());
+            warningNoticeLogService.update(new LambdaUpdateWrapper<WarningNoticeLog>().eq(WarningNoticeLog::getKeyId,groupId)
+                    .set(WarningNoticeLog::getRecordPhoto,recordPhoto));
+            return labRiskPlanAbnormalDescMapper.updateByGroupId(desc);
+        }
+        return 0;
+    }
 }

+ 50 - 19
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabRiskPlanServiceImpl.java

@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zd.algorithm.api.camera.feign.RemoteCameraService;
+import com.zd.algorithm.api.forward.feign.RemoteForwardService;
 import com.zd.algorithm.api.speaker.entity.ParamVo;
 import com.zd.algorithm.api.speaker.entity.PlayVo;
 import com.zd.algorithm.api.speaker.feign.RemoteSpeakService;
@@ -37,6 +38,7 @@ import com.zd.model.constant.BaseConstants;
 import com.zd.model.constant.HttpStatus;
 import com.zd.model.domain.R;
 import com.zd.model.domain.ResultData;
+import com.zd.model.entity.SysFile;
 import com.zd.model.entity.SysUser;
 import com.zd.model.enums.HardwareTypeEnum;
 import com.zd.model.enums.RiskPlanLevelEnum;
@@ -51,6 +53,7 @@ import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
@@ -148,6 +151,12 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
     @Autowired
     private ILabSparseHardwareService labSparseHardwareService;
 
+    @Resource
+    private RemoteForwardService remoteForwardService;
+
+    //目前矿大环测 c111 192.168.1.4 192.168.1.5均使用下面密码
+    private final String streamUrlFormat = "rtsp://admin:bai12345@{}:554/h264/ch1/main/av_stream";
+
     private static final Logger log = LoggerFactory.getLogger(LabRiskPlanServiceImpl.class);
 
 
@@ -647,8 +656,10 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
                 recordNotice(subFunction, labRiskPlanLevel, groupId);
                 //打开喇叭
                 openLoudSpeaker(subFunction.getSubId(), labRiskPlanLevel);
+                //获取摄像头第一帧
+                cutPhoto(subFunction.getSubId(),groupId);
                 //远程调用开始录制视频接口
-                startVideo(subFunction.getSubId());
+                //startVideo(subFunction.getSubId());
                 //向前端发送mqtt预案触发提示
                 messageSendService.riskPlanTriggerNotice();
             } else {
@@ -677,6 +688,26 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
         return flag;
     }
 
+    private void cutPhoto(Long subId, Long groupId) {
+        try {
+            LabHardware labHardware = labHardwareService.selectLabHardwareCameraBySub(subId);
+            if (labHardware != null && labHardware.getIpAddress() != null) {
+                String streamUrl = StrUtil.format(streamUrlFormat,labHardware.getIpAddress());
+                log.info("streamUrl = {}",streamUrl);
+                ResultData<SysFile> photograph = remoteForwardService.photograph(streamUrl);
+                log.info("文件上传状态:{},接口返回消息:{},文件上传路径:{}", photograph.getCode(), photograph.getMsg(), photograph.getData());
+                //更新风险概要  recordPhoto - 视频图片存放地址
+                String url = "statics/2023/11/23/87dfcc76-a75d-471d-ac79-90333f36b622.jpg";
+                labRiskPlanAbnormalDescService.updateLabRiskPlanAbnormalDesc(groupId, url);
+                //labRiskPlanAbnormalDescService.updateLabRiskPlanAbnormalDesc(groupId, photograph.getData().getUrl());
+            } else {
+                log.info("未查询到实验室关联摄像头信息!请检查ip是否为空!");
+            }
+        } catch (Exception e) {
+            log.error("远程调用截取图片接口异常!{}", e);
+        }
+    }
+
     /**
      * 更新结束预案日志
      *
@@ -748,24 +779,24 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
     private void stopVideoAndRecordLog(Long subjectId, Long groupId) {
         //关闭视频录像
         String recordVideo = "";
-        try {
-            LabHardware labHardware = labHardwareService.selectLabHardwareCameraBySub(subjectId);
-            if (labHardware != null) {
-                //开始录制视频
-                log.info("远程调用关闭视频ip地址={}", labHardware.getIpAddress());
-                R r = remoteCameraService.stopRecord(labHardware.getIpAddress());
-                log.info("录制视频结束返回结果打印={}", JSON.toJSONString(r));
-                if (r.getCode() == HttpStatus.SUCCESS) {
-                    recordVideo = String.valueOf(r.getData());
-                } else {
-                    log.info("结束录制视频失败!");
-                }
-            } else {
-                log.info("未查询到实验室关联摄像头信息!请检查ip是否为空!");
-            }
-        } catch (Exception e) {
-            log.error("远程调用结束录制视频接口异常!{}", e);
-        }
+//        try {
+//            LabHardware labHardware = labHardwareService.selectLabHardwareCameraBySub(subjectId);
+//            if (labHardware != null) {
+//                //开始录制视频
+//                log.info("远程调用关闭视频ip地址={}", labHardware.getIpAddress());
+//                R r = remoteCameraService.stopRecord(labHardware.getIpAddress());
+//                log.info("录制视频结束返回结果打印={}", JSON.toJSONString(r));
+//                if (r.getCode() == HttpStatus.SUCCESS) {
+//                    recordVideo = String.valueOf(r.getData());
+//                } else {
+//                    log.info("结束录制视频失败!");
+//                }
+//            } else {
+//                log.info("未查询到实验室关联摄像头信息!请检查ip是否为空!");
+//            }
+//        } catch (Exception e) {
+//            log.error("远程调用结束录制视频接口异常!{}", e);
+//        }
         //更新风险概要  recordVideo - 视频记录存放地址
         String handlePerson = "";
         if (!Objects.isNull(tokenService.getLoginUser())) {

+ 7 - 1
zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabRiskPlanAbnormalDescMapper.xml

@@ -13,6 +13,7 @@
         <result column="handled_person" property="handledPerson" />
         <result column="internal_person" property="internalPerson" />
         <result column="record_video" property="recordVideo" />
+        <result column="record_photo" property="recordPhoto" />
         <result column="create_time" property="createTime" />
         <result column="create_by" property="createBy" />
         <result column="update_time" property="updateTime" />
@@ -21,7 +22,7 @@
 
     <!-- 通用查询结果列 -->
     <sql id="selectBaseColumn">
-        select desc_id, group_id, risk_reason, risk_level, start_date, end_date, risk_duration, internal_person, handled_person, record_video, create_time, create_by, update_time, update_by from lab_risk_plan_abnormal_desc
+        select desc_id, group_id, risk_reason, risk_level, start_date, end_date, risk_duration, internal_person, handled_person, record_video, record_photo, create_time, create_by, update_time, update_by from lab_risk_plan_abnormal_desc
     </sql>
 
     <insert id="insert" parameterType="com.zd.laboratory.domain.LabRiskPlanAbnormalDesc">
@@ -36,6 +37,7 @@
         <if test="handledPerson != null and handledPerson != ''">handled_person,</if>
         <if test="internalPerson != null and internalPerson != ''">internal_person,</if>
         <if test="recordVideo != null and recordVideo != ''">record_video,</if>
+        <if test="recordPhoto != null and recordPhoto != ''">record_photo,</if>
         <if test="createBy != null and createBy != ''">create_by,</if>
         <if test="updateTime != null">update_time,</if>
         <if test="updateBy !=null and updateBy != ''">update_by,</if>
@@ -51,6 +53,7 @@
         <if test="handledPerson != null and handledPerson != ''">#{handledPerson},</if>
         <if test="internalPerson != null and internalPerson != ''">#{internalPerson},</if>
         <if test="recordVideo != null and recordVideo != ''">#{recordVideo},</if>
+        <if test="recordPhoto != null and recordPhoto != ''">#{recordPhoto},</if>
         <if test="createBy != null and createBy != ''">#{createBy},</if>
         <if test="updateTime != null">#{updateTime},</if>
         <if test="updateBy !=null and updateBy != ''">#{updateBy},</if>
@@ -70,6 +73,7 @@
             <if test="handledPerson != null and handledPerson != ''">handled_person = #{handledPerson},</if>
             <if test="internalPerson != null and internalPerson != ''">internal_person = #{internalPerson},</if>
             <if test="recordVideo != null and recordVideo != ''">record_video = #{recordVideo},</if>
+            <if test="recordPhoto != null and recordPhoto != ''">record_photo = #{recordPhoto},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
             <if test="updateBy !=null and updateBy != ''">update_by = #{updateBy},</if>
@@ -89,6 +93,7 @@
             <if test="handledPerson != null and handledPerson != ''">handled_person = #{handledPerson},</if>
             <if test="internalPerson != null and internalPerson != ''">internal_person = #{internalPerson},</if>
             <if test="recordVideo != null and recordVideo != ''">record_video = #{recordVideo},</if>
+            <if test="recordPhoto != null and recordPhoto != ''">record_photo = #{recordPhoto},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
             <if test="updateBy !=null and updateBy != ''">update_by = #{updateBy},</if>
@@ -117,6 +122,7 @@
             <if test="riskDuration != null and riskDuration != ''">AND risk_duration = #{riskDuration}</if>
             <if test="handledPerson != null and handledPerson != ''">AND handled_person LIKE concat('%', #{handledPerson}, '%'),</if>
             <if test="recordVideo != null and recordVideo != ''">AND record_video = #{recordVideo}</if>
+            <if test="recordPhoto != null and recordPhoto != ''">AND record_photo = #{recordPhoto}</if>
             <if test="createTime != null">AND create_time = #{createTime},</if>
             <if test="createBy != null and createBy != ''">AND create_by = #{createBy}</if>
             <if test="updateTime != null">AND update_time = #{updateTime}</if>