package com.ozs.web.controller.accountmanagment;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ozs.common.annotation.Log;
import com.ozs.common.core.controller.BaseController;
import com.ozs.common.core.domain.AjaxResult;
import com.ozs.common.core.domain.entity.SysDictData;
import com.ozs.common.enums.BusinessType;
import com.ozs.common.utils.AppendUtils;
import com.ozs.common.utils.StringUtils;
import com.ozs.common.utils.poi.ExcelUtil;
import com.ozs.entity.*;
import com.ozs.entity.vo.MsgAlarmResp;
import com.ozs.entity.vo.MsgAlarmVo;
import com.ozs.mapper.MsgAlarmMapper;
import com.ozs.service.*;
import com.ozs.system.service.DataScoreUtil;
import com.ozs.system.service.ISysDeptService;
import com.ozs.system.service.ISysDictDataService;
import com.ozs.system.service.ISysDictTypeService;
import com.ozs.utils.CameraUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 报警信息表 前端控制器
 * </p>
 *
 * @author ozs
 * @since 2023-02-22
 */
@RestController
@RequestMapping("/service/msgAlarm")
public class MsgAlarmController extends BaseController {
    public static final String PATTERN = "^(\\d+.\\d{1,3}|\\d+)$";
    private static final Logger log = LoggerFactory.getLogger(MsgAlarmController.class);
    @Resource
    MsgAlarmService msgAlarmService;
    @Resource
    MsgHeartbeatAlarmMessageService msgHeartbeatAlarmMessageService;
    @Resource
    MsgAlarmFrequencyService msgAlarmFrequencyService;
    @Autowired
    BaseCameraManagementService baseCameraManagementService;
    @Autowired
    BaseRailwayManagementService baseRailwayManagementService;
    @Autowired
    private MsgWebPushService msgWebPushService;
    @Autowired
    private ISysDictDataService dictDataService;
    @Autowired
    private DataScoreUtil dataScoreUtil;
    @Resource
    private BaseVehicleTerminalService baseVehicleTerminalService;
    @Autowired
    private BaseVehicleService baseVehicleService;
    @Autowired
    private ISysDictTypeService dictTypeService;
    @Autowired
    private MonitorSystemService monitorSystemService;
    @Autowired
    private BaseTerminalService baseTerminalService;
    @Autowired
    private CameraUtil cameraUtil;
    @Resource
    private MsgAlarmExtService msgAlarmExtService;

    /**
     * web更多消息-总数，已读数
     */
    @GetMapping("/messageMoreNum")
    @Log(title = "报警信息管理", businessType = BusinessType.SELECT)
    public AjaxResult messageMoreNum() {
        // MsgAlarmVo msgAlarmVo1 = (MsgAlarmVo) dataScoreUtil.setDataScore(getUserId(), msgAlarmVo);
        Map<String, Integer> messageMore = msgWebPushService.messageMoreNum(getUserId());
        return AjaxResult.success(messageMore);
    }

    /**
     * web更多消息
     */
    @PostMapping("/messageMore")
    @Log(title = "报警信息管理", businessType = BusinessType.SELECT)
    public AjaxResult messageMore(@RequestBody MsgAlarmVo msgAlarmVo) {
        // MsgAlarmVo msgAlarmVo1 = (MsgAlarmVo) dataScoreUtil.setDataScore(getUserId(), msgAlarmVo);
        String userId = getUserId();
        if (!StringUtils.isEmpty(userId)) {
            msgAlarmVo.setUserId(userId);
        }
        IPage<MsgAlarm> messageMore = msgWebPushService.messageMore(msgAlarmVo);
        return AjaxResult.success(messageMore);
    }

    /**
     * web报警未读消息个数+未读消息列表
     */
    @GetMapping("/webAlarm")
    @Log(title = "报警信息管理", businessType = BusinessType.SELECT)
    public AjaxResult webAlarmNum() {
        // MsgAlarmVo msgAlarm = (MsgAlarmVo) dataScoreUtil.setDataScore(getUserId(), new MsgAlarmVo());
        Map webAlarm = msgWebPushService.webAlarm(getUserId());
        return AjaxResult.success(webAlarm);
    }

    /**
     * web消息全部已读
     */
    @PostMapping("/readAll")
    @Log(title = "报警信息管理", businessType = BusinessType.SELECT)
    public AjaxResult readAll() {
        return toAjax(msgWebPushService.readAll(getUserId()));
    }

