|
@@ -1,9 +1,6 @@
|
|
|
using Hotline.Share.Dtos.Knowledge;
|
|
|
using Hotline.Share.Enums.KnowledgeBase;
|
|
|
using MapsterMapper;
|
|
|
-using Microsoft.AspNetCore.Http;
|
|
|
-using Microsoft.AspNetCore.Mvc;
|
|
|
-using System.Security.Permissions;
|
|
|
using XF.Domain.Dependency;
|
|
|
using XF.Domain.Exceptions;
|
|
|
|
|
@@ -32,16 +29,18 @@ namespace Hotline.KnowledgeBase
|
|
|
/// <summary>
|
|
|
/// 查询所有子级
|
|
|
/// </summary>
|
|
|
- /// <param name="treeDatas"></param>
|
|
|
- /// <param name="ID"></param>
|
|
|
- /// <param name="checkId"></param>
|
|
|
+ /// <param name="treeDatas">分类数据</param>
|
|
|
+ /// <param name="ID">需要查询哪级下面的分类</param>
|
|
|
+ /// <param name="checkId">选中的数据ID</param>
|
|
|
/// <returns></returns>
|
|
|
- public List<TreeListDto> GetChildren(List<KnowledgeType> treeDatas, string ID, string checkId)
|
|
|
+ public List<TreeListDto> GetChildren(List<KnowledgeType> treeDatas, string ID, string? checkId)
|
|
|
{
|
|
|
List<TreeListDto> nodeList = new();
|
|
|
+ //根据ID查询子级
|
|
|
var children = treeDatas.Where(q => q.ParentId == ID);
|
|
|
foreach (var dr in children)
|
|
|
{
|
|
|
+ //组装数据
|
|
|
TreeListDto node = new()
|
|
|
{
|
|
|
name = dr.Name,
|
|
@@ -49,27 +48,30 @@ namespace Hotline.KnowledgeBase
|
|
|
value = dr.Id,
|
|
|
IsEnable = dr.IsEnable
|
|
|
};
|
|
|
- if (!string.IsNullOrEmpty(checkId) && checkId == dr.Id)
|
|
|
- {
|
|
|
+ //是否选中
|
|
|
+ if (!string.IsNullOrEmpty(checkId) && checkId != Guid.Empty.ToString() && checkId == dr.Id)
|
|
|
node.selected = true;
|
|
|
- }
|
|
|
+ //子级数据赋值
|
|
|
node.children = GetChildren(treeDatas, node.value, checkId);
|
|
|
+ //添加数据
|
|
|
nodeList.Add(node);
|
|
|
}
|
|
|
return nodeList;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 查询父级节点
|
|
|
+ /// 查询父级名称
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
/// <returns></returns>
|
|
|
private async Task<List<string>> GetParentNode(string Id)
|
|
|
{
|
|
|
List<string> list = new();
|
|
|
+ //查询父级数据
|
|
|
var type = await _knowledgeTypeRepository.GetAsync(p => p.Id == Id);
|
|
|
if (type != null)
|
|
|
{
|
|
|
+ //添加名称
|
|
|
list.Add(type.Name);
|
|
|
list.AddRange(await GetParentNode(type.ParentId));
|
|
|
}
|
|
@@ -77,16 +79,18 @@ namespace Hotline.KnowledgeBase
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 查询子级节点
|
|
|
+ /// 查询子级节点数据
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
/// <returns></returns>
|
|
|
private async Task<List<KnowledgeType>> GetChildNode(string Id)
|
|
|
{
|
|
|
List<KnowledgeType> list = new();
|
|
|
+ //查询数据
|
|
|
var typelist = await _knowledgeTypeRepository.QueryAsync(p => p.ParentId == Id);
|
|
|
if (typelist != null)
|
|
|
{
|
|
|
+ //处理数据
|
|
|
foreach (var item in typelist)
|
|
|
{
|
|
|
list.Add(item);
|
|
@@ -97,23 +101,27 @@ namespace Hotline.KnowledgeBase
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- ///知识分类- 新增
|
|
|
+ /// 知识分类- 新增
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task<string> TypeAdd(AddKnowledgeTypeDto dto, CancellationToken cancellationToken)
|
|
|
{
|
|
|
var type = _mapper.Map<KnowledgeType>(dto);
|
|
|
type.IsEnable = true;
|
|
|
+ //获取分类名称全称
|
|
|
string FullName = await GetFullName(type.ParentId);
|
|
|
+ //处理全称,如果为第一级直接用全称,否则获取全称后拼接名称
|
|
|
type.SpliceName = string.IsNullOrEmpty(FullName) ? dto.Name : FullName + "-" + dto.Name;
|
|
|
return await _knowledgeTypeRepository.AddAsync(type, cancellationToken);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- ///知识分类- 编辑
|
|
|
+ /// 知识分类- 编辑
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task TypeUpdate(UpdateKnowledgeTypeDto dto, CancellationToken cancellationToken)
|
|
|
{
|
|
@@ -130,8 +138,8 @@ namespace Hotline.KnowledgeBase
|
|
|
//如果更改了名称,则修改全称,未更改不修改
|
|
|
if (result)
|
|
|
{
|
|
|
- string FullName = await GetFullName(type.ParentId);
|
|
|
- type.SpliceName = string.IsNullOrEmpty(FullName) ? dto.Name : FullName + "-" + dto.Name;
|
|
|
+ string FullName = await GetFullName(type.ParentId);//获取分类名称全称
|
|
|
+ type.SpliceName = string.IsNullOrEmpty(FullName) ? dto.Name : FullName + "-" + dto.Name;//处理全称,如果为第一级直接用全称,否则获取全称后拼接名称
|
|
|
}
|
|
|
//修改数据
|
|
|
await _knowledgeTypeRepository.UpdateAsync(type, cancellationToken);
|
|
@@ -141,28 +149,26 @@ namespace Hotline.KnowledgeBase
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 知识分类-新增、编辑初始化
|
|
|
+ /// 知识分类-新增、编辑初始化
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
/// <param name="ParentId"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task<KnowledgeTypeDto> TypeInit(string Id, string ParentId, CancellationToken cancellationToken)
|
|
|
{
|
|
|
KnowledgeTypeDto knowledgeTypeDto = new();
|
|
|
+ //查询是否有数据
|
|
|
if (!string.IsNullOrEmpty(Id))
|
|
|
{
|
|
|
var type = await _knowledgeTypeRepository.GetAsync(p => p.Id == Id, cancellationToken);
|
|
|
_mapper.Map(type, knowledgeTypeDto);
|
|
|
}
|
|
|
+ //查询已经启用的分类名称
|
|
|
var list = await _knowledgeTypeRepository.QueryAsync(p => p.IsEnable == true);
|
|
|
- if (!string.IsNullOrEmpty(ParentId) && ParentId != Guid.Empty.ToString())
|
|
|
- {
|
|
|
- knowledgeTypeDto.TreeLists = GetChildren(list, Guid.Empty.ToString(), ParentId);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- knowledgeTypeDto.TreeLists = GetChildren(list, Guid.Empty.ToString(), "");
|
|
|
- }
|
|
|
+ //分类组装树形
|
|
|
+ knowledgeTypeDto.TreeLists = GetChildren(list, Guid.Empty.ToString(), ParentId);
|
|
|
+
|
|
|
return knowledgeTypeDto;
|
|
|
}
|
|
|
|
|
@@ -170,6 +176,7 @@ namespace Hotline.KnowledgeBase
|
|
|
/// 知识分类-启用、禁用切换
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task TypeChangeState(string Id, CancellationToken cancellationToken)
|
|
|
{
|
|
@@ -210,6 +217,7 @@ namespace Hotline.KnowledgeBase
|
|
|
/// 知识分类-禁用,并且下架知识
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task TypeChangeStateAndOffShelf(string Id, CancellationToken cancellationToken)
|
|
|
{
|
|
@@ -238,6 +246,7 @@ namespace Hotline.KnowledgeBase
|
|
|
{
|
|
|
itemKnow.IsOnShelf = false;
|
|
|
itemKnow.OffShelfTime = DateTime.Now;
|
|
|
+ itemKnow.OnShelfTime = null;
|
|
|
await _knowledgeRepository.UpdateAsync(itemKnow, cancellationToken);
|
|
|
}
|
|
|
}
|
|
@@ -252,6 +261,7 @@ namespace Hotline.KnowledgeBase
|
|
|
/// 知识分类-删除
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task TypeDelete(string Id, CancellationToken cancellationToken)
|
|
|
{
|
|
@@ -261,7 +271,6 @@ namespace Hotline.KnowledgeBase
|
|
|
throw UserFriendlyException.SameMessage("分类不存在!");
|
|
|
|
|
|
//查询是否有子级分类
|
|
|
-
|
|
|
var checkChild = await _knowledgeTypeRepository.CountAsync(p => p.ParentId == Id, cancellationToken);
|
|
|
if (checkChild > 0)
|
|
|
throw UserFriendlyException.SameMessage("存在子级分类!");
|
|
@@ -273,7 +282,6 @@ namespace Hotline.KnowledgeBase
|
|
|
|
|
|
//删除操作
|
|
|
await _knowledgeTypeRepository.RemoveAsync(sandard, false, cancellationToken);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
#region 私有方法
|