临时提交

This commit is contained in:
648540858
2024-08-15 17:45:24 +08:00
parent 1cbd8d677c
commit abed3ecbec
32 changed files with 472 additions and 971 deletions

View File

@@ -33,10 +33,14 @@ public class VManageBootstrap extends SpringBootServletInitializer {
public static void main(String[] args) {
VManageBootstrap.args = args;
VManageBootstrap.context = SpringApplication.run(VManageBootstrap.class, args);
GitUtil gitUtil1 = SpringBeanFactory.getBean("gitUtil");
log.info("构建版本: {}", gitUtil1.getBuildVersion());
log.info("构建时间: {}", gitUtil1.getBuildDate());
log.info("GIT最后提交时间 {}", gitUtil1.getCommitTime());
GitUtil gitUtil = SpringBeanFactory.getBean("gitUtil");
if (gitUtil == null) {
log.info("获取版本信息失败");
}else {
log.info("构建版本: {}", gitUtil.getBuildVersion());
log.info("构建时间: {}", gitUtil.getBuildDate());
log.info("GIT最后提交时间 {}", gitUtil.getCommitTime());
}
}
// 项目重启
public static void restart() {

View File

@@ -1,12 +1,9 @@
package com.genersoft.iot.vmp.conf;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.support.spring.http.converter.FastJsonHttpMessageConverter;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import org.jetbrains.annotations.NotNull;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
@@ -15,6 +12,8 @@ import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import java.util.LinkedHashMap;
/**
* 全局统一返回结果
* @author lin
@@ -52,6 +51,13 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
return JSON.toJSONString(WVPResult.success(body));
}
if (body instanceof LinkedHashMap) {
LinkedHashMap<String, Object> bodyMap = (LinkedHashMap<String, Object>) body;
if (bodyMap.get("status") != null && (Integer)bodyMap.get("status") != 200) {
return body;
}
}
return WVPResult.success(body);
}

View File

@@ -46,7 +46,7 @@ public class SipPlatformRunner implements CommandLineRunner {
// 更新缓存
PlatformCatch parentPlatformCatch = new PlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setPlatform(parentPlatform);
parentPlatformCatch.setId(parentPlatform.getServerGBId());
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
if (parentPlatformCatchOld != null) {

View File

@@ -352,7 +352,7 @@ public class CommonGBChannel {
commonGBChannel.setGbAddress(platform.getAddress());
commonGBChannel.setGbRegisterWay(platform.getRegisterWay());
commonGBChannel.setGbSecrecy(platform.getSecrecy());
commonGBChannel.setGbStatus(platform.getStatus());
commonGBChannel.setGbStatus(platform.isStatus()?"ON":"OFF");
return commonGBChannel;
}

View File

@@ -26,7 +26,7 @@ public class Platform {
private String serverGBDomain;
@Schema(description = "SIP服务IP")
private String serverIP;
private String serverIp;
@Schema(description = "SIP服务端口")
private int serverPort;
@@ -67,7 +67,7 @@ public class Platform {
@Schema(description = "在线状态")
private boolean status;
@Schema(description = "在线状态")
@Schema(description = "通道数量")
private int channelCount;
@Schema(description = "已被订阅目录信息")
@@ -94,9 +94,6 @@ public class Platform {
@Schema(description = "点播回复200OK使用的IP")
private String sendStreamIp;
@Schema(description = "是否使用自定义业务分组")
private Boolean customGroup;
@Schema(description = "是否自动推送通道变化")
private Boolean autoPushChannel;
@@ -130,7 +127,4 @@ public class Platform {
@Schema(description = "保密属性必选缺省为00-不涉密1-涉密")
private int secrecy = 0;
@Schema(description = "在线状态")
private String Status = "ON";
}

View File

@@ -17,7 +17,7 @@ public class PlatformCatch {
private String callId;
private Platform parentPlatform;
private Platform platform;
private SipTransactionInfo sipTransactionInfo;

View File

@@ -29,6 +29,7 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
@@ -122,7 +123,7 @@ public class PlatformController {
@Parameter(name = "count", description = "每页条数", required = true)
public PageInfo<Platform> platforms(@PathVariable int page, @PathVariable int count) {
PageInfo<Platform> parentPlatformPageInfo = platformService.queryParentPlatformList(page, count);
PageInfo<Platform> parentPlatformPageInfo = platformService.queryPlatformList(page, count);
if (parentPlatformPageInfo.getList().size() > 0) {
for (Platform platform : parentPlatformPageInfo.getList()) {
platform.setMobilePositionSubscribe(subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId()) != null);
@@ -135,45 +136,53 @@ public class PlatformController {
/**
* 添加上级平台信息
*
* @param parentPlatform
* @param platform
* @return
*/
@Operation(summary = "添加上级平台信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
@PostMapping("/add")
@ResponseBody
public void addPlatform(@RequestBody Platform parentPlatform) {
public void addPlatform(@RequestBody Platform platform) {
if (log.isDebugEnabled()) {
log.debug("保存上级平台信息API调用");
}
if (ObjectUtils.isEmpty(parentPlatform.getName())
|| ObjectUtils.isEmpty(parentPlatform.getServerGBId())
|| ObjectUtils.isEmpty(parentPlatform.getServerGBDomain())
|| ObjectUtils.isEmpty(parentPlatform.getServerIP())
|| ObjectUtils.isEmpty(parentPlatform.getServerPort())
|| ObjectUtils.isEmpty(parentPlatform.getDeviceGBId())
|| ObjectUtils.isEmpty(parentPlatform.getExpires())
|| ObjectUtils.isEmpty(parentPlatform.getKeepTimeout())
|| ObjectUtils.isEmpty(parentPlatform.getTransport())
|| ObjectUtils.isEmpty(parentPlatform.getCharacterSet())
) {
throw new ControllerException(ErrorCode.ERROR400);
}
if (parentPlatform.getServerPort() < 0 || parentPlatform.getServerPort() > 65535) {
throw new ControllerException(ErrorCode.ERROR400.getCode(), "error severPort");
Assert.notNull(platform.getName(), "平台名称不可为空");
Assert.notNull(platform.getServerGBId(), "上级平台国标编号不可为空");
Assert.notNull(platform.getServerIp(), "上级平台IP不可为空");
Assert.isTrue(platform.getServerPort() > 0 && platform.getServerPort() < 65535, "上级平台端口异常");
Assert.notNull(platform.getDeviceGBId(), "本平台国标编号不可为空");
if (ObjectUtils.isEmpty(platform.getServerGBDomain())) {
platform.setServerGBDomain(platform.getServerGBId().substring(0, 6));
}
if (platform.getExpires() <= 0) {
platform.setExpires(3600);
}
Platform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
if (platform.getKeepTimeout() <= 0) {
platform.setKeepTimeout(60);
}
if (ObjectUtils.isEmpty(platform.getTransport())) {
platform.setTransport("UDP");
}
if (ObjectUtils.isEmpty(platform.getCharacterSet())) {
platform.setCharacterSet("GB2312");
}
Platform parentPlatformOld = platformService.queryPlatformByServerGBId(platform.getServerGBId());
if (parentPlatformOld != null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台 " + parentPlatform.getServerGBId() + " 已存在");
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台 " + platform.getServerGBId() + " 已存在");
}
parentPlatform.setCreateTime(DateUtil.getNow());
parentPlatform.setUpdateTime(DateUtil.getNow());
boolean updateResult = platformService.add(parentPlatform);
platform.setCreateTime(DateUtil.getNow());
platform.setUpdateTime(DateUtil.getNow());
boolean updateResult = platformService.add(platform);
if (!updateResult) {
throw new ControllerException(ErrorCode.ERROR100.getCode(),"写入数据库失败");
throw new ControllerException(ErrorCode.ERROR100);
}
}
@@ -184,9 +193,9 @@ public class PlatformController {
* @return
*/
@Operation(summary = "保存上级平台信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
@PostMapping("/save")
@PostMapping("/update")
@ResponseBody
public void savePlatform(@RequestBody Platform parentPlatform) {
public void updatePlatform(@RequestBody Platform parentPlatform) {
if (log.isDebugEnabled()) {
log.debug("保存上级平台信息API调用");
@@ -194,7 +203,7 @@ public class PlatformController {
if (ObjectUtils.isEmpty(parentPlatform.getName())
|| ObjectUtils.isEmpty(parentPlatform.getServerGBId())
|| ObjectUtils.isEmpty(parentPlatform.getServerGBDomain())
|| ObjectUtils.isEmpty(parentPlatform.getServerIP())
|| ObjectUtils.isEmpty(parentPlatform.getServerIp())
|| ObjectUtils.isEmpty(parentPlatform.getServerPort())
|| ObjectUtils.isEmpty(parentPlatform.getDeviceGBId())
|| ObjectUtils.isEmpty(parentPlatform.getExpires())

View File

@@ -466,40 +466,40 @@ public interface CommonGBChannelMapper {
" wdc.update_time,\n" +
" coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) as gb_device_id,\n" +
" coalesce(wpgc.name, wdc.gb_name, wdc.name) as gb_name,\n" +
" coalesce(wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" +
" coalesce(wdc.gb_model, wdc.model) as gb_model,\n" +
" coalesce(wdc.gb_owner, wdc.owner) as gb_owner,\n" +
" coalesce(wpgc.manufacturer, wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" +
" coalesce(wpgc.model, wdc.gb_model, wdc.model) as gb_model,\n" +
" coalesce(wpgc.owner, wdc.gb_owner, wdc.owner) as gb_owner,\n" +
" coalesce(wpgc.civil_code, wdc.gb_civil_code, wdc.civil_code),\n" +
" coalesce(wdc.gb_block, wdc.block) as gb_block,\n" +
" coalesce(wdc.gb_address, wdc.address) as gb_address,\n" +
" coalesce(wdc.gb_parental, wdc.parental) as gb_parental,\n" +
" coalesce(wpgc.block, wdc.gb_block, wdc.block) as gb_block,\n" +
" coalesce(wpgc.address, wdc.gb_address, wdc.address) as gb_address,\n" +
" coalesce(wpgc.parental, wdc.gb_parental, wdc.parental) as gb_parental,\n" +
" coalesce(wpgc.parent_id, wdc.gb_parent_id, wdc.parent_id) as gb_parent_id,\n" +
" coalesce(wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" +
" coalesce(wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" +
" coalesce(wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" +
" coalesce(wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" +
" coalesce(wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" +
" coalesce(wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" +
" coalesce(wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" +
" coalesce(wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" +
" coalesce(wdc.gb_port, wdc.port) as gb_port,\n" +
" coalesce(wdc.gb_password, wdc.password) as gb_password,\n" +
" coalesce(wdc.gb_status, wdc.status) as gb_status,\n" +
" coalesce(wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" +
" coalesce(wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" +
" coalesce(wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" +
" coalesce(wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" +
" coalesce(wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" +
" coalesce(wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" +
" coalesce(wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" +
" coalesce(wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" +
" coalesce(wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" +
" coalesce(wpgc.safety_way, wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" +
" coalesce(wpgc.register_way, wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" +
" coalesce(wpgc.cert_num, wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" +
" coalesce(wpgc.certifiable, wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" +
" coalesce(wpgc.err_code, wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" +
" coalesce(wpgc.end_time, wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" +
" coalesce(wpgc.secrecy, wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" +
" coalesce(wpgc.ip_address, wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" +
" coalesce(wpgc.port, wdc.gb_port, wdc.port) as gb_port,\n" +
" coalesce(wpgc.password, wdc.gb_password, wdc.password) as gb_password,\n" +
" coalesce(wpgc.status, wdc.gb_status, wdc.status) as gb_status,\n" +
" coalesce(wpgc.longitude, wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" +
" coalesce(wpgc.latitude, wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" +
" coalesce(wpgc.ptz_type, wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" +
" coalesce(wpgc.position_type, wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" +
" coalesce(wpgc.room_type, wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" +
" coalesce(wpgc.use_type, wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" +
" coalesce(wpgc.supply_light_type, wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" +
" coalesce(wpgc.direction_type, wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" +
" coalesce(wpgc.resolution, wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" +
" coalesce(wpgc.business_group_id, wdc.gb_business_group_id, wdc.business_group_id) as gb_business_group_id,\n" +
" coalesce(wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" +
" coalesce(wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" +
" coalesce(wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" +
" coalesce(wpgc.download_speed, wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" +
" coalesce(wpgc.svc_space_support_mod, wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" +
" coalesce(wpgc.svc_time_support_mode, wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" +
" from wvp_device_channel wdc" +
" left jon wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id" +
" left join wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id" +
" where wpgc.platform_id = #{platformId}"
)
@@ -514,40 +514,40 @@ public interface CommonGBChannelMapper {
" wdc.update_time,\n" +
" coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) as gb_device_id,\n" +
" coalesce(wpgc.name, wdc.gb_name, wdc.name) as gb_name,\n" +
" coalesce(wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" +
" coalesce(wdc.gb_model, wdc.model) as gb_model,\n" +
" coalesce(wdc.gb_owner, wdc.owner) as gb_owner,\n" +
" coalesce(wpgc.manufacturer, wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" +
" coalesce(wpgc.model, wdc.gb_model, wdc.model) as gb_model,\n" +
" coalesce(wpgc.owner, wdc.gb_owner, wdc.owner) as gb_owner,\n" +
" coalesce(wpgc.civil_code, wdc.gb_civil_code, wdc.civil_code),\n" +
" coalesce(wdc.gb_block, wdc.block) as gb_block,\n" +
" coalesce(wdc.gb_address, wdc.address) as gb_address,\n" +
" coalesce(wdc.gb_parental, wdc.parental) as gb_parental,\n" +
" coalesce(wpgc.block, wdc.gb_block, wdc.block) as gb_block,\n" +
" coalesce(wpgc.address, wdc.gb_address, wdc.address) as gb_address,\n" +
" coalesce(wpgc.parental, wdc.gb_parental, wdc.parental) as gb_parental,\n" +
" coalesce(wpgc.parent_id, wdc.gb_parent_id, wdc.parent_id) as gb_parent_id,\n" +
" coalesce(wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" +
" coalesce(wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" +
" coalesce(wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" +
" coalesce(wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" +
" coalesce(wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" +
" coalesce(wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" +
" coalesce(wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" +
" coalesce(wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" +
" coalesce(wdc.gb_port, wdc.port) as gb_port,\n" +
" coalesce(wdc.gb_password, wdc.password) as gb_password,\n" +
" coalesce(wdc.gb_status, wdc.status) as gb_status,\n" +
" coalesce(wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" +
" coalesce(wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" +
" coalesce(wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" +
" coalesce(wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" +
" coalesce(wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" +
" coalesce(wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" +
" coalesce(wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" +
" coalesce(wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" +
" coalesce(wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" +
" coalesce(wpgc.safety_way, wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" +
" coalesce(wpgc.register_way, wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" +
" coalesce(wpgc.cert_num, wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" +
" coalesce(wpgc.certifiable, wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" +
" coalesce(wpgc.err_code, wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" +
" coalesce(wpgc.end_time, wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" +
" coalesce(wpgc.secrecy, wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" +
" coalesce(wpgc.ip_address, wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" +
" coalesce(wpgc.port, wdc.gb_port, wdc.port) as gb_port,\n" +
" coalesce(wpgc.password, wdc.gb_password, wdc.password) as gb_password,\n" +
" coalesce(wpgc.status, wdc.gb_status, wdc.status) as gb_status,\n" +
" coalesce(wpgc.longitude, wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" +
" coalesce(wpgc.latitude, wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" +
" coalesce(wpgc.ptz_type, wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" +
" coalesce(wpgc.position_type, wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" +
" coalesce(wpgc.room_type, wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" +
" coalesce(wpgc.use_type, wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" +
" coalesce(wpgc.supply_light_type, wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" +
" coalesce(wpgc.direction_type, wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" +
" coalesce(wpgc.resolution, wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" +
" coalesce(wpgc.business_group_id, wdc.gb_business_group_id, wdc.business_group_id) as gb_business_group_id,\n" +
" coalesce(wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" +
" coalesce(wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" +
" coalesce(wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" +
" coalesce(wpgc.download_speed, wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" +
" coalesce(wpgc.svc_space_support_mod, wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" +
" coalesce(wpgc.svc_time_support_mode, wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" +
" from wvp_device_channel wdc" +
" left jon wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id" +
" left join wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id" +
" where wpgc.platform_id = #{platformId} and coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) = #{channelDeviceId}"
)

View File

@@ -1,9 +1,7 @@
package com.genersoft.iot.vmp.gb28181.dao;
import com.genersoft.iot.vmp.gb28181.bean.Platform;
import com.genersoft.iot.vmp.storager.dao.dto.ChannelSourceInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@@ -16,59 +14,59 @@ import java.util.List;
public interface PlatformMapper {
@Insert("INSERT INTO wvp_platform (enable, name, server_gb_id, server_gb_domain, server_ip, server_port,device_gb_id,device_ip,"+
"device_port,username,password,expires,keep_timeout,transport,character_set,ptz,rtcp,as_message_channel,auto_push_channel,"+
"status,catalog_id,administrative_division,catalog_group,create_time,update_time,send_stream_ip) " +
" VALUES (#{enable}, #{name}, #{serverGBId}, #{serverGBDomain}, #{serverIP}, #{serverPort}, #{deviceGBId}, #{deviceIp}, " +
" #{devicePort}, #{username}, #{password}, #{expires}, #{keepTimeout}, #{transport}, #{characterSet}, #{ptz}, #{rtcp}, #{asMessageChannel}, #{autoPushChannel}, " +
" #{status}, #{catalogId}, #{administrativeDivision}, #{catalogGroup}, #{createTime}, #{updateTime}, #{sendStreamIp})")
int addParentPlatform(Platform parentPlatform);
" device_port,username,password,expires,keep_timeout,transport,character_set,ptz,rtcp,status,catalog_group, update_time," +
" create_time, as_message_channel, send_stream_ip, auto_push_channel, catalog_with_platform,catalog_with_group,catalog_with_region, "+
" civil_code,manufacturer,model,address,register_way,secrecy) " +
" VALUES (#{enable}, #{name}, #{serverGBId}, #{serverGBDomain}, #{serverIp}, #{serverPort}, #{deviceGBId}, #{deviceIp}, " +
" #{devicePort}, #{username}, #{password}, #{expires}, #{keepTimeout}, #{transport}, #{characterSet}, #{ptz}, #{rtcp}, #{status}, #{catalogGroup},#{updateTime}," +
" #{createTime}, #{asMessageChannel}, #{sendStreamIp}, #{autoPushChannel}, #{catalogWithPlatform}, #{catalogWithGroup},#{catalogWithRegion}, " +
" #{civilCode}, #{manufacturer}, #{model}, #{address}, #{registerWay}, #{secrecy})")
int add(Platform parentPlatform);
@Update("UPDATE wvp_platform " +
"SET enable=#{enable}, " +
"name=#{name}," +
"device_gb_id=#{deviceGBId}," +
"server_gb_id=#{serverGBId}, " +
"server_gb_domain=#{serverGBDomain}, " +
"server_ip=#{serverIP}," +
"server_port=#{serverPort}, " +
"device_ip=#{deviceIp}, " +
"device_port=#{devicePort}, " +
"username=#{username}, " +
"password=#{password}, " +
"expires=#{expires}, " +
"keep_timeout=#{keepTimeout}, " +
"transport=#{transport}, " +
"character_set=#{characterSet}, " +
"ptz=#{ptz}, " +
"rtcp=#{rtcp}, " +
"as_message_channel=#{asMessageChannel}, " +
"auto_push_channel=#{autoPushChannel}, " +
"status=#{status}, " +
"catalog_group=#{catalogGroup}, " +
"administrative_division=#{administrativeDivision}, " +
"create_time=#{createTime}, " +
"update_time=#{updateTime}, " +
"send_stream_ip=#{sendStreamIp}, " +
"catalog_id=#{catalogId} " +
"SET update_time = #{updateTime}," +
" enable=#{enable}, " +
" name=#{name}," +
" server_gb_id=#{serverGBId}, " +
" server_gb_domain=#{serverGBDomain}, " +
" server_ip=#{serverIp}," +
" server_port=#{serverPort}, " +
" device_gb_id=#{deviceGBId}," +
" device_ip=#{deviceIp}, " +
" device_port=#{devicePort}, " +
" username=#{username}, " +
" password=#{password}, " +
" expires=#{expires}, " +
" keep_timeout=#{keepTimeout}, " +
" transport=#{transport}, " +
" character_set=#{characterSet}, " +
" ptz=#{ptz}, " +
" rtcp=#{rtcp}, " +
" status=#{status}, " +
" catalog_group=#{catalogGroup}, " +
" as_message_channel=#{asMessageChannel}, " +
" send_stream_ip=#{sendStreamIp}, " +
" auto_push_channel=#{autoPushChannel}, " +
" catalog_with_platform=#{catalogWithPlatform}, " +
" catalog_with_group=#{catalogWithGroup}, " +
" catalog_with_region=#{catalogWithRegion}, " +
" civil_code=#{civilCode}, " +
" manufacturer=#{manufacturer}, " +
" model=#{model}, " +
" address=#{address}, " +
" register_way=#{registerWay}, " +
" secrecy=#{secrecy} " +
"WHERE id=#{id}")
int updateParentPlatform(Platform parentPlatform);
int update(Platform parentPlatform);
@Delete("DELETE FROM wvp_platform WHERE server_gb_id=#{serverGBId}")
int delParentPlatform(Platform parentPlatform);
@Select("SELECT *, ((SELECT count(0)\n" +
" FROM wvp_platform_gb_channel pc\n" +
" WHERE pc.platform_id = pp.server_gb_id)\n" +
" +\n" +
" (SELECT count(0)\n" +
" FROM wvp_platform_gb_stream pgs\n" +
" WHERE pgs.platform_id = pp.server_gb_id)\n" +
" +\n" +
" (SELECT count(0)\n" +
" FROM wvp_platform_catalog pgc\n" +
" WHERE pgc.platform_id = pp.server_gb_id)) as channel_count\n" +
"FROM wvp_platform pp ")
List<Platform> getParentPlatformList();
@Select(" SELECT pp.*, " +
" (SELECT count(0) FROM wvp_platform_gb_channel pc WHERE pc.platform_id = pp.id ) as channel_count" +
" FROM wvp_platform pp "
)
List<Platform> queryList();
@Select("SELECT * FROM wvp_platform WHERE enable=#{enable} ")
List<Platform> getEnableParentPlatformList(boolean enable);
@@ -80,23 +78,9 @@ public interface PlatformMapper {
Platform getParentPlatByServerGBId(String platformGbId);
@Select("SELECT * FROM wvp_platform WHERE id=#{id}")
Platform getParentPlatById(int id);
@Update("UPDATE wvp_platform SET status=false" )
int outlineForAllParentPlatform();
Platform query(int id);
@Update("UPDATE wvp_platform SET status=#{online} WHERE server_gb_id=#{platformGbID}" )
int updateParentPlatformStatus(@Param("platformGbID") String platformGbID, @Param("online") boolean online);
int updateStatus(@Param("platformGbID") String platformGbID, @Param("online") boolean online);
@Update(value = {" <script>" +
"UPDATE wvp_platform " +
"SET catalog_id=#{catalogId}, update_time=#{updateTime}" +
"WHERE server_gb_id=#{platformId}"+
"</script>"})
int setDefaultCatalog(@Param("platformId") String platformId, @Param("catalogId") String catalogId, @Param("updateTime") String updateTime);
@Select("select 'channel' as name, count(pgc.platform_id) count from wvp_platform_gb_channel pgc left join wvp_device_channel dc on dc.id = pgc.device_channel_id where pgc.platform_id=#{platform_id} and dc.channel_id =#{gbId} " +
"union " +
"select 'stream' as name, count(pgs.platform_id) count from wvp_platform_gb_stream pgs left join wvp_gb_stream gs on pgs.gb_stream_id = gs.gb_stream_id where pgs.platform_id=#{platform_id} and gs.gb_id =#{gbId}")
List<ChannelSourceInfo> getChannelSource(@Param("platform_id") String platform_id, @Param("gbId") String gbId);
}

View File

@@ -1,7 +1,6 @@
package com.genersoft.iot.vmp.gb28181.service;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.Platform;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
@@ -28,7 +27,7 @@ public interface IPlatformService {
* @param count
* @return
*/
PageInfo<Platform> queryParentPlatformList(int page, int count);
PageInfo<Platform> queryPlatformList(int page, int count);
/**
* 添加级联平台

View File

@@ -36,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.sdp.*;
import javax.sip.InvalidArgumentException;
@@ -130,14 +131,14 @@ public class PlatformServiceImpl implements IPlatformService {
List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServerByStream(event.getStream());
if (sendRtpItems != null && !sendRtpItems.isEmpty()) {
for (SendRtpItem sendRtpItem : sendRtpItems) {
Platform parentPlatform = platformMapper.getParentPlatByServerGBId(sendRtpItem.getPlatformId());
Platform platform = platformMapper.getParentPlatByServerGBId(sendRtpItem.getPlatformId());
ssrcFactory.releaseSsrc(sendRtpItem.getMediaServerId(), sendRtpItem.getSsrc());
try {
commanderForPlatform.streamByeCmd(parentPlatform, sendRtpItem.getCallId());
commanderForPlatform.streamByeCmd(platform, sendRtpItem.getCallId());
} catch (SipException | InvalidArgumentException | ParseException e) {
log.error("[命令发送失败] 国标级联 发送BYE: {}", e.getMessage());
}
redisCatchStorage.deleteSendRTPServer(parentPlatform.getServerGBId(), sendRtpItem.getChannelId(),
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), sendRtpItem.getChannelId(),
sendRtpItem.getCallId(), sendRtpItem.getStream());
}
}
@@ -150,32 +151,31 @@ public class PlatformServiceImpl implements IPlatformService {
}
@Override
public PageInfo<Platform> queryParentPlatformList(int page, int count) {
public PageInfo<Platform> queryPlatformList(int page, int count) {
PageHelper.startPage(page, count);
List<Platform> all = platformMapper.getParentPlatformList();
List<Platform> all = platformMapper.queryList();
return new PageInfo<>(all);
}
@Override
public boolean add(Platform parentPlatform) {
if (parentPlatform.getCatalogGroup() == 0) {
public boolean add(Platform platform) {
log.info("[国标级联]添加平台 {}", platform.getDeviceGBId());
if (platform.getCatalogGroup() == 0) {
// 每次发送目录的数量默认为1
parentPlatform.setCatalogGroup(1);
platform.setCatalogGroup(1);
}
int result = platformMapper.addParentPlatform(parentPlatform);
int result = platformMapper.add(platform);
// 添加缓存
PlatformCatch parentPlatformCatch = new PlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setId(parentPlatform.getServerGBId());
parentPlatformCatch.setParentPlatform(parentPlatform);
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
if (parentPlatform.isEnable()) {
PlatformCatch platformCatch = new PlatformCatch();
platformCatch.setPlatform(platform);
platformCatch.setId(platform.getServerGBId());
redisCatchStorage.updatePlatformCatchInfo(platformCatch);
if (platform.isEnable()) {
// 保存时启用就发送注册
// 注册成功时由程序直接调用了online方法
try {
commanderForPlatform.register(parentPlatform, eventResult -> {
log.info("[国标级联] {},添加向上级注册失败,请确定上级平台可用时重新保存", parentPlatform.getServerGBId());
commanderForPlatform.register(platform, eventResult -> {
log.info("[国标级联] {}{},添加向上级注册失败,请确定上级平台可用时重新保存", platform.getName(), platform.getServerGBId());
}, null);
} catch (InvalidArgumentException | ParseException | SipException e) {
log.error("[命令发送失败] 国标级联: {}", e.getMessage());
@@ -185,25 +185,26 @@ public class PlatformServiceImpl implements IPlatformService {
}
@Override
public boolean update(Platform parentPlatform) {
log.info("[国标级联]更新平台 {}", parentPlatform.getDeviceGBId());
parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase());
Platform parentPlatformOld = platformMapper.getParentPlatById(parentPlatform.getId());
PlatformCatch parentPlatformCatchOld = redisCatchStorage.queryPlatformCatchInfo(parentPlatformOld.getServerGBId());
parentPlatform.setUpdateTime(DateUtil.getNow());
public boolean update(Platform platform) {
Assert.isTrue(platform.getId() > 0, "ID必须存在");
log.info("[国标级联] 更新平台 {}({})", platform.getName(), platform.getDeviceGBId());
platform.setCharacterSet(platform.getCharacterSet().toUpperCase());
Platform platformInDb = platformMapper.query(platform.getId());
PlatformCatch platformCatchOld = redisCatchStorage.queryPlatformCatchInfo(platformInDb.getServerGBId());
platform.setUpdateTime(DateUtil.getNow());
// 停止心跳定时
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatformOld.getServerGBId();
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + platformInDb.getServerGBId();
dynamicTask.stop(keepaliveTaskKey);
// 停止注册定时
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatformOld.getServerGBId();
final String registerTaskKey = REGISTER_KEY_PREFIX + platformInDb.getServerGBId();
dynamicTask.stop(registerTaskKey);
// 注销旧的
try {
if (parentPlatformOld.isStatus() && parentPlatformCatchOld != null) {
log.info("保存平台{}时发现旧平台在线,发送注销命令", parentPlatformOld.getServerGBId());
commanderForPlatform.unregister(parentPlatformOld, parentPlatformCatchOld.getSipTransactionInfo(), null, eventResult -> {
log.info("[国标级联] 注销成功, 平台:{}", parentPlatformOld.getServerGBId());
if (platformInDb.isStatus() && platformCatchOld != null) {
log.info("保存平台{}时发现旧平台在线,发送注销命令", platformInDb.getServerGBId());
commanderForPlatform.unregister(platformInDb, platformCatchOld.getSipTransactionInfo(), null, eventResult -> {
log.info("[国标级联] 注销成功, 平台:{}", platformInDb.getServerGBId());
});
}
} catch (InvalidArgumentException | ParseException | SipException e) {
@@ -211,98 +212,97 @@ public class PlatformServiceImpl implements IPlatformService {
}
// 更新数据库
if (parentPlatform.getCatalogGroup() == 0) {
parentPlatform.setCatalogGroup(1);
if (platform.getCatalogGroup() == 0) {
platform.setCatalogGroup(1);
}
platformMapper.updateParentPlatform(parentPlatform);
platformMapper.update(platform);
// 更新redis
redisCatchStorage.delPlatformCatchInfo(parentPlatformOld.getServerGBId());
PlatformCatch parentPlatformCatch = new PlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setId(parentPlatform.getServerGBId());
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
redisCatchStorage.delPlatformCatchInfo(platformInDb.getServerGBId());
PlatformCatch platformCatch = new PlatformCatch();
platformCatch.setPlatform(platform);
platformCatch.setId(platform.getServerGBId());
redisCatchStorage.updatePlatformCatchInfo(platformCatch);
// 注册
if (parentPlatform.isEnable()) {
if (platform.isEnable()) {
// 保存时启用就发送注册
// 注册成功时由程序直接调用了online方法
try {
log.info("[国标级联] 平台注册 {}", parentPlatform.getDeviceGBId());
commanderForPlatform.register(parentPlatform, eventResult -> {
log.info("[国标级联] {},添加向上级注册失败,请确定上级平台可用时重新保存", parentPlatform.getServerGBId());
log.info("[国标级联] 平台注册 {}", platform.getDeviceGBId());
commanderForPlatform.register(platform, eventResult -> {
log.info("[国标级联] {},添加向上级注册失败,请确定上级平台可用时重新保存", platform.getServerGBId());
}, null);
} catch (InvalidArgumentException | ParseException | SipException e) {
log.error("[命令发送失败] 国标级联: {}", e.getMessage());
}
}
return false;
}
@Override
public void online(Platform parentPlatform, SipTransactionInfo sipTransactionInfo) {
log.info("[国标级联]{}, 平台上线", parentPlatform.getServerGBId());
final String registerFailAgainTaskKey = REGISTER_FAIL_AGAIN_KEY_PREFIX + parentPlatform.getServerGBId();
public void online(Platform platform, SipTransactionInfo sipTransactionInfo) {
log.info("[国标级联]{}, 平台上线", platform.getServerGBId());
final String registerFailAgainTaskKey = REGISTER_FAIL_AGAIN_KEY_PREFIX + platform.getServerGBId();
dynamicTask.stop(registerFailAgainTaskKey);
platformMapper.updateParentPlatformStatus(parentPlatform.getServerGBId(), true);
PlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
if (parentPlatformCatch == null) {
parentPlatformCatch = new PlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setId(parentPlatform.getServerGBId());
parentPlatform.setStatus(true);
parentPlatformCatch.setParentPlatform(parentPlatform);
platformMapper.updateStatus(platform.getServerGBId(), true);
PlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(platform.getServerGBId());
if (platformCatch == null) {
platformCatch = new PlatformCatch();
platformCatch.setPlatform(platform);
platformCatch.setId(platform.getServerGBId());
platform.setStatus(true);
platformCatch.setPlatform(platform);
}
parentPlatformCatch.getParentPlatform().setStatus(true);
parentPlatformCatch.setSipTransactionInfo(sipTransactionInfo);
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
platformCatch.getPlatform().setStatus(true);
platformCatch.setSipTransactionInfo(sipTransactionInfo);
redisCatchStorage.updatePlatformCatchInfo(platformCatch);
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
final String registerTaskKey = REGISTER_KEY_PREFIX + platform.getServerGBId();
if (!dynamicTask.isAlive(registerTaskKey)) {
log.info("[国标级联]{}, 添加定时注册任务", parentPlatform.getServerGBId());
log.info("[国标级联]{}, 添加定时注册任务", platform.getServerGBId());
// 添加注册任务
dynamicTask.startCron(registerTaskKey,
// 注册失败注册成功时由程序直接调用了online方法
()-> registerTask(parentPlatform, sipTransactionInfo),
parentPlatform.getExpires() * 1000);
()-> registerTask(platform, sipTransactionInfo),
platform.getExpires() * 1000);
}
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId();
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + platform.getServerGBId();
if (!dynamicTask.contains(keepaliveTaskKey)) {
log.info("[国标级联]{}, 添加定时心跳任务", parentPlatform.getServerGBId());
log.info("[国标级联]{}, 添加定时心跳任务", platform.getServerGBId());
// 添加心跳任务
dynamicTask.startCron(keepaliveTaskKey,
()-> {
try {
commanderForPlatform.keepalive(parentPlatform, eventResult -> {
commanderForPlatform.keepalive(platform, eventResult -> {
// 心跳失败
if (eventResult.type != SipSubscribe.EventResultType.timeout) {
log.warn("[国标级联]发送心跳收到错误code {}, msg: {}", eventResult.statusCode, eventResult.msg);
}
// 心跳失败
PlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
PlatformCatch platformCatchForNow = redisCatchStorage.queryPlatformCatchInfo(platform.getServerGBId());
// 此时是第三次心跳超时, 平台离线
if (platformCatch.getKeepAliveReply() == 2) {
if (platformCatchForNow.getKeepAliveReply() == 2) {
// 设置平台离线,并重新注册
log.info("[国标级联] 三次心跳失败, 平台{}({})离线", parentPlatform.getName(), parentPlatform.getServerGBId());
offline(parentPlatform, false);
log.info("[国标级联] 三次心跳失败, 平台{}({})离线", platform.getName(), platform.getServerGBId());
offline(platform, false);
}else {
platformCatch.setKeepAliveReply(platformCatch.getKeepAliveReply() + 1);
redisCatchStorage.updatePlatformCatchInfo(platformCatch);
platformCatchForNow.setKeepAliveReply(platformCatchForNow.getKeepAliveReply() + 1);
redisCatchStorage.updatePlatformCatchInfo(platformCatchForNow);
}
}, eventResult -> {
// 心跳成功
// 清空之前的心跳超时计数
PlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
if (platformCatch != null && platformCatch.getKeepAliveReply() > 0) {
platformCatch.setKeepAliveReply(0);
redisCatchStorage.updatePlatformCatchInfo(platformCatch);
PlatformCatch platformCatchForNow = redisCatchStorage.queryPlatformCatchInfo(platform.getServerGBId());
if (platformCatchForNow != null && platformCatchForNow.getKeepAliveReply() > 0) {
platformCatchForNow.setKeepAliveReply(0);
redisCatchStorage.updatePlatformCatchInfo(platformCatchForNow);
}
log.info("[发送心跳] 国标级联 发送心跳, code {}, msg: {}", eventResult.statusCode, eventResult.msg);
});
@@ -310,37 +310,37 @@ public class PlatformServiceImpl implements IPlatformService {
log.error("[命令发送失败] 国标级联 发送心跳: {}", e.getMessage());
}
},
(parentPlatform.getKeepTimeout())*1000);
(platform.getKeepTimeout())*1000);
}
if (parentPlatform.getAutoPushChannel() != null && parentPlatform.getAutoPushChannel()) {
if (subscribeHolder.getCatalogSubscribe(parentPlatform.getServerGBId()) == null) {
log.info("[国标级联]{}, 添加自动通道推送模拟订阅信息", parentPlatform.getServerGBId());
addSimulatedSubscribeInfo(parentPlatform);
if (platform.getAutoPushChannel() != null && platform.getAutoPushChannel()) {
if (subscribeHolder.getCatalogSubscribe(platform.getServerGBId()) == null) {
log.info("[国标级联]{}, 添加自动通道推送模拟订阅信息", platform.getServerGBId());
addSimulatedSubscribeInfo(platform);
}
}else {
SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(parentPlatform.getServerGBId());
SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platform.getServerGBId());
if (catalogSubscribe != null && catalogSubscribe.getExpires() == -1) {
subscribeHolder.removeCatalogSubscribe(parentPlatform.getServerGBId());
subscribeHolder.removeCatalogSubscribe(platform.getServerGBId());
}
}
}
@Override
public void addSimulatedSubscribeInfo(Platform parentPlatform) {
public void addSimulatedSubscribeInfo(Platform platform) {
// 自动添加一条模拟的订阅信息
SubscribeInfo subscribeInfo = new SubscribeInfo();
subscribeInfo.setId(parentPlatform.getServerGBId());
subscribeInfo.setId(platform.getServerGBId());
subscribeInfo.setExpires(-1);
subscribeInfo.setEventType("Catalog");
int random = (int) Math.floor(Math.random() * 10000);
subscribeInfo.setEventId(random + "");
subscribeInfo.setSimulatedCallId(UUID.randomUUID().toString().replace("-", "") + "@" + parentPlatform.getServerIP());
subscribeInfo.setSimulatedCallId(UUID.randomUUID().toString().replace("-", "") + "@" + platform.getServerIp());
subscribeInfo.setSimulatedFromTag(UUID.randomUUID().toString().replace("-", ""));
subscribeInfo.setSimulatedToTag(UUID.randomUUID().toString().replace("-", ""));
subscribeHolder.putCatalogSubscribe(parentPlatform.getServerGBId(), subscribeInfo);
subscribeHolder.putCatalogSubscribe(platform.getServerGBId(), subscribeInfo);
}
private void registerTask(Platform parentPlatform, SipTransactionInfo sipTransactionInfo){
private void registerTask(Platform platform, SipTransactionInfo sipTransactionInfo){
try {
// 不在同一个会话中续订则每次全新注册
if (!userSetting.isRegisterKeepIntDialog()) {
@@ -348,15 +348,15 @@ public class PlatformServiceImpl implements IPlatformService {
}
if (sipTransactionInfo == null) {
log.info("[国标级联] 平台:{}注册即将到期,开始重新注册", parentPlatform.getServerGBId());
log.info("[国标级联] 平台:{}注册即将到期,开始重新注册", platform.getServerGBId());
}else {
log.info("[国标级联] 平台:{}注册即将到期,开始续订", parentPlatform.getServerGBId());
log.info("[国标级联] 平台:{}注册即将到期,开始续订", platform.getServerGBId());
}
commanderForPlatform.register(parentPlatform, sipTransactionInfo, eventResult -> {
log.info("[国标级联] 平台:{}注册失败,{}:{}", parentPlatform.getServerGBId(),
commanderForPlatform.register(platform, sipTransactionInfo, eventResult -> {
log.info("[国标级联] 平台:{}注册失败,{}:{}", platform.getServerGBId(),
eventResult.statusCode, eventResult.msg);
offline(parentPlatform, false);
offline(platform, false);
}, null);
} catch (Exception e) {
log.error("[命令发送失败] 国标级联定时注册: {}", e.getMessage());
@@ -364,52 +364,52 @@ public class PlatformServiceImpl implements IPlatformService {
}
@Override
public void offline(Platform parentPlatform, boolean stopRegister) {
log.info("[平台离线]{}", parentPlatform.getServerGBId());
PlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
parentPlatformCatch.setKeepAliveReply(0);
parentPlatformCatch.setRegisterAliveReply(0);
Platform parentPlatformInCatch = parentPlatformCatch.getParentPlatform();
parentPlatformInCatch.setStatus(false);
parentPlatformCatch.setParentPlatform(parentPlatformInCatch);
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
platformMapper.updateParentPlatformStatus(parentPlatform.getServerGBId(), false);
public void offline(Platform platform, boolean stopRegister) {
log.info("[平台离线]{}", platform.getServerGBId());
PlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(platform.getServerGBId());
platformCatch.setKeepAliveReply(0);
platformCatch.setRegisterAliveReply(0);
Platform catchPlatform = platformCatch.getPlatform();
catchPlatform.setStatus(false);
platformCatch.setPlatform(catchPlatform);
redisCatchStorage.updatePlatformCatchInfo(platformCatch);
platformMapper.updateStatus(platform.getServerGBId(), false);
// 停止所有推流
log.info("[平台离线] {}, 停止所有推流", parentPlatform.getServerGBId());
stopAllPush(parentPlatform.getServerGBId());
log.info("[平台离线] {}, 停止所有推流", platform.getServerGBId());
stopAllPush(platform.getServerGBId());
// 清除注册定时
log.info("[平台离线] {}, 停止定时注册任务", parentPlatform.getServerGBId());
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
log.info("[平台离线] {}, 停止定时注册任务", platform.getServerGBId());
final String registerTaskKey = REGISTER_KEY_PREFIX + platform.getServerGBId();
if (dynamicTask.contains(registerTaskKey)) {
dynamicTask.stop(registerTaskKey);
}
// 清除心跳定时
log.info("[平台离线] {}, 停止定时发送心跳任务", parentPlatform.getServerGBId());
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId();
log.info("[平台离线] {}, 停止定时发送心跳任务", platform.getServerGBId());
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + platform.getServerGBId();
if (dynamicTask.contains(keepaliveTaskKey)) {
// 清除心跳任务
dynamicTask.stop(keepaliveTaskKey);
}
// 停止订阅回复
SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(parentPlatform.getServerGBId());
SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platform.getServerGBId());
if (catalogSubscribe != null) {
if (catalogSubscribe.getExpires() > 0) {
log.info("[平台离线] {}, 停止目录订阅回复", parentPlatform.getServerGBId());
subscribeHolder.removeCatalogSubscribe(parentPlatform.getServerGBId());
log.info("[平台离线] {}, 停止目录订阅回复", platform.getServerGBId());
subscribeHolder.removeCatalogSubscribe(platform.getServerGBId());
}
}
log.info("[平台离线] {}, 停止移动位置订阅回复", parentPlatform.getServerGBId());
subscribeHolder.removeMobilePositionSubscribe(parentPlatform.getServerGBId());
log.info("[平台离线] {}, 停止移动位置订阅回复", platform.getServerGBId());
subscribeHolder.removeMobilePositionSubscribe(platform.getServerGBId());
// 发起定时自动重新注册
if (!stopRegister) {
// 设置为60秒自动尝试重新注册
final String registerFailAgainTaskKey = REGISTER_FAIL_AGAIN_KEY_PREFIX + parentPlatform.getServerGBId();
Platform platform = platformMapper.getParentPlatById(parentPlatform.getId());
if (platform.isEnable()) {
final String registerFailAgainTaskKey = REGISTER_FAIL_AGAIN_KEY_PREFIX + platform.getServerGBId();
Platform platformInDb = platformMapper.query(platform.getId());
if (platformInDb.isEnable()) {
dynamicTask.startCron(registerFailAgainTaskKey,
()-> registerTask(platform, null),
()-> registerTask(platformInDb, null),
userSetting.getRegisterAgainAfterTime() * 1000);
}
}
@@ -428,15 +428,15 @@ public class PlatformServiceImpl implements IPlatformService {
}
@Override
public void login(Platform parentPlatform) {
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
public void login(Platform platform) {
final String registerTaskKey = REGISTER_KEY_PREFIX + platform.getServerGBId();
try {
commanderForPlatform.register(parentPlatform, eventResult1 -> {
log.info("[国标级联] {}开始定时发起注册间隔为1分钟", parentPlatform.getServerGBId());
commanderForPlatform.register(platform, eventResult1 -> {
log.info("[国标级联] {}开始定时发起注册间隔为1分钟", platform.getServerGBId());
// 添加注册任务
dynamicTask.startCron(registerTaskKey,
// 注册失败注册成功时由程序直接调用了online方法
()-> log.info("[国标级联] {},平台离线后持续发起注册,失败", parentPlatform.getServerGBId()),
()-> log.info("[国标级联] {},平台离线后持续发起注册,失败", platform.getServerGBId()),
60*1000);
}, null);
} catch (InvalidArgumentException | ParseException | SipException e) {
@@ -807,6 +807,6 @@ public class PlatformServiceImpl implements IPlatformService {
@Override
public Platform queryOne(Integer platformId) {
return platformMapper.getParentPlatById(platformId);
return platformMapper.query(platformId);
}
}

View File

@@ -52,7 +52,7 @@ public class SIPRequestHeaderPlarformProvider {
String sipAddress = parentPlatform.getDeviceIp() + ":" + parentPlatform.getDevicePort();
//请求行
SipURI requestLine = SipFactory.getInstance().createAddressFactory().createSipURI(parentPlatform.getServerGBId(),
parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
parentPlatform.getServerIp() + ":" + parentPlatform.getServerPort());
//via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
ViaHeader viaHeader = SipFactory.getInstance().createHeaderFactory().createViaHeader(parentPlatform.getDeviceIp(),
@@ -93,7 +93,7 @@ public class SIPRequestHeaderPlarformProvider {
Request registerRequest = createRegisterRequest(parentPlatform, redisCatchStorage.getCSEQ(), fromTag, toTag, callIdHeader, expires);
SipURI requestURI = SipFactory.getInstance().createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
SipURI requestURI = SipFactory.getInstance().createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIp() + ":" + parentPlatform.getServerPort());
if (www == null) {
AuthorizationHeader authorizationHeader = SipFactory.getInstance().createHeaderFactory().createAuthorizationHeader("Digest");
String username = parentPlatform.getUsername();
@@ -178,7 +178,7 @@ public class SIPRequestHeaderPlarformProvider {
public Request createMessageRequest(Platform parentPlatform, String content, String fromTag, String viaTag, String toTag, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException {
Request request = null;
String serverAddress = parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort();
String serverAddress = parentPlatform.getServerIp()+ ":" + parentPlatform.getServerPort();
// sipuri
SipURI requestURI = SipFactory.getInstance().createAddressFactory().createSipURI(parentPlatform.getServerGBId(), serverAddress);
// via
@@ -217,7 +217,7 @@ public class SIPRequestHeaderPlarformProvider {
public SIPRequest createNotifyRequest(Platform parentPlatform, String content, SubscribeInfo subscribeInfo) throws PeerUnavailableException, ParseException, InvalidArgumentException {
SIPRequest request = null;
// sipuri
SipURI requestURI = SipFactory.getInstance().createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort());
SipURI requestURI = SipFactory.getInstance().createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIp()+ ":" + parentPlatform.getServerPort());
// via
ArrayList<ViaHeader> viaHeaders = new ArrayList<>();
ViaHeader viaHeader = SipFactory.getInstance().createHeaderFactory().createViaHeader(parentPlatform.getDeviceIp(), parentPlatform.getDevicePort(),
@@ -277,7 +277,7 @@ public class SIPRequestHeaderPlarformProvider {
SIPRequest request = null;
// sipuri
SipURI requestURI = SipFactory.getInstance().createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+ ":" + platform.getServerPort());
SipURI requestURI = SipFactory.getInstance().createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIp()+ ":" + platform.getServerPort());
// via
ArrayList<ViaHeader> viaHeaders = new ArrayList<>();
ViaHeader viaHeader = SipFactory.getInstance().createHeaderFactory().createViaHeader(platform.getDeviceIp(), platform.getDevicePort(),
@@ -318,7 +318,7 @@ public class SIPRequestHeaderPlarformProvider {
public Request createInviteRequest(Platform platform, String channelId, String content, String viaTag, String fromTag, String ssrc, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException {
Request request = null;
//请求行
String platformHostAddress = platform.getServerIP() + ":" + platform.getServerPort();
String platformHostAddress = platform.getServerIp() + ":" + platform.getServerPort();
String localHostAddress = sipLayer.getLocalIp(platform.getDeviceIp())+":"+ platform.getDevicePort();
SipURI requestLine = SipFactory.getInstance().createAddressFactory().createSipURI(channelId, platformHostAddress);
//via

View File

@@ -134,7 +134,7 @@ public abstract class SIPRequestProcessorParent {
// 兼容国标中的使用编码@域名作为RequestURI的情况
SipURI sipURI = (SipURI)request.getRequestURI();
if (sipURI.getPort() == -1) {
sipURI = SipFactory.getInstance().createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort());
sipURI = SipFactory.getInstance().createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIp()+":"+platform.getServerPort());
}
ResponseAckExtraParam responseAckExtraParam = new ResponseAckExtraParam();
responseAckExtraParam.contentTypeHeader = contentTypeHeader;
@@ -155,7 +155,7 @@ public abstract class SIPRequestProcessorParent {
SipURI sipURI = (SipURI)request.getRequestURI();
if (sipURI.getPort() == -1) {
sipURI = SipFactory.getInstance().createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort());
sipURI = SipFactory.getInstance().createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIp()+":"+platform.getServerPort());
}
ResponseAckExtraParam responseAckExtraParam = new ResponseAckExtraParam();
responseAckExtraParam.contentTypeHeader = contentTypeHeader;

View File

@@ -1217,7 +1217,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
content.append("f=v/////a/1/8/1\r\n");
Platform parentPlatform = new Platform();
parentPlatform.setServerIP(device.getIp());
parentPlatform.setServerIp(device.getIp());
parentPlatform.setServerPort(device.getPort());
parentPlatform.setServerGBId(device.getDeviceId());

View File

@@ -73,7 +73,7 @@ public class RegisterResponseProcessor extends SIPResponseProcessorAbstract {
String action = platformRegisterInfo.isRegister() ? "注册" : "注销";
log.info(String.format("[国标级联]%s %S响应,%s ", action, response.getStatusCode(), platformRegisterInfo.getPlatformId() ));
Platform parentPlatform = parentPlatformCatch.getParentPlatform();
Platform parentPlatform = parentPlatformCatch.getPlatform();
if (parentPlatform == null) {
log.warn(String.format("[国标级联]收到 %s %s的%S请求, 但是平台信息未查询到!!!", platformRegisterInfo.getPlatformId(), action, response.getStatusCode()));
return;

View File

@@ -64,25 +64,25 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
}
PlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); // .getDeviceGBId());
if (parentPlatform.getId() == null ) {
result = platformMapper.addParentPlatform(parentPlatform);
result = platformMapper.add(parentPlatform);
if (parentPlatformCatch == null) {
parentPlatformCatch = new PlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setPlatform(parentPlatform);
parentPlatformCatch.setId(parentPlatform.getServerGBId());
}
}else {
if (parentPlatformCatch == null) { // serverGBId 已变化
Platform parentPlatById = platformMapper.getParentPlatById(parentPlatform.getId());
Platform parentPlatById = platformMapper.query(parentPlatform.getId());
// 使用旧的查出缓存ID
parentPlatformCatch = new PlatformCatch();
parentPlatformCatch.setId(parentPlatform.getServerGBId());
redisCatchStorage.delPlatformCatchInfo(parentPlatById.getServerGBId());
}
result = platformMapper.updateParentPlatform(parentPlatform);
result = platformMapper.update(parentPlatform);
}
// 更新缓存
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setPlatform(parentPlatform);
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
return result > 0;