    /**
     * web消息已读
     */
    @PostMapping("/read")
    @Log(title = "报警信息管理", businessType = BusinessType.SELECT)
    public AjaxResult read(@RequestBody MsgWebPush msgWebPush) {
//        if (StringUtils.isEmpty(msgWebPush) || ObjectUtils.isEmpty(msgWebPush.getPushId())) {
//            return AjaxResult.error("PushId不能为空！");
//        }
        return toAjax(msgWebPushService.read(msgWebPush));
    }

    /**
     * 报警信息分页
     *
     * @param msgAlarmVo
     * @return
     */
    @PostMapping("/list")
    @Log(title = "报警信息管理", businessType = BusinessType.SELECT)
    public AjaxResult selectMsgAlarm(@RequestBody MsgAlarmVo msgAlarmVo) {
        msgAlarmVo = (MsgAlarmVo) dataScoreUtil.setDataScore(getUserId(), msgAlarmVo);
        if (!ObjectUtils.isEmpty(msgAlarmVo.getAlarmMile())) {
            msgAlarmVo.setAlarmMile(msgAlarmVo.getAlarmMile() * 1000);
        }
        if (!ObjectUtils.isEmpty(msgAlarmVo.getBeginMile())) {
            msgAlarmVo.setBeginMile(msgAlarmVo.getBeginMile() * 1000);
        }
        if (!ObjectUtils.isEmpty(msgAlarmVo.getEndMile())) {
            msgAlarmVo.setEndMile(msgAlarmVo.getEndMile() * 1000);
        }
        if (!StringUtils.isEmptySunhh(msgAlarmVo.getAlarmMileBD())) {
            if (!msgAlarmVo.getAlarmMileBD().toString().matches(PATTERN)) {
                return error("监控范围开始里程位置填写格式不正确");
            } else {
                msgAlarmVo.setAlarmMile(msgAlarmVo.getAlarmMileBD().multiply(new BigDecimal("1000")).intValue());
            }
        }
        IPage<MsgAlarm> page = msgAlarmService.queryPage(msgAlarmVo);
        page.setTotal(page.getTotal());
        page.setCurrent(page.getCurrent());
        page.setPages(page.getPages());

        if (!ObjectUtils.isEmpty(page) && page.getRecords().size() > 0) {
            List<MsgAlarm> dto1 = page.getRecords().stream().map(o -> {
                LambdaQueryWrapper<BaseRailwayManagement> queryWrapper = new LambdaQueryWrapper<BaseRailwayManagement>();
                if (!ObjectUtils.isEmpty(o.getRailwayCode())) {
                    queryWrapper.eq(BaseRailwayManagement::getRailwayCode, o.getRailwayCode());
                }
                BaseRailwayManagement baseRailwayManagement = baseRailwayManagementService.getOne(queryWrapper);
                if (!StringUtils.isEmptySunhh(baseRailwayManagement) && !StringUtils.isEmptySunhh(baseRailwayManagement.getRailwayName())) {
                    o.setRailwayName(baseRailwayManagement.getRailwayName());
                }
                if (!StringUtils.isEmptySunhh(o.getReleasedBy())) {
//                    BaseUser user = baseUserService.getUser(o.getReleasedBy());
//                    if (!StringUtils.isEmptySunhh(user) && !StringUtils.isEmptySunhh(user.getNickName())) {
//                        o.setReleasedByName(user.getNickName());
//                    }
                    o.setReleasedByName(o.getReleasedBy());
                }
                if(!ObjectUtils.isEmpty(o.getSource())){
                    MonitorSystem monitorSystem = monitorSystemService.selectByClientId(o.getSource());
                    if(!ObjectUtils.isEmpty(monitorSystem)){
                        o.setSourceName(monitorSystem.getMonitorSystemName());
                    }
                }
                String mils = AppendUtils.stringAppend(o.getAlarmMile());
                o.setAlarmMiles(mils);
                o.setLineDirName(o.getLineDir() == 1 ? "上行" : "下行");
                List<SysDictData> data = dictTypeService.selectDictDataByType("sys_alarm_type");
                data.stream().forEach(sysDictData -> {
                    if (sysDictData.getDictValue().equals(o.getAlarmType().toString())) {
                        o.setAlarmTypeName(sysDictData.getDictLabel());
                    }
                });
                List<MsgHeartbeatAlarmMessage> list = msgHeartbeatAlarmMessageService.selectBaseLineManagement(o.getAlarmId());
                if (!ObjectUtils.isEmpty(list)) {
                    StringBuilder stringBuilder = new StringBuilder();
                    for (MsgHeartbeatAlarmMessage msgHeartbeatAlarmMessage : list) {
                        stringBuilder.append(msgHeartbeatAlarmMessage.getTrainNum()).append(",");
                    }
                    String name = stringBuilder.toString();
                    o.setTrainNumName(name.substring(0, stringBuilder.lastIndexOf(",")));
                }
                List<MsgAlarmExt> list1 = msgAlarmExtService.list(new LambdaQueryWrapper<MsgAlarmExt>().eq(MsgAlarmExt::getAlarmId, o.getAlarmId()));
                if (!ObjectUtils.isEmpty(list1)) {
                    List<String> collect = list1.stream().map(MsgAlarmExt::getAlarmAttPath).collect(Collectors.toList());
                    o.setImageUrls(collect);
                }
                return o;
            }).collect(Collectors.toList());
            page.setRecords(dto1);
        }
        return AjaxResult.success(page);
    }

