소스 검색

心跳接口修改

gao.qiang 1 년 전
부모
커밋
f991de735c

+ 53 - 0
business-service/src/main/java/com/ozs/entity/PreAlarm.java

@@ -0,0 +1,53 @@
+package com.ozs.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ozs.common.core.domain.BaseEntity;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author Administrator
+ * 预警信息
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class PreAlarm extends BaseEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+    /**
+     * 车号
+     */
+    private Integer  trainId;
+    /**
+     * 预警类型
+     */
+    private Integer  preAlarmType;
+    /**
+     * 预警时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date preAlarmTime;
+    /**
+     * 预警目标个数
+     */
+    private Integer preAlarmNum;
+    /**
+     * 预警目标数据组
+     */
+    private String preAlarmList;
+}

+ 36 - 0
business-service/src/main/java/com/ozs/entity/response/PreAlarmListResponse.java

@@ -0,0 +1,36 @@
+package com.ozs.entity.response;
+
+import lombok.Data;
+
+/**
+ * @author Administrator
+ */
+@Data
+public class PreAlarmListResponse {
+
+    /**
+     * 预警目标点类型
+     */
+    private Integer targetType;
+    /**
+     * 预警级别
+     */
+    private Integer level;
+    /**
+     * 目标点离机车的距离
+     */
+    private Integer distance;
+    /**
+     * 预警内容
+     */
+    private String  content;
+
+    /**
+     * 前方相机/报警相机(实时播放流)
+     */
+    private String cameraStream;
+    /**
+     * 当前播放的相机编码
+     */
+    private String cameraCode;
+}

+ 53 - 0
business-service/src/main/java/com/ozs/entity/response/PreAlarmResponse.java

@@ -0,0 +1,53 @@
+package com.ozs.entity.response;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author Administrator
+ */
+@Data
+public class PreAlarmResponse {
+    /**
+     * 机车号
+     */
+    private Integer trainId;
+    /**
+     * 预警病害类型
+     */
+    private Integer preAlarmType;
+    /**
+     * 预警目标个数
+     */
+    private Integer preAlarmNum;
+    /**
+     * 预警时间
+     */
+    private Long preAlarmTime;
+    /**
+     * 预警目标集合
+     */
+    private List<PreAlarmList> preAlarmList;
+
+
+    @Data
+    public static class  PreAlarmList{
+        /**
+         * 预警目标点类型
+         */
+        private Integer targetType;
+        /**
+         * 预警级别
+         */
+        private Integer level;
+        /**
+         * 目标点离机车的距离
+         */
+        private Integer distance;
+        /**
+         * 预警内容
+         */
+        private String  content;
+    }
+}

+ 6 - 0
business-service/src/main/java/com/ozs/entity/vo/RespHeartbeatVo.java

@@ -1,5 +1,7 @@
 package com.ozs.entity.vo;
 
+import com.ozs.entity.response.PreAlarmListResponse;
+import com.ozs.entity.response.PreAlarmResponse;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -34,4 +36,8 @@ public class RespHeartbeatVo implements Serializable {
      * 车站编码
      */
     private String stationCode;
+    /**
+     * 预警集合
+     */
+    private List<PreAlarmListResponse> preAlarmList;
 }

+ 13 - 0
business-service/src/main/java/com/ozs/mapper/PreAlarmMapper.java

@@ -0,0 +1,13 @@
+package com.ozs.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ozs.entity.PreAlarm;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author Administrator
+ * 预警信息
+ */
+@Mapper
+public interface PreAlarmMapper extends BaseMapper<PreAlarm> {
+}

+ 11 - 0
business-service/src/main/java/com/ozs/service/PreAlarmService.java

@@ -0,0 +1,11 @@
+package com.ozs.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ozs.entity.PreAlarm;
+
+/**
+ * @author Administrator
+ * 预警信息
+ */
+public interface PreAlarmService extends IService<PreAlarm> {
+}

