Pārlūkot izejas kodu

自贡 任务 231 【标书】新增知识引用功能和统计

tangjiang 4 mēneši atpakaļ
vecāks
revīzija
6b9d9e5f92

+ 69 - 3
src/Hotline.Api/Controllers/Bi/BiOrderController.cs

@@ -45,6 +45,7 @@ using DocumentFormat.OpenXml.Bibliography;
 using NPOI.SS.Formula.Functions;
 using Hotline.Share.Dtos.File;
 using Hotline.File;
+using Hotline.KnowledgeBase;
 
 namespace Hotline.Api.Controllers.Bi
 {
@@ -86,6 +87,7 @@ namespace Hotline.Api.Controllers.Bi
         private readonly IRepository<CallNative> _callNativeRepository;
         private readonly IOptionsSnapshot<AppConfiguration> _appOptions;
         private readonly IRepository<OrderTsDetails> _orderTsDetailsRepository;
+        private readonly IRepository<KnowledgeQuote> _knowledgeQuoteRepository;
 
         public BiOrderController(
             IOrderRepository orderRepository,
@@ -123,7 +125,8 @@ namespace Hotline.Api.Controllers.Bi
             IOrderVisitApplication orderVisitApplication,
             IRepository<CallNative> callNativeRepository,
             IOptionsSnapshot<AppConfiguration> appOptions,
-            IRepository<OrderTsDetails> orderTsDetailsRepository)
+            IRepository<OrderTsDetails> orderTsDetailsRepository,
+            IRepository<KnowledgeQuote> knowledgeQuoteRepository)
         {
             _orderRepository = orderRepository;
             _hotspotTypeRepository = hotspotTypeRepository;
@@ -161,6 +164,7 @@ namespace Hotline.Api.Controllers.Bi
             _callNativeRepository = callNativeRepository;
             _appOptions = appOptions;
             _orderTsDetailsRepository = orderTsDetailsRepository;
+            _knowledgeQuoteRepository = knowledgeQuoteRepository;
         }
 
         /// <summary>
@@ -5217,7 +5221,7 @@ namespace Hotline.Api.Controllers.Bi
         [HttpGet("query_order_ts_details_list")]
         public async Task<PagedDto<OrderTsDetailsDto>> QueryOrderTsDetailsList([FromQuery] PagedKeywordRequest dto)
         {
-            var (total, items) = await _orderApplication.QueryOrderTsDetailslList(dto).ToPagedListAsync(dto, HttpContext.RequestAborted);
+            var (total, items) = await _orderApplication.QueryOrderTsDetailsList(dto).ToPagedListAsync(dto, HttpContext.RequestAborted);
 
             return new PagedDto<OrderTsDetailsDto>(total, _mapper.Map<IReadOnlyList<OrderTsDetailsDto>>(items));
         }
@@ -5230,7 +5234,7 @@ namespace Hotline.Api.Controllers.Bi
         [HttpPost("query_order_ts_details_list/export")]
         public async Task<FileStreamResult> ExportQueryOrderTsDetailsList([FromQuery] ExportExcelDto<PagedKeywordRequest> dto)
         {
-            var query = _orderApplication.QueryOrderTsDetailslList(dto.QueryDto);
+            var query = _orderApplication.QueryOrderTsDetailsList(dto.QueryDto);
 
             List<OrderTsDetailsDto> lists;
             if (dto.IsExportAll)
@@ -5270,5 +5274,67 @@ namespace Hotline.Api.Controllers.Bi
                    .Where(p => p.Terms == KeyWord)
                    .ToListAsync(HttpContext.RequestAborted);
         }