    /**
     * 导出报警消息
     *
     * @param response
     */
    @PostMapping("/exportMsgAlarm")
    @Log(title = "报警信息管理", businessType = BusinessType.EXPORT)
    public void exportMsgAlarm(HttpServletResponse response, @RequestBody MsgAlarmVo msgAlarmVo) {
        msgAlarmVo = (MsgAlarmVo) dataScoreUtil.setDataScore(getUserId(), msgAlarmVo);
        if (!ObjectUtils.isEmpty(msgAlarmVo.getAlarmMile())) {
            msgAlarmVo.setAlarmMile(msgAlarmVo.getAlarmMile() * 1000);
        }
        if (!ObjectUtils.isEmpty(msgAlarmVo.getBeginMile())) {
            msgAlarmVo.setBeginMile(msgAlarmVo.getBeginMile() * 1000);
        }
        if (!ObjectUtils.isEmpty(msgAlarmVo.getEndMile())) {
            msgAlarmVo.setEndMile(msgAlarmVo.getEndMile() * 1000);
        }
        List<MsgAlarm> msgAlarmList = msgAlarmService.msgAlarmList(msgAlarmVo);
        for (MsgAlarm o : msgAlarmList) {
            LambdaQueryWrapper<BaseRailwayManagement> queryWrapper = new LambdaQueryWrapper<>();
            if (!StringUtils.isEmptySunhh(o.getRailwayCode())) {
                queryWrapper.eq(BaseRailwayManagement::getRailwayCode, o.getRailwayCode());
            }
            BaseRailwayManagement baseRailwayManagement = baseRailwayManagementService.getOne(queryWrapper);
            if (!StringUtils.isEmptySunhh(baseRailwayManagement) && !StringUtils.isEmptySunhh(baseRailwayManagement.getRailwayName())) {
                o.setRailwayName(baseRailwayManagement.getRailwayName());
            }
            if (StringUtils.isNotEmpty(o.getReleasedBy())) {
//                BaseUser user = baseUserService.getUser(o.getReleasedBy());
//                if (!StringUtils.isEmptySunhh(user) && !StringUtils.isEmptySunhh(user.getNickName())) {
//                    o.setReleasedByName(user.getNickName());
//                }
                o.setReleasedByName(o.getReleasedBy());
            }
            String mils = AppendUtils.stringAppend(o.getAlarmMile());
            o.setAlarmMiles(mils);
            o.setLineDirName(o.getLineDir() == 1 ? "上行" : "下行");
            o.setAlarmTypeStr(o.getAlarmType() == 1 ? "泥石流" : (o.getAlarmType() == 2 ? "异物侵限" : (o.getAlarmType() == 3 ? "断轨监测" : "未知")));
            o.setIsReleaseName(o.getIsRelease() == 1 ? "已解除" : (o.getIsRelease() == 2 ? "未解除" : "未知"));
            List<SysDictData> data = dictTypeService.selectDictDataByType("sys_alarm_type");
            data.stream().forEach(sysDictData -> {
                if (sysDictData.getDictValue().equals(o.getAlarmType().toString())) {
                    o.setAlarmTypeName(sysDictData.getDictLabel());
                }
            });
            
            if (!StringUtils.isBlank(o.getAlarmId())) {
                QueryWrapper<MsgHeartbeatAlarmMessage> lw = new QueryWrapper<>();
                lw.eq("alarm_id", o.getAlarmId());
                lw.orderByDesc("create_time");
                lw.last("limit 1");
                MsgHeartbeatAlarmMessage msgHeartbeatAlarmMessage = msgHeartbeatAlarmMessageService.getOne(lw);
                if (!ObjectUtils.isEmpty(msgHeartbeatAlarmMessage)) {
                    o.setTrainNumName(msgHeartbeatAlarmMessage.getTrainNum());
                    o.setCreateTimes(msgHeartbeatAlarmMessage.getCreateTime());
                    LambdaQueryWrapper<BaseTerminal> wrapper5 = new LambdaQueryWrapper<>();
                    wrapper5.eq(BaseTerminal::getTerminalCode, msgHeartbeatAlarmMessage.getTerminalCode());
                    BaseTerminal baseTerminal = baseTerminalService.getOne(wrapper5);
                    if (!ObjectUtils.isEmpty(baseTerminal)) {
                        o.setTerminalName(baseTerminal.getTerminalName());
                    }
                    LambdaQueryWrapper<BaseVehicleTerminal> wrapper1 = new LambdaQueryWrapper<>();
                    wrapper1.eq(BaseVehicleTerminal::getTerminalCode, msgHeartbeatAlarmMessage.getTerminalCode());
                    BaseVehicleTerminal baseVehicleTerminal = baseVehicleTerminalService.getOne(wrapper1);
                    if (!ObjectUtils.isEmpty(baseVehicleTerminal)) {
                        LambdaQueryWrapper<BaseVehicle> wrapper2 = new LambdaQueryWrapper<>();
                        wrapper2.eq(BaseVehicle::getVehicleCode, baseVehicleTerminal.getVehicleCode());
                        wrapper2.eq(BaseVehicle::getEnds,baseVehicleTerminal.getEnds());
                        BaseVehicle baseVehicle = baseVehicleService.getOne(wrapper2);
                        if (!ObjectUtils.isEmpty(baseVehicle)) {
                            o.setVehicleCode(baseVehicle.getVehicleCode());
                        }
                    }

                }
            }
        }
        ExcelUtil<MsgAlarm> util = new ExcelUtil<>(MsgAlarm.class);
        util.exportExcel(response, msgAlarmList, "报警信息管理");
    }

