refactor,feat: 批量代码重构与新增业务模块
1. 重命名枚举项与实体字段,修正类型引用 2. 新增IsNull扩展方法与多项字符串处理扩展 3. 新增大量业务DTO、服务接口与枚举定义 4. 重构RabbitMQ服务实现,替换旧版消息队列组件 5. 优化签到服务的宠物喂养事务逻辑 6. 移除冗余的项目引用与旧版消息队列代码 7. 新增Excel导出、导入模板相关工具方法
This commit is contained in:
@ -68,7 +68,7 @@ public class CheckInService(
|
||||
.Where(p => p.UserId == userId && !p.IsDeleted)
|
||||
.FirstAsync();
|
||||
|
||||
// 6. 事务执行签到相关写操作
|
||||
// 6. 事务执行签到相关写操作(含宠物喂养,统一事务)
|
||||
var result = new CheckInOutput();
|
||||
|
||||
await checkInRecordRepository.UseTranAsync(async () =>
|
||||
@ -107,6 +107,17 @@ public class CheckInService(
|
||||
Description = $"签到奖励(连续{consecutiveDays}天)"
|
||||
});
|
||||
|
||||
// 6d. 如果有活跃宠物,喂养宠物(同一事务内)
|
||||
FeedPetOutput? feedResult = null;
|
||||
if (pet != null && pet.Status == (int)UserPetStatusEnum.Active && growthReward > 0)
|
||||
{
|
||||
feedResult = await petService.FeedPetInTranAsync(userId, new FeedPetInput
|
||||
{
|
||||
PetId = pet.Id,
|
||||
GrowthPoints = growthReward
|
||||
});
|
||||
}
|
||||
|
||||
// 构建返回结果
|
||||
result.RecordId = (long)recordId;
|
||||
result.CheckInDate = today;
|
||||
@ -116,41 +127,17 @@ public class CheckInService(
|
||||
result.PointsBalance = pointsResult.NewBalance;
|
||||
result.GrowthPointsBalance = newGrowthBalance;
|
||||
result.HasPet = pet != null;
|
||||
});
|
||||
|
||||
// 7. 如果用户有活跃宠物,调用 PetService 喂养(含进化检查),独立事务
|
||||
if (pet != null && pet.Status == (int)UserPetStatusEnum.Active && growthReward > 0)
|
||||
{
|
||||
try
|
||||
if (feedResult != null)
|
||||
{
|
||||
var feedResult = await petService.FeedPetAsync(userId, new FeedPetInput
|
||||
{
|
||||
PetId = pet.Id,
|
||||
GrowthPoints = growthReward
|
||||
});
|
||||
|
||||
result.HasEvolved = feedResult.HasEvolved;
|
||||
result.EvolvedStageName = feedResult.EvolvedStageName;
|
||||
|
||||
logger.LogInformation("签到成长值已喂养宠物,PetId: {PetId}, 进化: {HasEvolved}",
|
||||
pet.Id, feedResult.HasEvolved);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning(ex, "签到后喂养宠物失败,PetId: {PetId},将创建补偿任务", pet.Id);
|
||||
});
|
||||
|
||||
await compensationTaskService.CreateTaskAsync(new CreateCompensationTaskInput
|
||||
{
|
||||
TaskType = CompensationTaskTypeEnum.PetFeeding,
|
||||
BusinessSource = "CheckIn",
|
||||
BusinessId = result.RecordId.ToString(),
|
||||
UserId = userId,
|
||||
Payload = new { PetId = pet.Id, GrowthPoints = growthReward },
|
||||
ErrorMessage = ex.Message,
|
||||
ErrorSource = "CheckInService.CheckInAsync → PetService.FeedPetAsync",
|
||||
MaxRetries = 3
|
||||
});
|
||||
}
|
||||
if (pet != null && pet.Status == (int)UserPetStatusEnum.Active && growthReward > 0)
|
||||
{
|
||||
logger.LogInformation("签到成长值已喂养宠物,PetId: {PetId}, 进化: {HasEvolved}",
|
||||
pet.Id, result.HasEvolved);
|
||||
}
|
||||
|
||||
logger.LogInformation("用户签到成功,UserId: {UserId}, 连续{Days}天, 积分+{Points}, 成长值+{Growth}",
|
||||
@ -339,6 +326,17 @@ public class CheckInService(
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
// 如果有活跃宠物,喂养宠物(同一事务内)
|
||||
FeedPetOutput? feedResult = null;
|
||||
if (pet != null && pet.Status == (int)UserPetStatusEnum.Active && growthReward > 0)
|
||||
{
|
||||
feedResult = await petService.FeedPetInTranAsync(userId, new Models.Dto.Pet.FeedPetInput
|
||||
{
|
||||
PetId = pet.Id,
|
||||
GrowthPoints = growthReward
|
||||
});
|
||||
}
|
||||
|
||||
result.RecordId = (long)recordId;
|
||||
result.CheckInDate = targetDate;
|
||||
result.ConsecutiveDays = 0;
|
||||
@ -347,27 +345,17 @@ public class CheckInService(
|
||||
result.PointsBalance = pointsResult.NewBalance;
|
||||
result.GrowthPointsBalance = newGrowthBalance;
|
||||
result.HasPet = pet != null;
|
||||
});
|
||||
|
||||
// 如果有活跃宠物,喂养成长值
|
||||
if (pet != null && pet.Status == (int)UserPetStatusEnum.Active && growthReward > 0)
|
||||
{
|
||||
try
|
||||
if (feedResult != null)
|
||||
{
|
||||
var feedResult = await petService.FeedPetAsync(userId, new Models.Dto.Pet.FeedPetInput
|
||||
{
|
||||
PetId = pet.Id,
|
||||
GrowthPoints = growthReward
|
||||
});
|
||||
|
||||
result.HasEvolved = feedResult.HasEvolved;
|
||||
result.EvolvedStageName = feedResult.EvolvedStageName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning(ex, "补签后喂养宠物失败,PetId: {PetId}", pet.Id);
|
||||
// 补偿机制:如需可在此创建补偿任务
|
||||
}
|
||||
});
|
||||
|
||||
if (pet != null && pet.Status == (int)UserPetStatusEnum.Active && growthReward > 0)
|
||||
{
|
||||
logger.LogInformation("补签成长值已喂养宠物,PetId: {PetId}, 进化: {HasEvolved}",
|
||||
pet.Id, result.HasEvolved);
|
||||
}
|
||||
|
||||
logger.LogInformation("补签成功,UserId: {UserId}, Date: {Date}, 积分+{Points}, 成长值+{Growth}",
|
||||
|
||||
Reference in New Issue
Block a user