Banner配置完善

This commit is contained in:
马梓彭 2026-03-07 22:02:26 +08:00
parent 81ecb93aa5
commit e893a6763a
5 changed files with 134 additions and 55 deletions

View File

@ -66,7 +66,7 @@ public class BannerService : BaseService<YD_Event.Core.Entities.Banner>, 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<YD_Event.Core.Entities.Banner>, 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<YD_Event.Core.Entities.Banner>, 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<YD_Event.Core.Entities.Banner>, 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<YD_Event.Core.Entities.Banner>, ITransi
/// <returns></returns>
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<YD_Event.Core.Entities.Banner>();
entity.Id = _idGenerator.NextId();
await _repository.InsertAsync(entity);
@ -152,10 +160,36 @@ public class BannerService : BaseService<YD_Event.Core.Entities.Banner>, 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);
}
/// <summary>
/// 排序
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
[HttpPost("sort")]
public async Task Sort(List<long> 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);
}
/// <summary>
/// 删除轮播图
/// </summary>

View File

@ -21,14 +21,19 @@ public class AddBannerInput
public string ImageUrl { get; set; }
/// <summary>
/// 跳转链接类型(0-图片/无跳转 1-赛事)
/// 跳转链接类型
/// </summary>
public int LinkType { get; set; }
public LinkType LinkType { get; set; }
/// <summary>
/// 跳转目标(赛事ID或URL)
/// 跳转链接URL
/// </summary>
public string LinkTarget { get; set; }
public string LinkUrl { get; set; }
/// <summary>
/// 关联赛事ID
/// </summary>
public long? EventId { get; set; }
/// <summary>
/// 排序
@ -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; }

View File

@ -24,16 +24,22 @@ public class Banner : Entity<long>, ISoftDelete, ICreatedUserId, ICreatedTime, I
public string ImageUrl { get; set; }
/// <summary>
/// 跳转链接类型(0-图片/无跳转 1-赛事)
/// 跳转链接类型
/// </summary>
[SugarColumn(ColumnDescription = "跳转链接类型")]
public int LinkType { get; set; }
public LinkType LinkType { get; set; }
/// <summary>
/// 跳转目标(赛事ID或URL)
/// 跳转链接URL
/// </summary>
[SugarColumn(ColumnDescription = "跳转目标", Length = 512, IsNullable = true)]
public string LinkTarget { get; set; }
[SugarColumn(ColumnDescription = "跳转链接URL", Length = 512, IsNullable = true)]
public string LinkUrl { get; set; }
/// <summary>
/// 关联赛事ID
/// </summary>
[SugarColumn(ColumnDescription = "关联赛事ID", IsNullable = true)]
public long? EventId { get; set; }
/// <summary>
/// 排序
@ -77,42 +83,4 @@ public class Banner : Entity<long>, ISoftDelete, ICreatedUserId, ICreatedTime, I
/// 更新时间
/// </summary>
public DateTime? UpdatedTime { get; set; }
}
/// <summary>
/// 轮播图设置(存储手动/自动模式)
/// </summary>
[SugarTable("BannerConfig")]
public class BannerConfig : Entity<long>, ISoftDelete, ICreatedUserId, ICreatedTime, IUpdatedUserId, IUpdatedTime
{
/// <summary>
/// 模式(0-手动配置 1-自动配置)
/// </summary>
[SugarColumn(ColumnDescription = "模式(0-手动配置 1-自动配置)")]
public int Mode { get; set; }
/// <summary>
/// 标记删除
/// </summary>
public bool DeleteMark { get; set; }
/// <summary>
/// 创建人
/// </summary>
public long CreatedUserId { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreatedTime { get; set; }
/// <summary>
/// 更新人
/// </summary>
public long? UpdatedUserId { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime? UpdatedTime { get; set; }
}
}

View File

@ -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
{
/// <summary>
/// 轮播图设置(存储手动/自动模式)
/// </summary>
[SugarTable("BannerConfig")]
public class BannerConfig : Entity<long>, ISoftDelete, ICreatedUserId, ICreatedTime, IUpdatedUserId, IUpdatedTime
{
/// <summary>
/// 模式(0-手动配置 1-自动配置)
/// </summary>
[SugarColumn(ColumnDescription = "模式(0-手动配置 1-自动配置)")]
public int Mode { get; set; }
/// <summary>
/// 标记删除
/// </summary>
public bool DeleteMark { get; set; }
/// <summary>
/// 创建人
/// </summary>
public long CreatedUserId { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreatedTime { get; set; }
/// <summary>
/// 更新人
/// </summary>
public long? UpdatedUserId { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime? UpdatedTime { get; set; }
}
}

View File

@ -0,0 +1,24 @@
using System.ComponentModel;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.Reflection;
namespace YD_Event.Core.Enum;
/// <summary>
/// 跳转链接类型
/// </summary>
public enum LinkType
{
/// <summary>
/// 赛事
/// </summary>
[Description("赛事")]
Event = 0,
/// <summary>
/// URL
/// </summary>
[Description("URL")]
Url = 1
}