+ 15 - 0
business-service/src/main/java/com/ozs/service/impl/PreAlarmServiceImpl.java

@@ -0,0 +1,15 @@
+package com.ozs.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ozs.entity.PreAlarm;
+import com.ozs.mapper.PreAlarmMapper;
+import com.ozs.service.PreAlarmService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author Administrator
+ * 预警信息
+ */
+@Service
+public class PreAlarmServiceImpl extends ServiceImpl<PreAlarmMapper, PreAlarm> implements PreAlarmService {
+}

+ 4 - 0
business-service/src/main/resources/mapper/PreAlarmMapper.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ozs.mapper.PreAlarmMapper">
+</mapper>

+ 263 - 9
vehicle-sdk/src/main/java/com/ozs/controller/upload/GeoHazardMonitorTokenController.java

@@ -28,10 +28,13 @@ import com.ozs.entity.MsgAlarm;
 import com.ozs.entity.MsgAlarmExt;
 import com.ozs.entity.MsgAlarmFrequency;
 import com.ozs.entity.MsgHeartbeatAlarmMessage;
+import com.ozs.entity.PreAlarm;
 import com.ozs.entity.SkynetHeartbeatLog;
 import com.ozs.entity.SvcAddress;
 import com.ozs.entity.TerminalIgnoreAlarm;
 import com.ozs.entity.VehiclePosition;
+import com.ozs.entity.response.PreAlarmListResponse;
+import com.ozs.entity.response.PreAlarmResponse;
 import com.ozs.entity.vo.AlarmFilesVo;
 import com.ozs.entity.vo.AlarmHeartbeatLog;
 import com.ozs.entity.vo.AlarmInfoVo;
@@ -66,6 +69,7 @@ import com.ozs.service.BaseVideoTrainsService;
 import com.ozs.service.MsgAlarmExtService;
 import com.ozs.service.MsgAlarmFrequencyService;
 import com.ozs.service.MsgAlarmService;
+import com.ozs.service.PreAlarmService;
 import com.ozs.service.SvcAddressService;
 import com.ozs.service.TerminalIgnoreAlarmService;
 import com.ozs.service.VehiclePositionService;
