田爽 1 年之前
父節點
當前提交
300fcbca32

+ 61 - 3
src/Hotline.Api/Controllers/KnowledgeController.cs

@@ -3,8 +3,8 @@ using Hotline.Application.Knowledge;
 using Hotline.FlowEngine.WorkflowModules;
 using Hotline.KnowledgeBase;
 using Hotline.KnowledgeBase.Notifies;
-using Hotline.Orders;
 using Hotline.Permissions;
+using Hotline.Quality;
 using Hotline.Repository.SqlSugar.Extensions;
 using Hotline.Repository.SqlSugar.Ts;
 using Hotline.Settings;
@@ -13,11 +13,14 @@ using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.FlowEngine;
 using Hotline.Share.Dtos.Knowledge;
 using Hotline.Share.Dtos.Order;
+using Hotline.Share.Dtos.Quality;
 using Hotline.Share.Enums.KnowledgeBase;
 using Hotline.Users;
 using MapsterMapper;
 using MediatR;
 using Microsoft.AspNetCore.Mvc;
+using Org.BouncyCastle.Utilities;
+using Polly.Caching;
 using SqlSugar;
 using XF.Domain.Authentications;
 using XF.Domain.Exceptions;
@@ -47,6 +50,7 @@ namespace Hotline.Api.Controllers
 		private readonly IRepository<KnowledgeCorrection> _knowledgeCorrectionRepository;
 		private readonly IRepository<KnowledgeCollect> _knowledgeCollectRepository;
 		private readonly ISystemDomainService _systemDomainService;
+		private readonly IRepository<KnowledgeComment> _knowledgeCommentRepository;
 
 
 		public KnowledgeController(
@@ -66,7 +70,8 @@ namespace Hotline.Api.Controllers
 		   IRepository<KnowledgeQuestions> knowledgeQuestionsRepository,
 		   IRepository<KnowledgeCorrection> knowledgeCorrectionRepository,
 		   IRepository<KnowledgeCollect> knowledgeCollectRepository,
-		   ISystemDomainService systemDomainService
+		   ISystemDomainService systemDomainService,
+		   IRepository<KnowledgeComment> knowledgeCommentRepository
 		   )
 		{
 			_knowledgeRepository = knowledgeRepository;
@@ -86,6 +91,7 @@ namespace Hotline.Api.Controllers
 			_knowledgeCorrectionRepository = knowledgeCorrectionRepository;
 			_knowledgeCollectRepository = knowledgeCollectRepository;
 			_systemDomainService = systemDomainService;
+			_knowledgeCommentRepository = knowledgeCommentRepository;
 		}
 
 		#endregion
@@ -171,7 +177,7 @@ namespace Hotline.Api.Controllers
 		/// </summary>
 		/// <param name="title"></param>
 		/// <returns></returns>
-		[HttpGet("/{Title}")]
+		[HttpGet("{Title}")]
 		public async Task<bool> KnowledgeTitle(string Title) {
 			var count = await _knowledgeRepository.Queryable().Where(x => x.Title == Title).CountAsync();
 			return count > 0;
@@ -1030,5 +1036,57 @@ namespace Hotline.Api.Controllers
 			}
 		}
 		#endregion
