本次提交包含多方面更新: 1. 新增消息类型枚举、杂志标题字段与AI提示词状态管理 2. 重构杂志服务,新增创建杂志接口并统一OSS路径命名规范 3. 调整题库任务结构,将答案解析迁移至独立表并优化关联查询 4. 新增AI提示词无分页查询与状态切换接口 5. 精简任务添加输入DTO,移除冗余字段 6. 修复控制器路由命名大小写不一致问题
214 lines
8.2 KiB
C#
214 lines
8.2 KiB
C#
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using QYZH.InteractiveMagazine.Common.Extensions;
|
|
using QYZH.InteractiveMagazine.Infrastructure.OSS;
|
|
using QYZH.InteractiveMagazine.Infrastructure.RabbitMQ;
|
|
using QYZH.InteractiveMagazine.IService;
|
|
using QYZH.InteractiveMagazine.Models.Common;
|
|
using QYZH.InteractiveMagazine.Models.Dto.Journal;
|
|
using QYZH.InteractiveMagazine.Models.Entity;
|
|
using QYZH.InteractiveMagazine.Models.Enum;
|
|
using QYZH.InteractiveMagazine.Repository;
|
|
using System.Diagnostics;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace QYZH.InteractiveMagazine.Service;
|
|
|
|
public class JournalPageService(BaseRepository<Journal> JournalRepository,
|
|
OssService ossService,
|
|
IHttpClientFactory httpClientFactory,
|
|
IConfiguration configuration,
|
|
IRabbitMQService rabbitMqService,
|
|
BaseRepository<JournalPageTask> JournalPageTaskRepository,
|
|
BaseRepository<JournalPageTaskAnswer> JournalPageTaskAnswerRepository) : BaseRepository<JournalPage>, IJournalPageService
|
|
{
|
|
|
|
public async Task<long> InsertAsync(JournalAddV2Input input)
|
|
{
|
|
|
|
var Journal = await JournalRepository.Queryable().Where(w => w.Id == input.JournalId).FirstAsync();
|
|
BusinessException.ThrowIf(Journal.IsNull(), "未找到书本");
|
|
|
|
BusinessException.ThrowIf(Journal?.Status == (int)JournalStatusEnum.Archive, "书籍已归档不能修改");
|
|
|
|
var pages = new List<JournalPage>();
|
|
//var dotMatrixpages = new List<DotMatrixPage>();
|
|
|
|
//var dotMatrixpage = new DotMatrixPage()
|
|
//{
|
|
// Id = YitIdHelper.NextId(),
|
|
// DotMatrixNoteJournalId = input.JournalId,
|
|
// WidthMilliMeter = Journal.Width,
|
|
// HightMilliMeter = Journal.Height,
|
|
//};
|
|
|
|
var pageTemp = new JournalPage()
|
|
{
|
|
JournalId = input.JournalId,
|
|
JournalCatalogId = input.JournalCatalogId,
|
|
//DotMatrixPageId = dotMatrixpage.Id,
|
|
Url = input.Url,
|
|
PageNum = input.PageNum,
|
|
};
|
|
|
|
//dotMatrixpages.Add(dotMatrixpage);
|
|
pages.Add(pageTemp);
|
|
|
|
await UseTranAsync(async () =>
|
|
{
|
|
//using var uow = Context.Ado.BeginTran();
|
|
var pageData = await base.InsertRangeAsync(pages);
|
|
BusinessException.ThrowIf(pageData.IsNull(), "创建页失败");
|
|
|
|
//var result = await dotMatrixPageRepository.InsertRangeAsync(dotMatrixpages);
|
|
//BusinessException.ThrowIf(result, "创建点阵页失败");
|
|
});
|
|
|
|
return pages.Count; // 返回主目录ID
|
|
}
|
|
|
|
public async Task<bool> UpdateAsync(PageLayoutInput input)
|
|
{
|
|
var page = await Queryable().Where(w => w.Id == input.Id).FirstAsync();
|
|
BusinessException.ThrowIf(page == null, "不存在此页");
|
|
|
|
var Journal = await JournalRepository.GetByIdAsync(page.JournalId);
|
|
BusinessException.ThrowIf(Journal == null, "不存在此书");
|
|
|
|
BusinessException.ThrowIf(Journal?.Status == (int)JournalStatusEnum.Archive, "书籍已归档不能修改");
|
|
var transResult = await UseTranAsync(async () =>
|
|
{
|
|
//await dotMatrixPageRepository.Updateable().SetColumns(s => s.Area == input.Layout)
|
|
// .SetColumns(s => s.AreaPoints == dotMatrixPage.Area)
|
|
// .SetColumns(s => s.WidthMilliMeter == dotMatrixPage.WidthMilliMeter)
|
|
// .SetColumns(s => s.HightMilliMeter == dotMatrixPage.HightMilliMeter)
|
|
// .SetColumns(s => s.WidthDotMatrix == dotMatrixPage.WidthDotMatrix)
|
|
// .SetColumns(s => s.HightDotMatrix == dotMatrixPage.HightDotMatrix)
|
|
// .Where(w => w.Id == page.DotMatrixPageId).ExecuteCommandAsync();
|
|
|
|
page.Layout = input.Layout;
|
|
base.Update(page);
|
|
|
|
input.TasksImages?.ForEach(it =>
|
|
{
|
|
var key = $"journal/{Journal.Id}/{input.Id}/{it.TaskId}/qustion.{it.Url.ToExtension()}";
|
|
ossService.CopyObject(it.Url.RemoveDomain(), key);
|
|
JournalPageTaskRepository.Updateable().SetColumns(s => s.TaskUrl, key).Where(w => w.Id == it.TaskId).ExecuteCommand();
|
|
});
|
|
return true;
|
|
});
|
|
return transResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改书页的点阵码
|
|
/// </summary>
|
|
/// <param name="JournalId"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> UpdatePageNoAsync(long JournalId)
|
|
{
|
|
//这里不能修改 Exchange = "icr.direct" 否则会报错
|
|
var msRes = await rabbitMqService.SendAsync(new RabbitMQSendParam { Exchange = "icr.direct", Queue = "mq.Journal.updatePageNo.queue", RoutingKey = "mq.Journal.updatePageNo", Data = JournalId });//发生消息
|
|
return msRes;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打印书页(全部)
|
|
/// </summary>
|
|
/// <param name="JournalId"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PrintJournalPageAsync(long JournalId)
|
|
{
|
|
//这里不能修改 Exchange = "icr.direct" 否则会报错
|
|
var msRes = await rabbitMqService.SendAsync(new RabbitMQSendParam { Exchange = "icr.direct", Queue = "mq.Journal.printJournalPage.queue", RoutingKey = "mq.Journal.printJournalPage", Data = JournalId });//发生消息
|
|
return msRes;
|
|
}
|
|
|
|
public async Task<JournalPageV2Output> DetailAsync(long id)
|
|
{
|
|
var output = await Queryable()
|
|
//.LeftJoin<DotMatrixPage>((a, b) => a.DotMatrixPageId == b.Id)
|
|
.Where(a => a.Id == id)
|
|
.Select(a => new JournalPageV2Output
|
|
{
|
|
JournalId = a.JournalId,
|
|
JournalCatalogId = a.JournalCatalogId,
|
|
JournalPageId = a.Id,
|
|
Url = a.Url,
|
|
Layout = a.Layout,
|
|
PageNum = a.PageNum,
|
|
})
|
|
.FirstAsync();
|
|
|
|
if (output != null)
|
|
{
|
|
output.Tasks = await JournalPageTaskRepository.Queryable()
|
|
.LeftJoin<JournalPageTaskAnswer>((a, ans) => ans.JournalPageTaskId == a.Id)
|
|
.Where((a, ans) => a.JournalPageId == output.JournalPageId)
|
|
.Select((a, ans) => new JournalPageTaskV2Output
|
|
{
|
|
Id = a.Id,
|
|
GroupId = a.GroupId,
|
|
No = a.No,
|
|
Type = (TaskBankTypeEnum)a.Type,
|
|
Options = a.Options,
|
|
Answers = ans.Answer,
|
|
Analysis = ans.Analysis,
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
//if (output?.Areas != null)
|
|
// output.Areas = await _JournalPageOtherRepository.Queryable().Where(w => w.JournalPageId == output.JournalPageId).Select<JournalPageOtherOutput>().ToListAsync();
|
|
|
|
return output;
|
|
}
|
|
|
|
public async Task<bool> DeleteAsync(long id)
|
|
{
|
|
return await Deleteable().Where(d => d.Id == id).ExecuteCommandAsync() > 0;
|
|
}
|
|
//public async Task<List<JournalPageNoArticleOutput>> PageNoArticleAsync(long JournalId)
|
|
//{
|
|
// return await Queryable().Where(d => d.JournalId == JournalId)
|
|
// .Where(w => w.JournalArticleId == null)
|
|
// .ToListAsync(x => new JournalPageNoArticleOutput()
|
|
// {
|
|
// Id = x.Id,
|
|
// PageUrl = x.Url,
|
|
// PageNum = x.PageNum
|
|
// });
|
|
//}
|
|
|
|
private int MillimeterToDotMatrixUnit(float millimeterValue)
|
|
{
|
|
return (int)(millimeterValue * 8 / 0.3);
|
|
}
|
|
}
|
|
|
|
public class JournalDotPage_Task
|
|
{
|
|
public int X { get; set; }
|
|
public int Y { get; set; }
|
|
public int W { get; set; }
|
|
public int H { get; set; }
|
|
}
|
|
|
|
public class JournalDotPage_Answer
|
|
{
|
|
public int X { get; set; }
|
|
public int Y { get; set; }
|
|
public int W { get; set; }
|
|
public int H { get; set; }
|
|
}
|
|
|
|
public class JournalDotPage_Area
|
|
{
|
|
public JournalDotPage_Task Task { get; set; }
|
|
|
|
public List<JournalDotPage_Answer> AnswerList { get; set; }
|
|
|
|
public long TaskId { get; set; }
|
|
|
|
}
|