Ai
7 Star 111 Fork 43

a SSC博士-苏子轩 /AKStreamUI

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
videochannelsService.cs 10.95 KB
一键复制 编辑 原始数据 按行查看 历史
a SSC博士-苏子轩 提交于 2021-07-22 11:35 +08:00 . 完善新增设备功能
using Furion.Extras.Admin.NET;
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Linq.Dynamic.Core;
using Admin.NET.EntityFramework.Core;
using Microsoft.Extensions.Configuration;
using Furion.RemoteRequest.Extensions;
using System;
namespace Admin.NET.Application
{
/// <summary>
/// 设备管理服务
/// </summary>
[ApiDescriptionSettings("流媒体管理", Name = "videochannels", Order = 100)]
public class videochannelsService : IvideochannelsService, IDynamicApiController, ITransient
{
private readonly IRepository<videochannels> _rep;
private readonly IConfiguration _configuration;
public videochannelsService(
IRepository<videochannels> rep,
IConfiguration configuration
)
{
_rep = rep;
_configuration = configuration;
}
/// <summary>
/// 分页查询设备管理
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/videochannels/page")]
public async Task<dynamic> Page([FromQuery] videochannelsInput input)
{
var entities = await _rep.DetachedEntities
.Where(!string.IsNullOrEmpty(input.ChannelId), u => u.ChannelId == input.ChannelId)
.Where(!string.IsNullOrEmpty(input.DeviceId), u => u.DeviceId == input.DeviceId)
.Where(!string.IsNullOrEmpty(input.VideoDeviceType), u => u.VideoDeviceType == input.VideoDeviceType)
.Where(!string.IsNullOrEmpty(input.ChannelName), u => u.ChannelName == input.ChannelName)
.Where(!string.IsNullOrEmpty(input.MainId), u => u.MainId == input.MainId)
.OrderBy(PageInputOrder.OrderBuilder<videochannelsInput>(input))
.ToPagedListAsync(input.PageNo, input.PageSize);
var result = XnPageResult<videochannels>.PageResult<videochannelsDto>(entities);
await DtoMapper(result.Rows);
return result;
}
/// <summary>
/// 增加设备管理
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/videochannels/add")]
public async Task Add(AddvideochannelsInput input)
{
var entity = input.Adapt<videochannels>();
await entity.InsertAsync();
}
/// <summary>
/// 删除设备管理
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/videochannels/delete")]
public async Task Delete(DeletevideochannelsInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await entity.DeleteAsync();
}
/// <summary>
/// 更新设备管理
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/videochannels/edit")]
public async Task Update(UpdatevideochannelsInput input)
{
var entity = input.Adapt<videochannels>();
await entity.UpdateAsync(true);
}
/// <summary>
/// 获取设备管理
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/videochannels/detail")]
public async Task<videochannels> Get([FromQuery] QueryevideochannelsInput input)
{
return await _rep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id);
}
/// <summary>
/// 获取设备管理列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/videochannels/list")]
public async Task<dynamic> List([FromQuery] videochannelsInput input)
{
return await _rep.DetachedEntities.ToListAsync();
}
private async Task DtoMapper(ICollection<videochannelsDto> rows)
{
foreach (var item in rows)
{
}
}
#region AKStreamWeb Api
/// <summary>
/// 获取流媒体服务器列表
/// </summary>
/// <returns></returns>
[HttpGet("/MediaServer/GetMediaServerList")]
public async Task<dynamic> GetMediaServerList()
{
string apiUrl = _configuration["AKStream:ApiUrl"];
var result = await $"{apiUrl}/MediaServer/GetMediaServerList".SetHeaders(new
{
AccessKey = _configuration["AKStream:AccessKey"]
}).OnException((res, errors) => {
//激活异步拦截 此处可以做记录日志操作 也可保持现状
}).GetAsAsync<List<mediaserverDto>>();
var strJson = new
{
PageNo = 1,
PageSize =10,
Rows = result,
TotalPage = Math.Ceiling(decimal.Parse((result.Count / 10).ToString())),
TotalRows = result.Count
};
return strJson;
}
/// <summary>
/// 启动流媒体服务
/// </summary>
/// <param name="mServerId">流媒体服务ID</param>
/// <returns></returns>
[HttpGet("/AKStreamKeeper/StartMediaServer")]
public async Task StartMediaServer(string mServerId)
{
string apiUrl = _configuration["AKStream:ApiUrl"];
var result = await $"{apiUrl}/AKStreamKeeper/StartMediaServer".SetHeaders(new
{
AccessKey = _configuration["AKStream:AccessKey"]
}).SetQueries(new
{
mediaServerId = mServerId
}).OnException((res, errors) => {
//激活异步拦截 此处可以做记录日志操作 也可保持现状
}).GetAsync();
}
/// <summary>
/// 停止流媒体服务
/// </summary>
/// <param name="mServerId">流媒体服务ID</param>
/// <returns></returns>
[HttpGet("/AKStreamKeeper/ShutdownMediaServer")]
public async Task ShutdownMediaServer(string mServerId)
{
string apiUrl = _configuration["AKStream:ApiUrl"];
var result = await $"{apiUrl}/AKStreamKeeper/ShutdownMediaServer".SetHeaders(new
{
AccessKey = _configuration["AKStream:AccessKey"]
}).SetQueries(new
{
mediaServerId = mServerId
}).OnException((res, errors) => {
//激活异步拦截 此处可以做记录日志操作 也可保持现状
}).GetAsync();
}
/// <summary>
/// 获取Sip设备列表
/// </summary>
/// <returns></returns>
[HttpGet("/SipGate/GetSipDeviceList")]
public async Task<dynamic> GetSipDeviceList([FromQuery] devicechannelDto input)
{
string apiUrl = _configuration["AKStream:ApiUrl"];
var result = await $"{apiUrl}/SipGate/GetSipDeviceList".SetHeaders(new
{
AccessKey = _configuration["AKStream:AccessKey"]
}).OnException((res, errors) => {
//激活异步拦截 此处可以做记录日志操作 也可保持现状
}).GetAsAsync<List<devicechannelDto>>();
var strJson = new
{
PageNo = input.PageNo,
PageSize = 10,
Rows = result,
TotalPage = Math.Ceiling(decimal.Parse((result.Count / 10).ToString())),
TotalRows = result.Count
};
return strJson;
}
/// <summary>
/// 获取Sip设备列表
/// </summary>
/// <returns></returns>
[HttpGet("/SipGate/LiveVideo")]
public async Task<dynamic> GetSipDeviceList(string deviceId,string channelId)
{
string apiUrl = _configuration["AKStream:ApiUrl"];
var result = await $"{apiUrl}/SipGate/LiveVideo".SetHeaders(new
{
AccessKey = _configuration["AKStream:AccessKey"]
}).SetQueries(new
{
deviceId = deviceId,
channelId = channelId
}).OnException((res, errors) => {
//激活异步拦截 此处可以做记录日志操作 也可保持现状
}).GetAsAsync<resPlayUrlDto>();
return result;
}
/// <summary>
/// 增加设备管理
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/MediaServer/AddVideoChannel")]
public async Task<dynamic> AddVideoChannel(AddvideochannelsInput input)
{
var entity = input.Adapt<videochannels>();
string apiUrl = _configuration["AKStream:ApiUrl"];
var result = await $"{apiUrl}/MediaServer/AddVideoChannel".SetHeaders(new
{
AccessKey = _configuration["AKStream:AccessKey"]
}).SetBody(new
{
mainId = entity.MainId,
mediaServerId = entity.MediaServerId,
vhost = entity.Vhost,
app = entity.App,
channelName = entity.ChannelName,
departmentId = entity.DepartmentId,
departmentName = entity.DepartmentName,
pDepartmentId = entity.PDepartmentId,
pDepartmentName = entity.PDepartmentName,
deviceNetworkType = entity.DeviceNetworkType,
deviceStreamType = entity.DeviceStreamType,
methodByGetStream = entity.MethodByGetStream,
videoDeviceType = entity.VideoDeviceType,
autoVideo = entity.AutoVideo,
autoRecord = entity.AutoRecord,
recordSecs = entity.RecordSecs,
recordPlanName = entity.RecordPlanName,
ipV4Address = entity.IpV4Address,
ipV6Address = entity.IpV6Address,
hasPtz = entity.HasPtz,
deviceId = entity.DeviceId,
channelId = entity.ChannelId,
rtpWithTcp = entity.RtpWithTcp,
videoSrcUrl = entity.VideoSrcUrl,
defaultRtpPort = entity.DefaultRtpPort,
createTime = entity.CreateTime,
updateTime = entity.UpdateTime,
enabled = entity.Enabled,
noPlayerBreak = entity.NoPlayerBreak
}, "application/json").OnException((res, errors) => {
//激活异步拦截 此处可以做记录日志操作 也可保持现状
}).PostAsync();
return result;
}
#endregion
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/sscboshi/AKStreamUI.git
git@gitee.com:sscboshi/AKStreamUI.git
sscboshi
AKStreamUI
AKStreamUI
master

搜索帮助