+
+        /// <summary>
+        /// 知识库引用
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpGet("query_knowledge_quote_list")]
+        public async Task<PagedDto<OrderTsDetailsDto>> QueryKnowledgeQuoteList([FromQuery] PagedKeywordRequest dto)
+        {
+            var (total, items) = await _orderApplication.QueryKnowledgeQuoteList(dto).ToPagedListAsync(dto, HttpContext.RequestAborted);
+
+            return new PagedDto<OrderTsDetailsDto>(total, _mapper.Map<IReadOnlyList<OrderTsDetailsDto>>(items));
+        }
+
+        /// <summary>
+        /// 知识库引用导出
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost("query_knowledge_quote_list/export")]
+        public async Task<FileStreamResult> ExportQueryKnowledgeQuoteList([FromQuery] ExportExcelDto<PagedKeywordRequest> dto)
+        {
+            var query = _orderApplication.QueryKnowledgeQuoteList(dto.QueryDto);
+
+            List<OrderTsDetailsDto> lists;
+            if (dto.IsExportAll)
+            {
+                lists = await query.ToListAsync(HttpContext.RequestAborted);
+            }
+            else
+            {
+                var (_, items) = await query.ToPagedListAsync(dto.QueryDto, HttpContext.RequestAborted);
+                lists = items;
+            }
+
+            var listDtos = _mapper.Map<ICollection<OrderTsDetailsDto>>(lists);
+
+            dynamic? dynamicClass = DynamicClassHelper.CreateDynamicClass(dto.ColumnInfos);
+
+            var dtos = listDtos
+                .Select(stu => _mapper.Map(stu, typeof(OrderTsDetailsDto), dynamicClass))
+                .Cast<object>()
+                .ToList();
+
+            var stream = ExcelHelper.CreateStream(dtos);
+
+            return ExcelStreamResult(stream, "知识库引用数据");
+
+        }
+
+        /// <summary>
+        /// 根据知识库引用查询工单
+        /// </summary>
+        /// <param name="KeyWord"></param>
+        /// <returns></returns>
+        [HttpGet("get_query_knowledge_quote_order_list")]
+        public async Task<List<KnowledgeQuote>> GetQueryKnowledgeQuoteOrderList(string KeyWord)
+        {
+            return await _knowledgeQuoteRepository.Queryable()
+                   .Where(p => p.KnowledgeId == KeyWord)
+                   .ToListAsync(HttpContext.RequestAborted);
+        }
     }
 }

+ 4 - 2
src/Hotline.Api/Controllers/OrderController.cs

@@ -3584,8 +3584,8 @@ public class OrderController : BaseController
         await _orderApplication.OrderParticiple(dto.Content, order.Id, order.No, order.Title, order.CreationTime, HttpContext.RequestAborted);
         //敏感分词
         await _orderApplication.OrderSensitiveParticiple(dto.Content, order.Id, HttpContext.RequestAborted);
-
-
+        //知识库引用
+        await _orderApplication.AddKnowledgeQuote(order.Id, order.Title, order.No, order.KnowledgeQuote, HttpContext.RequestAborted);
         ////sms
         //try
         //{
@@ -3808,6 +3808,8 @@ public class OrderController : BaseController
 
         //敏感分词
         await _orderApplication.OrderSensitiveParticiple(dto.Content, order.Id, HttpContext.RequestAborted);
+        //知识库引用
+        await _orderApplication.AddKnowledgeQuote(order.Id, order.Title, order.No, order.KnowledgeQuote, HttpContext.RequestAborted);
 
         return new { Id = order.Id, No = order.No, Password = order.Password, CallId = order.CallId };
     }

+ 19 - 1
src/Hotline.Application/Orders/IOrderApplication.cs

@@ -2,6 +2,7 @@
 using Hotline.FlowEngine.Workflows;
 using Hotline.Orders;
 using Hotline.Settings;
+using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.DataSharing.PusherHotlineDto;
 using Hotline.Share.Dtos.FlowEngine;
 using Hotline.Share.Dtos.Order;
@@ -389,6 +390,23 @@ namespace Hotline.Application.Orders
         /// </summary>
         /// <param name="dto"></param>
         /// <returns></returns>
-        ISugarQueryable<OrderTsDetailsDto> QueryOrderTsDetailslList(PagedKeywordRequest dto);
+        ISugarQueryable<OrderTsDetailsDto> QueryOrderTsDetailsList(PagedKeywordRequest dto);
+
+        /// <summary>
+        /// 知识库引用
+        /// </summary>
+        /// <param name="orderId"></param>
+        /// <param name="title"></param>
+        /// <param name="no"></param>
+        /// <param name="knowledgeQuote"></param>
+        /// <returns></returns>
+        Task AddKnowledgeQuote(string orderId, string title, string no, List<Kv> knowledgeQuote, CancellationToken cancellationToken);
+
+        /// <summary>
+        /// 知识库引用
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        ISugarQueryable<OrderTsDetailsDto> QueryKnowledgeQuoteList(PagedKeywordRequest dto);
     }
 }

