648540858
2021-09-26 3ae18a558375532efcb7fcd374f58a1ad2d9105c
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
@@ -2,6 +2,8 @@
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.slf4j.Logger;
@@ -21,6 +23,7 @@
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import javax.sip.message.Response;
import java.io.UnsupportedEncodingException;
@Api(tags = "国标设备查询", value = "国标设备查询")
@SuppressWarnings("rawtypes")
@@ -33,6 +36,9 @@
   
   @Autowired
   private IVideoManagerStorager storager;
   @Autowired
   private IRedisCatchStorage redisCatchStorage;
   
   @Autowired
   private SIPCommander cmder;
@@ -128,15 +134,14 @@
    */
   @ApiOperation("同步设备通道")
   @ApiImplicitParams({
         @ApiImplicitParam(name="deviceId", value = "设备id", required = true ,dataTypeClass = String.class),
         @ApiImplicitParam(name="deviceId", value = "设备id", required = true, dataTypeClass = String.class),
   })
   @PostMapping("/devices/{deviceId}/sync")
   public DeferredResult<ResponseEntity<Device>> devicesSync(@PathVariable String deviceId){
      
      if (logger.isDebugEnabled()) {
      }
         logger.debug("设备通道信息同步API调用,deviceId:" + deviceId);
      }
      Device device = storager.queryVideoDevice(deviceId);
        cmder.catalogQuery(device, event -> {
         Response response = event.getResponse();
@@ -145,7 +150,7 @@
         msg.setData(String.format("同步通道失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase()));
         resultHolder.invokeResult(msg);
      });
        DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>(2*1000L);
        DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>(15*1000L);
      result.onTimeout(()->{
         logger.warn(String.format("设备通道信息同步超时"));
         // 释放rtpserver
@@ -177,8 +182,10 @@
      if (offLineDetector.isOnline(deviceId)) {
         return new ResponseEntity<String>("不允许删除在线设备!", HttpStatus.NOT_ACCEPTABLE);
      }
      // 清除redis记录
      boolean isSuccess = storager.delete(deviceId);
      if (isSuccess) {
         redisCatchStorage.clearCatchByDeviceId(deviceId);
         JSONObject json = new JSONObject();
         json.put("deviceId", deviceId);
         return new ResponseEntity<>(json.toString(),HttpStatus.OK);
@@ -258,7 +265,7 @@
   @ApiImplicitParams({
         @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataTypeClass = String.class),
         @ApiImplicitParam(name = "streamMode", value = "数据流传输模式, 取值:" +
               "UDP(udp传输),TCP-ACTIVE(tcp主动模式,暂不支持),TCP-PASSIVE(tcp被动模式)"),
               "UDP(udp传输),TCP-ACTIVE(tcp主动模式,暂不支持),TCP-PASSIVE(tcp被动模式)", dataTypeClass = String.class),
   })
   @PostMapping("/transport/{deviceId}/{streamMode}")
   public ResponseEntity<PageInfo> updateTransport(@PathVariable String deviceId, @PathVariable String streamMode){
@@ -269,6 +276,32 @@
   }
   /**
    * 更新设备信息
    * @param device 设备信息
    * @return
    */
   @ApiOperation("更新设备信息")
   @ApiImplicitParams({
         @ApiImplicitParam(name = "device", value = "设备信息", required = true, dataTypeClass = Device.class)
   })
   @PostMapping("/device/update/")
   public ResponseEntity<WVPResult<String>> updateDevice(Device device){
      if (device != null && device.getDeviceId() != null) {
         Device deviceInStore = storager.queryVideoDevice(device.getDeviceId());
         if (!StringUtils.isEmpty(device.getName())) deviceInStore.setName(device.getName());
         if (!StringUtils.isEmpty(device.getCharset())) deviceInStore.setCharset(device.getCharset());
         if (!StringUtils.isEmpty(device.getMediaServerId())) deviceInStore.setMediaServerId(device.getMediaServerId());
         storager.updateDevice(deviceInStore);
         cmder.deviceInfoQuery(deviceInStore);
      }
      WVPResult<String> result = new WVPResult<>();
      result.setCode(0);
      result.setMsg("success");
      return new ResponseEntity<>(result,HttpStatus.OK);
   }
   /**
    * 设备状态查询请求API接口
    * 
    * @param deviceId 设备id