refactor: 重构状态更新接口,新增商品管理与勋章规则配置

1. 重构用户、宠物模板、勋章、管理员状态更新接口,移除冗余参数改为自动切换状态
2. 重命名宠物背景枚举为宠物皮肤,调整商品状态字段为枚举类型
3. 新增商品上下架状态管理接口与对应逻辑
4. 新增勋章规则配置系统,支持动态加载可用表和字段
5. 优化商品查询与展示逻辑,适配新的状态字段
This commit is contained in:
glz
2026-06-09 11:41:28 +08:00
parent 0126c6b097
commit 1d86580db7
24 changed files with 405 additions and 61 deletions

View File

@ -1,10 +1,12 @@
using System.Text.Json;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using QYZH.InteractiveMagazine.IService;
using QYZH.InteractiveMagazine.Models.Common;
using QYZH.InteractiveMagazine.Models.Dto;
using QYZH.InteractiveMagazine.Models.Entity;
using QYZH.InteractiveMagazine.Models.Enum;
using QYZH.InteractiveMagazine.Models.Settings;
using QYZH.InteractiveMagazine.Repository;
using SqlSugar;
@ -13,7 +15,7 @@ namespace QYZH.InteractiveMagazine.Service;
/// <summary>
/// 勋章服务实现
/// </summary>
public class MedalService(BaseRepository<Medal> medalRepository, ILogger<MedalService> logger) : BaseRepository<Medal>, IMedalService
public class MedalService(BaseRepository<Medal> medalRepository, IOptions<MedalRuleConfigSettings> medalRuleConfig, ILogger<MedalService> logger) : BaseRepository<Medal>, IMedalService
{
/// <summary>
@ -257,15 +259,8 @@ public class MedalService(BaseRepository<Medal> medalRepository, ILogger<MedalSe
/// <summary>
/// 更新勋章启用/禁用状态
/// </summary>
public async Task UpdateStatusAsync(long id, int status)
public async Task<bool> UpdateStatusAsync(long id)
{
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)
{
@ -273,7 +268,7 @@ public class MedalService(BaseRepository<Medal> medalRepository, ILogger<MedalSe
throw new BusinessException("勋章不存在", 404);
}
medal.Status = status;
medal.Status = medal.Status == 0 ? 1 : 0;
medal.UpdatedBy = "System";
medal.UpdatedAt = DateTime.Now;
@ -283,8 +278,9 @@ public class MedalService(BaseRepository<Medal> medalRepository, ILogger<MedalSe
logger.LogError("勋章状态更新失败ID: {Id}", id);
throw new BusinessException("更新勋章状态失败", 500);
}
logger.LogInformation("勋章状态更新成功ID: {Id}, Status: {Status}", id, status);
logger.LogInformation("勋章状态更新成功ID: {Id}, Status: {Status}", id, medal.Status);
return result;
}
/// <summary>
@ -423,6 +419,40 @@ public class MedalService(BaseRepository<Medal> medalRepository, ILogger<MedalSe
logger.LogInformation("勋章激活成功用户ID: {UserId}, 勋章ID: {MedalId}", userId, input.MedalId);
}
/// <summary>
/// 获取规则配置中可用的目标表列表
/// </summary>
public Task<List<MedalRuleTableOptionOutput>> GetAvailableTablesAsync()
{
var tables = medalRuleConfig.Value.Tables?.Select(t => new MedalRuleTableOptionOutput
{
TableName = t.TableName,
DisplayName = t.DisplayName
}).ToList() ?? new List<MedalRuleTableOptionOutput>();
return Task.FromResult(tables);
}
/// <summary>
/// 获取指定表的可用字段列表
/// </summary>
public Task<List<MedalRuleFieldOptionOutput>> GetTableFieldsAsync(string tableName)
{
var table = medalRuleConfig.Value.Tables?.FirstOrDefault(t => t.TableName == tableName);
if (table == null)
{
return Task.FromResult(new List<MedalRuleFieldOptionOutput>());
}
var fields = table.Fields.Select(f => new MedalRuleFieldOptionOutput
{
FieldName = f.FieldName,
DisplayName = f.DisplayName
}).ToList();
return Task.FromResult(fields);
}
#region
/// <summary>