Banner配置完善
This commit is contained in:
parent
81ecb93aa5
commit
e893a6763a
@ -66,7 +66,7 @@ public class BannerService : BaseService<YD_Event.Core.Entities.Banner>, ITransi
|
|||||||
{
|
{
|
||||||
// 获取最新的4场赛事
|
// 获取最新的4场赛事
|
||||||
var events = await _eventRepository.AsQueryable()
|
var events = await _eventRepository.AsQueryable()
|
||||||
.Where(x => !x.DeleteMark) // 假设EventInfo有DeleteMark
|
.Where(x => !x.DeleteMark && x.Status == AvailabilityStatus.Enable) // 仅查询启用且未删除的赛事
|
||||||
.OrderByDescending(x => x.CreatedTime)
|
.OrderByDescending(x => x.CreatedTime)
|
||||||
.Take(4)
|
.Take(4)
|
||||||
.Select(x => new BannerOutput
|
.Select(x => new BannerOutput
|
||||||
@ -74,8 +74,8 @@ public class BannerService : BaseService<YD_Event.Core.Entities.Banner>, ITransi
|
|||||||
Id = x.Id,
|
Id = x.Id,
|
||||||
Title = x.EventName,
|
Title = x.EventName,
|
||||||
ImageUrl = x.CoverImage,
|
ImageUrl = x.CoverImage,
|
||||||
LinkType = 1, // 赛事
|
LinkType = LinkType.Event, // 赛事
|
||||||
LinkTarget = x.Id.ToString(),
|
EventId = x.Id,
|
||||||
Sort = 0,
|
Sort = 0,
|
||||||
Status = Core.Enum.AvailabilityStatus.Enable,
|
Status = Core.Enum.AvailabilityStatus.Enable,
|
||||||
CreatedTime = x.CreatedTime
|
CreatedTime = x.CreatedTime
|
||||||
@ -94,7 +94,8 @@ public class BannerService : BaseService<YD_Event.Core.Entities.Banner>, ITransi
|
|||||||
Title = x.Title,
|
Title = x.Title,
|
||||||
ImageUrl = x.ImageUrl,
|
ImageUrl = x.ImageUrl,
|
||||||
LinkType = x.LinkType,
|
LinkType = x.LinkType,
|
||||||
LinkTarget = x.LinkTarget,
|
LinkUrl = x.LinkUrl,
|
||||||
|
EventId = x.EventId,
|
||||||
Sort = x.Sort,
|
Sort = x.Sort,
|
||||||
Status = x.Status,
|
Status = x.Status,
|
||||||
Remark = x.Remark,
|
Remark = x.Remark,
|
||||||
@ -120,7 +121,8 @@ public class BannerService : BaseService<YD_Event.Core.Entities.Banner>, ITransi
|
|||||||
Title = x.Title,
|
Title = x.Title,
|
||||||
ImageUrl = x.ImageUrl,
|
ImageUrl = x.ImageUrl,
|
||||||
LinkType = x.LinkType,
|
LinkType = x.LinkType,
|
||||||
LinkTarget = x.LinkTarget,
|
LinkUrl = x.LinkUrl,
|
||||||
|
EventId = x.EventId,
|
||||||
Sort = x.Sort,
|
Sort = x.Sort,
|
||||||
Status = x.Status,
|
Status = x.Status,
|
||||||
Remark = x.Remark,
|
Remark = x.Remark,
|
||||||
@ -137,6 +139,12 @@ public class BannerService : BaseService<YD_Event.Core.Entities.Banner>, ITransi
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task Add(AddBannerInput input)
|
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>();
|
var entity = input.Adapt<YD_Event.Core.Entities.Banner>();
|
||||||
entity.Id = _idGenerator.NextId();
|
entity.Id = _idGenerator.NextId();
|
||||||
await _repository.InsertAsync(entity);
|
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);
|
var entity = await _repository.GetByIdAsync(input.Id);
|
||||||
if (entity == null) throw new InvalidOperationException("轮播图不存在");
|
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);
|
input.Adapt(entity);
|
||||||
await _repository.UpdateAsync(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>
|
||||||
/// 删除轮播图
|
/// 删除轮播图
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -21,14 +21,19 @@ public class AddBannerInput
|
|||||||
public string ImageUrl { get; set; }
|
public string ImageUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 跳转链接类型(0-图片/无跳转 1-赛事)
|
/// 跳转链接类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int LinkType { get; set; }
|
public LinkType LinkType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 跳转目标(赛事ID或URL)
|
/// 跳转链接URL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string LinkTarget { get; set; }
|
public string LinkUrl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 关联赛事ID
|
||||||
|
/// </summary>
|
||||||
|
public long? EventId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 排序
|
/// 排序
|
||||||
@ -77,8 +82,9 @@ public class BannerOutput
|
|||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public string ImageUrl { get; set; }
|
public string ImageUrl { get; set; }
|
||||||
public int LinkType { get; set; }
|
public LinkType LinkType { get; set; }
|
||||||
public string LinkTarget { get; set; }
|
public string LinkUrl { get; set; }
|
||||||
|
public long? EventId { get; set; }
|
||||||
public int Sort { get; set; }
|
public int Sort { get; set; }
|
||||||
public AvailabilityStatus Status { get; set; }
|
public AvailabilityStatus Status { get; set; }
|
||||||
public string Remark { get; set; }
|
public string Remark { get; set; }
|
||||||
|
|||||||
@ -24,16 +24,22 @@ public class Banner : Entity<long>, ISoftDelete, ICreatedUserId, ICreatedTime, I
|
|||||||
public string ImageUrl { get; set; }
|
public string ImageUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 跳转链接类型(0-图片/无跳转 1-赛事)
|
/// 跳转链接类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "跳转链接类型")]
|
[SugarColumn(ColumnDescription = "跳转链接类型")]
|
||||||
public int LinkType { get; set; }
|
public LinkType LinkType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 跳转目标(赛事ID或URL)
|
/// 跳转链接URL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "跳转目标", Length = 512, IsNullable = true)]
|
[SugarColumn(ColumnDescription = "跳转链接URL", Length = 512, IsNullable = true)]
|
||||||
public string LinkTarget { get; set; }
|
public string LinkUrl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 关联赛事ID
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "关联赛事ID", IsNullable = true)]
|
||||||
|
public long? EventId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 排序
|
/// 排序
|
||||||
@ -78,41 +84,3 @@ public class Banner : Entity<long>, ISoftDelete, ICreatedUserId, ICreatedTime, I
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? UpdatedTime { get; set; }
|
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; }
|
|
||||||
}
|
|
||||||
|
|||||||
47
YD_Event.Core/Entities/BannerConfig.cs
Normal file
47
YD_Event.Core/Entities/BannerConfig.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
24
YD_Event.Core/Enum/LinkType.cs
Normal file
24
YD_Event.Core/Enum/LinkType.cs
Normal 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
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user