Merge branch 'master' of http://8.137.159.94:3000/glz/QYZH.InteractiveMagazine
This commit is contained in:
@ -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>
|
||||
|
||||
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user