+
+		#region 知识评论
+
+		//[Permission(EPermission.AddKnowledgeCollect)]
+		[HttpPost("knowledge_comment")]
+		public async Task Add([FromBody] KnowledgeCommentAddDto dto)
+		{
+			var model = _mapper.Map<KnowledgeComment>(dto);
+			await _knowledgeCommentRepository.AddAsync(model, HttpContext.RequestAborted);
+			if (!string.IsNullOrEmpty(dto.ReplyId))
+			{
+				var comment = await _knowledgeCommentRepository.GetAsync(dto.ReplyId);
+				if (comment != null) 
+				{
+					comment.ReplyNum++;
+					await _knowledgeCommentRepository.UpdateAsync(comment, HttpContext.RequestAborted);
+				}
+			}
+		}
+
+		//[Permission(EPermission.DeleteQualityItem)]
+		[HttpDelete("itemBatch")]
+		public async Task Delete([FromBody] KnowledgeCommentDeleteDto dto)
+		{
+			await _knowledgeCommentRepository.RemoveAsync(x => x.Id == dto.Id);
+		}
+
+
+		//[Permission(EPermission.UpdateQualityItem)]
+		[HttpPut("item")]
+		public async Task Update([FromBody] KnowledgeCommentUpdateDto dto)
+		{
+			var comment = await _knowledgeCommentRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
+			if (comment is null)
+				throw UserFriendlyException.SameMessage("无效评论");
+			_mapper.Map(dto, comment);
+			await _knowledgeCommentRepository.UpdateAsync(comment, HttpContext.RequestAborted);
+		}
+
+		//[Permission(EPermission.QualityItemList)]
+		[HttpGet("item/list")]
+		public async Task<List<KnowledgeCommentDto>> List([FromQuery] KnowledgeCommentListDto dto)
+		{
+			var comments = await _knowledgeCommentRepository.Queryable()
+				.WhereIF(!string.IsNullOrEmpty(dto.KnowledgeId), x => x.KnowledgeId == dto.KnowledgeId)
+				.WhereIF(!string.IsNullOrEmpty(dto.ReplyId), x => x.ReplyId == dto.ReplyId)
+				.WhereIF(dto.All.HasValue && dto.All == false, x => x.CreatorId == _sessionContext.UserId)
+				.OrderByDescending(x => x.CreationTime)
+				.ToListAsync();
+			return new List<KnowledgeCommentDto>(_mapper.Map<IReadOnlyList<KnowledgeCommentDto>>(comments));
+		}
+		#endregion
 	}
 }

+ 133 - 0
src/Hotline.Share/Dtos/Knowledge/KnowledgeCommentDto.cs

@@ -0,0 +1,133 @@
+using Hotline.Share.Enums.Quality;
+using Hotline.Share.Requests;
+
+namespace Hotline.Share.Dtos.Knowledge
+{
+	public class KnowledgeCommentDto : KnowledgeCommentBaseDto
+	{
+		/// <summary>
+		/// 知识库ID
+		/// </summary>
+		public string KnowledgeId { get; set; }
+
+		/// <summary>
+		/// 知识库
+		/// </summary>
+		public KnowledgeDto Knowledge { get; set; }
+
+		/// <summary>
+		/// 评论内容
+		/// </summary>
+		public string? Content { get; set; }
+
+		/// <summary>
+		/// 回复ID
+		/// </summary>
+		public string? ReplyId { get; set; }
+
+		/// <summary>
+		/// 匿名
+		/// </summary>
+		public bool Cryptonym { get; set; }
+
+		/// <summary>
+		/// 回复数
+		/// </summary>
+		public int ReplyNum { get; set; } = 0;
+	}
+
+	public class KnowledgeCommentAddDto
+	{
+		/// <summary>
+		/// 知识库ID
+		/// </summary>
+		public string KnowledgeId { get; set; }
+
+		/// <summary>
+		/// 知识库
+		/// </summary>
+		public KnowledgeDto Knowledge { get; set; }
+
+		/// <summary>
+		/// 评论内容
+		/// </summary>
+		public string? Content { get; set; }
+
+		/// <summary>
+		/// 回复ID
+		/// </summary>
+		public string? ReplyId { get; set; }
+
+		/// <summary>
+		/// 匿名
+		/// </summary>
+		public bool Cryptonym { get; set; }
+
+		/// <summary>
+		/// 回复数
+		/// </summary>
+		public int ReplyNum { get; set; } = 0;
+	}
+
+	public class KnowledgeCommentDeleteDto
+	{
+		public string Id { get; set; }
+	}
+
+	public class KnowledgeCommentUpdateDto : KnowledgeCommentAddDto
+	{
+		public string Id { get; set; }
+	}
+	public class KnowledgeCommentBaseDto
+	{
+		public DateTime? LastModificationTime { get; set; }
+
+		public bool IsDeleted { get; set; }
+
+		/// <summary>
+		/// 删除时间
+		/// </summary>
+		public DateTime? DeletionTime { get; set; }
+
+
+		/// <summary>
+		/// 创建时间
+		/// </summary>
+		public DateTime CreationTime { get; set; }
+
+		public string Id { get; set; }
+
+		/// <summary>
+		/// 组织Id
+		/// </summary>
+		public string? CreatorOrgId { get; set; }
+
+
+		public string? CreatorOrgName { get; set; }
+
+		/// <summary>
+		/// 创建人
+		/// </summary>
+		public string? CreatorId { get; set; }
+
+		public string? CreatorName { get; set; }
+	}
+
+	public record KnowledgeCommentListDto : PagedKeywordRequest
+	{
+		/// <summary>
+		/// 知识库ID
+		/// </summary>
+		public string KnowledgeId { get; set; }
+
+		/// <summary>
+		/// 回复ID
+		/// </summary>
+		public string? ReplyId { get; set; }
+
+		/// <summary>
+		/// 查询全部
+		/// </summary>
+		public bool? All { get; set; }
+	}
+}

