| | |
| | | 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.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; |
| | | |
| | | /** |
| | | * 摄像头列表模糊查询 |
| | |
| | | /** |
| | | * 删除摄像头 |
| | | * |
| | | * @param Id |
| | | * @param |
| | | * @return |
| | | */ |
| | | public boolean deleteMonitor(Long Id) { |
| | | Monitor monitor = getById(Id); |
| | | if (monitor == null) { |
| | | throw new BusinessException("找不到摄像头"); |
| | | public boolean deleteMonitor(List<Long> ids) { |
| | | List<Long> idList = new ArrayList<Long>(); |
| | | List<Monitor> monitors = listByIds(ids); |
| | | if (!monitors.isEmpty()) { |
| | | monitors.forEach( |
| | | monitor -> { |
| | | if (monitor == null) { |
| | | throw new BusinessException("找不到摄像头"); |
| | | } |
| | | PoleBinding one = poleBindingService.getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, monitor.getDeviceSerial())); |
| | | if (one != null) { |
| | | //删除摄像头设备前需要先解绑 |
| | | poleBindingService.unBindPole(null, monitor.getDeviceSerial()); |
| | | } |
| | | /** |
| | | * 删除摄像头日志记录开始 |
| | | */ |
| | | String content = "{摄像头Code:" + monitor.getDeviceSerial() + ", 摄像头名称:" + monitor.getDeviceName() + " }"; |
| | | List<String> listCode = new ArrayList<>(); |
| | | listCode.add(monitor.getDeviceSerial()); |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "删除摄像头", content); |
| | | /** |
| | | * 删除摄像头日志记录结束 |
| | | */ |
| | | idList.add(monitor.getId()); |
| | | } |
| | | ); |
| | | } |
| | | PoleBinding one = poleBindingService.getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, monitor.getDeviceSerial())); |
| | | if (one != null) { |
| | | //删除摄像头设备前需要先解绑 |
| | | poleBindingService.unBindPole(null, monitor.getDeviceSerial()); |
| | | } |
| | | /** |
| | | * 删除摄像头日志记录开始 |
| | | */ |
| | | String content = "{摄像头Code:" + monitor.getDeviceSerial() + ", 摄像头名称:" + monitor.getDeviceName() + " }"; |
| | | List<String> listCode = new ArrayList<>(); |
| | | listCode.add(monitor.getDeviceSerial()); |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "删除摄像头", content); |
| | | /** |
| | | * 删除摄像头日志记录结束 |
| | | */ |
| | | return removeById(Id); |
| | | //全部删除成功 |
| | | return removeByIds(idList); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 向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()); |
| | | } |
| | | ); |
| | | |
| | | } |
| | | |
| | | |
| | | } |