feat: 完成宠物模块重构与社区功能开发
本次提交包含多项核心更新:
1. 重构宠物模块数据结构:拆分皮肤图片为独立表,优化Pet、PetEvolution实体,调整字段类型与冗余字段
2. 新增宠物皮肤图片管理表,支持多进化阶段多图片展示
3. 完善宠物DTO,新增当前形态名称、皮肤信息与图片序列返回
4. 新增社区功能模块:
- 微信端社区Feed流、点赞/取消点赞接口
- 后台社区消息管理接口与服务实现
5. 优化商城与背包模块,替换皮肤图片获取逻辑为从新表读取预览图
6. 重构勋章服务,新增规则校验逻辑
7. 调整命名规范,修复原有控制器命名问题
This commit is contained in:
@ -16,11 +16,13 @@ public class PetService(
|
||||
BaseRepository<Pet> petRepository,
|
||||
BaseRepository<PetFeedingRecord> feedingRecordRepository,
|
||||
BaseRepository<PetEvolution> petEvolutionRepository,
|
||||
BaseRepository<PetSkinImage> petSkinImageRepository,
|
||||
BaseRepository<PetSkin> petSkinRepository,
|
||||
ILogger<PetService> logger)
|
||||
: BaseRepository<Pet>, IPetService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取用户宠物信息
|
||||
/// 获取用户宠物信息(含当前形态名称、皮肤图片序列)
|
||||
/// </summary>
|
||||
public async Task<PetOutput?> GetPetByUserIdAsync(long userId)
|
||||
{
|
||||
@ -28,21 +30,56 @@ public class PetService(
|
||||
|
||||
var pet = await petRepository.Queryable()
|
||||
.Where(p => p.UserId == userId)
|
||||
.Select(p => new PetOutput
|
||||
{
|
||||
Id = p.Id,
|
||||
UserId = p.UserId,
|
||||
Name = p.Name,
|
||||
CurrentEvolutionId = p.CurrentEvolutionId,
|
||||
GrowthPoints = p.GrowthPoints,
|
||||
FeedingCount = p.FeedingCount,
|
||||
Type = p.Type,
|
||||
Status = p.Status,
|
||||
CreatedAt = p.CreatedAt
|
||||
})
|
||||
.FirstAsync();
|
||||
|
||||
return pet;
|
||||
if (pet == null) return null;
|
||||
|
||||
// 查询当前进化阶段名称
|
||||
var evolution = await petEvolutionRepository.Queryable()
|
||||
.Where(e => e.Id == pet.CurrentEvolutionId)
|
||||
.FirstAsync();
|
||||
|
||||
// 查询当前皮肤名称
|
||||
string? skinName = null;
|
||||
if (pet.CurrentSkinId > 0)
|
||||
{
|
||||
var skin = await petSkinRepository.Queryable()
|
||||
.Where(s => s.Id == pet.CurrentSkinId && !s.IsDeleted)
|
||||
.FirstAsync();
|
||||
skinName = skin?.Name;
|
||||
}
|
||||
|
||||
// 查询当前形态+当前皮肤 的图片序列
|
||||
var skinId = pet.CurrentSkinId; // 0 = 默认皮肤
|
||||
var images = await petSkinImageRepository.Queryable()
|
||||
.Where(i => i.SkinId == skinId
|
||||
&& i.EvolutionStageId == pet.CurrentEvolutionId
|
||||
&& !i.IsDeleted)
|
||||
.OrderBy(i => i.SortOrder)
|
||||
.Select(i => new SkinImageOutput
|
||||
{
|
||||
Id = i.Id,
|
||||
ImageUrl = i.ImageUrl,
|
||||
SortOrder = i.SortOrder
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return new PetOutput
|
||||
{
|
||||
Id = pet.Id,
|
||||
UserId = pet.UserId,
|
||||
Name = pet.Name,
|
||||
CurrentEvolutionId = pet.CurrentEvolutionId,
|
||||
EvolutionStageName = evolution?.StageName,
|
||||
GrowthPoints = pet.GrowthPoints,
|
||||
FeedingCount = pet.FeedingCount,
|
||||
CurrentSkinId = pet.CurrentSkinId,
|
||||
CurrentSkinName = skinName,
|
||||
CurrentImages = images,
|
||||
Type = pet.Type,
|
||||
Status = pet.Status,
|
||||
CreatedAt = pet.CreatedAt
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -61,13 +98,20 @@ public class PetService(
|
||||
return;
|
||||
}
|
||||
|
||||
// 查询初始进化形态(PreviousEvolutionId 为 null 的即为初始形态)
|
||||
var initialEvolution = await petEvolutionRepository.Queryable()
|
||||
.Where(e => e.PreviousEvolutionId == null && e.Status == "Active")
|
||||
.OrderBy(e => e.StageLevel)
|
||||
.FirstAsync();
|
||||
|
||||
var pet = new Pet
|
||||
{
|
||||
UserId = userId,
|
||||
Name = "小精灵",
|
||||
CurrentEvolutionId = 1,
|
||||
CurrentEvolutionId = initialEvolution?.Id ?? 0,
|
||||
GrowthPoints = 0,
|
||||
FeedingCount = 0,
|
||||
CurrentSkinId = 0,
|
||||
Type = "Normal",
|
||||
Status = "Inactive",
|
||||
IsDeleted = false,
|
||||
@ -84,7 +128,8 @@ public class PetService(
|
||||
throw new Exception("创建宠物失败");
|
||||
}
|
||||
|
||||
logger.LogInformation("用户默认宠物创建成功,UserId: {UserId}, PetId: {PetId}", userId, pet.Id);
|
||||
logger.LogInformation("用户默认宠物创建成功,UserId: {UserId}, PetId: {PetId}, EvolutionId: {EvolutionId}",
|
||||
userId, pet.Id, pet.CurrentEvolutionId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -185,7 +230,7 @@ public class PetService(
|
||||
throw new BusinessException("更新宠物成长值失败", 500);
|
||||
}
|
||||
|
||||
// 进化检查:查找下一阶段进化形态
|
||||
// 进化检查:查找下一阶段进化形态(PreviousEvolutionId 类型为 long?)
|
||||
var nextEvolution = await petEvolutionRepository.Queryable()
|
||||
.Where(e => e.PreviousEvolutionId == pet.CurrentEvolutionId
|
||||
&& e.RequiredGrowth <= growthAfter
|
||||
|
||||
Reference in New Issue
Block a user