+ 59 - 1
src/Hotline.Application/Orders/OrderApplication.cs

@@ -6,6 +6,7 @@ using Hotline.Configurations;
 using Hotline.File;
 using Hotline.FlowEngine.WorkflowModules;
 using Hotline.FlowEngine.Workflows;
+using Hotline.KnowledgeBase;
 using Hotline.Orders;
 using Hotline.OrderTranspond;
 using Hotline.Push.Notifies;
@@ -97,6 +98,7 @@ public class OrderApplication : IOrderApplication, IScopeDependency
     private readonly IRepository<StatisticsHotspotSatisfied> _statisticsHotspotSatisfiedRepository;
     private readonly IRepository<StatisticsDepartSatisfied> _statisticsDepartSatisfiedRepository;
     private readonly IRepository<OrderTsDetails> _orderTsDetailsRepository;
+    private readonly IRepository<KnowledgeQuote> _knowledgeQuoteRepository;
 
     public OrderApplication(
         IOrderDomainService orderDomainService,
@@ -139,7 +141,8 @@ public class OrderApplication : IOrderApplication, IScopeDependency
         IRepository<StatisticsHotspotSatisfied> statisticsHotspotSatisfiedRepository,
         IRepository<StatisticsDepartSatisfied> statisticsDepartSatisfiedRepository,
         IOrderDelayRepository orderDelayRepository,
-        IRepository<OrderTsDetails> orderTsDetailsRepository)
+        IRepository<OrderTsDetails> orderTsDetailsRepository,
+        IRepository<KnowledgeQuote> knowledgeQuoteRepository)
     {
         _orderDomainService = orderDomainService;
         _workflowDomainService = workflowDomainService;
@@ -182,6 +185,7 @@ public class OrderApplication : IOrderApplication, IScopeDependency
         _statisticsHotspotSatisfiedRepository = statisticsHotspotSatisfiedRepository;
         _statisticsDepartSatisfiedRepository = statisticsDepartSatisfiedRepository;
         _orderTsDetailsRepository = orderTsDetailsRepository;
+        _knowledgeQuoteRepository = knowledgeQuoteRepository;
     }
 
     /// <summary>
@@ -4129,4 +4133,58 @@ public class OrderApplication : IOrderApplication, IScopeDependency
 
         return query;
     }
+
+    /// <summary>
+    /// 知识库引用
+    /// </summary>
+    /// <param name="orderId"></param>
+    /// <param name="title"></param>
+    /// <param name="no"></param>
+    /// <param name="knowledgeQuote"></param>
+    /// <returns></returns>
+    public async Task AddKnowledgeQuote(string orderId, string title, string no, List<Kv> knowledgeQuote, CancellationToken cancellationToken)
+    {
+        await _knowledgeQuoteRepository.RemoveAsync(p => p.OrderId == orderId, false, cancellationToken);
+        if (knowledgeQuote != null && knowledgeQuote.Count > 0)
+        {
+            List<KnowledgeQuote> list = [];
+            foreach (var item in knowledgeQuote)
+            {
+                list.Add(new KnowledgeQuote
+                {
+                    KnowledgeId = item.Key,
+                    KnowledgeTitle = item.Value,
+                    OrderId = orderId,
+                    Title = title,
+                    No = no
+                });
+            }
+            if (list != null && list.Count > 0)
+                await _knowledgeQuoteRepository.AddRangeAsync(list, cancellationToken);
+        }
+    }
+
+    /// <summary>
+    /// 知识库引用
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    public ISugarQueryable<OrderTsDetailsDto> QueryKnowledgeQuoteList(PagedKeywordRequest dto)
+    {
+        var query = _knowledgeQuoteRepository.Queryable()
+            .Where(p => p.CreationTime >= dto.StartTime && p.CreationTime <= dto.EndTime)
+             .WhereIF(!string.IsNullOrEmpty(dto.Keyword), p => p.Title.Contains(dto.Keyword))
+             .MergeTable()
+           .GroupBy(p => new { p.KnowledgeId, p.KnowledgeTitle })
+           .Select(p => new OrderTsDetailsDto
+           {
+               Name = p.KnowledgeTitle,
+               CountNum = SqlFunc.AggregateCount(p.KnowledgeId),
+           })
+           .OrderByIF(dto is { SortField: "countNum", SortRule: 0 }, p => p.CountNum, OrderByType.Asc)
+           .OrderByIF(dto is { SortField: "countNum", SortRule: 1 }, p => p.CountNum, OrderByType.Desc);
+
+        return query;
+    }
+
 }

