| | |
| | | import com.sandu.ximon.admin.dto.YSY_AccessTokenDto; |
| | | import com.sandu.ximon.admin.dto.YSY_MonitorDto; |
| | | import com.sandu.ximon.admin.param.MonitorParam; |
| | | import com.sandu.ximon.admin.redis.DeviceRedisKey; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.ListPagingUtils; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.admin.vo.EquipmentInfomation; |
| | | import com.sandu.ximon.admin.vo.RedisDeviceStatus; |
| | | import com.sandu.ximon.dao.bo.MonitorBo; |
| | | import com.sandu.ximon.dao.domain.Monitor; |
| | | import com.sandu.ximon.dao.domain.PoleBinding; |
| | | import com.sandu.ximon.dao.enums.OrderByEnums; |
| | | import com.sandu.ximon.dao.enums.PoleBindingEnums; |
| | | import com.sandu.ximon.dao.mapper.MonitorMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | | @Slf4j |
| | | public class MonitorService extends BaseServiceImpl<MonitorMapper, Monitor> { |
| | | private final MonitorMapper monitorMapper; |
| | | //萤石云AppKey |
| | |
| | | |
| | | private final PoleBindingService poleBindingService; |
| | | |
| | | private final RedisUtils redisUtils; |
| | | |
| | | /** |
| | | * 模糊查询 |
| | | * 摄像头列表模糊查询 |
| | | */ |
| | | public CommonPage listMonitorByKeyword(BaseConditionVO baseConditionVO, MonitorParam monitorParam) { |
| | | public CommonPage listMonitorByKeyword(BaseConditionVO baseConditionVO, Integer order, Integer seq, MonitorParam monitorParam) { |
| | | //绑定状态:已绑定/未绑定/全部 |
| | | if (monitorParam.getBindingState() == null) { |
| | | //全部 |
| | | monitorParam.setBindingState(2); |
| | | } |
| | | //排序字段 |
| | | String orderByResult = "id"; |
| | | //正序、倒叙 |
| | | String orderBySeq = OrderByEnums.ASC.getCode(); |
| | | if (order != null) { |
| | | switch (order) { |
| | | case 1: |
| | | orderByResult = OrderByEnums.MONITOR_POLE_NAME.getCode(); |
| | | break; |
| | | case 2: |
| | | orderByResult = OrderByEnums.MONITOR_CREATE_TIME.getCode(); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | if (seq != null) { |
| | | switch (seq) { |
| | | case 1: |
| | | orderBySeq = " ASC"; |
| | | break; |
| | | case 2: |
| | | orderBySeq = " DESC"; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | //排序方式 |
| | | String orderBy = orderByResult + " " + orderBySeq; |
| | | |
| | | List<MonitorBo> list; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | list = monitorMapper.listMonitorDeviceSerial1(null, monitorParam.getKeyword(), monitorParam.getBindingState()); |
| | | list = monitorMapper.listMonitorDeviceSerial1(null, monitorParam.getKeyword(), monitorParam.getBindingState(), orderBy); |
| | | } else { |
| | | list = monitorMapper.listMonitorDeviceSerial1(SecurityUtils.getUserId(), monitorParam.getKeyword(), monitorParam.getBindingState()); |
| | | list = monitorMapper.listMonitorDeviceSerial1(SecurityUtils.getUserId(), monitorParam.getKeyword(), monitorParam.getBindingState(), orderBy); |
| | | } |
| | | |
| | | //没有数据时候直接返回空数组 |
| | |
| | | return commonPage; |
| | | } |
| | | |
| | | public Monitor getYSYMonitorInfoAndaddMonitorToTable(String deviceSerial) { |
| | | YSY_MonitorDto getMonitorDto = getYSYMonitorInfo(getAccessToken(), deviceSerial); |
| | | /** |
| | | * 摄像头列表地(用于首页数据统计) |
| | | * |
| | | * @return |
| | | */ |
| | | public List<MonitorBo> listMonitorOnHome() { |
| | | |
| | | if ("200".equals(getMonitorDto.getCode())) { |
| | | Monitor monitor = getOne(Wrappers.lambdaQuery(Monitor.class).eq(Monitor::getDeviceSerial, deviceSerial)); |
| | | if (monitor != null) { |
| | | monitor.setDeviceSerial(getMonitorDto.getData().getDeviceSerial()); |
| | | |
| | | 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()); |
| | | //更新摄像头状态 |
| | | updateById(monitor); |
| | | } else { |
| | | monitor = new Monitor(); |
| | | monitor.setDeviceSerial(getMonitorDto.getData().getDeviceSerial()); |
| | | 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()); |
| | | //更新摄像头状态 |
| | | save(monitor); |
| | | } |
| | | |
| | | return monitor; |
| | | List<MonitorBo> list; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | list = monitorMapper.listMonitorDeviceSerial1(null, null, 2, null); |
| | | } else { |
| | | return null; |
| | | list = monitorMapper.listMonitorDeviceSerial1(SecurityUtils.getUserId(), null, 2, null); |
| | | } |
| | | |
| | | //没有数据时候直接返回空数组 |
| | | if (list == null) { |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | |
| | | paramMap.put("appKey", AppKey); |
| | | paramMap.put("appSecret", Secret); |
| | | String s = HttpUtil.post(YSY_URL + ACCESSTOKEN_URL, paramMap); |
| | | if (!s.startsWith("{") || !s.endsWith("}")) { |
| | | log.error("获取摄像头token失败,格式有误!"); |
| | | } |
| | | YSY_AccessTokenDto accessTokenDto = JSON.parseObject(s, YSY_AccessTokenDto.class); |
| | | |
| | | //二次获取 |
| | | if(accessTokenDto == null){ |
| | | log.error("获取摄像头token失败,格式有误!"); |
| | | s = HttpUtil.post(YSY_URL + ACCESSTOKEN_URL, paramMap); |
| | | accessTokenDto = JSON.parseObject(s, YSY_AccessTokenDto.class); |
| | | } |
| | | return accessTokenDto.getData().getAccessToken(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 将摄像头设备相关信息更新到数据库 |
| | | * |
| | | * @param monitor 摄像头对象 |
| | | * @return |
| | | */ |
| | | public boolean upDateMonitorInfo(Monitor monitor) { |
| | | if (monitor.getId() == null) { |
| | | throw new BusinessException("缺少摄像头相关ID参数"); |
| | | } |
| | | |
| | | Monitor info = getById(monitor.getId()); |
| | | |
| | | if (info == null) { |
| | | throw new BusinessException("找不到相关摄像头"); |
| | | } |
| | | if (!monitor.getDevicesCode().equals(info.getDevicesCode()) || !monitor.getDeviceSerial().equals(info.getDeviceSerial())) { |
| | | throw new BusinessException("监控序列号或监控验证码不正确"); |
| | | } |
| | | |
| | | return updateById(monitor); |
| | | } |
| | | |
| | | /** |
| | | * 返回摄像头实时画面播放地址 |
| | | * |
| | | * @param accessToken |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 向Redis中存入设备状态 |
| | | */ |
| | | public void setCacheData() { |
| | | list().forEach( |
| | | device -> { |
| | | RedisDeviceStatus deviceStatus = new RedisDeviceStatus(); |
| | | deviceStatus.setDeviceId(device.getDeviceSerial()); |
| | | if (device != null) { |
| | | EquipmentInfomation monitorInfo = getMonitorInfo(device.getDeviceSerial()); |
| | | if (monitorInfo != null) { |
| | | if ("在线".equals(monitorInfo.getEquipmentState())) { |
| | | deviceStatus.setStatus(0); |
| | | } else { |
| | | deviceStatus.setStatus(1); |
| | | } |
| | | |
| | | } else { |
| | | deviceStatus.setStatus(1); |
| | | } |
| | | } |
| | | redisUtils.set(DeviceRedisKey.MONITOR + device.getDeviceSerial(), JSON.toJSONString(deviceStatus)); |
| | | // redisUtils.delete(DeviceRedisKey.MONITOR + device.getDeviceSerial()); |
| | | } |
| | | ); |
| | | |
| | | } |
| | | |
| | | |
| | | } |