package com.ozs.controller.upload;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ozs.common.core.domain.AjaxResult;
import com.ozs.common.core.domain.entity.SysDictData;
import com.ozs.common.core.redis.RedisCache;
import com.ozs.common.utils.ApiTokenUtils;
import com.ozs.common.utils.AppendUtils;
import com.ozs.common.utils.ChineseToPingyin;
import com.ozs.common.utils.HeartbeatUtils;
import com.ozs.common.utils.HttpClientUtil;
import com.ozs.common.utils.IgnoreUtils;
import com.ozs.common.utils.StringUtils;
import com.ozs.common.utils.stateSecrets.SM4Utils;
import com.ozs.config.Constant;
import com.ozs.entity.BaseCameraManagement;
import com.ozs.entity.BaseRailwayManagement;
import com.ozs.entity.BaseRouteMassage;
import com.ozs.entity.BaseTerminal;
import com.ozs.entity.BaseUser;
import com.ozs.entity.BaseVehicleTerminal;
import com.ozs.entity.MsgAlarm;
import com.ozs.entity.MsgAlarmExt;
import com.ozs.entity.MsgAlarmFrequency;
import com.ozs.entity.MsgHeartbeatAlarmMessage;
import com.ozs.entity.SkynetHeartbeatLog;
import com.ozs.entity.SvcAddress;
import com.ozs.entity.TerminalHeartbeatLog;
import com.ozs.entity.TerminalIgnoreAlarm;
import com.ozs.entity.VehiclePosition;
import com.ozs.entity.vo.AlarmFilesVo;
import com.ozs.entity.vo.AlarmHeartbeatLog;
import com.ozs.entity.vo.AlarmInfoVo;
import com.ozs.entity.vo.AlarmListVo;
import com.ozs.entity.vo.CameraPlayVo;
import com.ozs.entity.vo.CameraVo;
import com.ozs.entity.vo.CameraVos;
import com.ozs.entity.vo.CamerasVo;
import com.ozs.entity.vo.Files;
import com.ozs.entity.vo.HeartbeatVo;
import com.ozs.entity.vo.ParameterVo;
import com.ozs.entity.vo.QueryAlarmVo;
import com.ozs.entity.vo.ReleaseAlarmVo;
import com.ozs.entity.vo.ReqMsgAlarmVo;
import com.ozs.entity.vo.RespAlarmList;
import com.ozs.entity.vo.RespCameraVo;
import com.ozs.entity.vo.RespGeoHazardMonitorVo;
import com.ozs.entity.vo.RespHeartbeatVo;
import com.ozs.entity.vo.SkynetHeartbeatVo;
import com.ozs.entity.vo.TerminalIgnoreVo;
import com.ozs.mapper.AlarmHeartbeatLogMapper;
import com.ozs.mapper.MsgHeartbeatAlarmMessageMapper;
import com.ozs.mapper.SkynetHeartbeatLogMapper;
import com.ozs.service.BaseCameraManagementService;
import com.ozs.service.BaseRailwayManagementService;
import com.ozs.service.BaseRouteMassageService;
import com.ozs.service.BaseTerminalService;
import com.ozs.service.BaseUserService;
import com.ozs.service.BaseVehicleTerminalService;
import com.ozs.service.MsgAlarmExtService;
import com.ozs.service.MsgAlarmFrequencyService;
import com.ozs.service.MsgAlarmService;
import com.ozs.service.SvcAddressService;
import com.ozs.service.TerminalHeartbeatLogService;
import com.ozs.service.TerminalIgnoreAlarmService;
import com.ozs.service.VehiclePositionService;
import com.ozs.system.service.ISysDictDataService;
import com.ozs.system.service.ISysDictTypeService;
import com.ozs.utils.CameraUtil;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 1. 获取身份认证控制层
 *
 * @author Administrator
 */
@RestController
@Slf4j
@CrossOrigin(origins = "*")
public class GeoHazardMonitorTokenController {
    public static final String PATTERN = "^([0-9]+),([0-9]+),([0-9]+),([0-9]+),([0-9]+),([0-9]+)$";
    public static final String PATTERNS = "^[0-9]*$";

    public static final String KEY = "58792429c08c43e9";
    @Resource
    private ApiTokenUtils apiTokenUtils;
    @Autowired
    MsgAlarmService msgAlarmService;
    @Autowired
    MsgAlarmFrequencyService msgAlarmFrequencyService;
    @Autowired
    SvcAddressService svcAddressService;
    @Autowired
    BaseCameraManagementService baseCameraManagementService;
    @Autowired
    private BaseUserService baseUserService;
    @Autowired
    private MsgAlarmExtService msgAlarmExtService;
    @Autowired
    private BaseVehicleTerminalService baseVehicleTerminalService;
    @Autowired
    private VehiclePositionService vehiclePositionService;
    @Autowired
    private HeartbeatUtils heartbeatUtils;
    @Autowired
    private TerminalIgnoreAlarmService terminalIgnoreAlarmService;
    @Autowired
    private IgnoreUtils ignoreUtils;
    @Autowired
    private BaseRailwayManagementService baseRailwayManagementService;
    @Autowired
    private BaseTerminalService baseTerminalService;
    @Autowired
    private CameraUtil cameraUtil;
    @Resource
    private SkynetHeartbeatLogMapper synetHeartbeatLogMapper;
    @Resource
    private AlarmHeartbeatLogMapper alarmHeartbeatLogMapper;
    @Resource
    private MsgHeartbeatAlarmMessageMapper msgHearbeatAlarmMessageMapper;
    @Resource
    private BaseRouteMassageService baseRouteMassageService;

    @Value("${base.env}")
    private String env;
    @Value("${sdk.publish}")
    private String sdkUrl;
    @Autowired
    private ISysDictTypeService dictTypeService;
    @Resource
    private TerminalHeartbeatLogService terminalHeartbeatLogService;
    @Autowired
    private RedisCache redisCache;

    /**
     * 获取web访问令牌
     *
     * @return
     */
    @PostMapping("/api/token")
    public String getWebToken(@RequestBody SvcAddress svcAddress) {
        // 生成令牌
        JSONObject jsonObject = new JSONObject();
        if (ObjectUtils.isEmpty(svcAddress)) {
            jsonObject.put("resultCode", 0);
            jsonObject.put("message", "svcAddress参数不能为空");
            return JSONObject.toJSONString(jsonObject);
        }
        LambdaQueryWrapper<SvcAddress> lw = new LambdaQueryWrapper<SvcAddress>();
        if (!ObjectUtils.isEmpty(svcAddress.getClientId())) {
            lw.eq(SvcAddress::getClientId, svcAddress.getClientId());
            lw.eq(SvcAddress::getEnv, env);
        } else {
            jsonObject.put("resultCode", 0);
            jsonObject.put("message", "客户端编号不能为空");
            return JSONObject.toJSONString(jsonObject);
        }
        SvcAddress serviceOne = svcAddressService.getOne(lw);
        if (!ObjectUtils.isEmpty(serviceOne)) {
            String clientSecret = SM4Utils.decryptData_ECB(serviceOne.getClientSecret(), KEY);
            String sm4 = SM4Utils.decryptData_ECB(svcAddress.getClientSecret(), clientSecret);
            if (clientSecret.equals(sm4)) {
                if (!ObjectUtils.isEmpty(svcAddress.getGrantType())) {
                    if (!svcAddress.getGrantType().toString().matches(PATTERNS)) {
                        jsonObject.put("resultCode", 0);
                        jsonObject.put("message", "授权类型填写错误");
                        return JSONObject.toJSONString(jsonObject);
                    }
                } else {
                    jsonObject.put("resultCode", 0);
                    jsonObject.put("message", "授权类型不能为空");
                    return JSONObject.toJSONString(jsonObject);
                }
                ArrayList<String> objects = apiTokenUtils.createGeoHazardMonitorToken(svcAddress.getGrantType().toString(), svcAddress.getClientId(), sm4);
                if (objects.size() > 0) {
                    RespGeoHazardMonitorVo respGeoHazardMonitorVo = new RespGeoHazardMonitorVo();
                    respGeoHazardMonitorVo.setAccessToken(objects.get(1));
                    Long l = Long.valueOf(objects.get(0));
                    respGeoHazardMonitorVo.setExpiresIn(l / 1000);
                    respGeoHazardMonitorVo.setTokenType("令牌类型");
                    jsonObject.put("resultCode", 1);
                    jsonObject.put("message", "ok");
                    jsonObject.put("data", respGeoHazardMonitorVo);
                    return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), sm4);
                } else {
                    jsonObject.put("resultCode", 0);
                    jsonObject.put("message", "生成token失败");
                    return JSONObject.toJSONString(jsonObject);
                }
            } else {
                jsonObject.put("resultCode", 2);
                jsonObject.put("message", "客户端密钥错误");
                return JSONObject.toJSONString(jsonObject);
            }
        } else {
            jsonObject.put("resultCode", 0);
            jsonObject.put("message", "参数验证失败");
            return JSONObject.toJSONString(jsonObject);
        }
    }

    /**
     * 报警信息数据传输
     */
    @PostMapping("/api/alarm")
    @Transactional(rollbackFor = Exception.class)
    public String alarm(@RequestBody ParameterVo parameterVo, HttpServletRequest request) throws Exception {
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            ReqMsgAlarmVo reqMsgAlarmVo = JSON.parseObject(s, ReqMsgAlarmVo.class);
            if (ObjectUtils.isEmpty(reqMsgAlarmVo.getAlarmAttr())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "你填写的报警病害属性不符合规则!!!");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (!reqMsgAlarmVo.getAlarmMile().toString().matches(PATTERNS)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "报警里程位置填写错误");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (reqMsgAlarmVo.getLineDir() != 1 && reqMsgAlarmVo.getLineDir() != 2) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "行别填写错误");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            LambdaQueryWrapper<BaseRailwayManagement> queryWrapper = new LambdaQueryWrapper<BaseRailwayManagement>();
            if (!ObjectUtils.isEmpty(reqMsgAlarmVo.getAlarmRailway())) {
                queryWrapper.eq(BaseRailwayManagement::getRailwayCode, reqMsgAlarmVo.getAlarmRailway());
            }
            BaseRailwayManagement baseRailwayManagement = baseRailwayManagementService.getOne(queryWrapper);
            if (ObjectUtils.isEmpty(baseRailwayManagement)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "填写的报警线路编码不存在");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(reqMsgAlarmVo.getAlarmId())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "报警的唯一标识不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(reqMsgAlarmVo.getAlarmTime())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "报警时间不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (reqMsgAlarmVo.getAlarmType() < 1 || reqMsgAlarmVo.getAlarmType() > 4) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "报警病害类型填写错误");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (!reqMsgAlarmVo.getAlarmLevel().toString().matches(PATTERNS)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "报警级别填写错误");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (reqMsgAlarmVo.getAlarmTime().toString().length() == 10) {
                reqMsgAlarmVo.setAlarmTime(reqMsgAlarmVo.getAlarmTime() * 1000);
            }
            log.info("reqMsgAlarmVo:{}", reqMsgAlarmVo);

            LambdaQueryWrapper<BaseCameraManagement> wrapper = new LambdaQueryWrapper<BaseCameraManagement>();
            if (!ObjectUtils.isEmpty(reqMsgAlarmVo.getAlarmMile())) {
                if (reqMsgAlarmVo.getLineDir() == 1) {
                    wrapper.ge(BaseCameraManagement::getEndMile, reqMsgAlarmVo.getAlarmMile());
                    wrapper.le(BaseCameraManagement::getBeginMile, reqMsgAlarmVo.getAlarmMile());
                    wrapper.in(BaseCameraManagement::getMonitoringDirection, 1, 3);
                    wrapper.orderByAsc(BaseCameraManagement::getInstallMile);
                }
                if (reqMsgAlarmVo.getLineDir() == 2) {
                    wrapper.ge(BaseCameraManagement::getEndMile,reqMsgAlarmVo.getAlarmMile());
                    wrapper.le(BaseCameraManagement::getBeginMile,reqMsgAlarmVo.getAlarmMile());
                    wrapper.in(BaseCameraManagement::getMonitoringDirection, 2, 3);
                    wrapper.orderByDesc(BaseCameraManagement::getInstallMile);
                }
                wrapper.eq(BaseCameraManagement::getRailwayCode, reqMsgAlarmVo.getAlarmRailway());
                wrapper.eq(BaseCameraManagement::getOnline, 2);
                wrapper.eq(BaseCameraManagement::getEnableOrNot, 1);
            }
            List<BaseCameraManagement> baseCameraManagementList = baseCameraManagementService.list(wrapper);
            LambdaQueryWrapper<MsgAlarm> lw = new LambdaQueryWrapper<MsgAlarm>();
            if (!ObjectUtils.isEmpty(reqMsgAlarmVo.getAlarmId())) {
                lw.eq(MsgAlarm::getAlarmId, reqMsgAlarmVo.getAlarmId());
            }
            MsgAlarm alarm = msgAlarmService.getOne(lw);
            BaseUser admin = baseUserService.getUserName("admin");
            MsgAlarmFrequency msgAlarmVice = new MsgAlarmFrequency();
            if (ObjectUtils.isEmpty(alarm)) {
                MsgAlarm msgAlarm = new MsgAlarm();
                BeanUtils.copyProperties(reqMsgAlarmVo, msgAlarm);
                BeanUtils.copyProperties(reqMsgAlarmVo, msgAlarmVice);
                msgAlarm.setCreateBy(admin.getUserId());
                msgAlarm.setUpdateBy(admin.getUserId());
                log.info("时间++++ long ---- " + reqMsgAlarmVo.getAlarmTime());
                log.info("时间++++" + new Date(reqMsgAlarmVo.getAlarmTime()));
                msgAlarm.setAlarmTime(new Date(reqMsgAlarmVo.getAlarmTime()));
                log.info("时间++++get" + msgAlarm.getAlarmTime());
                msgAlarm.setRailwayCode(reqMsgAlarmVo.getAlarmRailway());
                String source = split[split.length - 2];
                msgAlarm.setSource(source);
                msgAlarmService.save(msgAlarm);
                Files[] files1 = reqMsgAlarmVo.getFiles();
                if (files1.length > 0) {
                    for (int i = 0; i < files1.length; i++) {
                        if (ObjectUtils.isEmpty(files1[i].fileUrl)) {
                            jsonObject.put("resultCode", 0);
                            jsonObject.put("message", "上传文件地址不能为空");
                            jsonObject.put("data", "");
                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                        }
                        if (files1[i].fileType < 1 || files1[i].fileType > 3) {
                            jsonObject.put("resultCode", 0);
                            jsonObject.put("message", "文件类型填写错误");
                            jsonObject.put("data", "");
                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                        }
                        MsgAlarmExt msgAlarmExt = new MsgAlarmExt();
                        msgAlarmExt.setAlarmId(msgAlarm.getAlarmId());
                        msgAlarmExt.setAlarmAttPath(files1[i].fileUrl);
                        msgAlarmExt.setAlarmAttType(files1[i].fileType);
                        msgAlarmExtService.save(msgAlarmExt);
                    }
                }
                msgAlarmVice.setCreateBy(admin.getUserId());
                msgAlarmVice.setUpdateBy(admin.getUserId());
                msgAlarmVice.setRailwayCode(reqMsgAlarmVo.getAlarmRailway());
                msgAlarmVice.setAlarmTime(new Date(reqMsgAlarmVo.getAlarmTime()));
                msgAlarmFrequencyService.save(msgAlarmVice);

                log.info("alarmJSON ：{}", JSON.toJSONString(msgAlarm));
                log.info("->>>>>>>>>>>>>>>>>>>>>>>>>>" + msgAlarm);
                String result = HttpClientUtil.postJson(sdkUrl, JSON.toJSONString(msgAlarm));
                log.info("->>>>>>>>>>>>>>>>>>>>>>>>>>>>" + result);
                log.info("result：{}", result);
                if (!ObjectUtils.isEmpty(baseCameraManagementList)) {
                    int minDifference = Integer.MAX_VALUE;
                    String code = null;
                    for (BaseCameraManagement baseCameraManagement : baseCameraManagementList) {
                        int difference = Math.abs(baseCameraManagement.getInstallMile() - reqMsgAlarmVo.getAlarmMile());
                        if (difference < minDifference) {
                            minDifference = difference;
                            code = baseCameraManagement.getCameraCode();
                        }
                    }
                    List<SysDictData> frontValue = dictTypeService.selectDictDataByType("alarm_play_time_front_value");
                    List<SysDictData> laterValue = dictTypeService.selectDictDataByType("alarm_play_time_later_value");
                    String finalCode = code;
                    CompletableFuture<String> future =CompletableFuture.supplyAsync(() -> {
                        String urLs = cameraUtil.playbackURLs(finalCode, frontValue.get(0).getDictValue(), laterValue.get(0).getDictValue());
                        if (urLs.contains("无视频")) {
                            return urLs;
                        }
                        String playback = CameraUtil.startRecording(finalCode, "playback");
                        if (!"ok".equals(playback)){
                            return "暂无视频-" + finalCode; 
                        }
                        return null;
                    });
                    String url = future.get();
                    if (url.contains("无视频")) {
                        jsonObject.put("resultCode", 0);
                        jsonObject.put("message", url);
                        return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                    }else {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        // 使用SimpleDateFormat将Date对象格式化为指定样式的字符串
                        String formattedDate = sdf.format(msgAlarmVice.getAlarmTime());
                        log.info("-----formattedDate-----------"+formattedDate);
                        String records = cameraUtil.getQueryRecords(code + "/playback", formattedDate);
                        log.info("-----records-----------"+records);
                        MsgAlarm alarm1 = msgAlarmService.getById(msgAlarm.getId());
                        alarm1.setReleasedUrl(records);
                        msgAlarmService.updateById(alarm1);
                    }
                }
            } else {
                BeanUtils.copyProperties(reqMsgAlarmVo, msgAlarmVice);
                msgAlarmVice.setCreateBy(admin.getUserId());
                msgAlarmVice.setUpdateBy(admin.getUserId());
                msgAlarmVice.setAlarmTime(new Date(reqMsgAlarmVo.getAlarmTime()));
                msgAlarmVice.setRailwayCode(reqMsgAlarmVo.getAlarmRailway());
                msgAlarmFrequencyService.save(msgAlarmVice);
            }
            jsonObject.put("resultCode", 1);
            jsonObject.put("message", "ok");
            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            return JSONObject.toJSONString(jsonObject);
        }
    }

    /**
     * 报警解除接口
     *
     * @param parameterVo
     * @param request
     * @return
     */
    @PostMapping("/api/releaseAlarm")
    public String releaseAlarm(@RequestBody ParameterVo parameterVo, HttpServletRequest request) {
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            ReleaseAlarmVo releaseAlarmVo = JSON.parseObject(s, ReleaseAlarmVo.class);
            if (ObjectUtils.isEmpty(releaseAlarmVo.getAlarmId())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "报警的唯一标识不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(releaseAlarmVo.getReleaseTime())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "解除报警时间不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(releaseAlarmVo.getReleaseContent())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "解除原因不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(releaseAlarmVo.getReleaseTime())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "解除人不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            LambdaQueryWrapper<MsgAlarm> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(MsgAlarm::getAlarmId, releaseAlarmVo.getAlarmId());
            MsgAlarm msgAlarm = msgAlarmService.getOne(wrapper);
            if (ObjectUtils.isEmpty(msgAlarm)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "不存在该报警的唯一标识的数据");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (releaseAlarmVo.getReleaseTime().toString().length() == 10) {
                releaseAlarmVo.setReleaseTime(releaseAlarmVo.getReleaseTime() * 1000);
            }
            msgAlarm.setReleasedTime(new Date(releaseAlarmVo.getReleaseTime()));
            msgAlarm.setReleaseContent(releaseAlarmVo.getReleaseContent());
            msgAlarm.setReleasedBy(releaseAlarmVo.getOperator());
            msgAlarm.setUpdateBy(releaseAlarmVo.getOperator());
            msgAlarm.setIsRelease(1);
            boolean count = msgAlarmService.updateById(msgAlarm);
            Map<String, Object> map = new HashMap<>();
            map.put("alarmId", msgAlarm.getAlarmId());
            if (count) {
                map.put("releaseState", 1);
                jsonObject.put("resultCode", 1);
                jsonObject.put("message", "ok");
                jsonObject.put("data", map);
            } else {
                map.put("releaseState", 2);
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "失败");
                jsonObject.put("data", map);
            }
            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            return JSONObject.toJSONString(jsonObject);
        }
    }

    /**
     * 车载心跳机制交互
     *
     * @param parameterVo
     * @param parameterVo
     * @param request
     * @return
     */
    @PostMapping("/api/terminal/heartbeat")
    @Transactional
    public String heartbeat(@RequestBody ParameterVo parameterVo, HttpServletRequest request) throws Exception {
        long begin = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("接受心跳时间: " + sdf.format(new Date(begin)));
        Map<String, Object> twoMap = new HashMap<>();
        String playFlv1;
        int distance = 0;
        boolean type = true;
        RespHeartbeatVo respHeartbeatVo = new RespHeartbeatVo();
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            if (ObjectUtils.isEmpty(parameterVo)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "parameterVo参数不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            //  1.  解密参数
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            //  2、 心跳参数
            HeartbeatVo heartbeatVo = JSON.parseObject(s, HeartbeatVo.class);
            if (ObjectUtils.isEmpty(heartbeatVo.getTerminalCode())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "车载终端编码不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (!heartbeatVo.getCurrentMile().toString().matches(PATTERNS)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "当前里程位置填写错误");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(heartbeatVo.getLatitude())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "当前所在纬度不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(heartbeatVo.getLongitude())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "当前所在经度不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            LambdaQueryWrapper<BaseRailwayManagement> railway = new LambdaQueryWrapper<BaseRailwayManagement>();
            if (!ObjectUtils.isEmpty(heartbeatVo.getRailwayCode())) {
                railway.eq(BaseRailwayManagement::getRailwayCode, heartbeatVo.getRailwayCode());
            }
            BaseRailwayManagement baseRailwayManagement = baseRailwayManagementService.getOne(railway);
            if (ObjectUtils.isEmpty(baseRailwayManagement)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "填写的线路编码不存在");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (heartbeatVo.getLineDir() != 1 && heartbeatVo.getLineDir() != 2) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "行别填写错误");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (!heartbeatVo.getVisualDistance().toString().matches(PATTERNS)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "司机目视距离填写错误");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (heartbeatVo.getSignalStrength() != 1 && heartbeatVo.getSignalStrength() != 2) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "信号强度填写错误");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            VehiclePosition vehiclePosition = new VehiclePosition();
            BeanUtils.copyProperties(heartbeatVo, vehiclePosition);
            LambdaQueryWrapper<BaseVehicleTerminal> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(BaseVehicleTerminal::getTerminalCode, vehiclePosition.getTerminalCode());
            BaseVehicleTerminal baseTerminal = baseVehicleTerminalService.getOne(wrapper);
            if (ObjectUtils.isEmpty(baseTerminal)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "关联表中没有改终端编码的信息");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (heartbeatVo.getSignalStrength() == 2) {
                type = false;
            }
            vehiclePosition.setTravelMile(heartbeatVo.getCurrentMile());
            vehiclePosition.setVehicleCode(baseTerminal.getVehicleCode());
            vehiclePosition.setTerminalLatitude(heartbeatVo.getLatitude());
            vehiclePosition.setTerminalLongitude(heartbeatVo.getLongitude());
            vehiclePosition.setCreateTime(new Date());
            vehiclePosition.setCurrenTime(vehiclePosition.getCreateTime());
            //机车行驶表添加数据
            boolean save = vehiclePositionService.save(vehiclePosition);
            //修改车载终端经度纬度
            BaseTerminal baseTerminal1 = new BaseTerminal();
            baseTerminal1.setTerminalLatitude(heartbeatVo.getLatitude());
            baseTerminal1.setTerminalLongitude(heartbeatVo.getLongitude());
            baseTerminal1.setStatus(1);
            LambdaQueryWrapper<BaseTerminal> terminal = new LambdaQueryWrapper<>();
            terminal.eq(BaseTerminal::getTerminalCode, vehiclePosition.getTerminalCode());
            boolean update = baseTerminalService.update(baseTerminal1, terminal);

            //目视距离和里程位置
            if (save && update) {
                LambdaQueryWrapper<MsgAlarm> queryWrapper = new LambdaQueryWrapper<>();
                if (heartbeatVo.getLineDir() == 1) {
                    queryWrapper.ge(MsgAlarm::getAlarmMile, heartbeatVo.getCurrentMile());
                    queryWrapper.le(MsgAlarm::getAlarmMile, (heartbeatVo.getCurrentMile() + 10000));
                    queryWrapper.orderByAsc(MsgAlarm::getAlarmMile);
                } else if (heartbeatVo.getLineDir() == 2) {
                    queryWrapper.le(MsgAlarm::getAlarmMile, heartbeatVo.getCurrentMile());
                    queryWrapper.ge(MsgAlarm::getAlarmMile, (heartbeatVo.getCurrentMile() - 10000));
                    queryWrapper.orderByDesc(MsgAlarm::getAlarmMile);
                }
                queryWrapper.eq(MsgAlarm::getRailwayCode, heartbeatVo.getRailwayCode());
                queryWrapper.eq(MsgAlarm::getIsRelease, 2);
                List<MsgAlarm> alarmsList = msgAlarmService.list(queryWrapper);
                //根据终端编码 判断终端忽略报警信息记录表中的是否有忽略的报警
                if (!ObjectUtils.isEmpty(alarmsList)) {
                    // 获取当前时间
                    LocalDateTime currentDateTime = LocalDateTime.now();
                    // 获取前一天的时间
                    LocalDateTime previousDateTime = currentDateTime.minusDays(1);
                    // 格式化日期时间
                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                    String currentFormattedDateTime = currentDateTime.format(formatter);
                    String previousFormattedDateTime = previousDateTime.format(formatter);

                    LambdaQueryWrapper<TerminalIgnoreAlarm> queryWrapper1 = new LambdaQueryWrapper<>();
                    //报警信息表中报警标识的信息
                    List<String> collect = alarmsList.stream().map(MsgAlarm::getAlarmId).collect(Collectors.toList());
                    queryWrapper1.in(TerminalIgnoreAlarm::getAlarmId, collect);
                    queryWrapper1.eq(TerminalIgnoreAlarm::getTerminalCode, heartbeatVo.getTerminalCode());
                    queryWrapper1.ge(TerminalIgnoreAlarm::getIgnoreTime, previousFormattedDateTime);
                    queryWrapper1.le(TerminalIgnoreAlarm::getIgnoreTime, currentFormattedDateTime);
                    //终端忽略报警信息记录表
                    List<TerminalIgnoreAlarm> list2 = terminalIgnoreAlarmService.list(queryWrapper1);
                    //找出未忽略的报警信息
                    LambdaQueryWrapper<MsgAlarm> queryWrapper2 = new LambdaQueryWrapper<>();
                    if (!ObjectUtils.isEmpty(list2)) {
                        //忽略报警表中报警标识的信息
                        List<String> collect1 = list2.stream().map(TerminalIgnoreAlarm::getAlarmId).collect(Collectors.toList());
                        List<String> list = collect.stream()
                                .filter(item -> !collect1.contains(item))
                                .collect(Collectors.toList());
                        if (!ObjectUtils.isEmpty(list)) {
                            queryWrapper2.in(MsgAlarm::getAlarmId, list);
                        } else {
                            queryWrapper2.eq(MsgAlarm::getAlarmId, "1111111111111");
                        }
                    } else {
                        queryWrapper2.in(MsgAlarm::getAlarmId, collect);
                    }
                    if (heartbeatVo.getLineDir() == 1) {
                        queryWrapper2.orderByAsc(MsgAlarm::getAlarmMile);
                    } else if (heartbeatVo.getLineDir() == 2) {
                        queryWrapper2.orderByDesc(MsgAlarm::getAlarmMile);
                    }
                    List<MsgAlarm> list = msgAlarmService.list(queryWrapper2);
                    log.info("--------List<MsgAlarm>--------" + list);
                    //有报警信息的时候
                    LambdaQueryWrapper<BaseCameraManagement> camera = new LambdaQueryWrapper<BaseCameraManagement>();
                    if (!ObjectUtils.isEmpty(list)) {
                        //获取报警里程所监控的所有相机
                        if (heartbeatVo.getLineDir() == 1) {
                            log.info("-------getLineDir() == 1--------" + list.get(0).getAlarmMile());
                            camera.ge(BaseCameraManagement::getEndMile, list.get(0).getAlarmMile());
                            camera.le(BaseCameraManagement::getBeginMile, list.get(0).getAlarmMile());
                            camera.in(BaseCameraManagement::getMonitoringDirection, 1, 3);
                            camera.orderByAsc(BaseCameraManagement::getInstallMile);
                        }
                        if (heartbeatVo.getLineDir() == 2) {
                            log.info("-------getLineDir() == 2--------" + list.get(0).getAlarmMile());
                            camera.ge(BaseCameraManagement::getEndMile, list.get(0).getAlarmMile());
                            camera.le(BaseCameraManagement::getBeginMile, list.get(0).getAlarmMile());
                            camera.in(BaseCameraManagement::getMonitoringDirection, 2, 3);
                            camera.orderByDesc(BaseCameraManagement::getInstallMile);
                        }
                        camera.eq(BaseCameraManagement::getRailwayCode, heartbeatVo.getRailwayCode());
                        camera.eq(BaseCameraManagement::getOnline, 2);
                        camera.eq(BaseCameraManagement::getEnableOrNot, 1);
                        List<BaseCameraManagement> baseCameraManagementList = baseCameraManagementService.list(camera);
                        log.info("-------baseCameraManagementList123111--------" + baseCameraManagementList);
                        List<AlarmListVo> listVos = new ArrayList<>();
                        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()-------" + list.get(0).getAlarmMile());
                                int difference = Math.abs(baseCameraManagement.getInstallMile() - list.get(0).getAlarmMile());
                                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);
                                }
                            }
                            playFlv1 = cameraUtil.heartbeatgetPlayFlv(code, channel, type);
                            if (StringUtils.isEmpty(playFlv1)) {
                                playFlv1 = cameraUtil.heartbeatgetUrl(code, channel, type);
                            }
                            log.info("-------playFlv--------" + playFlv1);
                            CameraVos cameraVos = new CameraVos();
                            cameraVos.setCameraCode(baseCameraManagementList.get(0).getCameraCode());
                            cameraVos.setCurrentStream(playFlv1);
                            List<CameraVos> cameraVosList = new ArrayList<>();
                            cameraVosList.add(cameraVos);
                            respHeartbeatVo.setCameraList(cameraVosList);
                            respHeartbeatVo.setIsAlarm(1);
                            twoMap.put("currentStream", playFlv1);
                            twoMap.put("cameraCode", baseCameraManagementList.get(0).getCameraCode());
                        } else {
                            //赋值--股道
                            List<BaseRouteMassage> baseRouteMassageList = baseRouteMassageService.list();
                            if (!ObjectUtils.isEmpty(baseRouteMassageList)) {
                                for (BaseRouteMassage baseRouteMassage : baseRouteMassageList) {
                                    if (heartbeatVo.getLineDir() == 1) {
                                        if (baseRouteMassage.getMileagePosition() - heartbeatVo.getCurrentMile() <= 1500 && baseRouteMassage.getMileagePosition() - heartbeatVo.getCurrentMile() >= 0) {
                                            respHeartbeatVo.setRouteTrack(baseRouteMassage.getRouteStationTrack().toString());
                                            respHeartbeatVo.setStationCode(baseRouteMassage.getStationCode());
                                            break;
                                        } else {
                                            respHeartbeatVo.setRouteTrack("");
                                            respHeartbeatVo.setStationCode("");
                                        }
                                    } else if (heartbeatVo.getLineDir() == 2) {
                                        if (heartbeatVo.getCurrentMile() - baseRouteMassage.getMileagePosition() <= 1500 && heartbeatVo.getCurrentMile() - baseRouteMassage.getMileagePosition() >= 0) {
                                            respHeartbeatVo.setRouteTrack(baseRouteMassage.getRouteStationTrack().toString());
                                            respHeartbeatVo.setStationCode(baseRouteMassage.getStationCode());
                                            break;
                                        } else {
                                            respHeartbeatVo.setRouteTrack("");
                                            respHeartbeatVo.setStationCode("");
                                        }
                                    }
                                }
                            } else {
                                respHeartbeatVo.setRouteTrack("");
                                respHeartbeatVo.setStationCode("");
                            }
                            jsonObject.put("resultCode", 0);
                            jsonObject.put("message", "报警里程无可用相机");
                            jsonObject.put("data", respHeartbeatVo);
                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                        }
                        for (int i = 0; i < list.size(); i++) {
                            MsgHeartbeatAlarmMessage msgHearbeatAlarmMessage = new MsgHeartbeatAlarmMessage();
                            msgHearbeatAlarmMessage.setAlarmId(list.get(i).getAlarmId());
                            msgHearbeatAlarmMessage.setTerminalCode(heartbeatVo.getTerminalCode());
                            msgHearbeatAlarmMessage.setTrainNum(heartbeatVo.getTrainNum());
                            msgHearbeatAlarmMessageMapper.insert(msgHearbeatAlarmMessage);
                            //获取剩余的报警信息
                            LambdaQueryWrapper<BaseCameraManagement> ment = new LambdaQueryWrapper<BaseCameraManagement>();
                            ment.eq(BaseCameraManagement::getRailwayCode, heartbeatVo.getRailwayCode());
                            ment.eq(BaseCameraManagement::getOnline, 2);
                            ment.eq(BaseCameraManagement::getEnableOrNot, 1);
                            if (heartbeatVo.getLineDir() == 1) {
                                ment.ge(BaseCameraManagement::getEndMile, list.get(i).getAlarmMile());
                                ment.le(BaseCameraManagement::getBeginMile, list.get(i).getAlarmMile());
                                ment.in(BaseCameraManagement::getMonitoringDirection, 1, 3);
                                ment.orderByAsc(BaseCameraManagement::getInstallMile);
                            } else if (heartbeatVo.getLineDir() == 2) {
                                ment.ge(BaseCameraManagement::getEndMile, list.get(i).getAlarmMile());
                                ment.le(BaseCameraManagement::getBeginMile, list.get(i).getAlarmMile());
                                ment.in(BaseCameraManagement::getMonitoringDirection, 2, 3);
                                ment.orderByDesc(BaseCameraManagement::getInstallMile);
                            }
                            //获取所有报警安装里程位置的相机
                            List<BaseCameraManagement> baseList = baseCameraManagementService.list(ment);
                            if (baseList.size() > 0) {
                                if (i > 0) {
                                    int minDifference = Integer.MAX_VALUE;
                                    String code = null;
                                    String channel = null;
                                    for (BaseCameraManagement baseCameraManagement : baseList) {
                                        log.info("------------baseCameraManagement.getInstallMile()-------" + baseCameraManagement.getInstallMile());
                                        log.info("------------list.get(0).getAlarmMile()-------" + list.get(0).getAlarmMile());
                                        int difference = Math.abs(baseCameraManagement.getInstallMile() - list.get(0).getAlarmMile());
                                        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);
                                        }
                                    }
                                    playFlv1 = cameraUtil.heartbeatgetPlayFlv(code, channel, type);
                                }
                                AlarmListVo alarmListVo = new AlarmListVo();
                                //alarmList对象
                                if (playFlv1 != null) {
                                    alarmListVo.setCameraStream(playFlv1);
                                } else {
                                    alarmListVo.setCameraStream("");
                                }
                                alarmListVo.setCameraCode(baseList.get(0).getCameraCode());
                                //alarmInfo对象
                                AlarmInfoVo alarmInfoVo1 = new AlarmInfoVo();
                                log.info("----------------list.get(i).getAlarmId()---后续-----------" + list.get(i).getAlarmId());
                                alarmInfoVo1.setAlarmId(list.get(i).getAlarmId());
                                alarmInfoVo1.setAlarmMile(list.get(i).getAlarmMile());
                                alarmInfoVo1.setAlarmTime(list.get(i).getAlarmTime().getTime());
                                alarmInfoVo1.setAlarmType(list.get(i).getAlarmType());
                                alarmInfoVo1.setAlarmContent(list.get(i).getContent());
                                alarmInfoVo1.setAlarmLevel(list.get(i).getAlarmLevel());
                                LambdaQueryWrapper<MsgAlarmExt> alarm = new LambdaQueryWrapper<>();
                                alarm.eq(MsgAlarmExt::getAlarmId, list.get(i).getAlarmId());
                                List<MsgAlarmExt> list1 = msgAlarmExtService.list(alarm);
                                if (list1.size() > 0) {
                                    AlarmFilesVo[] vo = new AlarmFilesVo[list1.size()];
                                    for (int i1 = 0; i1 < list1.size(); i1++) {
                                        vo[i1] = new AlarmFilesVo();
                                        vo[i1].setAlarmAttType(list1.get(i1).getAlarmAttType());
                                        vo[i1].setAlarmAttPath(list1.get(i1).getAlarmAttPath());
                                    }
                                    alarmInfoVo1.setAlarmFiles(vo);
                                }
                                alarmListVo.setAlarmInfo(alarmInfoVo1);
                                log.info("----------------alarmListVo-----------" + alarmListVo);
                                listVos.add(alarmListVo);
                            }
                        }
                        AlarmListVo[] array = listVos.toArray(new AlarmListVo[]{});
                        log.info("----------------array-----------" + Arrays.toString(array));
                        respHeartbeatVo.setAlarmList(array);
                        //获取机车前一路视频
                        int mile = heartbeatVo.getVisualDistance() + heartbeatVo.getCurrentMile();
                        LambdaQueryWrapper<BaseCameraManagement> base = new LambdaQueryWrapper<>();
                        if (heartbeatVo.getLineDir() == 1) {
                            base.orderByAsc(BaseCameraManagement::getInstallMile);
                            base.gt(BaseCameraManagement::getInstallMile, mile);
                        }
                        if (heartbeatVo.getLineDir() == 2) {
                            base.orderByDesc(BaseCameraManagement::getInstallMile);
                            base.lt(BaseCameraManagement::getInstallMile, mile);
                        }
                        base.eq(BaseCameraManagement::getRailwayCode, heartbeatVo.getRailwayCode());
                        base.eq(BaseCameraManagement::getOnline, 2);
                        base.eq(BaseCameraManagement::getEnableOrNot, 1);
                        base.last("limit 1");
                        BaseCameraManagement baseCameraManagement = baseCameraManagementService.getOne(base);
                        //根据相机ID找出分组并排序
                        List<BaseCameraManagement> baseCameraManagementList1 = cameraUtil.getBaseCameraManagementList(baseCameraManagement.getId());
                        if (!ObjectUtils.isEmpty(baseCameraManagementList1)) {
                            for (BaseCameraManagement cameraManagement : baseCameraManagementList1) {
                                String playFlv = cameraUtil.heartbeatgetPlayFlv(cameraManagement.getCameraCode(), cameraManagement.getChannel(), type);
                                if (StringUtils.isEmpty(playFlv)) {
                                    String url = cameraUtil.heartbeatgetUrl(cameraManagement.getCameraCode(), cameraManagement.getChannel(), type);
                                    if (url.contains("无视频")) {
                                        jsonObject.put("resultCode", 0);
                                        jsonObject.put("message", url);
                                        return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                                    }
                                }
                            }
                        }
                    } else {
                        //没有报警信息的时候
                        if (heartbeatVo.getLineDir() == 1) {
                            distance = heartbeatVo.getVisualDistance() + heartbeatVo.getCurrentMile();
                            camera.ge(BaseCameraManagement::getInstallMile, distance);
                            camera.le(BaseCameraManagement::getInstallMile, (heartbeatVo.getCurrentMile() + 10000));
                            camera.in(BaseCameraManagement::getMonitoringDirection, 1, 3);
                            camera.orderByAsc(BaseCameraManagement::getInstallMile);
                        }
                        if (heartbeatVo.getLineDir() == 2) {
                            distance = heartbeatVo.getCurrentMile() - heartbeatVo.getVisualDistance();
                            camera.le(BaseCameraManagement::getInstallMile, distance);
                            camera.ge(BaseCameraManagement::getInstallMile, (heartbeatVo.getCurrentMile() - 10000));
                            camera.in(BaseCameraManagement::getMonitoringDirection, 2, 3);
                            camera.orderByDesc(BaseCameraManagement::getInstallMile);
                        }
                        camera.eq(BaseCameraManagement::getRailwayCode, heartbeatVo.getRailwayCode());
                        camera.eq(BaseCameraManagement::getOnline, 2);
                        camera.eq(BaseCameraManagement::getEnableOrNot, 1);
                        camera.last("limit 2");
                        List<BaseCameraManagement> list1 = baseCameraManagementService.list(camera);
                        if (list1.size() <= 0) {
                            //赋值--股道
                            List<BaseRouteMassage> baseRouteMassageList = baseRouteMassageService.list();
                            if (!ObjectUtils.isEmpty(baseRouteMassageList)) {
                                for (BaseRouteMassage baseRouteMassage : baseRouteMassageList) {
                                    if (heartbeatVo.getLineDir() == 1) {
                                        if (baseRouteMassage.getMileagePosition() - heartbeatVo.getCurrentMile() <= 1500 && baseRouteMassage.getMileagePosition() - heartbeatVo.getCurrentMile() >= 0) {
                                            respHeartbeatVo.setRouteTrack(baseRouteMassage.getRouteStationTrack().toString());
                                            respHeartbeatVo.setStationCode(baseRouteMassage.getStationCode());
                                            break;
                                        } else {
                                            respHeartbeatVo.setRouteTrack("");
                                            respHeartbeatVo.setStationCode("");
                                        }
                                    } else if (heartbeatVo.getLineDir() == 2) {
                                        if (heartbeatVo.getCurrentMile() - baseRouteMassage.getMileagePosition() <= 1500 && heartbeatVo.getCurrentMile() - baseRouteMassage.getMileagePosition() >= 0) {
                                            respHeartbeatVo.setRouteTrack(baseRouteMassage.getRouteStationTrack().toString());
                                            respHeartbeatVo.setStationCode(baseRouteMassage.getStationCode());
                                            break;
                                        } else {
                                            respHeartbeatVo.setRouteTrack("");
                                            respHeartbeatVo.setStationCode("");
                                        }
                                    }
                                }
                            } else {
                                respHeartbeatVo.setRouteTrack("");
                                respHeartbeatVo.setStationCode("");
                            }
                            jsonObject.put("resultCode", 0);
                            jsonObject.put("message", "前方没有摄像机");
                            jsonObject.put("data", respHeartbeatVo);
                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                        }
                        log.info("流程1----------------->");
                        //判断流媒体是否有流
                        String playFlv = cameraUtil.heartbeatgetPlayFlv(list1.get(0).getCameraCode(), list1.get(0).getChannel(), type);
                        log.info("playFlv------------>" + playFlv);
                        //拉两路视频
                        if (StringUtils.isEmpty(playFlv)) {
                            log.info("--------------->>已进入拉两路视频");
                            for (BaseCameraManagement baseCameraManagement : list1) {
                                boolean finalType = type;
                                List<BaseCameraManagement> baseCameraManagementList1 = cameraUtil.getBaseCameraManagementList(baseCameraManagement.getId());
                                if (!ObjectUtils.isEmpty(baseCameraManagementList1)) {
                                    for (BaseCameraManagement cameraManagement : baseCameraManagementList1) {
                                        String url = cameraUtil.heartbeatgetUrl(cameraManagement.getCameraCode(), cameraManagement.getChannel(), finalType);
                                        if (url.contains("无视频")) {
                                            jsonObject.put("resultCode", 0);
                                            jsonObject.put("message", url);
                                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                                        }
                                    }
                                }
                                BaseCameraManagement idOne = baseCameraManagementService.getById(list1.get(0).getId());
                                BaseCameraManagement idTwo = baseCameraManagementService.getById(list1.get(1).getId());
                                if (idOne.getGrouping().equals(idTwo.getGrouping())) {
                                    break;
                                }
                            }
//                            CompletableFuture.runAsync(() -> {
//                                cameraUtil.removePlayFlv(heartbeatVo.getLineDir(), heartbeatVo.getCurrentMile(), heartbeatVo.getVisualDistance());
//                            });
                        } else {
                            log.info("-------------->>已进入拉一路视频");
                            log.info("list1-------------->>" + list1.size());
                            for (int i = 1; i < list1.size(); i++) {
                                boolean finalType = type;
                                int finalI = i;
                                List<BaseCameraManagement> baseCameraManagementList1 = cameraUtil.getBaseCameraManagementList(list1.get(finalI).getId());
                                if (!ObjectUtils.isEmpty(baseCameraManagementList1)) {
                                    for (BaseCameraManagement cameraManagement : baseCameraManagementList1) {
                                        String url = cameraUtil.heartbeatgetUrl(cameraManagement.getCameraCode(), cameraManagement.getChannel(), finalType);
                                        if (url.contains("无视频")) {
                                            jsonObject.put("resultCode", 0);
                                            jsonObject.put("message", url);
                                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                                        }
                                    }
                                }
                            }
                        }
                        List<BaseCameraManagement> baseCameraManagementList1 = cameraUtil.getBaseCameraManagementList(list1.get(0).getId());
                        if (!ObjectUtils.isEmpty(baseCameraManagementList1)) {
                            List<CameraVos> cameraVosList = new ArrayList<>();
                            for (BaseCameraManagement baseCameraManagement : baseCameraManagementList1) {
                                CameraVos cameraVos = new CameraVos();
                                cameraVos.setCameraCode(baseCameraManagement.getCameraCode());
                                cameraVos.setCurrentStream(CameraUtil.getPlayFlvRtsp(baseCameraManagement.getCameraCode(), baseCameraManagement.getChannel(), type));
                                cameraVosList.add(cameraVos);
                            }
                            respHeartbeatVo.setCameraList(cameraVosList);
                        }
                        twoMap.put("currentStream", playFlv);
                        twoMap.put("cameraCode", list1.get(0).getCameraCode());
                        respHeartbeatVo.setIsAlarm(2);
                    }
                } else {
                    //没有报警信息的时候
                    LambdaQueryWrapper<BaseCameraManagement> base = new LambdaQueryWrapper<>();
                    if (heartbeatVo.getLineDir() == 1) {
                        distance = heartbeatVo.getVisualDistance() + heartbeatVo.getCurrentMile();
                        base.ge(BaseCameraManagement::getInstallMile, distance);
                        base.in(BaseCameraManagement::getMonitoringDirection, 1, 3);
                        base.orderByAsc(BaseCameraManagement::getInstallMile);
                        base.le(BaseCameraManagement::getInstallMile, (heartbeatVo.getCurrentMile() + 10000));
                    }
                    if (heartbeatVo.getLineDir() == 2) {
                        distance = heartbeatVo.getCurrentMile() - heartbeatVo.getVisualDistance();
                        base.le(BaseCameraManagement::getInstallMile, distance);
                        base.ge(BaseCameraManagement::getInstallMile, (heartbeatVo.getCurrentMile() - 10000));
                        base.in(BaseCameraManagement::getMonitoringDirection, 2, 3);
                        base.orderByDesc(BaseCameraManagement::getInstallMile);
                    }
                    base.eq(BaseCameraManagement::getRailwayCode, heartbeatVo.getRailwayCode());
                    base.eq(BaseCameraManagement::getOnline, 2);
                    base.eq(BaseCameraManagement::getEnableOrNot, 1);
                    base.last("limit 2");
                    List<BaseCameraManagement> list1 = baseCameraManagementService.list(base);
                    if (list1.size() <= 0) {
                        //赋值--股道
                        List<BaseRouteMassage> list = baseRouteMassageService.list();
                        if (!ObjectUtils.isEmpty(list)) {
                            for (BaseRouteMassage baseRouteMassage : list) {
                                if (heartbeatVo.getLineDir() == 1) {
                                    if (baseRouteMassage.getMileagePosition() - heartbeatVo.getCurrentMile() <= 1500 && baseRouteMassage.getMileagePosition() - heartbeatVo.getCurrentMile() >= 0) {
                                        respHeartbeatVo.setRouteTrack(baseRouteMassage.getRouteStationTrack().toString());
                                        respHeartbeatVo.setStationCode(baseRouteMassage.getStationCode());
                                        break;
                                    } else {
                                        respHeartbeatVo.setRouteTrack("");
                                        respHeartbeatVo.setStationCode("");
                                    }
                                } else if (heartbeatVo.getLineDir() == 2) {
                                    if (heartbeatVo.getCurrentMile() - baseRouteMassage.getMileagePosition() <= 1500 && heartbeatVo.getCurrentMile() - baseRouteMassage.getMileagePosition() >= 0) {
                                        respHeartbeatVo.setRouteTrack(baseRouteMassage.getRouteStationTrack().toString());
                                        respHeartbeatVo.setStationCode(baseRouteMassage.getStationCode());
                                        break;
                                    } else {
                                        respHeartbeatVo.setRouteTrack("");
                                        respHeartbeatVo.setStationCode("");
                                    }
                                }
                            }
                        } else {
                            respHeartbeatVo.setRouteTrack("");
                            respHeartbeatVo.setStationCode("");
                        }
                        jsonObject.put("resultCode", 0);
                        jsonObject.put("message", "前方没有摄像机");
                        jsonObject.put("data", respHeartbeatVo);
                        return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                    }
                    log.info("流程2----------------->");
                    //判断流媒体是否有流
                    String playFlv = cameraUtil.heartbeatgetPlayFlv(list1.get(0).getCameraCode(), list1.get(0).getChannel(), type);
                    log.info("playFlv------------>" + playFlv);
                    //拉两路视频
                    if (StringUtils.isEmpty(playFlv)) {
                        log.info("--------------->>已进入拉两路视频");
                        for (BaseCameraManagement baseCameraManagement : list1) {
                            boolean finalType = type;
                            List<BaseCameraManagement> baseCameraManagementList1 = cameraUtil.getBaseCameraManagementList(baseCameraManagement.getId());
                            if (!ObjectUtils.isEmpty(baseCameraManagementList1)) {
                                for (BaseCameraManagement cameraManagement : baseCameraManagementList1) {
                                    String url = cameraUtil.heartbeatgetUrl(cameraManagement.getCameraCode(), cameraManagement.getChannel(), finalType);
                                    if (url.contains("无视频")) {
                                        jsonObject.put("resultCode", 0);
                                        jsonObject.put("message", url);
                                        return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                                    }
                                }
                            }
                            BaseCameraManagement idOne = baseCameraManagementService.getById(list1.get(0).getId());
                            BaseCameraManagement idTwo = baseCameraManagementService.getById(list1.get(1).getId());
                            if (idOne.getGrouping().equals(idTwo.getGrouping())) {
                                break;
                            }
                        }
                    } else {
                        log.info("-------------->>已进入拉一路路视频");
                        log.info("list1-------------->>" + list1.size());
                        for (int i = 1; i < list1.size(); i++) {
                            boolean finalType = type;
                            int finalI = i;
                            List<BaseCameraManagement> baseCameraManagementList1 = cameraUtil.getBaseCameraManagementList(list1.get(finalI).getId());
                            if (!ObjectUtils.isEmpty(baseCameraManagementList1)) {
                                for (BaseCameraManagement cameraManagement : baseCameraManagementList1) {
                                    String url = cameraUtil.heartbeatgetUrl(cameraManagement.getCameraCode(), cameraManagement.getChannel(), finalType);
                                    if (url.contains("无视频")) {
                                        jsonObject.put("resultCode", 0);
                                        jsonObject.put("message", url);
                                        return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                                    }
                                }
                            }
                        }
                    }
                    List<BaseCameraManagement> baseCameraManagementList1 = cameraUtil.getBaseCameraManagementList(list1.get(0).getId());
                    if (!ObjectUtils.isEmpty(baseCameraManagementList1)) {
                        List<CameraVos> cameraVosList = new ArrayList<>();
                        for (BaseCameraManagement baseCameraManagement : baseCameraManagementList1) {
                            CameraVos cameraVos = new CameraVos();
                            cameraVos.setCameraCode(baseCameraManagement.getCameraCode());
                            cameraVos.setCurrentStream(CameraUtil.getPlayFlvRtsp(baseCameraManagement.getCameraCode(), baseCameraManagement.getChannel(), type));
                            cameraVosList.add(cameraVos);
                        }
                        respHeartbeatVo.setCameraList(cameraVosList);
                    }
                    twoMap.put("currentStream", playFlv);
                    twoMap.put("cameraCode", list1.get(0).getCameraCode());
                    respHeartbeatVo.setIsAlarm(2);
                    //赋值--股道
                    List<BaseRouteMassage> list = baseRouteMassageService.list();
                    if (!ObjectUtils.isEmpty(list)) {
                        for (BaseRouteMassage baseRouteMassage : list) {
                            if (heartbeatVo.getLineDir() == 1) {
                                if (baseRouteMassage.getMileagePosition() - heartbeatVo.getCurrentMile() <= 1500 && baseRouteMassage.getMileagePosition() - heartbeatVo.getCurrentMile() >= 0) {
                                    respHeartbeatVo.setRouteTrack(baseRouteMassage.getRouteStationTrack().toString());
                                    respHeartbeatVo.setStationCode(baseRouteMassage.getStationCode());
                                    break;
                                } else {
                                    respHeartbeatVo.setRouteTrack("");
                                    respHeartbeatVo.setStationCode("");
                                }
                            } else if (heartbeatVo.getLineDir() == 2) {
                                if (heartbeatVo.getCurrentMile() - baseRouteMassage.getMileagePosition() <= 1500 && heartbeatVo.getCurrentMile() - baseRouteMassage.getMileagePosition() >= 0) {
                                    respHeartbeatVo.setRouteTrack(baseRouteMassage.getRouteStationTrack().toString());
                                    respHeartbeatVo.setStationCode(baseRouteMassage.getStationCode());
                                    break;
                                } else {
                                    respHeartbeatVo.setRouteTrack("");
                                    respHeartbeatVo.setStationCode("");
                                }
                            }
                        }
                    } else {
                        respHeartbeatVo.setRouteTrack("");
                        respHeartbeatVo.setStationCode("");
                    }
                }
                twoMap.put("visualDistance", heartbeatVo.getVisualDistance().toString());
                String string = JSON.toJSONString(twoMap);
                heartbeatUtils.createHeartbeat(Constant.HERTBEA_KEY + heartbeatVo.getTerminalCode(), string);
                if (StringUtils.isNotEmpty(respHeartbeatVo.getCameraList())) {
                    jsonObject.put("resultCode", 1);
                    jsonObject.put("message", "ok");
                } else {
                    jsonObject.put("resultCode", 0);
                    jsonObject.put("message", "该相机暂无视频");
                }
                log.info("---------data---结果-------" + respHeartbeatVo);
                jsonObject.put("data", respHeartbeatVo);
                log.info("---------jsonObject---开始-------" + jsonObject);
                long end = System.currentTimeMillis();
                log.info("接受心跳时间: " + sdf.format(new Date(end)));
                log.info("心跳接口请求用时时间:" + (begin - end) / 1000+"秒");
                log.info("---------jsonObject---结果-------" + jsonObject);
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            } else {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "心跳机制交互失败");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            return JSONObject.toJSONString(jsonObject);
        }

    }

    /**
     * 司机忽略报警接口
     *
     * @param parameterVo
     * @param request
     * @return
     */
    @PostMapping("/api/terminal/ignore")
    public String terminalIgnore(@RequestBody ParameterVo parameterVo, HttpServletRequest request) {
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        Map<String, Object> map = new HashMap<>();
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            if (ObjectUtils.isEmpty(parameterVo)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "parameterVo参数不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            TerminalIgnoreVo terminalIgnoreVo = JSON.parseObject(s, TerminalIgnoreVo.class);
            if (ObjectUtils.isEmpty(terminalIgnoreVo.getTerminalCode())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "车载终端编码不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(terminalIgnoreVo.getAlarmId())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "报警唯一UUID不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            map.put("terminalCode", terminalIgnoreVo.getTerminalCode());
            map.put("alarmId", terminalIgnoreVo.getAlarmId());
            LambdaQueryWrapper<MsgAlarm> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(MsgAlarm::getAlarmId, terminalIgnoreVo.getAlarmId());
            MsgAlarm msgAlarm = msgAlarmService.getOne(wrapper);
            if (ObjectUtils.isEmpty(msgAlarm)) {
                map.put("isIgnore", 1);
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "失败");
                jsonObject.put("data", map);
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            TerminalIgnoreAlarm terminalIgnoreAlarm = new TerminalIgnoreAlarm();
            terminalIgnoreAlarm.setAlarmId(terminalIgnoreVo.getAlarmId());
            terminalIgnoreAlarm.setTerminalCode(terminalIgnoreVo.getTerminalCode());
            terminalIgnoreAlarm.setIgnoreTime(new Date());
            terminalIgnoreAlarm.setCreateBy(terminalIgnoreVo.getTerminalCode());
            terminalIgnoreAlarm.setUpdateBy(terminalIgnoreVo.getTerminalCode());
            boolean save = terminalIgnoreAlarmService.save(terminalIgnoreAlarm);
            if (save) {
                ignoreUtils.createIgnore("HL" + terminalIgnoreAlarm.getTerminalCode(), terminalIgnoreAlarm.getAlarmId());
                map.put("isIgnore", 2);
                jsonObject.put("resultCode", 1);
                jsonObject.put("message", "ok");
                jsonObject.put("data", map);
            } else {
                map.put("isIgnore", 3);
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "失败");
                jsonObject.put("data", map);
            }
            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            jsonObject.put("data", "");
            return JSONObject.toJSONString(jsonObject);
        }
    }

    /**
     * 获取所有的相机列表接口定义
     *
     * @param parameterVo
     * @param request
     * @return
     */
    @PostMapping("/api/query/camera")
    public String camera(@RequestBody ParameterVo parameterVo, HttpServletRequest request) {
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            if (ObjectUtils.isEmpty(parameterVo)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "parameterVo参数不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            CameraVo cameraVo = JSON.parseObject(s, CameraVo.class);
            if (ObjectUtils.isEmpty(cameraVo.getTerminalCode())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "车载终端编码不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            LambdaQueryWrapper<BaseCameraManagement> wrapper = new LambdaQueryWrapper<>();
            if (!ObjectUtils.isEmpty(cameraVo.getLineDir())) {
                wrapper.eq(BaseCameraManagement::getRailwayCode, cameraVo.getRailwayCode())
                        .and(w1 -> w1.eq(BaseCameraManagement::getMonitoringDirection, cameraVo.getLineDir())
                                .or(w2 -> w2.eq(BaseCameraManagement::getMonitoringDirection, 3)));
            }
            wrapper.eq(BaseCameraManagement::getEnableOrNot, 1);
            wrapper.orderByAsc(BaseCameraManagement::getInstallMile);
            List<BaseCameraManagement> list = baseCameraManagementService.list(wrapper);
            if (list.size() <= 0) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "没有该线路编码或行别的相机信息");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            for (BaseCameraManagement baseCameraManagement : list) {
                LambdaQueryWrapper<BaseRailwayManagement> queryWrapper = new LambdaQueryWrapper<BaseRailwayManagement>();
                if (!ObjectUtils.isEmpty(baseCameraManagement.getRailwayCode())) {
                    queryWrapper.eq(BaseRailwayManagement::getRailwayCode, baseCameraManagement.getRailwayCode());
                }
                BaseRailwayManagement baseRailwayManagement = baseRailwayManagementService.getOne(queryWrapper);
                if (ObjectUtils.isEmpty(baseRailwayManagement)) {
                    jsonObject.put("resultCode", 0);
                    jsonObject.put("message", "没有该线路编码的线路信息");
                    jsonObject.put("data", "");
                    return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                }
                baseCameraManagement.setRailwayName(baseRailwayManagement.getRailwayName());
            }
            list.sort(new Comparator<BaseCameraManagement>() {
                @Override
                public int compare(BaseCameraManagement o1, BaseCameraManagement o2) {
                    String name1 = ChineseToPingyin.convertHanziToPinyin(o1.getRailwayName());
                    String substring1 = name1.substring(0, 1);
                    String name2 = ChineseToPingyin.convertHanziToPinyin(o2.getRailwayName());
                    String substring2 = name2.substring(0, 1);
                    int i = substring1.compareTo(substring2);
                    if (i == 0) {
                        return -o1.getInstallMile() - o2.getInstallMile();
                    } else {
                        return i;
                    }
                }
            });
            List<RespCameraVo> cameraVos = new ArrayList<>();
            for (BaseCameraManagement baseCameraManagement : list) {
                RespCameraVo respCameraVo = new RespCameraVo();
                BeanUtils.copyProperties(baseCameraManagement, respCameraVo);
                cameraVos.add(respCameraVo);
            }

            jsonObject.put("resultCode", 1);
            jsonObject.put("message", "ok");
            jsonObject.put("data", cameraVos);
            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            jsonObject.put("data", "");
            return JSONObject.toJSONString(jsonObject);
        }
    }

    /**
     * 点播功能接口定义(直播流)
     *
     * @param parameterVo
     * @param request
     * @return
     */
    @PostMapping("/api/camera/play")
    public String cameraPlay(@RequestBody ParameterVo parameterVo, HttpServletRequest request) throws Exception {
        Map<String, Object> map = new HashMap<>();
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            if (ObjectUtils.isEmpty(parameterVo)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "parameterVo参数不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            CameraPlayVo cameraPlayVo = JSON.parseObject(s, CameraPlayVo.class);
            if (ObjectUtils.isEmpty(cameraPlayVo.getTerminalCode())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "车载终端编码不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(cameraPlayVo.getCameraCode())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "相机编码不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            LambdaQueryWrapper<BaseCameraManagement> lw = new LambdaQueryWrapper<BaseCameraManagement>();
            lw.eq(BaseCameraManagement::getCameraCode, cameraPlayVo.getCameraCode());
            lw.eq(BaseCameraManagement::getOnline, 2);
            lw.eq(BaseCameraManagement::getEnableOrNot, 1);
            BaseCameraManagement one = baseCameraManagementService.getOne(lw);
            if (ObjectUtils.isEmpty(one)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "没有该相机编码的相机或已离线");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            String playFlv = cameraUtil.heartbeatgetUrls(one.getCameraCode(), one.getChannel(), false);
            if (playFlv.contains("无视频")) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", playFlv);
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            ArrayList<String> list3 = new ArrayList<>();
            String code = one.getCameraCode() + "/" + one.getChannel();
            list3.add(code);
            log.info("--------------cameraPlay--------------:" + list3);
            redisCache.setCacheObject("cameraPlay", list3);
            map.put("url", playFlv);
            jsonObject.put("resultCode", 1);
            jsonObject.put("message", "ok");
            jsonObject.put("data", map);
            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            jsonObject.put("data", "");
            return JSONObject.toJSONString(jsonObject);
        }
    }

    /**
     * 关闭点播功能接口
     *
     * @param parameterVo
     * @param request
     * @return
     */
    @PostMapping("/api/close/camera/play")
    public String closeCameraPlay(@RequestBody ParameterVo parameterVo, HttpServletRequest request) {
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            if (ObjectUtils.isEmpty(parameterVo)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "parameterVo参数不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            CameraPlayVo cameraPlayVo = JSON.parseObject(s, CameraPlayVo.class);
            if (ObjectUtils.isEmpty(cameraPlayVo.getCameraCode())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "相机编码不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            LambdaQueryWrapper<BaseCameraManagement> lw = new LambdaQueryWrapper<BaseCameraManagement>();
            lw.eq(BaseCameraManagement::getCameraCode, cameraPlayVo.getCameraCode());
            lw.eq(BaseCameraManagement::getOnline, 2);
            lw.eq(BaseCameraManagement::getEnableOrNot, 1);
            BaseCameraManagement one = baseCameraManagementService.getOne(lw);
            if (ObjectUtils.isEmpty(one)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "没有该相机编码的相机或已离线");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            String code = cameraUtil.stopStream(one.getCameraCode(), one.getChannel());
            redisCache.deleteObject("cameraPlay");
            log.info("---------------code------------->" + code);
            jsonObject.put("resultCode", 1);
            jsonObject.put("message", "ok");
            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            jsonObject.put("data", "");
            return JSONObject.toJSONString(jsonObject);
        }
    }


    /**
     * 获取报警列表（已解除和未解除）
     *
     * @param parameterVo
     * @param request
     * @return
     */
    @PostMapping("/api/query/alarm")
    public String queryAlarm(@RequestBody ParameterVo parameterVo, HttpServletRequest request) {
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            if (ObjectUtils.isEmpty(parameterVo)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "parameterVo参数不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            CameraVo cameraVo = JSON.parseObject(s, CameraVo.class);
            if (ObjectUtils.isEmpty(cameraVo.getTerminalCode())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "车载终端编码不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            LambdaQueryWrapper<MsgAlarm> wrapper = new LambdaQueryWrapper<>();
            if (!ObjectUtils.isEmpty(cameraVo.getRailwayCode())) {
                wrapper.eq(MsgAlarm::getRailwayCode, cameraVo.getRailwayCode());
            }
            if (!ObjectUtils.isEmpty(cameraVo.getLineDir())) {
                wrapper.eq(MsgAlarm::getLineDir, cameraVo.getLineDir());
            }
            wrapper.orderByDesc(MsgAlarm::getAlarmTime);
            List<MsgAlarm> list = msgAlarmService.list(wrapper);
            if (list.size() <= 0) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "没有该报警线路或行别的报警信息");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            QueryAlarmVo queryAlarmVo = new QueryAlarmVo();
            List<RespAlarmList> listVos = new ArrayList<>();
            for (MsgAlarm msgAlarm : list) {
                RespAlarmList alarmListVo = new RespAlarmList();
                AlarmInfoVo alarmInfoVo1 = new AlarmInfoVo();
                alarmInfoVo1.setAlarmId(msgAlarm.getAlarmId());
                alarmInfoVo1.setAlarmMile(msgAlarm.getAlarmMile());
                alarmInfoVo1.setAlarmTime(msgAlarm.getAlarmTime().getTime());
                alarmInfoVo1.setAlarmType(msgAlarm.getAlarmType());
                alarmInfoVo1.setAlarmLevel(msgAlarm.getAlarmLevel());
                alarmInfoVo1.setLineDirStr(msgAlarm.getLineDir() == 1 ? "上行" : "下行");
                alarmInfoVo1.setIsRelease(msgAlarm.getIsRelease());
                LambdaQueryWrapper<MsgAlarmExt> alarm = new LambdaQueryWrapper<>();
                alarm.eq(MsgAlarmExt::getAlarmId, msgAlarm.getAlarmId());
                List<MsgAlarmExt> list1 = msgAlarmExtService.list(alarm);
                if (list1.size() > 0) {
                    AlarmFilesVo[] vo = new AlarmFilesVo[list1.size()];
                    for (int i1 = 0; i1 < list1.size(); i1++) {
                        vo[i1] = new AlarmFilesVo();
                        vo[i1].setAlarmAttType(list1.get(i1).getAlarmAttType());
                        vo[i1].setAlarmAttPath(list1.get(i1).getAlarmAttPath());
                    }
                    //返回结果
                    alarmInfoVo1.setAlarmFiles(vo);
                }
                alarmListVo.setAlarmInfo(alarmInfoVo1);
                listVos.add(alarmListVo);
            }
            RespAlarmList[] array = listVos.toArray(new RespAlarmList[]{});
            queryAlarmVo.setAlarmList(array);
            jsonObject.put("resultCode", 1);
            jsonObject.put("message", "ok");
            jsonObject.put("data", queryAlarmVo);
            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            jsonObject.put("data", "");
            return JSONObject.toJSONString(jsonObject);
        }
    }

    /**
     * 获取报警回放
     *
     * @param parameterVo
     * @param request
     * @return
     */
    @PostMapping("/api/alarm/play")
    public String alarmPlay(@RequestBody ParameterVo parameterVo, HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        String urls = null;
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            if (ObjectUtils.isEmpty(parameterVo)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "parameterVo参数不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            TerminalIgnoreVo terminalIgnoreVo = JSON.parseObject(s, TerminalIgnoreVo.class);
            if (ObjectUtils.isEmpty(terminalIgnoreVo.getTerminalCode())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "车载终端编码不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(terminalIgnoreVo.getAlarmId())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "报警唯一UUID不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            LambdaQueryWrapper<MsgAlarm> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(MsgAlarm::getAlarmId, terminalIgnoreVo.getAlarmId());
            MsgAlarm one = msgAlarmService.getOne(wrapper);
            if (ObjectUtils.isEmpty(one)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "没有该报警唯一UUID的报警数据");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            } else {
                if(StringUtils.isEmpty(one.getReleasedUrl())){
                    jsonObject.put("resultCode", 0);
                    jsonObject.put("message", "该报警还未生成报警回放视频");
                    return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
                }
            }
            map.put("url", one.getReleasedUrl());
            jsonObject.put("resultCode", 1);
            jsonObject.put("message", "ok");
            jsonObject.put("data", map);
            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            jsonObject.put("data", "");
            return JSONObject.toJSONString(jsonObject);
        }
    }


    /**
     * 天网相机心跳监测接口定义
     */
    @PostMapping("/api/skynet/heartbeat")
    public String skynetHeartbeat(@RequestBody ParameterVo parameterVo, HttpServletRequest request) {
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            if (ObjectUtils.isEmpty(parameterVo)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "parameterVo参数不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            SkynetHeartbeatVo skynetHeartbeatVo = JSON.parseObject(s, SkynetHeartbeatVo.class);
            if (ObjectUtils.isEmpty(skynetHeartbeatVo.getRailwayCode())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "线路编码不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(skynetHeartbeatVo.getLineDir())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "行别不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (skynetHeartbeatVo.getLineDir() != 1 && skynetHeartbeatVo.getLineDir() != 2) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "行别填写错误");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(skynetHeartbeatVo.getInstallMile())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "安装里程位置不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (!skynetHeartbeatVo.getInstallMile().toString().matches(PATTERNS)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "里程位置填写错误,只能填写数字");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(skynetHeartbeatVo.getCameraCode())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "相机编码不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            SkynetHeartbeatLog skynetHeartbeatLog = new SkynetHeartbeatLog();
            skynetHeartbeatLog.setCameraCode(skynetHeartbeatVo.getCameraCode());
            skynetHeartbeatLog.setInstallMile(skynetHeartbeatVo.getInstallMile());
            skynetHeartbeatLog.setRailwayCode(skynetHeartbeatVo.getRailwayCode());
            skynetHeartbeatLog.setLineDir(skynetHeartbeatVo.getLineDir());
            if (synetHeartbeatLogMapper.insert(skynetHeartbeatLog) > 0) {
                Map<String, Object> map = new HashMap<>();
                map.put("cameraCode", skynetHeartbeatVo.getCameraCode());
                jsonObject.put("resultCode", 1);
                jsonObject.put("message", "ok");
                jsonObject.put("data", map);
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            } else {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "新增失败");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            jsonObject.put("data", "");
            return JSONObject.toJSONString(jsonObject);
        }
    }

    /**
     * 第三方报警系统心跳监测接口定义
     */
    @PostMapping("/api/alarm/heartbeat")
    public String alarmHeartbeat(@RequestBody ParameterVo parameterVo, HttpServletRequest request) {
        String token = apiTokenUtils.getGeoHazardMonitorToken(request);
        log.info("token:{}", token);
        log.info("parameter:{}", parameterVo);
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotEmpty(token)) {
            String[] split = token.split("-");
            String key = split[split.length - 1];
            if (ObjectUtils.isEmpty(parameterVo)) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "parameterVo参数不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
            SvcAddress svcAddress = JSON.parseObject(s, SvcAddress.class);
            if (ObjectUtils.isEmpty(svcAddress.getGrantType())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "授权类型不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            if (ObjectUtils.isEmpty(svcAddress.getClientId())) {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "客户端编号不能为空");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
            AlarmHeartbeatLog alarmHeartbeatLog = new AlarmHeartbeatLog();
            alarmHeartbeatLog.setClientId(svcAddress.getClientId());
            alarmHeartbeatLog.setGrantType(svcAddress.getGrantType());
            if (alarmHeartbeatLogMapper.insert(alarmHeartbeatLog) > 0) {
                Map<String, Object> map = new HashMap<>();
                map.put("clientId", svcAddress.getClientId());
                jsonObject.put("resultCode", 1);
                jsonObject.put("message", "ok");
                jsonObject.put("data", map);
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            } else {
                jsonObject.put("resultCode", 0);
                jsonObject.put("message", "新增失败");
                jsonObject.put("data", "");
                return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
            }
        } else {
            jsonObject.put("resultCode", 2);
            jsonObject.put("message", "token验证失败");
            jsonObject.put("data", "");
            return JSONObject.toJSONString(jsonObject);
        }
    }

    @GetMapping("/test/{key}")
    public void test(@PathVariable String key) {
        String heartbeat = heartbeatUtils.getHeartbeat(key);
        Map maps2 = JSON.parseObject(heartbeat, Map.class);
        System.out.println(maps2);
    }

    @GetMapping("/testi")
    public void testi() {
        Map<String, String> map = new HashMap<>();
        map.put("age", "18");
        map.put("name", "小明");
        map.put("gender", "男");
        String string = JSON.toJSONString(map);
        heartbeatUtils.createHeartbeat("key", string);
    }

    private String objStr(HeartbeatVo heartbeatVoCH) {
        JSONObject obj = new JSONObject();
        //data
        obj.put("data", heartbeatVoCH);
        //code
        obj.put("code", 151);
        log.info("【websocket消息】 机车地址信息:" + obj.toJSONString());
        return obj.toJSONString();
    }

    public static void main(String[] args) {
        JSONObject res = new JSONObject();
        res.put("grantType", "1");
        res.put("clientId", "1005");
        String s = SM4Utils.encryptData_ECB(JSONObject.toJSONString(res), "4370780c9a8c43e5");
        System.out.println(s);
    }

    @PostMapping("/encryptionAlarm")
    public String encryptionAlarm(@RequestBody ReqMsgAlarmVo vo) {
        String s1 = JSONObject.toJSONString(vo);
        return SM4Utils.encryptData_ECB(s1, "4370780c9a8c43e5");
    }

    /**
     * 添加进路信息
     *
     * @return
     */
    @PostMapping("/api/addRouteMassage")
    public AjaxResult addRouteMassage(@RequestBody BaseRouteMassage baseRouteMassage) {
        if (!ObjectUtils.isEmpty(baseRouteMassage) && !ObjectUtils.isEmpty(baseRouteMassage.getStationCode())) {
            BaseRouteMassage one = baseRouteMassageService.getOne(new LambdaQueryWrapper<BaseRouteMassage>().eq(BaseRouteMassage::getStationCode, baseRouteMassage.getStationCode()));
            if (!ObjectUtils.isEmpty(one)) {
                return AjaxResult.error("车站信息已存在");
            }
        }
        baseRouteMassage.setCreateTime(new Date());
        baseRouteMassageService.save(baseRouteMassage);
        return AjaxResult.success();
    }

    /**
     * 查询进路信息
     *
     * @return
     */
    @GetMapping("/api/getRouteMassageList")
    public AjaxResult getRouteMassageList() {
        List<BaseRouteMassage> list = baseRouteMassageService.list();
        for (BaseRouteMassage baseRouteMassage : list) {
            if (!ObjectUtils.isEmpty(baseRouteMassage.getMileagePosition())) {
                String mils = AppendUtils.stringAppend(baseRouteMassage.getMileagePosition());
                baseRouteMassage.setMileagePositionName(mils);
            }
        }
        return AjaxResult.success(list);
    }

    /**
     * 删除进路信息
     *
     * @return
     */
    @PostMapping("/api/deleteRouteMassage")
    public AjaxResult deleteRouteMassage(@RequestBody BaseRouteMassage baseRouteMassage) {
        if (!ObjectUtils.isEmpty(baseRouteMassage) && !ObjectUtils.isEmpty(baseRouteMassage.getId())) {
            baseRouteMassageService.removeById(baseRouteMassage.getId());
            return AjaxResult.success();
        } else {
            return AjaxResult.error("ID不存在");
        }
    }

    /**
     * ttt
     *
     * @return
     */
    @PostMapping("/api/ttt")
    public void ttt() {
        List<BaseCameraManagement> list = baseCameraManagementService.list();
        for (BaseCameraManagement baseCameraManagement : list) {
            log.info("------------baseCameraManagement---------" + baseCameraManagement);
//            cameraUtil.heartbeatgetUrl(baseCameraManagement.getCameraCode(), baseCameraManagement.getChannel(), true);
        }
    }
}
