规范数据库,解决bug

This commit is contained in:
648540858
2022-02-25 20:33:02 +08:00
parent a42dda2bd3
commit 7400ace65d
19 changed files with 142 additions and 82 deletions

View File

@@ -3,6 +3,10 @@ package com.genersoft.iot.vmp.gb28181.bean;
public class DeviceChannel {
/**
* 数据库自赠ID
*/
private int id;
/**
* 通道id
@@ -165,6 +169,14 @@ public class DeviceChannel {
*/
private boolean hasAudio;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDeviceId() {
return deviceId;
}

View File

@@ -60,7 +60,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
Map<String, List<ParentPlatform>> parentPlatformMap = new HashMap<>();
if (event.getPlatformId() != null) {
parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformId());
if (!parentPlatform.isStatus())return;
if (parentPlatform != null && !parentPlatform.isStatus())return;
String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetup.getServerId() + "_Catalog_" + event.getPlatformId();
subscribe = redisCatchStorage.getSubscribe(key);
if (subscribe == null) return;

View File

@@ -98,7 +98,6 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
DeviceChannel deviceChannel = storager.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId());
deviceChannel.setParental(0);
deviceChannel.setParentId(channelReduce.getCatalogId());
cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
// 防止发送过快
Thread.sleep(50);

View File

