using Application.Domain.Entities; using Infrastructure.Data; using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Swashbuckle.AspNetCore.Annotations; using System.Collections.Generic; using System.Linq; namespace IoT.Shared.Controllers.Onvif { [SwaggerTag("Swagger")] public class SwaggerController : Controller { private readonly IRepository _productRepo; private readonly IRepository _deviceRepo; private readonly IRepository _nodeRepo; public SwaggerController(IRepository productRepo, IRepository deviceRepo, IRepository nodeRepo) { this._productRepo = productRepo; this._deviceRepo = deviceRepo; this._nodeRepo = nodeRepo; } [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("设备型号列表")] public List GetDeviceInfos([SwaggerParameter("当前页序号")]int pageIndex = 1, [SwaggerParameter("单页数量")]int pageSize = 10) { return this._productRepo.ReadOnlyTable().Paged(pageIndex, pageSize); } [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("节点列表")] public List GetNodes([SwaggerParameter("当前页序号")]int pageIndex = 1, [SwaggerParameter("单页数量")]int pageSize = 10) { return this._nodeRepo.ReadOnlyTable().Paged(pageIndex, pageSize); } [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("设备列表")] public List GetDevices([SwaggerParameter("当前页序号")]int pageIndex = 1, [SwaggerParameter("单页数量")]int pageSize = 10) { return this._deviceRepo.ReadOnlyTable().Paged(pageIndex, pageSize); } [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("设备")] public Device GetDevice([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) { return this._deviceRepo.ReadOnlyTable() .Include(o => o.Data) .WhereIf(!string.IsNullOrEmpty(gateway), o => o.Gateway == gateway) .Where(o => o.Number == number) .FirstOrDefault(); } } }