initial
This commit is contained in:
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
src/DRS9.Dashboard.Application/bin/
|
||||
src/DRS9.Dashboard.Application/obj/
|
||||
src/DRS9.Dashboard.Domain/bin/
|
||||
src/DRS9.Dashboard.Domain/obj/
|
||||
src/DRS9.Dashboard.Infrastructure/bin/
|
||||
src/DRS9.Dashboard.Infrastructure/obj/
|
||||
src/DRS9.Dashboard.Server/bin/
|
||||
src/DRS9.Dashboard.Server/obj/
|
||||
175
README.md
Normal file
175
README.md
Normal file
@@ -0,0 +1,175 @@
|
||||
# DRS9 信息发布系统
|
||||
|
||||
## 系统概述
|
||||
|
||||
一套企业级看板信息发布管理系统,支持企业内部数据大屏展示和公共场所信息发布。系统采用 C/S + B/S 混合架构,通过服务器端统一管理内容分发和设备控制。
|
||||
|
||||
### 应用场景
|
||||
- **企业内部**:数据大屏、会议显示、KPI 展示、公告发布
|
||||
- **公共场所**:学校信息发布、商场广告、车站信息发布、医院导诊显示
|
||||
|
||||
---
|
||||
|
||||
## 系统架构
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ 服务器端 (ASP.NET Core) │
|
||||
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
||||
│ │ 内容管理 │ │ 设备管理 │ │ 用户管理 │ │ 推送服务 │ │
|
||||
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
|
||||
│ │ │
|
||||
│ ┌──────────────────────────────────────────────────────────┐ │
|
||||
│ │ WebSocket 实时通信 │ │
|
||||
│ └──────────────────────────────────────────────────────────┘ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
│
|
||||
┌───────────────┴───────────────┐
|
||||
▼ ▼
|
||||
┌─────────────────────┐ ┌─────────────────────┐
|
||||
│ 移动客户端 App │ │ 浏览器客户端 │
|
||||
│ (Android/iOS/Win) │ │ (Web) │
|
||||
│ - 内容展示 │ │ - 内容展示 │
|
||||
│ - WebSocket 长连接 │ │ - 短连接/轮询 │
|
||||
│ - 自动升级 │ │ - 临时访问授权 │
|
||||
└─────────────────────┘ └─────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 技术选型
|
||||
|
||||
### 服务器端
|
||||
- **框架**:ASP.NET Core 8.0+
|
||||
- **通信**:WebSocket (实时)、REST API (配置管理)
|
||||
- **数据库**:SQLite (单机) / PostgreSQL/MySQL (集群)
|
||||
- **缓存**:内存缓存 / Redis (分布式)
|
||||
|
||||
### 客户端
|
||||
- **移动端**:.NET MAUI / Flutter (跨平台)
|
||||
- **Web端**:Vue 3 / React
|
||||
|
||||
---
|
||||
|
||||
## 功能模块
|
||||
|
||||
### 服务器端
|
||||
|
||||
#### 1. 内容管理模块
|
||||
- **应用类型**:数据看板、网页轮转器、图片轮播、视频播放
|
||||
- **内容编排**:支持多内容组合、定时切换、优先级控制
|
||||
- **URL 管理**:每个应用对应一个服务器端 URL 地址
|
||||
|
||||
#### 2. 设备管理模块
|
||||
- **设备注册**:设备码激活绑定
|
||||
- **设备分组**:按区域/部门批量管理
|
||||
- **远程控制**:推送内容、重启应用、禁用设备、升级 App
|
||||
- **状态监控**:在线状态、内容加载情况、设备信息
|
||||
|
||||
#### 3. 授权认证模块
|
||||
- **认证方式**:设备码(首次注册) + Token(日常通信)
|
||||
- **设备码格式**:`XXX-XXX-XXX`(如 `ABC-123-XYZ`)
|
||||
- **Token 类型**:JWT,包含设备 ID、权限、过期时间
|
||||
|
||||
#### 4. 推送服务模块
|
||||
- **实时推送**:通过 WebSocket 推送内容更新、指令
|
||||
- **指令类型**:刷新内容、切换应用、重启、截图上报
|
||||
- **离线消息**:设备离线时消息持久化,上线后推送
|
||||
|
||||
### 客户端
|
||||
|
||||
#### 1. 移动客户端 App
|
||||
- **配置简化**:仅需设置服务器地址
|
||||
- **自动获取**:内容 URL 由服务器动态分配
|
||||
- **长连接**:WebSocket 保持与服务器连接
|
||||
- **自动升级**:支持服务器推送的版本更新
|
||||
|
||||
#### 2. 浏览器客户端
|
||||
- **访问方式**:通过授权链接或设备码访问
|
||||
- **实时同步**:WebSocket 或短轮询获取更新
|
||||
- **临时授权**:支持限时访问 Token
|
||||
|
||||
---
|
||||
|
||||
## 设备授权流程
|
||||
|
||||
```
|
||||
┌─────────┐ 设备码 ┌─────────┐ 验证+Token ┌─────────┐
|
||||
│ 客户端 │ ───────────────→ │ 服务器端 │ ───────────────→ │ 客户端 │
|
||||
└─────────┘ └─────────┘ └─────────┘
|
||||
│ │ │
|
||||
│ 激活请求(设备码) │ │
|
||||
│ ABC-123-XYZ │ │
|
||||
│ │ │
|
||||
│ ┌─────────────────┐ │
|
||||
│ │ 验证设备码 │ │
|
||||
│ │ 绑定设备身份 │ │
|
||||
│ │ 生成 JWT Token │ │
|
||||
│ └─────────────────┘ │
|
||||
│ │ │
|
||||
│ 返回 Token │ │
|
||||
│ ←───────────────────────── │
|
||||
│ │ │
|
||||
│ 后续请求携带 Token │
|
||||
│ ────────────────────────────────────────────────────────→│
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 数据库设计(草案)
|
||||
|
||||
### 表结构
|
||||
- `devices` - 设备信息表
|
||||
- `device_groups` - 设备分组表
|
||||
- `applications` - 应用内容表
|
||||
- `device_assignments` - 设备与应用分配表
|
||||
- `users` - 用户管理表
|
||||
- `audit_logs` - 操作审计日志
|
||||
|
||||
---
|
||||
|
||||
## 部署要求
|
||||
|
||||
### 服务器端
|
||||
- **操作系统**:Linux (推荐) / Windows Server
|
||||
- **运行时**:.NET 8.0 Runtime
|
||||
- **端口**:HTTP (8080)、HTTPS (8443)、WebSocket (同端口)
|
||||
- **内存**:最低 2GB,推荐 4GB+
|
||||
|
||||
### 客户端
|
||||
- **移动端**:Android 8.0+ / iOS 12+
|
||||
- **Windows**:Windows 10+
|
||||
|
||||
---
|
||||
|
||||
## 开发计划
|
||||
|
||||
### Phase 1 - 基础框架
|
||||
- [ ] 服务器端项目搭建
|
||||
- [ ] 数据库设计与迁移
|
||||
- [ ] 设备注册与认证
|
||||
- [ ] WebSocket 通信基础
|
||||
|
||||
### Phase 2 - 核心功能
|
||||
- [ ] 内容管理模块
|
||||
- [ ] 设备管理模块
|
||||
- [ ] 推送服务模块
|
||||
- [ ] 移动端 App 基础框架
|
||||
|
||||
### Phase 3 - 高级功能
|
||||
- [ ] 内容编排与定时切换
|
||||
- [ ] 设备分组批量管理
|
||||
- [ ] 自动升级功能
|
||||
- [ ] 浏览器客户端
|
||||
|
||||
### Phase 4 - 优化完善
|
||||
- [ ] 性能优化
|
||||
- [ ] 监控告警
|
||||
- [ ] 部署文档
|
||||
- [ ] 用户手册
|
||||
|
||||
---
|
||||
|
||||
## 许可证
|
||||
|
||||
待定
|
||||
6
src/DRS9.Dashboard.Application/Class1.cs
Normal file
6
src/DRS9.Dashboard.Application/Class1.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace DRS9.Dashboard.Application;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DRS9.Dashboard.Domain\DRS9.Dashboard.Domain.csproj" />
|
||||
<ProjectReference Include="..\DRS9.Dashboard.Infrastructure\DRS9.Dashboard.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.*" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.*" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
64
src/DRS9.Dashboard.Application/DTOs/AppVersionDto.cs
Normal file
64
src/DRS9.Dashboard.Application/DTOs/AppVersionDto.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Application.DTOs;
|
||||
|
||||
public record AppVersionCreateRequest
|
||||
{
|
||||
[Required]
|
||||
[MaxLength(50)]
|
||||
public string Platform { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(20)]
|
||||
public string Version { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(100)]
|
||||
public string VersionName { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? DownloadUrl { get; set; }
|
||||
|
||||
public long? FileSize { get; set; }
|
||||
|
||||
[MaxLength(1000)]
|
||||
public string? ChangeLog { get; set; }
|
||||
|
||||
public bool IsForceUpdate { get; set; } = false;
|
||||
}
|
||||
|
||||
public record AppVersionDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Platform { get; set; } = string.Empty;
|
||||
public string Version { get; set; } = string.Empty;
|
||||
public string VersionName { get; set; } = string.Empty;
|
||||
public string? DownloadUrl { get; set; }
|
||||
public long? FileSize { get; set; }
|
||||
public string? ChangeLog { get; set; }
|
||||
public bool IsForceUpdate { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public DateTime? PublishedAt { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
}
|
||||
|
||||
public record CheckVersionRequest
|
||||
{
|
||||
[Required]
|
||||
[MaxLength(50)]
|
||||
public string Platform { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(20)]
|
||||
public string CurrentVersion { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public record CheckVersionResponse
|
||||
{
|
||||
public bool HasUpdate { get; set; }
|
||||
public bool IsForceUpdate { get; set; }
|
||||
public AppVersionDto? LatestVersion { get; set; }
|
||||
public string? DownloadUrl { get; set; }
|
||||
public long? FileSize { get; set; }
|
||||
public string? ChangeLog { get; set; }
|
||||
}
|
||||
76
src/DRS9.Dashboard.Application/DTOs/ApplicationDto.cs
Normal file
76
src/DRS9.Dashboard.Application/DTOs/ApplicationDto.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Application.DTOs;
|
||||
|
||||
public record ApplicationCreateRequest
|
||||
{
|
||||
[Required]
|
||||
[MaxLength(200)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(50)]
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(1000)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(2000)]
|
||||
public string ContentUrl { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? ThumbnailUrl { get; set; }
|
||||
|
||||
public int Priority { get; set; } = 0;
|
||||
}
|
||||
|
||||
public record ApplicationUpdateRequest
|
||||
{
|
||||
[MaxLength(200)]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[MaxLength(50)]
|
||||
public string? Type { get; set; }
|
||||
|
||||
[MaxLength(1000)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[MaxLength(2000)]
|
||||
public string? ContentUrl { get; set; }
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? ThumbnailUrl { get; set; }
|
||||
|
||||
public int? Priority { get; set; }
|
||||
|
||||
public bool? IsEnabled { get; set; }
|
||||
}
|
||||
|
||||
public record ApplicationDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
public string ContentUrl { get; set; } = string.Empty;
|
||||
public string? ThumbnailUrl { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
public record ApplicationListResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public List<ApplicationDto> Data { get; set; } = new();
|
||||
public int Total { get; set; }
|
||||
}
|
||||
|
||||
public record ApplicationResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public ApplicationDto? Data { get; set; }
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
63
src/DRS9.Dashboard.Application/DTOs/BatchManagementDto.cs
Normal file
63
src/DRS9.Dashboard.Application/DTOs/BatchManagementDto.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Application.DTOs;
|
||||
|
||||
// 批量管理 DTO
|
||||
public record BatchAssignContentRequest
|
||||
{
|
||||
[Required]
|
||||
public List<int> DeviceIds { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
public List<int> ApplicationIds { get; set; } = new();
|
||||
}
|
||||
|
||||
public record BatchAssignPlaylistRequest
|
||||
{
|
||||
[Required]
|
||||
public List<int> DeviceGroupIds { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
public int PlaylistId { get; set; }
|
||||
}
|
||||
|
||||
public record BatchPushRequest
|
||||
{
|
||||
[Required]
|
||||
public List<int> DeviceIds { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
public string MessageType { get; set; } = string.Empty;
|
||||
|
||||
public object? Data { get; set; }
|
||||
}
|
||||
|
||||
public record BatchPushToGroupRequest
|
||||
{
|
||||
[Required]
|
||||
public List<int> DeviceGroupIds { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
public string MessageType { get; set; } = string.Empty;
|
||||
|
||||
public object? Data { get; set; }
|
||||
}
|
||||
|
||||
public record BatchOperationResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public int SuccessCount { get; set; }
|
||||
public int FailedCount { get; set; }
|
||||
public List<string> Errors { get; set; } = new();
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
// 批量启用/禁用
|
||||
public record BatchToggleDevicesRequest
|
||||
{
|
||||
[Required]
|
||||
public List<int> DeviceIds { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
public bool IsEnabled { get; set; }
|
||||
}
|
||||
43
src/DRS9.Dashboard.Application/DTOs/DeviceAuthDto.cs
Normal file
43
src/DRS9.Dashboard.Application/DTOs/DeviceAuthDto.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Application.DTOs;
|
||||
|
||||
public record DeviceRegisterRequest
|
||||
{
|
||||
[Required]
|
||||
public string DeviceCode { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(200)]
|
||||
public string DeviceName { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(50)]
|
||||
public string? DeviceType { get; set; }
|
||||
|
||||
[MaxLength(50)]
|
||||
public string? OsVersion { get; set; }
|
||||
|
||||
[MaxLength(100)]
|
||||
public string? AppVersion { get; set; }
|
||||
}
|
||||
|
||||
public record DeviceRegisterResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string? Token { get; set; }
|
||||
public string? Message { get; set; }
|
||||
public int DeviceId { get; set; }
|
||||
}
|
||||
|
||||
public record DeviceRefreshTokenRequest
|
||||
{
|
||||
[Required]
|
||||
public string Token { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public record DeviceRefreshTokenResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string? Token { get; set; }
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
136
src/DRS9.Dashboard.Application/DTOs/DeviceManagementDto.cs
Normal file
136
src/DRS9.Dashboard.Application/DTOs/DeviceManagementDto.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Application.DTOs;
|
||||
|
||||
// 设备管理 DTO
|
||||
public record DeviceCreateRequest
|
||||
{
|
||||
[Required]
|
||||
[MaxLength(50)]
|
||||
public string DeviceCode { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(200)]
|
||||
public string DeviceName { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
public int? DeviceGroupId { get; set; }
|
||||
}
|
||||
|
||||
public record DeviceUpdateRequest
|
||||
{
|
||||
[MaxLength(200)]
|
||||
public string? DeviceName { get; set; }
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
public int? DeviceGroupId { get; set; }
|
||||
|
||||
public bool? IsEnabled { get; set; }
|
||||
}
|
||||
|
||||
public record DeviceDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string DeviceCode { get; set; } = string.Empty;
|
||||
public string DeviceName { get; set; } = string.Empty;
|
||||
public string? DeviceType { get; set; }
|
||||
public string? OsVersion { get; set; }
|
||||
public string? AppVersion { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public DateTime? LastSeenAt { get; set; }
|
||||
public DateTime? ActivatedAt { get; set; }
|
||||
public int? DeviceGroupId { get; set; }
|
||||
public string? DeviceGroupName { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
public record DeviceListResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public List<DeviceDto> Data { get; set; } = new();
|
||||
public int Total { get; set; }
|
||||
}
|
||||
|
||||
// 设备分组 DTO
|
||||
public record DeviceGroupCreateRequest
|
||||
{
|
||||
[Required]
|
||||
[MaxLength(100)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public record DeviceGroupUpdateRequest
|
||||
{
|
||||
[MaxLength(100)]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public record DeviceGroupDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
public int DeviceCount { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
public record DeviceGroupListResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public List<DeviceGroupDto> Data { get; set; } = new();
|
||||
public int Total { get; set; }
|
||||
}
|
||||
|
||||
// 设备内容分配 DTO
|
||||
public record DeviceAssignmentRequest
|
||||
{
|
||||
[Required]
|
||||
public int DeviceId { get; set; }
|
||||
|
||||
[Required]
|
||||
public List<int> ApplicationIds { get; set; } = new();
|
||||
}
|
||||
|
||||
public record DeviceAssignmentDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int DeviceId { get; set; }
|
||||
public int ApplicationId { get; set; }
|
||||
public string ApplicationName { get; set; } = string.Empty;
|
||||
public string ApplicationType { get; set; } = string.Empty;
|
||||
public string ContentUrl { get; set; } = string.Empty;
|
||||
public int Order { get; set; }
|
||||
public int Duration { get; set; }
|
||||
}
|
||||
|
||||
public record DeviceContentResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public List<DeviceAssignmentDto> Data { get; set; } = new();
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
|
||||
// 推送消息 DTO
|
||||
public record PushMessageRequest
|
||||
{
|
||||
[Required]
|
||||
public int DeviceId { get; set; }
|
||||
|
||||
[Required]
|
||||
public string MessageType { get; set; } = string.Empty; // refresh, restart, etc.
|
||||
|
||||
public object? Data { get; set; }
|
||||
}
|
||||
31
src/DRS9.Dashboard.Application/DTOs/GuestAccessDto.cs
Normal file
31
src/DRS9.Dashboard.Application/DTOs/GuestAccessDto.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Application.DTOs;
|
||||
|
||||
public record GuestAccessCreateRequest
|
||||
{
|
||||
[MaxLength(200)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ValidityMinutes { get; set; } = 60; // 默认 60 分钟
|
||||
|
||||
public int? DeviceId { get; set; } // 如果指定,模拟该设备获取内容
|
||||
}
|
||||
|
||||
public record GuestAccessResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string? Token { get; set; }
|
||||
public string? AccessUrl { get; set; }
|
||||
public DateTime? ExpiresAt { get; set; }
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
|
||||
// 统计 DTO
|
||||
public class DashboardStatsDto
|
||||
{
|
||||
public int TotalDevices { get; set; }
|
||||
public int OnlineDevices { get; set; }
|
||||
public int TotalApplications { get; set; }
|
||||
}
|
||||
114
src/DRS9.Dashboard.Application/DTOs/PlaylistDto.cs
Normal file
114
src/DRS9.Dashboard.Application/DTOs/PlaylistDto.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Application.DTOs;
|
||||
|
||||
// 播放计划 DTO
|
||||
public record PlaylistCreateRequest
|
||||
{
|
||||
[Required]
|
||||
[MaxLength(200)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(1000)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[MaxLength(20)]
|
||||
public string LoopMode { get; set; } = "Loop"; // Loop, Once, Shuffle
|
||||
|
||||
public int? DeviceGroupId { get; set; }
|
||||
|
||||
public List<PlaylistItemRequest> Items { get; set; } = new();
|
||||
}
|
||||
|
||||
public record PlaylistUpdateRequest
|
||||
{
|
||||
[MaxLength(200)]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[MaxLength(1000)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[MaxLength(20)]
|
||||
public string? LoopMode { get; set; }
|
||||
|
||||
public int? DeviceGroupId { get; set; }
|
||||
|
||||
public bool? IsEnabled { get; set; }
|
||||
}
|
||||
|
||||
public record PlaylistItemRequest
|
||||
{
|
||||
public int ApplicationId { get; set; }
|
||||
public int Order { get; set; }
|
||||
public int Duration { get; set; } = 60;
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
public string? ScheduleRule { get; set; }
|
||||
}
|
||||
|
||||
public record PlaylistDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
public string LoopMode { get; set; } = string.Empty;
|
||||
public int? DeviceGroupId { get; set; }
|
||||
public string? DeviceGroupName { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public int ItemCount { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
public record PlaylistDetailDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
public string LoopMode { get; set; } = string.Empty;
|
||||
public int? DeviceGroupId { get; set; }
|
||||
public string? DeviceGroupName { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public List<PlaylistItemDto> Items { get; set; } = new();
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
public record PlaylistItemDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int PlaylistId { get; set; }
|
||||
public int ApplicationId { get; set; }
|
||||
public string ApplicationName { get; set; } = string.Empty;
|
||||
public string ApplicationType { get; set; } = string.Empty;
|
||||
public string ContentUrl { get; set; } = string.Empty;
|
||||
public int Order { get; set; }
|
||||
public int Duration { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public string? ScheduleRule { get; set; }
|
||||
}
|
||||
|
||||
public record PlaylistListResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public List<PlaylistDto> Data { get; set; } = new();
|
||||
public int Total { get; set; }
|
||||
}
|
||||
|
||||
// 设备获取播放内容响应
|
||||
public record DevicePlaylistResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public List<PlaylistContentDto> Data { get; set; } = new();
|
||||
public string? LoopMode { get; set; }
|
||||
public int? TotalDuration { get; set; }
|
||||
}
|
||||
|
||||
public record PlaylistContentDto
|
||||
{
|
||||
public int Order { get; set; }
|
||||
public string ApplicationName { get; set; } = string.Empty;
|
||||
public string ApplicationType { get; set; } = string.Empty;
|
||||
public string ContentUrl { get; set; } = string.Empty;
|
||||
public int Duration { get; set; }
|
||||
public string? ThumbnailUrl { get; set; }
|
||||
}
|
||||
198
src/DRS9.Dashboard.Application/Services/AppVersionService.cs
Normal file
198
src/DRS9.Dashboard.Application/Services/AppVersionService.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Domain.Entities;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DRS9.Dashboard.Application.Services;
|
||||
|
||||
public class AppVersionService
|
||||
{
|
||||
private readonly DashboardDbContext _context;
|
||||
private readonly DashboardWebSocketManager _wsManager;
|
||||
|
||||
public AppVersionService(DashboardDbContext context, DashboardWebSocketManager wsManager)
|
||||
{
|
||||
_context = context;
|
||||
_wsManager = wsManager;
|
||||
}
|
||||
|
||||
public async Task<List<AppVersionDto>> GetAllAsync()
|
||||
{
|
||||
return await _context.AppVersions
|
||||
.OrderByDescending(v => v.PublishedAt)
|
||||
.ThenByDescending(v => v.Id)
|
||||
.Select(v => new AppVersionDto
|
||||
{
|
||||
Id = v.Id,
|
||||
Platform = v.Platform,
|
||||
Version = v.Version,
|
||||
VersionName = v.VersionName,
|
||||
DownloadUrl = v.DownloadUrl,
|
||||
FileSize = v.FileSize,
|
||||
ChangeLog = v.ChangeLog,
|
||||
IsForceUpdate = v.IsForceUpdate,
|
||||
IsEnabled = v.IsEnabled,
|
||||
PublishedAt = v.PublishedAt,
|
||||
CreatedAt = v.CreatedAt
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<AppVersionDto?> GetByIdAsync(int id)
|
||||
{
|
||||
return await _context.AppVersions
|
||||
.Where(v => v.Id == id)
|
||||
.Select(v => new AppVersionDto
|
||||
{
|
||||
Id = v.Id,
|
||||
Platform = v.Platform,
|
||||
Version = v.Version,
|
||||
VersionName = v.VersionName,
|
||||
DownloadUrl = v.DownloadUrl,
|
||||
FileSize = v.FileSize,
|
||||
ChangeLog = v.ChangeLog,
|
||||
IsForceUpdate = v.IsForceUpdate,
|
||||
IsEnabled = v.IsEnabled,
|
||||
PublishedAt = v.PublishedAt,
|
||||
CreatedAt = v.CreatedAt
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<AppVersionDto?> CreateAsync(AppVersionCreateRequest request)
|
||||
{
|
||||
var version = new AppVersion
|
||||
{
|
||||
Platform = request.Platform,
|
||||
Version = request.Version,
|
||||
VersionName = request.VersionName,
|
||||
DownloadUrl = request.DownloadUrl,
|
||||
FileSize = request.FileSize,
|
||||
ChangeLog = request.ChangeLog,
|
||||
IsForceUpdate = request.IsForceUpdate,
|
||||
IsEnabled = true,
|
||||
PublishedAt = DateTime.UtcNow
|
||||
};
|
||||
|
||||
_context.AppVersions.Add(version);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return await GetByIdAsync(version.Id);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id)
|
||||
{
|
||||
var version = await _context.AppVersions.FindAsync(id);
|
||||
if (version == null) return false;
|
||||
|
||||
_context.AppVersions.Remove(version);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查版本更新
|
||||
/// </summary>
|
||||
public async Task<CheckVersionResponse> CheckVersionAsync(string platform, string currentVersion)
|
||||
{
|
||||
// 获取该平台最新且启用的版本
|
||||
var latestVersion = await _context.AppVersions
|
||||
.Where(v => v.Platform == platform && v.IsEnabled)
|
||||
.OrderByDescending(v => v.PublishedAt)
|
||||
.ThenByDescending(v => v.Id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (latestVersion == null)
|
||||
{
|
||||
return new CheckVersionResponse
|
||||
{
|
||||
HasUpdate = false,
|
||||
IsForceUpdate = false
|
||||
};
|
||||
}
|
||||
|
||||
// 比较版本号
|
||||
var hasUpdate = CompareVersions(latestVersion.Version, currentVersion) > 0;
|
||||
|
||||
return new CheckVersionResponse
|
||||
{
|
||||
HasUpdate = hasUpdate,
|
||||
IsForceUpdate = hasUpdate && latestVersion.IsForceUpdate,
|
||||
LatestVersion = new AppVersionDto
|
||||
{
|
||||
Id = latestVersion.Id,
|
||||
Platform = latestVersion.Platform,
|
||||
Version = latestVersion.Version,
|
||||
VersionName = latestVersion.VersionName,
|
||||
DownloadUrl = latestVersion.DownloadUrl,
|
||||
FileSize = latestVersion.FileSize,
|
||||
ChangeLog = latestVersion.ChangeLog,
|
||||
IsForceUpdate = latestVersion.IsForceUpdate,
|
||||
IsEnabled = latestVersion.IsEnabled,
|
||||
PublishedAt = latestVersion.PublishedAt,
|
||||
CreatedAt = latestVersion.CreatedAt
|
||||
},
|
||||
DownloadUrl = latestVersion.DownloadUrl,
|
||||
FileSize = latestVersion.FileSize,
|
||||
ChangeLog = latestVersion.ChangeLog
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 推送升级通知到设备
|
||||
/// </summary>
|
||||
public async Task<bool> PushUpdateNotificationAsync(int versionId, string? platform = null)
|
||||
{
|
||||
var version = await _context.AppVersions.FindAsync(versionId);
|
||||
if (version == null) return false;
|
||||
|
||||
// 获取需要通知的设备
|
||||
var devices = await _context.Devices
|
||||
.Where(d => d.IsActive && d.IsEnabled)
|
||||
.Where(d => platform == null || d.DeviceType == platform)
|
||||
.Select(d => d.Id)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var deviceId in devices)
|
||||
{
|
||||
await _wsManager.BroadcastToDeviceAsync(deviceId, new WebSocketMessage
|
||||
{
|
||||
Type = "update_available",
|
||||
Data = new
|
||||
{
|
||||
version = version.Version,
|
||||
versionName = version.VersionName,
|
||||
platform = version.Platform,
|
||||
downloadUrl = version.DownloadUrl,
|
||||
file = version.FileSize,
|
||||
isForceUpdate = version.IsForceUpdate,
|
||||
changeLog = version.ChangeLog
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 简单的版本号比较
|
||||
/// 返回: 1 (v1 > v2), -1 (v1 < v2), 0 (v1 == v2)
|
||||
/// </summary>
|
||||
private int CompareVersions(string v1, string v2)
|
||||
{
|
||||
var parts1 = v1.Split('.').Select(int.Parse).ToArray();
|
||||
var parts2 = v2.Split('.').Select(int.Parse).ToArray();
|
||||
|
||||
for (int i = 0; i < Math.Max(parts1.Length, parts2.Length); i++)
|
||||
{
|
||||
var p1 = i < parts1.Length ? parts1[i] : 0;
|
||||
var p2 = i < parts2.Length ? parts2[i] : 0;
|
||||
|
||||
if (p1 > p2) return 1;
|
||||
if (p1 < p2) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
131
src/DRS9.Dashboard.Application/Services/ApplicationService.cs
Normal file
131
src/DRS9.Dashboard.Application/Services/ApplicationService.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AppEntity = DRS9.Dashboard.Domain.Entities.Application;
|
||||
|
||||
namespace DRS9.Dashboard.Application.Services;
|
||||
|
||||
public class ApplicationService
|
||||
{
|
||||
private readonly DashboardDbContext _context;
|
||||
|
||||
public ApplicationService(DashboardDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<ApplicationListResponse> GetAllAsync()
|
||||
{
|
||||
var applications = await _context.Applications
|
||||
.OrderBy(a => a.Priority)
|
||||
.ThenBy(a => a.Id)
|
||||
.ToListAsync();
|
||||
|
||||
return new ApplicationListResponse
|
||||
{
|
||||
Success = true,
|
||||
Data = applications.Select(a => MapToDto(a)).ToList(),
|
||||
Total = applications.Count
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ApplicationResponse?> GetByIdAsync(int id)
|
||||
{
|
||||
var application = await _context.Applications.FindAsync(id);
|
||||
if (application == null)
|
||||
{
|
||||
return new ApplicationResponse { Success = false, Message = "应用不存在" };
|
||||
}
|
||||
|
||||
return new ApplicationResponse
|
||||
{
|
||||
Success = true,
|
||||
Data = MapToDto(application)
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ApplicationResponse> CreateAsync(ApplicationCreateRequest request)
|
||||
{
|
||||
var application = new AppEntity
|
||||
{
|
||||
Name = request.Name,
|
||||
Type = request.Type,
|
||||
Description = request.Description,
|
||||
ContentUrl = request.ContentUrl,
|
||||
ThumbnailUrl = request.ThumbnailUrl,
|
||||
Priority = request.Priority,
|
||||
IsEnabled = true
|
||||
};
|
||||
|
||||
_context.Applications.Add(application);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return new ApplicationResponse
|
||||
{
|
||||
Success = true,
|
||||
Data = MapToDto(application),
|
||||
Message = "创建成功"
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ApplicationResponse?> UpdateAsync(int id, ApplicationUpdateRequest request)
|
||||
{
|
||||
var application = await _context.Applications.FindAsync(id);
|
||||
if (application == null)
|
||||
{
|
||||
return new ApplicationResponse { Success = false, Message = "应用不存在" };
|
||||
}
|
||||
|
||||
if (request.Name != null) application.Name = request.Name;
|
||||
if (request.Type != null) application.Type = request.Type;
|
||||
if (request.Description != null) application.Description = request.Description;
|
||||
if (request.ContentUrl != null) application.ContentUrl = request.ContentUrl;
|
||||
if (request.ThumbnailUrl != null) application.ThumbnailUrl = request.ThumbnailUrl;
|
||||
if (request.Priority.HasValue) application.Priority = request.Priority.Value;
|
||||
if (request.IsEnabled.HasValue) application.IsEnabled = request.IsEnabled.Value;
|
||||
application.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return new ApplicationResponse
|
||||
{
|
||||
Success = true,
|
||||
Data = MapToDto(application),
|
||||
Message = "更新成功"
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id)
|
||||
{
|
||||
var application = await _context.Applications.FindAsync(id);
|
||||
if (application == null) return false;
|
||||
|
||||
// 删除相关的设备分配
|
||||
var assignments = await _context.DeviceAssignments
|
||||
.Where(da => da.ApplicationId == id)
|
||||
.ToListAsync();
|
||||
_context.DeviceAssignments.RemoveRange(assignments);
|
||||
|
||||
_context.Applications.Remove(application);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ApplicationDto MapToDto(AppEntity application)
|
||||
{
|
||||
return new ApplicationDto
|
||||
{
|
||||
Id = application.Id,
|
||||
Name = application.Name,
|
||||
Type = application.Type,
|
||||
Description = application.Description,
|
||||
ContentUrl = application.ContentUrl,
|
||||
ThumbnailUrl = application.ThumbnailUrl,
|
||||
Priority = application.Priority,
|
||||
IsEnabled = application.IsEnabled,
|
||||
CreatedAt = application.CreatedAt,
|
||||
UpdatedAt = application.UpdatedAt
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Domain.Entities;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DRS9.Dashboard.Application.Services;
|
||||
|
||||
public class BatchManagementService
|
||||
{
|
||||
private readonly DashboardDbContext _context;
|
||||
private readonly DashboardWebSocketManager _wsManager;
|
||||
|
||||
public BatchManagementService(DashboardDbContext context, DashboardWebSocketManager wsManager)
|
||||
{
|
||||
_context = context;
|
||||
_wsManager = wsManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量为设备分配内容
|
||||
/// </summary>
|
||||
public async Task<BatchOperationResponse> BatchAssignContentAsync(BatchAssignContentRequest request)
|
||||
{
|
||||
var response = new BatchOperationResponse();
|
||||
var errors = new List<string>();
|
||||
|
||||
foreach (var deviceId in request.DeviceIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 删除现有分配
|
||||
var existingAssignments = await _context.DeviceAssignments
|
||||
.Where(da => da.DeviceId == deviceId)
|
||||
.ToListAsync();
|
||||
_context.DeviceAssignments.RemoveRange(existingAssignments);
|
||||
|
||||
// 创建新分配
|
||||
var order = 0;
|
||||
foreach (var appId in request.ApplicationIds)
|
||||
{
|
||||
_context.DeviceAssignments.Add(new DeviceAssignment
|
||||
{
|
||||
DeviceId = deviceId,
|
||||
ApplicationId = appId,
|
||||
Order = order++,
|
||||
Duration = 60
|
||||
});
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// 推送更新到设备
|
||||
await _wsManager.BroadcastToDeviceAsync(deviceId, new WebSocketMessage
|
||||
{
|
||||
Type = "content_refresh",
|
||||
Data = new { message = "内容已更新" }
|
||||
});
|
||||
|
||||
response.SuccessCount++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.FailedCount++;
|
||||
errors.Add($"设备 {deviceId}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
response.Success = response.SuccessCount > 0;
|
||||
response.Errors = errors;
|
||||
response.Message = $"成功: {response.SuccessCount}, 失败: {response.FailedCount}";
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量推送消息到设备
|
||||
/// </summary>
|
||||
public async Task<BatchOperationResponse> BatchPushAsync(BatchPushRequest request)
|
||||
{
|
||||
var response = new BatchOperationResponse();
|
||||
var message = new WebSocketMessage
|
||||
{
|
||||
Type = request.MessageType,
|
||||
Data = request.Data
|
||||
};
|
||||
|
||||
foreach (var deviceId in request.DeviceIds)
|
||||
{
|
||||
var connections = _wsManager.GetConnectionsByDevice(deviceId);
|
||||
if (connections.Any())
|
||||
{
|
||||
await _wsManager.BroadcastToDeviceAsync(deviceId, message);
|
||||
response.SuccessCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
response.FailedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
response.Success = response.SuccessCount > 0;
|
||||
response.Message = $"已推送到 {response.SuccessCount} 个在线设备";
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量推送到设备分组
|
||||
/// </summary>
|
||||
public async Task<BatchOperationResponse> BatchPushToGroupAsync(BatchPushToGroupRequest request)
|
||||
{
|
||||
var response = new BatchOperationResponse();
|
||||
var deviceIds = await _context.Devices
|
||||
.Where(d => request.DeviceGroupIds.Contains(d.DeviceGroupId ?? 0))
|
||||
.Select(d => d.Id)
|
||||
.ToListAsync();
|
||||
|
||||
var batchRequest = new BatchPushRequest
|
||||
{
|
||||
DeviceIds = deviceIds,
|
||||
MessageType = request.MessageType,
|
||||
Data = request.Data
|
||||
};
|
||||
|
||||
return await BatchPushAsync(batchRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量启用/禁用设备
|
||||
/// </summary>
|
||||
public async Task<BatchOperationResponse> BatchToggleDevicesAsync(BatchToggleDevicesRequest request)
|
||||
{
|
||||
var response = new BatchOperationResponse();
|
||||
|
||||
foreach (var deviceId in request.DeviceIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var device = await _context.Devices.FindAsync(deviceId);
|
||||
if (device != null)
|
||||
{
|
||||
device.IsEnabled = request.IsEnabled;
|
||||
device.UpdatedAt = DateTime.UtcNow;
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// 如果禁用设备,推送通知
|
||||
if (!request.IsEnabled)
|
||||
{
|
||||
await _wsManager.BroadcastToDeviceAsync(deviceId, new WebSocketMessage
|
||||
{
|
||||
Type = "device_disabled",
|
||||
Data = new { deviceId, message = "设备已被管理员禁用" }
|
||||
});
|
||||
}
|
||||
|
||||
response.SuccessCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
response.FailedCount++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.FailedCount++;
|
||||
response.Errors.Add($"设备 {deviceId}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
response.Success = response.SuccessCount > 0;
|
||||
response.Message = $"成功: {response.SuccessCount}, 失败: {response.FailedCount}";
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量分配播放列表到设备分组
|
||||
/// </summary>
|
||||
public async Task<BatchOperationResponse> BatchAssignPlaylistToGroupAsync(BatchAssignPlaylistRequest request)
|
||||
{
|
||||
var response = new BatchOperationResponse();
|
||||
var playlist = await _context.Playlists.FindAsync(request.PlaylistId);
|
||||
|
||||
if (playlist == null)
|
||||
{
|
||||
response.Success = false;
|
||||
response.Message = "播放列表不存在";
|
||||
return response;
|
||||
}
|
||||
|
||||
// 为每个分组创建播放列表副本(或使用共享逻辑)
|
||||
foreach (var groupId in request.DeviceGroupIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 这里简单实现:将原播放列表关联到第一个分组
|
||||
// 实际应用中可能需要为每个分组创建独立的播放列表
|
||||
var deviceIds = await _context.Devices
|
||||
.Where(d => d.DeviceGroupId == groupId)
|
||||
.Select(d => d.Id)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var deviceId in deviceIds)
|
||||
{
|
||||
await _wsManager.BroadcastToDeviceAsync(deviceId, new WebSocketMessage
|
||||
{
|
||||
Type = "playlist_changed",
|
||||
Data = new { message = "播放列表已更新" }
|
||||
});
|
||||
}
|
||||
|
||||
response.SuccessCount++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.FailedCount++;
|
||||
response.Errors.Add($"分组 {groupId}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
response.Success = response.SuccessCount > 0;
|
||||
response.Message = $"成功: {response.SuccessCount}, 失败: {response.FailedCount}";
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取分组中的所有设备 ID
|
||||
/// </summary>
|
||||
public async Task<List<int>> GetDeviceIdsByGroupsAsync(List<int> groupIds)
|
||||
{
|
||||
return await _context.Devices
|
||||
.Where(d => groupIds.Contains(d.DeviceGroupId ?? 0))
|
||||
.Select(d => d.Id)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace DRS9.Dashboard.Application.Services;
|
||||
|
||||
public interface IWebSocketMessage
|
||||
{
|
||||
string Type { get; set; }
|
||||
object? Data { get; set; }
|
||||
}
|
||||
|
||||
public class WebSocketMessage : IWebSocketMessage
|
||||
{
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public object? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DashboardWebSocketManager
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, WebSocketConnection> _connections = new();
|
||||
private readonly ILogger<DashboardWebSocketManager> _logger;
|
||||
|
||||
public DashboardWebSocketManager(ILogger<DashboardWebSocketManager> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public WebSocketConnection AddConnection(WebSocket webSocket, int? deviceId = null)
|
||||
{
|
||||
var connectionId = Guid.NewGuid().ToString();
|
||||
var connection = new WebSocketConnection
|
||||
{
|
||||
ConnectionId = connectionId,
|
||||
WebSocket = webSocket,
|
||||
DeviceId = deviceId
|
||||
};
|
||||
|
||||
_connections[connectionId] = connection;
|
||||
_logger.LogInformation("WebSocket connected: {ConnectionId}, DeviceId: {DeviceId}", connectionId, deviceId);
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void RemoveConnection(string connectionId)
|
||||
{
|
||||
if (_connections.TryRemove(connectionId, out var connection))
|
||||
{
|
||||
_logger.LogInformation("WebSocket disconnected: {ConnectionId}, DeviceId: {DeviceId}", connectionId, connection.DeviceId);
|
||||
}
|
||||
}
|
||||
|
||||
public WebSocketConnection? GetConnection(string connectionId)
|
||||
{
|
||||
return _connections.TryGetValue(connectionId, out var connection) ? connection : null;
|
||||
}
|
||||
|
||||
public IEnumerable<WebSocketConnection> GetAllConnections()
|
||||
{
|
||||
return _connections.Values;
|
||||
}
|
||||
|
||||
public IEnumerable<WebSocketConnection> GetConnectionsByDevice(int deviceId)
|
||||
{
|
||||
return _connections.Values.Where(c => c.DeviceId == deviceId);
|
||||
}
|
||||
|
||||
public async Task SendMessageAsync(string connectionId, IWebSocketMessage message)
|
||||
{
|
||||
if (_connections.TryGetValue(connectionId, out var connection))
|
||||
{
|
||||
await SendMessageAsync(connection, message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SendMessageAsync(WebSocketConnection connection, IWebSocketMessage message)
|
||||
{
|
||||
if (connection.WebSocket.State == WebSocketState.Open)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(message);
|
||||
var buffer = Encoding.UTF8.GetBytes(json);
|
||||
var segment = new ArraySegment<byte>(buffer, 0, buffer.Length);
|
||||
|
||||
await connection.WebSocket.SendAsync(segment, WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
connection.LastActivityAt = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task BroadcastToAllAsync(IWebSocketMessage message)
|
||||
{
|
||||
var tasks = _connections.Values
|
||||
.Where(c => c.WebSocket.State == WebSocketState.Open)
|
||||
.Select(c => SendMessageAsync(c, message));
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
public async Task BroadcastToDeviceAsync(int deviceId, IWebSocketMessage message)
|
||||
{
|
||||
var connections = GetConnectionsByDevice(deviceId);
|
||||
var tasks = connections
|
||||
.Where(c => c.WebSocket.State == WebSocketState.Open)
|
||||
.Select(c => SendMessageAsync(c, message));
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
public int GetConnectionCount()
|
||||
{
|
||||
return _connections.Count;
|
||||
}
|
||||
|
||||
public int GetDeviceConnectionCount(int deviceId)
|
||||
{
|
||||
return GetConnectionsByDevice(deviceId).Count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Domain.Entities;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DRS9.Dashboard.Application.Services;
|
||||
|
||||
public class DeviceManagementService
|
||||
{
|
||||
private readonly DashboardDbContext _context;
|
||||
private readonly DashboardWebSocketManager _wsManager;
|
||||
|
||||
public DeviceManagementService(DashboardDbContext context, DashboardWebSocketManager wsManager)
|
||||
{
|
||||
_context = context;
|
||||
_wsManager = wsManager;
|
||||
}
|
||||
|
||||
// 设备管理
|
||||
public async Task<DeviceListResponse> GetAllDevicesAsync()
|
||||
{
|
||||
var devices = await _context.Devices
|
||||
.Include(d => d.DeviceGroup)
|
||||
.OrderBy(d => d.Id)
|
||||
.ToListAsync();
|
||||
|
||||
return new DeviceListResponse
|
||||
{
|
||||
Success = true,
|
||||
Data = devices.Select(MapToDto).ToList(),
|
||||
Total = devices.Count
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<DeviceDto?> GetDeviceByIdAsync(int id)
|
||||
{
|
||||
var device = await _context.Devices
|
||||
.Include(d => d.DeviceGroup)
|
||||
.FirstOrDefaultAsync(d => d.Id == id);
|
||||
|
||||
return device == null ? null : MapToDto(device);
|
||||
}
|
||||
|
||||
public async Task<DeviceDto?> CreateDeviceAsync(DeviceCreateRequest request)
|
||||
{
|
||||
// 检查设备码是否已存在
|
||||
var exists = await _context.Devices.AnyAsync(d => d.DeviceCode == request.DeviceCode);
|
||||
if (exists) return null;
|
||||
|
||||
var device = new Device
|
||||
{
|
||||
DeviceCode = request.DeviceCode,
|
||||
DeviceName = request.DeviceName,
|
||||
DeviceGroupId = request.DeviceGroupId,
|
||||
IsActive = false,
|
||||
IsEnabled = true
|
||||
};
|
||||
|
||||
_context.Devices.Add(device);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return MapToDto(device);
|
||||
}
|
||||
|
||||
public async Task<DeviceDto?> UpdateDeviceAsync(int id, DeviceUpdateRequest request)
|
||||
{
|
||||
var device = await _context.Devices.FindAsync(id);
|
||||
if (device == null) return null;
|
||||
|
||||
if (request.DeviceName != null) device.DeviceName = request.DeviceName;
|
||||
if (request.DeviceGroupId.HasValue) device.DeviceGroupId = request.DeviceGroupId.Value;
|
||||
if (request.IsEnabled.HasValue)
|
||||
{
|
||||
device.IsEnabled = request.IsEnabled.Value;
|
||||
// 如果禁用设备,推送通知
|
||||
if (!request.IsEnabled.Value)
|
||||
{
|
||||
await _wsManager.BroadcastToDeviceAsync(id, new WebSocketMessage
|
||||
{
|
||||
Type = "device_disabled",
|
||||
Data = new { deviceId = id, message = "设备已被管理员禁用" }
|
||||
});
|
||||
}
|
||||
}
|
||||
device.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return MapToDto(device);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteDeviceAsync(int id)
|
||||
{
|
||||
var device = await _context.Devices.FindAsync(id);
|
||||
if (device == null) return false;
|
||||
|
||||
// 删除相关分配
|
||||
var assignments = await _context.DeviceAssignments
|
||||
.Where(da => da.DeviceId == id)
|
||||
.ToListAsync();
|
||||
_context.DeviceAssignments.RemoveRange(assignments);
|
||||
|
||||
_context.Devices.Remove(device);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 设备分组管理
|
||||
public async Task<DeviceGroupListResponse> GetAllGroupsAsync()
|
||||
{
|
||||
var groups = await _context.DeviceGroups
|
||||
.Include(g => g.Devices)
|
||||
.OrderBy(g => g.Id)
|
||||
.ToListAsync();
|
||||
|
||||
return new DeviceGroupListResponse
|
||||
{
|
||||
Success = true,
|
||||
Data = groups.Select(g => new DeviceGroupDto
|
||||
{
|
||||
Id = g.Id,
|
||||
Name = g.Name,
|
||||
Description = g.Description,
|
||||
DeviceCount = g.Devices.Count,
|
||||
CreatedAt = g.CreatedAt,
|
||||
UpdatedAt = g.UpdatedAt
|
||||
}).ToList(),
|
||||
Total = groups.Count
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<DeviceGroupDto?> CreateGroupAsync(DeviceGroupCreateRequest request)
|
||||
{
|
||||
var group = new DeviceGroup
|
||||
{
|
||||
Name = request.Name,
|
||||
Description = request.Description
|
||||
};
|
||||
|
||||
_context.DeviceGroups.Add(group);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return new DeviceGroupDto
|
||||
{
|
||||
Id = group.Id,
|
||||
Name = group.Name,
|
||||
Description = group.Description,
|
||||
DeviceCount = 0,
|
||||
CreatedAt = group.CreatedAt,
|
||||
UpdatedAt = group.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<DeviceGroupDto?> UpdateGroupAsync(int id, DeviceGroupUpdateRequest request)
|
||||
{
|
||||
var group = await _context.DeviceGroups.FindAsync(id);
|
||||
if (group == null) return null;
|
||||
|
||||
if (request.Name != null) group.Name = request.Name;
|
||||
if (request.Description != null) group.Description = request.Description;
|
||||
group.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var deviceCount = await _context.Devices.CountAsync(d => d.DeviceGroupId == id);
|
||||
|
||||
return new DeviceGroupDto
|
||||
{
|
||||
Id = group.Id,
|
||||
Name = group.Name,
|
||||
Description = group.Description,
|
||||
DeviceCount = deviceCount,
|
||||
CreatedAt = group.CreatedAt,
|
||||
UpdatedAt = group.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteGroupAsync(int id)
|
||||
{
|
||||
var group = await _context.DeviceGroups.FindAsync(id);
|
||||
if (group == null) return false;
|
||||
|
||||
// 取消所有设备的分组关联
|
||||
var devices = await _context.Devices.Where(d => d.DeviceGroupId == id).ToListAsync();
|
||||
foreach (var device in devices)
|
||||
{
|
||||
device.DeviceGroupId = null;
|
||||
}
|
||||
|
||||
_context.DeviceGroups.Remove(group);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 设备内容分配
|
||||
public async Task<DeviceContentResponse> GetDeviceContentAsync(int deviceId)
|
||||
{
|
||||
var assignments = await _context.DeviceAssignments
|
||||
.Where(da => da.DeviceId == deviceId)
|
||||
.Include(da => da.Application)
|
||||
.OrderBy(da => da.Order)
|
||||
.ToListAsync();
|
||||
|
||||
return new DeviceContentResponse
|
||||
{
|
||||
Success = true,
|
||||
Data = assignments.Select(da => new DeviceAssignmentDto
|
||||
{
|
||||
Id = da.Id,
|
||||
DeviceId = da.DeviceId,
|
||||
ApplicationId = da.ApplicationId,
|
||||
ApplicationName = da.Application.Name,
|
||||
ApplicationType = da.Application.Type,
|
||||
ContentUrl = da.Application.ContentUrl,
|
||||
Order = da.Order,
|
||||
Duration = da.Duration
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<bool> AssignContentToDeviceAsync(int deviceId, List<int> applicationIds)
|
||||
{
|
||||
var device = await _context.Devices.FindAsync(deviceId);
|
||||
if (device == null) return false;
|
||||
|
||||
// 删除现有分配
|
||||
var existingAssignments = await _context.DeviceAssignments
|
||||
.Where(da => da.DeviceId == deviceId)
|
||||
.ToListAsync();
|
||||
_context.DeviceAssignments.RemoveRange(existingAssignments);
|
||||
|
||||
// 创建新分配
|
||||
var order = 0;
|
||||
foreach (var appId in applicationIds)
|
||||
{
|
||||
_context.DeviceAssignments.Add(new DeviceAssignment
|
||||
{
|
||||
DeviceId = deviceId,
|
||||
ApplicationId = appId,
|
||||
Order = order++,
|
||||
Duration = 60
|
||||
});
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// 推送更新到设备
|
||||
await _wsManager.BroadcastToDeviceAsync(deviceId, new WebSocketMessage
|
||||
{
|
||||
Type = "content_refresh",
|
||||
Data = new { deviceId, message = "内容已更新" }
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 推送消息到设备
|
||||
public async Task<bool> PushMessageAsync(int deviceId, string messageType, object? data = null)
|
||||
{
|
||||
var connections = _wsManager.GetConnectionsByDevice(deviceId);
|
||||
if (!connections.Any()) return false;
|
||||
|
||||
await _wsManager.BroadcastToDeviceAsync(deviceId, new WebSocketMessage
|
||||
{
|
||||
Type = messageType,
|
||||
Data = data
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 获取在线设备
|
||||
public async Task<DeviceListResponse> GetOnlineDevicesAsync()
|
||||
{
|
||||
var onlineThreshold = DateTime.UtcNow.AddMinutes(-5);
|
||||
var devices = await _context.Devices
|
||||
.Include(d => d.DeviceGroup)
|
||||
.Where(d => d.LastSeenAt >= onlineThreshold)
|
||||
.ToListAsync();
|
||||
|
||||
return new DeviceListResponse
|
||||
{
|
||||
Success = true,
|
||||
Data = devices.Select(MapToDto).ToList(),
|
||||
Total = devices.Count
|
||||
};
|
||||
}
|
||||
|
||||
private static DeviceDto MapToDto(Device device)
|
||||
{
|
||||
return new DeviceDto
|
||||
{
|
||||
Id = device.Id,
|
||||
DeviceCode = device.DeviceCode,
|
||||
DeviceName = device.DeviceName,
|
||||
DeviceType = device.DeviceType,
|
||||
OsVersion = device.OsVersion,
|
||||
AppVersion = device.AppVersion,
|
||||
IsActive = device.IsActive,
|
||||
IsEnabled = device.IsEnabled,
|
||||
LastSeenAt = device.LastSeenAt,
|
||||
ActivatedAt = device.ActivatedAt,
|
||||
DeviceGroupId = device.DeviceGroupId,
|
||||
DeviceGroupName = device.DeviceGroup?.Name,
|
||||
CreatedAt = device.CreatedAt,
|
||||
UpdatedAt = device.UpdatedAt
|
||||
};
|
||||
}
|
||||
}
|
||||
84
src/DRS9.Dashboard.Application/Services/DeviceService.cs
Normal file
84
src/DRS9.Dashboard.Application/Services/DeviceService.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Domain.Entities;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DRS9.Dashboard.Application.Services;
|
||||
|
||||
public class DeviceService
|
||||
{
|
||||
private readonly DashboardDbContext _context;
|
||||
private readonly JwtTokenService _jwtTokenService;
|
||||
|
||||
public DeviceService(DashboardDbContext context, JwtTokenService jwtTokenService)
|
||||
{
|
||||
_context = context;
|
||||
_jwtTokenService = jwtTokenService;
|
||||
}
|
||||
|
||||
public async Task<DeviceRegisterResponse> RegisterAsync(DeviceRegisterRequest request)
|
||||
{
|
||||
// 查找设备码
|
||||
var device = await _context.Devices
|
||||
.FirstOrDefaultAsync(d => d.DeviceCode == request.DeviceCode);
|
||||
|
||||
if (device == null)
|
||||
{
|
||||
return new DeviceRegisterResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = "设备码无效"
|
||||
};
|
||||
}
|
||||
|
||||
if (!device.IsEnabled)
|
||||
{
|
||||
return new DeviceRegisterResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = "设备已被禁用"
|
||||
};
|
||||
}
|
||||
|
||||
// 更新设备信息
|
||||
device.DeviceName = request.DeviceName;
|
||||
device.DeviceType = request.DeviceType;
|
||||
device.OsVersion = request.OsVersion;
|
||||
device.AppVersion = request.AppVersion;
|
||||
device.IsActive = true;
|
||||
device.ActivatedAt = device.ActivatedAt ?? DateTime.UtcNow;
|
||||
device.LastSeenAt = DateTime.UtcNow;
|
||||
device.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// 生成 Token
|
||||
var token = _jwtTokenService.GenerateToken(device.Id, device.DeviceCode, device.DeviceName);
|
||||
|
||||
return new DeviceRegisterResponse
|
||||
{
|
||||
Success = true,
|
||||
Token = token,
|
||||
DeviceId = device.Id,
|
||||
Message = "注册成功"
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<Device?> GetDeviceAsync(int deviceId)
|
||||
{
|
||||
return await _context.Devices
|
||||
.Include(d => d.DeviceGroup)
|
||||
.FirstOrDefaultAsync(d => d.Id == deviceId);
|
||||
}
|
||||
|
||||
public async Task UpdateLastSeenAsync(int deviceId)
|
||||
{
|
||||
var device = await _context.Devices.FindAsync(deviceId);
|
||||
if (device != null)
|
||||
{
|
||||
device.LastSeenAt = DateTime.UtcNow;
|
||||
device.UpdatedAt = DateTime.UtcNow;
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Domain.Entities;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DRS9.Dashboard.Application.Services;
|
||||
|
||||
public class GuestAccessService
|
||||
{
|
||||
private readonly DashboardDbContext _context;
|
||||
private readonly JwtTokenService _jwtTokenService;
|
||||
|
||||
public GuestAccessService(DashboardDbContext context, JwtTokenService jwtTokenService)
|
||||
{
|
||||
_context = context;
|
||||
_jwtTokenService = jwtTokenService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建临时访问 Token
|
||||
/// </summary>
|
||||
public async Task<GuestAccessResponse> CreateGuestTokenAsync(GuestAccessCreateRequest request)
|
||||
{
|
||||
// 验证设备是否存在
|
||||
if (request.DeviceId.HasValue)
|
||||
{
|
||||
var device = await _context.Devices.FindAsync(request.DeviceId.Value);
|
||||
if (device == null || !device.IsEnabled)
|
||||
{
|
||||
return new GuestAccessResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = "设备不存在或已禁用"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 使用 JWT 创建临时 Token
|
||||
var deviceId = request.DeviceId ?? 0; // 0 表示访客模式
|
||||
var token = _jwtTokenService.GenerateToken(deviceId, "GUEST", $"访客-{request.Description ?? "临时访问"}");
|
||||
|
||||
// 计算 Token 过期时间
|
||||
var expiresAt = DateTime.UtcNow.AddMinutes(request.ValidityMinutes);
|
||||
|
||||
return new GuestAccessResponse
|
||||
{
|
||||
Success = true,
|
||||
Token = token,
|
||||
AccessUrl = $"/guest/{token}",
|
||||
ExpiresAt = expiresAt,
|
||||
Message = "临时访问链接已创建"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证访客 Token
|
||||
/// </summary>
|
||||
public bool ValidateGuestToken(string token)
|
||||
{
|
||||
var principal = _jwtTokenService.ValidateToken(token);
|
||||
if (principal == null) return false;
|
||||
|
||||
var deviceCodeClaim = principal.FindFirst("deviceCode")?.Value;
|
||||
return deviceCodeClaim == "GUEST";
|
||||
}
|
||||
}
|
||||
72
src/DRS9.Dashboard.Application/Services/JwtTokenService.cs
Normal file
72
src/DRS9.Dashboard.Application/Services/JwtTokenService.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace DRS9.Dashboard.Application.Services;
|
||||
|
||||
public class JwtTokenService
|
||||
{
|
||||
private readonly string _key;
|
||||
private readonly string _issuer;
|
||||
private readonly string _audience;
|
||||
private readonly int _expiryMinutes;
|
||||
|
||||
public JwtTokenService(string key, string issuer, string audience, int expiryMinutes)
|
||||
{
|
||||
_key = key;
|
||||
_issuer = issuer;
|
||||
_audience = audience;
|
||||
_expiryMinutes = expiryMinutes;
|
||||
}
|
||||
|
||||
public string GenerateToken(int deviceId, string deviceCode, string deviceName)
|
||||
{
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new Claim("deviceId", deviceId.ToString()),
|
||||
new Claim("deviceCode", deviceCode),
|
||||
new Claim("deviceName", deviceName),
|
||||
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
|
||||
};
|
||||
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_key));
|
||||
var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||
|
||||
var token = new JwtSecurityToken(
|
||||
issuer: _issuer,
|
||||
audience: _audience,
|
||||
claims: claims,
|
||||
expires: DateTime.UtcNow.AddMinutes(_expiryMinutes),
|
||||
signingCredentials: credentials
|
||||
);
|
||||
|
||||
return new JwtSecurityTokenHandler().WriteToken(token);
|
||||
}
|
||||
|
||||
public ClaimsPrincipal? ValidateToken(string token)
|
||||
{
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.UTF8.GetBytes(_key);
|
||||
|
||||
try
|
||||
{
|
||||
var principal = tokenHandler.ValidateToken(token, new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = _issuer,
|
||||
ValidAudience = _audience,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(key)
|
||||
}, out _);
|
||||
|
||||
return principal;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
288
src/DRS9.Dashboard.Application/Services/PlaylistService.cs
Normal file
288
src/DRS9.Dashboard.Application/Services/PlaylistService.cs
Normal file
@@ -0,0 +1,288 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Domain.Entities;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DRS9.Dashboard.Application.Services;
|
||||
|
||||
public class PlaylistService
|
||||
{
|
||||
private readonly DashboardDbContext _context;
|
||||
private readonly DashboardWebSocketManager _wsManager;
|
||||
|
||||
public PlaylistService(DashboardDbContext context, DashboardWebSocketManager wsManager)
|
||||
{
|
||||
_context = context;
|
||||
_wsManager = wsManager;
|
||||
}
|
||||
|
||||
public async Task<PlaylistListResponse> GetAllAsync()
|
||||
{
|
||||
var playlists = await _context.Playlists
|
||||
.Include(p => p.DeviceGroup)
|
||||
.Include(p => p.Items)
|
||||
.OrderBy(p => p.Id)
|
||||
.ToListAsync();
|
||||
|
||||
return new PlaylistListResponse
|
||||
{
|
||||
Success = true,
|
||||
Data = playlists.Select(p => new PlaylistDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Name,
|
||||
Description = p.Description,
|
||||
LoopMode = p.LoopMode,
|
||||
DeviceGroupId = p.DeviceGroupId,
|
||||
DeviceGroupName = p.DeviceGroup?.Name,
|
||||
IsEnabled = p.IsEnabled,
|
||||
ItemCount = p.Items.Count,
|
||||
CreatedAt = p.CreatedAt,
|
||||
UpdatedAt = p.UpdatedAt
|
||||
}).ToList(),
|
||||
Total = playlists.Count
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<PlaylistDetailDto?> GetByIdAsync(int id)
|
||||
{
|
||||
var playlist = await _context.Playlists
|
||||
.Include(p => p.DeviceGroup)
|
||||
.Include(p => p.Items)
|
||||
.ThenInclude(i => i.Application)
|
||||
.FirstOrDefaultAsync(p => p.Id == id);
|
||||
|
||||
if (playlist == null) return null;
|
||||
|
||||
return new PlaylistDetailDto
|
||||
{
|
||||
Id = playlist.Id,
|
||||
Name = playlist.Name,
|
||||
Description = playlist.Description,
|
||||
LoopMode = playlist.LoopMode,
|
||||
DeviceGroupId = playlist.DeviceGroupId,
|
||||
DeviceGroupName = playlist.DeviceGroup?.Name,
|
||||
IsEnabled = playlist.IsEnabled,
|
||||
Items = playlist.Items.OrderBy(i => i.Order).Select(i => new PlaylistItemDto
|
||||
{
|
||||
Id = i.Id,
|
||||
PlaylistId = i.PlaylistId,
|
||||
ApplicationId = i.ApplicationId,
|
||||
ApplicationName = i.Application.Name,
|
||||
ApplicationType = i.Application.Type,
|
||||
ContentUrl = i.Application.ContentUrl,
|
||||
Order = i.Order,
|
||||
Duration = i.Duration,
|
||||
IsEnabled = i.IsEnabled,
|
||||
ScheduleRule = i.ScheduleRule
|
||||
}).ToList(),
|
||||
CreatedAt = playlist.CreatedAt,
|
||||
UpdatedAt = playlist.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<PlaylistDetailDto?> CreateAsync(PlaylistCreateRequest request)
|
||||
{
|
||||
var playlist = new Playlist
|
||||
{
|
||||
Name = request.Name,
|
||||
Description = request.Description,
|
||||
LoopMode = request.LoopMode,
|
||||
DeviceGroupId = request.DeviceGroupId,
|
||||
IsEnabled = true
|
||||
};
|
||||
|
||||
_context.Playlists.Add(playlist);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// 添加播放项
|
||||
foreach (var itemRequest in request.Items)
|
||||
{
|
||||
var item = new PlaylistItem
|
||||
{
|
||||
PlaylistId = playlist.Id,
|
||||
ApplicationId = itemRequest.ApplicationId,
|
||||
Order = itemRequest.Order,
|
||||
Duration = itemRequest.Duration,
|
||||
IsEnabled = itemRequest.IsEnabled,
|
||||
ScheduleRule = itemRequest.ScheduleRule
|
||||
};
|
||||
_context.PlaylistItems.Add(item);
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return await GetByIdAsync(playlist.Id);
|
||||
}
|
||||
|
||||
public async Task<PlaylistDetailDto?> UpdateAsync(int id, PlaylistUpdateRequest request)
|
||||
{
|
||||
var playlist = await _context.Playlists.FindAsync(id);
|
||||
if (playlist == null) return null;
|
||||
|
||||
if (request.Name != null) playlist.Name = request.Name;
|
||||
if (request.Description != null) playlist.Description = request.Description;
|
||||
if (request.LoopMode != null) playlist.LoopMode = request.LoopMode;
|
||||
if (request.DeviceGroupId.HasValue) playlist.DeviceGroupId = request.DeviceGroupId.Value;
|
||||
if (request.IsEnabled.HasValue) playlist.IsEnabled = request.IsEnabled.Value;
|
||||
playlist.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return await GetByIdAsync(id);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id)
|
||||
{
|
||||
var playlist = await _context.Playlists.FindAsync(id);
|
||||
if (playlist == null) return false;
|
||||
|
||||
_context.Playlists.Remove(playlist);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取设备当前应该播放的内容列表
|
||||
/// </summary>
|
||||
public async Task<DevicePlaylistResponse> GetDevicePlaylistAsync(int deviceId)
|
||||
{
|
||||
var device = await _context.Devices
|
||||
.Include(d => d.DeviceGroup)
|
||||
.FirstOrDefaultAsync(d => d.Id == deviceId);
|
||||
|
||||
if (device == null)
|
||||
{
|
||||
return new DevicePlaylistResponse { Success = false };
|
||||
}
|
||||
|
||||
// 查找匹配的播放列表
|
||||
var playlist = await _context.Playlists
|
||||
.Include(p => p.Items)
|
||||
.ThenInclude(i => i.Application)
|
||||
.Where(p => p.IsEnabled &&
|
||||
(p.DeviceGroupId == null || p.DeviceGroupId == device.DeviceGroupId))
|
||||
.OrderByDescending(p => p.DeviceGroupId) // 优先使用设备专属的播放列表
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (playlist == null || !playlist.Items.Any())
|
||||
{
|
||||
return new DevicePlaylistResponse { Success = true, Data = new(), LoopMode = "Loop" };
|
||||
}
|
||||
|
||||
// 过滤启用的播放项,并检查定时规则
|
||||
var now = DateTime.UtcNow;
|
||||
var enabledItems = playlist.Items
|
||||
.Where(i => i.IsEnabled && IsItemScheduled(i, now))
|
||||
.OrderBy(i => i.Order)
|
||||
.Select(i => new PlaylistContentDto
|
||||
{
|
||||
Order = i.Order,
|
||||
ApplicationName = i.Application.Name,
|
||||
ApplicationType = i.Application.Type,
|
||||
ContentUrl = i.Application.ContentUrl,
|
||||
Duration = i.Duration,
|
||||
ThumbnailUrl = i.Application.ThumbnailUrl
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return new DevicePlaylistResponse
|
||||
{
|
||||
Success = true,
|
||||
Data = enabledItems,
|
||||
LoopMode = playlist.LoopMode,
|
||||
TotalDuration = enabledItems.Sum(i => i.Duration)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查播放项是否应该在当前时间播放
|
||||
/// </summary>
|
||||
private bool IsItemScheduled(PlaylistItem item, DateTime now)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item.ScheduleRule)) return true;
|
||||
|
||||
try
|
||||
{
|
||||
// 简单的定时规则检查
|
||||
// 格式: {"startDate":"2025-01-01","endDate":"2025-12-31","weekdays":[1,2,3,4,5],"startTime":"08:00","endTime":"18:00"}
|
||||
using var jsonDoc = System.Text.Json.JsonDocument.Parse(item.ScheduleRule);
|
||||
var root = jsonDoc.RootElement;
|
||||
|
||||
// 检查日期范围
|
||||
if (root.TryGetProperty("startDate", out var startDateElem))
|
||||
{
|
||||
var startDate = DateTime.Parse(startDateElem.GetString()!);
|
||||
if (now < startDate) return false;
|
||||
}
|
||||
|
||||
if (root.TryGetProperty("endDate", out var endDateElem))
|
||||
{
|
||||
var endDate = DateTime.Parse(endDateElem.GetString()!).AddDays(1).AddSeconds(-1);
|
||||
if (now > endDate) return false;
|
||||
}
|
||||
|
||||
// 检查星期
|
||||
if (root.TryGetProperty("weekdays", out var weekdaysElem) && weekdaysElem.ValueKind == System.Text.Json.JsonValueKind.Array)
|
||||
{
|
||||
var currentDay = (int)now.DayOfWeek;
|
||||
var allowedDays = weekdaysElem.EnumerateArray().Select(e => e.GetInt32()).ToHashSet();
|
||||
if (!allowedDays.Contains(currentDay)) return false;
|
||||
}
|
||||
|
||||
// 检查时间范围
|
||||
var currentTime = now.TimeOfDay;
|
||||
if (root.TryGetProperty("startTime", out var startTimeElem))
|
||||
{
|
||||
var startTime = TimeSpan.Parse(startTimeElem.GetString()!);
|
||||
if (currentTime < startTime) return false;
|
||||
}
|
||||
|
||||
if (root.TryGetProperty("endTime", out var endTimeElem))
|
||||
{
|
||||
var endTime = TimeSpan.Parse(endTimeElem.GetString()!);
|
||||
if (currentTime > endTime) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 解析失败,默认允许播放
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为播放列表分配到设备分组
|
||||
/// </summary>
|
||||
public async Task<bool> AssignToGroupAsync(int playlistId, int? groupId)
|
||||
{
|
||||
var playlist = await _context.Playlists.FindAsync(playlistId);
|
||||
if (playlist == null) return false;
|
||||
|
||||
playlist.DeviceGroupId = groupId;
|
||||
playlist.UpdatedAt = DateTime.UtcNow;
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// 推送更新到相关设备
|
||||
if (groupId.HasValue)
|
||||
{
|
||||
var devices = await _context.Devices
|
||||
.Where(d => d.DeviceGroupId == groupId.Value)
|
||||
.Select(d => d.Id)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var deviceId in devices)
|
||||
{
|
||||
await _wsManager.BroadcastToDeviceAsync(deviceId, new WebSocketMessage
|
||||
{
|
||||
Type = "playlist_changed",
|
||||
Data = new { message = "播放列表已更新" }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Net.WebSockets;
|
||||
|
||||
namespace DRS9.Dashboard.Application.Services;
|
||||
|
||||
public class WebSocketConnection
|
||||
{
|
||||
public required string ConnectionId { get; set; }
|
||||
public required WebSocket WebSocket { get; set; }
|
||||
public int? DeviceId { get; set; }
|
||||
public DateTime ConnectedAt { get; set; } = DateTime.UtcNow;
|
||||
public DateTime LastActivityAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
9
src/DRS9.Dashboard.Domain/DRS9.Dashboard.Domain.csproj
Normal file
9
src/DRS9.Dashboard.Domain/DRS9.Dashboard.Domain.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
29
src/DRS9.Dashboard.Domain/Entities/AppVersion.cs
Normal file
29
src/DRS9.Dashboard.Domain/Entities/AppVersion.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Domain.Entities;
|
||||
|
||||
public class AppVersion : BaseEntity
|
||||
{
|
||||
[MaxLength(50)]
|
||||
public string Platform { get; set; } = string.Empty; // Android, iOS, Windows
|
||||
|
||||
[MaxLength(20)]
|
||||
public string Version { get; set; } = string.Empty; // e.g., "1.0.0"
|
||||
|
||||
[MaxLength(100)]
|
||||
public string VersionName { get; set; } = string.Empty; // e.g., "正式版 v1.0"
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? DownloadUrl { get; set; }
|
||||
|
||||
public long? FileSize { get; set; }
|
||||
|
||||
[MaxLength(1000)]
|
||||
public string? ChangeLog { get; set; }
|
||||
|
||||
public bool IsForceUpdate { get; set; } = false;
|
||||
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
|
||||
public DateTime? PublishedAt { get; set; }
|
||||
}
|
||||
28
src/DRS9.Dashboard.Domain/Entities/Application.cs
Normal file
28
src/DRS9.Dashboard.Domain/Entities/Application.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Domain.Entities;
|
||||
|
||||
public class Application : BaseEntity
|
||||
{
|
||||
[MaxLength(200)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(50)]
|
||||
public string Type { get; set; } = string.Empty; // Dashboard, WebRotator, ImageRotator, Video
|
||||
|
||||
[MaxLength(1000)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[MaxLength(2000)]
|
||||
public string ContentUrl { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? ThumbnailUrl { get; set; }
|
||||
|
||||
public int Priority { get; set; } = 0; // 用于排序
|
||||
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
|
||||
// 导航属性
|
||||
public ICollection<DeviceAssignment> Assignments { get; set; } = new List<DeviceAssignment>();
|
||||
}
|
||||
22
src/DRS9.Dashboard.Domain/Entities/AuditLog.cs
Normal file
22
src/DRS9.Dashboard.Domain/Entities/AuditLog.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Domain.Entities;
|
||||
|
||||
public class AuditLog : BaseEntity
|
||||
{
|
||||
[MaxLength(50)]
|
||||
public string Action { get; set; } = string.Empty; // Create, Update, Delete, Push, etc.
|
||||
|
||||
[MaxLength(100)]
|
||||
public string? EntityType { get; set; }
|
||||
|
||||
public int? EntityId { get; set; }
|
||||
|
||||
[MaxLength(50)]
|
||||
public string? Username { get; set; }
|
||||
|
||||
[MaxLength(100)]
|
||||
public string? IpAddress { get; set; }
|
||||
|
||||
public string? Details { get; set; }
|
||||
}
|
||||
8
src/DRS9.Dashboard.Domain/Entities/BaseEntity.cs
Normal file
8
src/DRS9.Dashboard.Domain/Entities/BaseEntity.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace DRS9.Dashboard.Domain.Entities;
|
||||
|
||||
public abstract class BaseEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
36
src/DRS9.Dashboard.Domain/Entities/Device.cs
Normal file
36
src/DRS9.Dashboard.Domain/Entities/Device.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Domain.Entities;
|
||||
|
||||
public class Device : BaseEntity
|
||||
{
|
||||
[MaxLength(50)]
|
||||
public string DeviceCode { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(200)]
|
||||
public string DeviceName { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(100)]
|
||||
public string? DeviceType { get; set; } // Android, iOS, Windows, Browser
|
||||
|
||||
[MaxLength(50)]
|
||||
public string? OsVersion { get; set; }
|
||||
|
||||
[MaxLength(100)]
|
||||
public string? AppVersion { get; set; }
|
||||
|
||||
public bool IsActive { get; set; } = false;
|
||||
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
|
||||
public DateTime? LastSeenAt { get; set; }
|
||||
|
||||
public DateTime? ActivatedAt { get; set; }
|
||||
|
||||
// 外键
|
||||
public int? DeviceGroupId { get; set; }
|
||||
|
||||
// 导航属性
|
||||
public DeviceGroup? DeviceGroup { get; set; }
|
||||
public ICollection<DeviceAssignment> Assignments { get; set; } = new List<DeviceAssignment>();
|
||||
}
|
||||
18
src/DRS9.Dashboard.Domain/Entities/DeviceAssignment.cs
Normal file
18
src/DRS9.Dashboard.Domain/Entities/DeviceAssignment.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Domain.Entities;
|
||||
|
||||
public class DeviceAssignment : BaseEntity
|
||||
{
|
||||
public int DeviceId { get; set; }
|
||||
|
||||
public int ApplicationId { get; set; }
|
||||
|
||||
public int Order { get; set; } = 0;
|
||||
|
||||
public int Duration { get; set; } = 60; // 显示时长(秒)
|
||||
|
||||
// 导航属性
|
||||
public Device Device { get; set; } = null!;
|
||||
public Application Application { get; set; } = null!;
|
||||
}
|
||||
15
src/DRS9.Dashboard.Domain/Entities/DeviceGroup.cs
Normal file
15
src/DRS9.Dashboard.Domain/Entities/DeviceGroup.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Domain.Entities;
|
||||
|
||||
public class DeviceGroup : BaseEntity
|
||||
{
|
||||
[MaxLength(100)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
// 导航属性
|
||||
public ICollection<Device> Devices { get; set; } = new List<Device>();
|
||||
}
|
||||
57
src/DRS9.Dashboard.Domain/Entities/Playlist.cs
Normal file
57
src/DRS9.Dashboard.Domain/Entities/Playlist.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Domain.Entities;
|
||||
|
||||
public class Playlist : BaseEntity
|
||||
{
|
||||
[MaxLength(200)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(1000)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 循环模式: Loop(循环播放), Once(播放一次), Shuffle(随机播放)
|
||||
/// </summary>
|
||||
[MaxLength(20)]
|
||||
public string LoopMode { get; set; } = "Loop";
|
||||
|
||||
public int? DeviceGroupId { get; set; }
|
||||
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
|
||||
// 导航属性
|
||||
public DeviceGroup? DeviceGroup { get; set; }
|
||||
public ICollection<PlaylistItem> Items { get; set; } = new List<PlaylistItem>();
|
||||
}
|
||||
|
||||
public class PlaylistItem : BaseEntity
|
||||
{
|
||||
public int PlaylistId { get; set; }
|
||||
|
||||
public int ApplicationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 播放顺序
|
||||
/// </summary>
|
||||
public int Order { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 显示时长(秒),0 表示使用默认值
|
||||
/// </summary>
|
||||
public int Duration { get; set; } = 60;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 定时规则:JSON 格式,例如 {"startDate":"2025-01-01","endDate":"2025-12-31","weekdays":[1,2,3,4,5],"startTime":"08:00","endTime":"18:00"}
|
||||
/// </summary>
|
||||
public string? ScheduleRule { get; set; }
|
||||
|
||||
// 导航属性
|
||||
public Playlist Playlist { get; set; } = null!;
|
||||
public Application Application { get; set; } = null!;
|
||||
}
|
||||
20
src/DRS9.Dashboard.Domain/Entities/User.cs
Normal file
20
src/DRS9.Dashboard.Domain/Entities/User.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DRS9.Dashboard.Domain.Entities;
|
||||
|
||||
public class User : BaseEntity
|
||||
{
|
||||
[MaxLength(100)]
|
||||
public string Username { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(255)]
|
||||
public string PasswordHash { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(100)]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(20)]
|
||||
public string Role { get; set; } = "User"; // Admin, User
|
||||
|
||||
public bool IsActive { get; set; } = true;
|
||||
}
|
||||
6
src/DRS9.Dashboard.Infrastructure/Class1.cs
Normal file
6
src/DRS9.Dashboard.Infrastructure/Class1.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace DRS9.Dashboard.Infrastructure;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DRS9.Dashboard.Domain\DRS9.Dashboard.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.*" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.*" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
105
src/DRS9.Dashboard.Infrastructure/Data/DashboardDbContext.cs
Normal file
105
src/DRS9.Dashboard.Infrastructure/Data/DashboardDbContext.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using DRS9.Dashboard.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DRS9.Dashboard.Infrastructure.Data;
|
||||
|
||||
public class DashboardDbContext : DbContext
|
||||
{
|
||||
public DashboardDbContext(DbContextOptions<DashboardDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Device> Devices { get; set; }
|
||||
public DbSet<DeviceGroup> DeviceGroups { get; set; }
|
||||
public DbSet<Application> Applications { get; set; }
|
||||
public DbSet<DeviceAssignment> DeviceAssignments { get; set; }
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<AuditLog> AuditLogs { get; set; }
|
||||
public DbSet<Playlist> Playlists { get; set; }
|
||||
public DbSet<PlaylistItem> PlaylistItems { get; set; }
|
||||
public DbSet<AppVersion> AppVersions { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
// DeviceGroup 配置
|
||||
modelBuilder.Entity<DeviceGroup>(entity =>
|
||||
{
|
||||
entity.HasIndex(e => e.Name).IsUnique();
|
||||
});
|
||||
|
||||
// Device 配置
|
||||
modelBuilder.Entity<Device>(entity =>
|
||||
{
|
||||
entity.HasIndex(e => e.DeviceCode).IsUnique();
|
||||
entity.HasOne(e => e.DeviceGroup)
|
||||
.WithMany(g => g.Devices)
|
||||
.HasForeignKey(e => e.DeviceGroupId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
});
|
||||
|
||||
// Application 配置
|
||||
modelBuilder.Entity<Application>(entity =>
|
||||
{
|
||||
entity.HasIndex(e => e.Name);
|
||||
});
|
||||
|
||||
// DeviceAssignment 配置(多对多关系的中间表)
|
||||
modelBuilder.Entity<DeviceAssignment>(entity =>
|
||||
{
|
||||
entity.HasOne(e => e.Device)
|
||||
.WithMany(d => d.Assignments)
|
||||
.HasForeignKey(e => e.DeviceId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
entity.HasOne(e => e.Application)
|
||||
.WithMany(a => a.Assignments)
|
||||
.HasForeignKey(e => e.ApplicationId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// 确保同一设备的同一应用只有一个分配
|
||||
entity.HasIndex(e => new { e.DeviceId, e.ApplicationId }).IsUnique();
|
||||
});
|
||||
|
||||
// User 配置
|
||||
modelBuilder.Entity<User>(entity =>
|
||||
{
|
||||
entity.HasIndex(e => e.Username).IsUnique();
|
||||
entity.HasIndex(e => e.Email).IsUnique();
|
||||
});
|
||||
|
||||
// Playlist 配置
|
||||
modelBuilder.Entity<Playlist>(entity =>
|
||||
{
|
||||
entity.HasIndex(e => e.Name);
|
||||
entity.HasOne(e => e.DeviceGroup)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.DeviceGroupId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
});
|
||||
|
||||
// PlaylistItem 配置
|
||||
modelBuilder.Entity<PlaylistItem>(entity =>
|
||||
{
|
||||
entity.HasOne(e => e.Playlist)
|
||||
.WithMany(p => p.Items)
|
||||
.HasForeignKey(e => e.PlaylistId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
entity.HasOne(e => e.Application)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.ApplicationId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// 同一播放列表中的项目按 Order 排序
|
||||
entity.HasIndex(e => new { e.PlaylistId, e.Order });
|
||||
});
|
||||
|
||||
// AppVersion 配置
|
||||
modelBuilder.Entity<AppVersion>(entity =>
|
||||
{
|
||||
entity.HasIndex(e => new { e.Platform, e.Version });
|
||||
});
|
||||
}
|
||||
}
|
||||
44
src/DRS9.Dashboard.Infrastructure/Data/DataSeeder.cs
Normal file
44
src/DRS9.Dashboard.Infrastructure/Data/DataSeeder.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using DRS9.Dashboard.Domain.Entities;
|
||||
|
||||
namespace DRS9.Dashboard.Infrastructure.Data;
|
||||
|
||||
public static class DataSeeder
|
||||
{
|
||||
public static async Task SeedAsync(DashboardDbContext context)
|
||||
{
|
||||
// 确保数据库已创建
|
||||
await context.Database.EnsureCreatedAsync();
|
||||
|
||||
// 添加测试设备码
|
||||
if (!context.Devices.Any())
|
||||
{
|
||||
var devices = new List<Device>
|
||||
{
|
||||
new() { DeviceCode = "TEST-001-DEV", DeviceName = "测试设备1", IsEnabled = true },
|
||||
new() { DeviceCode = "TEST-002-DEV", DeviceName = "测试设备2", IsEnabled = true },
|
||||
new() { DeviceCode = "TEST-003-DEV", DeviceName = "测试设备3", IsEnabled = true },
|
||||
new() { DeviceCode = "SCHOOL-001-DS", DeviceName = "学校显示屏1", IsEnabled = true },
|
||||
new() { DeviceCode = "MALL-001-DS", DeviceName = "商场广告屏1", IsEnabled = true }
|
||||
};
|
||||
|
||||
await context.Devices.AddRangeAsync(devices);
|
||||
await context.SaveChangesAsync();
|
||||
Console.WriteLine("已添加 5 个测试设备码");
|
||||
}
|
||||
|
||||
// 添加测试应用
|
||||
if (!context.Applications.Any())
|
||||
{
|
||||
var apps = new List<Application>
|
||||
{
|
||||
new() { Name = "欢迎页面", Type = "Dashboard", ContentUrl = "/dashboard/welcome", IsEnabled = true, Priority = 1 },
|
||||
new() { Name = "新闻轮转", Type = "WebRotator", ContentUrl = "/rotator/news", IsEnabled = true, Priority = 2 },
|
||||
new() { Name = "图片轮播", Type = "ImageRotator", ContentUrl = "/gallery/promo", IsEnabled = true, Priority = 3 }
|
||||
};
|
||||
|
||||
await context.Applications.AddRangeAsync(apps);
|
||||
await context.SaveChangesAsync();
|
||||
Console.WriteLine("已添加 3 个测试应用");
|
||||
}
|
||||
}
|
||||
}
|
||||
325
src/DRS9.Dashboard.Infrastructure/Migrations/20260112082557_InitialCreate.Designer.cs
generated
Normal file
325
src/DRS9.Dashboard.Infrastructure/Migrations/20260112082557_InitialCreate.Designer.cs
generated
Normal file
@@ -0,0 +1,325 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DRS9.Dashboard.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(DashboardDbContext))]
|
||||
[Migration("20260112082557_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.11");
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Application", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ContentUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Priority")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ThumbnailUrl")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.ToTable("Applications");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.AuditLog", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Action")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Details")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("EntityId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("EntityType")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("IpAddress")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("AuditLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("ActivatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("AppVersion")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DeviceCode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("DeviceGroupId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("DeviceName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DeviceType")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("LastSeenAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("OsVersion")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DeviceCode")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("DeviceGroupId");
|
||||
|
||||
b.ToTable("Devices");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceAssignment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ApplicationId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("DeviceId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Duration")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Order")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ApplicationId");
|
||||
|
||||
b.HasIndex("DeviceId", "ApplicationId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("DeviceAssignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceGroup", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("DeviceGroups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Role")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Email")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.DeviceGroup", "DeviceGroup")
|
||||
.WithMany("Devices")
|
||||
.HasForeignKey("DeviceGroupId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("DeviceGroup");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceAssignment", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Application", "Application")
|
||||
.WithMany("Assignments")
|
||||
.HasForeignKey("ApplicationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Device", "Device")
|
||||
.WithMany("Assignments")
|
||||
.HasForeignKey("DeviceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Application");
|
||||
|
||||
b.Navigation("Device");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Application", b =>
|
||||
{
|
||||
b.Navigation("Assignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.Navigation("Assignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceGroup", b =>
|
||||
{
|
||||
b.Navigation("Devices");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DRS9.Dashboard.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Applications",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Name = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
|
||||
Type = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
|
||||
Description = table.Column<string>(type: "TEXT", maxLength: 1000, nullable: true),
|
||||
ContentUrl = table.Column<string>(type: "TEXT", maxLength: 2000, nullable: false),
|
||||
ThumbnailUrl = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
|
||||
Priority = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
IsEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Applications", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AuditLogs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Action = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
|
||||
EntityType = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
||||
EntityId = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
Username = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
IpAddress = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
||||
Details = table.Column<string>(type: "TEXT", nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AuditLogs", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "DeviceGroups",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
||||
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_DeviceGroups", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Username = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
||||
PasswordHash = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
|
||||
Email = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
||||
Role = table.Column<string>(type: "TEXT", maxLength: 20, nullable: false),
|
||||
IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Devices",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
DeviceCode = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
|
||||
DeviceName = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
|
||||
DeviceType = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
||||
OsVersion = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
AppVersion = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
||||
IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
IsEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
LastSeenAt = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
ActivatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
DeviceGroupId = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Devices", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Devices_DeviceGroups_DeviceGroupId",
|
||||
column: x => x.DeviceGroupId,
|
||||
principalTable: "DeviceGroups",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "DeviceAssignments",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
DeviceId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ApplicationId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Order = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Duration = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_DeviceAssignments", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_DeviceAssignments_Applications_ApplicationId",
|
||||
column: x => x.ApplicationId,
|
||||
principalTable: "Applications",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_DeviceAssignments_Devices_DeviceId",
|
||||
column: x => x.DeviceId,
|
||||
principalTable: "Devices",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Applications_Name",
|
||||
table: "Applications",
|
||||
column: "Name");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_DeviceAssignments_ApplicationId",
|
||||
table: "DeviceAssignments",
|
||||
column: "ApplicationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_DeviceAssignments_DeviceId_ApplicationId",
|
||||
table: "DeviceAssignments",
|
||||
columns: new[] { "DeviceId", "ApplicationId" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_DeviceGroups_Name",
|
||||
table: "DeviceGroups",
|
||||
column: "Name",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Devices_DeviceCode",
|
||||
table: "Devices",
|
||||
column: "DeviceCode",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Devices_DeviceGroupId",
|
||||
table: "Devices",
|
||||
column: "DeviceGroupId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Users_Email",
|
||||
table: "Users",
|
||||
column: "Email",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Users_Username",
|
||||
table: "Users",
|
||||
column: "Username",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AuditLogs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "DeviceAssignments");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Applications");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Devices");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "DeviceGroups");
|
||||
}
|
||||
}
|
||||
}
|
||||
439
src/DRS9.Dashboard.Infrastructure/Migrations/20260112091958_AddPlaylists.Designer.cs
generated
Normal file
439
src/DRS9.Dashboard.Infrastructure/Migrations/20260112091958_AddPlaylists.Designer.cs
generated
Normal file
@@ -0,0 +1,439 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DRS9.Dashboard.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(DashboardDbContext))]
|
||||
[Migration("20260112091958_AddPlaylists")]
|
||||
partial class AddPlaylists
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.11");
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Application", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ContentUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Priority")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ThumbnailUrl")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.ToTable("Applications");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.AuditLog", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Action")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Details")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("EntityId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("EntityType")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("IpAddress")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("AuditLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("ActivatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("AppVersion")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DeviceCode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("DeviceGroupId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("DeviceName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DeviceType")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("LastSeenAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("OsVersion")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DeviceCode")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("DeviceGroupId");
|
||||
|
||||
b.ToTable("Devices");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceAssignment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ApplicationId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("DeviceId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Duration")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Order")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ApplicationId");
|
||||
|
||||
b.HasIndex("DeviceId", "ApplicationId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("DeviceAssignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceGroup", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("DeviceGroups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Playlist", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("DeviceGroupId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("LoopMode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DeviceGroupId");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.ToTable("Playlists");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.PlaylistItem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ApplicationId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Duration")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Order")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("PlaylistId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ScheduleRule")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ApplicationId");
|
||||
|
||||
b.HasIndex("PlaylistId", "Order");
|
||||
|
||||
b.ToTable("PlaylistItems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Role")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Email")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.DeviceGroup", "DeviceGroup")
|
||||
.WithMany("Devices")
|
||||
.HasForeignKey("DeviceGroupId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("DeviceGroup");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceAssignment", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Application", "Application")
|
||||
.WithMany("Assignments")
|
||||
.HasForeignKey("ApplicationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Device", "Device")
|
||||
.WithMany("Assignments")
|
||||
.HasForeignKey("DeviceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Application");
|
||||
|
||||
b.Navigation("Device");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Playlist", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.DeviceGroup", "DeviceGroup")
|
||||
.WithMany()
|
||||
.HasForeignKey("DeviceGroupId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("DeviceGroup");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.PlaylistItem", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Application", "Application")
|
||||
.WithMany()
|
||||
.HasForeignKey("ApplicationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Playlist", "Playlist")
|
||||
.WithMany("Items")
|
||||
.HasForeignKey("PlaylistId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Application");
|
||||
|
||||
b.Navigation("Playlist");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Application", b =>
|
||||
{
|
||||
b.Navigation("Assignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.Navigation("Assignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceGroup", b =>
|
||||
{
|
||||
b.Navigation("Devices");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Playlist", b =>
|
||||
{
|
||||
b.Navigation("Items");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DRS9.Dashboard.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddPlaylists : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Playlists",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Name = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
|
||||
Description = table.Column<string>(type: "TEXT", maxLength: 1000, nullable: true),
|
||||
LoopMode = table.Column<string>(type: "TEXT", maxLength: 20, nullable: false),
|
||||
DeviceGroupId = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
IsEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Playlists", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Playlists_DeviceGroups_DeviceGroupId",
|
||||
column: x => x.DeviceGroupId,
|
||||
principalTable: "DeviceGroups",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PlaylistItems",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
PlaylistId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ApplicationId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Order = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Duration = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
IsEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
ScheduleRule = table.Column<string>(type: "TEXT", nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PlaylistItems", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_PlaylistItems_Applications_ApplicationId",
|
||||
column: x => x.ApplicationId,
|
||||
principalTable: "Applications",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PlaylistItems_Playlists_PlaylistId",
|
||||
column: x => x.PlaylistId,
|
||||
principalTable: "Playlists",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlaylistItems_ApplicationId",
|
||||
table: "PlaylistItems",
|
||||
column: "ApplicationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlaylistItems_PlaylistId_Order",
|
||||
table: "PlaylistItems",
|
||||
columns: new[] { "PlaylistId", "Order" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Playlists_DeviceGroupId",
|
||||
table: "Playlists",
|
||||
column: "DeviceGroupId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Playlists_Name",
|
||||
table: "Playlists",
|
||||
column: "Name");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "PlaylistItems");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Playlists");
|
||||
}
|
||||
}
|
||||
}
|
||||
493
src/DRS9.Dashboard.Infrastructure/Migrations/20260112092747_AddAppVersions.Designer.cs
generated
Normal file
493
src/DRS9.Dashboard.Infrastructure/Migrations/20260112092747_AddAppVersions.Designer.cs
generated
Normal file
@@ -0,0 +1,493 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DRS9.Dashboard.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(DashboardDbContext))]
|
||||
[Migration("20260112092747_AddAppVersions")]
|
||||
partial class AddAppVersions
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.11");
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.AppVersion", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ChangeLog")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DownloadUrl")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<long?>("FileSize")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsForceUpdate")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Platform")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("PublishedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Version")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("VersionName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Platform", "Version");
|
||||
|
||||
b.ToTable("AppVersions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Application", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ContentUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Priority")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ThumbnailUrl")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.ToTable("Applications");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.AuditLog", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Action")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Details")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("EntityId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("EntityType")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("IpAddress")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("AuditLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("ActivatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("AppVersion")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DeviceCode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("DeviceGroupId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("DeviceName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DeviceType")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("LastSeenAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("OsVersion")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DeviceCode")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("DeviceGroupId");
|
||||
|
||||
b.ToTable("Devices");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceAssignment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ApplicationId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("DeviceId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Duration")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Order")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ApplicationId");
|
||||
|
||||
b.HasIndex("DeviceId", "ApplicationId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("DeviceAssignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceGroup", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("DeviceGroups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Playlist", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("DeviceGroupId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("LoopMode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DeviceGroupId");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.ToTable("Playlists");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.PlaylistItem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ApplicationId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Duration")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Order")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("PlaylistId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ScheduleRule")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ApplicationId");
|
||||
|
||||
b.HasIndex("PlaylistId", "Order");
|
||||
|
||||
b.ToTable("PlaylistItems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Role")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Email")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.DeviceGroup", "DeviceGroup")
|
||||
.WithMany("Devices")
|
||||
.HasForeignKey("DeviceGroupId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("DeviceGroup");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceAssignment", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Application", "Application")
|
||||
.WithMany("Assignments")
|
||||
.HasForeignKey("ApplicationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Device", "Device")
|
||||
.WithMany("Assignments")
|
||||
.HasForeignKey("DeviceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Application");
|
||||
|
||||
b.Navigation("Device");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Playlist", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.DeviceGroup", "DeviceGroup")
|
||||
.WithMany()
|
||||
.HasForeignKey("DeviceGroupId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("DeviceGroup");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.PlaylistItem", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Application", "Application")
|
||||
.WithMany()
|
||||
.HasForeignKey("ApplicationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Playlist", "Playlist")
|
||||
.WithMany("Items")
|
||||
.HasForeignKey("PlaylistId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Application");
|
||||
|
||||
b.Navigation("Playlist");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Application", b =>
|
||||
{
|
||||
b.Navigation("Assignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.Navigation("Assignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceGroup", b =>
|
||||
{
|
||||
b.Navigation("Devices");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Playlist", b =>
|
||||
{
|
||||
b.Navigation("Items");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DRS9.Dashboard.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddAppVersions : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AppVersions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Platform = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
|
||||
Version = table.Column<string>(type: "TEXT", maxLength: 20, nullable: false),
|
||||
VersionName = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
||||
DownloadUrl = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
|
||||
FileSize = table.Column<long>(type: "INTEGER", nullable: true),
|
||||
ChangeLog = table.Column<string>(type: "TEXT", maxLength: 1000, nullable: true),
|
||||
IsForceUpdate = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
IsEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
PublishedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AppVersions", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AppVersions_Platform_Version",
|
||||
table: "AppVersions",
|
||||
columns: new[] { "Platform", "Version" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AppVersions");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,490 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DRS9.Dashboard.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(DashboardDbContext))]
|
||||
partial class DashboardDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.11");
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.AppVersion", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ChangeLog")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DownloadUrl")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<long?>("FileSize")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsForceUpdate")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Platform")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("PublishedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Version")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("VersionName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Platform", "Version");
|
||||
|
||||
b.ToTable("AppVersions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Application", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ContentUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Priority")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ThumbnailUrl")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.ToTable("Applications");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.AuditLog", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Action")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Details")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("EntityId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("EntityType")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("IpAddress")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("AuditLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("ActivatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("AppVersion")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DeviceCode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("DeviceGroupId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("DeviceName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DeviceType")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("LastSeenAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("OsVersion")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DeviceCode")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("DeviceGroupId");
|
||||
|
||||
b.ToTable("Devices");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceAssignment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ApplicationId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("DeviceId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Duration")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Order")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ApplicationId");
|
||||
|
||||
b.HasIndex("DeviceId", "ApplicationId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("DeviceAssignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceGroup", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("DeviceGroups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Playlist", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("DeviceGroupId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("LoopMode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DeviceGroupId");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.ToTable("Playlists");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.PlaylistItem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ApplicationId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Duration")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Order")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("PlaylistId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ScheduleRule")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ApplicationId");
|
||||
|
||||
b.HasIndex("PlaylistId", "Order");
|
||||
|
||||
b.ToTable("PlaylistItems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Role")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Email")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.DeviceGroup", "DeviceGroup")
|
||||
.WithMany("Devices")
|
||||
.HasForeignKey("DeviceGroupId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("DeviceGroup");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceAssignment", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Application", "Application")
|
||||
.WithMany("Assignments")
|
||||
.HasForeignKey("ApplicationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Device", "Device")
|
||||
.WithMany("Assignments")
|
||||
.HasForeignKey("DeviceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Application");
|
||||
|
||||
b.Navigation("Device");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Playlist", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.DeviceGroup", "DeviceGroup")
|
||||
.WithMany()
|
||||
.HasForeignKey("DeviceGroupId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("DeviceGroup");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.PlaylistItem", b =>
|
||||
{
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Application", "Application")
|
||||
.WithMany()
|
||||
.HasForeignKey("ApplicationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DRS9.Dashboard.Domain.Entities.Playlist", "Playlist")
|
||||
.WithMany("Items")
|
||||
.HasForeignKey("PlaylistId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Application");
|
||||
|
||||
b.Navigation("Playlist");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Application", b =>
|
||||
{
|
||||
b.Navigation("Assignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Device", b =>
|
||||
{
|
||||
b.Navigation("Assignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.DeviceGroup", b =>
|
||||
{
|
||||
b.Navigation("Devices");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DRS9.Dashboard.Domain.Entities.Playlist", b =>
|
||||
{
|
||||
b.Navigation("Items");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/DRS9.Dashboard.Server/Components/App.razor
Normal file
21
src/DRS9.Dashboard.Server/Components/App.razor
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<base href="/" />
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css" rel="stylesheet">
|
||||
<link href="/css/app.css" rel="stylesheet" />
|
||||
<link rel="icon" type="image/png" href="/favicon.png" />
|
||||
<HeadOutlet />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<Routes />
|
||||
<script src="_framework/blazor.server.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
63
src/DRS9.Dashboard.Server/Components/Layout/MainLayout.razor
Normal file
63
src/DRS9.Dashboard.Server/Components/Layout/MainLayout.razor
Normal file
@@ -0,0 +1,63 @@
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
<div class="page">
|
||||
<main>
|
||||
<div class="top-row px-4">
|
||||
<h4 class="mb-0">
|
||||
<i class="bi bi-display"></i> DRS9 信息发布系统
|
||||
</h4>
|
||||
<div class="ms-auto">
|
||||
<a href="/swagger" target="_blank" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="bi bi-book"></i> API 文档
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<!-- 侧边导航 -->
|
||||
<nav class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse show">
|
||||
<div class="position-sticky pt-3">
|
||||
<ul class="nav flex-column">
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
|
||||
<i class="bi bi-house-door"></i> 仪表盘
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link" href="devices">
|
||||
<i class="bi bi-pc-display"></i> 设备管理
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link" href="applications">
|
||||
<i class="bi bi-grid"></i> 内容管理
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link" href="batch">
|
||||
<i class="bi bi-collection"></i> 批量操作
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link" href="versions">
|
||||
<i class="bi bi-arrow-repeat"></i> 版本管理
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link" href="guest">
|
||||
<i class="bi bi-link-45deg"></i> 访客链接
|
||||
</NavLink>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||
@Body
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
249
src/DRS9.Dashboard.Server/Components/Pages/Applications.razor
Normal file
249
src/DRS9.Dashboard.Server/Components/Pages/Applications.razor
Normal file
@@ -0,0 +1,249 @@
|
||||
@page "/applications"
|
||||
@rendermode @(new InteractiveServerRenderMode())
|
||||
@inject Services.ApiClientService ApiClient
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<PageTitle>内容管理 - DRS9 信息发布系统</PageTitle>
|
||||
|
||||
<h3 class="mb-4">内容管理</h3>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-grid"></i> 内容列表</span>
|
||||
<button class="btn btn-primary btn-sm" @onclick="ShowAddModal">
|
||||
<i class="bi bi-plus-lg"></i> 添加内容
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (_applications == null)
|
||||
{
|
||||
<div class="text-center py-4">
|
||||
<div class="spinner-border text-primary" role="status"></div>
|
||||
</div>
|
||||
}
|
||||
else if (_applications.Count == 0)
|
||||
{
|
||||
<div class="text-center text-muted py-4">
|
||||
<i class="bi bi-inbox fs-1 d-block mb-3"></i>
|
||||
<p>暂无内容,点击上方按钮添加</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
@foreach (var app in _applications)
|
||||
{
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="card h-100">
|
||||
<div class="card-body">
|
||||
<div class="d-flex align-items-start">
|
||||
<div class="content-icon @GetAppTypeClass(app.Type)">
|
||||
<i class="bi @GetAppIcon(app.Type)"></i>
|
||||
</div>
|
||||
<div class="flex-grow-1">
|
||||
<h6 class="mb-1">@app.Name</h6>
|
||||
<p class="text-muted mb-2 small">@app.Type</p>
|
||||
<p class="mb-2 small">@app.Description</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer d-flex justify-content-end gap-2">
|
||||
<button class="btn btn-sm btn-outline-primary" @onclick="@(() => EditApp(app))">
|
||||
<i class="bi bi-pencil"></i> 编辑
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick="@(() => DeleteApp(app))">
|
||||
<i class="bi bi-trash"></i> 删除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 添加/编辑 Modal -->
|
||||
@if (_showModal)
|
||||
{
|
||||
<div class="modal fade show d-block" style="background-color: rgba(0,0,0,0.5)" tabindex="-1" @onclick="CloseModal">
|
||||
<div class="modal-dialog" @onclick:stopPropagation="true">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">@(_editingApp?.Id == null ? "添加内容" : "编辑内容")</h5>
|
||||
<button type="button" class="btn-close" @onclick="CloseModal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
@_errorMessage
|
||||
</div>
|
||||
}
|
||||
<div class="mb-3">
|
||||
<label class="form-label">内容名称</label>
|
||||
<input type="text" class="form-control" @bind="_appName" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">内容类型</label>
|
||||
<select class="form-select" @bind="_appType" disabled="@(_editingApp != null)">
|
||||
<option value="">请选择...</option>
|
||||
<option value="Dashboard">Dashboard</option>
|
||||
<option value="WebRotator">WebRotator</option>
|
||||
<option value="Image">Image</option>
|
||||
<option value="Video">Video</option>
|
||||
</select>
|
||||
@if (_editingApp != null)
|
||||
{
|
||||
<small class="text-muted">内容类型创建后不可修改</small>
|
||||
}
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">内容 URL</label>
|
||||
<input type="url" class="form-control" @bind="_appContentUrl" placeholder="https://..." />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">描述</label>
|
||||
<textarea class="form-control" @bind="_appDescription" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" @onclick="CloseModal">取消</button>
|
||||
<button type="button" class="btn btn-primary" @onclick="SaveApp">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private List<ApplicationDto> _applications = new();
|
||||
private ApplicationDto? _editingApp;
|
||||
private string _appName = "";
|
||||
private string _appType = "";
|
||||
private string _appContentUrl = "";
|
||||
private string _appDescription = "";
|
||||
private bool _showModal = false;
|
||||
private string _errorMessage = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_applications = await ApiClient.GetApplicationsAsync();
|
||||
}
|
||||
|
||||
private void ShowAddModal()
|
||||
{
|
||||
_editingApp = null;
|
||||
_appName = "";
|
||||
_appType = "";
|
||||
_appContentUrl = "";
|
||||
_appDescription = "";
|
||||
_errorMessage = "";
|
||||
_showModal = true;
|
||||
}
|
||||
|
||||
private void EditApp(ApplicationDto app)
|
||||
{
|
||||
_editingApp = app;
|
||||
_appName = app.Name;
|
||||
_appType = app.Type;
|
||||
_appContentUrl = app.ContentUrl;
|
||||
_appDescription = app.Description ?? "";
|
||||
_errorMessage = "";
|
||||
_showModal = true;
|
||||
}
|
||||
|
||||
private void CloseModal()
|
||||
{
|
||||
_showModal = false;
|
||||
_editingApp = null;
|
||||
_errorMessage = "";
|
||||
}
|
||||
|
||||
private async Task SaveApp()
|
||||
{
|
||||
// Validate inputs
|
||||
if (string.IsNullOrWhiteSpace(_appName))
|
||||
{
|
||||
_errorMessage = "请输入内容名称";
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(_appType))
|
||||
{
|
||||
_errorMessage = "请选择内容类型";
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(_appContentUrl))
|
||||
{
|
||||
_errorMessage = "请输入内容 URL";
|
||||
return;
|
||||
}
|
||||
|
||||
bool success;
|
||||
if (_editingApp == null)
|
||||
{
|
||||
success = await ApiClient.CreateApplicationAsync(new ApplicationCreateRequest
|
||||
{
|
||||
Name = _appName,
|
||||
Type = _appType,
|
||||
ContentUrl = _appContentUrl,
|
||||
Description = _appDescription
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
success = await ApiClient.UpdateApplicationAsync(_editingApp.Id, new ApplicationUpdateRequest
|
||||
{
|
||||
Name = _appName,
|
||||
Description = _appDescription,
|
||||
ContentUrl = _appContentUrl
|
||||
});
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
CloseModal();
|
||||
_applications = await ApiClient.GetApplicationsAsync();
|
||||
await JSRuntime.InvokeVoidAsync("alert", "保存成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorMessage = "保存失败,请检查输入数据或稍后重试";
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteApp(ApplicationDto app)
|
||||
{
|
||||
if (await JSRuntime.InvokeAsync<bool>("confirm", $"确定要删除内容 '{app.Name}' 吗?"))
|
||||
{
|
||||
var success = await ApiClient.DeleteApplicationAsync(app.Id);
|
||||
if (success)
|
||||
{
|
||||
_applications = await ApiClient.GetApplicationsAsync();
|
||||
await JSRuntime.InvokeVoidAsync("alert", "删除成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", "删除失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetAppTypeClass(string type) => type switch
|
||||
{
|
||||
"Dashboard" => "dashboard",
|
||||
"WebRotator" => "web",
|
||||
"Image" => "image",
|
||||
"Video" => "video",
|
||||
_ => ""
|
||||
};
|
||||
|
||||
private string GetAppIcon(string type) => type switch
|
||||
{
|
||||
"Dashboard" => "bi-bar-chart",
|
||||
"WebRotator" => "bi-arrow-repeat",
|
||||
"Image" => "bi-image",
|
||||
"Video" => "bi-play-circle",
|
||||
_ => "bi-file-earmark"
|
||||
};
|
||||
}
|
||||
234
src/DRS9.Dashboard.Server/Components/Pages/Batch.razor
Normal file
234
src/DRS9.Dashboard.Server/Components/Pages/Batch.razor
Normal file
@@ -0,0 +1,234 @@
|
||||
@page "/batch"
|
||||
@rendermode @(new InteractiveServerRenderMode())
|
||||
@inject Services.ApiClientService ApiClient
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<PageTitle>批量操作 - DRS9 信息发布系统</PageTitle>
|
||||
|
||||
<h3 class="mb-4">批量操作</h3>
|
||||
|
||||
<div class="row">
|
||||
<!-- 批量分配内容 -->
|
||||
<div class="col-md-6 mb-4">
|
||||
<div class="card h-100">
|
||||
<div class="card-header">
|
||||
<i class="bi bi-grid"></i> 批量分配内容
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="text-muted">将内容批量分配给多个设备或设备组</p>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">选择设备组</label>
|
||||
<select class="form-select" @bind="@_batchAssignGroupId">
|
||||
<option value="0">选择设备组...</option>
|
||||
@if (_groups != null)
|
||||
{
|
||||
@foreach (var group in _groups)
|
||||
{
|
||||
<option value="@group.Id">@group.Name</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">选择内容</label>
|
||||
<div class="border rounded p-2" style="max-height: 150px; overflow-y: auto;">
|
||||
@if (_applications != null)
|
||||
{
|
||||
@foreach (var app in _applications)
|
||||
{
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input"
|
||||
id="batch-app-@app.Id"
|
||||
@bind="@_selectedAppIds[app.Id]" />
|
||||
<label class="form-check-label" for="batch-app-@app.Id">
|
||||
@app.Name (@app.Type)
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-primary w-100" @onclick="ExecuteBatchAssign">
|
||||
<i class="bi bi-check-lg"></i> 执行分配
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 批量推送 -->
|
||||
<div class="col-md-6 mb-4">
|
||||
<div class="card h-100">
|
||||
<div class="card-header">
|
||||
<i class="bi bi-send"></i> 批量推送命令
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="text-muted">向多个设备发送控制命令</p>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">选择设备</label>
|
||||
<div class="border rounded p-2" style="max-height: 150px; overflow-y: auto;">
|
||||
@if (_devices != null)
|
||||
{
|
||||
@foreach (var device in _devices)
|
||||
{
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input"
|
||||
id="batch-device-@device.Id"
|
||||
@bind="@_selectedDeviceIds[device.Id]" />
|
||||
<label class="form-check-label" for="batch-device-@device.Id">
|
||||
@device.DeviceName
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">推送命令</label>
|
||||
<select class="form-select" @bind="@_batchCommand">
|
||||
<option value="refresh">刷新内容</option>
|
||||
<option value="restart">重启应用</option>
|
||||
<option value="screenshot">获取截图</option>
|
||||
<option value="clear_cache">清除缓存</option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-success w-100" @onclick="ExecuteBatchPush">
|
||||
<i class="bi bi-send"></i> 发送命令
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 批量启用/禁用 -->
|
||||
<div class="col-md-6 mb-4">
|
||||
<div class="card h-100">
|
||||
<div class="card-header">
|
||||
<i class="bi bi-power"></i> 批量启用/禁用
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="text-muted">批量启用或禁用多个设备</p>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">选择设备</label>
|
||||
<div class="border rounded p-2" style="max-height: 150px; overflow-y: auto;">
|
||||
@if (_devices != null)
|
||||
{
|
||||
@foreach (var device in _devices)
|
||||
{
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input"
|
||||
id="toggle-device-@device.Id"
|
||||
@bind="@_toggleDeviceIds[device.Id]" />
|
||||
<label class="form-check-label" for="toggle-device-@device.Id">
|
||||
@device.DeviceName
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group w-100" role="group">
|
||||
<button class="btn btn-success flex-grow-1" @onclick="@(() => ExecuteBatchToggle(true))">
|
||||
<i class="bi bi-check-circle"></i> 批量启用
|
||||
</button>
|
||||
<button class="btn btn-danger flex-grow-1" @onclick="@(() => ExecuteBatchToggle(false))">
|
||||
<i class="bi bi-x-circle"></i> 批量禁用
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<DeviceDto> _devices = new();
|
||||
private List<ApplicationDto> _applications = new();
|
||||
private List<DeviceGroupDto> _groups = new();
|
||||
private Dictionary<int, bool> _selectedAppIds = new();
|
||||
private Dictionary<int, bool> _selectedDeviceIds = new();
|
||||
private Dictionary<int, bool> _toggleDeviceIds = new();
|
||||
private int _batchAssignGroupId = 0;
|
||||
private string _batchCommand = "refresh";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
var devicesTask = ApiClient.GetDevicesAsync();
|
||||
var appsTask = ApiClient.GetApplicationsAsync();
|
||||
var groupsTask = ApiClient.GetDeviceGroupsAsync();
|
||||
|
||||
_devices = await devicesTask;
|
||||
_applications = await appsTask;
|
||||
_groups = await groupsTask;
|
||||
|
||||
_selectedAppIds = _applications.ToDictionary(a => a.Id, _ => false);
|
||||
_selectedDeviceIds = _devices.ToDictionary(d => d.Id, _ => false);
|
||||
_toggleDeviceIds = _devices.ToDictionary(d => d.Id, _ => false);
|
||||
}
|
||||
|
||||
private async Task ExecuteBatchAssign()
|
||||
{
|
||||
var selectedApps = _selectedAppIds.Where(kvp => kvp.Value).Select(kvp => kvp.Key).ToList();
|
||||
|
||||
if (_batchAssignGroupId > 0)
|
||||
{
|
||||
var groupDevices = _devices.Where(d => d.DeviceGroupId == _batchAssignGroupId).Select(d => d.Id).ToList();
|
||||
if (groupDevices.Count == 0 || selectedApps.Count == 0)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", "请选择设备和内容");
|
||||
return;
|
||||
}
|
||||
await ApiClient.BatchAssignContentAsync(new BatchAssignContentRequest
|
||||
{
|
||||
DeviceIds = groupDevices,
|
||||
ApplicationIds = selectedApps
|
||||
});
|
||||
await JSRuntime.InvokeVoidAsync("alert", "批量分配完成");
|
||||
}
|
||||
else
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", "请选择设备组");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ExecuteBatchPush()
|
||||
{
|
||||
var selectedDevices = _selectedDeviceIds.Where(kvp => kvp.Value).Select(kvp => kvp.Key).ToList();
|
||||
|
||||
if (selectedDevices.Count == 0)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", "请选择设备");
|
||||
return;
|
||||
}
|
||||
|
||||
await ApiClient.BatchPushAsync(new BatchPushRequest
|
||||
{
|
||||
DeviceIds = selectedDevices,
|
||||
MessageType = _batchCommand
|
||||
});
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("alert", "命令推送完成");
|
||||
}
|
||||
|
||||
private async Task ExecuteBatchToggle(bool enable)
|
||||
{
|
||||
var selectedDevices = _toggleDeviceIds.Where(kvp => kvp.Value).Select(kvp => kvp.Key).ToList();
|
||||
|
||||
if (selectedDevices.Count == 0)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", "请选择设备");
|
||||
return;
|
||||
}
|
||||
|
||||
await ApiClient.BatchToggleDevicesAsync(new BatchToggleDevicesRequest
|
||||
{
|
||||
DeviceIds = selectedDevices,
|
||||
IsEnabled = enable
|
||||
});
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("alert", $"批量{(enable ? "启用" : "禁用")}完成");
|
||||
await LoadData();
|
||||
}
|
||||
}
|
||||
512
src/DRS9.Dashboard.Server/Components/Pages/Devices.razor
Normal file
512
src/DRS9.Dashboard.Server/Components/Pages/Devices.razor
Normal file
@@ -0,0 +1,512 @@
|
||||
@page "/devices"
|
||||
@rendermode @(new InteractiveServerRenderMode())
|
||||
@inject Services.ApiClientService ApiClient
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<PageTitle>设备管理 - DRS9 信息发布系统</PageTitle>
|
||||
|
||||
<h3 class="mb-4">设备管理</h3>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-pc-display"></i> 设备列表</span>
|
||||
<button class="btn btn-primary btn-sm" @onclick="ShowAddModal">
|
||||
<i class="bi bi-plus-lg"></i> 添加设备
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (_devices == null)
|
||||
{
|
||||
<div class="text-center py-4">
|
||||
<div class="spinner-border text-primary" role="status"></div>
|
||||
</div>
|
||||
}
|
||||
else if (_devices.Count == 0)
|
||||
{
|
||||
<div class="text-center text-muted py-4">
|
||||
<i class="bi bi-inbox fs-1 d-block mb-3"></i>
|
||||
<p>暂无设备,点击上方按钮添加</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>设备名称</th>
|
||||
<th>设备编码</th>
|
||||
<th>分组</th>
|
||||
<th>状态</th>
|
||||
<th>最后在线</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var device in _devices)
|
||||
{
|
||||
<tr>
|
||||
<td>@device.Id</td>
|
||||
<td>@device.DeviceName</td>
|
||||
<td><code>@device.DeviceCode</code></td>
|
||||
<td>@device.DeviceGroupName</td>
|
||||
<td>
|
||||
@if (device.IsEnabled)
|
||||
{
|
||||
<span class="badge bg-success">启用</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-secondary">禁用</span>
|
||||
}
|
||||
</td>
|
||||
<td>@device.LastSeenAt?.ToString("MM-dd HH:mm") ?? "从未"</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-outline-primary" @onclick="@(() => EditDevice(device))">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-info" @onclick="@(() => AssignContent(device))">
|
||||
<i class="bi bi-grid"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-success" @onclick="@(() => PushToDevice(device))">
|
||||
<i class="bi bi-arrow-repeat"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick="@(() => DeleteDevice(device))">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 设备分组 -->
|
||||
<div class="row mt-3">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-folder"></i> 设备分组</span>
|
||||
<button class="btn btn-primary btn-sm" @onclick="ShowAddGroupModal">
|
||||
<i class="bi bi-plus-lg"></i> 添加分组
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (_groups == null)
|
||||
{
|
||||
<div class="text-center py-3">
|
||||
<div class="spinner-border spinner-border-sm text-primary"></div>
|
||||
</div>
|
||||
}
|
||||
else if (_groups.Count == 0)
|
||||
{
|
||||
<p class="text-muted text-center mb-0">暂无分组</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="d-flex flex-wrap gap-2">
|
||||
@foreach (var group in _groups)
|
||||
{
|
||||
<div class="card" style="min-width: 200px;">
|
||||
<div class="card-body d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h6 class="mb-0">@group.Name</h6>
|
||||
<small class="text-muted">@group.Description</small>
|
||||
</div>
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick="@(() => DeleteGroup(group))">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 添加/编辑设备 Modal -->
|
||||
@if (_showModal)
|
||||
{
|
||||
<div class="modal fade show d-block" style="background-color: rgba(0,0,0,0.5)" tabindex="-1" @onclick="CloseModal">
|
||||
<div class="modal-dialog" @onclick:stopPropagation="true">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">@(_editingDevice?.Id == null ? "添加设备" : "编辑设备")</h5>
|
||||
<button type="button" class="btn-close" @onclick="CloseModal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
@_errorMessage
|
||||
</div>
|
||||
}
|
||||
<form id="deviceForm">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">设备名称</label>
|
||||
<input type="text" class="form-control" @bind="_editDeviceName" required />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">设备编码</label>
|
||||
<input type="text" class="form-control" @bind="_editDeviceCode" required />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">分组</label>
|
||||
<select class="form-select" @bind="_editGroupId">
|
||||
<option value="0">无分组</option>
|
||||
@if (_groups != null)
|
||||
{
|
||||
@foreach (var group in _groups)
|
||||
{
|
||||
<option value="@group.Id">@group.Name</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3 form-check">
|
||||
<input type="checkbox" class="form-check-input" @bind="_editIsEnabled" />
|
||||
<label class="form-check-label">启用设备</label>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" @onclick="CloseModal">取消</button>
|
||||
<button type="button" class="btn btn-primary" @onclick="SaveDevice">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- 添加分组 Modal -->
|
||||
@if (_showGroupModal)
|
||||
{
|
||||
<div class="modal fade show d-block" style="background-color: rgba(0,0,0,0.5)" tabindex="-1" @onclick="CloseGroupModal">
|
||||
<div class="modal-dialog" @onclick:stopPropagation="true">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">添加分组</h5>
|
||||
<button type="button" class="btn-close" @onclick="CloseGroupModal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
@_errorMessage
|
||||
</div>
|
||||
}
|
||||
<div class="mb-3">
|
||||
<label class="form-label">分组名称</label>
|
||||
<input type="text" class="form-control" @bind="_newGroupName" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">描述</label>
|
||||
<input type="text" class="form-control" @bind="_newGroupDesc" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" @onclick="CloseGroupModal">取消</button>
|
||||
<button type="button" class="btn btn-primary" @onclick="SaveGroup">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- 分配内容 Modal -->
|
||||
@if (_assigningDevice != null)
|
||||
{
|
||||
<div class="modal fade show d-block" style="background-color: rgba(0,0,0,0.5)" tabindex="-1" @onclick="CloseAssignModal">
|
||||
<div class="modal-dialog modal-lg" @onclick:stopPropagation="true">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">分配内容 - @_assigningDevice.DeviceName</h5>
|
||||
<button type="button" class="btn-close" @onclick="CloseAssignModal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@if (_applications == null)
|
||||
{
|
||||
<div class="text-center py-3">
|
||||
<div class="spinner-border spinner-border-sm text-primary"></div>
|
||||
</div>
|
||||
}
|
||||
else if (_applications.Count == 0)
|
||||
{
|
||||
<p class="text-muted">暂无可用内容</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
@foreach (var app in _applications)
|
||||
{
|
||||
<div class="col-md-4 mb-2">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input"
|
||||
id="app-@app.Id"
|
||||
@bind="@_selectedAppIds[app.Id]" />
|
||||
<label class="form-check-label" for="app-@app.Id">
|
||||
@app.Name
|
||||
</label>
|
||||
<br />
|
||||
<small class="text-muted">@app.Type</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" @onclick="CloseAssignModal">取消</button>
|
||||
<button type="button" class="btn btn-primary" @onclick="SaveAssignment">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private List<DeviceDto> _devices = new();
|
||||
private List<DeviceGroupDto> _groups = new();
|
||||
private List<ApplicationDto> _applications = new();
|
||||
private DeviceDto? _editingDevice;
|
||||
private DeviceDto? _assigningDevice;
|
||||
private Dictionary<int, bool> _selectedAppIds = new();
|
||||
private string _newGroupName = "";
|
||||
private string _newGroupDesc = "";
|
||||
private string _editDeviceName = "";
|
||||
private string _editDeviceCode = "";
|
||||
private int _editGroupId = 0;
|
||||
private bool _editIsEnabled = true;
|
||||
private bool _showModal = false;
|
||||
private bool _showGroupModal = false;
|
||||
private string _errorMessage = "";
|
||||
private string _successMessage = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
var devicesTask = ApiClient.GetDevicesAsync();
|
||||
var groupsTask = ApiClient.GetDeviceGroupsAsync();
|
||||
var appsTask = ApiClient.GetApplicationsAsync();
|
||||
|
||||
_devices = await devicesTask;
|
||||
_groups = await groupsTask;
|
||||
_applications = await appsTask;
|
||||
}
|
||||
|
||||
private void ShowAddModal()
|
||||
{
|
||||
_editingDevice = null;
|
||||
_editDeviceName = "";
|
||||
_editDeviceCode = "";
|
||||
_editGroupId = 0;
|
||||
_editIsEnabled = true;
|
||||
_errorMessage = "";
|
||||
_showModal = true;
|
||||
}
|
||||
|
||||
private void EditDevice(DeviceDto device)
|
||||
{
|
||||
_editingDevice = device;
|
||||
_editDeviceName = device.DeviceName;
|
||||
_editDeviceCode = device.DeviceCode;
|
||||
_editGroupId = device.DeviceGroupId ?? 0;
|
||||
_editIsEnabled = device.IsEnabled;
|
||||
_errorMessage = "";
|
||||
_showModal = true;
|
||||
}
|
||||
|
||||
private void CloseModal()
|
||||
{
|
||||
_showModal = false;
|
||||
_editingDevice = null;
|
||||
_errorMessage = "";
|
||||
}
|
||||
|
||||
private async Task SaveDevice()
|
||||
{
|
||||
// Validate inputs
|
||||
if (string.IsNullOrWhiteSpace(_editDeviceName))
|
||||
{
|
||||
_errorMessage = "请输入设备名称";
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(_editDeviceCode))
|
||||
{
|
||||
_errorMessage = "请输入设备编码";
|
||||
return;
|
||||
}
|
||||
|
||||
bool success;
|
||||
if (_editingDevice == null)
|
||||
{
|
||||
success = await ApiClient.CreateDeviceAsync(new DeviceCreateRequest
|
||||
{
|
||||
DeviceName = _editDeviceName,
|
||||
DeviceCode = _editDeviceCode,
|
||||
DeviceGroupId = _editGroupId > 0 ? _editGroupId : null
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
success = await ApiClient.UpdateDeviceAsync(_editingDevice.Id, new DeviceUpdateRequest
|
||||
{
|
||||
DeviceName = _editDeviceName,
|
||||
DeviceGroupId = _editGroupId > 0 ? _editGroupId : null,
|
||||
IsEnabled = _editIsEnabled
|
||||
});
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
CloseModal();
|
||||
await LoadData();
|
||||
await JSRuntime.InvokeVoidAsync("alert", "保存成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorMessage = "保存失败,请检查输入数据或稍后重试";
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteDevice(DeviceDto device)
|
||||
{
|
||||
if (await JSRuntime.InvokeAsync<bool>("confirm", $"确定要删除设备 '{device.DeviceName}' 吗?"))
|
||||
{
|
||||
var success = await ApiClient.DeleteDeviceAsync(device.Id);
|
||||
if (success)
|
||||
{
|
||||
await LoadData();
|
||||
await JSRuntime.InvokeVoidAsync("alert", "删除成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", "删除失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PushToDevice(DeviceDto device)
|
||||
{
|
||||
var success = await ApiClient.PushToDeviceAsync(device.Id, "refresh");
|
||||
if (success)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", $"已向设备 '{device.DeviceName}' 发送刷新命令");
|
||||
}
|
||||
else
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", "发送命令失败,设备可能不在线");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AssignContent(DeviceDto device)
|
||||
{
|
||||
_assigningDevice = device;
|
||||
_selectedAppIds = _applications.ToDictionary(a => a.Id, _ => false);
|
||||
await LoadAssignedContent(device.Id);
|
||||
}
|
||||
|
||||
private async Task LoadAssignedContent(int deviceId)
|
||||
{
|
||||
// TODO: 从 API 获取已分配的内容
|
||||
}
|
||||
|
||||
private void CloseAssignModal()
|
||||
{
|
||||
_assigningDevice = null;
|
||||
_selectedAppIds.Clear();
|
||||
}
|
||||
|
||||
private async Task SaveAssignment()
|
||||
{
|
||||
if (_assigningDevice != null)
|
||||
{
|
||||
var selectedIds = _selectedAppIds.Where(kvp => kvp.Value).Select(kvp => kvp.Key).ToList();
|
||||
var success = await ApiClient.AssignContentAsync(_assigningDevice.Id, selectedIds);
|
||||
if (success)
|
||||
{
|
||||
CloseAssignModal();
|
||||
await JSRuntime.InvokeVoidAsync("alert", "内容分配成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", "内容分配失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowAddGroupModal()
|
||||
{
|
||||
_newGroupName = "";
|
||||
_newGroupDesc = "";
|
||||
_errorMessage = "";
|
||||
_showGroupModal = true;
|
||||
}
|
||||
|
||||
private void CloseGroupModal()
|
||||
{
|
||||
_showGroupModal = false;
|
||||
_errorMessage = "";
|
||||
}
|
||||
|
||||
private async Task SaveGroup()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_newGroupName))
|
||||
{
|
||||
_errorMessage = "请输入分组名称";
|
||||
return;
|
||||
}
|
||||
|
||||
var success = await ApiClient.CreateDeviceGroupAsync(new DeviceGroupCreateRequest
|
||||
{
|
||||
Name = _newGroupName,
|
||||
Description = _newGroupDesc
|
||||
});
|
||||
|
||||
if (success)
|
||||
{
|
||||
CloseGroupModal();
|
||||
await LoadData();
|
||||
await JSRuntime.InvokeVoidAsync("alert", "分组创建成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorMessage = "创建失败,请检查输入或稍后重试";
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteGroup(DeviceGroupDto group)
|
||||
{
|
||||
if (await JSRuntime.InvokeAsync<bool>("confirm", $"确定要删除分组 '{group.Name}' 吗?"))
|
||||
{
|
||||
var success = await ApiClient.DeleteDeviceGroupAsync(group.Id);
|
||||
if (success)
|
||||
{
|
||||
await LoadData();
|
||||
await JSRuntime.InvokeVoidAsync("alert", "删除成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", "删除失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
167
src/DRS9.Dashboard.Server/Components/Pages/Guest.razor
Normal file
167
src/DRS9.Dashboard.Server/Components/Pages/Guest.razor
Normal file
@@ -0,0 +1,167 @@
|
||||
@page "/guest"
|
||||
@rendermode @(new InteractiveServerRenderMode())
|
||||
@inject Services.ApiClientService ApiClient
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<PageTitle>访客链接 - DRS9 信息发布系统</PageTitle>
|
||||
|
||||
<h3 class="mb-4">访客访问链接</h3>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<!-- 创建访客链接 -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
<i class="bi bi-link-45deg"></i> 创建临时访问链接
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="text-muted">生成临时访问链接,允许用户在浏览器中查看设备内容,无需登录。</p>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">关联设备</label>
|
||||
<select class="form-select" @bind="@_selectedDeviceId">
|
||||
<option value="0">无(通用访客模式)</option>
|
||||
@if (_devices != null)
|
||||
{
|
||||
@foreach (var device in _devices)
|
||||
{
|
||||
<option value="@device.Id">@device.DeviceName (@device.DeviceCode)</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
<small class="text-muted">选择设备后,访客将看到该设备分配的内容</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">有效时长</label>
|
||||
<select class="form-select" @bind="@_validityMinutes">
|
||||
<option value="30">30 分钟</option>
|
||||
<option value="60" selected>1 小时</option>
|
||||
<option value="120">2 小时</option>
|
||||
<option value="360">6 小时</option>
|
||||
<option value="720">12 小时</option>
|
||||
<option value="1440">24 小时</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">描述(可选)</label>
|
||||
<input type="text" class="form-control" @bind="@_description" placeholder="例如:会议展示、临时访问" />
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary w-100" @onclick="CreateGuestLink">
|
||||
<i class="bi bi-plus-lg"></i> 生成访客链接
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<!-- 生成的链接 -->
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-list-check"></i> 已生成的链接</span>
|
||||
<button class="btn btn-sm btn-outline-secondary" @onclick="LoadData">
|
||||
<i class="bi bi-arrow-clockwise"></i> 刷新
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (_generatedLinks.Count == 0)
|
||||
{
|
||||
<p class="text-muted text-center mb-0">暂无生成的链接</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="list-group">
|
||||
@foreach (var link in _generatedLinks)
|
||||
{
|
||||
<div class="list-group-item">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div style="flex: 1;">
|
||||
<h6 class="mb-1">@link.Description</h6>
|
||||
<p class="mb-1">
|
||||
<small class="text-muted">
|
||||
设备: @(link.DeviceId > 0 ? $"设备 {link.DeviceId}" : "通用")
|
||||
| 过期时间: @link.ExpiresAt?.ToString("MM-dd HH:mm")
|
||||
</small>
|
||||
</p>
|
||||
<div class="input-group input-group-sm mt-2">
|
||||
<input type="text" class="form-control" readonly value="@link.FullUrl" />
|
||||
<button class="btn btn-outline-secondary" type="button" @onclick="@(() => CopyLink(link.FullUrl))">
|
||||
<i class="bi bi-clipboard"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-end ms-2">
|
||||
@if (link.ExpiresAt > DateTime.UtcNow)
|
||||
{
|
||||
<span class="badge bg-success">有效</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-secondary">已过期</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<DeviceDto> _devices = new();
|
||||
private List<(string Description, int DeviceId, string FullUrl, DateTime? ExpiresAt)> _generatedLinks = new();
|
||||
private int _selectedDeviceId = 0;
|
||||
private int _validityMinutes = 60;
|
||||
private string _description = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_devices = await ApiClient.GetDevicesAsync();
|
||||
}
|
||||
|
||||
private async Task CreateGuestLink()
|
||||
{
|
||||
var result = await ApiClient.CreateGuestAccessAsync(new GuestAccessCreateRequest
|
||||
{
|
||||
DeviceId = _selectedDeviceId > 0 ? _selectedDeviceId : null,
|
||||
ValidityMinutes = _validityMinutes,
|
||||
Description = string.IsNullOrWhiteSpace(_description) ? null : _description
|
||||
});
|
||||
|
||||
if (result != null && result.Success)
|
||||
{
|
||||
var fullUrl = $"{NavigationManager.BaseUri.TrimEnd('/')}{result.AccessUrl}";
|
||||
_generatedLinks.Insert(0, (
|
||||
_description ?? "临时访问",
|
||||
_selectedDeviceId,
|
||||
fullUrl,
|
||||
result.ExpiresAt
|
||||
));
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("alert", $"访客链接已生成!\n\n访问地址: {fullUrl}");
|
||||
|
||||
_description = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("alert", "生成访客链接失败");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CopyLink(string url)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", url);
|
||||
await JSRuntime.InvokeVoidAsync("alert", "链接已复制到剪贴板");
|
||||
}
|
||||
}
|
||||
113
src/DRS9.Dashboard.Server/Components/Pages/Home.razor
Normal file
113
src/DRS9.Dashboard.Server/Components/Pages/Home.razor
Normal file
@@ -0,0 +1,113 @@
|
||||
@page "/"
|
||||
@rendermode @(new InteractiveServerRenderMode())
|
||||
@inject Services.ApiClientService ApiClient
|
||||
|
||||
<PageTitle>仪表盘 - DRS9 信息发布系统</PageTitle>
|
||||
|
||||
<h3 class="mb-4">系统概览</h3>
|
||||
|
||||
@if (_stats == null)
|
||||
{
|
||||
<div class="text-center py-5">
|
||||
<div class="spinner-border text-primary" role="status">
|
||||
<span class="visually-hidden">加载中...</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="stat-card">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h3>@_stats.TotalDevices</h3>
|
||||
<p>设备总数</p>
|
||||
</div>
|
||||
<i class="bi bi-pc-display fs-1 opacity-50"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="stat-card success">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h3>@_stats.OnlineDevices</h3>
|
||||
<p>在线设备</p>
|
||||
</div>
|
||||
<i class="bi bi-wifi fs-1 opacity-50"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="stat-card info">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h3>@_stats.TotalApplications</h3>
|
||||
<p>内容数量</p>
|
||||
</div>
|
||||
<i class="bi bi-grid fs-1 opacity-50"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-lightning-charge"></i> 快速操作</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="d-grid gap-2">
|
||||
<a href="devices" class="btn btn-outline-primary text-start">
|
||||
<i class="bi bi-plus-circle"></i> 添加新设备
|
||||
</a>
|
||||
<a href="applications" class="btn btn-outline-success text-start">
|
||||
<i class="bi bi-file-plus"></i> 创建新内容
|
||||
</a>
|
||||
<a href="batch" class="btn btn-outline-warning text-start">
|
||||
<i class="bi bi-collection"></i> 批量分配内容
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<i class="bi bi-info-circle"></i> 系统信息
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-sm">
|
||||
<tr>
|
||||
<th>系统名称</th>
|
||||
<td>DRS9 信息发布系统</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>版本</th>
|
||||
<td>v1.0.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>API 文档</th>
|
||||
<td><a href="/swagger" target="_blank">Swagger UI</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>WebSocket</th>
|
||||
<td><code>ws://localhost:5264/ws</code></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private DashboardStatsDto? _stats;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_stats = await ApiClient.GetStatsAsync();
|
||||
}
|
||||
}
|
||||
161
src/DRS9.Dashboard.Server/Components/Pages/Versions.razor
Normal file
161
src/DRS9.Dashboard.Server/Components/Pages/Versions.razor
Normal file
@@ -0,0 +1,161 @@
|
||||
@page "/versions"
|
||||
@rendermode @(new InteractiveServerRenderMode())
|
||||
@inject Services.ApiClientService ApiClient
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<PageTitle>版本管理 - DRS9 信息发布系统</PageTitle>
|
||||
|
||||
<h3 class="mb-4">版本管理 (OTA)</h3>
|
||||
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-arrow-repeat"></i> 版本列表</span>
|
||||
<button class="btn btn-primary btn-sm" @onclick="ShowAddModal">
|
||||
<i class="bi bi-plus-lg"></i> 添加版本
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (_versions == null)
|
||||
{
|
||||
<div class="text-center py-4">
|
||||
<div class="spinner-border text-primary" role="status"></div>
|
||||
</div>
|
||||
}
|
||||
else if (_versions.Count == 0)
|
||||
{
|
||||
<div class="text-center text-muted py-4">
|
||||
<i class="bi bi-inbox fs-1 d-block mb-3"></i>
|
||||
<p>暂无版本记录</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>平台</th>
|
||||
<th>版本号</th>
|
||||
<th>版本名称</th>
|
||||
<th>下载地址</th>
|
||||
<th>大小</th>
|
||||
<th>强制更新</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var version in _versions)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<span class="badge @GetPlatformBadgeClass(version.Platform)">
|
||||
@version.Platform
|
||||
</span>
|
||||
</td>
|
||||
<td><code>@version.Version</code></td>
|
||||
<td>@version.VersionName</td>
|
||||
<td>
|
||||
<a href="@version.DownloadUrl" target="_blank" class="text-truncate d-inline-block" style="max-width: 200px;">
|
||||
@version.DownloadUrl
|
||||
</a>
|
||||
</td>
|
||||
<td>@(version.FileSize.HasValue ? $"{version.FileSize / 1024.0 / 1024.0:F2} MB" : "-")</td>
|
||||
<td>
|
||||
@if (version.IsForceUpdate)
|
||||
{
|
||||
<span class="badge bg-danger">是</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-secondary">否</span>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@if (version.PublishedAt.HasValue)
|
||||
{
|
||||
<span class="badge bg-success">已发布</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-warning text-dark">草稿</span>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@if (version.PublishedAt.HasValue)
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-success" @onclick="@(() => PushUpdate(version))" disabled>
|
||||
<i class="bi bi-check-lg"></i> 已推送
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-success" @onclick="@(() => PushUpdate(version))">
|
||||
<i class="bi bi-send"></i> 推送更新
|
||||
</button>
|
||||
}
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick="@(() => DeleteVersion(version))">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<AppVersionDto> _versions = new();
|
||||
private bool _showModal = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_versions = await ApiClient.GetVersionsAsync();
|
||||
}
|
||||
|
||||
private void ShowAddModal()
|
||||
{
|
||||
_showModal = true;
|
||||
}
|
||||
|
||||
private void CloseModal()
|
||||
{
|
||||
_showModal = false;
|
||||
}
|
||||
|
||||
private async Task PushUpdate(AppVersionDto version)
|
||||
{
|
||||
if (await JSRuntime.InvokeAsync<bool>("confirm", $"确定要向所有设备推送版本 {version.Version} 的更新通知吗?"))
|
||||
{
|
||||
await ApiClient.PushUpdateAsync(version.Id);
|
||||
version.PublishedAt = DateTime.UtcNow;
|
||||
await JSRuntime.InvokeVoidAsync("alert", "更新通知已推送");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteVersion(AppVersionDto version)
|
||||
{
|
||||
if (await JSRuntime.InvokeAsync<bool>("confirm", $"确定要删除版本 {version.Version} 吗?"))
|
||||
{
|
||||
await ApiClient.DeleteVersionAsync(version.Id);
|
||||
_versions = await ApiClient.GetVersionsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetPlatformBadgeClass(string platform) => platform switch
|
||||
{
|
||||
"android" => "bg-success",
|
||||
"ios" => "bg-primary",
|
||||
"windows" => "bg-info",
|
||||
"macos" => "bg-secondary",
|
||||
"linux" => "bg-warning text-dark",
|
||||
_ => "bg-secondary"
|
||||
};
|
||||
}
|
||||
12
src/DRS9.Dashboard.Server/Components/Routes.razor
Normal file
12
src/DRS9.Dashboard.Server/Components/Routes.razor
Normal file
@@ -0,0 +1,12 @@
|
||||
<Router AppAssembly="@typeof(App).Assembly">
|
||||
<Found Context="routeData">
|
||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(DRS9.Dashboard.Server.Components.Layout.MainLayout)" />
|
||||
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||
</Found>
|
||||
<NotFound>
|
||||
<PageTitle>Not found</PageTitle>
|
||||
<LayoutView Layout="@typeof(DRS9.Dashboard.Server.Components.Layout.MainLayout)">
|
||||
<p role="alert">抱歉,未找到该页面。</p>
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
||||
10
src/DRS9.Dashboard.Server/Components/_Imports.razor
Normal file
10
src/DRS9.Dashboard.Server/Components/_Imports.razor
Normal file
@@ -0,0 +1,10 @@
|
||||
@using System.Net.Http
|
||||
@using System.Net.Http.Json
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||
@using Microsoft.JSInterop
|
||||
@using DRS9.Dashboard.Server.Components
|
||||
@using DRS9.Dashboard.Application.DTOs
|
||||
@using DRS9.Dashboard.Server.Services
|
||||
@@ -0,0 +1,98 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Application.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DRS9.Dashboard.Server.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/versions")]
|
||||
// [Authorize] - 暂时禁用认证以便测试
|
||||
public class AppVersionsController : ControllerBase
|
||||
{
|
||||
private readonly AppVersionService _appVersionService;
|
||||
private readonly ILogger<AppVersionsController> _logger;
|
||||
|
||||
public AppVersionsController(AppVersionService appVersionService, ILogger<AppVersionsController> logger)
|
||||
{
|
||||
_appVersionService = appVersionService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有版本
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<List<AppVersionDto>>> GetAll()
|
||||
{
|
||||
var result = await _appVersionService.GetAllAsync();
|
||||
return Ok(new { success = true, data = result });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建新版本
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<object>> Create([FromBody] AppVersionCreateRequest request)
|
||||
{
|
||||
var result = await _appVersionService.CreateAsync(request);
|
||||
if (result == null)
|
||||
{
|
||||
return BadRequest(new { success = false, message = "创建失败" });
|
||||
}
|
||||
_logger.LogInformation("App version created: {Platform} {Version}", request.Platform, request.Version);
|
||||
return Ok(new { success = true, data = result, message = "创建成功" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除版本
|
||||
/// </summary>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult> Delete(int id)
|
||||
{
|
||||
var success = await _appVersionService.DeleteAsync(id);
|
||||
if (!success)
|
||||
{
|
||||
return NotFound(new { success = false, message = "版本不存在" });
|
||||
}
|
||||
_logger.LogInformation("App version deleted: {Id}", id);
|
||||
return Ok(new { success = true, message = "删除成功" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 推送升级通知
|
||||
/// </summary>
|
||||
[HttpPost("{id}/push-notification")]
|
||||
public async Task<ActionResult> PushNotification(int id, [FromQuery] string? platform = null)
|
||||
{
|
||||
var success = await _appVersionService.PushUpdateNotificationAsync(id, platform);
|
||||
if (!success)
|
||||
{
|
||||
return NotFound(new { success = false, message = "版本不存在" });
|
||||
}
|
||||
return Ok(new { success = true, message = "通知已推送" });
|
||||
}
|
||||
}
|
||||
|
||||
// 设备端版本检查控制器
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class VersionsController : ControllerBase
|
||||
{
|
||||
private readonly AppVersionService _appVersionService;
|
||||
|
||||
public VersionsController(AppVersionService appVersionService)
|
||||
{
|
||||
_appVersionService = appVersionService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查版本更新
|
||||
/// </summary>
|
||||
[HttpPost("check")]
|
||||
public async Task<ActionResult<CheckVersionResponse>> CheckVersion([FromBody] CheckVersionRequest request)
|
||||
{
|
||||
var result = await _appVersionService.CheckVersionAsync(request.Platform, request.CurrentVersion);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Application.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DRS9.Dashboard.Server.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/[controller]")]
|
||||
// [Authorize] - 暂时禁用认证以便测试 // TODO: 后续添加管理员角色验证
|
||||
public class ApplicationsController : ControllerBase
|
||||
{
|
||||
private readonly ApplicationService _applicationService;
|
||||
private readonly ILogger<ApplicationsController> _logger;
|
||||
|
||||
public ApplicationsController(ApplicationService applicationService, ILogger<ApplicationsController> logger)
|
||||
{
|
||||
_applicationService = applicationService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有应用
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<ApplicationListResponse>> GetAll()
|
||||
{
|
||||
var result = await _applicationService.GetAllAsync();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取应用详情
|
||||
/// </summary>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<ApplicationResponse>> GetById(int id)
|
||||
{
|
||||
var result = await _applicationService.GetByIdAsync(id);
|
||||
if (result == null || !result.Success)
|
||||
{
|
||||
return NotFound(new { success = false, message = "应用不存在" });
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建新应用
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<ApplicationResponse>> Create([FromBody] ApplicationCreateRequest request)
|
||||
{
|
||||
var result = await _applicationService.CreateAsync(request);
|
||||
_logger.LogInformation("Application created: {Name}", request.Name);
|
||||
return CreatedAtAction(nameof(GetById), new { id = result.Data?.Id }, result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新应用
|
||||
/// </summary>
|
||||
[HttpPut("{id}")]
|
||||
public async Task<ActionResult<ApplicationResponse>> Update(int id, [FromBody] ApplicationUpdateRequest request)
|
||||
{
|
||||
var result = await _applicationService.UpdateAsync(id, request);
|
||||
if (result == null || !result.Success)
|
||||
{
|
||||
return NotFound(new { success = false, message = "应用不存在" });
|
||||
}
|
||||
_logger.LogInformation("Application updated: {Id}", id);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除应用
|
||||
/// </summary>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult> Delete(int id)
|
||||
{
|
||||
var success = await _applicationService.DeleteAsync(id);
|
||||
if (!success)
|
||||
{
|
||||
return NotFound(new { success = false, message = "应用不存在" });
|
||||
}
|
||||
_logger.LogInformation("Application deleted: {Id}", id);
|
||||
return Ok(new { success = true, message = "删除成功" });
|
||||
}
|
||||
}
|
||||
128
src/DRS9.Dashboard.Server/Controllers/DevicesController.cs
Normal file
128
src/DRS9.Dashboard.Server/Controllers/DevicesController.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Application.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DRS9.Dashboard.Server.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DevicesController : ControllerBase
|
||||
{
|
||||
private readonly DeviceService _deviceService;
|
||||
private readonly DeviceManagementService _deviceManagementService;
|
||||
private readonly PlaylistService _playlistService;
|
||||
private readonly ILogger<DevicesController> _logger;
|
||||
|
||||
public DevicesController(DeviceService deviceService, DeviceManagementService deviceManagementService, PlaylistService playlistService, ILogger<DevicesController> logger)
|
||||
{
|
||||
_deviceService = deviceService;
|
||||
_deviceManagementService = deviceManagementService;
|
||||
_playlistService = playlistService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设备注册 - 使用设备码激活设备
|
||||
/// </summary>
|
||||
[HttpPost("register")]
|
||||
public async Task<ActionResult<DeviceRegisterResponse>> Register([FromBody] DeviceRegisterRequest request)
|
||||
{
|
||||
_logger.LogInformation("Device registration attempt: {DeviceCode}", request.DeviceCode);
|
||||
|
||||
var result = await _deviceService.RegisterAsync(request);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
_logger.LogWarning("Device registration failed: {DeviceCode} - {Message}", request.DeviceCode, result.Message);
|
||||
return BadRequest(result);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Device registered successfully: {DeviceCode}", request.DeviceCode);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新设备心跳时间
|
||||
/// </summary>
|
||||
[HttpPost("heartbeat")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Heartbeat()
|
||||
{
|
||||
var deviceIdClaim = User.FindFirst("deviceId")?.Value;
|
||||
if (int.TryParse(deviceIdClaim, out var deviceId))
|
||||
{
|
||||
await _deviceService.UpdateLastSeenAsync(deviceId);
|
||||
return Ok(new { success = true });
|
||||
}
|
||||
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取设备信息
|
||||
/// </summary>
|
||||
[HttpGet("info")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> GetInfo()
|
||||
{
|
||||
var deviceIdClaim = User.FindFirst("deviceId")?.Value;
|
||||
if (int.TryParse(deviceIdClaim, out var deviceId))
|
||||
{
|
||||
var device = await _deviceService.GetDeviceAsync(deviceId);
|
||||
if (device == null)
|
||||
{
|
||||
return NotFound(new { success = false, message = "设备不存在" });
|
||||
}
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
success = true,
|
||||
data = new
|
||||
{
|
||||
id = device.Id,
|
||||
deviceCode = device.DeviceCode,
|
||||
deviceName = device.DeviceName,
|
||||
deviceType = device.DeviceType,
|
||||
isEnabled = device.IsEnabled
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取设备分配的内容
|
||||
/// </summary>
|
||||
[HttpGet("content")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> GetContent()
|
||||
{
|
||||
var deviceIdClaim = User.FindFirst("deviceId")?.Value;
|
||||
if (int.TryParse(deviceIdClaim, out var deviceId))
|
||||
{
|
||||
var result = await _deviceManagementService.GetDeviceContentAsync(deviceId);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取设备播放列表(基于内容编排)
|
||||
/// </summary>
|
||||
[HttpGet("playlist")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> GetPlaylist()
|
||||
{
|
||||
var deviceIdClaim = User.FindFirst("deviceId")?.Value;
|
||||
if (int.TryParse(deviceIdClaim, out var deviceId))
|
||||
{
|
||||
var result = await _playlistService.GetDevicePlaylistAsync(deviceId);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Application.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DRS9.Dashboard.Server.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/devices")]
|
||||
// [Authorize] - 暂时禁用认证以便测试 // TODO: 后续添加管理员角色验证
|
||||
public class DevicesManagementController : ControllerBase
|
||||
{
|
||||
private readonly DeviceManagementService _deviceManagementService;
|
||||
private readonly DashboardWebSocketManager _wsManager;
|
||||
private readonly ILogger<DevicesManagementController> _logger;
|
||||
|
||||
public DevicesManagementController(
|
||||
DeviceManagementService deviceManagementService,
|
||||
DashboardWebSocketManager wsManager,
|
||||
ILogger<DevicesManagementController> logger)
|
||||
{
|
||||
_deviceManagementService = deviceManagementService;
|
||||
_wsManager = wsManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// ===== 设备管理 =====
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有设备
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<DeviceListResponse>> GetAll()
|
||||
{
|
||||
var result = await _deviceManagementService.GetAllDevicesAsync();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取在线设备
|
||||
/// </summary>
|
||||
[HttpGet("online")]
|
||||
public async Task<ActionResult<DeviceListResponse>> GetOnline()
|
||||
{
|
||||
var result = await _deviceManagementService.GetOnlineDevicesAsync();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取设备详情
|
||||
/// </summary>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<DeviceDto>> GetById(int id)
|
||||
{
|
||||
var result = await _deviceManagementService.GetDeviceByIdAsync(id);
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound(new { success = false, message = "设备不存在" });
|
||||
}
|
||||
return Ok(new { success = true, data = result });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建设备(生成设备码)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<object>> Create([FromBody] DeviceCreateRequest request)
|
||||
{
|
||||
var result = await _deviceManagementService.CreateDeviceAsync(request);
|
||||
if (result == null)
|
||||
{
|
||||
return BadRequest(new { success = false, message = "设备码已存在" });
|
||||
}
|
||||
_logger.LogInformation("Device created: {DeviceCode}", request.DeviceCode);
|
||||
return Ok(new { success = true, data = result, message = "创建成功" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新设备
|
||||
/// </summary>
|
||||
[HttpPut("{id}")]
|
||||
public async Task<ActionResult<object>> Update(int id, [FromBody] DeviceUpdateRequest request)
|
||||
{
|
||||
var result = await _deviceManagementService.UpdateDeviceAsync(id, request);
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound(new { success = false, message = "设备不存在" });
|
||||
}
|
||||
_logger.LogInformation("Device updated: {Id}", id);
|
||||
return Ok(new { success = true, data = result, message = "更新成功" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除设备
|
||||
/// </summary>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult> Delete(int id)
|
||||
{
|
||||
var success = await _deviceManagementService.DeleteDeviceAsync(id);
|
||||
if (!success)
|
||||
{
|
||||
return NotFound(new { success = false, message = "设备不存在" });
|
||||
}
|
||||
_logger.LogInformation("Device deleted: {Id}", id);
|
||||
return Ok(new { success = true, message = "删除成功" });
|
||||
}
|
||||
|
||||
// ===== 设备内容分配 =====
|
||||
|
||||
/// <summary>
|
||||
/// 获取设备分配的内容
|
||||
/// </summary>
|
||||
[HttpGet("{id}/content")]
|
||||
public async Task<ActionResult<DeviceContentResponse>> GetContent(int id)
|
||||
{
|
||||
var result = await _deviceManagementService.GetDeviceContentAsync(id);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为设备分配内容
|
||||
/// </summary>
|
||||
[HttpPost("{id}/content")]
|
||||
public async Task<ActionResult> AssignContent(int id, [FromBody] DeviceAssignmentRequest request)
|
||||
{
|
||||
if (request.DeviceId != id)
|
||||
{
|
||||
return BadRequest(new { success = false, message = "设备ID不匹配" });
|
||||
}
|
||||
|
||||
var success = await _deviceManagementService.AssignContentToDeviceAsync(id, request.ApplicationIds);
|
||||
if (!success)
|
||||
{
|
||||
return NotFound(new { success = false, message = "设备不存在" });
|
||||
}
|
||||
|
||||
_logger.LogInformation("Content assigned to device {DeviceId}: {Count} applications", id, request.ApplicationIds.Count);
|
||||
return Ok(new { success = true, message = "内容分配成功,已通知设备刷新" });
|
||||
}
|
||||
|
||||
// ===== 推送控制 =====
|
||||
|
||||
/// <summary>
|
||||
/// 刷新设备内容
|
||||
/// </summary>
|
||||
[HttpPost("{id}/push/refresh")]
|
||||
public async Task<ActionResult> PushRefresh(int id)
|
||||
{
|
||||
var success = await _deviceManagementService.PushMessageAsync(id, "content_refresh", new { message = "请刷新内容" });
|
||||
if (!success)
|
||||
{
|
||||
return NotFound(new { success = false, message = "设备不在线或不存在" });
|
||||
}
|
||||
_logger.LogInformation("Push refresh to device: {DeviceId}", id);
|
||||
return Ok(new { success = true, message = "推送成功" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重启设备应用
|
||||
/// </summary>
|
||||
[HttpPost("{id}/push/restart")]
|
||||
public async Task<ActionResult> PushRestart(int id)
|
||||
{
|
||||
var success = await _deviceManagementService.PushMessageAsync(id, "app_restart", new { message = "请重启应用" });
|
||||
if (!success)
|
||||
{
|
||||
return NotFound(new { success = false, message = "设备不在线或不存在" });
|
||||
}
|
||||
_logger.LogInformation("Push restart to device: {DeviceId}", id);
|
||||
return Ok(new { success = true, message = "推送成功" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 WebSocket 连接统计
|
||||
/// </summary>
|
||||
[HttpGet("stats/connections")]
|
||||
public ActionResult GetConnectionStats()
|
||||
{
|
||||
var totalConnections = _wsManager.GetConnectionCount();
|
||||
return Ok(new
|
||||
{
|
||||
success = true,
|
||||
data = new
|
||||
{
|
||||
totalConnections,
|
||||
timestamp = DateTime.UtcNow
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 设备分组控制器 =====
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/device-groups")]
|
||||
// [Authorize] - 暂时禁用认证以便测试
|
||||
public class DeviceGroupsController : ControllerBase
|
||||
{
|
||||
private readonly DeviceManagementService _deviceManagementService;
|
||||
private readonly ILogger<DeviceGroupsController> _logger;
|
||||
|
||||
public DeviceGroupsController(DeviceManagementService deviceManagementService, ILogger<DeviceGroupsController> logger)
|
||||
{
|
||||
_deviceManagementService = deviceManagementService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有设备分组
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<DeviceGroupListResponse>> GetAll()
|
||||
{
|
||||
var result = await _deviceManagementService.GetAllGroupsAsync();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建设备分组
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<object>> Create([FromBody] DeviceGroupCreateRequest request)
|
||||
{
|
||||
var result = await _deviceManagementService.CreateGroupAsync(request);
|
||||
if (result == null)
|
||||
{
|
||||
return BadRequest(new { success = false, message = "创建失败" });
|
||||
}
|
||||
_logger.LogInformation("Device group created: {Name}", request.Name);
|
||||
return Ok(new { success = true, data = result, message = "创建成功" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新设备分组
|
||||
/// </summary>
|
||||
[HttpPut("{id}")]
|
||||
public async Task<ActionResult<object>> Update(int id, [FromBody] DeviceGroupUpdateRequest request)
|
||||
{
|
||||
var result = await _deviceManagementService.UpdateGroupAsync(id, request);
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound(new { success = false, message = "分组不存在" });
|
||||
}
|
||||
_logger.LogInformation("Device group updated: {Id}", id);
|
||||
return Ok(new { success = true, data = result, message = "更新成功" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除设备分组
|
||||
/// </summary>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult> Delete(int id)
|
||||
{
|
||||
var success = await _deviceManagementService.DeleteGroupAsync(id);
|
||||
if (!success)
|
||||
{
|
||||
return NotFound(new { success = false, message = "分组不存在" });
|
||||
}
|
||||
_logger.LogInformation("Device group deleted: {Id}", id);
|
||||
return Ok(new { success = true, message = "删除成功" });
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 批量管理控制器 =====
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/batch")]
|
||||
// [Authorize] - 暂时禁用认证以便测试
|
||||
public class BatchManagementController : ControllerBase
|
||||
{
|
||||
private readonly BatchManagementService _batchService;
|
||||
private readonly ILogger<BatchManagementController> _logger;
|
||||
|
||||
public BatchManagementController(BatchManagementService batchService, ILogger<BatchManagementController> logger)
|
||||
{
|
||||
_batchService = batchService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量为设备分配内容
|
||||
/// </summary>
|
||||
[HttpPost("assign-content")]
|
||||
public async Task<ActionResult<BatchOperationResponse>> BatchAssignContent([FromBody] BatchAssignContentRequest request)
|
||||
{
|
||||
var result = await _batchService.BatchAssignContentAsync(request);
|
||||
_logger.LogInformation("Batch assign content: {Count} devices", request.DeviceIds.Count);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量推送消息到设备
|
||||
/// </summary>
|
||||
[HttpPost("push")]
|
||||
public async Task<ActionResult<BatchOperationResponse>> BatchPush([FromBody] BatchPushRequest request)
|
||||
{
|
||||
var result = await _batchService.BatchPushAsync(request);
|
||||
_logger.LogInformation("Batch push: {Type} to {Count} devices", request.MessageType, request.DeviceIds.Count);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量推送消息到设备分组
|
||||
/// </summary>
|
||||
[HttpPost("push-to-groups")]
|
||||
public async Task<ActionResult<BatchOperationResponse>> BatchPushToGroups([FromBody] BatchPushToGroupRequest request)
|
||||
{
|
||||
var result = await _batchService.BatchPushToGroupAsync(request);
|
||||
_logger.LogInformation("Batch push to groups: {Type} to {Count} groups", request.MessageType, request.DeviceGroupIds.Count);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量启用/禁用设备
|
||||
/// </summary>
|
||||
[HttpPost("toggle-devices")]
|
||||
public async Task<ActionResult<BatchOperationResponse>> BatchToggleDevices([FromBody] BatchToggleDevicesRequest request)
|
||||
{
|
||||
var result = await _batchService.BatchToggleDevicesAsync(request);
|
||||
_logger.LogInformation("Batch toggle devices: {Enabled} for {Count} devices", request.IsEnabled, request.DeviceIds.Count);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量分配播放列表到分组
|
||||
/// </summary>
|
||||
[HttpPost("assign-playlist")]
|
||||
public async Task<ActionResult<BatchOperationResponse>> BatchAssignPlaylist([FromBody] BatchAssignPlaylistRequest request)
|
||||
{
|
||||
var result = await _batchService.BatchAssignPlaylistToGroupAsync(request);
|
||||
_logger.LogInformation("Batch assign playlist: {PlaylistId} to {Count} groups", request.PlaylistId, request.DeviceGroupIds.Count);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 仪表盘统计控制器 =====
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/stats")]
|
||||
// [Authorize] - 暂时禁用认证以便测试
|
||||
public class DashboardController : ControllerBase
|
||||
{
|
||||
private readonly DeviceManagementService _deviceManagementService;
|
||||
private readonly ApplicationService _applicationService;
|
||||
|
||||
public DashboardController(
|
||||
DeviceManagementService deviceManagementService,
|
||||
ApplicationService applicationService)
|
||||
{
|
||||
_deviceManagementService = deviceManagementService;
|
||||
_applicationService = applicationService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取仪表盘统计数据
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<DashboardStatsDto>> GetStats()
|
||||
{
|
||||
var devices = await _deviceManagementService.GetAllDevicesAsync();
|
||||
var applications = await _applicationService.GetAllAsync();
|
||||
|
||||
var stats = new DashboardStatsDto
|
||||
{
|
||||
TotalDevices = devices.Data.Count,
|
||||
OnlineDevices = devices.Data.Count(d => d.IsEnabled),
|
||||
TotalApplications = applications.Total
|
||||
};
|
||||
|
||||
return Ok(stats);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Application.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DRS9.Dashboard.Server.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/[controller]")]
|
||||
[Authorize]
|
||||
public class GuestAccessController : ControllerBase
|
||||
{
|
||||
private readonly GuestAccessService _guestAccessService;
|
||||
private readonly ILogger<GuestAccessController> _logger;
|
||||
|
||||
public GuestAccessController(GuestAccessService guestAccessService, ILogger<GuestAccessController> logger)
|
||||
{
|
||||
_guestAccessService = guestAccessService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建临时访问链接
|
||||
/// </summary>
|
||||
[HttpPost("create")]
|
||||
public async Task<ActionResult<GuestAccessResponse>> CreateGuestAccess([FromBody] GuestAccessCreateRequest request)
|
||||
{
|
||||
var result = await _guestAccessService.CreateGuestTokenAsync(request);
|
||||
if (!result.Success)
|
||||
{
|
||||
return BadRequest(result);
|
||||
}
|
||||
_logger.LogInformation("Guest access created: {Description}", request.Description);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
// 访客端内容查看控制器
|
||||
[ApiController]
|
||||
[Route("api/guest")]
|
||||
public class GuestViewController : ControllerBase
|
||||
{
|
||||
private readonly PlaylistService _playlistService;
|
||||
private readonly DeviceManagementService _deviceManagementService;
|
||||
|
||||
public GuestViewController(PlaylistService playlistService, DeviceManagementService deviceManagementService)
|
||||
{
|
||||
_playlistService = playlistService;
|
||||
_deviceManagementService = deviceManagementService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 访客获取内容(使用设备分配的内容)
|
||||
/// </summary>
|
||||
[HttpGet("content/{deviceId}")]
|
||||
public async Task<IActionResult> GetContent(int deviceId)
|
||||
{
|
||||
var result = await _deviceManagementService.GetDeviceContentAsync(deviceId);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 访客获取播放列表
|
||||
/// </summary>
|
||||
[HttpGet("playlist/{deviceId}")]
|
||||
public async Task<IActionResult> GetPlaylist(int deviceId)
|
||||
{
|
||||
var result = await _playlistService.GetDevicePlaylistAsync(deviceId);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
110
src/DRS9.Dashboard.Server/Controllers/PlaylistsController.cs
Normal file
110
src/DRS9.Dashboard.Server/Controllers/PlaylistsController.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
using DRS9.Dashboard.Application.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DRS9.Dashboard.Server.Controllers;
|
||||
|
||||
// 播放列表功能已禁用
|
||||
// [ApiController]
|
||||
// [Route("api/admin/[controller]")]
|
||||
// // [Authorize] - 暂时禁用认证以便测试
|
||||
// public class PlaylistsController : ControllerBase
|
||||
// {
|
||||
// private readonly PlaylistService _playlistService;
|
||||
// private readonly ILogger<PlaylistsController> _logger;
|
||||
//
|
||||
// public PlaylistsController(PlaylistService playlistService, ILogger<PlaylistsController> logger)
|
||||
// {
|
||||
// _playlistService = playlistService;
|
||||
// _logger = logger;
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 获取所有播放列表
|
||||
// /// </summary>
|
||||
// [HttpGet]
|
||||
// public async Task<ActionResult<PlaylistListResponse>> GetAll()
|
||||
// {
|
||||
// var result = await _playlistService.GetAllAsync();
|
||||
// return Ok(result);
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 获取播放列表详情
|
||||
// /// </summary>
|
||||
// [HttpGet("{id}")]
|
||||
// public async Task<ActionResult<PlaylistDetailDto>> GetById(int id)
|
||||
// {
|
||||
// var result = await _playlistService.GetByIdAsync(id);
|
||||
// if (result == null)
|
||||
// {
|
||||
// return NotFound(new { success = false, message = "播放列表不存在" });
|
||||
// }
|
||||
// return Ok(new { success = true, data = result });
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 创建播放列表
|
||||
// /// </summary>
|
||||
// [HttpPost]
|
||||
// public async Task<ActionResult<object>> Create([FromBody] PlaylistCreateRequest request)
|
||||
// {
|
||||
// var result = await _playlistService.CreateAsync(request);
|
||||
// if (result == null)
|
||||
// {
|
||||
// return BadRequest(new { success = false, message = "创建失败" });
|
||||
// }
|
||||
// _logger.LogInformation("Playlist created: {Name}", request.Name);
|
||||
// return Ok(new { success = true, data = result, message = "创建成功" });
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 更新播放列表
|
||||
// /// </summary>
|
||||
// [HttpPut("{id}")]
|
||||
// public async Task<ActionResult<object>> Update(int id, [FromBody] PlaylistUpdateRequest request)
|
||||
// {
|
||||
// var result = await _playlistService.UpdateAsync(id, request);
|
||||
// if (result == null)
|
||||
// {
|
||||
// return NotFound(new { success = false, message = "播放列表不存在" });
|
||||
// }
|
||||
// _logger.LogInformation("Playlist updated: {Id}", id);
|
||||
// return Ok(new { success = true, data = result, message = "更新成功" });
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 删除播放列表
|
||||
// /// </summary>
|
||||
// [HttpDelete("{id}")]
|
||||
// public async Task<ActionResult> Delete(int id)
|
||||
// {
|
||||
// var success = await _playlistService.DeleteAsync(id);
|
||||
// if (!success)
|
||||
// {
|
||||
// return NotFound(new { success = false, message = "播放列表不存在" });
|
||||
// }
|
||||
// _logger.LogInformation("Playlist deleted: {Id}", id);
|
||||
// return Ok(new { success = true, message = "删除成功" });
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 将播放列表分配到设备分组
|
||||
// /// </summary>
|
||||
// [HttpPost("{id}/assign")]
|
||||
// public async Task<ActionResult> AssignToGroup(int id, [FromBody] GroupAssignRequest request)
|
||||
// {
|
||||
// var success = await _playlistService.AssignToGroupAsync(id, request.DeviceGroupId);
|
||||
// if (!success)
|
||||
// {
|
||||
// return NotFound(new { success = false, message = "播放列表不存在" });
|
||||
// }
|
||||
// return Ok(new { success = true, message = "分配成功" });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public record GroupAssignRequest
|
||||
// {
|
||||
// public int? DeviceGroupId { get; set; }
|
||||
// }
|
||||
29
src/DRS9.Dashboard.Server/DRS9.Dashboard.Server.csproj
Normal file
29
src/DRS9.Dashboard.Server/DRS9.Dashboard.Server.csproj
Normal file
@@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Components\" />
|
||||
<Folder Include="Components\Pages\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.*" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.*">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DRS9.Dashboard.Application\DRS9.Dashboard.Application.csproj" />
|
||||
<ProjectReference Include="..\DRS9.Dashboard.Infrastructure\DRS9.Dashboard.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
src/DRS9.Dashboard.Server/DRS9.Dashboard.Server.http
Normal file
6
src/DRS9.Dashboard.Server/DRS9.Dashboard.Server.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@DRS9.Dashboard.Server_HostAddress = http://localhost:5264
|
||||
|
||||
GET {{DRS9.Dashboard.Server_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
122
src/DRS9.Dashboard.Server/Middleware/WebSocketMiddleware.cs
Normal file
122
src/DRS9.Dashboard.Server/Middleware/WebSocketMiddleware.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using DRS9.Dashboard.Application.Services;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DRS9.Dashboard.Server.Middleware;
|
||||
|
||||
public class WebSocketMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly DashboardWebSocketManager _wsManager;
|
||||
private readonly ILogger<WebSocketMiddleware> _logger;
|
||||
private const int BufferSize = 4096;
|
||||
|
||||
public WebSocketMiddleware(RequestDelegate next, DashboardWebSocketManager wsManager, ILogger<WebSocketMiddleware> logger)
|
||||
{
|
||||
_next = next;
|
||||
_wsManager = wsManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
if (!context.WebSockets.IsWebSocketRequest)
|
||||
{
|
||||
await _next(context);
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceId = context.Request.Query["deviceId"].ToString();
|
||||
var parsedDeviceId = int.TryParse(deviceId, out var id) ? id : (int?)null;
|
||||
|
||||
using var webSocket = await context.WebSockets.AcceptWebSocketAsync();
|
||||
var connection = _wsManager.AddConnection(webSocket, parsedDeviceId);
|
||||
|
||||
_logger.LogInformation("WebSocket connection established: {ConnectionId}", connection.ConnectionId);
|
||||
|
||||
try
|
||||
{
|
||||
await ReceiveMessagesAsync(connection);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "WebSocket error for connection: {ConnectionId}", connection.ConnectionId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_wsManager.RemoveConnection(connection.ConnectionId);
|
||||
await webSocket.CloseAsync(
|
||||
connection.WebSocket.CloseStatus ?? WebSocketCloseStatus.NormalClosure,
|
||||
connection.WebSocket.CloseStatusDescription,
|
||||
CancellationToken.None);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ReceiveMessagesAsync(WebSocketConnection connection)
|
||||
{
|
||||
var buffer = new byte[BufferSize];
|
||||
var segment = new ArraySegment<byte>(buffer);
|
||||
|
||||
while (connection.WebSocket.State == WebSocketState.Open)
|
||||
{
|
||||
var result = await connection.WebSocket.ReceiveAsync(segment, CancellationToken.None);
|
||||
|
||||
if (result.MessageType == WebSocketMessageType.Close)
|
||||
{
|
||||
_logger.LogInformation("WebSocket close requested: {ConnectionId}", connection.ConnectionId);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result.MessageType == WebSocketMessageType.Text)
|
||||
{
|
||||
var message = Encoding.UTF8.GetString(buffer, 0, result.Count);
|
||||
await ProcessMessageAsync(connection, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ProcessMessageAsync(WebSocketConnection connection, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonDoc = JsonDocument.Parse(message);
|
||||
var messageType = jsonDoc.RootElement.GetProperty("type").GetString();
|
||||
|
||||
_logger.LogDebug("Received message from {ConnectionId}: {Type}", connection.ConnectionId, messageType);
|
||||
|
||||
// Handle different message types
|
||||
switch (messageType)
|
||||
{
|
||||
case "ping":
|
||||
await _wsManager.SendMessageAsync(connection, new WebSocketMessage
|
||||
{
|
||||
Type = "pong",
|
||||
Data = new { timestamp = DateTime.UtcNow }
|
||||
});
|
||||
break;
|
||||
|
||||
case "heartbeat":
|
||||
connection.LastActivityAt = DateTime.UtcNow;
|
||||
await _wsManager.SendMessageAsync(connection, new WebSocketMessage
|
||||
{
|
||||
Type = "heartbeat_ack",
|
||||
Data = new { timestamp = DateTime.UtcNow }
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
_logger.LogWarning("Unknown message type: {Type} from {ConnectionId}", messageType, connection.ConnectionId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Invalid JSON message from {ConnectionId}", connection.ConnectionId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error processing message from {ConnectionId}", connection.ConnectionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
164
src/DRS9.Dashboard.Server/Program.cs
Normal file
164
src/DRS9.Dashboard.Server/Program.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using System.Text;
|
||||
using DRS9.Dashboard.Application.Services;
|
||||
using DRS9.Dashboard.Infrastructure.Data;
|
||||
using DRS9.Dashboard.Server.Middleware;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers();
|
||||
|
||||
// Configure Database
|
||||
builder.Services.AddDbContext<DashboardDbContext>(options =>
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
|
||||
// Configure JWT Authentication
|
||||
var jwtKey = builder.Configuration["Jwt:Key"] ?? throw new InvalidOperationException("JWT Key not configured");
|
||||
var jwtIssuer = builder.Configuration["Jwt:Issuer"] ?? throw new InvalidOperationException("JWT Issuer not configured");
|
||||
var jwtAudience = builder.Configuration["Jwt:Audience"] ?? throw new InvalidOperationException("JWT Audience not configured");
|
||||
|
||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = jwtIssuer,
|
||||
ValidAudience = jwtAudience,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey))
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
// Add Blazor Server
|
||||
builder.Services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents();
|
||||
|
||||
// Configure Blazor Server Circuit
|
||||
builder.Services.AddServerSideBlazor()
|
||||
.AddCircuitOptions(options =>
|
||||
{
|
||||
options.DetailedErrors = true;
|
||||
options.DisconnectedCircuitRetentionPeriod = TimeSpan.FromMinutes(3);
|
||||
});
|
||||
|
||||
// Register HttpClient and API Client Service
|
||||
builder.Services.AddHttpClient<DRS9.Dashboard.Server.Services.ApiClientService>(client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("http://localhost:5000");
|
||||
});
|
||||
|
||||
// Configure CORS
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll", policy =>
|
||||
{
|
||||
policy.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
// Register Application Services
|
||||
var jwtExpiry = int.TryParse(builder.Configuration["Jwt:ExpiryMinutes"], out var expiry) ? expiry : 43200;
|
||||
builder.Services.AddSingleton(new JwtTokenService(
|
||||
jwtKey,
|
||||
jwtIssuer,
|
||||
jwtAudience,
|
||||
jwtExpiry
|
||||
));
|
||||
|
||||
builder.Services.AddScoped<DeviceService>();
|
||||
builder.Services.AddScoped<ApplicationService>();
|
||||
builder.Services.AddScoped<DeviceManagementService>();
|
||||
builder.Services.AddScoped<PlaylistService>();
|
||||
builder.Services.AddScoped<BatchManagementService>();
|
||||
builder.Services.AddScoped<AppVersionService>();
|
||||
builder.Services.AddScoped<GuestAccessService>();
|
||||
builder.Services.AddSingleton<DashboardWebSocketManager>();
|
||||
|
||||
// Configure OpenAPI/Swagger
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Title = "DRS9 Dashboard API",
|
||||
Version = "v1",
|
||||
Description = "信息发布系统 API"
|
||||
});
|
||||
|
||||
// Add JWT Authentication to Swagger
|
||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||
{
|
||||
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
|
||||
Name = "Authorization",
|
||||
In = ParameterLocation.Header,
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
Scheme = "Bearer"
|
||||
});
|
||||
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
}
|
||||
},
|
||||
Array.Empty<string>()
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Initialize Database
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<DashboardDbContext>();
|
||||
await DataSeeder.SeedAsync(dbContext);
|
||||
}
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "DRS9 Dashboard API v1");
|
||||
});
|
||||
|
||||
app.UseCors("AllowAll");
|
||||
|
||||
// 静态文件
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
// Add anti-forgery for Blazor Server
|
||||
app.UseAntiforgery();
|
||||
|
||||
app.UseWebSockets();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
// Blazor Server
|
||||
app.MapRazorComponents<DRS9.Dashboard.Server.Components.App>()
|
||||
.AddInteractiveServerRenderMode();
|
||||
|
||||
// WebSocket endpoint
|
||||
app.Map("/ws", app => app.UseMiddleware<WebSocketMiddleware>());
|
||||
|
||||
app.Run();
|
||||
14
src/DRS9.Dashboard.Server/Properties/launchSettings.json
Normal file
14
src/DRS9.Dashboard.Server/Properties/launchSettings.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5264",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
254
src/DRS9.Dashboard.Server/Services/ApiClientService.cs
Normal file
254
src/DRS9.Dashboard.Server/Services/ApiClientService.cs
Normal file
@@ -0,0 +1,254 @@
|
||||
using DRS9.Dashboard.Application.DTOs;
|
||||
|
||||
namespace DRS9.Dashboard.Server.Services;
|
||||
|
||||
public class ApiClientService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public ApiClientService(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
|
||||
private void AddAuthHeader()
|
||||
{
|
||||
// TODO: 实现认证 token 管理
|
||||
}
|
||||
|
||||
// 设备管理 API
|
||||
public async Task<List<DeviceDto>> GetDevicesAsync()
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.GetAsync("/api/admin/devices");
|
||||
if (!response.IsSuccessStatusCode) return new List<DeviceDto>();
|
||||
var result = await response.Content.ReadFromJsonAsync<DeviceListResponse>();
|
||||
return result?.Data ?? new List<DeviceDto>();
|
||||
}
|
||||
|
||||
public async Task<DeviceDto?> GetDeviceAsync(int id)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.GetAsync($"/api/admin/devices/{id}");
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
var result = await response.Content.ReadFromJsonAsync<DeviceDto>();
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> CreateDeviceAsync(DeviceCreateRequest device)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync("/api/admin/devices", device);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateDeviceAsync(int id, DeviceUpdateRequest device)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PutAsJsonAsync($"/api/admin/devices/{id}", device);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteDeviceAsync(int id)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.DeleteAsync($"/api/admin/devices/{id}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> AssignContentAsync(int deviceId, List<int> applicationIds)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync($"/api/admin/devices/{deviceId}/content",
|
||||
new DeviceAssignmentRequest { DeviceId = deviceId, ApplicationIds = applicationIds });
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> PushToDeviceAsync(int deviceId, string messageType)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync($"/api/admin/devices/{deviceId}/push",
|
||||
new PushMessageRequest { DeviceId = deviceId, MessageType = messageType });
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
// 设备分组 API
|
||||
public async Task<List<DeviceGroupDto>> GetDeviceGroupsAsync()
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.GetAsync("/api/admin/device-groups");
|
||||
if (!response.IsSuccessStatusCode) return new List<DeviceGroupDto>();
|
||||
var result = await response.Content.ReadFromJsonAsync<DeviceGroupListResponse>();
|
||||
return result?.Data ?? new List<DeviceGroupDto>();
|
||||
}
|
||||
|
||||
public async Task<bool> CreateDeviceGroupAsync(DeviceGroupCreateRequest group)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync("/api/admin/device-groups", group);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteDeviceGroupAsync(int id)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.DeleteAsync($"/api/admin/device-groups/{id}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
// 应用/内容管理 API
|
||||
public async Task<List<ApplicationDto>> GetApplicationsAsync()
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.GetAsync("/api/admin/applications");
|
||||
if (!response.IsSuccessStatusCode) return new List<ApplicationDto>();
|
||||
var result = await response.Content.ReadFromJsonAsync<ApplicationListResponse>();
|
||||
return result?.Data ?? new List<ApplicationDto>();
|
||||
}
|
||||
|
||||
public async Task<ApplicationDto?> GetApplicationAsync(int id)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.GetAsync($"/api/admin/applications/{id}");
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
return await response.Content.ReadFromJsonAsync<ApplicationDto>();
|
||||
}
|
||||
|
||||
public async Task<bool> CreateApplicationAsync(ApplicationCreateRequest application)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync("/api/admin/applications", application);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateApplicationAsync(int id, ApplicationUpdateRequest application)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PutAsJsonAsync($"/api/admin/applications/{id}", application);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteApplicationAsync(int id)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.DeleteAsync($"/api/admin/applications/{id}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
// 播放列表 API
|
||||
public async Task<List<PlaylistDto>> GetPlaylistsAsync()
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.GetAsync("/api/admin/playlists");
|
||||
if (!response.IsSuccessStatusCode) return new List<PlaylistDto>();
|
||||
return await response.Content.ReadFromJsonAsync<List<PlaylistDto>>() ?? new List<PlaylistDto>();
|
||||
}
|
||||
|
||||
public async Task<PlaylistDto?> GetPlaylistAsync(int id)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.GetAsync($"/api/admin/playlists/{id}");
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
return await response.Content.ReadFromJsonAsync<PlaylistDto>();
|
||||
}
|
||||
|
||||
public async Task<bool> CreatePlaylistAsync(object playlist)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync("/api/admin/playlists", playlist);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdatePlaylistAsync(int id, object playlist)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PutAsJsonAsync($"/api/admin/playlists/{id}", playlist);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> DeletePlaylistAsync(int id)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.DeleteAsync($"/api/admin/playlists/{id}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> AssignPlaylistToGroupAsync(int playlistId, int groupId)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync($"/api/admin/playlists/{playlistId}/assign",
|
||||
new { DeviceGroupId = groupId });
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
// 批量操作 API
|
||||
public async Task<bool> BatchAssignContentAsync(BatchAssignContentRequest request)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync("/api/admin/batch/assign-content", request);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> BatchPushAsync(BatchPushRequest request)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync("/api/admin/batch/push", request);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> BatchToggleDevicesAsync(BatchToggleDevicesRequest request)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync("/api/admin/batch/toggle", request);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
// 版本管理 API
|
||||
public async Task<List<AppVersionDto>> GetVersionsAsync()
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.GetAsync("/api/admin/versions");
|
||||
if (!response.IsSuccessStatusCode) return new List<AppVersionDto>();
|
||||
return await response.Content.ReadFromJsonAsync<List<AppVersionDto>>() ?? new List<AppVersionDto>();
|
||||
}
|
||||
|
||||
public async Task<bool> CreateVersionAsync(object version)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync("/api/admin/versions", version);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteVersionAsync(int id)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.DeleteAsync($"/api/admin/versions/{id}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> PushUpdateAsync(int versionId)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync($"/api/admin/versions/{versionId}/push", new { });
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
// 访客链接 API
|
||||
public async Task<GuestAccessResponse?> CreateGuestAccessAsync(GuestAccessCreateRequest request)
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.PostAsJsonAsync("/api/admin/guest-access/create", request);
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
return await response.Content.ReadFromJsonAsync<GuestAccessResponse>();
|
||||
}
|
||||
|
||||
// 统计 API
|
||||
public async Task<DashboardStatsDto> GetStatsAsync()
|
||||
{
|
||||
AddAuthHeader();
|
||||
var response = await _httpClient.GetAsync("/api/admin/stats");
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return new DashboardStatsDto();
|
||||
return await response.Content.ReadFromJsonAsync<DashboardStatsDto>() ?? new DashboardStatsDto();
|
||||
}
|
||||
}
|
||||
8
src/DRS9.Dashboard.Server/appsettings.Development.json
Normal file
8
src/DRS9.Dashboard.Server/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/DRS9.Dashboard.Server/appsettings.json
Normal file
19
src/DRS9.Dashboard.Server/appsettings.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=dashboard.db"
|
||||
},
|
||||
"Jwt": {
|
||||
"Key": "DRS9_DASHBOARD_SECRET_KEY_2026_CHANGE_THIS_IN_PRODUCTION",
|
||||
"Issuer": "DRS9.Dashboard",
|
||||
"Audience": "DRS9.Dashboard.Clients",
|
||||
"ExpiryMinutes": 43200
|
||||
}
|
||||
}
|
||||
BIN
src/DRS9.Dashboard.Server/dashboard.db
Normal file
BIN
src/DRS9.Dashboard.Server/dashboard.db
Normal file
Binary file not shown.
252
src/DRS9.Dashboard.Server/wwwroot/css/app.css
Normal file
252
src/DRS9.Dashboard.Server/wwwroot/css/app.css
Normal file
@@ -0,0 +1,252 @@
|
||||
/* DRS9 Dashboard Admin Styles */
|
||||
|
||||
.page {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
main {
|
||||
flex: 1;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.top-row {
|
||||
background-color: #fff;
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
padding: 1rem 0;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
background-color: #f8f9fa;
|
||||
border-right: 1px solid #dee2e6;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.sidebar .nav-link {
|
||||
color: #495057;
|
||||
padding: 0.75rem 1rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.sidebar .nav-link:hover {
|
||||
color: #0d6efd;
|
||||
background-color: #e9ecef;
|
||||
}
|
||||
|
||||
.sidebar .nav-link.active {
|
||||
color: #0d6efd;
|
||||
background-color: #e7f1ff;
|
||||
}
|
||||
|
||||
.sidebar .nav-link i {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
/* Card Styles */
|
||||
.card {
|
||||
border: none;
|
||||
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
background-color: #fff;
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Status Badges */
|
||||
.badge {
|
||||
padding: 0.5em 0.75em;
|
||||
}
|
||||
|
||||
/* Table Styles */
|
||||
.table {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.table thead th {
|
||||
border-bottom: 2px solid #dee2e6;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Form Styles */
|
||||
.form-label {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Action Buttons */
|
||||
.btn-sm {
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
/* Modal Customization */
|
||||
.modal-header {
|
||||
background-color: #f8f9fa;
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
}
|
||||
|
||||
/* Stats Cards */
|
||||
.stat-card {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border-radius: 10px;
|
||||
padding: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.stat-card.success {
|
||||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||||
}
|
||||
|
||||
.stat-card.warning {
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
}
|
||||
|
||||
.stat-card.info {
|
||||
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
|
||||
}
|
||||
|
||||
.stat-card h3 {
|
||||
font-size: 2rem;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.stat-card p {
|
||||
margin-bottom: 0;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* Loading Spinner */
|
||||
.spinner-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
/* Device Status Indicators */
|
||||
.status-indicator {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.status-online {
|
||||
background-color: #28a745;
|
||||
}
|
||||
|
||||
.status-offline {
|
||||
background-color: #6c757d;
|
||||
}
|
||||
|
||||
.status-error {
|
||||
background-color: #dc3545;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 768px) {
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
top: 60px;
|
||||
left: -250px;
|
||||
width: 250px;
|
||||
height: calc(100vh - 60px);
|
||||
transition: left 0.3s;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.sidebar.show {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
main {
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* Content Type Icons */
|
||||
.content-icon {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 1.5rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
.content-icon.video {
|
||||
background-color: #e3f2fd;
|
||||
color: #1976d2;
|
||||
}
|
||||
|
||||
.content-icon.image {
|
||||
background-color: #f3e5f5;
|
||||
color: #7b1fa2;
|
||||
}
|
||||
|
||||
.content-icon.web {
|
||||
background-color: #e8f5e9;
|
||||
color: #388e3c;
|
||||
}
|
||||
|
||||
.content-icon.dashboard {
|
||||
background-color: #fff3e0;
|
||||
color: #f57c00;
|
||||
}
|
||||
|
||||
/* Drag and Drop */
|
||||
.draggable-item {
|
||||
cursor: move;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.draggable-item:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.draggable-item.dragging {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.drop-zone {
|
||||
border: 2px dashed #dee2e6;
|
||||
border-radius: 8px;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
transition: border-color 0.2s, background-color 0.2s;
|
||||
}
|
||||
|
||||
.drop-zone.drag-over {
|
||||
border-color: #0d6efd;
|
||||
background-color: #e7f1ff;
|
||||
}
|
||||
|
||||
/* Toast Notifications */
|
||||
.toast-container {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
z-index: 9999;
|
||||
}
|
||||
173
src/DRS9.Dashboard.Server/wwwroot/viewer.html
Normal file
173
src/DRS9.Dashboard.Server/wwwroot/viewer.html
Normal file
@@ -0,0 +1,173 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DRS9 查看器</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
background: #000;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#viewer {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
#viewer iframe {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#viewer img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
#viewer video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.loading {
|
||||
color: #fff;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #f44;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.info {
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
color: #fff;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="viewer">
|
||||
<div class="loading">正在加载内容...</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API_BASE = '/api/guest';
|
||||
|
||||
// 从 URL 获取设备 ID
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const deviceId = urlParams.get('deviceId') || urlParams.get('d');
|
||||
|
||||
if (!deviceId) {
|
||||
showError('请指定设备 ID:?deviceId=1 或 ?d=1');
|
||||
} else {
|
||||
loadContent(deviceId);
|
||||
}
|
||||
|
||||
async function loadContent(deviceId) {
|
||||
try {
|
||||
// 先尝试获取播放列表
|
||||
const playlistRes = await fetch(`${API_BASE}/playlist/${deviceId}`);
|
||||
const playlistData = await playlistRes.json();
|
||||
|
||||
if (playlistData.success && playlistData.data.length > 0) {
|
||||
showPlaylist(playlistData.data, playlistData.loopMode);
|
||||
} else {
|
||||
// 回退到直接获取内容
|
||||
const contentRes = await fetch(`${API_BASE}/content/${deviceId}`);
|
||||
const contentData = await contentRes.json();
|
||||
|
||||
if (contentData.success && contentData.data.length > 0) {
|
||||
showContent(contentData.data);
|
||||
} else {
|
||||
showError('暂无内容');
|
||||
}
|
||||
}
|
||||
|
||||
// 显示设备信息
|
||||
document.getElementById('viewer').innerHTML += `
|
||||
<div class="info">设备 ${deviceId}</div>
|
||||
`;
|
||||
} catch (err) {
|
||||
showError('加载失败:' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
function showPlaylist(items, loopMode) {
|
||||
let currentIndex = 0;
|
||||
|
||||
const showItem = (index) => {
|
||||
if (index >= items.length) {
|
||||
if (loopMode === 'Loop') {
|
||||
index = 0;
|
||||
} else {
|
||||
// Once 模式,结束
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const item = items[index];
|
||||
const duration = item.duration * 1000;
|
||||
|
||||
if (item.applicationType === 'Video' || item.contentUrl.endsWith('.mp4')) {
|
||||
document.getElementById('viewer').innerHTML = `
|
||||
<video src="${item.contentUrl}" autoplay muted></video>
|
||||
`;
|
||||
const video = document.querySelector('video');
|
||||
video.onended = () => showItem(index + 1);
|
||||
} else if (item.applicationType === 'Image' || /\.(jpg|jpeg|png|gif|svg|webp)$/i.test(item.contentUrl)) {
|
||||
document.getElementById('viewer').innerHTML = `
|
||||
<img src="${item.contentUrl}" alt="${item.applicationName}">
|
||||
`;
|
||||
setTimeout(() => showItem(index + 1), duration);
|
||||
} else {
|
||||
// Web 内容
|
||||
document.getElementById('viewer').innerHTML = `
|
||||
<iframe src="${item.contentUrl}" sandbox="allow-scripts allow-same-origin allow-forms"></iframe>
|
||||
`;
|
||||
setTimeout(() => showItem(index + 1), duration);
|
||||
}
|
||||
|
||||
currentIndex = index;
|
||||
};
|
||||
|
||||
showItem(0);
|
||||
}
|
||||
|
||||
function showContent(items) {
|
||||
showPlaylist(items.map(item => ({
|
||||
applicationName: item.applicationName,
|
||||
applicationType: item.applicationType,
|
||||
contentUrl: item.contentUrl,
|
||||
duration: item.duration
|
||||
})), 'Loop');
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
document.getElementById('viewer').innerHTML = `
|
||||
<div class="error">${message}</div>
|
||||
`;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
76
src/DRS9.Dashboard.sln
Normal file
76
src/DRS9.Dashboard.sln
Normal file
@@ -0,0 +1,76 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DRS9.Dashboard.Server", "DRS9.Dashboard.Server\DRS9.Dashboard.Server.csproj", "{A3945441-31C8-4602-A097-894EBCB2C121}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DRS9.Dashboard.Domain", "DRS9.Dashboard.Domain\DRS9.Dashboard.Domain.csproj", "{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DRS9.Dashboard.Application", "DRS9.Dashboard.Application\DRS9.Dashboard.Application.csproj", "{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DRS9.Dashboard.Infrastructure", "DRS9.Dashboard.Infrastructure\DRS9.Dashboard.Infrastructure.csproj", "{2C46B23F-7485-48B2-9BCA-0E2D9636B142}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A3945441-31C8-4602-A097-894EBCB2C121}.Release|x86.Build.0 = Release|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Release|x64.Build.0 = Release|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{261896C4-D2FB-4A0C-A2DD-98B41F8CA1C9}.Release|x86.Build.0 = Release|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{7F748342-07F7-4EFE-9D61-B0B9412F1B5B}.Release|x86.Build.0 = Release|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Release|x64.Build.0 = Release|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{2C46B23F-7485-48B2-9BCA-0E2D9636B142}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
56
test_api.sh
Executable file
56
test_api.sh
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
# DRS9 Dashboard API 测试脚本
|
||||
|
||||
BASE_URL="http://localhost:5264"
|
||||
|
||||
echo "=================================="
|
||||
echo "DRS9 Dashboard API 测试"
|
||||
echo "=================================="
|
||||
|
||||
# 1. 设备注册
|
||||
echo -e "\n1. 设备注册..."
|
||||
REGISTER_RESPONSE=$(curl -s -X POST $BASE_URL/api/devices/register \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"deviceCode":"TEST-001-DEV","deviceName":"测试设备1号","deviceType":"Android"}')
|
||||
|
||||
TOKEN=$(echo $REGISTER_RESPONSE | jq -r '.token')
|
||||
DEVICE_ID=$(echo $REGISTER_RESPONSE | jq -r '.deviceId')
|
||||
|
||||
echo "Token: $TOKEN"
|
||||
echo "Device ID: $DEVICE_ID"
|
||||
|
||||
# 2. 获取设备信息
|
||||
echo -e "\n2. 获取设备信息..."
|
||||
curl -s -X GET $BASE_URL/api/devices/info \
|
||||
-H "Authorization: Bearer $TOKEN" | jq .
|
||||
|
||||
# 3. 获取设备分配的内容(初始为空)
|
||||
echo -e "\n3. 获取设备分配的内容(初始为空)..."
|
||||
curl -s -X GET $BASE_URL/api/devices/content \
|
||||
-H "Authorization: Bearer $TOKEN" | jq .
|
||||
|
||||
# 4. 心跳测试
|
||||
echo -e "\n4. 心跳测试..."
|
||||
curl -s -X POST $BASE_URL/api/devices/heartbeat \
|
||||
-H "Authorization: Bearer $TOKEN" | jq .
|
||||
|
||||
# 5. 获取所有可用应用(不需要认证的测试接口)
|
||||
echo -e "\n5. 获取所有应用(数据库中的预置数据)..."
|
||||
echo "注意:需要管理员权限访问 /api/admin/applications"
|
||||
|
||||
echo -e "\n=================================="
|
||||
echo "测试完成"
|
||||
echo "=================================="
|
||||
echo ""
|
||||
echo "管理 API 端点(需要管理员认证):"
|
||||
echo " GET /api/admin/applications - 获取所有应用"
|
||||
echo " POST /api/admin/applications - 创建应用"
|
||||
echo " GET /api/admin/devices - 获取所有设备"
|
||||
echo " POST /api/admin/devices - 创建设备(生成设备码)"
|
||||
echo " GET /api/admin/devices/{id}/content - 获取设备内容"
|
||||
echo " POST /api/admin/devices/{id}/content - 分配内容给设备"
|
||||
echo " POST /api/admin/devices/{id}/push/refresh - 推送刷新指令"
|
||||
echo " GET /api/admin/devicegroups - 获取所有分组"
|
||||
echo ""
|
||||
echo "WebSocket 端点:"
|
||||
echo " ws://localhost:5264/ws?deviceId=1"
|
||||
67
test_websocket.html
Normal file
67
test_websocket.html
Normal file
@@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>WebSocket Test</title>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<h1>DRS9 Dashboard WebSocket Test</h1>
|
||||
<div>
|
||||
<input type="text" id="deviceId" placeholder="Device ID (optional)" value="1">
|
||||
<button onclick="connect()">Connect</button>
|
||||
<button onclick="disconnect()">Disconnect</button>
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" id="message" placeholder="Message (e.g., {\"type\":\"ping\"})" value='{"type":"ping"}'>
|
||||
<button onclick="send()">Send</button>
|
||||
</div>
|
||||
<pre id="log"></pre>
|
||||
|
||||
<script>
|
||||
let ws = null;
|
||||
|
||||
function log(msg) {
|
||||
const el = document.getElementById('log');
|
||||
el.textContent += new Date().toLocaleTimeString() + ': ' + msg + '\n';
|
||||
}
|
||||
|
||||
function connect() {
|
||||
const deviceId = document.getElementById('deviceId').value;
|
||||
const url = 'ws://localhost:5264/ws' + (deviceId ? '?deviceId=' + deviceId : '');
|
||||
log('Connecting to ' + url);
|
||||
|
||||
ws = new WebSocket(url);
|
||||
|
||||
ws.onopen = () => {
|
||||
log('Connected!');
|
||||
};
|
||||
|
||||
ws.onmessage = (e) => {
|
||||
log('Received: ' + e.data);
|
||||
};
|
||||
|
||||
ws.onerror = (e) => {
|
||||
log('Error: ' + e);
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
log('Disconnected');
|
||||
};
|
||||
}
|
||||
|
||||
function disconnect() {
|
||||
if (ws) ws.close();
|
||||
}
|
||||
|
||||
function send() {
|
||||
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
||||
log('Not connected');
|
||||
return;
|
||||
}
|
||||
const msg = document.getElementById('message').value;
|
||||
log('Sending: ' + msg);
|
||||
ws.send(msg);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user