feat: 完成多模块功能迭代与代码重构
本次提交包含多方面更新: 1. 新增消息类型枚举、杂志标题字段与AI提示词状态管理 2. 重构杂志服务,新增创建杂志接口并统一OSS路径命名规范 3. 调整题库任务结构,将答案解析迁移至独立表并优化关联查询 4. 新增AI提示词无分页查询与状态切换接口 5. 精简任务添加输入DTO,移除冗余字段 6. 修复控制器路由命名大小写不一致问题
This commit is contained in:
@ -59,6 +59,65 @@ public class JournalService(BaseRepository<JournalPage> JournalPageRepository,
|
||||
return new PageListModel<JournalDto>(dataList, search.PageIndex, search.PageSize, totalNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建杂志
|
||||
/// </summary>
|
||||
/// <param name="input">杂志信息</param>
|
||||
/// <returns>新杂志ID</returns>
|
||||
public async Task<BaseResponse<long>> AddAsync(JournalAddDto input)
|
||||
{
|
||||
BusinessException.ThrowIf(string.IsNullOrWhiteSpace(input.Name), "书籍名称不能为空");
|
||||
|
||||
var journal = new Journal
|
||||
{
|
||||
Name = input.Name.Trim(),
|
||||
Title = input.Title,
|
||||
TotalPage = input.TotalPage,
|
||||
Status = (int)JournalStatusEnum.Created,
|
||||
PdfUrl = input.PdfUrl?.RemoveDomain(),
|
||||
Width = input.Width,
|
||||
Height = input.Height,
|
||||
Cover = input.Cover?.RemoveDomain(),
|
||||
BackCover = input.BackCover?.RemoveDomain(),
|
||||
PdfPreviewUrl = input.PdfPreviewUrl?.RemoveDomain(),
|
||||
CreatedBy = "System",
|
||||
UpdatedBy = "System",
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedAt = DateTime.Now,
|
||||
IsDeleted = false
|
||||
};
|
||||
|
||||
// Id 已由 YitIdHelper 预生成,先搬运文件到正式目录,再一次性插入
|
||||
if (!string.IsNullOrWhiteSpace(input.Cover))
|
||||
{
|
||||
var coverKey = $"journal/{journal.Id}/cover.{input.Cover.ToExtension()}";
|
||||
ossService.CopyObject(input.Cover.RemoveDomain(), coverKey);
|
||||
journal.Cover = coverKey;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(input.BackCover))
|
||||
{
|
||||
var backCoverKey = $"journal/{journal.Id}/backCover.{input.BackCover.ToExtension()}";
|
||||
ossService.CopyObject(input.BackCover.RemoveDomain(), backCoverKey);
|
||||
journal.BackCover = backCoverKey;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(input.PdfUrl))
|
||||
{
|
||||
var pdfKey = $"journal/{journal.Id}/Journal.{input.PdfUrl.ToExtension()}";
|
||||
ossService.CopyObject(input.PdfUrl.RemoveDomain(), pdfKey);
|
||||
journal.PdfUrl = pdfKey;
|
||||
}
|
||||
|
||||
var res = await base.InsertAsync(journal);
|
||||
if (!res)
|
||||
{
|
||||
new BusinessException("创建失败");
|
||||
}
|
||||
logger.LogInformation("杂志创建成功,ID: {Id}, 名称: {Name}", journal.Id, input.Name);
|
||||
return BaseResponse<long>.Success(journal.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑
|
||||
/// </summary>
|
||||
@ -76,7 +135,7 @@ public class JournalService(BaseRepository<JournalPage> JournalPageRepository,
|
||||
}
|
||||
else if (input.Cover.RemoveDomain() != Journal.Cover)
|
||||
{
|
||||
var key = $"Journal/{Journal.Id}/cover.{input.Cover.ToExtension()}";
|
||||
var key = $"journal/{Journal.Id}/cover.{input.Cover.ToExtension()}";
|
||||
ossService.CopyObject(input.Cover.RemoveDomain(), key);
|
||||
Journal.Cover = key;
|
||||
}
|
||||
@ -87,7 +146,7 @@ public class JournalService(BaseRepository<JournalPage> JournalPageRepository,
|
||||
}
|
||||
else if (input.BackCover.RemoveDomain() != Journal.BackCover)
|
||||
{
|
||||
var backCoverkey = $"Journal/{Journal.Id}/backCover.{input.BackCover.ToExtension()}";
|
||||
var backCoverkey = $"journal/{Journal.Id}/backCover.{input.BackCover.ToExtension()}";
|
||||
ossService.CopyObject(input.BackCover.RemoveDomain(), backCoverkey);
|
||||
Journal.BackCover = backCoverkey;
|
||||
}
|
||||
@ -98,13 +157,14 @@ public class JournalService(BaseRepository<JournalPage> JournalPageRepository,
|
||||
}
|
||||
else if (input.PdfUrl.RemoveDomain() != Journal.PdfUrl)
|
||||
{
|
||||
var pdfUrlkey = $"Journal/{Journal.Id}/Journal.{input.PdfUrl.ToExtension()}";
|
||||
var pdfUrlkey = $"journal/{Journal.Id}/Journal.{input.PdfUrl.ToExtension()}";
|
||||
ossService.CopyObject(input.PdfUrl.RemoveDomain(), pdfUrlkey);
|
||||
Journal.PdfUrl = pdfUrlkey;
|
||||
}
|
||||
Journal.Width = input.Width;
|
||||
Journal.Height = input.Height;
|
||||
Journal.Name = input.Name;
|
||||
Journal.Title = input.Title;
|
||||
|
||||
var res = await UseTranAsync(async () =>
|
||||
{
|
||||
@ -152,12 +212,12 @@ public class JournalService(BaseRepository<JournalPage> JournalPageRepository,
|
||||
return true;
|
||||
});
|
||||
|
||||
//删除OSS上的Journal/{JournalId}文件夹
|
||||
//删除OSS上的journal/{JournalId}文件夹
|
||||
if (result)
|
||||
{
|
||||
foreach (var JournalId in ids)
|
||||
{
|
||||
var prefix = $"Journal/{JournalId}/";
|
||||
var prefix = $"journal/{JournalId}/";
|
||||
var keys = ossService.ListObjects(prefix);
|
||||
if (keys?.Count > 0)
|
||||
{
|
||||
@ -219,72 +279,6 @@ public class JournalService(BaseRepository<JournalPage> JournalPageRepository,
|
||||
PdfUrl = Journal.PdfUrl
|
||||
};
|
||||
|
||||
|
||||
//铺码业务后续调整
|
||||
|
||||
//var exist = pages.All(c => c.PageNo.IsNull());
|
||||
//if (!exist)
|
||||
//{
|
||||
// var dotIds = pages.Select(s => s.DotId).Distinct();
|
||||
// var dots = await dotFileRepository.Queryable().Where(w => dotIds.Contains(w.Id)).ToListAsync();
|
||||
// output.DotMatrixs = dots.Select(s => new DotMatrixMqOutput() { DotId = s.Id, FileAddress = s.FileAddress }).ToList();
|
||||
// foreach (var page in pages)
|
||||
// {
|
||||
// var find = output.DotMatrixs.Find(f => f.DotId == page.DotId);
|
||||
// find!.Pages.Add(new DotMatrixPageDto()
|
||||
// {
|
||||
// PageNo = page.PageNo,
|
||||
// PageNum = 1
|
||||
// });
|
||||
// }
|
||||
|
||||
// var ok = await producingService.SendAsync(new RabbitMQSendParam() { Exchange = "icr.direct", RoutingKey = "mq.dotmatrix", Data = output });
|
||||
// BusinessException.ThrowIf(!ok, "消息发送失败,生成失败");
|
||||
|
||||
// await base.Updateable().SetColumns(s => s.Status, JournalStatusEnum.Codeing).Where(w => w.Id == id).ExecuteCommandAsync();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// //var first = await dotFileDetailRepository.Queryable().Where(w => w.IsUse == false).GroupBy(g => g.DotId).Having(h => h.Count() >= pages.Count).FirstAsync(a => new { DotId = a.Key, Count = a.Count() });
|
||||
// var first = await dotFileDetailRepository.Queryable().Where(w => w.IsUse == false).GroupBy(g => g.DotId).Having(h => SqlFunc.AggregateCount(h.Id) >= pages.Count).Select(a => new { DotId = a.DotId, Count = SqlFunc.AggregateCount(a.Id) }).FirstAsync();
|
||||
// BusinessException.ThrowIf(first.IsNull(), "点阵页码不足,生成失败");
|
||||
// var dotFile = await dotFileRepository.Queryable().Where(w => w.Id == first.DotId).FirstAsync();
|
||||
// if (dotFile != null)
|
||||
// dotFile.Details = dotFileDetailRepository.Queryable().Where(w => !w.IsUse && w.DotId == dotFile.Id).Take(pages.Count()).ToList();
|
||||
// var dotMatrix = new DotMatrixMqOutput()
|
||||
// {
|
||||
// DotId = dotFile.Id,
|
||||
// FileAddress = dotFile.FileAddress,
|
||||
// };
|
||||
// output.DotMatrixs.Add(dotMatrix);
|
||||
|
||||
// foreach (var item in dotFile.Details)
|
||||
// {
|
||||
// var index = dotFile.Details.IndexOf(item);
|
||||
// pages[index].PageNo = item.PageName;
|
||||
// pages[index].DotId = dotFile.Id;
|
||||
|
||||
// dotMatrix.Pages.Add(new DotMatrixPageDto()
|
||||
// {
|
||||
// PageNo = item.PageName,
|
||||
// PageNum = 1
|
||||
// });
|
||||
// }
|
||||
// await UseTranAsync(async () =>
|
||||
// {
|
||||
// // 更新使用数量
|
||||
// //await dotFileRepository.Updateable().SetColumns(s => s.TotalUse, dotFile.TotalUse + pages.Count).Where(w => w.Id == dotFile.Id).ExecuteCommandAsync();
|
||||
// // 更新使用
|
||||
// await dotFileDetailRepository.Updateable().SetColumns(s => s.IsUse, true).Where(w => dotFile.Details.Select(s => s.Id).Contains(w.Id)).ExecuteCommandAsync();
|
||||
// // 更新页码
|
||||
// await dotMatrixPageRepository.UpdateRangeAsync(pages);
|
||||
// await Updateable().SetColumns(s => s.Status, JournalStatusEnum.CodeSuccess).Where(w => w.Id == id).ExecuteCommandAsync();
|
||||
// //发送消息
|
||||
// //var ok = await producingService.SendAsync(new RabbitMQSendParam() { Exchange = "icr.direct", RoutingKey = "mq.dotmatrix", Data = output });
|
||||
// //BusinessException.ThrowIf(!ok, "消息发送失败,生成失败");
|
||||
// });
|
||||
//}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user