Former-commit-id: 08c188f8807c3057252ea80918ad3f05696df1cb
Former-commit-id: e997d09cf3a4293f2776383f55bd020a016f72f5
1.0
wanggang 4 years ago
parent 8403e74bd6
commit 208a89e842

@ -1,22 +1,19 @@
using Application.Domain.Entities; using Application.Domain.Entities;
using Infrastructure.Application.Services.Settings;
using Infrastructure.Data; using Infrastructure.Data;
using Infrastructure.Events; using Infrastructure.Events;
using IoT.Shared.Application.Models; using IoT.Shared.Application.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Platform.EventHandlers;
using Platform.Services; using Platform.Services;
using System; using System;
using System.Linq; using System.Linq;
namespace Platform.Api.Api namespace Platform.Api.Api
{ {
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]/[action]")] [Route("api/v{version:apiVersion}/[controller]/[action]")]
[ApiVersion("1.0")]
[ApiController] [ApiController]
public class ApiController : ControllerBase public class ApiController : ControllerBase
{ {

@ -10,7 +10,10 @@ using System.Security.Claims;
namespace Platform.Api namespace Platform.Api
{ {
public class SiteController : Controller [ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
[ApiController]
public class SiteController : ControllerBase
{ {
private readonly ISettingService _settingService; private readonly ISettingService _settingService;
private readonly IRepository<AppModule> _appModuleRepo; private readonly IRepository<AppModule> _appModuleRepo;

@ -1,87 +1,87 @@
using Infrastructure.Application.Services.Settings; //using Infrastructure.Application.Services.Settings;
using Infrastructure.Data; //using Infrastructure.Data;
using Infrastructure.Extensions; //using Infrastructure.Extensions;
using Application.Domain.Entities; //using Application.Domain.Entities;
using Microsoft.AspNetCore.Mvc; //using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; //using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; //using Microsoft.Extensions.Logging;
using System; //using System;
using System.Collections.Generic; //using System.Collections.Generic;
using System.Linq; //using System.Linq;
using System.Net.Http; //using System.Net.Http;
namespace Platform.Apis.Controllers //namespace Platform.Apis.Controllers
{ //{
[ApiVersion("1.0")] // [ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]/[action]")] // [Route("api/v{version:apiVersion}/[controller]/[action]")]
[ApiController] // [ApiController]
public class SiteController : ControllerBase // public class SiteController : ControllerBase
{ // {
private readonly IConfiguration _cfg; // private readonly IConfiguration _cfg;
private readonly ILogger<OrganController> _logger; // private readonly ILogger<OrganController> _logger;
private readonly IHttpClientFactory _httpClientFactory; // private readonly IHttpClientFactory _httpClientFactory;
private readonly IRepository<IoTTimer> _organSceneTimerRepo; // private readonly IRepository<IoTTimer> _organSceneTimerRepo;
private readonly ISettingService _settingService; // private readonly ISettingService _settingService;
private readonly IRepository<OrganUser> _userRepo; // private readonly IRepository<OrganUser> _userRepo;
public SiteController(IConfiguration cfg, // public SiteController(IConfiguration cfg,
IHttpClientFactory httpClientFactory, // IHttpClientFactory httpClientFactory,
IRepository<IoTTimer> organSceneTimerRepo, // IRepository<IoTTimer> organSceneTimerRepo,
ILogger<OrganController> logger, // ILogger<OrganController> logger,
ISettingService settingService, // ISettingService settingService,
IRepository<OrganUser> userRepo) // IRepository<OrganUser> userRepo)
{ // {
this._cfg = cfg; // this._cfg = cfg;
this._httpClientFactory = httpClientFactory; // this._httpClientFactory = httpClientFactory;
this._organSceneTimerRepo = organSceneTimerRepo; // this._organSceneTimerRepo = organSceneTimerRepo;
this._logger = logger; // this._logger = logger;
this._settingService = settingService; // this._settingService = settingService;
this._userRepo = userRepo; // this._userRepo = userRepo;
} // }
[HttpPost] // [HttpPost]
public IActionResult GetSite(Guid? organId) // public IActionResult GetSite(Guid? organId)
{ // {
try // try
{ // {
var username = User.Identity.IsAuthenticated ? this.HttpContext.User.Identity.Name : null; // var username = User.Identity.IsAuthenticated ? this.HttpContext.User.Identity.Name : null;
var roles = new List<string>(); // var roles = new List<string>();
var permissions = new List<string>(); // var permissions = new List<string>();
if (User.Identity.IsAuthenticated) // if (User.Identity.IsAuthenticated)
{ // {
roles = this._userRepo.ReadOnlyTable() // roles = this._userRepo.ReadOnlyTable()
.Where(o => o.User.UserName == username) // .Where(o => o.User.UserName == username)
.WhereIf(organId.HasValue,o=>o.OrganId==organId.Value) // .WhereIf(organId.HasValue,o=>o.OrganId==organId.Value)
.SelectMany(o => o.UserRoles) // .SelectMany(o => o.UserRoles)
.Select(o => o.OrganRole.Name) // .Select(o => o.OrganRole.Name)
.ToList(); // .ToList();
permissions = this._userRepo.ReadOnlyTable() // permissions = this._userRepo.ReadOnlyTable()
.Where(o => o.User.UserName == username) // .Where(o => o.User.UserName == username)
.WhereIf(organId.HasValue, o => o.OrganId == organId.Value) // .WhereIf(organId.HasValue, o => o.OrganId == organId.Value)
.SelectMany(o => o.UserRoles) // .SelectMany(o => o.UserRoles)
.Select(o => o.OrganRole) // .Select(o => o.OrganRole)
.SelectMany(o => o.RolePermissions) // .SelectMany(o => o.RolePermissions)
.Select(o => o.Permission) // .Select(o => o.Permission)
.Select(o => o.Number) // .Select(o => o.Number)
.ToList(); // .ToList();
} // }
return Ok(new // return Ok(new
{ // {
logo = this._settingService.GetValue("logo"), // logo = this._settingService.GetValue("logo"),
name = this._settingService.GetValue("name"), // name = this._settingService.GetValue("name"),
copyright = this._settingService.GetValue("copyright"), // copyright = this._settingService.GetValue("copyright"),
version = Helper.Instance.GetVersion(), // version = Helper.Instance.GetVersion(),
username, // username,
roles, // roles,
permissions, // permissions,
sso = this._settingService.GetValue("sso") // sso = this._settingService.GetValue("sso")
}); // });
} // }
catch (Exception ex) // catch (Exception ex)
{ // {
this._logger.LogError(ex, ex.Message); // this._logger.LogError(ex, ex.Message);
return Problem(ex.Message); // return Problem(ex.Message);
} // }
} // }
} // }
} //}

@ -1,64 +0,0 @@
using Infrastructure.Data;
using Application.Domain.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace Platform.Apis.Controllers
{
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
[ApiController]
public class SrsController : ControllerBase
{
private readonly IRepository<IoTDevice> _deviceRepo;
private readonly IRepository<LiveRecord> _liveRecordRepo;
public SrsController(IRepository<IoTDevice> deviceRepo,
IRepository<LiveRecord> liveRecordRepo)
{
this._deviceRepo = deviceRepo;
this._liveRecordRepo = liveRecordRepo;
}
/// <summary>
/// 录制完毕事件响应
///{"action":"on_dvr","client_id":107,"ip":"192.168.3.124","vhost":"__defaultVhost__","app":"live","stream":"main0a5d5deee43011b483884cbd8fd2b3dd","param":"","cwd":"/root/publish/apps/srs","file":"./objs/nginx/html/live.main0a5d5deee43011b483884cbd8fd2b3dd.1574832559180.mp4"}
/// </summary>
/// <returns></returns>
[AllowAnonymous]
[HttpPost]
public string OnDvr()
{
using (var reader = new StreamReader(Request.Body))
{
var json = reader.ReadToEndAsync().Result;
Debug.WriteLine("ondvr:");
Debug.WriteLine(json);
var result = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
if (result["action"] == "on_dvr")
{
var streamId = result["stream"];
var device = this._deviceRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == streamId);
if (device != null)
{
this._liveRecordRepo.Add(new LiveRecord
{
DeviceNumber = device.Number,
DeviceName = device?.DisplayName,
Name = $"回放{DateTime.Now:yyyy-MM-dd HH:mm}",
Value = $"/video{result["file"].Substring(result["file"].LastIndexOf('/'))}"
});
this._liveRecordRepo.SaveChanges();
}
}
}
return string.Empty;
}
}
}

@ -1,32 +1,32 @@
using Application.Domain.Entities; //using Application.Domain.Entities;
using Infrastructure.Events; //using Infrastructure.Events;
using Microsoft.AspNetCore.SignalR; //using Microsoft.AspNetCore.SignalR;
using Platform.Services; //using Platform.Services;
namespace Platform.EventHandlers //namespace Platform.EventHandlers
{ //{
public class StatisticEventHandler : BaseEventHandler, // public class StatisticEventHandler : BaseEventHandler,
IEventHander<EntityInserted<Statistic>>, // IEventHander<EntityInserted<Statistic>>,
IEventHander<EntityUpdated<Statistic>>, // IEventHander<EntityUpdated<Statistic>>,
IEventHander<EntityDeleted<Statistic>> // IEventHander<EntityDeleted<Statistic>>
{ // {
public StatisticEventHandler(IHubContext<IoTCenterHub> hub) : base(hub) // public StatisticEventHandler(IHubContext<IoTCenterHub> hub) : base(hub)
{ // {
} // }
public void Handle(EntityInserted<Statistic> message) // public void Handle(EntityInserted<Statistic> message)
{ // {
this.Notify<Statistic>(message); // this.Notify<Statistic>(message);
} // }
public void Handle(EntityUpdated<Statistic> message) // public void Handle(EntityUpdated<Statistic> message)
{ // {
this.Notify<Statistic>(message); // this.Notify<Statistic>(message);
} // }
public void Handle(EntityDeleted<Statistic> message) // public void Handle(EntityDeleted<Statistic> message)
{ // {
this.Notify<Statistic>(message); // this.Notify<Statistic>(message);
} // }
} // }
} //}

@ -1,6 +1,9 @@
#docker-compose up -d #docker-compose up -d
version: "3.8" version: "3.8"
services: services:
srs:
volumes:
- ./docker/conf/srs/dev:/usr/local/srs/conf
website: website:
volumes: volumes:
- ../../../../projects/Platform/wwwroot:/root/nginx/html/desktop - ../../../../projects/Platform/wwwroot:/root/nginx/html/desktop

@ -105,18 +105,15 @@ services:
ipv4_address: 172.172.0.40 ipv4_address: 172.172.0.40
#streaming server #streaming server
srs: srs:
image: ubuntu image: ossrs/srs:v4.0.76
environment:
TZ: "Asia/Shanghai"
restart: always restart: always
ports: ports:
- 1935:1935 - 1935:1935
- 8080:8080 - 8080:8080
- 1985:1985 - 1985:1985
working_dir: /usr/local/srs
command: bash -c "chmod +x ./objs/srs && ./objs/srs -c ./conf/srs.conf"
volumes: volumes:
- ./apps/srs:/usr/local/srs - ./docker/conf/srs/conf:/usr/local/srs/conf
- ./docker/data/srs:/usr/local/srs/objs/nginx/html/video
networks: networks:
default: default:
ipv4_address: 172.172.0.60 ipv4_address: 172.172.0.60

Loading…
Cancel
Save