feat: 新增上传地址管理、答题评分及社区消息功能

1. 新增UploadDomain实体与上传地址分配逻辑,为用户分配可用上传域名
2. 新增绑定期刊消息推送,通过RabbitMQ传递绑定信息
3. 优化答题评分逻辑,新增完成度阈值判定与社区消息插入
4. 新增配置项用于评分阈值配置
5. 补充相关DTO与实体类字段,完善数据传输与存储
This commit is contained in:
glz
2026-07-01 14:50:37 +08:00
parent eb4f09e391
commit 07614b5fe6
10 changed files with 262 additions and 25 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using QYZH.InteractiveMagazine.Infrastructure.RabbitMQ;
using QYZH.InteractiveMagazine.IService;
using QYZH.InteractiveMagazine.Models.Common;
using QYZH.InteractiveMagazine.Models.Dto;
@ -17,9 +18,14 @@ public class UserJournalService(
BaseRepository<Users> usersRepository,
BaseRepository<Journal> journalRepository,
ILogger<UserJournalService> logger,
IRabbitMQService rabbitMqService,
IPetService petService)
: BaseRepository<UserJournal>, IUserJournalService
{
private const string JournalExchange = "ex.journal";
private const string BindJournalQueue = "mq.journal.bindUser";
private const string BindJournalRoutingKey = "rk.journal.bindUser";
/// <summary>
/// 用户绑定期刊(扫码绑定)
/// </summary>
@ -93,6 +99,7 @@ public class UserJournalService(
}
logger.LogInformation("用户绑定期刊成功UserId: {UserId}, JournalId: {JournalId}, Id: {Id}", userId, input.JournalId, userJournal.Id);
await SendBindJournalMessageAsync(user, journal);
// 首次绑定期刊时激活宠物
if (isFirstBind)
@ -119,6 +126,36 @@ public class UserJournalService(
};
}
private async Task SendBindJournalMessageAsync(Users user, Journal journal)
{
try
{
var messageSent = await rabbitMqService.SendAsync(new RabbitMQSendParam
{
Exchange = JournalExchange,
Queue = BindJournalQueue,
RoutingKey = BindJournalRoutingKey,
Data = new BindJournalMessage
{
UserId = user.Id,
JournalId = journal.Id,
StartTime = journal.StartTime,
EndTime = journal.EndTime,
UploadDomain = user.UploadDomain
}
});
if (!messageSent)
{
logger.LogError("发送绑定期刊消息失败UserId: {UserId}, JournalId: {JournalId}", user.Id, journal.Id);
}
}
catch (Exception ex)
{
logger.LogError(ex, "发送绑定期刊消息异常UserId: {UserId}, JournalId: {JournalId}", user.Id, journal.Id);
}
}
/// <summary>
/// 获取用户的期刊绑定列表
/// </summary>

View File

@ -19,6 +19,7 @@ namespace QYZH.InteractiveMagazine.Service;
/// </summary>
public class WeChatAuthService(
BaseRepository<WxUser> wxUserRepository,
BaseRepository<UploadDomain> uploadDomainRepository,
IConfiguration configuration,
ILogger<WeChatAuthService> logger,
IPetService petService)
@ -260,7 +261,27 @@ public class WeChatAuthService(
UpdatedAt = DateTime.Now
};
await wxUserRepository.Context.Insertable(newUser).ExecuteReturnIdentityAsync();
await UseTranAsync(async () =>
{
var uploadDomain = await uploadDomainRepository.Queryable()
.Where(d => d.Status == 1 && !d.IsDeleted)
.OrderBy(d => d.AssignedCount, SqlSugar.OrderByType.Asc)
.OrderBy(d => d.Id, SqlSugar.OrderByType.Asc)
.FirstAsync();
BusinessException.ThrowIf(uploadDomain == null, "暂无可用上传地址,请联系管理员", ResultCode.UNPROCESSABLE_ENTITY);
newUser.UploadDomain = uploadDomain!.Domain;
await wxUserRepository.Context.Insertable(newUser).ExecuteCommandAsync();
await uploadDomainRepository.Updateable()
.SetColumns(d => d.AssignedCount == d.AssignedCount + 1)
.SetColumns(d => d.UpdatedBy == wxUserId.ToString())
.SetColumns(d => d.UpdatedAt == DateTime.Now)
.Where(d => d.Id == uploadDomain.Id)
.ExecuteCommandAsync();
});
logger.LogInformation("新用户创建成功UserId: {UserId}, WxUserId: {WxUserId}, Name: {Name}",
newUser.Id, wxUserId, input.Name);
@ -431,7 +452,8 @@ public class WeChatAuthService(
Type = user.Type.ToString(),
Status = user.Status.ToString(),
IsLastOnline = user.IsLastOnline,
CreatedAt = user.CreatedAt
CreatedAt = user.CreatedAt,
UploadDomain = user.UploadDomain
};
}