@@ -163,6 +167,8 @@ public class GeoHazardMonitorTokenController {
     private RedisCache redisCache;
     @Autowired
     private BaseVideoTrainsService baseVideoTrainsService;
+    @Resource
+    private PreAlarmService preAlarmService;
 
     /**
      * 获取web访问令牌
@@ -241,10 +247,6 @@ public class GeoHazardMonitorTokenController {
             }
             String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
             ReqMsgAlarmVo reqMsgAlarmVo = JSON.parseObject(s, ReqMsgAlarmVo.class);
-            if (ObjectUtils.isEmpty(reqMsgAlarmVo.getAlarmAttr())) {
-                AjaxResults1 = new AjaxResults(0, "你填写的报警病害属性不符合规则");
-                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
-            }
             if (!reqMsgAlarmVo.getAlarmMile().toString().matches(PATTERNS)) {
                 AjaxResults1 = new AjaxResults(0, "报警里程位置填写错误");
                 return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
@@ -522,7 +524,7 @@ public class GeoHazardMonitorTokenController {
                 return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
             }
             if (ObjectUtils.isEmpty(heartbeatVo.getLongitude())) {
-                AjaxResults1 = new AjaxResults(0, "当前所在度不能为空");
+                AjaxResults1 = new AjaxResults(0, "当前所在度不能为空");
                 return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
             }
             LambdaQueryWrapper<BaseRailwayManagement> railway = new LambdaQueryWrapper<BaseRailwayManagement>();
@@ -592,6 +594,10 @@ public class GeoHazardMonitorTokenController {
                 queryWrapper.eq(MsgAlarm::getIsRelease, 2);
                 List<MsgAlarm> alarmsList = msgAlarmService.list(queryWrapper);
                 //根据终端编码 判断终端忽略报警信息记录表中的是否有忽略的报警
+                PreAlarm preAlarm = preAlarmService.getOne(new LambdaQueryWrapper<PreAlarm>()
+                        .eq(PreAlarm::getTrainId, heartbeatVo.getTrainNum())
+                        .orderByDesc(PreAlarm::getPreAlarmTime)
+                        .last("limit 1"));
                 if (!ObjectUtils.isEmpty(alarmsList)) {
                     // 获取当前时间
                     LocalDateTime currentDateTime = LocalDateTime.now();
@@ -687,7 +693,7 @@ public class GeoHazardMonitorTokenController {
                             }
                             log.info("-------playFlv--------" + playFlv1);
                             CameraVos cameraVos = new CameraVos();
-                            cameraVos.setCameraCode(baseCameraManagementList.get(0).getCameraCode());
+                            cameraVos.setCameraCode(code);
                             cameraVos.setCurrentStream(playFlv1);
                             List<CameraVos> cameraVosList = new ArrayList<>();
                             cameraVosList.add(cameraVos);
@@ -695,6 +701,9 @@ public class GeoHazardMonitorTokenController {
                             respHeartbeatVo.setIsAlarm(1);
                             twoMap.put("currentStream", playFlv1);
                             twoMap.put("cameraCode", baseCameraManagementList.get(0).getCameraCode());
+                        } else {
+                            AjaxResults1 = new AjaxResults(0, "报警里程无可用相机",respHeartbeatVo);
+                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
                         }
                         for (int i = 0; i < list.size(); i++) {
                             MsgHeartbeatAlarmMessage msgHearbeatAlarmMessage = new MsgHeartbeatAlarmMessage();
@@ -809,6 +818,87 @@ public class GeoHazardMonitorTokenController {
                                 }
                             }
                         }
+                    }else if (!ObjectUtils.isEmpty(preAlarm)) {
+                        List<PreAlarmListResponse> responseList = new ArrayList<>();
+                        List<PreAlarmResponse.PreAlarmList> preAlarmList = JSON.parseArray(preAlarm.getPreAlarmList(), PreAlarmResponse.PreAlarmList.class);
+                        Comparator<PreAlarmResponse.PreAlarmList> distanceComparator = new Comparator<PreAlarmResponse.PreAlarmList>() {
+                            @Override
+                            public int compare(PreAlarmResponse.PreAlarmList o1, PreAlarmResponse.PreAlarmList o2) {
+                                return Integer.compare(o1.getDistance(), o2.getDistance());
+                            }
+                        };
+                        //排序
+                        preAlarmList.sort(distanceComparator);
+                        for (int i = 0; i < preAlarmList.size(); i++) {
+                            int mile=0;
+                            LambdaQueryWrapper<BaseCameraManagement> wrapper1 = new LambdaQueryWrapper<BaseCameraManagement>();
+                            if (heartbeatVo.getLineDir() == 1) {
+                                mile = preAlarmList.get(i).getDistance() + heartbeatVo.getCurrentMile();
+                                wrapper1.ge(BaseCameraManagement::getEndMile, mile);
+                                wrapper1.le(BaseCameraManagement::getBeginMile, mile);
+                                wrapper1.in(BaseCameraManagement::getMonitoringDirection, 1, 3);
+                                wrapper1.orderByAsc(BaseCameraManagement::getGrou).orderByAsc(BaseCameraManagement::getSort);
+                            }
+                            if (heartbeatVo.getLineDir() == 2) {
+                                mile = heartbeatVo.getCurrentMile() - preAlarmList.get(i).getDistance();
+                                wrapper1.ge(BaseCameraManagement::getEndMile, mile);
+                                wrapper1.le(BaseCameraManagement::getBeginMile, mile);
+                                wrapper1.in(BaseCameraManagement::getMonitoringDirection, 2, 3);
+                                wrapper1.orderByDesc(BaseCameraManagement::getGrou).orderByDesc(BaseCameraManagement::getSort);
+                            }
+                            List<BaseCameraManagement> baseCameraManagementList = baseCameraManagementService.list(wrapper1);
+                            log.info("-------baseCameraManagementList123111--------" + baseCameraManagementList);
+                            if (baseCameraManagementList.size() > 0) {
+                                int minDifference = Integer.MAX_VALUE;
+                                String code = null;
+                                String channel = null;
+                                for (BaseCameraManagement baseCameraManagement : baseCameraManagementList) {
+                                    log.info("------------baseCameraManagement.getInstallMile()-------" + baseCameraManagement.getInstallMile());
+                                    log.info("------------list.get(0).getAlarmMile()-------" + mile);
+                                    int difference = Math.abs(baseCameraManagement.getInstallMile() - mile);
+                                    log.info("------------difference-------" + difference);
+                                    log.info("------------minDifference-------" + minDifference);
+                                    if (difference < minDifference) {
+                                        minDifference = difference;
+                                        log.info("------------minDifference变更-------" + minDifference);
+                                        code = baseCameraManagement.getCameraCode();
+                                        log.info("------------code-------" + code);
+                                        channel = baseCameraManagement.getChannel();
+                                        log.info("------------channel-------" + channel);
+                                    }
+                                    //添加预警信息
+                                    PreAlarmListResponse preAlarmListResponse = new PreAlarmListResponse();
+                                    BeanUtils.copyProperties(preAlarmList.get(i), preAlarmListResponse);
+                                    preAlarmListResponse.setCameraCode(baseCameraManagement.getCameraCode());
+                                    preAlarmListResponse.setCameraStream(cameraUtil.heartbeatgetPlayFlv(baseCameraManagement.getCameraCode(), baseCameraManagement.getChannel(), type));
+                                    responseList.add(preAlarmListResponse);
+                                }
+                                if (i == 0) {
+                                    playFlv1 =cameraUtil.heartbeatgetPlayFlv(code, channel, type);
+                                    if (StringUtils.isEmpty(playFlv1)) {
+                                        playFlv1 = cameraUtil.heartbeatgetUrl(code, channel, type);
+                                        if (playFlv1.contains("无视频")) {
+                                            AjaxResults1 = new AjaxResults(0, playFlv1);
+                                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+                                        }
+                                    }
+                                    log.info("-------playFlv--------" + playFlv1);
+                                    CameraVos cameraVos = new CameraVos();
+                                    cameraVos.setCameraCode(code);
+                                    cameraVos.setCurrentStream(playFlv1);
+                                    List<CameraVos> cameraVosList = new ArrayList<>();
+                                    cameraVosList.add(cameraVos);
+                                    respHeartbeatVo.setCameraList(cameraVosList);
+                                    respHeartbeatVo.setIsAlarm(2);
+                                    twoMap.put("currentStream", playFlv1);
+                                    twoMap.put("cameraCode", baseCameraManagementList.get(0).getCameraCode());
+                                }
+                            }else {
+                                AjaxResults1 = new AjaxResults(0, "前方没有摄像机",respHeartbeatVo);
+                                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+                            }
+                        }
+                        respHeartbeatVo.setPreAlarmList(responseList);
                     } else {
                         //没有报警信息的时候
                         if (heartbeatVo.getLineDir() == 1) {
@@ -831,6 +921,10 @@ public class GeoHazardMonitorTokenController {
                         camera.eq(BaseCameraManagement::getEnableOrNot, 1);
                         camera.last("limit 2");
                         List<BaseCameraManagement> list1 = baseCameraManagementService.list(camera);
+                        if (list1.size() <= 0) {
+                            AjaxResults1 = new AjaxResults(0, "前方没有摄像机",respHeartbeatVo);
+                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+                        }
                         log.info("流程1----------------->");
                         //判断流媒体是否有流
                         String playFlv = cameraUtil.heartbeatgetPlayFlv(list1.get(0).getCameraCode(), list1.get(0).getChannel(), type);
@@ -855,13 +949,12 @@ public class GeoHazardMonitorTokenController {
                         if (StringUtils.isEmpty(playFlv)) {
                             log.info("--------------->>已进入拉两路视频");
                             for (BaseCameraManagement baseCameraManagement : list1) {
-                                boolean finalType = type;
                                 List<BaseCameraManagement> baseCameraManagementList1 = cameraUtil.getBaseCameraManagementList(baseCameraManagement.getId(), heartbeatVo.getLineDir());
                                 if (!ObjectUtils.isEmpty(baseCameraManagementList1)) {
                                     for (BaseCameraManagement cameraManagement : baseCameraManagementList1) {
-                                        String flv = cameraUtil.heartbeatgetPlayFlv(cameraManagement.getCameraCode(), cameraManagement.getChannel(), finalType);
+                                        String flv = cameraUtil.heartbeatgetPlayFlv(cameraManagement.getCameraCode(), cameraManagement.getChannel(), type);
                                         if (StringUtils.isEmpty(flv)) {
-                                            String url = cameraUtil.heartbeatgetUrl(cameraManagement.getCameraCode(), cameraManagement.getChannel(), finalType);
+                                            String url = cameraUtil.heartbeatgetUrl(cameraManagement.getCameraCode(), cameraManagement.getChannel(), type);
                                             if (url.contains("无视频")) {
                                                 AjaxResults1 = new AjaxResults(0, url);
                                                 return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
@@ -915,6 +1008,87 @@ public class GeoHazardMonitorTokenController {
                         twoMap.put("cameraCode", list1.get(0).getCameraCode());
                         respHeartbeatVo.setIsAlarm(2);
                     }
+                }else if (!ObjectUtils.isEmpty(preAlarm)) {
+                    List<PreAlarmListResponse> responseList = new ArrayList<>();
+                    List<PreAlarmResponse.PreAlarmList> preAlarmList = JSON.parseArray(preAlarm.getPreAlarmList(), PreAlarmResponse.PreAlarmList.class);
+                    Comparator<PreAlarmResponse.PreAlarmList> distanceComparator = new Comparator<PreAlarmResponse.PreAlarmList>() {
+                        @Override
+                        public int compare(PreAlarmResponse.PreAlarmList o1, PreAlarmResponse.PreAlarmList o2) {
+                            return Integer.compare(o1.getDistance(), o2.getDistance());
+                        }
+                    };
+                    //排序
+                    preAlarmList.sort(distanceComparator);
+                    for (int i = 0; i < preAlarmList.size(); i++) {
+                        int mile=0;
+                        LambdaQueryWrapper<BaseCameraManagement> wrapper1 = new LambdaQueryWrapper<BaseCameraManagement>();
+                        if (heartbeatVo.getLineDir() == 1) {
+                            mile = preAlarmList.get(i).getDistance() + heartbeatVo.getCurrentMile();
+                            wrapper1.ge(BaseCameraManagement::getEndMile, mile);
+                            wrapper1.le(BaseCameraManagement::getBeginMile, mile);
+                            wrapper1.in(BaseCameraManagement::getMonitoringDirection, 1, 3);
+                            wrapper1.orderByAsc(BaseCameraManagement::getGrou).orderByAsc(BaseCameraManagement::getSort);
+                        }
+                        if (heartbeatVo.getLineDir() == 2) {
+                            mile = heartbeatVo.getCurrentMile() - preAlarmList.get(i).getDistance();
+                            wrapper1.ge(BaseCameraManagement::getEndMile, mile);
+                            wrapper1.le(BaseCameraManagement::getBeginMile, mile);
+                            wrapper1.in(BaseCameraManagement::getMonitoringDirection, 2, 3);
+                            wrapper1.orderByDesc(BaseCameraManagement::getGrou).orderByDesc(BaseCameraManagement::getSort);
+                        }
+                        List<BaseCameraManagement> baseCameraManagementList = baseCameraManagementService.list(wrapper1);
+                        log.info("-------baseCameraManagementList123111--------" + baseCameraManagementList);
+                        if (baseCameraManagementList.size() > 0) {
+                            int minDifference = Integer.MAX_VALUE;
+                            String code = null;
+                            String channel = null;
+                            for (BaseCameraManagement baseCameraManagement : baseCameraManagementList) {
+                                log.info("------------baseCameraManagement.getInstallMile()-------" + baseCameraManagement.getInstallMile());
+                                log.info("------------list.get(0).getAlarmMile()-------" + mile);
+                                int difference = Math.abs(baseCameraManagement.getInstallMile() - mile);
+                                log.info("------------difference-------" + difference);
+                                log.info("------------minDifference-------" + minDifference);
+                                if (difference < minDifference) {
+                                    minDifference = difference;
+                                    log.info("------------minDifference变更-------" + minDifference);
+                                    code = baseCameraManagement.getCameraCode();
+                                    log.info("------------code-------" + code);
+                                    channel = baseCameraManagement.getChannel();
+                                    log.info("------------channel-------" + channel);
+                                }
+                                //添加预警信息
+                                PreAlarmListResponse preAlarmListResponse = new PreAlarmListResponse();
+                                BeanUtils.copyProperties(preAlarmList.get(i), preAlarmListResponse);
+                                preAlarmListResponse.setCameraCode(baseCameraManagement.getCameraCode());
+                                preAlarmListResponse.setCameraStream(cameraUtil.heartbeatgetPlayFlv(baseCameraManagement.getCameraCode(), baseCameraManagement.getChannel(), type));
+                                responseList.add(preAlarmListResponse);
+                            }
+                            if (i == 0) {
+                                playFlv1 =cameraUtil.heartbeatgetPlayFlv(code, channel, type);
+                                if (StringUtils.isEmpty(playFlv1)) {
+                                    playFlv1 = cameraUtil.heartbeatgetUrl(code, channel, type);
+                                    if (playFlv1.contains("无视频")) {
+                                        AjaxResults1 = new AjaxResults(0, playFlv1);
+                                        return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+                                    }
+                                }
+                                log.info("-------playFlv--------" + playFlv1);
+                                CameraVos cameraVos = new CameraVos();
+                                cameraVos.setCameraCode(code);
+                                cameraVos.setCurrentStream(playFlv1);
+                                List<CameraVos> cameraVosList = new ArrayList<>();
+                                cameraVosList.add(cameraVos);
+                                respHeartbeatVo.setCameraList(cameraVosList);
+                                respHeartbeatVo.setIsAlarm(2);
+                                twoMap.put("currentStream", playFlv1);
+                                twoMap.put("cameraCode", baseCameraManagementList.get(0).getCameraCode());
+                            }
+                        }else {
+                            AjaxResults1 = new AjaxResults(0, "前方没有摄像机",respHeartbeatVo);
+                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+                        }
+                    }
+                    respHeartbeatVo.setPreAlarmList(responseList);
                 } else {
                     //没有报警信息的时候
                     LambdaQueryWrapper<BaseCameraManagement> base = new LambdaQueryWrapper<>();
@@ -937,6 +1111,10 @@ public class GeoHazardMonitorTokenController {
                     base.eq(BaseCameraManagement::getEnableOrNot, 1);
                     base.last("limit 2");
                     List<BaseCameraManagement> list1 = baseCameraManagementService.list(base);
+                    if (list1.size() <= 0) {
+                        AjaxResults1 = new AjaxResults(0, "前方没有摄像机",respHeartbeatVo);
+                        return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+                    }
                     log.info("流程2----------------->");
                     //判断流媒体是否有流
                     String playFlv = cameraUtil.heartbeatgetPlayFlv(list1.get(0).getCameraCode(), list1.get(0).getChannel(), type);
@@ -1594,6 +1772,82 @@ public class GeoHazardMonitorTokenController {
         }
     }
 
+
+    /**
+     * 预警信息接口定义
+     */
+    @PostMapping("/api/preAlarm")
+    public String preAlarm(@RequestBody ParameterVo parameterVo, HttpServletRequest request) {
+        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
+        log.info("token:{}", token);
+        log.info("parameterVo:{}", parameterVo);
+        AjaxResults AjaxResults1 = null;
+        if (StringUtils.isNotEmpty(token)) {
+            String[] split = token.split("-");
+            String key = split[split.length - 1];
+            if (ObjectUtils.isEmpty(parameterVo)) {
+                AjaxResults1 = new AjaxResults(0, "parameterVo参数不能为空");
+                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+            }
+            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
+            PreAlarmResponse preAlarmResponse = JSON.parseObject(s, PreAlarmResponse.class);
+            if (ObjectUtils.isEmpty(preAlarmResponse.getTrainId())) {
+                AjaxResults1 = new AjaxResults(0, "机车号不能为空");
+                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+            }
+            if (ObjectUtils.isEmpty(preAlarmResponse.getPreAlarmType())) {
+                AjaxResults1 = new AjaxResults(0, "预警病害类型不能为空");
+                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+            }
+            if (ObjectUtils.isEmpty(preAlarmResponse.getPreAlarmNum())) {
+                AjaxResults1 = new AjaxResults(0, "预警目标个数不难为空");
+                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+            }
+            if (ObjectUtils.isEmpty(preAlarmResponse.getPreAlarmTime())) {
+                AjaxResults1 = new AjaxResults(0, "预警时间不难为空");
+                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+            }
+            if (ObjectUtils.isEmpty(preAlarmResponse.getPreAlarmList())) {
+                AjaxResults1 = new AjaxResults(0, "预警目标集合不难为空");
+                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+            }
+            for (PreAlarmResponse.PreAlarmList preAlarmList : preAlarmResponse.getPreAlarmList()) {
+                if (ObjectUtils.isEmpty(preAlarmList.getContent())) {
+                    AjaxResults1 = new AjaxResults(0, "预警内容不难为空");
+                    return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+                }
+                if (ObjectUtils.isEmpty(preAlarmList.getDistance())) {
+                    AjaxResults1 = new AjaxResults(0, "目标点离机车的距离不难为空");
+                    return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+                }
+                if (ObjectUtils.isEmpty(preAlarmList.getLevel())) {
+                    AjaxResults1 = new AjaxResults(0, "预警级别不难为空");
+                    return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+                }
+                if (ObjectUtils.isEmpty(preAlarmList.getTargetType())) {
+                    AjaxResults1 = new AjaxResults(0, "预警目标点类型不难为空");
+                    return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+                }
+            }
+            PreAlarm preAlarm = new PreAlarm();
+            preAlarm.setTrainId(preAlarmResponse.getTrainId());
+            preAlarm.setPreAlarmNum(preAlarmResponse.getPreAlarmNum());
+            preAlarm.setPreAlarmTime(new Date(preAlarmResponse.getPreAlarmTime()));
+            preAlarm.setPreAlarmType(preAlarmResponse.getPreAlarmType());
+            preAlarm.setPreAlarmList(JSON.toJSONString(preAlarmResponse.getPreAlarmList()));
+            if (preAlarmService.save(preAlarm)) {
+                AjaxResults1 = new AjaxResults(1, "ok");
+                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+            } else {
+                AjaxResults1 = new AjaxResults(0, "新增失败");
+                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(AjaxResults1), key);
+            }
+        } else {
+            AjaxResults1 = new AjaxResults(2, "token验证失败");
+            return JSONObject.toJSONString(AjaxResults1);
+        }
+    }
+
     @GetMapping("/test/{key}")
     public void test(@PathVariable String key) {
         String heartbeat = heartbeatUtils.getHeartbeat(key);