diff --git a/QYZH.InteractiveMagazine.Common/Helpers/RandomIdHelper.cs b/QYZH.InteractiveMagazine.Common/Helpers/RandomIdHelper.cs index 78fd452..0845d83 100644 --- a/QYZH.InteractiveMagazine.Common/Helpers/RandomIdHelper.cs +++ b/QYZH.InteractiveMagazine.Common/Helpers/RandomIdHelper.cs @@ -7,8 +7,8 @@ namespace QYZH.InteractiveMagazine.Common.Helpers; /// public static class RandomIdHelper { - private const long DefaultMinValue = 1_000_000_000_000_000_000L; - private const long DefaultMaxValue = 9_000_000_000_000_000_000L; + private const long DefaultMinValue = 1_000_000_000_000L; + private const long DefaultMaxValue = 9_000_000_000_000_000L; /// /// 生成不可预测的正数长整型ID diff --git a/QYZH.InteractiveMagazine.IService/IUserJournalService.cs b/QYZH.InteractiveMagazine.IService/IUserJournalService.cs index 0528b2f..8c9a7ed 100644 --- a/QYZH.InteractiveMagazine.IService/IUserJournalService.cs +++ b/QYZH.InteractiveMagazine.IService/IUserJournalService.cs @@ -31,14 +31,6 @@ public interface IUserJournalService : IBaseService /// 绑定记录Id Task UnbindJournalAsync(long userId, long id); - /// - /// 生成期刊二维码记录 - /// - /// 生成输入 - /// 操作人名称 - /// 二维码记录 - Task CreateQrCodeAsync(CreateUserJournalQrCodeInput input, string operatorName); - /// /// 批量提交期刊二维码生成任务 /// diff --git a/QYZH.InteractiveMagazine.Models/Dto/Journal/BindJournalDto.cs b/QYZH.InteractiveMagazine.Models/Dto/Journal/BindJournalDto.cs index 0907687..d9392a8 100644 --- a/QYZH.InteractiveMagazine.Models/Dto/Journal/BindJournalDto.cs +++ b/QYZH.InteractiveMagazine.Models/Dto/Journal/BindJournalDto.cs @@ -1,4 +1,5 @@ using QYZH.InteractiveMagazine.Models.Enum; +using System.Text.Json.Serialization; namespace QYZH.InteractiveMagazine.Models.Dto; @@ -10,11 +11,13 @@ public class BindJournalInput /// /// 期刊模板Id(扫码解析的期刊定义Id) /// + [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] public long JournalId { get; set; } /// /// 实例化期刊Id(扫码解析的具体期刊实例Id,可选) /// + [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] public long Id { get; set; } } @@ -146,6 +149,7 @@ public class CreateUserJournalQrCodeOutput /// /// 二维码记录Id列表 /// + [JsonNumberHandling(JsonNumberHandling.WriteAsString)] public List RecordIds { get; set; } = []; /// @@ -209,6 +213,7 @@ public class UserJournalQrCodeOutput /// /// 二维码记录Id /// + [JsonNumberHandling(JsonNumberHandling.WriteAsString)] public long Id { get; set; } /// @@ -270,5 +275,6 @@ public class DeleteUserJournalQrCodeInput /// /// 二维码记录Id列表 /// + [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] public List Ids { get; set; } = []; } diff --git a/QYZH.InteractiveMagazine.Service/UserJournalService.cs b/QYZH.InteractiveMagazine.Service/UserJournalService.cs index 3f3b1b4..a1085ef 100644 --- a/QYZH.InteractiveMagazine.Service/UserJournalService.cs +++ b/QYZH.InteractiveMagazine.Service/UserJournalService.cs @@ -166,62 +166,6 @@ public class UserJournalService( /// /// 生成期刊二维码记录 /// - public async Task CreateQrCodeAsync(CreateUserJournalQrCodeInput input, string operatorName) - { - if (input.JournalId <= 0) - { - throw new BusinessException("期刊Id不能为空", ResultCode.BAD_REQUEST); - } - - var journal = await journalRepository.GetByIdAsync(input.JournalId); - if (journal == null || journal.IsDeleted) - { - throw new BusinessException("期刊不存在", ResultCode.NOT_FOUND); - } - - if (journal.Status != (int)JournalStatusEnum.Published) - { - throw new BusinessException("该期刊暂未发布,无法生成二维码", ResultCode.UNPROCESSABLE_ENTITY); - } - - var recordId = await GenerateUniqueQrCodeIdAsync(); - var record = new UserJournal - { - Id = recordId, - UserId = null, - JournalId = input.JournalId, - Type = 0, - Status = (int)UserJournalStatusEnum.Active, - IsDeleted = false, - CreatedBy = operatorName, - CreatedAt = DateTime.Now, - UpdatedBy = operatorName, - UpdatedAt = DateTime.Now - }; - - var qrCodeContent = BuildQrCodeContent(record.JournalId, record.Id); - var qrCodeKey = $"journal/qrcode/{record.JournalId}/{record.Id}.png"; - using var qrCodeStream = new MemoryStream(QrCodeHelper.GeneratePng(qrCodeContent)); - var uploadedKey = ossService.PutObject(qrCodeKey, qrCodeStream); - if (string.IsNullOrWhiteSpace(uploadedKey)) - { - throw new BusinessException("二维码图片上传失败,请稍后重试", ResultCode.GLOBAL_ERROR); - } - - record.QrCodeUrl = uploadedKey; - - var result = await userJournalRepository.InsertAsync(record); - if (!result) - { - throw new BusinessException("生成二维码失败,请稍后重试", ResultCode.GLOBAL_ERROR); - } - - return MapQrCodeOutput(record, journal, null); - } - - /// - /// 分页查询期刊二维码记录 - /// public async Task CreateQrCodesAsync(CreateUserJournalQrCodeInput input, string operatorName) { if (input.JournalId <= 0) @@ -461,7 +405,7 @@ public class UserJournalService( private static string BuildQrCodeContent(long journalId, long id) { - return JsonSerializer.Serialize(new { JournalId = journalId, Id = id }); + return JsonSerializer.Serialize(new { JournalId = journalId.ToString(), Id = id.ToString() }); } private async Task GenerateUniqueQrCodeIdAsync()