From b7756e2112e71403f3dbbdc21ca38d8ffdfad25b Mon Sep 17 00:00:00 2001 From: chenchun Date: Mon, 10 Nov 2025 15:03:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 概要 - 重构并扩展公告相关模型、DTO、服务,新增公告类型、图片与时间字段,调整缓存与查询处理。 - 新增枚举 AnnouncementTypeEnum。 - 主要改动(简要) - Yi.Framework.AiHub.Application.Contracts/Dtos/Announcement/AnnouncementLogDto.cs - 新增 ImageUrl、StartTime、EndTime、Type 字段,移除 Date 字段,Title 不再默认空串。 - Yi.Framework.AiHub.Domain/Entities - 重命名 AnnouncementLogAggregateRoot -> AnnouncementAggregateRoot - 表名由 Ai_AnnouncementLog 改为 Ai_Announcement(SugarTable 标注) - 新增 ImageUrl、StartTime、EndTime、Type、Remark 字段(Remark 已存在,保持) - Yi.Framework.AiHub.Domain.Shared/Enums/AnnouncementTypeEnum.cs - 新增枚举文件(Activity=1, System=2) - Yi.Framework.AiHub.Application.Contracts/IServices/IAnnouncementService.cs - GetAsync 返回类型由 AnnouncementOutput 改为 List - Yi.Framework.AiHub.Application/Services/AnnouncementService.cs - 使用 Mapster 进行 DTO 映射 - 查询按 StartTime 降序,返回 List,缓存结构简化 - Yi.Abp.Web/YiAbpWebModule.cs - 改为初始化 AnnouncementAggregateRoot 的表(Ai_Announcement) - Yi.Ai.Vue3/types/import_meta.d.ts - 移除 VITE_BUILD_COMPRESS 环境变量声明 - 重要注意/兼容性提示 - 接口变更:IAnnouncementService.GetAsync 返回类型已改变,调用方需同步更新(之前返回 AnnouncementOutput 的代码需调整)。 - 数据库表变更:表名从 Ai_AnnouncementLog -> Ai_Announcement,若需保留历史数据,请在部署前做好数据迁移(重命名表或迁移数据到新表结构),或使用 CodeFirst 初始化新表(当前代码在启动时会 InitTables())。 - 新增 Mapster 适配(确保项目有 Mapster 依赖)。 - 前端类型声明移除环境变量后,前端构建/运行脚本若依赖 VITE_BUILD_COMPRESS 需同步调整。 - 若有缓存结构(AnnouncementCacheDto)或序列化相关约定变更,确认兼容性。 - 建议操作 - 更新所有使用 IAnnouncementService 的代码(API 层/前端适配返回结构)。 - 在非生产环境先执行数据迁移验证(保留旧表数据或写迁移脚本)。 - 确认 Mapster 包已安装并编译通过。 - 前端项目检查并同步 import_meta.d.ts 变更。 --- .../Dtos/Announcement/AnnouncementLogDto.cs | 29 ++++++++--- .../IServices/IAnnouncementService.cs | 2 +- .../Services/AnnouncementService.cs | 27 +++------- .../Enums/AnnouncementTypeEnum.cs | 7 +++ .../Entities/AnnouncementAggregateRoot.cs | 52 +++++++++++++++++++ .../Entities/AnnouncementLogAggregateRoot.cs | 44 ---------------- Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs | 6 ++- Yi.Ai.Vue3/types/import_meta.d.ts | 1 - 8 files changed, 94 insertions(+), 74 deletions(-) create mode 100644 Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/AnnouncementTypeEnum.cs create mode 100644 Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/AnnouncementAggregateRoot.cs delete mode 100644 Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/AnnouncementLogAggregateRoot.cs diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Announcement/AnnouncementLogDto.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Announcement/AnnouncementLogDto.cs index 0a7ef430..fdb7a59d 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Announcement/AnnouncementLogDto.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Announcement/AnnouncementLogDto.cs @@ -1,3 +1,5 @@ +using Yi.Framework.AiHub.Domain.Shared.Enums; + namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Announcement; /// @@ -5,18 +7,33 @@ namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Announcement; /// public class AnnouncementLogDto { - /// - /// 日期 - /// - public string Date { get; set; } = string.Empty; - /// /// 标题 /// - public string Title { get; set; } = string.Empty; + public string Title { get; set; } /// /// 内容列表 /// public List Content { get; set; } = new List(); + + /// + /// 图片url + /// + public string? ImageUrl { get; set; } + + /// + /// 开始时间(系统公告时间、活动开始时间) + /// + public DateTime StartTime { get; set; } + + /// + /// 活动结束时间 + /// + public DateTime? EndTime { get; set; } + + /// + /// 公告类型(系统、活动) + /// + public AnnouncementTypeEnum Type{ get; set; } } diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/IServices/IAnnouncementService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/IServices/IAnnouncementService.cs index 77d4d29a..acdda549 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/IServices/IAnnouncementService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/IServices/IAnnouncementService.cs @@ -11,5 +11,5 @@ public interface IAnnouncementService /// 获取公告信息 /// /// 公告信息 - Task GetAsync(); + Task> GetAsync(); } diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AnnouncementService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AnnouncementService.cs index 8914cd25..2399070e 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AnnouncementService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AnnouncementService.cs @@ -1,3 +1,4 @@ +using Mapster; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Configuration; using Volo.Abp.Application.Services; @@ -14,13 +15,13 @@ namespace Yi.Framework.AiHub.Application.Services; /// public class AnnouncementService : ApplicationService, IAnnouncementService { - private readonly ISqlSugarRepository _announcementRepository; + private readonly ISqlSugarRepository _announcementRepository; private readonly IConfiguration _configuration; private readonly IDistributedCache _announcementCache; private const string AnnouncementCacheKey = "AiHub:Announcement"; public AnnouncementService( - ISqlSugarRepository announcementRepository, + ISqlSugarRepository announcementRepository, IConfiguration configuration, IDistributedCache announcementCache) { @@ -32,7 +33,7 @@ public class AnnouncementService : ApplicationService, IAnnouncementService /// /// 获取公告信息 /// - public async Task GetAsync() + public async Task> GetAsync() { // 使用 GetOrAddAsync 从缓存获取或添加数据,缓存1小时 var cacheData = await _announcementCache.GetOrAddAsync( @@ -44,11 +45,7 @@ public class AnnouncementService : ApplicationService, IAnnouncementService } ); - return new AnnouncementOutput - { - Version = cacheData?.Version ?? "v1.0.0", - Logs = cacheData?.Logs ?? new List() - }; + return cacheData?.Logs ?? new List(); } /// @@ -56,25 +53,15 @@ public class AnnouncementService : ApplicationService, IAnnouncementService /// private async Task LoadAnnouncementDataAsync() { - // 从配置文件读取版本号,如果没有配置则使用默认值 - var version = _configuration["AiHubVersion"] ?? "v1.0.0"; - // 查询所有公告日志,按日期降序排列 var logs = await _announcementRepository._DbQueryable - .OrderByDescending(x => x.Date) + .OrderByDescending(x => x.StartTime) .ToListAsync(); // 转换为 DTO - var logDtos = logs.Select(log => new AnnouncementLogDto - { - Date = log.Date.ToString("yyyy-MM-dd"), - Title = log.Title, - Content = log.Content - }).ToList(); - + var logDtos = logs.Adapt>(); return new AnnouncementCacheDto { - Version = version, Logs = logDtos }; } diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/AnnouncementTypeEnum.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/AnnouncementTypeEnum.cs new file mode 100644 index 00000000..fa898e18 --- /dev/null +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/AnnouncementTypeEnum.cs @@ -0,0 +1,7 @@ +namespace Yi.Framework.AiHub.Domain.Shared.Enums; + +public enum AnnouncementTypeEnum +{ + Activity=1, + System=2 +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/AnnouncementAggregateRoot.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/AnnouncementAggregateRoot.cs new file mode 100644 index 00000000..e2e05b0d --- /dev/null +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/AnnouncementAggregateRoot.cs @@ -0,0 +1,52 @@ +using SqlSugar; +using Volo.Abp.Domain.Entities.Auditing; +using Yi.Framework.AiHub.Domain.Shared.Enums; + +namespace Yi.Framework.AiHub.Domain.Entities; + +/// +/// 公告日志 +/// +[SugarTable("Ai_Announcement")] +public class AnnouncementAggregateRoot : FullAuditedAggregateRoot +{ + public AnnouncementAggregateRoot() + { + } + + /// + /// 标题 + /// + public string Title { get; set; } = string.Empty; + + /// + /// 内容列表(JSON格式存储) + /// + [SugarColumn(IsJson = true, IsNullable = false)] + public List Content { get; set; } = new List(); + + /// + /// 备注 + /// + public string? Remark { get; set; } + + /// + /// 图片url + /// + public string? ImageUrl { get; set; } + + /// + /// 开始时间(系统公告时间、活动开始时间) + /// + public DateTime StartTime { get; set; } + + /// + /// 活动结束时间 + /// + public DateTime? EndTime { get; set; } + + /// + /// 公告类型(系统、活动) + /// + public AnnouncementTypeEnum Type{ get; set; } +} diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/AnnouncementLogAggregateRoot.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/AnnouncementLogAggregateRoot.cs deleted file mode 100644 index ec890394..00000000 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/AnnouncementLogAggregateRoot.cs +++ /dev/null @@ -1,44 +0,0 @@ -using SqlSugar; -using Volo.Abp.Domain.Entities.Auditing; - -namespace Yi.Framework.AiHub.Domain.Entities; - -/// -/// 公告日志 -/// -[SugarTable("Ai_AnnouncementLog")] -[SugarIndex($"index_{nameof(Date)}", nameof(Date), OrderByType.Desc)] -public class AnnouncementLogAggregateRoot : FullAuditedAggregateRoot -{ - public AnnouncementLogAggregateRoot() - { - } - - public AnnouncementLogAggregateRoot(DateTime date, string title, List content) - { - Date = date; - Title = title; - Content = content; - } - - /// - /// 日期 - /// - public DateTime Date { get; set; } - - /// - /// 标题 - /// - public string Title { get; set; } = string.Empty; - - /// - /// 内容列表(JSON格式存储) - /// - [SugarColumn(IsJson = true, IsNullable = false)] - public List Content { get; set; } = new List(); - - /// - /// 备注 - /// - public string? Remark { get; set; } -} diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs index 1e701178..2149f1b5 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs @@ -29,6 +29,7 @@ using Volo.Abp.Swashbuckle; using Yi.Abp.Application; using Yi.Abp.SqlsugarCore; using Yi.Framework.AiHub.Application; +using Yi.Framework.AiHub.Application.Services; using Yi.Framework.AiHub.Domain.Entities; using Yi.Framework.AspNetCore; using Yi.Framework.AspNetCore.Authentication.OAuth; @@ -354,8 +355,9 @@ namespace Yi.Abp.Web var app = context.GetApplicationBuilder(); app.UseRouting(); - //app.ApplicationServices.GetRequiredService().SqlSugarClient.CodeFirst.InitTables(); - + app.ApplicationServices.GetRequiredService().SqlSugarClient.CodeFirst.InitTables(); + // app.ApplicationServices.GetRequiredService().SqlSugarClient.CodeFirst.InitTables(); + //跨域 app.UseCors(DefaultCorsPolicyName); diff --git a/Yi.Ai.Vue3/types/import_meta.d.ts b/Yi.Ai.Vue3/types/import_meta.d.ts index d8a60d41..b3e9d275 100644 --- a/Yi.Ai.Vue3/types/import_meta.d.ts +++ b/Yi.Ai.Vue3/types/import_meta.d.ts @@ -6,7 +6,6 @@ interface ImportMetaEnv { readonly VITE_WEB_ENV: string; readonly VITE_WEB_BASE_API: string; readonly VITE_API_URL: string; - readonly VITE_BUILD_COMPRESS: string; readonly VITE_SSO_SEVER_URL: string; readonly VITE_APP_VERSION: string; }