| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.param.MonitorParam; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.dao.bo.AirEquipmentBo; |
| | | import com.sandu.ximon.dao.bo.MonitorBo; |
| | | import com.sandu.ximon.dao.domain.Monitor; |
| | | import com.sandu.ximon.admin.dto.YSY_AccessTokenDto; |
| | | import com.sandu.ximon.admin.dto.YSY_MonitorDto; |
| | |
| | | //获取萤石云摄像头播放地址URL |
| | | private static final String GET_VEDIO_URL = "/v2/live/address/get"; |
| | | |
| | | /** |
| | | * 查询全部摄像头 |
| | | */ |
| | | public List<Monitor> listMonitor() { |
| | | LambdaQueryWrapper<Monitor> wrapper = Wrappers.lambdaQuery(Monitor.class); |
| | | List<Monitor> list = list(wrapper); |
| | | |
| | | return list; |
| | | } |
| | | private final PoleBindingService poleBindingService; |
| | | |
| | | /** |
| | | * 模糊查询 |
| | | */ |
| | | public List<Monitor> listMonitorByKeyword(MonitorParam monitorParam) { |
| | | //设备状态:在线/离线/全部 |
| | | int equipmentState1; |
| | | int equipmentState2; |
| | | if (2 == monitorParam.getEquipmentState()) { |
| | | //在线 |
| | | equipmentState1 = 1; |
| | | //离线 |
| | | equipmentState2 = 0; |
| | | } else { |
| | | equipmentState1 = monitorParam.getEquipmentState(); |
| | | equipmentState2 = monitorParam.getEquipmentState(); |
| | | public List<MonitorBo> listMonitorByKeyword(BaseConditionVO baseConditionVO, MonitorParam monitorParam) { |
| | | List<String> list; |
| | | list = monitorMapper.listMonitorDeviceSerial(); |
| | | |
| | | MonitorParam monitorParam1; |
| | | for (String devices_serial : list) { |
| | | monitorParam1 = new MonitorParam(); |
| | | monitorParam1.setAccessToken(getAccessToken()); |
| | | monitorParam1.setDeviceSerial(devices_serial); |
| | | getYSYMonitorInfoAndaddMonitorToTable(monitorParam1); |
| | | } |
| | | |
| | | //绑定状态:已绑定/未绑定/全部 |
| | | int bindingState1; |
| | | int bindingState2; |
| | | if (2 == monitorParam.getBindingState()) { |
| | | //已绑定 |
| | | bindingState1 = 1; |
| | | //未绑定 |
| | | bindingState2 = 0; |
| | | } else { |
| | | bindingState1 = monitorParam.getBindingState(); |
| | | bindingState2 = monitorParam.getBindingState(); |
| | | |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | if (baseConditionVO != null) { |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | } |
| | | return monitorMapper.listMonitorByKeyword(monitorParam.getKeyword(), equipmentState1, equipmentState2, bindingState1, bindingState2); |
| | | List<MonitorBo> monitorList; |
| | | //绑定状态:已绑定/未绑定/全部 |
| | | if (monitorParam.getBindingState() == null) { |
| | | //全部 |
| | | monitorParam.setBindingState(2); |
| | | } |
| | | if (monitorParam.getEquipmentState() == null) { |
| | | //全部 |
| | | monitorParam.setEquipmentState(2); |
| | | } |
| | | |
| | | monitorList = monitorMapper.listMonitorByIds(list, monitorParam.getKeyword(), monitorParam.getBindingState(), monitorParam.getEquipmentState(), clientId); |
| | | |
| | | return monitorList; |
| | | } |
| | | |
| | | public Monitor getYSYMonitorInfoAndaddMonitorToTable(MonitorParam monitorParam) { |
| | | YSY_MonitorDto getMonitorDto = getYSYMonitorInfo(getAccessToken(), monitorParam.getDeviceSerial()); |
| | | |
| | | if ("200".equals(getMonitorDto.getCode())) { |
| | | Monitor monitor = new Monitor(); |
| | | monitor.setDeviceSerial(getMonitorDto.getData().getDeviceSerial()); |
| | | if (monitorParam.getValidateCode() != null) { |
| | | monitor.setDevicesCode(monitorParam.getValidateCode()); |
| | | } |
| | | monitor.setDeviceName(getMonitorDto.getData().getDeviceName()); |
| | | monitor.setDeviceType(getMonitorDto.getData().getModel()); |
| | | monitor.setEquipmentState(getMonitorDto.getData().getStatus()); |
| | | monitor.setIsEncrypt(getMonitorDto.getData().getIsEncrypt()); |
| | | monitor.setAddTime(getMonitorDto.getData().getUpdateTime()); |
| | | monitor.setNetAddress(getMonitorDto.getData().getNetAddress()); |
| | | |
| | | return monitor; |
| | | } else { |
| | | throw new BusinessException(getMonitorDto.getMsg()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | if (monitor == null) { |
| | | throw new BusinessException("找不到摄像头"); |
| | | } |
| | | |
| | | //删除摄像头设备前需要先解绑 |
| | | poleBindingService.unBindPole(null, monitor.getDeviceSerial()); |
| | | return removeById(Id); |
| | | } |
| | | |
| | |
| | | return accessTokenDto.getData().getAccessToken(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取萤石云摄像头信息 无需验证accessToken |
| | | * |
| | | * @return |
| | | */ |
| | | public YSY_MonitorDto.MonitorDto getMonitorInfo(String deviceSerial) { |
| | | String token = getAccessToken(); |
| | | Map<String, Object> paramMap = new HashMap<>(); |
| | | paramMap.put("accessToken", token); |
| | | paramMap.put("deviceSerial", deviceSerial); |
| | | String s = HttpUtil.post(YSY_URL + GET_DEVICE_URL, paramMap); |
| | | YSY_MonitorDto monitorDto = JSON.parseObject(s, YSY_MonitorDto.class); |
| | | return monitorDto.getData(); |
| | | } |
| | | |
| | | /** |
| | | * 添加萤石云摄像头 |
| | | * |
| | | * @param accessToken 授权过程获取的access_token |
| | | * @param deviceSerial 设备序列号,存在英文字母的设备序列号,字母需为大写 |
| | | * @param validateCode 设备验证码,设备机身上的六位大写字母 |
| | | * // * @param validateCode 设备验证码,设备机身上的六位大写字母 |
| | | */ |
| | | public YSY_MonitorDto addYSYMonitor(String accessToken, String deviceSerial, String validateCode) { |
| | | // public YSY_MonitorDto addYSYMonitor(String accessToken, String deviceSerial) { |
| | | |
| | | Map<String, Object> paramMap = new HashMap<>(); |
| | | paramMap.put("accessToken", accessToken); |
| | | paramMap.put("deviceSerial", deviceSerial); |
| | | paramMap.put("validateCode", validateCode); |
| | | if (validateCode != null && validateCode.trim().length() != 0) { |
| | | paramMap.put("validateCode", validateCode); |
| | | } |
| | | String s = HttpUtil.post(YSY_URL + ADD_DEVICE_URL, paramMap); |
| | | System.out.println(s); |
| | | YSY_MonitorDto monitorDto = JSON.parseObject(s, YSY_MonitorDto.class); |
| | |
| | | * @param deviceSerial |
| | | * @return |
| | | */ |
| | | public String getMonitorVideoUrl(String accessToken, String deviceSerial, int protocol) { |
| | | public String getMonitorVideoUrl(String accessToken, String deviceSerial, int protocol, int expireTime) { |
| | | if (expireTime < 30 || expireTime > 62208000) { |
| | | throw new BusinessException("设置的URL播放地址过期时长数据错误"); |
| | | } |
| | | Map<String, Object> paramMap = new HashMap<>(); |
| | | paramMap.put("accessToken", accessToken); |
| | | paramMap.put("deviceSerial", deviceSerial); |
| | | paramMap.put("protocol", protocol); |
| | | paramMap.put("expireTime", expireTime); |
| | | String s = HttpUtil.post(YSY_URL + GET_VEDIO_URL, paramMap); |
| | | System.out.println(s); |
| | | YSY_MonitorDto monitor = JSON.parseObject(s, YSY_MonitorDto.class); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改设备绑定状态 |
| | | * |
| | | * @param flag true为绑定 false 为解绑 |
| | | */ |
| | | public void updateBingdingState(boolean flag, String deviceCode) { |
| | | if (flag) {//绑定 |
| | | Monitor monitor = getOne(Wrappers.lambdaQuery(Monitor.class).eq(Monitor::getDeviceSerial, deviceCode)); |
| | | if (monitor == null) { |
| | | return; |
| | | } |
| | | monitor.setBindingState(1); |
| | | updateById(monitor); |
| | | } else {//解绑 |
| | | Monitor monitor = getOne(Wrappers.lambdaQuery(Monitor.class).eq(Monitor::getDeviceSerial, deviceCode)); |
| | | if (monitor == null) { |
| | | return; |
| | | } |
| | | monitor.setBindingState(0); |
| | | updateById(monitor); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改note |
| | | * |
| | | * @param deviceSerial |
| | | * @param notes |
| | | * @return |
| | | */ |
| | | public boolean updateNotes(String deviceSerial, String notes) { |
| | | if (deviceSerial == null || deviceSerial.trim().length() == 0 || notes == null) { |
| | | throw new BusinessException("修改备注参数有误!"); |
| | | } |
| | | Monitor one = getOne(Wrappers.lambdaQuery(Monitor.class).eq(Monitor::getDeviceSerial, deviceSerial)); |
| | | if (one != null) { |
| | | one.setNote(notes); |
| | | return updateById(one); |
| | | } else { |
| | | throw new BusinessException("摄像头设备不存在!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |