Skip to content

Commit

Permalink
支持分组和级联分组上报
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjoge committed Aug 1, 2024
1 parent f39c2cb commit e7e0d86
Show file tree
Hide file tree
Showing 32 changed files with 1,379 additions and 435 deletions.
13 changes: 13 additions & 0 deletions GB28181/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,18 @@ public static string SafeReplace(this string str)

return str;
}
/// <summary>
/// 获取ID类型
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string GetIdType(this string str)
{
if (str.Length == 20)
{
return str[10..13];
}
return null;
}
}
}
5 changes: 4 additions & 1 deletion GBWeb/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ApiResult<UserInfo> Info()
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<ApiResult<PermMenu>> Permmenu()
public ApiResult<PermMenu> Permmenu()
{
List<Menu> menus = new List<Menu>();
List<string> perms = new List<string>();
Expand All @@ -83,6 +83,9 @@ public async Task<ApiResult<PermMenu>> Permmenu()
perms.Add("Superior:CreateSuperior");
perms.Add("Superior:UpdateSuperior");
perms.Add("Superior:DeleteSuperiors");
perms.Add("Group:CreateGroup");
perms.Add("Group:UpdateGroup");
perms.Add("Group:DeleteGroups");
return RetApiResult(new PermMenu
{
Menus = menus,
Expand Down
131 changes: 131 additions & 0 deletions GBWeb/Controllers/GroupController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using GBWeb.Attribute;
using GBWeb.Models;
using Microsoft.AspNetCore.Mvc;
using SipServer.DBModel;
using SipServer.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace GBWeb.Controllers
{
/// <summary>
/// 分组管理接口
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class GroupController : BaseApi
{
/// <summary>
/// 获取分组信息
/// </summary>
/// <param name="ParentId">上级分组ID,传空或NULL表示查询根节点</param>
/// <returns></returns>
[HttpGet]
public async Task<ApiResult<List<TGroup>>> GetGroupsByParent([FromCustom] string ParentId)
{
return await RetApiResult(Program.sipServer.DB.GetGroupsByParent(ParentId ?? ""));
}
/// <summary>
/// 获取全部分组
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<ApiResult<List<TGroup>>> GetAllGroups()
{
return await RetApiResult(Program.sipServer.DB.GetAllGroups());
}
/// <summary>
/// 添加分组
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<bool>> CreateGroup(TGroup info)
{
return await RetApiResult(Program.sipServer.DB.AddGroup(info));
}
/// <summary>
/// 更新分组
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<bool>> UpdateGroup(TGroup info)
{
return await RetApiResult(Program.sipServer.DB.UpdateGroup(info));
}
/// <summary>
/// 删除分组
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<bool>> DeleteGroups(DeleteModelIds model)
{
if (model == null || model.Ids.Length != 1)
return RetApiResult(false);
return await RetApiResult(Program.sipServer.DB.DeleteGroup(model.Ids[0]));
}


/// <summary>
/// 获取通道信息
/// </summary>
/// <param name="SuperiorId"></param>
/// <param name="DeviceId"></param>
/// <param name="ParentId"></param>
/// <param name="ChannelId"></param>
/// <param name="Name"></param>
/// <param name="Parental"></param>
/// <param name="Manufacturer"></param>
/// <param name="OnlyBind">仅筛选已绑定的</param>
/// <param name="Page"></param>
/// <param name="Limit"></param>
/// <returns></returns>
[HttpGet]
public async Task<ApiResult<DPager<GroupChannel>>> GetChannelList(string GroupID, string DeviceId, string ChannelId, string Name, bool? Parental, string Manufacturer, bool OnlyBind, int Page = 1, int Limit = 10)
{
return await RetApiResult(Program.sipServer.DB.GetGroupChannels(GroupID, DeviceId, ChannelId, Name, Parental, Manufacturer, Page, Limit, !OnlyBind));
}

/// <summary>
///
/// </summary>
public class BindChannelsModel
{
public string GroupID { get; set; }
public List<TGroupBind> Add { get; set; }
public List<TGroupBind> Remove { get; set; }
}
/// <summary>
/// 绑定通道
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<bool>> BindChannels(BindChannelsModel model)
{
return await RetApiResult(Program.sipServer.DB.BindChannels(model.GroupID, model.Add, model.Remove));
}
/// <summary>
///
/// </summary>
public class BindSuperiorModel
{
public string SuperiorId { get; set; }
public string GroupId { get; set; }
public bool HasChild { get; set; }
public bool Cancel { get; set; }
}
/// <summary>
/// 绑定上级平台
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<bool>> BindSuperior(BindSuperiorModel model)
{
return await RetApiResult(Program.sipServer.DB.BindSuperior(model.SuperiorId, model.GroupId, model.HasChild, model.Cancel));
}
}
}
62 changes: 31 additions & 31 deletions GBWeb/Controllers/SuperiorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,43 +78,43 @@ public async Task<ApiResult<bool>> DeleteSuperiors(DeleteModelIds model)
return RetApiResult(await Program.sipServer.Cascade.Remove(model.Ids));
}

/// <summary>
/// 获取通道信息
/// </summary>
/// <param name="SuperiorId"></param>
/// <param name="DeviceId"></param>
/// <param name="ParentId"></param>
/// <param name="ChannelId"></param>
/// <param name="Name"></param>
/// <param name="Parental"></param>
/// <param name="Manufacturer"></param>
/// <param name="OnlyBind">仅筛选已绑定的</param>
/// <param name="Page"></param>
/// <param name="Limit"></param>
/// <returns></returns>
[HttpGet]
public async Task<ApiResult<DPager<SuperiorChannel>>> GetChannelList(string SuperiorId, string DeviceId, string ParentId, string ChannelId, string Name, bool? Parental, string Manufacturer, bool OnlyBind, int Page = 1, int Limit = 10)
{
return await RetApiResult(Program.sipServer.DB.GetSuperiorChannels(SuperiorId, DeviceId, ChannelId, Name, Parental, Manufacturer, Page, Limit, !OnlyBind));
}
///// <summary>
///// 获取通道信息
///// </summary>
///// <param name="SuperiorId"></param>
///// <param name="DeviceId"></param>
///// <param name="ParentId"></param>
///// <param name="ChannelId"></param>
///// <param name="Name"></param>
///// <param name="Parental"></param>
///// <param name="Manufacturer"></param>
///// <param name="OnlyBind">仅筛选已绑定的</param>
///// <param name="Page"></param>
///// <param name="Limit"></param>
///// <returns></returns>
//[HttpGet]
//public async Task<ApiResult<DPager<SuperiorChannel>>> GetChannelList(string SuperiorId, string DeviceId, string ParentId, string ChannelId, string Name, bool? Parental, string Manufacturer, bool OnlyBind, int Page = 1, int Limit = 10)
//{
// return await RetApiResult(Program.sipServer.DB.GetSuperiorChannels(SuperiorId, DeviceId, ChannelId, Name, Parental, Manufacturer, Page, Limit, !OnlyBind));
//}
/// <summary>
///
/// </summary>
public class BindChannelsModel
{
public string SuperiorId { get; set; }
public List<TSuperiorChannel> Add { get; set; }
public List<TSuperiorChannel> Remove { get; set; }
}
/// <summary>
/// 绑定通道
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<bool>> BindChannels(BindChannelsModel model)
{
return await RetApiResult(Program.sipServer.DB.BindChannels(model.SuperiorId, model.Add, model.Remove));
public List<TSuperiorGroup> Add { get; set; }
public List<TSuperiorGroup> Remove { get; set; }
}
///// <summary>
///// 绑定通道
///// </summary>
///// <param name="model"></param>
///// <returns></returns>
//[HttpPost]
//public async Task<ApiResult<bool>> BindChannels(BindChannelsModel model)
//{
// return await RetApiResult(Program.sipServer.DB.BindChannels(model.SuperiorId, model.Add, model.Remove));
//}
}
}
2 changes: 1 addition & 1 deletion SipServer/Cascade/CascadeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ protected internal void AddChannel(SuperiorChannel item)
Password = Empty2Null(item.Password),
Status = item.Status,
};
if (item.IsDevice)
if (item.DType < 1 || item.DType > 3)
{
ci.Parental = item.Parental ? 1 : 0;
ci.SafetyWay = item.SafetyWay;
Expand Down
42 changes: 37 additions & 5 deletions SipServer/Cascade/CascadeManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SipServer.DBModel;
using GB28181;
using SipServer.DBModel;
using SipServer.Models;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -90,7 +91,8 @@ public async Task<bool> Remove(params string[] ids)
}
async Task<bool> AddClient(TSuperiorInfo sinfo)
{
var tmp = await sipServer.DB.GetSuperiorChannels(sinfo.Id);
var groups = await sipServer.DB.GetSuperiorGroups(sinfo.Id);
var tmp = await sipServer.DB.GetSuperiorChannels(sinfo.Id, groups.Select(p => p.GroupId).ToList());
var id = sinfo.ClientId;
var ClientName = string.IsNullOrEmpty(sinfo.ClientName) ? sinfo.Name : sinfo.ClientName;
var root = new SuperiorChannel(new TCatalog
Expand All @@ -105,18 +107,48 @@ async Task<bool> AddClient(TSuperiorInfo sinfo)
Address = "Address",
RegisterWay = 1,
Secrecy = false,
DType = 1,
},
null,
false
sinfo.ServerId, null, null
);
var channels = new List<SuperiorChannel>
{
//添加系统目录项
root
};
foreach (var item in groups)
{
var channel = new SuperiorChannel(new TCatalog
{
ChannelId = item.GroupId,
DeviceId = item.GroupId,
Name = item.Name,
ParentId = string.IsNullOrEmpty(item.ParentId) ? id : item.ParentId,
DType = item.GroupId.GetIdType() == "215" ? 2 : 3,
},
sinfo.ServerId, null, null
);
if (channel.ChannelId.GetIdType() == "216" && channel.ParentId.GetIdType() == "215")
{
//虚拟目录增加BusinessGroupID
channel.BusinessGroupId = channel.ParentId;
}
channels.Add(channel);
}
foreach (var channel in tmp)
{
channel.ParentId = id;
//GB/T28181—2016 附 录 O
// <!--若上传目录中有此设备的父设备则应填写父设备ID,若无父设备则应填写系统ID;若设备属于某虚拟组织下,则应同时填写虚拟组织ID; 各个ID之间用“/”分隔。
if (tmp.FindIndex(p => p.ChannelId == channel.ParentId) < 0)
{
//找不到父设备时,将ParentId设为系统ID
channel.ParentId = id;
}
if (!string.IsNullOrEmpty(channel.GroupId))
{
//有虚拟分组时,增加虚拟分组ID
channel.ParentId += "/" + channel.GroupId;
}
channels.Add(channel);
}
CascadeClient client = new CascadeClient(this, sinfo.Id, SuperiorInfoEx.GetServerSipStr(sinfo), sinfo.ServerId, new GB28181.XML.DeviceInfo
Expand Down
Loading

0 comments on commit e7e0d86

Please sign in to comment.