소스 검색

自贡任务 522 在【数据统计->知识库统计】目录下新增【超期未更新统计】菜单

tangjiang 3 일 전
부모
커밋
f4dc1eec7e

+ 52 - 1
src/Hotline.Api/Controllers/KnowledgeApplyController.cs

@@ -1,10 +1,14 @@
 using Hotline.Application.Knowledge;
 using Hotline.KnowledgeBase;
-using Hotline.Permissions;
+using Hotline.Repository.SqlSugar.Extensions;
 using Hotline.Settings;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.Knowledge;
+using Hotline.Share.Dtos.ObservationPiece;
+using Hotline.Share.Dtos.Order;
 using Hotline.Share.Enums.KnowledgeBase;
+using Hotline.Share.Requests;
+using Hotline.Tools;
 using Hotline.Users;
 using MapsterMapper;
 using Microsoft.AspNetCore.Mvc;
@@ -268,5 +272,52 @@ namespace Hotline.Api.Controllers
         }
 
         #endregion
+
+        #region 知识超期未更新统计
+        /// <summary>
+        /// 知识超期未更新统计
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpGet("get-know-overdue-statistics-list")]
+        public async Task<PagedDto<KnowedgeStatisticsDto>> GetKnowOverdueStatisticsList([FromQuery] PagedKeywordRequest dto)
+        {
+            var (total, items) = await _knowApplication.GetKnowedgeStatistics(dto)
+                .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
+            return new PagedDto<KnowedgeStatisticsDto>(total, items);
+        }
+
+        /// <summary>
+        ///知识超期未更新统计导出
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost("get-know-overdue-statistics-list-export")]
+        public async Task<FileStreamResult> GetKnowOverdueStatisticsListExport([FromBody] ExportExcelDto<PagedKeywordRequest> dto)
+        {
+            var query = _knowApplication.GetKnowedgeStatistics(dto.QueryDto);
+            List<KnowedgeStatisticsDto> data;
+            if (dto.IsExportAll)
+            {
+                data = await query.ToListAsync(HttpContext.RequestAborted);
+            }
+            else
+            {
+                var (_, items) = await query.ToPagedListAsync(dto.QueryDto, HttpContext.RequestAborted);
+                data = items;
+            }
+
+            dynamic? dynamicClass = DynamicClassHelper.CreateDynamicClass<KnowedgeStatisticsDto>(dto.ColumnInfos);
+
+            var dtos = data
+                .Select(stu => _mapper.Map(stu, typeof(KnowedgeStatisticsDto), dynamicClass))
+                .Cast<object>()
+                .ToList();
+
+            var stream = ExcelHelper.CreateStream(dtos);
+
+            return ExcelStreamResult(stream, "知识超期未更新统计");
+        } 
+        #endregion
     }
 }

+ 9 - 0
src/Hotline.Application/Knowledge/IKnowApplication.cs

@@ -1,7 +1,9 @@
 using Hotline.KnowledgeBase;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.Knowledge;
+using Hotline.Share.Requests;
 using Microsoft.AspNetCore.Mvc;
+using SqlSugar;
 
 namespace Hotline.Application.Knowledge
 {
@@ -77,5 +79,12 @@ namespace Hotline.Application.Knowledge
         /// <param name="dto"></param>
         /// <returns></returns>
         Task<(int, List<KnowledgeRetrievalDataDto>)> KnowRetrievalAsync(KnowledgeRetrievalPagedListDto dto);
+
+        /// <summary>
+        /// 知识超期未更新统计
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        ISugarQueryable<KnowedgeStatisticsDto> GetKnowedgeStatistics(PagedKeywordRequest dto);
     }
 }

+ 17 - 8
src/Hotline.Application/Knowledge/KnowApplication.cs

@@ -1,23 +1,17 @@
-using DocumentFormat.OpenXml.EMMA;
-using Hotline.Application.Tools;
+using Hotline.Application.Tools;
 using Hotline.Configurations;
 using Hotline.KnowledgeBase;
 using Hotline.Pdf;
 using Hotline.Repository.SqlSugar.Extensions;
-using Hotline.Settings;
 using Hotline.Settings.Hotspots;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.Knowledge;
-using Hotline.Share.Enums.Article;
 using Hotline.Share.Enums.KnowledgeBase;
+using Hotline.Share.Requests;
 using Hotline.Share.Tools;
-using Hotline.Users;
 using Mapster;
 using MapsterMapper;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Options;
-using Org.BouncyCastle.Utilities.IO;
 using PanGu;
 using SqlSugar;
 using XF.Domain.Authentications;
@@ -521,5 +515,20 @@ namespace Hotline.Application.Knowledge
             }
             return await sugar.Select<KnowledgeRetrievalDataDto>().ToPagedListAsync(dto.PageIndex, dto.PageSize);
         }
+
+        public ISugarQueryable<KnowedgeStatisticsDto> GetKnowedgeStatistics(PagedKeywordRequest dto)
+        {
+            return _knowledgeRepository.Queryable()
+                    .Includes(p => p.SourceOrganize)
+                    .WhereIF(dto.StartTime.HasValue, p => p.LastModificationTime >= dto.StartTime)
+                    .WhereIF(dto.EndTime.HasValue, p => p.LastModificationTime <= dto.EndTime)
+                    .WhereIF(!string.IsNullOrEmpty(dto.Keyword), p => p.SourceOrganize.Name.Contains(dto.Keyword))
+                    .Select(p => new KnowedgeStatisticsDto
+                    {
+                        LastModificationTime = p.LastModificationTime,
+                        OrgName = p.SourceOrganize.Name
+                    })
+                    .OrderByDescending(p => p.LastModificationTime);
+        }
     }
 }

+ 9 - 0
src/Hotline.Share/Dtos/Knowledge/KnowedgeStatisticsDto.cs

@@ -0,0 +1,9 @@
+namespace Hotline.Share.Dtos.Knowledge
+{
+    public class KnowedgeStatisticsDto
+    {
+        public string? OrgName { get; set; }
+
+        public DateTime? LastModificationTime { get; set; }
+    }
+}