refactor: 批量新增枚举类型并完成实体、DTO、服务层枚举替换
- 新增30+业务枚举类型覆盖用户、宠物、商城、社区、积分等模块 - 完成实体类、DTO、服务层的字符串枚举替换为强类型枚举 - 修复用户状态枚举名称变更,将Frozen改为Disabled - 新增批量发布社区消息接口与控制器实现 - 新增操作日志、积分管理、补偿任务相关服务与DTO
This commit is contained in:
@ -1,10 +1,13 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using QYZH.InteractiveMagazine.Common.Extensions;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto.CheckIn;
|
||||
using QYZH.InteractiveMagazine.Models.Dto.Compensation;
|
||||
using QYZH.InteractiveMagazine.Models.Dto.Pet;
|
||||
using QYZH.InteractiveMagazine.Models.Dto.Points;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
using QYZH.InteractiveMagazine.Models.Enum;
|
||||
using QYZH.InteractiveMagazine.Repository;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Service;
|
||||
@ -16,6 +19,7 @@ public class CheckInService(
|
||||
BaseRepository<CheckInRecord> checkInRecordRepository,
|
||||
IPetService petService,
|
||||
ICompensationTaskService compensationTaskService,
|
||||
IPointsService pointsService,
|
||||
ILogger<CheckInService> logger)
|
||||
: BaseRepository<CheckInRecord>, ICheckInService
|
||||
{
|
||||
@ -77,35 +81,29 @@ public class CheckInService(
|
||||
PointsAwarded = pointsReward,
|
||||
GrowthPointsAwarded = growthReward,
|
||||
ConsecutiveDays = consecutiveDays,
|
||||
Type = "Normal",
|
||||
Status = "Success"
|
||||
Type = CheckInRecordTypeEnum.Normal,
|
||||
Status = (int)CheckInRecordStatusEnum.Success
|
||||
};
|
||||
var recordId = await checkInRecordRepository.Insertable(checkInRecord).ExecuteReturnIdentityAsync();
|
||||
checkInRecord.Id = recordId;
|
||||
|
||||
// 6b. 更新用户积分余额
|
||||
var newPointsBalance = user.Points + pointsReward;
|
||||
// 6b. 更新用户成长值
|
||||
var newGrowthBalance = user.GrowthPoints + growthReward;
|
||||
|
||||
await checkInRecordRepository.Context.Updateable<Users>()
|
||||
.SetColumns(u => u.Points == newPointsBalance)
|
||||
.SetColumns(u => u.GrowthPoints == newGrowthBalance)
|
||||
.Where(u => u.Id == userId && !u.IsDeleted)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
// 6c. 创建积分变动记录
|
||||
var pointsRecord = new PointsRecord
|
||||
// 6c. 通过积分服务增加积分
|
||||
var pointsResult = await pointsService.AddPointsInTranAsync(new AddPointsInput
|
||||
{
|
||||
UserId = userId,
|
||||
ChangeAmount = pointsReward,
|
||||
BalanceAfter = newPointsBalance,
|
||||
ChangeType = "SignIn",
|
||||
Amount = pointsReward,
|
||||
ChangeType = PointsChangeTypeEnum.SignIn,
|
||||
RelatedId = recordId,
|
||||
Description = $"签到奖励(连续{consecutiveDays}天)",
|
||||
Type = "Income",
|
||||
Status = "Success"
|
||||
};
|
||||
await checkInRecordRepository.Context.Insertable(pointsRecord).ExecuteCommandAsync();
|
||||
Description = $"签到奖励(连续{consecutiveDays}天)"
|
||||
});
|
||||
|
||||
// 构建返回结果
|
||||
result.RecordId = (long)recordId;
|
||||
@ -113,13 +111,13 @@ public class CheckInService(
|
||||
result.ConsecutiveDays = consecutiveDays;
|
||||
result.PointsAwarded = pointsReward;
|
||||
result.GrowthPointsAwarded = growthReward;
|
||||
result.PointsBalance = newPointsBalance;
|
||||
result.PointsBalance = pointsResult.NewBalance;
|
||||
result.GrowthPointsBalance = newGrowthBalance;
|
||||
result.HasPet = pet != null;
|
||||
});
|
||||
|
||||
// 7. 如果用户有活跃宠物,调用 PetService 喂养(含进化检查),独立事务
|
||||
if (pet != null && pet.Status == "Active" && growthReward > 0)
|
||||
if (pet != null && pet.Status == UserPetStatusEnum.Active && growthReward > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -141,7 +139,7 @@ public class CheckInService(
|
||||
|
||||
await compensationTaskService.CreateTaskAsync(new CreateCompensationTaskInput
|
||||
{
|
||||
TaskType = CompensationTaskType.PetFeeding,
|
||||
TaskType = CompensationTaskTypeEnum.PetFeeding,
|
||||
BusinessSource = "CheckIn",
|
||||
BusinessId = result.RecordId.ToString(),
|
||||
UserId = userId,
|
||||
@ -212,8 +210,8 @@ public class CheckInService(
|
||||
ConsecutiveDays = r.ConsecutiveDays,
|
||||
PointsAwarded = r.PointsAwarded,
|
||||
GrowthPointsAwarded = r.GrowthPointsAwarded,
|
||||
Type = r.Type,
|
||||
Status = r.Status
|
||||
Type = r.Type.ToString(),
|
||||
Status = r.Status.ToString()
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
@ -277,8 +275,8 @@ public class CheckInService(
|
||||
PointsAwarded = pointsReward,
|
||||
GrowthPointsAwarded = growthReward,
|
||||
ConsecutiveDays = 0, // 补签不纳入连续天数
|
||||
Type = "MakeUp",
|
||||
Status = "Success",
|
||||
Type = CheckInRecordTypeEnum.MakeUp,
|
||||
Status = (int)CheckInRecordStatusEnum.Success,
|
||||
IsDeleted = false,
|
||||
CreatedBy = userId.ToString(),
|
||||
CreatedAt = DateTime.Now,
|
||||
@ -288,47 +286,36 @@ public class CheckInService(
|
||||
var recordId = await checkInRecordRepository.Insertable(checkInRecord).ExecuteReturnIdentityAsync();
|
||||
checkInRecord.Id = recordId;
|
||||
|
||||
// 更新用户积分和成长值
|
||||
var newPointsBalance = user.Points + pointsReward;
|
||||
// 更新用户成长值
|
||||
var newGrowthBalance = user.GrowthPoints + growthReward;
|
||||
|
||||
await checkInRecordRepository.Context.Updateable<Users>()
|
||||
.SetColumns(u => u.Points == newPointsBalance)
|
||||
.SetColumns(u => u.GrowthPoints == newGrowthBalance)
|
||||
.Where(u => u.Id == userId && !u.IsDeleted)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
// 创建积分变动记录
|
||||
var pointsRecord = new PointsRecord
|
||||
// 通过积分服务增加积分
|
||||
var pointsResult = await pointsService.AddPointsInTranAsync(new AddPointsInput
|
||||
{
|
||||
UserId = userId,
|
||||
ChangeAmount = pointsReward,
|
||||
BalanceAfter = newPointsBalance,
|
||||
ChangeType = "MakeUpSign",
|
||||
Amount = pointsReward,
|
||||
ChangeType = PointsChangeTypeEnum.MakeUpSign,
|
||||
RelatedId = recordId,
|
||||
Description = $"补签奖励({targetDate:yyyy-MM-dd})",
|
||||
Type = "Income",
|
||||
Status = "Success",
|
||||
IsDeleted = false,
|
||||
CreatedBy = userId.ToString(),
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedBy = userId.ToString(),
|
||||
UpdatedAt = DateTime.Now
|
||||
};
|
||||
await checkInRecordRepository.Context.Insertable(pointsRecord).ExecuteCommandAsync();
|
||||
Description = $"补签奖励({targetDate:yyyy-MM-dd})"
|
||||
});
|
||||
|
||||
result.RecordId = (long)recordId;
|
||||
result.CheckInDate = targetDate;
|
||||
result.ConsecutiveDays = 0;
|
||||
result.PointsAwarded = pointsReward;
|
||||
result.GrowthPointsAwarded = growthReward;
|
||||
result.PointsBalance = newPointsBalance;
|
||||
result.PointsBalance = pointsResult.NewBalance;
|
||||
result.GrowthPointsBalance = newGrowthBalance;
|
||||
result.HasPet = pet != null;
|
||||
});
|
||||
|
||||
// 如果有活跃宠物,喂养成长值
|
||||
if (pet != null && pet.Status == "Active" && growthReward > 0)
|
||||
if (pet != null && pet.Status == UserPetStatusEnum.Active && growthReward > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -404,7 +391,7 @@ public class CheckInService(
|
||||
{
|
||||
// 查询签到配置(按 DayNumber 升序)
|
||||
var configs = await checkInRecordRepository.Context.Queryable<CheckInConfig>()
|
||||
.Where(c => c.Status == "Active" && !c.IsDeleted)
|
||||
.Where(c => c.Status == CheckInConfigStatusEnum.Active && !c.IsDeleted)
|
||||
.OrderBy(c => c.DayNumber)
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user