修改
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
|
||||
using Aliyun.Acs.Core.Logging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using QYZH.InteractiveMagazine.Common.Extensions;
|
||||
using QYZH.InteractiveMagazine.Common.Helpers;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.OSS;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.RabbitMQ;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
@ -11,6 +14,7 @@ using QYZH.InteractiveMagazine.Models.Entity;
|
||||
using QYZH.InteractiveMagazine.Models.Enum;
|
||||
using QYZH.InteractiveMagazine.Repository;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Service;
|
||||
@ -20,6 +24,8 @@ public class JournalPageService(BaseRepository<Journal> JournalRepository,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
IConfiguration configuration,
|
||||
IRabbitMQService rabbitMqService,
|
||||
ILogger<AiBasePromptService> logger,
|
||||
BaseRepository<JournalPage> JournalPageRepository,
|
||||
BaseRepository<JournalPageTask> JournalPageTaskRepository,
|
||||
BaseRepository<JournalPageTaskAnswer> JournalPageTaskAnswerRepository) : BaseRepository<JournalPage>, IJournalPageService
|
||||
{
|
||||
@ -108,10 +114,87 @@ public class JournalPageService(BaseRepository<Journal> JournalRepository,
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpdatePageNoAsync(long JournalId)
|
||||
{
|
||||
var msRes = await rabbitMqService.SendAsync(new RabbitMQSendParam { Exchange = "ex.journal", Queue = "mq.journal.dotcode.auto", RoutingKey = "rk.journal.dotcode.auto", Data = JournalId });//发生消息
|
||||
var journalEntity = await JournalRepository.Queryable().FirstAsync(w => w.Id == JournalId);
|
||||
BusinessException.ThrowIf(journalEntity == null, "不存在此期刊");
|
||||
|
||||
//如果书籍状态不等于“已归档”,“已废弃”,“已铺码”的情况下,就更新状态为“已铺码”
|
||||
BusinessException.ThrowIf((JournalStatusEnum)journalEntity.Status is JournalStatusEnum.Abandoned or JournalStatusEnum.Archive or JournalStatusEnum.Codeing, "当前【状态】不允许铺码");
|
||||
|
||||
var journalPageList = await JournalPageRepository.Queryable().Where(x => x.JournalId == JournalId).OrderBy(x => x.PageNum).ToListAsync();
|
||||
BusinessException.ThrowIf(journalPageList.Count == 0, "此期刊不存在任何书页");
|
||||
|
||||
var uploadPdfUrl = DomainHelper.OssFullUrl(journalEntity?.PdfUrl!);
|
||||
BusinessException.ThrowIf(string.IsNullOrWhiteSpace(uploadPdfUrl), "此期刊上传的PDF路径错误,请检查期刊PDF文件是否上传成功");
|
||||
|
||||
logger.LogInformation("uploadPdfUrl:" + uploadPdfUrl);
|
||||
//验证是否上传了PDF文件
|
||||
var response = await httpClientFactory.CreateClient().SendAsync(new HttpRequestMessage(HttpMethod.Head, uploadPdfUrl));
|
||||
BusinessException.ThrowIf(response.StatusCode != HttpStatusCode.OK, "获取期刊上传的PDF文件失败,请检查PDF文件是否上传成功");
|
||||
|
||||
journalEntity.Status = (int)JournalStatusEnum.Codeing;
|
||||
|
||||
await JournalRepository.Updateable(journalEntity).UpdateColumns(x => new { x.Status, x.UpdatedAt }).ExecuteCommandAsync();
|
||||
|
||||
var data = new JournalPagePrintDto
|
||||
{
|
||||
JournalId = JournalId,
|
||||
JournalPdfUrl = uploadPdfUrl,
|
||||
PageNum = [.. journalPageList.Select(x => x.PageNum)]
|
||||
};
|
||||
var msRes = await rabbitMqService.SendAsync(new RabbitMQSendParam { Exchange = "ex.journal", Queue = "mq.journal.dotcode.auto", RoutingKey = "rk.journal.dotcode.auto", Data = data });//发生消息
|
||||
return msRes;
|
||||
}
|
||||
/// <summary>
|
||||
/// 回调接口-自动铺码, 书页铺码后回调接口,更新书页的点阵码
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CallbackPageUpdatePageNo(JournalPagePrintDto request)
|
||||
{
|
||||
return await UseTranAsync(async () =>
|
||||
{
|
||||
var journalEntity = await JournalRepository.Queryable().FirstAsync(w => w.Id == request.JournalId);
|
||||
BusinessException.ThrowIf(journalEntity == null, "不存在此书");
|
||||
|
||||
//如果书籍状态不等于“铺码中”则不允许回调接口更新点阵码
|
||||
BusinessException.ThrowIf(journalEntity.Status != (int)JournalStatusEnum.Codeing, "当前【状态】不允许修改铺码");
|
||||
|
||||
var bookPageList = await JournalPageRepository.Queryable().Where(x => x.JournalId == request.JournalId).OrderBy(x => x.PageNum).ToListAsync();
|
||||
|
||||
BusinessException.ThrowIf(bookPageList.Count == 0, "此书不存在任何书页");
|
||||
|
||||
journalEntity.Status = (int)request.Status!.Value;
|
||||
journalEntity.UpdatedAt = DateTime.Now;
|
||||
|
||||
//如果铺码成功了,并且之前已经有下载链接了,就删除原来的文件
|
||||
if (request.Status == JournalStatusEnum.CodeSuccess && !string.IsNullOrWhiteSpace(journalEntity.DownloadJournalPagePdfName))
|
||||
{
|
||||
//删除oss上原来的文件
|
||||
ossService.DeleteObject(journalEntity.DownloadJournalPagePdfName.RemoveDomain());
|
||||
}
|
||||
//如果铺码成功了,就更新下载链接,以及书页的点阵码
|
||||
if (request.Status == JournalStatusEnum.CodeSuccess)
|
||||
{
|
||||
journalEntity.DownloadJournalPagePdfName = request.DownloadJournalPagePdfName;
|
||||
|
||||
BusinessException.ThrowIf(request.PageNo.Length != bookPageList.Count, $"点阵码条数与页码数量不匹配,点阵码条数:{request.PageNo.Length},页码数量:{bookPageList.Count}");
|
||||
|
||||
|
||||
for (var i = 0; i < bookPageList.Count; i++)
|
||||
{
|
||||
//让也页码和点阵码的顺序必须保持一致
|
||||
bookPageList[i].PageNo = request.PageNo[i];
|
||||
bookPageList[i].UpdatedAt = DateTime.Now;
|
||||
}
|
||||
|
||||
await JournalPageRepository.UpdateRangeAsync(bookPageList);
|
||||
}
|
||||
|
||||
await JournalRepository.Updateable(journalEntity).UpdateColumns(x => new { x.Status, x.DownloadJournalPagePdfName, x.UpdatedAt }).ExecuteCommandAsync();
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
public async Task<JournalPageV2Output> DetailAsync(long id)
|
||||
{
|
||||
var output = await Queryable()
|
||||
|
||||
@ -252,7 +252,7 @@ public class PetService(
|
||||
logger.LogWarning("喂养失败,宠物未激活,PetId: {PetId}, Status: {Status}", input.PetId, pet.Status);
|
||||
throw new BusinessException("宠物未激活,无法喂养", 400);
|
||||
}
|
||||
FeedPetOutput result = new FeedPetOutput ();
|
||||
FeedPetOutput result = new FeedPetOutput();
|
||||
// 事务保证一致性
|
||||
await UseTranAsync(async () =>
|
||||
{
|
||||
@ -590,6 +590,11 @@ public class PetService(
|
||||
if (template == null || template.IsDeleted)
|
||||
throw new BusinessException("宠物模板不存在", 404);
|
||||
|
||||
|
||||
if (template.Type == PetTemplateTypeEnum.Default)
|
||||
throw new BusinessException("默认模板不允许删除", 400);
|
||||
|
||||
|
||||
// 校验是否有用户宠物实例关联
|
||||
var hasUserPet = petRepository.Context.Queryable<UserPet>()
|
||||
.Any(p => p.TemplateId == id && !p.IsDeleted);
|
||||
@ -659,9 +664,9 @@ public class PetService(
|
||||
var template = await petTemplateRepository.GetByIdAsync(id);
|
||||
if (template == null || template.IsDeleted)
|
||||
throw new BusinessException("宠物模板不存在", 404);
|
||||
|
||||
template.Status = template.Status == (int)DefaultStatusEnum.Active
|
||||
? (int)DefaultStatusEnum.Inactive
|
||||
|
||||
template.Status = template.Status == (int)DefaultStatusEnum.Active
|
||||
? (int)DefaultStatusEnum.Inactive
|
||||
: (int)DefaultStatusEnum.Active;
|
||||
template.UpdatedBy = "System";
|
||||
template.UpdatedAt = DateTime.Now;
|
||||
|
||||
Reference in New Issue
Block a user