    @GetMapping(value = "/{id}")
    @Log(title = "报警信息管理", businessType = BusinessType.MESSAGE)
    public AjaxResult getInfo(@PathVariable Long id) {
        MsgAlarm msgAlarm = msgAlarmService.getById(id);
        if (!ObjectUtils.isEmpty(msgAlarm)) {
            LambdaQueryWrapper<BaseRailwayManagement> wrapper = new LambdaQueryWrapper<>();
            if (!ObjectUtils.isEmpty(msgAlarm.getRailwayCode())) {
                wrapper.eq(BaseRailwayManagement::getRailwayCode, msgAlarm.getRailwayCode());
            }
            BaseRailwayManagement baseRailwayManagement = baseRailwayManagementService.getOne(wrapper);
//            if (StringUtils.isEmptySunhh(baseRailwayManagement)) {
//                return AjaxResult.error("线路编码：" + msgAlarm.getRailwayCode() + "不存在！");
//            }
            // 查询里程位置最近的相机
            LambdaQueryWrapper<BaseCameraManagement> lw = new LambdaQueryWrapper<>();
            if (msgAlarm.getLineDir() == 1) {
                lw.ge(BaseCameraManagement::getEndMile, msgAlarm.getAlarmMile());
                lw.le(BaseCameraManagement::getBeginMile, msgAlarm.getAlarmMile());
                lw.in(BaseCameraManagement::getMonitoringDirection, 1, 3);
                lw.orderByAsc(BaseCameraManagement::getGrou).orderByAsc(BaseCameraManagement::getSort);
            }
            if (msgAlarm.getLineDir() == 2) {
                lw.ge(BaseCameraManagement::getEndMile, msgAlarm.getAlarmMile());
                lw.le(BaseCameraManagement::getBeginMile, msgAlarm.getAlarmMile());
                lw.in(BaseCameraManagement::getMonitoringDirection, 2, 3);
                lw.orderByDesc(BaseCameraManagement::getGrou).orderByDesc(BaseCameraManagement::getSort);
            }
            lw.eq(BaseCameraManagement::getRailwayCode, msgAlarm.getRailwayCode());
            lw.eq(BaseCameraManagement::getOnline, 2);
            lw.eq(BaseCameraManagement::getEnableOrNot, 1);
            List<BaseCameraManagement> baseCameraManagementList = baseCameraManagementService.list(lw);
            BaseCameraManagement baseCameraManagement = new BaseCameraManagement();
            if (!StringUtils.isEmptySunhh(baseCameraManagementList) && baseCameraManagementList.size() > 0) {
                baseCameraManagement = baseCameraManagementList.get(0);
            }
//        BaseCameraManagement baseCameraManagement = baseCameraManagementMapper.selectOne(lw);
//            if (StringUtils.isEmptySunhh(baseCameraManagement)) {
//                return AjaxResult.error("线路编码：" + msgAlarm.getRailwayCode() + "不存在对应里程范围为："+ msgAlarm.getAlarmMile() +"的相机！");
//            }
            MsgAlarmResp msgAlarmResp = new MsgAlarmResp();
            BeanUtils.copyProperties(msgAlarm, msgAlarmResp);
            if (!StringUtils.isEmptySunhh(baseCameraManagement)) {
                msgAlarmResp.setCameraCode(baseCameraManagement.getCameraCode());
            }
            if (!StringUtils.isEmptySunhh(msgAlarm.getReleasedBy())) {
//                BaseUser user = baseUserService.getUser(msgAlarm.getReleasedBy());
//                if (!StringUtils.isEmptySunhh(user) && !StringUtils.isEmptySunhh(user.getNickName())) {
//                    msgAlarmResp.setReleasedByName(user.getNickName());
//                }
                msgAlarmResp.setReleasedByName(msgAlarm.getReleasedBy());
            }
            if (!StringUtils.isEmptySunhh(baseRailwayManagement) && !StringUtils.isEmptySunhh(baseRailwayManagement.getRailwayName())) {
                msgAlarmResp.setRailwayName(baseRailwayManagement.getRailwayName());
            }
            String mile = AppendUtils.stringAppend(msgAlarm.getAlarmMile());
            msgAlarmResp.setAlarmMile(mile);
            if (StringUtils.isNotEmpty(msgAlarm.getAlarmAttr())) {
                String[] split1 = msgAlarm.getAlarmAttr().split(",");
//                String stringBuilder = "画面,大小为" + split1[0] + "×" + split1[1] + "," +
//                        "泥石流范围为左上角坐标(" + split1[2] + "," + split1[3] + ")" +
//                        "大小" + split1[4] + "×" + split1[5];
                msgAlarmResp.setAlarmAttrName(msgAlarm.getAlarmAttr());
            }
            msgAlarmResp.setLineDirStr(msgAlarm.getLineDir() == 1 ? "上行" : "下行");
            msgAlarmResp.setAlarmTypeStr(msgAlarm.getAlarmType() == 1 ? "泥石流" : (msgAlarm.getAlarmType() == 2 ? "异物侵限" : (msgAlarm.getAlarmType() == 3 ? "断轨监测" : "未知")));
            msgAlarmResp.setIsReleaseName(msgAlarm.getIsRelease() == 1 ? "已解除" : (msgAlarm.getIsRelease() == 2 ? "未解除" : "未知"));
            msgAlarmResp.setAlarmLevel(msgAlarm.getAlarmLevel());
            List<SysDictData> data = dictTypeService.selectDictDataByType("sys_alarm_type");
            data.stream().forEach(sysDictData -> {
                if (sysDictData.getDictValue().equals(msgAlarm.getAlarmType().toString())) {
                    msgAlarmResp.setAlarmTypeName(sysDictData.getDictLabel());
                }
                if(!ObjectUtils.isEmpty(msgAlarm.getSource())){
                    MonitorSystem monitorSystem = monitorSystemService.selectByClientId(msgAlarm.getSource());
                    if (!ObjectUtils.isEmpty(monitorSystem)) {
                        msgAlarmResp.setSourceName(monitorSystem.getMonitorSystemName());
                    }
                }
            });
            if (msgAlarm.getAlarmType() == 2) {
                msgAlarmResp.setAlarmUrl("https://rtmp01open.ys7.com:9188/v3/openlive/K38316196_1_1.flv?expire=1745409016&id=704781554165264384&t=477265ab4d36debe072836e0b16755ba50303c3b8eb165a628bc9c0a0328afb5&ev=100");
            }else {
                if (StringUtils.isNotEmpty(baseCameraManagement.getCameraCode())) {
                    msgAlarmResp.setAlarmUrl(CameraUtil.getPlayFlv(baseCameraManagement.getCameraCode(), baseCameraManagement.getChannel()));
                }else {
                    return success("该报警信息无匹判断相机");
                }
            }
            return AjaxResult.success(msgAlarmResp);
        } else {
            return success("无报警信息数据");
        }
    }

