[国标级联] 调整云台控制调用逻辑

This commit is contained in:
lin
2025-03-05 17:20:55 +08:00
parent e080534b15
commit c0aec7562b
3 changed files with 63 additions and 36 deletions

View File

@@ -1,13 +1,17 @@
package com.genersoft.iot.vmp.gb28181.service;
import com.genersoft.iot.vmp.common.enums.DeviceControlType;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelReduce;
import com.genersoft.iot.vmp.service.bean.ErrorCallback;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
import com.genersoft.iot.vmp.web.gb28181.dto.DeviceChannelExtend;
import com.github.pagehelper.PageInfo;
import org.dom4j.Element;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
@@ -126,4 +130,5 @@ public interface IDeviceChannelService {
List<Integer> queryChaneIdListByDeviceDbIds(List<Integer> deviceDbId);
void handlePtzCmd(@NotNull Integer dataDeviceId, @NotNull Integer gbId, Element rootElement, DeviceControlType type, ErrorCallback<String> callback);
}

View File

@@ -5,6 +5,7 @@ import com.baomidou.dynamic.datasource.annotation.DS;
import com.genersoft.iot.vmp.common.InviteInfo;
import com.genersoft.iot.vmp.common.InviteSessionType;
import com.genersoft.iot.vmp.common.enums.ChannelDataType;
import com.genersoft.iot.vmp.common.enums.DeviceControlType;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.*;
@@ -18,7 +19,9 @@ import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService;
import com.genersoft.iot.vmp.gb28181.service.IInviteStreamService;
import com.genersoft.iot.vmp.gb28181.service.IPlatformChannelService;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
import com.genersoft.iot.vmp.service.bean.ErrorCallback;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
@@ -27,6 +30,7 @@ import com.genersoft.iot.vmp.web.gb28181.dto.DeviceChannelExtend;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -34,8 +38,15 @@ import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import javax.sip.message.Response;
import javax.validation.constraints.NotNull;
import java.text.ParseException;
import java.util.*;
import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText;
/**
* @author lin
*/
@@ -72,6 +83,10 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
private IPlatformChannelService platformChannelService;
@Autowired
private ISIPCommander cmder;
@Override
public int updateChannels(Device device, List<DeviceChannel> channels) {
List<DeviceChannel> addChannels = new ArrayList<>();
@@ -362,6 +377,39 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
return channelMapper.queryChaneIdListByDeviceDbIds(deviceDbIds);
}
@Override
public void handlePtzCmd(@NotNull Integer dataDeviceId, @NotNull Integer gbId, Element rootElement, DeviceControlType type, ErrorCallback<String> callback) {
// 根据通道ID获取所属设备
Device device = deviceMapper.query(dataDeviceId);
if (device == null) {
// 不存在则回复404
log.warn("[INFO 消息] 通道所属设备不存在, 设备ID {}", dataDeviceId);
callback.run(Response.NOT_FOUND, "device not found", null);
return;
}
DeviceChannel deviceChannel = channelMapper.getOneForSource(gbId);
if (deviceChannel == null) {
log.warn("[deviceControl] 未找到设备原始通道, 设备: {}{}),通道编号:{}", device.getName(),
device.getDeviceId(), gbId);
callback.run(Response.NOT_FOUND, "channel not found", null);
return;
}
log.info("[deviceControl] 命令: {}, 设备: {}{} 通道{}{}", type, device.getName(), device.getDeviceId(),
deviceChannel.getName(), deviceChannel.getDeviceId());
String cmdString = getText(rootElement, type.getVal());
try {
cmder.fronEndCmd(device, deviceChannel.getDeviceId(), cmdString, errorResult->{
callback.run(errorResult.statusCode, errorResult.msg, null);
}, errorResult->{
callback.run(errorResult.statusCode, errorResult.msg, null);
});
} catch (InvalidArgumentException | SipException | ParseException e) {
log.error("[命令发送失败] 云台/前端: {}", e.getMessage());
}
}
@Override
public void updateChannelGPS(Device device, DeviceChannel deviceChannel, MobilePosition mobilePosition) {
if (userSetting.getSavePositionHistory()) {