Prechádzať zdrojové kódy

Merge branch 'test' of http://110.188.24.182:10023/Fengwo/hotline into test

田爽 4 mesiacov pred
rodič
commit
aabaaa413b

+ 103 - 29
src/Hotline.Api/Controllers/PlanController.cs

@@ -12,6 +12,9 @@ using Hotline.Share.Tools;
 using Hotline.Share.Enums.Planlibrary;
 using Hotline.Application.ExportWord;
 using Hotline.Application.Tools;
+using Hotline.KnowledgeBase;
+using Hotline.Share.Dtos.Knowledge;
+using System.Data;
 
 namespace Hotline.Api.Controllers
 {
@@ -129,6 +132,30 @@ namespace Hotline.Api.Controllers
 
         #region 预案库管理
 
+        /// <summary>
+        /// 预案库分类列表
+        /// </summary>
+        /// <param name="IsEnable"></param>
+        /// <returns></returns>
+        [HttpGet("list/treelist")]
+        public async Task<List<PlanTypeDto>> QueryAllPlanTypeTreeList(bool? IsEnable)
+        {
+            return await _planTypeRepository.Queryable()
+                .WhereIF(IsEnable.HasValue, x => x.IsEnable == IsEnable)
+                .Where(x => SqlFunc.Subqueryable<PlanTypeOrg>().Where(to => to.TypeId == x.Id).Any() ||
+                SqlFunc.Subqueryable<PlanTypeOrg>().Where(to => to.TypeId == x.Id).NotAny()
+                )
+                .Select(x => new PlanTypeDto()
+                {
+                    Id = x.Id.SelectAll(),
+                    PlanNum = SqlFunc.Subqueryable<PlanRelationType>().LeftJoin<PlanList>((kr, k) => kr.PlanId == k.Id)
+                         .Where((kr, k) => kr.PlanTypeSpliceName.StartsWith(x.SpliceName))
+                         .DistinctCount(kr => kr.PlanId)
+                }
+                )
+                .OrderBy(x => x.Sort).ToTreeAsync(it => it.children, it => it.ParentId, null, it => it.Id);
+        }
+
         /// <summary>
         /// 预案库列表
         /// </summary>
@@ -146,14 +173,39 @@ namespace Hotline.Api.Controllers
         /// <param name="dto"></param>
         /// <returns></returns>
         [HttpPost("list/draft")]
-        public async Task<string> AddPlanDraft([FromBody] AddPlanListDto dto)
+        public async Task<string> PlanDraft([FromBody] AddPlanListDto dto)
         {
-            dto.Status = EPlanStatus.Drafts;
+            dto.Status = EPlanStatus.NewDrafts;
             return await _planApplication.AddPlanAsync(dto, HttpContext.RequestAborted);
         }
 
         /// <summary>
-        /// 预案库新增
+        /// 预案库草稿修改
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPut("list/draftupdate")]
+        public async Task UpdatePlanDraft([FromBody] UpdatePlanListDto dto)
+        {
+            dto.Status = EPlanStatus.NewDrafts;
+            await _planApplication.UpdatePlanAsync(dto, HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 预案库草稿上架到审核
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPut("list/draftadd")]
+        public async Task AddPlanDraft([FromBody] UpdatePlanListDto dto)
+        {
+            dto.ApplyStatus = EPlanApplyStatus.Add;
+            dto.Status = EPlanStatus.Auditing;
+            await _planApplication.UpdatePlanAsync(dto, HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 预案库新增到审核
         /// </summary>
         /// <param name="dto"></param>
         /// <returns></returns>
@@ -166,7 +218,7 @@ namespace Hotline.Api.Controllers
         }
 
         /// <summary>
-        /// 预案库编辑
+        /// 预案库编辑提交到审核
         /// </summary>
         /// <param name="dto"></param>
         /// <returns></returns>
@@ -183,7 +235,7 @@ namespace Hotline.Api.Controllers
         /// </summary>
         /// <param name="Id">预案库ID</param>
         /// <returns></returns>
-        [HttpPut("list/offshelf")]
+        [HttpGet("list/offshelf/{Id}")]
         public async Task OffshelfPlan(string Id)
         {
             UpdatePlanListDto dto = new UpdatePlanListDto();
@@ -191,29 +243,28 @@ namespace Hotline.Api.Controllers
             dto.ApplyStatus = EPlanApplyStatus.Offshelf;
             dto.Status = EPlanStatus.Auditing;
 
-            await _planApplication.UpdatePlanAsync(dto, HttpContext.RequestAborted);
+            await _planApplication.AuditPlanAsync(dto, HttpContext.RequestAborted);
         }
 
         /// <summary>
         /// 预案库审核(新增、修改、下架)
         /// </summary>
-        /// <param name="Id">预案库ID</param>
-        /// <param name="state">0不通过 1通过</param>
+        /// <param name="dto"></param>
         /// <returns></returns>
         [HttpPut("list/examin")]
-        public async Task ExaminPlan(string Id, int state)
+        public async Task ExaminPlan([FromBody] AuditPlanListDto dto)
         {
-            var plan = await _planListRepository.GetAsync(Id);
+            var plan = await _planListRepository.GetAsync(dto.Id);
             if (plan == null)
                 throw UserFriendlyException.SameMessage("预案库查询失败");
 
             var planDto = _mapper.Map<UpdatePlanListDto>(plan);
 
-            if (state == 0)
+            if (dto.State == 0)
             {//不同意
-                planDto.Status = EPlanStatus.Drafts;
+                planDto.Status = EPlanStatus.Revert;
             }
-            else if (state == 1)
+            else if (dto.State == 1)
             {//同意 
                 if (planDto.ApplyStatus == EPlanApplyStatus.Add)
                 {
@@ -222,63 +273,63 @@ namespace Hotline.Api.Controllers
                 if (planDto.ApplyStatus == EPlanApplyStatus.Update)
                 {
                     planDto.Status = EPlanStatus.OnShelf;
+                    planDto.UpdateTime = DateTime.Now;
                 }
                 if (planDto.ApplyStatus == EPlanApplyStatus.Offshelf)
                 {
                     planDto.Status = EPlanStatus.OffShelf;
                 }
             }
-            planDto.Id = Id;
+            planDto.Id = dto.Id;
             planDto.ExaminTime = DateTime.Now;
             planDto.ExaminManId = _sessionContext.UserId;
             planDto.ExaminOrganizeId = _sessionContext.OrgId;
 
-            await _planApplication.UpdatePlanAsync(planDto, HttpContext.RequestAborted);
+            await _planApplication.AuditPlanAsync(planDto, HttpContext.RequestAborted);
         }
 
         /// <summary>
         /// 预案库详情
         /// </summary>
-        /// <param name="Id">预案库ID</param>
-        /// <param name="IsAddPv">默认不增加,false不增加,true增加浏览量</param>
+        /// <param name="dto"></param>
         /// <returns></returns>
-        [HttpGet("list/info/{Id}")]
-        public async Task<PlanInfoDto> GetPlan(string Id, bool? IsAddPv)
+        [HttpGet("list/info")]
+        public async Task<PlanInfoDto> GetPlan([FromBody] PvPlanListDto dto)
         {
-            return await _planApplication.GetPlanAsync(Id, IsAddPv, HttpContext.RequestAborted);
+            return await _planApplication.GetPlanAsync(dto.Id, dto.IsAddPv, HttpContext.RequestAborted);
         }
 
         /// <summary>
         /// 预案库评分
         /// </summary>
-        /// <param name="Id">预案库ID</param>
-        /// <param name="Score">评分</param>
+        /// <param name="dto"></param>
         /// <returns></returns>
         [HttpPut("list/score")]
-        public async Task ScorePlan(string Id, decimal Score)
+        public async Task ScorePlan([FromBody] PvPlanListDto dto)
         {
-            var collect = await _planCollectRepository.GetAsync(x => x.PlanId == Id && x.CreatorId == _sessionContext.UserId);
+            var collect = await _planCollectRepository.GetAsync(x => x.PlanId == dto.Id && x.CreatorId == _sessionContext.UserId);
             if (collect != null)
             {
                 if (collect.Score > 0)
                     throw UserFriendlyException.SameMessage("当前知识已经评分");
 
-                collect.Score = Score;
+                collect.Score = dto.Score;
                 await _planCollectRepository.UpdateAsync(collect, HttpContext.RequestAborted);
             }
             else
             {
-                collect.PlanId = Id;
-                collect.Score = Score;
+                collect = new PlanCollect();
+                collect.PlanId = dto.Id;
+                collect.Score = dto.Score;
                 await _planCollectRepository.AddAsync(collect, HttpContext.RequestAborted);
             }
 
             //计算总分
-            var sugar = _planCollectRepository.Queryable().Where(x => x.PlanId == Id);
+            var sugar = _planCollectRepository.Queryable().Where(x => x.PlanId == dto.Id);
             var count = await sugar.CountAsync();
             var collects = await sugar.SumAsync(x => x.Score);
             var scoreTemp = collects / count;
-            var plan = await _planListRepository.GetAsync(x => x.Id == Id);
+            var plan = await _planListRepository.GetAsync(x => x.Id == dto.Id);
             if (plan != null)
             {
                 plan.Score = decimal.Round(scoreTemp.Value, 1);
@@ -324,5 +375,28 @@ namespace Hotline.Api.Controllers
 
         #endregion
 
+        #region 预案库检索
+
+        /// <summary>
+        /// 预案库列表前10
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("list/top10")]
+        public async Task<List<PlanPageViewDto>> QueryTop10PlanList()
+        {
+            return await _planListRepository.Queryable()
+                .Take(10)
+                .Where(x => x.Status == EPlanStatus.OnShelf)
+                .Select(x => new PlanPageViewDto
+                {
+                    Id = x.Id,
+                    Title = x.Title,
+                    PageView = x.PageView
+                })
+                .OrderBy(x => x.PageView, OrderByType.Desc)
+                .ToListAsync();
+        }
+
+        #endregion
     }
 }

+ 7 - 0
src/Hotline.Application/Planlibrary/IPlanApplication.cs

@@ -54,6 +54,13 @@ namespace Hotline.Application.Planlibrary
         /// <returns></returns>
         Task UpdatePlanAsync(UpdatePlanListDto dto, CancellationToken cancellationToken);
 
+        /// <summary>
+        ///预案库类型 - 下架审核
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        Task AuditPlanAsync(UpdatePlanListDto dto, CancellationToken cancellationToken);
+
         /// <summary>
         ///预案库类型 - 详情
         /// </summary>

+ 52 - 16
src/Hotline.Application/Planlibrary/PlanApplication.cs

@@ -14,6 +14,10 @@ using Hotline.File;
 using Hotline.Application.Bulletin;
 using Hotline.Share.Tools;
 using Hotline.Application.Tools;
+using Hotline.KnowledgeBase;
+using NPOI.SS.Formula.Functions;
+using SqlSugar;
+using Senparc.CO2NET.Extensions;
 
 namespace Hotline.Application.Planlibrary
 {
@@ -177,10 +181,10 @@ namespace Hotline.Application.Planlibrary
         /// <returns></returns>
         public async Task<(int, IList<PlanDataDto>)> QueryAllPlanListAsync(PlanListDto pagedDto, CancellationToken cancellationToken)
         {
-            if (!_sessionContext.OrgIsCenter)
-            {// 部门只能查询【部门预案库】
-                pagedDto.Attribution = "部门预案库";
-            }
+            //if (!_sessionContext.OrgIsCenter)
+            //{// 部门只能查询【部门预案库】
+            //    pagedDto.Attribution = "部门预案库";
+            //}
 
             var typeSpliceName = string.Empty;
             var hotspotHotSpotFullName = string.Empty;
@@ -199,8 +203,8 @@ namespace Hotline.Application.Planlibrary
 
             //单表分页
             var (total, temp) = await _planListRepository.Queryable()
-                //.Includes(x => x.PlanTypes)
-
+                .Includes(x => x.PlanTypes)
+                .Includes(x => x.HotspotType)
                 .Where(x => x.IsDeleted == false)
                 .Where(x => (x.Status == EPlanStatus.Drafts && x.CreatorId == _sessionContext.UserId) || (x.Status != EPlanStatus.Drafts))
                 .WhereIF(OrgSeedData.CenterId != pagedDto.CreateOrgId && !string.IsNullOrEmpty(pagedDto.CreateOrgId), x => x.CreatorOrgId != null && x.CreatorOrgId.StartsWith(pagedDto.CreateOrgId!))
@@ -234,7 +238,11 @@ namespace Hotline.Application.Planlibrary
                 .WhereIF(pagedDto.ExaminTimeStart.HasValue, x => x.ExaminTime >= pagedDto.ExaminTimeStart)
                 .WhereIF(pagedDto.ExaminTimeEnd.HasValue, x => x.ExaminTime <= pagedDto.ExaminTimeEnd)
 
-                .OrderByDescending(d => d.CreationTime)
+                .OrderByIF(string.IsNullOrEmpty(pagedDto.SortField), d => d.CreationTime, OrderByType.Desc)
+                .OrderByIF(pagedDto is { SortField: "PageView" }, d => d.PageView, OrderByType.Desc)         //阅读量
+                .OrderByIF(pagedDto is { SortField: "Score" }, d => d.Score, OrderByType.Desc)               //评分
+                .OrderByIF(pagedDto is { SortField: "CreationTime" }, d => d.CreationTime, OrderByType.Desc) //创建时间
+
                 .ToPagedListAsync(pagedDto.PageIndex, pagedDto.PageSize, cancellationToken);
 
             return (total, _mapper.Map<IList<PlanDataDto>>(temp));
@@ -258,7 +266,7 @@ namespace Hotline.Application.Planlibrary
             if (any)
                 throw UserFriendlyException.SameMessage("当前知识标题存在重复标题!");
 
-            if (dto.Files != null)
+            if (dto.Files != null && dto.Files.Count > 0)
                 pList.FileJson = await _fileRepository.AddFileAsync(dto.Files, pList.Id, "", cancellationToken);
             await _planListRepository.AddAsync(pList, cancellationToken);
 
@@ -285,6 +293,7 @@ namespace Hotline.Application.Planlibrary
         public async Task UpdatePlanAsync(UpdatePlanListDto dto, CancellationToken cancellationToken)
         {
             var plan = await _planListRepository.GetAsync(dto.Id);
+
             if (plan == null)
                 throw UserFriendlyException.SameMessage("预案库查询失败");
 
@@ -299,7 +308,7 @@ namespace Hotline.Application.Planlibrary
 
             plan.HotspotId = dto.HotspotId;
 
-            if (dto.Files.Any())
+            if (dto.Files != null && dto.Files.Count > 0)
                 plan.FileJson = await _fileRepository.AddFileAsync(dto.Files, plan.Id, "", cancellationToken);
             else
                 plan.FileJson = new List<Share.Dtos.File.FileJson>();
@@ -318,6 +327,33 @@ namespace Hotline.Application.Planlibrary
 
         #endregion
 
+        #region 预案库 - 下架审核
+
+        /// <summary>
+        /// 下架审核
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public async Task AuditPlanAsync(UpdatePlanListDto dto, CancellationToken cancellationToken)
+        {
+            var plan = await _planListRepository.GetAsync(dto.Id);
+
+            if (plan == null)
+                throw UserFriendlyException.SameMessage("预案库查询失败");
+
+            plan.Status = (EPlanStatus)dto.Status!;
+            plan.ApplyStatus = (EPlanApplyStatus)dto.ApplyStatus!;
+            plan.ExaminTime = dto.ExaminTime;
+            plan.ExaminManId = dto.ExaminManId;
+            plan.ExaminOrganizeId = dto.ExaminOrganizeId;
+            plan.UpdateTime = dto.UpdateTime;
+
+            await _planListRepository.UpdateNullAsync(plan, cancellationToken);
+        }
+
+        #endregion
+
         #region 预案库 - 详情
 
         /// <summary>
@@ -342,11 +378,6 @@ namespace Hotline.Application.Planlibrary
             //var hot = await _hotspotTypeRepository.GetAsync(plan.HotspotId, cancellationToken);
             //if (hot != null)
             //    planDto.HotspotId = hot.HotSpotFullName;
-            
-            // 收藏
-            //var collect = await _knowledgeCollectRepository.GetAsync(x => x.KnowledgeId == Id && x.CreatorId == _sessionContext.UserId);
-            //if (collect != null)
-            //    knowledgeShowInfoDto.Collect = _mapper.Map<KnowledgeCollectDto>(collect);
 
             if (planInfoDto.FileJson != null && planInfoDto.FileJson.Any())
             {
@@ -355,8 +386,13 @@ namespace Hotline.Application.Planlibrary
             }
 
             // 更新浏览量
-            //if (IsAddPv == true)
-            //    _mediator.Publish(new GetKnowledgeInfoNotify(knowledge));
+            if (IsAddPv == true)
+            {
+                //修改浏览量
+                plan.PageView++;
+                //修改点击量
+                await _planListRepository.UpdateAsync(plan, cancellationToken);
+            }
             return planInfoDto;
         }
 

+ 23 - 15
src/Hotline.Share/Dtos/Planlibrary/PlanDataDto.cs

@@ -93,38 +93,38 @@ namespace Hotline.Share.Dtos.Planlibrary
         /// </summary>
         public string StatusName => NewStatus.GetDescription();
 
-        public HotspotDto HotspotType { get; set; }
-
-        /// <summary>
-        /// 热点
-        /// </summary>
-        public string HotspotName => HotspotType != null ? HotspotType.HotSpotFullName : string.Empty;
-
         /// <summary>
-        /// 知识分类名称
+        /// 预案分类
         /// </summary>
-        public string KnowledgeTypeText => GetKnowledgeTypeText(KnowledgeType);
+        public List<PlanRelationTypeDto> PlanTypes { get; set; }
 
         /// <summary>
-        /// 知识分类
+        /// 预案分类名称
         /// </summary>
-        public List<PlanRelationTypeDto> KnowledgeType { get; set; }
+        public string PlanTypeText => GetPlanTypeText(PlanTypes);
 
         /// <summary>
-        /// 获取知识分类名称
+        /// 获取预案分类名称
         /// </summary>
         /// <returns></returns>
-        public string GetKnowledgeTypeText(List<PlanRelationTypeDto> items)
+        public string GetPlanTypeText(List<PlanRelationTypeDto> items)
         {
 
-            if (KnowledgeType != null && KnowledgeType.Any())
+            if (PlanTypes != null && PlanTypes.Any())
             {
-                var names = KnowledgeType.Select(x => x.PlanTypeName).ToList();
+                var names = PlanTypes.Select(x => x.PlanTypeName).ToList();
                 return string.Join(",", names);
             }
             return "";
         }
 
+        public HotspotDto HotspotType { get; set; }
+
+        /// <summary>
+        /// 热点
+        /// </summary>
+        public string HotspotName => HotspotType != null ? HotspotType.HotSpotFullName : string.Empty;
+
     }
 
     public record PlanRelationTypeDto
@@ -178,4 +178,12 @@ public class PlanInfoExportDto
     /// 导出格式
     /// </summary>
     public EFileType FileType { get; set; }
+}
+
+
+public class PlanPageViewDto
+{
+    public string Id { get; set; }
+    public string Title { get; set; }
+    public int PageView { get; set; }
 }

+ 51 - 5
src/Hotline.Share/Dtos/Planlibrary/PlanListDto.cs

@@ -140,6 +140,16 @@ namespace Hotline.Share.Dtos.Planlibrary
         /// 评分
         /// </summary>
         public decimal? Score { get; set; } = decimal.Zero;
+
+        /// <summary>
+        /// 排序(需要被排序的字段名)
+        /// </summary>
+        public string? SortField { get; set; }
+
+        /// <summary>
+        /// 排序方向 (0: 升序Asc; 1: 降序Desc)
+        /// </summary>
+        public int OrderByType { get; set; } = 1;
     }
 
 
@@ -163,12 +173,12 @@ namespace Hotline.Share.Dtos.Planlibrary
         /// <summary>
         /// 预案归属
         /// </summary>
-        public string? Attribution { get; set; }
+        public string Attribution { get; set; }
 
-        /// <summary>
-        /// 分类ID
-        /// </summary>
-        public string? PlanTypeID { get; set; }
+        ///// <summary>
+        ///// 分类ID
+        ///// </summary>
+        //public string? PlanTypeID { get; set; }
 
         /// <summary>
         /// 分类
@@ -227,6 +237,11 @@ namespace Hotline.Share.Dtos.Planlibrary
         /// 审核时间
         /// </summary>
         public DateTime? ExaminTime { get; set; }
+
+        /// <summary>
+        /// 修改时间
+        /// </summary>
+        public DateTime? UpdateTime { get; set; }
     }
 
     public record DelPlanListDto