    /**
     * 视频上方显示的数据
     *
     * @param msgAlarmVo
     * @return
     */
    @PostMapping("/getDate")
    @Log(title = "报警信息管理", businessType = BusinessType.OTHER)
    public AjaxResult getDate(@RequestBody MsgAlarmVo msgAlarmVo) {
        if (StringUtils.isEmptySunhh(msgAlarmVo) || StringUtils.isEmptySunhh(msgAlarmVo.getId())) {
            return error("报警id不能为空！");
        }
        if (StringUtils.isEmptySunhh(msgAlarmVo) || StringUtils.isEmptySunhh(msgAlarmVo.getRailwayCode())) {
            return error("报警线路编码不能为空！");
        }
        if (StringUtils.isEmptySunhh(msgAlarmVo) || StringUtils.isEmptySunhh(msgAlarmVo.getAlarmMile())) {
            return error("报警里程位置不能为空！");
        }
//        MsgAlarmVo msgAlarmVo1 = msgAlarmService.getDate(msgAlarmVo);
        return msgAlarmService.getDate(msgAlarmVo);
    }

    @RequestMapping(value = "/updateIsRelease")
    @Log(title = "报警信息管理", businessType = BusinessType.UPDATE)
    public AjaxResult updateIsRelease(@RequestParam(value = "id") Long id) {
        MsgAlarm msgAlarm = msgAlarmService.getById(id);
        msgAlarm.setIsRelease(1);
        msgAlarm.setUpdateBy(getUserId());
        msgAlarm.setReleasedBy(getUserId());
        msgAlarm.setReleasedTime(new Date());
        return AjaxResult.success(msgAlarmService.updateById(msgAlarm));
    }