+ 52 - 0
src/Hotline/KnowledgeBase/KnowledgeComment.cs

@@ -0,0 +1,52 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using XF.Domain.Repository;
+
+namespace Hotline.KnowledgeBase
+{
+	[Description("知识库评论")]
+	public class KnowledgeComment : FullStateEntity
+	{
+		/// <summary>
+		/// 知识库ID
+		/// </summary>
+		[SugarColumn(ColumnDescription = "知识库ID")]
+		public string KnowledgeId { get; set; }
+
+		/// <summary>
+		/// 知识库
+		/// </summary>
+		[Navigate(NavigateType.OneToOne, nameof(KnowledgeId))]
+		public Knowledge Knowledge { get; set; }
+
+		/// <summary>
+		/// 评论内容
+		/// </summary>
+		[SugarColumn(ColumnDescription = "评论内容", ColumnDataType = "varchar(2000)")]
+		public string? Content { get; set; }
+
+		/// <summary>
+		/// 回复ID
+		/// </summary>
+		[SugarColumn(ColumnDescription = "回复ID")]
+		public string? ReplyId { get; set; }
+
+		/// <summary>
+		/// 匿名
+		/// </summary>
+		[SugarColumn(ColumnDescription = "匿名")]
+		public bool Cryptonym { get; set; }= false;
+
+		/// <summary>
+		/// 回复数
+		/// </summary>
+		[SugarColumn(ColumnDescription = "回复数")]
+		public int ReplyNum { get; set; } = 0;
+
+	}
+}

+ 26 - 0
src/Hotline/Permissions/EPermission.cs

@@ -952,6 +952,32 @@ namespace Hotline.Permissions
 		AddKnowledgeScore = 400902,
 		#endregion
 
+		#region 知识评论
+		/// <summary>
+		/// 知识提问列表
+		/// </summary>
+		[Display(GroupName = "KnowledgeComment", Name = "知识提问列表", Description = "知识提问列表")]
+		KnowledgeCommentList = 401000,
+
+		/// <summary>
+		/// 新增知识提问
+		/// </summary>
+		[Display(GroupName = "KnowledgeComment", Name = "新增知识提问", Description = "新增知识提问")]
+		AddKnowledgeComment = 401001,
+
+		/// <summary>
+		/// 删除知识提问
+		/// </summary>
+		[Display(GroupName = "KnowledgeComment", Name = "删除知识提问", Description = "删除知识提问")]
+		DeleteKnowledgeComment = 401002,
+
+		/// <summary>
+		/// 修改知识提问
+		/// </summary>
+		[Display(GroupName = "KnowledgeComment", Name = "修改知识提问", Description = "修改知识提问")]
+		UpdateKnowledgeComment = 401003,
+		#endregion
+
 		#endregion
 
 		#region 业务管理(500)