+ 5 - 0
src/Hotline.Share/Dtos/Order/OrderDto.cs

@@ -1379,6 +1379,11 @@ namespace Hotline.Share.Dtos.Order
         /// 工单推送分类
         /// </summary>
         public List<OrderPushTypeDto>? OrderPushTypes { get; set; }
+
+        /// <summary>
+        ///知识库引用
+        /// </summary>
+        public List<Kv>? KnowledgeQuote { get; set; }
     }
 
     public record CanLinkCallRecordOrderDto : PagedKeywordRequest

+ 43 - 0
src/Hotline/KnowledgeBase/KnowledgeQuote.cs

@@ -0,0 +1,43 @@
+using SqlSugar;
+using System.ComponentModel;
+using XF.Domain.Repository;
+
+namespace Hotline.KnowledgeBase
+{
+    /// <summary>
+	/// 知识库引用
+	/// </summary>
+	[Description("知识库引用")]
+    public class KnowledgeQuote : CreationEntity
+    {
+        /// <summary>
+        /// 知识库Id
+        /// </summary>
+        [SugarColumn(ColumnDescription = "知识库Id")]
+        public string KnowledgeId { get; set; }
+
+        /// <summary>
+        /// 知识标题
+        /// </summary>
+        [SugarColumn(ColumnDescription = "知识标题")]
+        public string KnowledgeTitle { get; set; }
+
+        /// <summary>
+        /// 工单ID
+        /// </summary>
+        [SugarColumn(ColumnDescription = "工单ID")]
+        public string OrderId { get; set; }
+
+        /// <summary>
+        /// 工单标题
+        /// </summary>
+        [SugarColumn(ColumnDescription = "工单标题")]
+        public string Title { get; set; }
+
+        /// <summary>
+        /// 工单编号
+        /// </summary>
+        [SugarColumn(ColumnDescription = "工单编号")]
+        public string No { get; set; }
+    }
+}

+ 10 - 4
src/Hotline/Orders/Order.cs

@@ -1086,14 +1086,20 @@ namespace Hotline.Orders
         /// </summary>
         [SugarColumn(ColumnDataType = "json", ColumnDescription = "部门办件结果", IsJson = true, IsNullable = true)]
         public Kv? OrgProcessingResults { get; set; }
-		#endregion
+        #endregion
 
         /// <summary>
         /// 老系统工单Id
         /// </summary>
-		[SugarColumn(ColumnDescription = "老系统工单Id")]
-		public string? OldOrderId { get; set; }
-	}
+        [SugarColumn(ColumnDescription = "老系统工单Id")]
+        public string? OldOrderId { get; set; }
+
+        /// <summary>
+        ///知识库引用
+        /// </summary>
+        [SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true, ColumnDescription = "知识库引用")]
+        public List<Kv>? KnowledgeQuote { get; set; }
+    }
 
     public partial class Order
     {

+ 11 - 1
src/Hotline/Orders/OrderTsDetails.cs

@@ -1,27 +1,37 @@
-using XF.Domain.Repository;
+using SqlSugar;
+using System.ComponentModel;
+using XF.Domain.Repository;
 
 namespace Hotline.Orders
 {
+    /// <summary>
+	/// 工单热词
+	/// </summary>
+	[Description("工单热词")]
     public class OrderTsDetails : CreationEntity
     {
         /// <summary>
         /// 分词词语
         /// </summary>
+        [SugarColumn(ColumnDescription = "分词词语")]
         public string Terms { get; set; }
 
         /// <summary>
         /// 工单ID
         /// </summary>
+        [SugarColumn(ColumnDescription = "工单ID")]
         public string OrderId { get; set; }
 
         /// <summary>
         /// 工单标题
         /// </summary>
+        [SugarColumn(ColumnDescription = "工单标题")]
         public string Title { get; set; }
 
         /// <summary>
         /// 工单编号
         /// </summary>
+        [SugarColumn(ColumnDescription = "工单编号")]
         public string No {  get; set; }
     }
 }