    @GetMapping(value = "/alarmHistoricalAlarm/{alarmId}")
    @Log(title = "报警信息管理", businessType = BusinessType.SELECT)
    public AjaxResult alarmHistoricalAlarm(@PathVariable String alarmId) {
        QueryWrapper<MsgAlarm> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("alarm_id", alarmId);
        MsgAlarm one = msgAlarmService.getOne(queryWrapper);
        if (ObjectUtils.isEmpty(one)) {
            return error("报警表没有此报警唯一标识的报警数据");
        }
        QueryWrapper<MsgAlarmFrequency> wrapper = new QueryWrapper<>();
        wrapper.eq("alarm_id", alarmId);
        wrapper.orderByDesc("alarm_time");
        List<MsgAlarmFrequency> list = msgAlarmFrequencyService.list(wrapper);
        if (list.size() > 0) {
            if (one.getIsRelease() == 1) {
                for (int i = 0; i < list.size(); i++) {
                    if (i == 0) {
                        list.get(i).setIsLock(1);
                    } else {
                        list.get(i).setIsLock(2);
                    }
                }
            } else {
                for (MsgAlarmFrequency msgAlarmFrequency : list) {
                    msgAlarmFrequency.setIsLock(2);
                }
            }
            return AjaxResult.success(list);
        } else {
            return error("报警频次表没有此报警唯一标识的报警数据");
        }
    }

    @GetMapping(value = "/videoHistoricalAlarm/{cameraCode}")
    @Log(title = "报警信息管理", businessType = BusinessType.SELECT)
    public AjaxResult videoHistoricalAlarm(@PathVariable String cameraCode) {
        QueryWrapper<MsgAlarm> wrapper = new QueryWrapper<>();
        wrapper.eq("camera_code", cameraCode);
        wrapper.orderByDesc("alarm_time");
        List<MsgAlarm> list = msgAlarmService.list(wrapper);
        return AjaxResult.success(list);
    }
}