@@ -122,7 +122,6 @@ public class ZLMMediaListManager {
transform.setName(thirdPartyGB.getName());
}
}
storager.updateMedia(transform);
if (!StringUtils.isEmpty(transform.getGbId())) {
// 如果这个国标ID已经给了其他推流且流已离线则移除其他推流
List<GbStream> gbStreams = gbStreamMapper.selectByGBId(transform.getGbId());
@@ -135,13 +134,16 @@ public class ZLMMediaListManager {
}
}
}
if (gbStreamMapper.selectOne(transform.getApp(), transform.getStream()) != null) {
StreamProxyItem streamProxyItem = gbStreamMapper.selectOne(transform.getApp(), transform.getStream());
if (streamProxyItem != null) {
transform.setGbStreamId(streamProxyItem.getGbStreamId());
gbStreamMapper.update(transform);
}else {
transform.setCreateStamp(System.currentTimeMillis());
gbStreamMapper.add(transform);
}
}
storager.updateMedia(transform);
return transform;
}

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import okhttp3.*;
import okhttp3.logging.HttpLoggingInterceptor;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,8 +26,23 @@ public class ZLMRESTfulUtils {
void run(JSONObject response);
}
private OkHttpClient getClient(){
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
if (logger.isDebugEnabled()) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> {
logger.debug("http请求参数" + message);
});
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
// OkHttp進行添加攔截器loggingInterceptor
httpClientBuilder.addInterceptor(logging);
}
return httpClientBuilder.build();
}
public JSONObject sendPost(MediaServerItem mediaServerItem, String api, Map<String, Object> param, RequestCallback callback) {
OkHttpClient client = new OkHttpClient();
OkHttpClient client = getClient();
if (mediaServerItem == null) {
return null;
}
@@ -56,6 +72,7 @@ public class ZLMRESTfulUtils {
ResponseBody responseBody = response.body();
if (responseBody != null) {
String responseStr = responseBody.string();
System.out.println(responseStr);
responseJSON = JSON.parseObject(responseStr);
}
}else {

View File

@@ -87,26 +87,27 @@ public interface DeviceChannelMapper {
void startPlay(String deviceId, String channelId, String streamId);
@Select(value = {" <script>" +
"SELECT dc.channelId, "+
"dc.deviceId, " +
"dc.name, " +
"de.manufacturer, " +
"de.hostAddress, " +
"dc.subCount, " +
"pgc.platformId as platformId, " +
"pgc.catalogId as catalogId " +
"FROM device_channel dc " +
"LEFT JOIN device de ON dc.deviceId = de.deviceId " +
"LEFT JOIN platform_gb_channel pgc on de.deviceId = pgc.deviceId and pgc.channelId = dc.channelId " +
"LEFT JOIN device_channel dc2 ON dc2.deviceId = de.deviceId AND dc2.parentId = dc.channelId " +
"SELECT " +
" dc.id,\n" +
" dc.channelId,\n" +
" dc.deviceId,\n" +
" dc.name,\n" +
" de.manufacturer,\n" +
" de.hostAddress,\n" +
" dc.subCount,\n" +
" pgc.platformId as platformId,\n" +
" pgc.catalogId as catalogId " +
" FROM device_channel dc " +
" LEFT JOIN device de ON dc.deviceId = de.deviceId " +
" LEFT JOIN platform_gb_channel pgc on pgc.deviceChannelId = dc.id " +
" WHERE 1=1 " +
" <if test='query != null'> AND (dc.channelId LIKE '%${query}%' OR dc.name LIKE '%${query}%' OR dc.name LIKE '%${query}%')</if> " +
" <if test='online == true' > AND dc.status=1</if> " +
" <if test='online == false' > AND dc.status=0</if> " +
" <if test='hasSubChannel!= null and hasSubChannel == true' > AND dc2.channelId is not null</if> " +
" <if test='hasSubChannel!= null and hasSubChannel == false' > AND dc2.channelId is null</if> " +
" <if test='catalogId == null ' > AND ((pgc.platformId IS NULL AND pgc.catalogId IS NULL) or (pgc.platformId != #{platformId}))</if> " +
" <if test='catalogId != null ' > AND pgc.platformId =#{platformId} AND pgc.catalogId = #{catalogId}</if> " +
" <if test='hasSubChannel!= null and hasSubChannel == true' > AND dc.subCount > 0</if> " +
" <if test='hasSubChannel!= null and hasSubChannel == false' > AND dc.subCount == 0</if> " +
" <if test='catalogId == null ' > AND dc.id not in (select deviceChannelId from platform_gb_channel where platformId=#{platformId} ) </if> " +
" <if test='catalogId != null ' > AND pgc.platformId = #{platformId} and pgc.catalogId=#{catalogId} </if> " +
" ORDER BY dc.deviceId, dc.channelId ASC" +
" </script>"})
List<ChannelReduce> queryChannelListInAll(String query, Boolean online, Boolean hasSubChannel, String platformId, String catalogId);
@@ -196,8 +197,8 @@ public interface DeviceChannelMapper {
List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId);
@Select(" SELECT\n" +
" id,\n" +
" channelId,\n" +
" channelId as id,\n" +
" deviceId,\n" +
" parentId,\n" +
" status,\n" +

View File

@@ -19,6 +19,7 @@ public interface GbStreamMapper {
"('${app}', '${stream}', '${gbId}', '${name}', " +
"'${longitude}', '${latitude}', '${streamType}', " +
"'${mediaServerId}', ${status}, ${createStamp})")
@Options(useGeneratedKeys = true, keyProperty = "gbStreamId", keyColumn = "gbStreamId")
int add(GbStream gbStream);
@Update("UPDATE gb_stream " +

View File

@@ -21,22 +21,22 @@ public interface PlatformChannelMapper {
* 查询列表里已经关联的
*/
@Select("<script> "+
"SELECT deviceAndChannelId FROM platform_gb_channel WHERE platformId='${platformId}' AND deviceAndChannelId in" +
"<foreach collection='deviceAndChannelIds' open='(' item='id_' separator=',' close=')'> '${id_}'</foreach> ORDER BY deviceAndChannelId ASC" +
"SELECT deviceChannelId FROM platform_gb_channel WHERE platformId='${platformId}' AND deviceChannelId in" +
"<foreach collection='channelReduces' open='(' item='item' separator=',' close=')'> '${item.id}'</foreach>" +
"</script>")
List<String> findChannelRelatedPlatform(String platformId, List<String> deviceAndChannelIds);
List<Integer> findChannelRelatedPlatform(String platformId, List<ChannelReduce> channelReduces);
@Insert("<script> "+
"INSERT INTO platform_gb_channel (channelId, deviceId, platformId, deviceAndChannelId, catalogId) VALUES" +
"INSERT INTO platform_gb_channel (platformId, deviceChannelId, catalogId) VALUES" +
"<foreach collection='channelReducesToAdd' item='item' separator=','>" +
" ('${item.channelId}','${item.deviceId}', '${platformId}', '${item.deviceId}_${item.channelId}' , '${item.catalogId}' )" +
" ('${platformId}', '${item.id}' , '${item.catalogId}' )" +
"</foreach>" +
"</script>")
int addChannels(String platformId, List<ChannelReduce> channelReducesToAdd);
@Delete("<script> "+
"DELETE FROM platform_gb_channel WHERE platformId='${platformId}' AND deviceAndChannelId in" +
"<foreach collection='channelReducesToDel' item='item' open='(' separator=',' close=')' > '${item.deviceId}_${item.channelId}'</foreach>" +
"DELETE FROM platform_gb_channel WHERE platformId='${platformId}' AND deviceChannelId in" +
"<foreach collection='channelReducesToDel' item='item' open='(' separator=',' close=')' > '${item.id}'</foreach>" +
"</script>")
int delChannelForGB(String platformId, List<ChannelReduce> channelReducesToDel);
@@ -79,8 +79,10 @@ public interface PlatformChannelMapper {
"parent_platform pp " +
"left join platform_gb_channel pgc on " +
"pp.serverGBId = pgc.platformId " +
"left join device_channel dc on " +
"dc.id = pgc.deviceChannelId " +
"WHERE " +
"pgc.channelId = #{channelId} and pp.status = true " +
"dc.channelId = #{channelId} and pp.status = true " +
"AND pp.serverGBId IN" +
"<foreach collection='platforms' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
"</script> ")

View File

@@ -607,19 +607,19 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
@Override
public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces, String catalogId) {
Map<String, ChannelReduce> deviceAndChannels = new HashMap<>();
Map<Integer, ChannelReduce> deviceAndChannels = new HashMap<>();
for (ChannelReduce channelReduce : channelReduces) {
channelReduce.setCatalogId(catalogId);
deviceAndChannels.put(channelReduce.getDeviceId() + "_" + channelReduce.getChannelId(), channelReduce);
deviceAndChannels.put(channelReduce.getId(), channelReduce);
}
List<String> deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet());
List<Integer> deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet());
// 查询当前已经存在的
List<String> relatedPlatformchannels = platformChannelMapper.findChannelRelatedPlatform(platformId, deviceAndChannelList);
if (relatedPlatformchannels != null) {
deviceAndChannelList.removeAll(relatedPlatformchannels);
List<Integer> channelIds = platformChannelMapper.findChannelRelatedPlatform(platformId, channelReduces);
if (deviceAndChannelList != null) {
deviceAndChannelList.removeAll(channelIds);
}
for (String relatedPlatformchannel : relatedPlatformchannels) {
deviceAndChannels.remove(relatedPlatformchannel);
for (Integer channelId : channelIds) {
deviceAndChannels.remove(channelId);
}
List<ChannelReduce> channelReducesToAdd = new ArrayList<>(deviceAndChannels.values());
// 对剩下的数据进行存储

View File

@@ -18,7 +18,7 @@ public class BaseNode<T> implements INode<T> {
/**
* 主键ID
*/
protected String id;
protected int id;
/**
* 父节点ID

View File

@@ -19,7 +19,7 @@ public class ForestNode extends BaseNode<ForestNode> {
*/
private Object content;
public ForestNode(String id, String parentId, Object content) {
public ForestNode(int id, String parentId, Object content) {
this.id = id;
this.parentId = parentId;
this.content = content;

View File

@@ -17,12 +17,12 @@ public class ForestNodeManager<T extends INode<T>> {
/**
* 森林的所有节点
*/
private final ImmutableMap<String, T> nodeMap;
private final ImmutableMap<Integer, T> nodeMap;
/**
* 森林的父节点ID
*/
private final Map<String, Object> parentIdMap = Maps.newHashMap();
private final Map<Integer, Object> parentIdMap = Maps.newHashMap();
public ForestNodeManager(List<T> nodes) {
nodeMap = Maps.uniqueIndex(nodes, INode::getId);
@@ -46,7 +46,7 @@ public class ForestNodeManager<T extends INode<T>> {
*
* @param parentId 父节点ID
*/
public void addParentId(String parentId) {
public void addParentId(int parentId) {
parentIdMap.put(parentId, "");
}

View File

@@ -14,7 +14,7 @@ public interface INode<T> extends Serializable {
*
* @return String
*/
String getId();
int getId();
/**
* 父主键

View File

@@ -19,7 +19,7 @@ public class DeviceChannelTree extends DeviceChannel implements INode<DeviceChan
/**
* 主键ID
*/
private String id;
private int id;
/**
* 父节点ID

View File

@@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.vmanager.gb28181.media;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IStreamPushService;
import com.genersoft.iot.vmp.service.IMediaService;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
@@ -9,6 +10,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +35,9 @@ public class MediaController {
@Autowired
private IMediaService mediaService;
@Autowired
private IMediaServerService mediaServerService;
/**
* 根据应用名和流id获取播放地址

View File

@@ -1,10 +1,17 @@
package com.genersoft.iot.vmp.vmanager.gb28181.platform.bean;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
/**
* 精简的channel信息展示主要是选择通道的时候展示列表使用
*/
public class ChannelReduce {
/**
* deviceChannel的数据库自增ID
*/
private int id;
/**
* 通道id
*/
@@ -45,6 +52,13 @@ public class ChannelReduce {
*/
private String catalogId;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getChannelId() {
return channelId;