From e893a6763ae5cdd7c8ae06d9697375bfdc6c18f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Sat, 7 Mar 2026 22:02:26 +0800 Subject: [PATCH] =?UTF-8?q?Banner=E9=85=8D=E7=BD=AE=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YD_Event.Application/Banner/BannerService.cs | 44 +++++++++++++-- .../Banner/Dtos/BannerDtos.cs | 18 ++++-- YD_Event.Core/Entities/Banner.cs | 56 ++++--------------- YD_Event.Core/Entities/BannerConfig.cs | 47 ++++++++++++++++ YD_Event.Core/Enum/LinkType.cs | 24 ++++++++ 5 files changed, 134 insertions(+), 55 deletions(-) create mode 100644 YD_Event.Core/Entities/BannerConfig.cs create mode 100644 YD_Event.Core/Enum/LinkType.cs diff --git a/YD_Event.Application/Banner/BannerService.cs b/YD_Event.Application/Banner/BannerService.cs index 7c6641c..ff97101 100644 --- a/YD_Event.Application/Banner/BannerService.cs +++ b/YD_Event.Application/Banner/BannerService.cs @@ -66,7 +66,7 @@ public class BannerService : BaseService, ITransi { // 获取最新的4场赛事 var events = await _eventRepository.AsQueryable() - .Where(x => !x.DeleteMark) // 假设EventInfo有DeleteMark + .Where(x => !x.DeleteMark && x.Status == AvailabilityStatus.Enable) // 仅查询启用且未删除的赛事 .OrderByDescending(x => x.CreatedTime) .Take(4) .Select(x => new BannerOutput @@ -74,8 +74,8 @@ public class BannerService : BaseService, ITransi Id = x.Id, Title = x.EventName, ImageUrl = x.CoverImage, - LinkType = 1, // 赛事 - LinkTarget = x.Id.ToString(), + LinkType = LinkType.Event, // 赛事 + EventId = x.Id, Sort = 0, Status = Core.Enum.AvailabilityStatus.Enable, CreatedTime = x.CreatedTime @@ -94,7 +94,8 @@ public class BannerService : BaseService, ITransi Title = x.Title, ImageUrl = x.ImageUrl, LinkType = x.LinkType, - LinkTarget = x.LinkTarget, + LinkUrl = x.LinkUrl, + EventId = x.EventId, Sort = x.Sort, Status = x.Status, Remark = x.Remark, @@ -120,7 +121,8 @@ public class BannerService : BaseService, ITransi Title = x.Title, ImageUrl = x.ImageUrl, LinkType = x.LinkType, - LinkTarget = x.LinkTarget, + LinkUrl = x.LinkUrl, + EventId = x.EventId, Sort = x.Sort, Status = x.Status, Remark = x.Remark, @@ -137,6 +139,12 @@ public class BannerService : BaseService, ITransi /// public async Task Add(AddBannerInput input) { + if (input.LinkType == LinkType.Event && input.EventId.HasValue) + { + var exists = await _eventRepository.IsAnyAsync(x => x.Id == input.EventId.Value && !x.DeleteMark); + if (!exists) throw Oops.Bah("关联的赛事不存在"); + } + var entity = input.Adapt(); entity.Id = _idGenerator.NextId(); await _repository.InsertAsync(entity); @@ -152,10 +160,36 @@ public class BannerService : BaseService, ITransi var entity = await _repository.GetByIdAsync(input.Id); if (entity == null) throw new InvalidOperationException("轮播图不存在"); + if (input.LinkType == LinkType.Event && input.EventId.HasValue) + { + var exists = await _eventRepository.IsAnyAsync(x => x.Id == input.EventId.Value && !x.DeleteMark); + if (!exists) throw Oops.Bah("关联的赛事不存在"); + } + input.Adapt(entity); await _repository.UpdateAsync(entity); } + /// + /// 排序 + /// + /// + /// + [HttpPost("sort")] + public async Task Sort(List ids) + { + var banners = await _repository.AsQueryable().Where(x => ids.Contains(x.Id)).ToListAsync(); + foreach (var banner in banners) + { + var index = ids.IndexOf(banner.Id); + if (index >= 0) + { + banner.Sort = index + 1; + } + } + await _repository.UpdateRangeAsync(banners); + } + /// /// 删除轮播图 /// diff --git a/YD_Event.Application/Banner/Dtos/BannerDtos.cs b/YD_Event.Application/Banner/Dtos/BannerDtos.cs index 5077273..8008f2b 100644 --- a/YD_Event.Application/Banner/Dtos/BannerDtos.cs +++ b/YD_Event.Application/Banner/Dtos/BannerDtos.cs @@ -21,14 +21,19 @@ public class AddBannerInput public string ImageUrl { get; set; } /// - /// 跳转链接类型(0-图片/无跳转 1-赛事) + /// 跳转链接类型 /// - public int LinkType { get; set; } + public LinkType LinkType { get; set; } /// - /// 跳转目标(赛事ID或URL) + /// 跳转链接URL /// - public string LinkTarget { get; set; } + public string LinkUrl { get; set; } + + /// + /// 关联赛事ID + /// + public long? EventId { get; set; } /// /// 排序 @@ -77,8 +82,9 @@ public class BannerOutput public long Id { get; set; } public string Title { get; set; } public string ImageUrl { get; set; } - public int LinkType { get; set; } - public string LinkTarget { get; set; } + public LinkType LinkType { get; set; } + public string LinkUrl { get; set; } + public long? EventId { get; set; } public int Sort { get; set; } public AvailabilityStatus Status { get; set; } public string Remark { get; set; } diff --git a/YD_Event.Core/Entities/Banner.cs b/YD_Event.Core/Entities/Banner.cs index 9f84c8c..a093e40 100644 --- a/YD_Event.Core/Entities/Banner.cs +++ b/YD_Event.Core/Entities/Banner.cs @@ -24,16 +24,22 @@ public class Banner : Entity, ISoftDelete, ICreatedUserId, ICreatedTime, I public string ImageUrl { get; set; } /// - /// 跳转链接类型(0-图片/无跳转 1-赛事) + /// 跳转链接类型 /// [SugarColumn(ColumnDescription = "跳转链接类型")] - public int LinkType { get; set; } + public LinkType LinkType { get; set; } /// - /// 跳转目标(赛事ID或URL) + /// 跳转链接URL /// - [SugarColumn(ColumnDescription = "跳转目标", Length = 512, IsNullable = true)] - public string LinkTarget { get; set; } + [SugarColumn(ColumnDescription = "跳转链接URL", Length = 512, IsNullable = true)] + public string LinkUrl { get; set; } + + /// + /// 关联赛事ID + /// + [SugarColumn(ColumnDescription = "关联赛事ID", IsNullable = true)] + public long? EventId { get; set; } /// /// 排序 @@ -77,42 +83,4 @@ public class Banner : Entity, ISoftDelete, ICreatedUserId, ICreatedTime, I /// 更新时间 /// public DateTime? UpdatedTime { get; set; } -} - -/// -/// 轮播图设置(存储手动/自动模式) -/// -[SugarTable("BannerConfig")] -public class BannerConfig : Entity, ISoftDelete, ICreatedUserId, ICreatedTime, IUpdatedUserId, IUpdatedTime -{ - /// - /// 模式(0-手动配置 1-自动配置) - /// - [SugarColumn(ColumnDescription = "模式(0-手动配置 1-自动配置)")] - public int Mode { get; set; } - - /// - /// 标记删除 - /// - public bool DeleteMark { get; set; } - - /// - /// 创建人 - /// - public long CreatedUserId { get; set; } - - /// - /// 创建时间 - /// - public DateTime CreatedTime { get; set; } - - /// - /// 更新人 - /// - public long? UpdatedUserId { get; set; } - - /// - /// 更新时间 - /// - public DateTime? UpdatedTime { get; set; } -} +} \ No newline at end of file diff --git a/YD_Event.Core/Entities/BannerConfig.cs b/YD_Event.Core/Entities/BannerConfig.cs new file mode 100644 index 0000000..cf5b279 --- /dev/null +++ b/YD_Event.Core/Entities/BannerConfig.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YD_Event.Core.Entities +{ + /// + /// 轮播图设置(存储手动/自动模式) + /// + [SugarTable("BannerConfig")] + public class BannerConfig : Entity, ISoftDelete, ICreatedUserId, ICreatedTime, IUpdatedUserId, IUpdatedTime + { + /// + /// 模式(0-手动配置 1-自动配置) + /// + [SugarColumn(ColumnDescription = "模式(0-手动配置 1-自动配置)")] + public int Mode { get; set; } + + /// + /// 标记删除 + /// + public bool DeleteMark { get; set; } + + /// + /// 创建人 + /// + public long CreatedUserId { get; set; } + + /// + /// 创建时间 + /// + public DateTime CreatedTime { get; set; } + + /// + /// 更新人 + /// + public long? UpdatedUserId { get; set; } + + /// + /// 更新时间 + /// + public DateTime? UpdatedTime { get; set; } + } + +} diff --git a/YD_Event.Core/Enum/LinkType.cs b/YD_Event.Core/Enum/LinkType.cs new file mode 100644 index 0000000..5ec0827 --- /dev/null +++ b/YD_Event.Core/Enum/LinkType.cs @@ -0,0 +1,24 @@ +using System.ComponentModel; +using System.Collections.Concurrent; +using System.Collections.ObjectModel; +using System.Reflection; + +namespace YD_Event.Core.Enum; + +/// +/// 跳转链接类型 +/// +public enum LinkType +{ + /// + /// 赛事 + /// + [Description("赛事")] + Event = 0, + + /// + /// URL + /// + [Description("URL")] + Url = 1 +} \ No newline at end of file