根据 catalog 更新 proxy 表
This commit is contained in:
parent
e0974681f9
commit
e2aa0a5b0c
@ -50,8 +50,8 @@ public class DeviceController {
|
||||
|
||||
@Operation(summary = "根据设备编码(21位) 查询指定设备信息")
|
||||
@GetJson("/info/deviceCode")
|
||||
public JsonResponse<WvpProxyDevice> infoByDeviceCode(@RequestParam String deviceCode) {
|
||||
WvpProxyDevice wvpProxyDevice = deviceService.getDeviceByDeviceCode(deviceCode).orElse(null);
|
||||
public JsonResponse<List<WvpProxyDevice>> infoByDeviceCode(@RequestParam String deviceCode) {
|
||||
List<WvpProxyDevice> wvpProxyDevice = deviceService.getDeviceByDeviceCode(deviceCode);
|
||||
return JsonResponse.success(wvpProxyDevice);
|
||||
}
|
||||
|
||||
|
@ -208,6 +208,12 @@
|
||||
<artifactId>commons-exec</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -6,7 +6,9 @@ import cn.skcks.docking.gb28181.core.sip.gb28181.constant.CmdType;
|
||||
import cn.skcks.docking.gb28181.core.sip.gb28181.constant.GB28181Constant;
|
||||
import cn.skcks.docking.gb28181.core.sip.message.subscribe.GenericSubscribe;
|
||||
import cn.skcks.docking.gb28181.core.sip.utils.SipUtil;
|
||||
import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDevice;
|
||||
import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDocking;
|
||||
import cn.skcks.docking.gb28181.wvp.service.device.DeviceService;
|
||||
import cn.skcks.docking.gb28181.wvp.service.docking.DockingService;
|
||||
import cn.skcks.docking.gb28181.wvp.sip.message.message.catalog.dto.CatalogItemDTO;
|
||||
import cn.skcks.docking.gb28181.wvp.sip.message.message.catalog.dto.CatalogRequestDTO;
|
||||
@ -18,6 +20,7 @@ import gov.nist.javax.sip.message.SIPRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -34,6 +37,8 @@ public class CatalogService {
|
||||
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
||||
private final DockingService dockingService;
|
||||
|
||||
private final DeviceService deviceService;
|
||||
|
||||
@SneakyThrows
|
||||
public CompletableFuture<CatalogResponseDTO> getCatalog(String deviceId){
|
||||
CompletableFuture<CatalogResponseDTO> result = new CompletableFuture<>();
|
||||
@ -100,9 +105,25 @@ public class CatalogService {
|
||||
log.info("订阅结束 {}", key);
|
||||
if(dto != null){
|
||||
dto.getDeviceList().setDeviceList(deviceList);
|
||||
scheduledExecutorService.execute(()->{
|
||||
updateProxyDevice(dto);
|
||||
});
|
||||
}
|
||||
result.complete(dto);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void updateProxyDevice(CatalogResponseDTO dto){
|
||||
String gbDeviceId = dto.getDeviceId();
|
||||
List<WvpProxyDevice> deviceByGbDeviceId = deviceService.getDeviceByGbDeviceId(gbDeviceId);
|
||||
List<String> existChannels = deviceByGbDeviceId.stream().map(WvpProxyDevice::getGbDeviceChannelId).toList();
|
||||
List<CatalogItemDTO> deviceList = dto.getDeviceList().getDeviceList();
|
||||
List<String> catalogChannels = deviceList.stream().map(CatalogItemDTO::getDeviceId).toList();
|
||||
List<String> noexist = ListUtils.subtract(catalogChannels, existChannels);
|
||||
noexist.forEach(channel->{
|
||||
log.info("更新 设备 {}, 通道 {} 信息", gbDeviceId, channel);
|
||||
deviceService.autoUpdateDeviceByGbDeviceIdAndChannel(gbDeviceId,channel);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
@ -31,8 +32,8 @@ public class DeviceService {
|
||||
s.where(WvpProxyDeviceDynamicSqlSupport.id, isEqualTo(id)));
|
||||
}
|
||||
|
||||
public Optional<WvpProxyDevice> getDeviceByDeviceCode(String deviceCode){
|
||||
return deviceMapper.selectOne(s->
|
||||
public List<WvpProxyDevice> getDeviceByDeviceCode(String deviceCode){
|
||||
return deviceMapper.select(s->
|
||||
s.where(WvpProxyDeviceDynamicSqlSupport.deviceCode,isEqualTo(deviceCode)));
|
||||
}
|
||||
|
||||
@ -47,6 +48,32 @@ public class DeviceService {
|
||||
.and(WvpProxyDeviceDynamicSqlSupport.gbDeviceChannelId,isEqualTo(channel)));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean autoUpdateDeviceByGbDeviceIdAndChannel(String gbDeviceId, String channel){
|
||||
List<WvpProxyDevice> deviceByGbDeviceId = getDeviceByGbDeviceId(gbDeviceId);
|
||||
if(deviceByGbDeviceId.isEmpty()){
|
||||
WvpProxyDevice device = new WvpProxyDevice();
|
||||
device.setDeviceCode("");
|
||||
device.setGbDeviceId(gbDeviceId);
|
||||
device.setGbDeviceChannelId(channel);
|
||||
return deviceMapper.insert(device) > 0;
|
||||
}
|
||||
|
||||
Optional<WvpProxyDevice> deviceByGbDeviceIdAndChannel = getDeviceByGbDeviceIdAndChannel(gbDeviceId,channel);
|
||||
if(deviceByGbDeviceIdAndChannel.isPresent()) {
|
||||
return deviceMapper.update(u->
|
||||
u.set(WvpProxyDeviceDynamicSqlSupport.gbDeviceChannelId).equalTo(channel)
|
||||
.where(WvpProxyDeviceDynamicSqlSupport.gbDeviceChannelId, isEqualTo(gbDeviceId))
|
||||
.and(WvpProxyDeviceDynamicSqlSupport.gbDeviceChannelId, isEqualTo(channel))) > 0;
|
||||
} else {
|
||||
WvpProxyDevice device = new WvpProxyDevice();
|
||||
device.setDeviceCode("");
|
||||
device.setGbDeviceId(gbDeviceId);
|
||||
device.setGbDeviceChannelId(channel);
|
||||
return deviceMapper.insert(device) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加设备
|
||||
* @param device 设备
|
||||
@ -62,7 +89,7 @@ public class DeviceService {
|
||||
if(StringUtils.isBlank(deviceCode)){
|
||||
throw new JsonException("设备编码不能为空");
|
||||
}
|
||||
if(getDeviceByDeviceCode(deviceCode).isPresent()){
|
||||
if(getDeviceByDeviceCode(deviceCode).isEmpty()){
|
||||
throw new JsonException(MessageFormat.format("设备编码 {0} 已存在" ,deviceCode));
|
||||
}
|
||||
|
||||
@ -81,6 +108,12 @@ public class DeviceService {
|
||||
return deviceMapper.insert(device) > 0;
|
||||
}
|
||||
|
||||
public boolean deleteDeviceByGbDeviceIdAndChannel(String gbDeviceId, String channel){
|
||||
return deviceMapper.delete(d->
|
||||
d.where(WvpProxyDeviceDynamicSqlSupport.gbDeviceChannelId, isEqualTo(gbDeviceId))
|
||||
.and(WvpProxyDeviceDynamicSqlSupport.gbDeviceChannelId, isEqualTo(channel))) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据 id 或 deviceCode 或 gbDeviceId 删除设备信息
|
||||
* @param device 设备
|
||||
|
@ -0,0 +1,16 @@
|
||||
package cn.skcks.docking.gb28181.wvp.service.gb28181;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class Gb28181DownloadService {
|
||||
public void download(String deviceId, Date startTime, Date endTime){
|
||||
|
||||
}
|
||||
}
|
@ -71,11 +71,12 @@ public class WvpService {
|
||||
|
||||
@SneakyThrows
|
||||
public void video(HttpServletRequest request, HttpServletResponse response, String deviceCode, Date startTime, Date endTime) {
|
||||
WvpProxyDevice wvpProxyDevice = deviceService.getDeviceByDeviceCode(deviceCode).orElse(null);
|
||||
if (wvpProxyDevice == null) {
|
||||
List<WvpProxyDevice> wvpProxyDeviceList = deviceService.getDeviceByDeviceCode(deviceCode);
|
||||
if (wvpProxyDeviceList.isEmpty()) {
|
||||
writeErrorToResponse(response, JsonResponse.error("设备不存在"));
|
||||
return;
|
||||
}
|
||||
WvpProxyDevice wvpProxyDevice = wvpProxyDeviceList.get(0);
|
||||
String deviceId = wvpProxyDevice.getGbDeviceId();
|
||||
String channelId = wvpProxyDevice.getGbDeviceChannelId();
|
||||
log.info("设备编码 (deviceCode=>{}) 查询到的设备信息 国标id(gbDeviceId => {}), 通道(channelId => {})", deviceCode, deviceId, channelId);
|
||||
|
@ -19,6 +19,7 @@ import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.RequestEvent;
|
||||
@ -64,7 +65,8 @@ public class MessageRequestProcessor implements MessageProcessor {
|
||||
|
||||
Response ok = response(request, Response.OK, "OK");
|
||||
Response response;
|
||||
if(messageDto.getCmdType().equalsIgnoreCase(CmdType.KEEPALIVE)){
|
||||
|
||||
if(StringUtils.equalsAnyIgnoreCase(messageDto.getCmdType(), CmdType.KEEPALIVE)){
|
||||
response = ok;
|
||||
// 更新设备在线状态
|
||||
} else if(messageDto.getCmdType().equalsIgnoreCase(CmdType.CATALOG)){
|
||||
|
Loading…
Reference in New Issue
Block a user