refactor: 完善枚举系统与状态类型转换,新增枚举管理接口
1. 为所有枚举添加Description特性用于中文描述 2. 移除实体类中冗余的状态字段注释与定义 3. 将所有枚举状态参数改为int类型转换,统一数据交互格式 4. 新增系统管理枚举查询接口与实现,支持获取所有枚举元数据 5. 调整宠物服务模板状态更新接口参数类型
This commit is contained in:
@ -109,7 +109,7 @@ public class PetService(
|
||||
|
||||
// 查询默认宠物模板(取排序权重最低且状态为Active的模板)
|
||||
var defaultTemplate = await petTemplateRepository.Queryable()
|
||||
.Where(t => t.Status == PetTemplateStatusEnum.Active && !t.IsDeleted)
|
||||
.Where(t => t.Status == (int)PetTemplateStatusEnum.Active && !t.IsDeleted)
|
||||
.OrderBy(t => t.SortOrder)
|
||||
.FirstAsync();
|
||||
|
||||
@ -123,7 +123,7 @@ public class PetService(
|
||||
var initialEvolution = await petEvolutionRepository.Queryable()
|
||||
.Where(e => e.TemplateId == defaultTemplate.Id
|
||||
&& e.PreviousEvolutionId == null
|
||||
&& e.Status == PetEvolutionStatusEnum.Active)
|
||||
&& e.Status == (int)PetEvolutionStatusEnum.Active)
|
||||
.OrderBy(e => e.StageLevel)
|
||||
.FirstAsync();
|
||||
|
||||
@ -137,7 +137,7 @@ public class PetService(
|
||||
FeedingCount = 0,
|
||||
CurrentSkinId = 0,
|
||||
Type = UserPetTypeEnum.Normal,
|
||||
Status = UserPetStatusEnum.Inactive,
|
||||
Status = (int)UserPetStatusEnum.Inactive,
|
||||
IsDeleted = false,
|
||||
CreatedBy = userId.ToString(),
|
||||
CreatedAt = DateTime.Now,
|
||||
@ -173,14 +173,14 @@ public class PetService(
|
||||
return;
|
||||
}
|
||||
|
||||
if (pet.Status != UserPetStatusEnum.Inactive)
|
||||
if (pet.Status != (int)UserPetStatusEnum.Inactive)
|
||||
{
|
||||
logger.LogInformation("用户宠物已非未激活状态,跳过激活,UserId: {UserId}, Status: {Status}", userId, pet.Status);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await petRepository.UpdateAsync(
|
||||
p => new UserPet { Status = UserPetStatusEnum.Active },
|
||||
p => new UserPet { Status = (int)UserPetStatusEnum.Active },
|
||||
p => p.UserId == userId);
|
||||
|
||||
if (!result)
|
||||
@ -226,7 +226,7 @@ public class PetService(
|
||||
}
|
||||
|
||||
// 校验宠物状态
|
||||
if (pet.Status != UserPetStatusEnum.Active)
|
||||
if (pet.Status != (int)UserPetStatusEnum.Active)
|
||||
{
|
||||
logger.LogWarning("喂养失败,宠物未激活,PetId: {PetId}, Status: {Status}", input.PetId, pet.Status);
|
||||
throw new BusinessException("宠物未激活,无法喂养", 400);
|
||||
@ -258,7 +258,7 @@ public class PetService(
|
||||
var nextEvolution = await petEvolutionRepository.Queryable()
|
||||
.Where(e => e.PreviousEvolutionId == pet.CurrentEvolutionId
|
||||
&& e.RequiredGrowth <= growthAfter
|
||||
&& e.Status == PetEvolutionStatusEnum.Active)
|
||||
&& e.Status == (int)PetEvolutionStatusEnum.Active)
|
||||
.OrderBy(e => e.RequiredGrowth, OrderByType.Desc)
|
||||
.FirstAsync();
|
||||
|
||||
@ -291,7 +291,7 @@ public class PetService(
|
||||
GrowthBefore = growthBefore,
|
||||
GrowthAfter = growthAfter,
|
||||
Type = PetFeedingRecordTypeEnum.Normal,
|
||||
Status = PetFeedingRecordStatusEnum.Success,
|
||||
Status = (int)PetFeedingRecordStatusEnum.Success,
|
||||
IsDeleted = false,
|
||||
CreatedBy = userId.ToString(),
|
||||
CreatedAt = DateTime.Now,
|
||||
@ -367,7 +367,7 @@ public class PetService(
|
||||
IconUrl = input.IconUrl,
|
||||
SortOrder = input.SortOrder,
|
||||
Type = Enum.Parse<PetTemplateTypeEnum>(input.Type, true),
|
||||
Status = PetTemplateStatusEnum.Active,
|
||||
Status = (int)PetTemplateStatusEnum.Active,
|
||||
CreatedBy = "System",
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedBy = "System",
|
||||
@ -484,13 +484,13 @@ public class PetService(
|
||||
/// <summary>
|
||||
/// 更新模板状态(启用/禁用)
|
||||
/// </summary>
|
||||
public async Task UpdateTemplateStatusAsync(long id, string status)
|
||||
public async Task UpdateTemplateStatusAsync(long id, int status)
|
||||
{
|
||||
var template = await petTemplateRepository.GetByIdAsync(id);
|
||||
if (template == null || template.IsDeleted)
|
||||
throw new BusinessException("宠物模板不存在", 404);
|
||||
|
||||
template.Status = Enum.Parse<PetTemplateStatusEnum>(status, true);
|
||||
template.Status = status;
|
||||
template.UpdatedBy = "System";
|
||||
template.UpdatedAt = DateTime.Now;
|
||||
await petTemplateRepository.UpdateAsync(template);
|
||||
@ -548,7 +548,7 @@ public class PetService(
|
||||
BaseIntelligence = input.BaseIntelligence,
|
||||
BaseCharm = input.BaseCharm,
|
||||
Type = Enum.Parse<PetEvolutionTypeEnum>(input.Type, true),
|
||||
Status = PetEvolutionStatusEnum.Active,
|
||||
Status = (int)PetEvolutionStatusEnum.Active,
|
||||
CreatedBy = "System",
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedBy = "System",
|
||||
|
||||
Reference in New Issue
Block a user