Compare commits
2 Commits
edc0122a3b
...
1d467a5fc4
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d467a5fc4 | |||
| 24059dfebb |
61
QYZH.InteractiveMagazine.IService/IBannerService.cs
Normal file
61
QYZH.InteractiveMagazine.IService/IBannerService.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using QYZH.InteractiveMagazine.Models.Dto;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto.Banner;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Entity;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.IService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图服务接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IBannerService : IBaseService<Banner>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 创建轮播图
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">轮播图信息</param>
|
||||||
|
/// <returns>创建后的轮播图信息</returns>
|
||||||
|
Task<BannerOutput> CreateAsync(BannerInput input);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新轮播图
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">轮播图ID</param>
|
||||||
|
/// <param name="input">轮播图信息</param>
|
||||||
|
/// <returns>更新后的轮播图信息</returns>
|
||||||
|
Task<BannerOutput> UpdateAsync(long id, BannerInput input);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除轮播图
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">轮播图ID</param>
|
||||||
|
Task DeleteAsync(long id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据ID获取轮播图
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">轮播图ID</param>
|
||||||
|
/// <returns>轮播图信息</returns>
|
||||||
|
Task<BannerOutput> GetByIdAsync(long id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分页查询轮播图列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">查询条件</param>
|
||||||
|
/// <returns>分页结果</returns>
|
||||||
|
Task<PageListModel<BannerOutput>> GetListAsync(BannerQueryInput input);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新轮播图启用/禁用状态
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">轮播图ID</param>
|
||||||
|
/// <returns>操作结果</returns>
|
||||||
|
Task<bool> UpdateStatusAsync(long id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取启用轮播图列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">展示位置</param>
|
||||||
|
/// <returns>轮播图列表</returns>
|
||||||
|
Task<List<BannerOutput>> GetEnabledListAsync(BannerPositionEnum position);
|
||||||
|
}
|
||||||
59
QYZH.InteractiveMagazine.IService/IMaterialService.cs
Normal file
59
QYZH.InteractiveMagazine.IService/IMaterialService.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using QYZH.InteractiveMagazine.Models.Dto;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto.Material;
|
||||||
|
using MaterialEntity = QYZH.InteractiveMagazine.Models.Entity.Material;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.IService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料服务接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IMaterialService : IBaseService<MaterialEntity>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 创建资料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">资料信息</param>
|
||||||
|
/// <returns>创建后的资料信息</returns>
|
||||||
|
Task<MaterialOutput> CreateAsync(MaterialInput input);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新资料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">资料ID</param>
|
||||||
|
/// <param name="input">资料信息</param>
|
||||||
|
/// <returns>更新后的资料信息</returns>
|
||||||
|
Task<MaterialOutput> UpdateAsync(long id, MaterialInput input);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除资料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">资料ID</param>
|
||||||
|
Task DeleteAsync(long id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据ID获取资料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">资料ID</param>
|
||||||
|
/// <returns>资料信息</returns>
|
||||||
|
Task<MaterialOutput> GetByIdAsync(long id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分页查询资料列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">查询条件</param>
|
||||||
|
/// <returns>分页结果</returns>
|
||||||
|
Task<PageListModel<MaterialOutput>> GetListAsync(MaterialQueryInput input);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新资料启用/禁用状态
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">资料ID</param>
|
||||||
|
/// <returns>操作结果</returns>
|
||||||
|
Task<bool> UpdateStatusAsync(long id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取小程序可见资料列表
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>资料列表</returns>
|
||||||
|
Task<List<MaterialOutput>> GetEnabledListAsync();
|
||||||
|
}
|
||||||
163
QYZH.InteractiveMagazine.Models/Dto/Banner/BannerDto.cs
Normal file
163
QYZH.InteractiveMagazine.Models/Dto/Banner/BannerDto.cs
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
using QYZH.InteractiveMagazine.Common.Helpers;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Models.Dto.Banner;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图创建/更新输入
|
||||||
|
/// </summary>
|
||||||
|
public class BannerInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 标题
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图OSS路径
|
||||||
|
/// </summary>
|
||||||
|
public string ImageUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 展示位置
|
||||||
|
/// </summary>
|
||||||
|
public BannerPositionEnum Position { get; set; } = BannerPositionEnum.Home;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 跳转类型
|
||||||
|
/// </summary>
|
||||||
|
public BannerTargetTypeEnum TargetType { get; set; } = BannerTargetTypeEnum.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 跳转值
|
||||||
|
/// </summary>
|
||||||
|
public string? TargetValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序值,越小越靠前
|
||||||
|
/// </summary>
|
||||||
|
public int Sort { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生效开始时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? StartTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生效结束时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? EndTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备注
|
||||||
|
/// </summary>
|
||||||
|
public string? Remark { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图输出
|
||||||
|
/// </summary>
|
||||||
|
public class BannerOutput
|
||||||
|
{
|
||||||
|
private string _imageUrl = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 主键ID
|
||||||
|
/// </summary>
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 标题
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图完整地址
|
||||||
|
/// </summary>
|
||||||
|
public string ImageUrl
|
||||||
|
{
|
||||||
|
get => DomainHelper.OssFullUrl(_imageUrl);
|
||||||
|
set => _imageUrl = value ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 展示位置
|
||||||
|
/// </summary>
|
||||||
|
public BannerPositionEnum Position { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 跳转类型
|
||||||
|
/// </summary>
|
||||||
|
public BannerTargetTypeEnum TargetType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 跳转值
|
||||||
|
/// </summary>
|
||||||
|
public string? TargetValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序值,越小越靠前
|
||||||
|
/// </summary>
|
||||||
|
public int Sort { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生效开始时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? StartTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生效结束时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? EndTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备注
|
||||||
|
/// </summary>
|
||||||
|
public string? Remark { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 状态
|
||||||
|
/// </summary>
|
||||||
|
public int Status { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建人
|
||||||
|
/// </summary>
|
||||||
|
public string? CreatedBy { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime CreatedAt { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改人
|
||||||
|
/// </summary>
|
||||||
|
public string? UpdatedBy { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? UpdatedAt { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图分页查询输入
|
||||||
|
/// </summary>
|
||||||
|
public class BannerQueryInput : PageQueryModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 标题
|
||||||
|
/// </summary>
|
||||||
|
public string? Title { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 展示位置
|
||||||
|
/// </summary>
|
||||||
|
public BannerPositionEnum? Position { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 状态
|
||||||
|
/// </summary>
|
||||||
|
public int? Status { get; set; }
|
||||||
|
}
|
||||||
200
QYZH.InteractiveMagazine.Models/Dto/Material/MaterialDto.cs
Normal file
200
QYZH.InteractiveMagazine.Models/Dto/Material/MaterialDto.cs
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
using QYZH.InteractiveMagazine.Common.Helpers;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Models.Dto.Material;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料创建/更新输入
|
||||||
|
/// </summary>
|
||||||
|
public class MaterialInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 资料标题
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料名称
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料描述
|
||||||
|
/// </summary>
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序值,越小越靠前
|
||||||
|
/// </summary>
|
||||||
|
public int Sort { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生效开始时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? StartTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生效结束时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? EndTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料文件列表
|
||||||
|
/// </summary>
|
||||||
|
public List<MaterialFileInput> Files { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料文件输入
|
||||||
|
/// </summary>
|
||||||
|
public class MaterialFileInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 文件类型
|
||||||
|
/// </summary>
|
||||||
|
public MaterialFileTypeEnum FileType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件OSS路径
|
||||||
|
/// </summary>
|
||||||
|
public string FileUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件名称
|
||||||
|
/// </summary>
|
||||||
|
public string? FileName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序值,越小越靠前
|
||||||
|
/// </summary>
|
||||||
|
public int Sort { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料输出
|
||||||
|
/// </summary>
|
||||||
|
public class MaterialOutput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 主键ID
|
||||||
|
/// </summary>
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料标题
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料名称
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料描述
|
||||||
|
/// </summary>
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序值,越小越靠前
|
||||||
|
/// </summary>
|
||||||
|
public int Sort { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生效开始时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? StartTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生效结束时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? EndTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 状态
|
||||||
|
/// </summary>
|
||||||
|
public int Status { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建人
|
||||||
|
/// </summary>
|
||||||
|
public string? CreatedBy { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime CreatedAt { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改人
|
||||||
|
/// </summary>
|
||||||
|
public string? UpdatedBy { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? UpdatedAt { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料文件列表
|
||||||
|
/// </summary>
|
||||||
|
public List<MaterialFileOutput> Files { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料文件输出
|
||||||
|
/// </summary>
|
||||||
|
public class MaterialFileOutput
|
||||||
|
{
|
||||||
|
private string _fileUrl = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 主键ID
|
||||||
|
/// </summary>
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件类型
|
||||||
|
/// </summary>
|
||||||
|
public MaterialFileTypeEnum FileType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件完整地址
|
||||||
|
/// </summary>
|
||||||
|
public string FileUrl
|
||||||
|
{
|
||||||
|
get => DomainHelper.OssFullUrl(_fileUrl);
|
||||||
|
set => _fileUrl = value ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件名称
|
||||||
|
/// </summary>
|
||||||
|
public string? FileName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序值,越小越靠前
|
||||||
|
/// </summary>
|
||||||
|
public int Sort { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料分页查询输入
|
||||||
|
/// </summary>
|
||||||
|
public class MaterialQueryInput : PageQueryModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 标题
|
||||||
|
/// </summary>
|
||||||
|
public string? Title { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 名称
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 状态
|
||||||
|
/// </summary>
|
||||||
|
public int? Status { get; set; }
|
||||||
|
}
|
||||||
74
QYZH.InteractiveMagazine.Models/Entity/Banner.cs
Normal file
74
QYZH.InteractiveMagazine.Models/Entity/Banner.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Models.Entity;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("Banner")]
|
||||||
|
public partial class Banner : SqlSugarBaseEntity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:标题
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:轮播图OSS路径
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public string ImageUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:展示位置
|
||||||
|
/// Default:1
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public BannerPositionEnum Position { get; set; } = BannerPositionEnum.Home;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:跳转类型
|
||||||
|
/// Default:0
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public BannerTargetTypeEnum TargetType { get; set; } = BannerTargetTypeEnum.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:跳转值
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public string? TargetValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:排序值,越小越靠前
|
||||||
|
/// Default:0
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public int Sort { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:生效开始时间
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? StartTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:生效结束时间
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? EndTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:备注
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public string? Remark { get; set; }
|
||||||
|
}
|
||||||
52
QYZH.InteractiveMagazine.Models/Entity/Material.cs
Normal file
52
QYZH.InteractiveMagazine.Models/Entity/Material.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Models.Entity;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("Material")]
|
||||||
|
public partial class Material : SqlSugarBaseEntity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:资料标题
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:资料名称
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:资料描述
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:排序值,越小越靠前
|
||||||
|
/// Default:0
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public int Sort { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:生效开始时间
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? StartTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:生效结束时间
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? EndTime { get; set; }
|
||||||
|
}
|
||||||
46
QYZH.InteractiveMagazine.Models/Entity/MaterialFile.cs
Normal file
46
QYZH.InteractiveMagazine.Models/Entity/MaterialFile.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Models.Entity;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料文件表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("MaterialFile")]
|
||||||
|
public partial class MaterialFile : SqlSugarBaseEntity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:资料ID
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public long MaterialId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:文件类型
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public MaterialFileTypeEnum FileType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:文件OSS路径
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public string FileUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:文件名称
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public string? FileName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:排序值,越小越靠前
|
||||||
|
/// Default:0
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public int Sort { get; set; }
|
||||||
|
}
|
||||||
15
QYZH.InteractiveMagazine.Models/Enum/BannerPositionEnum.cs
Normal file
15
QYZH.InteractiveMagazine.Models/Enum/BannerPositionEnum.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图展示位置枚举
|
||||||
|
/// </summary>
|
||||||
|
public enum BannerPositionEnum
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 首页
|
||||||
|
/// </summary>
|
||||||
|
[Description("首页")]
|
||||||
|
Home = 1
|
||||||
|
}
|
||||||
33
QYZH.InteractiveMagazine.Models/Enum/BannerTargetTypeEnum.cs
Normal file
33
QYZH.InteractiveMagazine.Models/Enum/BannerTargetTypeEnum.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图跳转类型枚举
|
||||||
|
/// </summary>
|
||||||
|
public enum BannerTargetTypeEnum
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 无跳转
|
||||||
|
/// </summary>
|
||||||
|
[Description("无跳转")]
|
||||||
|
None = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 链接
|
||||||
|
/// </summary>
|
||||||
|
[Description("链接")]
|
||||||
|
Url = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 期刊
|
||||||
|
/// </summary>
|
||||||
|
[Description("期刊")]
|
||||||
|
Journal = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商品
|
||||||
|
/// </summary>
|
||||||
|
[Description("商品")]
|
||||||
|
Product = 3
|
||||||
|
}
|
||||||
27
QYZH.InteractiveMagazine.Models/Enum/MaterialFileTypeEnum.cs
Normal file
27
QYZH.InteractiveMagazine.Models/Enum/MaterialFileTypeEnum.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料文件类型枚举
|
||||||
|
/// </summary>
|
||||||
|
public enum MaterialFileTypeEnum
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 视频
|
||||||
|
/// </summary>
|
||||||
|
[Description("视频")]
|
||||||
|
Video = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图片
|
||||||
|
/// </summary>
|
||||||
|
[Description("图片")]
|
||||||
|
Image = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 音频
|
||||||
|
/// </summary>
|
||||||
|
[Description("音频")]
|
||||||
|
Audio = 3
|
||||||
|
}
|
||||||
244
QYZH.InteractiveMagazine.Service/BannerService.cs
Normal file
244
QYZH.InteractiveMagazine.Service/BannerService.cs
Normal file
@ -0,0 +1,244 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using QYZH.InteractiveMagazine.Infrastructure.OSS;
|
||||||
|
using QYZH.InteractiveMagazine.IService;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Common;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto.Banner;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Entity;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
using QYZH.InteractiveMagazine.Repository;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Service;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图服务实现
|
||||||
|
/// </summary>
|
||||||
|
public class BannerService(
|
||||||
|
BaseRepository<Banner> bannerRepository,
|
||||||
|
OssService ossService,
|
||||||
|
ILogger<BannerService> logger) : BaseRepository<Banner>, IBannerService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 创建轮播图
|
||||||
|
/// </summary>
|
||||||
|
public async Task<BannerOutput> CreateAsync(BannerInput input)
|
||||||
|
{
|
||||||
|
ValidateInput(input);
|
||||||
|
|
||||||
|
var banner = new Banner
|
||||||
|
{
|
||||||
|
Title = input.Title.Trim(),
|
||||||
|
ImageUrl = input.ImageUrl.Trim(),
|
||||||
|
Position = input.Position,
|
||||||
|
TargetType = input.TargetType,
|
||||||
|
TargetValue = NormalizeTargetValue(input),
|
||||||
|
Sort = input.Sort,
|
||||||
|
StartTime = input.StartTime,
|
||||||
|
EndTime = input.EndTime,
|
||||||
|
Remark = input.Remark,
|
||||||
|
Status = (int)DefaultStatusEnum.Active,
|
||||||
|
IsDeleted = false,
|
||||||
|
CreatedBy = "System",
|
||||||
|
CreatedAt = DateTime.Now,
|
||||||
|
UpdatedBy = "System",
|
||||||
|
UpdatedAt = DateTime.Now
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await bannerRepository.InsertAsync(banner);
|
||||||
|
BusinessException.ThrowIf(!result, "创建轮播图失败", ResultCode.GLOBAL_ERROR);
|
||||||
|
|
||||||
|
if (OssImageHelper.IsTempImage(banner.ImageUrl))
|
||||||
|
{
|
||||||
|
var helper = CreateImageHelper();
|
||||||
|
banner.ImageUrl = await helper.MoveToFormalAsync(banner.ImageUrl, GetBannerFormalFolder(banner.Position, banner.Id));
|
||||||
|
await bannerRepository.UpdateAsync(banner);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogInformation("轮播图创建成功:{Id}", banner.Id);
|
||||||
|
return MapToOutput(banner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新轮播图
|
||||||
|
/// </summary>
|
||||||
|
public async Task<BannerOutput> UpdateAsync(long id, BannerInput input)
|
||||||
|
{
|
||||||
|
ValidateInput(input);
|
||||||
|
|
||||||
|
var banner = await GetValidBannerAsync(id);
|
||||||
|
var newImageUrl = input.ImageUrl.Trim();
|
||||||
|
if (OssImageHelper.IsTempImage(newImageUrl))
|
||||||
|
{
|
||||||
|
var helper = CreateImageHelper();
|
||||||
|
newImageUrl = await helper.MoveToFormalAsync(newImageUrl, GetBannerFormalFolder(input.Position, banner.Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
banner.Title = input.Title.Trim();
|
||||||
|
banner.ImageUrl = newImageUrl;
|
||||||
|
banner.Position = input.Position;
|
||||||
|
banner.TargetType = input.TargetType;
|
||||||
|
banner.TargetValue = NormalizeTargetValue(input);
|
||||||
|
banner.Sort = input.Sort;
|
||||||
|
banner.StartTime = input.StartTime;
|
||||||
|
banner.EndTime = input.EndTime;
|
||||||
|
banner.Remark = input.Remark;
|
||||||
|
banner.UpdatedBy = "System";
|
||||||
|
banner.UpdatedAt = DateTime.Now;
|
||||||
|
|
||||||
|
var result = await bannerRepository.UpdateAsync(banner);
|
||||||
|
BusinessException.ThrowIf(!result, "更新轮播图失败", ResultCode.GLOBAL_ERROR);
|
||||||
|
|
||||||
|
logger.LogInformation("轮播图更新成功:{Id}", banner.Id);
|
||||||
|
return MapToOutput(banner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除轮播图
|
||||||
|
/// </summary>
|
||||||
|
public async Task DeleteAsync(long id)
|
||||||
|
{
|
||||||
|
await GetValidBannerAsync(id);
|
||||||
|
|
||||||
|
var result = await bannerRepository.Context.Updateable<Banner>()
|
||||||
|
.SetColumns(b => new Banner
|
||||||
|
{
|
||||||
|
IsDeleted = true,
|
||||||
|
UpdatedBy = "System",
|
||||||
|
UpdatedAt = DateTime.Now
|
||||||
|
})
|
||||||
|
.Where(b => b.Id == id && !b.IsDeleted)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
|
||||||
|
BusinessException.ThrowIf(result <= 0, "删除轮播图失败", ResultCode.GLOBAL_ERROR);
|
||||||
|
logger.LogInformation("轮播图删除成功:{Id}", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据ID获取轮播图
|
||||||
|
/// </summary>
|
||||||
|
public async Task<BannerOutput> GetByIdAsync(long id)
|
||||||
|
{
|
||||||
|
var banner = await GetValidBannerAsync(id);
|
||||||
|
return MapToOutput(banner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分页查询轮播图列表
|
||||||
|
/// </summary>
|
||||||
|
public async Task<PageListModel<BannerOutput>> GetListAsync(BannerQueryInput input)
|
||||||
|
{
|
||||||
|
BusinessException.ThrowIf(input.PageIndex <= 0, "页码必须大于0", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.PageSize <= 0 || input.PageSize > 100, "每页条数必须在1-100之间", ResultCode.BAD_REQUEST);
|
||||||
|
|
||||||
|
RefAsync<int> totalNumber = 0;
|
||||||
|
var banners = await bannerRepository.Queryable()
|
||||||
|
.Where(b => !b.IsDeleted)
|
||||||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Title), b => b.Title.Contains(input.Title!.Trim()))
|
||||||
|
.WhereIF(input.Position.HasValue, b => b.Position == input.Position!.Value)
|
||||||
|
.WhereIF(input.Status.HasValue, b => b.Status == input.Status!.Value)
|
||||||
|
.OrderBy(b => b.Sort)
|
||||||
|
.OrderByDescending(b => b.CreatedAt)
|
||||||
|
.ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);
|
||||||
|
|
||||||
|
var result = banners.Select(MapToOutput).ToList();
|
||||||
|
return new PageListModel<BannerOutput>(result, input.PageIndex, input.PageSize, totalNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新轮播图启用/禁用状态
|
||||||
|
/// </summary>
|
||||||
|
public async Task<bool> UpdateStatusAsync(long id)
|
||||||
|
{
|
||||||
|
var banner = await GetValidBannerAsync(id);
|
||||||
|
banner.Status = banner.Status == (int)DefaultStatusEnum.Active
|
||||||
|
? (int)DefaultStatusEnum.Inactive
|
||||||
|
: (int)DefaultStatusEnum.Active;
|
||||||
|
banner.UpdatedBy = "System";
|
||||||
|
banner.UpdatedAt = DateTime.Now;
|
||||||
|
|
||||||
|
var result = await bannerRepository.UpdateAsync(banner);
|
||||||
|
BusinessException.ThrowIf(!result, "更新轮播图状态失败", ResultCode.GLOBAL_ERROR);
|
||||||
|
|
||||||
|
logger.LogInformation("轮播图状态更新成功:{Id},状态:{Status}", id, banner.Status);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取启用轮播图列表
|
||||||
|
/// </summary>
|
||||||
|
public async Task<List<BannerOutput>> GetEnabledListAsync(BannerPositionEnum position)
|
||||||
|
{
|
||||||
|
var now = DateTime.Now;
|
||||||
|
var banners = await bannerRepository.Queryable()
|
||||||
|
.Where(b => !b.IsDeleted)
|
||||||
|
.Where(b => b.Status == (int)DefaultStatusEnum.Active)
|
||||||
|
.Where(b => b.Position == position)
|
||||||
|
.Where(b => b.StartTime == null || b.StartTime <= now)
|
||||||
|
.Where(b => b.EndTime == null || b.EndTime >= now)
|
||||||
|
.OrderBy(b => b.Sort)
|
||||||
|
.OrderByDescending(b => b.CreatedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return banners.Select(MapToOutput).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<Banner> GetValidBannerAsync(long id)
|
||||||
|
{
|
||||||
|
var banner = await bannerRepository.Queryable()
|
||||||
|
.Where(b => b.Id == id && !b.IsDeleted)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
BusinessException.ThrowIf(banner == null, "轮播图不存在", ResultCode.NOT_FOUND);
|
||||||
|
return banner;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateInput(BannerInput input)
|
||||||
|
{
|
||||||
|
BusinessException.ThrowIf(string.IsNullOrWhiteSpace(input.Title), "标题不能为空", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.Title.Trim().Length > 100, "标题长度不能超过100个字符", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(string.IsNullOrWhiteSpace(input.ImageUrl), "轮播图不能为空", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.ImageUrl.Trim().Length > 500, "轮播图路径长度不能超过500个字符", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.Sort < 0, "排序值不能小于0", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.StartTime.HasValue && input.EndTime.HasValue && input.EndTime <= input.StartTime, "结束时间必须大于开始时间", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.TargetType != BannerTargetTypeEnum.None && string.IsNullOrWhiteSpace(input.TargetValue), "跳转值不能为空", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(!string.IsNullOrWhiteSpace(input.TargetValue) && input.TargetValue.Length > 500, "跳转值长度不能超过500个字符", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(!string.IsNullOrWhiteSpace(input.Remark) && input.Remark.Length > 500, "备注长度不能超过500个字符", ResultCode.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? NormalizeTargetValue(BannerInput input)
|
||||||
|
{
|
||||||
|
return input.TargetType == BannerTargetTypeEnum.None
|
||||||
|
? null
|
||||||
|
: input.TargetValue?.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private OssImageHelper CreateImageHelper() => new(ossService, logger);
|
||||||
|
|
||||||
|
private static string GetBannerFormalFolder(BannerPositionEnum position, long bannerId)
|
||||||
|
{
|
||||||
|
return $"banner/{position.ToString().ToLowerInvariant()}/{bannerId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BannerOutput MapToOutput(Banner banner)
|
||||||
|
{
|
||||||
|
return new BannerOutput
|
||||||
|
{
|
||||||
|
Id = banner.Id,
|
||||||
|
Title = banner.Title,
|
||||||
|
ImageUrl = banner.ImageUrl,
|
||||||
|
Position = banner.Position,
|
||||||
|
TargetType = banner.TargetType,
|
||||||
|
TargetValue = banner.TargetValue,
|
||||||
|
Sort = banner.Sort,
|
||||||
|
StartTime = banner.StartTime,
|
||||||
|
EndTime = banner.EndTime,
|
||||||
|
Remark = banner.Remark,
|
||||||
|
Status = banner.Status,
|
||||||
|
CreatedBy = banner.CreatedBy,
|
||||||
|
CreatedAt = banner.CreatedAt,
|
||||||
|
UpdatedBy = banner.UpdatedBy,
|
||||||
|
UpdatedAt = banner.UpdatedAt
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
334
QYZH.InteractiveMagazine.Service/MaterialService.cs
Normal file
334
QYZH.InteractiveMagazine.Service/MaterialService.cs
Normal file
@ -0,0 +1,334 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using QYZH.InteractiveMagazine.Infrastructure.OSS;
|
||||||
|
using QYZH.InteractiveMagazine.IService;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Common;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto.Material;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
using QYZH.InteractiveMagazine.Repository;
|
||||||
|
using SqlSugar;
|
||||||
|
using MaterialEntity = QYZH.InteractiveMagazine.Models.Entity.Material;
|
||||||
|
using MaterialFileEntity = QYZH.InteractiveMagazine.Models.Entity.MaterialFile;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Service;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料服务实现
|
||||||
|
/// </summary>
|
||||||
|
public class MaterialService(
|
||||||
|
BaseRepository<MaterialEntity> materialRepository,
|
||||||
|
BaseRepository<MaterialFileEntity> materialFileRepository,
|
||||||
|
OssService ossService,
|
||||||
|
ILogger<MaterialService> logger) : BaseRepository<MaterialEntity>, IMaterialService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 创建资料
|
||||||
|
/// </summary>
|
||||||
|
public async Task<MaterialOutput> CreateAsync(MaterialInput input)
|
||||||
|
{
|
||||||
|
ValidateInput(input);
|
||||||
|
|
||||||
|
var material = new MaterialEntity
|
||||||
|
{
|
||||||
|
Title = input.Title.Trim(),
|
||||||
|
Name = Normalize(input.Name),
|
||||||
|
Description = Normalize(input.Description),
|
||||||
|
Sort = input.Sort,
|
||||||
|
StartTime = input.StartTime,
|
||||||
|
EndTime = input.EndTime,
|
||||||
|
Status = (int)DefaultStatusEnum.Active,
|
||||||
|
IsDeleted = false,
|
||||||
|
CreatedBy = "System",
|
||||||
|
CreatedAt = DateTime.Now,
|
||||||
|
UpdatedBy = "System",
|
||||||
|
UpdatedAt = DateTime.Now
|
||||||
|
};
|
||||||
|
|
||||||
|
await materialRepository.UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
var materialResult = await materialRepository.InsertAsync(material);
|
||||||
|
BusinessException.ThrowIf(!materialResult, "创建资料失败", ResultCode.GLOBAL_ERROR);
|
||||||
|
|
||||||
|
var files = await BuildFileEntitiesAsync(material.Id, input.Files);
|
||||||
|
var fileResult = await materialFileRepository.Context.Insertable(files).ExecuteCommandAsync();
|
||||||
|
BusinessException.ThrowIf(fileResult <= 0, "创建资料文件失败", ResultCode.GLOBAL_ERROR);
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.LogInformation("资料创建成功:{Id}", material.Id);
|
||||||
|
return await GetByIdAsync(material.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新资料
|
||||||
|
/// </summary>
|
||||||
|
public async Task<MaterialOutput> UpdateAsync(long id, MaterialInput input)
|
||||||
|
{
|
||||||
|
ValidateInput(input);
|
||||||
|
|
||||||
|
var material = await GetValidMaterialAsync(id);
|
||||||
|
material.Title = input.Title.Trim();
|
||||||
|
material.Name = Normalize(input.Name);
|
||||||
|
material.Description = Normalize(input.Description);
|
||||||
|
material.Sort = input.Sort;
|
||||||
|
material.StartTime = input.StartTime;
|
||||||
|
material.EndTime = input.EndTime;
|
||||||
|
material.UpdatedBy = "System";
|
||||||
|
material.UpdatedAt = DateTime.Now;
|
||||||
|
|
||||||
|
await materialRepository.UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
var materialResult = await materialRepository.UpdateAsync(material);
|
||||||
|
BusinessException.ThrowIf(!materialResult, "更新资料失败", ResultCode.GLOBAL_ERROR);
|
||||||
|
|
||||||
|
await SoftDeleteFilesAsync(material.Id);
|
||||||
|
var files = await BuildFileEntitiesAsync(material.Id, input.Files);
|
||||||
|
var fileResult = await materialFileRepository.Context.Insertable(files).ExecuteCommandAsync();
|
||||||
|
BusinessException.ThrowIf(fileResult <= 0, "更新资料文件失败", ResultCode.GLOBAL_ERROR);
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.LogInformation("资料更新成功:{Id}", material.Id);
|
||||||
|
return await GetByIdAsync(material.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除资料
|
||||||
|
/// </summary>
|
||||||
|
public async Task DeleteAsync(long id)
|
||||||
|
{
|
||||||
|
await GetValidMaterialAsync(id);
|
||||||
|
|
||||||
|
await materialRepository.UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
var materialResult = await materialRepository.Context.Updateable<MaterialEntity>()
|
||||||
|
.SetColumns(m => new MaterialEntity
|
||||||
|
{
|
||||||
|
IsDeleted = true,
|
||||||
|
UpdatedBy = "System",
|
||||||
|
UpdatedAt = DateTime.Now
|
||||||
|
})
|
||||||
|
.Where(m => m.Id == id && !m.IsDeleted)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
BusinessException.ThrowIf(materialResult <= 0, "删除资料失败", ResultCode.GLOBAL_ERROR);
|
||||||
|
|
||||||
|
await SoftDeleteFilesAsync(id);
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.LogInformation("资料删除成功:{Id}", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据ID获取资料
|
||||||
|
/// </summary>
|
||||||
|
public async Task<MaterialOutput> GetByIdAsync(long id)
|
||||||
|
{
|
||||||
|
var material = await GetValidMaterialAsync(id);
|
||||||
|
var files = await GetFilesAsync(material.Id);
|
||||||
|
return MapToOutput(material, files);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分页查询资料列表
|
||||||
|
/// </summary>
|
||||||
|
public async Task<PageListModel<MaterialOutput>> GetListAsync(MaterialQueryInput input)
|
||||||
|
{
|
||||||
|
BusinessException.ThrowIf(input.PageIndex <= 0, "页码必须大于0", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.PageSize <= 0 || input.PageSize > 100, "每页条数必须在1-100之间", ResultCode.BAD_REQUEST);
|
||||||
|
|
||||||
|
RefAsync<int> totalNumber = 0;
|
||||||
|
var materials = await materialRepository.Queryable()
|
||||||
|
.Where(m => !m.IsDeleted)
|
||||||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Title), m => m.Title.Contains(input.Title!.Trim()))
|
||||||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), m => m.Name != null && m.Name.Contains(input.Name!.Trim()))
|
||||||
|
.WhereIF(input.Status.HasValue, m => m.Status == input.Status!.Value)
|
||||||
|
.OrderBy(m => m.Sort)
|
||||||
|
.OrderByDescending(m => m.CreatedAt)
|
||||||
|
.ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);
|
||||||
|
|
||||||
|
var result = await BuildOutputsAsync(materials);
|
||||||
|
return new PageListModel<MaterialOutput>(result, input.PageIndex, input.PageSize, totalNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新资料启用/禁用状态
|
||||||
|
/// </summary>
|
||||||
|
public async Task<bool> UpdateStatusAsync(long id)
|
||||||
|
{
|
||||||
|
var material = await GetValidMaterialAsync(id);
|
||||||
|
material.Status = material.Status == (int)DefaultStatusEnum.Active
|
||||||
|
? (int)DefaultStatusEnum.Inactive
|
||||||
|
: (int)DefaultStatusEnum.Active;
|
||||||
|
material.UpdatedBy = "System";
|
||||||
|
material.UpdatedAt = DateTime.Now;
|
||||||
|
|
||||||
|
var result = await materialRepository.UpdateAsync(material);
|
||||||
|
BusinessException.ThrowIf(!result, "更新资料状态失败", ResultCode.GLOBAL_ERROR);
|
||||||
|
|
||||||
|
logger.LogInformation("资料状态更新成功:{Id},状态:{Status}", id, material.Status);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取小程序可见资料列表
|
||||||
|
/// </summary>
|
||||||
|
public async Task<List<MaterialOutput>> GetEnabledListAsync()
|
||||||
|
{
|
||||||
|
var now = DateTime.Now;
|
||||||
|
var materials = await materialRepository.Queryable()
|
||||||
|
.Where(m => !m.IsDeleted)
|
||||||
|
.Where(m => m.Status == (int)DefaultStatusEnum.Active)
|
||||||
|
.Where(m => m.StartTime == null || m.StartTime <= now)
|
||||||
|
.Where(m => m.EndTime == null || m.EndTime >= now)
|
||||||
|
.OrderBy(m => m.Sort)
|
||||||
|
.OrderByDescending(m => m.CreatedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return await BuildOutputsAsync(materials);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<MaterialEntity> GetValidMaterialAsync(long id)
|
||||||
|
{
|
||||||
|
var material = await materialRepository.Queryable()
|
||||||
|
.Where(m => m.Id == id && !m.IsDeleted)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
BusinessException.ThrowIf(material == null, "资料不存在", ResultCode.NOT_FOUND);
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<MaterialFileEntity>> BuildFileEntitiesAsync(long materialId, List<MaterialFileInput> inputs)
|
||||||
|
{
|
||||||
|
var helper = CreateImageHelper();
|
||||||
|
var files = new List<MaterialFileEntity>();
|
||||||
|
|
||||||
|
foreach (var input in inputs.OrderBy(f => f.Sort))
|
||||||
|
{
|
||||||
|
var file = new MaterialFileEntity
|
||||||
|
{
|
||||||
|
MaterialId = materialId,
|
||||||
|
FileType = input.FileType,
|
||||||
|
FileUrl = input.FileUrl.Trim(),
|
||||||
|
FileName = Normalize(input.FileName),
|
||||||
|
Sort = input.Sort,
|
||||||
|
Status = (int)DefaultStatusEnum.Active,
|
||||||
|
IsDeleted = false,
|
||||||
|
CreatedBy = "System",
|
||||||
|
CreatedAt = DateTime.Now,
|
||||||
|
UpdatedBy = "System",
|
||||||
|
UpdatedAt = DateTime.Now
|
||||||
|
};
|
||||||
|
|
||||||
|
if (OssImageHelper.IsTempImage(file.FileUrl))
|
||||||
|
{
|
||||||
|
file.FileUrl = await helper.MoveToFormalAsync(file.FileUrl, GetMaterialFormalFolder(materialId, file.FileType, file.Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
files.Add(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SoftDeleteFilesAsync(long materialId)
|
||||||
|
{
|
||||||
|
await materialFileRepository.Context.Updateable<MaterialFileEntity>()
|
||||||
|
.SetColumns(f => new MaterialFileEntity
|
||||||
|
{
|
||||||
|
IsDeleted = true,
|
||||||
|
UpdatedBy = "System",
|
||||||
|
UpdatedAt = DateTime.Now
|
||||||
|
})
|
||||||
|
.Where(f => f.MaterialId == materialId && !f.IsDeleted)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<MaterialFileEntity>> GetFilesAsync(long materialId)
|
||||||
|
{
|
||||||
|
return await materialFileRepository.Queryable()
|
||||||
|
.Where(f => f.MaterialId == materialId && !f.IsDeleted)
|
||||||
|
.OrderBy(f => f.Sort)
|
||||||
|
.OrderByDescending(f => f.CreatedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<MaterialOutput>> BuildOutputsAsync(List<MaterialEntity> materials)
|
||||||
|
{
|
||||||
|
if (materials.Count == 0)
|
||||||
|
{
|
||||||
|
return new List<MaterialOutput>();
|
||||||
|
}
|
||||||
|
|
||||||
|
var materialIds = materials.Select(m => m.Id).ToList();
|
||||||
|
var files = await materialFileRepository.Queryable()
|
||||||
|
.Where(f => materialIds.Contains(f.MaterialId) && !f.IsDeleted)
|
||||||
|
.OrderBy(f => f.Sort)
|
||||||
|
.OrderByDescending(f => f.CreatedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
var fileMap = files.GroupBy(f => f.MaterialId).ToDictionary(g => g.Key, g => g.ToList());
|
||||||
|
|
||||||
|
return materials.Select(m => MapToOutput(m, fileMap.GetValueOrDefault(m.Id) ?? new List<MaterialFileEntity>())).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateInput(MaterialInput input)
|
||||||
|
{
|
||||||
|
BusinessException.ThrowIf(string.IsNullOrWhiteSpace(input.Title), "资料标题不能为空", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.Title.Trim().Length > 100, "资料标题长度不能超过100个字符", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(!string.IsNullOrWhiteSpace(input.Name) && input.Name.Length > 100, "资料名称长度不能超过100个字符", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(!string.IsNullOrWhiteSpace(input.Description) && input.Description.Length > 1000, "资料描述长度不能超过1000个字符", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.Sort < 0, "排序值不能小于0", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.StartTime.HasValue && input.EndTime.HasValue && input.EndTime <= input.StartTime, "结束时间必须大于开始时间", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(input.Files == null || input.Files.Count == 0, "资料文件不能为空", ResultCode.BAD_REQUEST);
|
||||||
|
|
||||||
|
foreach (var file in input.Files)
|
||||||
|
{
|
||||||
|
BusinessException.ThrowIf(!Enum.IsDefined(typeof(MaterialFileTypeEnum), file.FileType), "资料文件类型不正确", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(string.IsNullOrWhiteSpace(file.FileUrl), "资料文件地址不能为空", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(file.FileUrl.Trim().Length > 500, "资料文件地址长度不能超过500个字符", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(!string.IsNullOrWhiteSpace(file.FileName) && file.FileName.Length > 100, "资料文件名称长度不能超过100个字符", ResultCode.BAD_REQUEST);
|
||||||
|
BusinessException.ThrowIf(file.Sort < 0, "资料文件排序值不能小于0", ResultCode.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private OssImageHelper CreateImageHelper() => new(ossService, logger);
|
||||||
|
|
||||||
|
private static string GetMaterialFormalFolder(long materialId, MaterialFileTypeEnum fileType, long fileId)
|
||||||
|
{
|
||||||
|
return $"material/{materialId}/{fileType.ToString().ToLowerInvariant()}/{fileId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? Normalize(string? value)
|
||||||
|
{
|
||||||
|
return string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MaterialOutput MapToOutput(MaterialEntity material, List<MaterialFileEntity> files)
|
||||||
|
{
|
||||||
|
return new MaterialOutput
|
||||||
|
{
|
||||||
|
Id = material.Id,
|
||||||
|
Title = material.Title,
|
||||||
|
Name = material.Name,
|
||||||
|
Description = material.Description,
|
||||||
|
Sort = material.Sort,
|
||||||
|
StartTime = material.StartTime,
|
||||||
|
EndTime = material.EndTime,
|
||||||
|
Status = material.Status,
|
||||||
|
CreatedBy = material.CreatedBy,
|
||||||
|
CreatedAt = material.CreatedAt,
|
||||||
|
UpdatedBy = material.UpdatedBy,
|
||||||
|
UpdatedAt = material.UpdatedAt,
|
||||||
|
Files = files.Select(MapFileToOutput).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MaterialFileOutput MapFileToOutput(MaterialFileEntity file)
|
||||||
|
{
|
||||||
|
return new MaterialFileOutput
|
||||||
|
{
|
||||||
|
Id = file.Id,
|
||||||
|
FileType = file.FileType,
|
||||||
|
FileUrl = file.FileUrl,
|
||||||
|
FileName = file.FileName,
|
||||||
|
Sort = file.Sort
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using QYZH.InteractiveMagazine.IService;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto.Banner;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.WeChatApi.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 小程序轮播图控制器
|
||||||
|
/// </summary>
|
||||||
|
public class BannerController(IBannerService bannerService) : WeChatBaseController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取启用轮播图列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">展示位置</param>
|
||||||
|
/// <returns>轮播图列表</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<BaseResponse<List<BannerOutput>>> GetListAsync([FromQuery] BannerPositionEnum position = BannerPositionEnum.Home)
|
||||||
|
{
|
||||||
|
var result = await bannerService.GetEnabledListAsync(position);
|
||||||
|
return Success(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using QYZH.InteractiveMagazine.IService;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto.Material;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.WeChatApi.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 小程序资料控制器
|
||||||
|
/// </summary>
|
||||||
|
public class MaterialController(IMaterialService materialService) : WeChatBaseController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取可见资料列表
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>资料列表</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<BaseResponse<List<MaterialOutput>>> GetListAsync()
|
||||||
|
{
|
||||||
|
var result = await materialService.GetEnabledListAsync();
|
||||||
|
return Success(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using QYZH.InteractiveMagazine.IService;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto.Banner;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮播图管理控制器
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
|
||||||
|
public class BannerController(IBannerService bannerService) : BaseController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 创建轮播图
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">轮播图信息</param>
|
||||||
|
/// <returns>创建后的轮播图信息</returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<BaseResponse<BannerOutput>> CreateAsync([FromBody] BannerInput input)
|
||||||
|
{
|
||||||
|
var result = await bannerService.CreateAsync(input);
|
||||||
|
return Success(result, "创建轮播图成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新轮播图
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">轮播图ID</param>
|
||||||
|
/// <param name="input">轮播图信息</param>
|
||||||
|
/// <returns>更新后的轮播图信息</returns>
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public async Task<BaseResponse<BannerOutput>> UpdateAsync(long id, [FromBody] BannerInput input)
|
||||||
|
{
|
||||||
|
var result = await bannerService.UpdateAsync(id, input);
|
||||||
|
return Success(result, "更新轮播图成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除轮播图
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">轮播图ID</param>
|
||||||
|
/// <returns>操作结果</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<BaseResponse<object>> DeleteAsync(long id)
|
||||||
|
{
|
||||||
|
await bannerService.DeleteAsync(id);
|
||||||
|
return Success(new object(), "删除轮播图成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据ID获取轮播图
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">轮播图ID</param>
|
||||||
|
/// <returns>轮播图信息</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<BaseResponse<BannerOutput>> GetByIdAsync(long id)
|
||||||
|
{
|
||||||
|
var result = await bannerService.GetByIdAsync(id);
|
||||||
|
return Success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分页查询轮播图列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">查询条件</param>
|
||||||
|
/// <returns>分页结果</returns>
|
||||||
|
[HttpPost("list")]
|
||||||
|
public async Task<BaseResponse<PageListModel<BannerOutput>>> GetListAsync([FromBody] BannerQueryInput input)
|
||||||
|
{
|
||||||
|
var result = await bannerService.GetListAsync(input);
|
||||||
|
return Success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新轮播图启用/禁用状态
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">轮播图ID</param>
|
||||||
|
/// <returns>操作结果</returns>
|
||||||
|
[HttpPut("{id}/status")]
|
||||||
|
public async Task<BaseResponse<bool>> UpdateStatusAsync(long id)
|
||||||
|
{
|
||||||
|
var result = await bannerService.UpdateStatusAsync(id);
|
||||||
|
return Success(result, "更新轮播图状态成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using QYZH.InteractiveMagazine.IService;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Dto.Material;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资料管理控制器
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
|
||||||
|
public class MaterialController(IMaterialService materialService) : BaseController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 创建资料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">资料信息</param>
|
||||||
|
/// <returns>创建后的资料信息</returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<BaseResponse<MaterialOutput>> CreateAsync([FromBody] MaterialInput input)
|
||||||
|
{
|
||||||
|
var result = await materialService.CreateAsync(input);
|
||||||
|
return Success(result, "创建资料成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新资料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">资料ID</param>
|
||||||
|
/// <param name="input">资料信息</param>
|
||||||
|
/// <returns>更新后的资料信息</returns>
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public async Task<BaseResponse<MaterialOutput>> UpdateAsync(long id, [FromBody] MaterialInput input)
|
||||||
|
{
|
||||||
|
var result = await materialService.UpdateAsync(id, input);
|
||||||
|
return Success(result, "更新资料成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除资料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">资料ID</param>
|
||||||
|
/// <returns>操作结果</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<BaseResponse<object>> DeleteAsync(long id)
|
||||||
|
{
|
||||||
|
await materialService.DeleteAsync(id);
|
||||||
|
return Success(new object(), "删除资料成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据ID获取资料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">资料ID</param>
|
||||||
|
/// <returns>资料信息</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<BaseResponse<MaterialOutput>> GetByIdAsync(long id)
|
||||||
|
{
|
||||||
|
var result = await materialService.GetByIdAsync(id);
|
||||||
|
return Success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分页查询资料列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">查询条件</param>
|
||||||
|
/// <returns>分页结果</returns>
|
||||||
|
[HttpPost("list")]
|
||||||
|
public async Task<BaseResponse<PageListModel<MaterialOutput>>> GetListAsync([FromBody] MaterialQueryInput input)
|
||||||
|
{
|
||||||
|
var result = await materialService.GetListAsync(input);
|
||||||
|
return Success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新资料启用/禁用状态
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">资料ID</param>
|
||||||
|
/// <returns>操作结果</returns>
|
||||||
|
[HttpPut("{id}/status")]
|
||||||
|
public async Task<BaseResponse<bool>> UpdateStatusAsync(long id)
|
||||||
|
{
|
||||||
|
var result = await materialService.UpdateStatusAsync(id);
|
||||||
|
return Success(result, "更新资料状态成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user