@@ -305,4 +320,35 @@ namespace Hotline.Share.Dtos.Planlibrary
         /// </summary>
         public List<FileJson>? FileJson { get; set; }
     }
+
+    public record AuditPlanListDto
+    {
+        /// <summary>
+        /// 预案库ID
+        /// </summary>
+        public string Id { get; set; }
+
+        /// <summary>
+        /// 审核状态 0不同意 1同意
+        /// </summary>
+        public int State { get; set; }
+    }
+
+    public record PvPlanListDto
+    {
+        /// <summary>
+        /// 预案库ID
+        /// </summary>
+        public string Id { get; set; }
+
+        /// <summary>
+        /// 浏览量:默认不增加,false不增加,true增加浏览量
+        /// </summary>
+        public bool IsAddPv { get; set; } = false;
+
+        /// <summary>
+        /// 评分
+        /// </summary>
+        public decimal Score { get; set; }
+    }
 }

+ 2 - 2
src/Hotline/Planlibrary/PlanList.cs

@@ -53,7 +53,7 @@ public class PlanList : CreationEntity
     /// 预案归属
     /// </summary>
     [SugarColumn(ColumnDescription = "预案归属")]
-    public string? Attribution { get; set; }
+    public string Attribution { get; set; }
 
     /// <summary>
     /// 热点
@@ -71,7 +71,7 @@ public class PlanList : CreationEntity
     /// 是否公开
     /// </summary>
     [SugarColumn(ColumnDescription = "是否公开")]
-    public bool? IsPublic { get; set; }
+    public bool IsPublic { get; set; }
 
     /// <summary>
     /// 是否删除