feat: add medal module and optimize community entities
1. 新增勋章管理全流程功能,包含实体、DTO、服务层、控制器 2. 重构DotFile实体继承基础实体类 3. 删除UserJournal的无用JournalInstanceId字段 4. 重构CommunityMessage实体字段并新增点赞数、精选标记字段 5. 新增社区点赞、评论、模板言论实体并替换旧有实体文件 6. 更新gitignore忽略PROJECT_STRUCTURE.md文件
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -363,4 +363,5 @@ MigrationBackup/
|
||||
FodyWeavers.xsd
|
||||
|
||||
# Trae IDE related files
|
||||
.trae/
|
||||
.trae/
|
||||
PROJECT_STRUCTURE.md
|
||||
|
||||
73
QYZH.InteractiveMagazine.IService/IMedalService.cs
Normal file
73
QYZH.InteractiveMagazine.IService/IMedalService.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.IService;
|
||||
|
||||
/// <summary>
|
||||
/// 勋章服务接口
|
||||
/// </summary>
|
||||
public interface IMedalService : IBaseService<Medal>
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建勋章
|
||||
/// </summary>
|
||||
/// <param name="input">勋章输入</param>
|
||||
/// <returns>创建的勋章信息</returns>
|
||||
Task<MedalOutput> CreateAsync(MedalInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 更新勋章
|
||||
/// </summary>
|
||||
/// <param name="id">勋章ID</param>
|
||||
/// <param name="input">勋章输入</param>
|
||||
/// <returns>更新后的勋章信息</returns>
|
||||
Task<MedalOutput> UpdateAsync(long id, MedalInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 删除勋章(软删除)
|
||||
/// </summary>
|
||||
/// <param name="id">勋章ID</param>
|
||||
Task DeleteAsync(long id);
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取勋章
|
||||
/// </summary>
|
||||
/// <param name="id">勋章ID</param>
|
||||
/// <returns>勋章信息</returns>
|
||||
Task<MedalOutput> GetByIdAsync(long id);
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询勋章列表
|
||||
/// </summary>
|
||||
/// <param name="input">查询条件</param>
|
||||
/// <returns>分页结果</returns>
|
||||
Task<PageListModel<MedalOutput>> GetListAsync(MedalQueryInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 更新勋章启用/禁用状态
|
||||
/// </summary>
|
||||
/// <param name="id">勋章ID</param>
|
||||
/// <param name="status">状态: 0=禁用, 1=启用</param>
|
||||
Task UpdateStatusAsync(long id, int status);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有启用勋章列表(含当前用户拥有状态)
|
||||
/// </summary>
|
||||
/// <param name="userId">当前用户ID</param>
|
||||
/// <returns>勋章列表</returns>
|
||||
Task<List<WxMedalListOutput>> GetAllMedalsAsync(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户已拥有的勋章列表
|
||||
/// </summary>
|
||||
/// <param name="userId">用户ID</param>
|
||||
/// <returns>用户勋章列表</returns>
|
||||
Task<List<WxUserMedalOutput>> GetUserMedalsAsync(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 激活/获得勋章
|
||||
/// </summary>
|
||||
/// <param name="userId">用户ID</param>
|
||||
/// <param name="input">激活输入</param>
|
||||
Task ActivateMedalAsync(long userId, WxMedalActivateInput input);
|
||||
}
|
||||
247
QYZH.InteractiveMagazine.Models/Dto/Medal/MedalDto.cs
Normal file
247
QYZH.InteractiveMagazine.Models/Dto/Medal/MedalDto.cs
Normal file
@ -0,0 +1,247 @@
|
||||
namespace QYZH.InteractiveMagazine.Models.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// 勋章创建/更新输入
|
||||
/// </summary>
|
||||
public class MedalInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 勋章名称
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获得条件描述
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图片地址
|
||||
/// </summary>
|
||||
public string? ImageUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条件类型: EvolutionCount, FeedingCount等
|
||||
/// </summary>
|
||||
public string ConditionType { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 条件阈值
|
||||
/// </summary>
|
||||
public int ConditionValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 勋章的类型: Pet, Community
|
||||
/// </summary>
|
||||
public string Type { get; set; } = "Pet";
|
||||
|
||||
/// <summary>
|
||||
/// 书id
|
||||
/// </summary>
|
||||
public long JournalId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 勋章输出
|
||||
/// </summary>
|
||||
public class MedalOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键ID
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 勋章名称
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获得条件描述
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图片地址
|
||||
/// </summary>
|
||||
public string? ImageUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条件类型
|
||||
/// </summary>
|
||||
public string ConditionType { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 条件阈值
|
||||
/// </summary>
|
||||
public int ConditionValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 勋章的类型
|
||||
/// </summary>
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 书id
|
||||
/// </summary>
|
||||
public long JournalId { 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 MedalQueryInput : PageQueryModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 勋章名称(模糊查询)
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 勋章的类型: Pet, Community
|
||||
/// </summary>
|
||||
public string? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条件类型
|
||||
/// </summary>
|
||||
public string? ConditionType { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 微信端勋章列表输出(含拥有状态)
|
||||
/// </summary>
|
||||
public class WxMedalListOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 勋章ID
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 勋章名称
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获得条件描述
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图片地址
|
||||
/// </summary>
|
||||
public string? ImageUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条件类型
|
||||
/// </summary>
|
||||
public string ConditionType { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 条件阈值
|
||||
/// </summary>
|
||||
public int ConditionValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 勋章的类型
|
||||
/// </summary>
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 是否已拥有
|
||||
/// </summary>
|
||||
public bool IsOwned { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得时间(未拥有则为null)
|
||||
/// </summary>
|
||||
public DateTime? AwardedAt { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 微信端用户已拥有勋章输出
|
||||
/// </summary>
|
||||
public class WxUserMedalOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 勋章ID
|
||||
/// </summary>
|
||||
public long MedalId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 勋章名称
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获得条件描述
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图片地址
|
||||
/// </summary>
|
||||
public string? ImageUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 勋章的类型
|
||||
/// </summary>
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获得时间
|
||||
/// </summary>
|
||||
public DateTime? AwardedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态: Awarded, Revoked
|
||||
/// </summary>
|
||||
public string Status { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 微信端激活勋章输入
|
||||
/// </summary>
|
||||
public class WxMedalActivateInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 勋章ID
|
||||
/// </summary>
|
||||
public long MedalId { get; set; }
|
||||
}
|
||||
@ -8,58 +8,90 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
[SugarTable("CommunityMessage")]
|
||||
public partial class CommunityMessage : SqlSugarBaseEntity
|
||||
{
|
||||
public CommunityMessage(){
|
||||
public CommunityMessage()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:期刊Id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long JournalId {get;set;}
|
||||
public long JournalId { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:用户Id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:消息内容
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Content {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:配图
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string ImageUrl {get;set;}
|
||||
/// <summary>
|
||||
/// Desc:用户实例期刊Id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long UserJournalId { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:期刊任务Id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long JournalTaskId { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:用户期刊任务回答Id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long JournalTaskAnswerId { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:消息内容
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:排序
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int SortOrder {get;set;}
|
||||
/// <summary>
|
||||
/// Desc:配图
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string ImageUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:是否启用
|
||||
/// Default:b'1'
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public bool IsActive {get;set;}
|
||||
/// <summary>
|
||||
/// Desc:排序
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:消息类型: Article, Quote, Announcement
|
||||
/// Default:Article
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Type {get;set;}
|
||||
/// <summary>
|
||||
/// Desc:是否启用
|
||||
/// Default:b'1'
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:状态: Draft, Published
|
||||
/// Default:Draft
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Status {get;set;}
|
||||
/// <summary>
|
||||
/// Desc:消息类型: Article, Quote, Announcement
|
||||
/// Default:Article
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:点赞数
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int LikeCount { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:是否是精选消息
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int IsFeatured { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
{
|
||||
///<summary>
|
||||
///点赞记录表
|
||||
///</summary>
|
||||
[SugarTable("MessageLike")]
|
||||
public partial class CommunityMessageLike : SqlSugarBaseEntity
|
||||
{
|
||||
public CommunityMessageLike()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:用户Id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:消息Id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long MessageId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:点赞类型
|
||||
/// Default:Like
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
///
|
||||
///</summary>
|
||||
[SugarTable("DotFile")]
|
||||
public partial class DotFile
|
||||
public partial class DotFile : SqlSugarBaseEntity
|
||||
{
|
||||
public DotFile(){
|
||||
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
{
|
||||
///<summary>
|
||||
///点赞记录表
|
||||
///</summary>
|
||||
[SugarTable("MessageLike")]
|
||||
public partial class MessageLike : SqlSugarBaseEntity
|
||||
{
|
||||
public MessageLike(){
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:用户Id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long UserId {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:消息Id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long MessageId {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:点赞类型
|
||||
/// Default:Like
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Type {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:状态: Liked, Cancelled
|
||||
/// Default:Liked
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Status {get;set;}
|
||||
}
|
||||
}
|
||||
@ -29,14 +29,6 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
[SugarColumn(ColumnName = "JournalId")]
|
||||
public long JournalId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:实例化期刊Id(扫码获取的具体期刊实例,可为空表示绑定到期刊模板本身)
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "JournalInstanceId", IsNullable = true)]
|
||||
public long? JournalInstanceId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:关联类型: Read(已读), Favorite(收藏), Subscribe(订阅)
|
||||
/// Default:Read
|
||||
|
||||
410
QYZH.InteractiveMagazine.Service/MedalService.cs
Normal file
410
QYZH.InteractiveMagazine.Service/MedalService.cs
Normal file
@ -0,0 +1,410 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
using QYZH.InteractiveMagazine.Repository;
|
||||
using SqlSugar;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Service;
|
||||
|
||||
/// <summary>
|
||||
/// 勋章服务实现
|
||||
/// </summary>
|
||||
public class MedalService(BaseRepository<Medal> medalRepository, ILogger<MedalService> logger) : BaseRepository<Medal>, IMedalService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 创建勋章
|
||||
/// </summary>
|
||||
public async Task<MedalOutput> CreateAsync(MedalInput input)
|
||||
{
|
||||
logger.LogInformation("正在创建勋章,勋章名称: {Name}", input.Name);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.Name))
|
||||
{
|
||||
throw new BusinessException("勋章名称不能为空", 400);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.ConditionType))
|
||||
{
|
||||
throw new BusinessException("条件类型不能为空", 400);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.Type))
|
||||
{
|
||||
throw new BusinessException("勋章类型不能为空", 400);
|
||||
}
|
||||
|
||||
if (input.ConditionValue < 0)
|
||||
{
|
||||
throw new BusinessException("条件阈值不能为负数", 400);
|
||||
}
|
||||
|
||||
var medal = new Medal
|
||||
{
|
||||
Name = input.Name.Trim(),
|
||||
Description = input.Description,
|
||||
ImageUrl = input.ImageUrl,
|
||||
ConditionType = input.ConditionType,
|
||||
ConditionValue = input.ConditionValue,
|
||||
SortOrder = input.SortOrder,
|
||||
Type = input.Type,
|
||||
JournalId = input.JournalId,
|
||||
CreatedBy = "System",
|
||||
UpdatedBy = "System",
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedAt = DateTime.Now,
|
||||
IsDeleted = false
|
||||
};
|
||||
|
||||
var result = await medalRepository.InsertAsync(medal);
|
||||
if (!result)
|
||||
{
|
||||
logger.LogError("勋章创建失败,勋章名称: {Name}", input.Name);
|
||||
throw new BusinessException("创建勋章失败", 500);
|
||||
}
|
||||
|
||||
logger.LogInformation("勋章创建成功,勋章名称: {Name}, ID: {Id}", input.Name, medal.Id);
|
||||
|
||||
return new MedalOutput
|
||||
{
|
||||
Id = medal.Id,
|
||||
Name = medal.Name,
|
||||
Description = medal.Description,
|
||||
ImageUrl = medal.ImageUrl,
|
||||
ConditionType = medal.ConditionType,
|
||||
ConditionValue = medal.ConditionValue,
|
||||
SortOrder = medal.SortOrder,
|
||||
Type = medal.Type,
|
||||
JournalId = medal.JournalId,
|
||||
CreatedBy = medal.CreatedBy,
|
||||
CreatedAt = medal.CreatedAt,
|
||||
UpdatedBy = medal.UpdatedBy,
|
||||
UpdatedAt = medal.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新勋章
|
||||
/// </summary>
|
||||
public async Task<MedalOutput> UpdateAsync(long id, MedalInput input)
|
||||
{
|
||||
logger.LogInformation("正在更新勋章,ID: {Id}", id);
|
||||
|
||||
var medal = await medalRepository.GetByIdAsync(id);
|
||||
if (medal == null)
|
||||
{
|
||||
logger.LogWarning("未找到要更新的勋章,ID: {Id}", id);
|
||||
throw new BusinessException("勋章不存在", 404);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.Name))
|
||||
{
|
||||
throw new BusinessException("勋章名称不能为空", 400);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.ConditionType))
|
||||
{
|
||||
throw new BusinessException("条件类型不能为空", 400);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.Type))
|
||||
{
|
||||
throw new BusinessException("勋章类型不能为空", 400);
|
||||
}
|
||||
|
||||
if (input.ConditionValue < 0)
|
||||
{
|
||||
throw new BusinessException("条件阈值不能为负数", 400);
|
||||
}
|
||||
|
||||
medal.Name = input.Name.Trim();
|
||||
medal.Description = input.Description;
|
||||
medal.ImageUrl = input.ImageUrl;
|
||||
medal.ConditionType = input.ConditionType;
|
||||
medal.ConditionValue = input.ConditionValue;
|
||||
medal.SortOrder = input.SortOrder;
|
||||
medal.Type = input.Type;
|
||||
medal.JournalId = input.JournalId;
|
||||
medal.UpdatedBy = "System";
|
||||
medal.UpdatedAt = DateTime.Now;
|
||||
|
||||
var result = await medalRepository.UpdateAsync(medal);
|
||||
if (!result)
|
||||
{
|
||||
logger.LogError("勋章更新失败,ID: {Id}", id);
|
||||
throw new BusinessException("更新勋章失败", 500);
|
||||
}
|
||||
|
||||
logger.LogInformation("勋章更新成功,ID: {Id}", id);
|
||||
|
||||
return new MedalOutput
|
||||
{
|
||||
Id = medal.Id,
|
||||
Name = medal.Name,
|
||||
Description = medal.Description,
|
||||
ImageUrl = medal.ImageUrl,
|
||||
ConditionType = medal.ConditionType,
|
||||
ConditionValue = medal.ConditionValue,
|
||||
SortOrder = medal.SortOrder,
|
||||
Type = medal.Type,
|
||||
JournalId = medal.JournalId,
|
||||
CreatedBy = medal.CreatedBy,
|
||||
CreatedAt = medal.CreatedAt,
|
||||
UpdatedBy = medal.UpdatedBy,
|
||||
UpdatedAt = medal.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除勋章(软删除)
|
||||
/// </summary>
|
||||
public async Task DeleteAsync(long id)
|
||||
{
|
||||
logger.LogInformation("正在删除勋章,ID: {Id}", id);
|
||||
|
||||
var medal = await medalRepository.GetByIdAsync(id);
|
||||
if (medal == null)
|
||||
{
|
||||
logger.LogWarning("未找到要删除的勋章,ID: {Id}", id);
|
||||
throw new BusinessException("勋章不存在", 404);
|
||||
}
|
||||
|
||||
var result = await medalRepository.DeleteByIdAsync(id);
|
||||
if (!result)
|
||||
{
|
||||
logger.LogError("勋章删除失败,ID: {Id}", id);
|
||||
throw new BusinessException("删除勋章失败", 500);
|
||||
}
|
||||
|
||||
logger.LogInformation("勋章删除成功,ID: {Id}", id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取勋章
|
||||
/// </summary>
|
||||
public async Task<MedalOutput> GetByIdAsync(long id)
|
||||
{
|
||||
logger.LogInformation("正在获取勋章信息,ID: {Id}", id);
|
||||
|
||||
var medal = await medalRepository.GetByIdAsync(id);
|
||||
if (medal == null)
|
||||
{
|
||||
logger.LogWarning("未找到勋章,ID: {Id}", id);
|
||||
throw new BusinessException("勋章不存在", 404);
|
||||
}
|
||||
|
||||
return new MedalOutput
|
||||
{
|
||||
Id = medal.Id,
|
||||
Name = medal.Name,
|
||||
Description = medal.Description,
|
||||
ImageUrl = medal.ImageUrl,
|
||||
ConditionType = medal.ConditionType,
|
||||
ConditionValue = medal.ConditionValue,
|
||||
SortOrder = medal.SortOrder,
|
||||
Type = medal.Type,
|
||||
JournalId = medal.JournalId,
|
||||
CreatedBy = medal.CreatedBy,
|
||||
CreatedAt = medal.CreatedAt,
|
||||
UpdatedBy = medal.UpdatedBy,
|
||||
UpdatedAt = medal.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询勋章列表
|
||||
/// </summary>
|
||||
public async Task<PageListModel<MedalOutput>> GetListAsync(MedalQueryInput input)
|
||||
{
|
||||
logger.LogInformation("正在查询勋章列表,页码: {PageIndex}, 每页条数: {PageSize}", input.PageIndex, input.PageSize);
|
||||
|
||||
if (input.PageIndex <= 0)
|
||||
{
|
||||
throw new BusinessException("页码必须大于0", 400);
|
||||
}
|
||||
|
||||
if (input.PageSize <= 0 || input.PageSize > 100)
|
||||
{
|
||||
throw new BusinessException("每页条数必须在1-100之间", 400);
|
||||
}
|
||||
|
||||
RefAsync<int> totalNumber = 0;
|
||||
var pageResult = await medalRepository.Queryable()
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), m => m.Name.Contains(input.Name))
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Type), m => m.Type == input.Type)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.ConditionType), m => m.ConditionType == input.ConditionType)
|
||||
.OrderBy(m => m.SortOrder, SqlSugar.OrderByType.Asc)
|
||||
.OrderByDescending(m => m.CreatedAt)
|
||||
.Select(m => new MedalOutput
|
||||
{
|
||||
Id = m.Id,
|
||||
Name = m.Name,
|
||||
Description = m.Description,
|
||||
ImageUrl = m.ImageUrl,
|
||||
ConditionType = m.ConditionType,
|
||||
ConditionValue = m.ConditionValue,
|
||||
SortOrder = m.SortOrder,
|
||||
Type = m.Type,
|
||||
JournalId = m.JournalId,
|
||||
CreatedBy = m.CreatedBy,
|
||||
CreatedAt = m.CreatedAt,
|
||||
UpdatedBy = m.UpdatedBy,
|
||||
UpdatedAt = m.UpdatedAt
|
||||
}, true)
|
||||
.ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);
|
||||
|
||||
return new PageListModel<MedalOutput>(pageResult, input.PageIndex, input.PageSize, totalNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新勋章启用/禁用状态
|
||||
/// </summary>
|
||||
public async Task UpdateStatusAsync(long id, int status)
|
||||
{
|
||||
logger.LogInformation("正在更新勋章状态,ID: {Id}, Status: {Status}", id, status);
|
||||
|
||||
if (status != 0 && status != 1)
|
||||
{
|
||||
throw new BusinessException("状态值无效,只能为0(禁用)或1(启用)", 400);
|
||||
}
|
||||
|
||||
var medal = await medalRepository.GetByIdAsync(id);
|
||||
if (medal == null)
|
||||
{
|
||||
logger.LogWarning("未找到要更新状态的勋章,ID: {Id}", id);
|
||||
throw new BusinessException("勋章不存在", 404);
|
||||
}
|
||||
|
||||
medal.Status = status;
|
||||
medal.UpdatedBy = "System";
|
||||
medal.UpdatedAt = DateTime.Now;
|
||||
|
||||
var result = await medalRepository.UpdateAsync(medal);
|
||||
if (!result)
|
||||
{
|
||||
logger.LogError("勋章状态更新失败,ID: {Id}", id);
|
||||
throw new BusinessException("更新勋章状态失败", 500);
|
||||
}
|
||||
|
||||
logger.LogInformation("勋章状态更新成功,ID: {Id}, Status: {Status}", id, status);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有启用勋章列表(含当前用户拥有状态)
|
||||
/// </summary>
|
||||
public async Task<List<WxMedalListOutput>> GetAllMedalsAsync(long userId)
|
||||
{
|
||||
logger.LogInformation("正在获取所有勋章列表,用户ID: {UserId}", userId);
|
||||
|
||||
var medals = await medalRepository.Queryable()
|
||||
.Where(m => m.Status == 1)
|
||||
.OrderBy(m => m.SortOrder, SqlSugar.OrderByType.Asc)
|
||||
.OrderByDescending(m => m.CreatedAt)
|
||||
.ToListAsync();
|
||||
|
||||
var userMedals = await Context.Queryable<UserMedal>()
|
||||
.Where(um => um.UserId == userId && um.Status == "Awarded")
|
||||
.ToListAsync();
|
||||
|
||||
var userMedalDict = userMedals.ToDictionary(um => um.MedalId, um => um.AwardedAt);
|
||||
|
||||
return medals.Select(m => new WxMedalListOutput
|
||||
{
|
||||
Id = m.Id,
|
||||
Name = m.Name,
|
||||
Description = m.Description,
|
||||
ImageUrl = m.ImageUrl,
|
||||
ConditionType = m.ConditionType,
|
||||
ConditionValue = m.ConditionValue,
|
||||
SortOrder = m.SortOrder,
|
||||
Type = m.Type,
|
||||
IsOwned = userMedalDict.ContainsKey((int)m.Id),
|
||||
AwardedAt = userMedalDict.TryGetValue((int)m.Id, out var awardedAt) ? awardedAt : null
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户已拥有的勋章列表
|
||||
/// </summary>
|
||||
public async Task<List<WxUserMedalOutput>> GetUserMedalsAsync(long userId)
|
||||
{
|
||||
logger.LogInformation("正在获取用户勋章列表,用户ID: {UserId}", userId);
|
||||
|
||||
var result = await Context.Queryable<UserMedal>()
|
||||
.InnerJoin<Medal>((um, m) => um.MedalId == m.Id)
|
||||
.Where((um, m) => um.UserId == userId && um.Status == "Awarded")
|
||||
.OrderByDescending((um, m) => um.AwardedAt)
|
||||
.Select((um, m) => new WxUserMedalOutput
|
||||
{
|
||||
MedalId = m.Id,
|
||||
Name = m.Name,
|
||||
Description = m.Description,
|
||||
ImageUrl = m.ImageUrl,
|
||||
Type = m.Type,
|
||||
AwardedAt = um.AwardedAt,
|
||||
Status = um.Status
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 激活/获得勋章
|
||||
/// </summary>
|
||||
public async Task ActivateMedalAsync(long userId, WxMedalActivateInput input)
|
||||
{
|
||||
logger.LogInformation("用户正在激活勋章,用户ID: {UserId}, 勋章ID: {MedalId}", userId, input.MedalId);
|
||||
|
||||
if (input.MedalId <= 0)
|
||||
{
|
||||
throw new BusinessException("勋章ID无效", 400);
|
||||
}
|
||||
|
||||
var medal = await medalRepository.GetByIdAsync(input.MedalId);
|
||||
if (medal == null)
|
||||
{
|
||||
logger.LogWarning("未找到要激活的勋章,勋章ID: {MedalId}", input.MedalId);
|
||||
throw new BusinessException("勋章不存在", 404);
|
||||
}
|
||||
|
||||
if (medal.Status != 1)
|
||||
{
|
||||
throw new BusinessException("该勋章当前不可获得", 400);
|
||||
}
|
||||
|
||||
var existingUserMedal = await Context.Queryable<UserMedal>()
|
||||
.Where(um => um.UserId == userId && um.MedalId == (int)input.MedalId && um.Status == "Awarded")
|
||||
.FirstAsync();
|
||||
|
||||
if (existingUserMedal != null)
|
||||
{
|
||||
throw new BusinessException("您已拥有该勋章", 400);
|
||||
}
|
||||
|
||||
var userMedal = new UserMedal
|
||||
{
|
||||
UserId = userId,
|
||||
MedalId = (int)input.MedalId,
|
||||
AwardedAt = DateTime.Now,
|
||||
Type = medal.Type,
|
||||
Status = "Awarded",
|
||||
CreatedBy = "System",
|
||||
UpdatedBy = "System",
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedAt = DateTime.Now,
|
||||
IsDeleted = false
|
||||
};
|
||||
|
||||
var insertResult = await Context.Insertable(userMedal).ExecuteCommandAsync();
|
||||
if (insertResult <= 0)
|
||||
{
|
||||
logger.LogError("勋章激活失败,用户ID: {UserId}, 勋章ID: {MedalId}", userId, input.MedalId);
|
||||
throw new BusinessException("激活勋章失败", 500);
|
||||
}
|
||||
|
||||
logger.LogInformation("勋章激活成功,用户ID: {UserId}, 勋章ID: {MedalId}", userId, input.MedalId);
|
||||
}
|
||||
}
|
||||
177
QYZH.InteractiveMagazine.WebApi/Controllers/MedalController.cs
Normal file
177
QYZH.InteractiveMagazine.WebApi/Controllers/MedalController.cs
Normal file
@ -0,0 +1,177 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Enum;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 勋章管理控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
|
||||
public class MedalController : BaseController
|
||||
{
|
||||
private readonly IMedalService _medalService;
|
||||
private readonly ILogger<MedalController> _logger;
|
||||
|
||||
public MedalController(IMedalService medalService, ILogger<MedalController> logger)
|
||||
{
|
||||
_medalService = medalService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建勋章
|
||||
/// </summary>
|
||||
/// <param name="input">勋章信息</param>
|
||||
/// <returns>创建的勋章信息</returns>
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse<MedalOutput>> CreateAsync([FromBody] MedalInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _medalService.CreateAsync(input);
|
||||
return Success(result, "创建勋章成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "创建勋章业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<MedalOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "创建勋章系统异常,参数:{Input}", input);
|
||||
return BaseResponse<MedalOutput>.Fail("创建勋章失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新勋章
|
||||
/// </summary>
|
||||
/// <param name="id">勋章ID</param>
|
||||
/// <param name="input">勋章信息</param>
|
||||
/// <returns>更新后的勋章信息</returns>
|
||||
[HttpPut("{id}")]
|
||||
public async Task<BaseResponse<MedalOutput>> UpdateAsync(long id, [FromBody] MedalInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _medalService.UpdateAsync(id, input);
|
||||
return Success(result, "更新勋章成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "更新勋章业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<MedalOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "更新勋章系统异常,ID:{Id},参数:{Input}", id, input);
|
||||
return BaseResponse<MedalOutput>.Fail("更新勋章失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除勋章
|
||||
/// </summary>
|
||||
/// <param name="id">勋章ID</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<BaseResponse<object>> DeleteAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _medalService.DeleteAsync(id);
|
||||
return Success(new object(), "删除勋章成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "删除勋章业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<object>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "删除勋章系统异常,ID:{Id}", id);
|
||||
return BaseResponse<object>.Fail("删除勋章失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取勋章
|
||||
/// </summary>
|
||||
/// <param name="id">勋章ID</param>
|
||||
/// <returns>勋章信息</returns>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<BaseResponse<MedalOutput>> GetByIdAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _medalService.GetByIdAsync(id);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "获取勋章业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<MedalOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取勋章系统异常,ID:{Id}", id);
|
||||
return BaseResponse<MedalOutput>.Fail("获取勋章信息失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询勋章列表
|
||||
/// </summary>
|
||||
/// <param name="input">查询条件</param>
|
||||
/// <returns>分页结果</returns>
|
||||
[HttpPost("list")]
|
||||
public async Task<BaseResponse<PageListModel<MedalOutput>>> GetListAsync([FromBody] MedalQueryInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _medalService.GetListAsync(input);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "查询勋章列表业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<PageListModel<MedalOutput>>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "查询勋章列表系统异常,参数:{Input}", input);
|
||||
return BaseResponse<PageListModel<MedalOutput>>.Fail("查询勋章列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新勋章启用/禁用状态
|
||||
/// </summary>
|
||||
/// <param name="id">勋章ID</param>
|
||||
/// <param name="status">状态: 0=禁用, 1=启用</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPut("{id}/status")]
|
||||
public async Task<BaseResponse<object>> UpdateStatusAsync(long id, [FromBody] int status)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _medalService.UpdateStatusAsync(id, status);
|
||||
return Success(new object(), status == 1 ? "启用勋章成功" : "禁用勋章成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "更新勋章状态业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<object>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "更新勋章状态系统异常,ID:{Id},Status:{Status}", id, status);
|
||||
return BaseResponse<object>.Fail("更新勋章状态失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.WebApi.Controllers.WeChat;
|
||||
|
||||
/// <summary>
|
||||
/// 小程序勋章控制器
|
||||
/// </summary>
|
||||
public class WeChatMedalController(IMedalService medalService, ILogger<WeChatMedalController> logger) : WeChatBaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有勋章列表(含当前用户拥有状态)
|
||||
/// </summary>
|
||||
[HttpGet("all")]
|
||||
public async Task<BaseResponse<List<WxMedalListOutput>>> GetAllMedals()
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
return BaseResponse<List<WxMedalListOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await medalService.GetAllMedalsAsync(userId.Value);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
logger.LogWarning(ex, "获取勋章列表业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<List<WxMedalListOutput>>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取勋章列表系统异常");
|
||||
return BaseResponse<List<WxMedalListOutput>>.Fail("获取勋章列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户已拥有的勋章列表
|
||||
/// </summary>
|
||||
[HttpGet("my")]
|
||||
public async Task<BaseResponse<List<WxUserMedalOutput>>> GetUserMedals()
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
return BaseResponse<List<WxUserMedalOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await medalService.GetUserMedalsAsync(userId.Value);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
logger.LogWarning(ex, "获取用户勋章列表业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<List<WxUserMedalOutput>>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取用户勋章列表系统异常");
|
||||
return BaseResponse<List<WxUserMedalOutput>>.Fail("获取用户勋章列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 激活/获得勋章
|
||||
/// </summary>
|
||||
[HttpPost("activate")]
|
||||
public async Task<BaseResponse<object>> ActivateMedal([FromBody] WxMedalActivateInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
return BaseResponse<object>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
await medalService.ActivateMedalAsync(userId.Value, input);
|
||||
return Success<object>(null!, "勋章激活成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
logger.LogWarning(ex, "激活勋章业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<object>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "激活勋章系统异常,参数:{Input}", input);
|
||||
return BaseResponse<object>.Fail("激活勋章失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user