|
@@ -0,0 +1,568 @@
|
|
|
+using Hotline.Settings.Hotspots;
|
|
|
+using Hotline.Share.Dtos.Knowledge;
|
|
|
+using Hotline.Share.Dtos.Caselibrary;
|
|
|
+using Hotline.Share.Enums.Caselibrary;
|
|
|
+using MapsterMapper;
|
|
|
+using XF.Domain.Authentications;
|
|
|
+using XF.Domain.Dependency;
|
|
|
+using XF.Domain.Exceptions;
|
|
|
+using XF.Domain.Repository;
|
|
|
+using Hotline.Repository.SqlSugar.Extensions;
|
|
|
+using Hotline.SeedData;
|
|
|
+using Hotline.File;
|
|
|
+using Hotline.Application.Bulletin;
|
|
|
+using Hotline.Share.Tools;
|
|
|
+using Hotline.Application.Tools;
|
|
|
+using SqlSugar;
|
|
|
+using Hotline.CaseLibrary;
|
|
|
+
|
|
|
+namespace Hotline.Application.Caselibrary
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// 案例库处理
|
|
|
+ /// </summary>
|
|
|
+ public class CaseApplication : ICaseApplication, IScopeDependency
|
|
|
+ {
|
|
|
+
|
|
|
+ #region 注册
|
|
|
+
|
|
|
+ private readonly IRepository<CaseList> _CaseListRepository; //案例库列表
|
|
|
+ private readonly IRepository<CaseRelationType> _CaseRelationTypeRepository; //案例库关联类型
|
|
|
+ private readonly IRepository<CaseType> _CaseTypeRepository; //案例库分类管理
|
|
|
+ private readonly IRepository<CaseTypeOrg> _CaseTypeOrgRepository; //案例库分类关联机构
|
|
|
+ private readonly ISessionContext _sessionContext;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly IRepository<Hotspot> _hotspotTypeRepository;
|
|
|
+ private readonly IFileRepository _fileRepository;
|
|
|
+ private readonly IBulletinApplication _bulletinApplication;
|
|
|
+
|
|
|
+ public CaseApplication(
|
|
|
+ IRepository<CaseList> CaseListRepository,
|
|
|
+ IRepository<CaseRelationType> CaseRelationTypeRepository,
|
|
|
+ IRepository<CaseType> CaseTypeRepository,
|
|
|
+ IRepository<CaseTypeOrg> CaseTypeOrgRepository,
|
|
|
+ ISessionContext sessionContext,
|
|
|
+ IMapper mapper,
|
|
|
+ IRepository<Hotspot> hotspotTypeRepository,
|
|
|
+ IFileRepository fileRepository,
|
|
|
+ IBulletinApplication bulletinApplication)
|
|
|
+ {
|
|
|
+ _CaseListRepository = CaseListRepository;
|
|
|
+ _CaseRelationTypeRepository = CaseRelationTypeRepository;
|
|
|
+ _CaseTypeRepository = CaseTypeRepository;
|
|
|
+ _CaseTypeOrgRepository = CaseTypeOrgRepository;
|
|
|
+ _sessionContext = sessionContext;
|
|
|
+ _mapper = mapper;
|
|
|
+ _hotspotTypeRepository = hotspotTypeRepository;
|
|
|
+ _fileRepository = fileRepository;
|
|
|
+ _bulletinApplication = bulletinApplication;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 案例库类型管理
|
|
|
+
|
|
|
+ #region 案例库类型 - 新增
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 案例库类型 - 新增
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<string> AddTypeAsync(AddCaseTypeDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var sandard = await _CaseTypeRepository.GetAsync(p => p.ParentId == dto.ParentId && p.Name == dto.Name && p.IsDeleted == false, cancellationToken);
|
|
|
+ if (sandard is not null)
|
|
|
+ throw UserFriendlyException.SameMessage("当前层级已存在相同名称的分类!");
|
|
|
+
|
|
|
+ var type = _mapper.Map<CaseType>(dto);
|
|
|
+ type.InitId();
|
|
|
+ type.IsEnable = true;
|
|
|
+ //获取分类名称全称
|
|
|
+ string FullName = await GetFullName(type.ParentId);
|
|
|
+ //处理全称,如果为第一级直接用全称,否则获取全称后拼接名称
|
|
|
+ type.SpliceName = string.IsNullOrEmpty(FullName) ? dto.Name : FullName + "-" + dto.Name;
|
|
|
+ var id = await _CaseTypeRepository.AddAsync(type, cancellationToken);
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 案例库类型 - 编辑
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 案例库类型 - 编辑
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task UpdateTypeAsync(UpdateCaseTypeDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ //查询原有数据
|
|
|
+ var type = await _CaseTypeRepository.GetAsync(dto.Id, cancellationToken);
|
|
|
+ if (type is null)
|
|
|
+ throw UserFriendlyException.SameMessage("编辑失败!");
|
|
|
+ bool result = type.Name != dto.Name || type.ParentId != dto.ParentId;
|
|
|
+ //是否更改分类名称或者层级
|
|
|
+
|
|
|
+ //转换
|
|
|
+ _mapper.Map(dto, type);
|
|
|
+ //如果更改了名称或者修改了层级,则修改全称,未更改不修改
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ string FullName = await GetFullName(type.ParentId);//获取分类名称全称
|
|
|
+ type.SpliceName = string.IsNullOrEmpty(FullName) ? dto.Name : FullName + "-" + dto.Name;//处理全称,如果为第一级直接用全称,否则获取全称后拼接名称
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改数据
|
|
|
+ await _CaseTypeRepository.UpdateAsync(type, cancellationToken);
|
|
|
+
|
|
|
+ //如果修改了名称,对应修改子分类全称
|
|
|
+ if (result)
|
|
|
+ await UpdateChildNode(type.Id);
|
|
|
+
|
|
|
+ // 修改关联机构
|
|
|
+ await _CaseTypeOrgRepository.RemoveAsync(x => x.TypeId == type.Id, false, cancellationToken);
|
|
|
+ if (dto.TypeOrgDtos != null && dto.TypeOrgDtos.Any())
|
|
|
+ {
|
|
|
+ List<CaseTypeOrg> orgs = _mapper.Map<List<CaseTypeOrg>>(dto.TypeOrgDtos);
|
|
|
+ orgs.ForEach(x => x.TypeId = type.Id);
|
|
|
+ await _CaseTypeOrgRepository.AddRangeAsync(orgs, cancellationToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 案例库类型 - 删除
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 案例库类型 - 删除
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="Id"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task RemoveTypeAsync(string Id, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ //查询数据是否存在
|
|
|
+ var sandard = await _CaseTypeRepository.GetAsync(p => p.Id == Id && p.IsDeleted == false, cancellationToken);
|
|
|
+ if (sandard is null)
|
|
|
+ throw UserFriendlyException.SameMessage("分类不存在!");
|
|
|
+
|
|
|
+ //查询是否有子级分类
|
|
|
+ var checkChild = await _CaseTypeRepository.CountAsync(p => p.ParentId == Id && p.IsDeleted == false, cancellationToken);
|
|
|
+ if (checkChild > 0)
|
|
|
+ throw UserFriendlyException.SameMessage("存在子级分类!");
|
|
|
+
|
|
|
+ //查询是否有案例分类
|
|
|
+ var checkKnowledge = await _CaseListRepository.CountAsync(p => p.CaseTypes.Any(t => t.CaseId == Id), cancellationToken);
|
|
|
+ if (checkKnowledge > 0)
|
|
|
+ throw UserFriendlyException.SameMessage("分类存在案例!");
|
|
|
+
|
|
|
+ //删除操作
|
|
|
+ await _CaseTypeRepository.RemoveAsync(sandard, true, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 案例库管理
|
|
|
+
|
|
|
+ #region 案例库 - 列表
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 案例库 - 列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="pagedDto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<(int, IList<CaseDataDto>)> QueryAllCaseListAsync(CaseListDto pagedDto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ //if (!_sessionContext.OrgIsCenter)
|
|
|
+ //{// 部门只能查询【部门案例库】
|
|
|
+ // pagedDto.Attribution = "部门案例库";
|
|
|
+ //}
|
|
|
+
|
|
|
+ var typeSpliceName = string.Empty;
|
|
|
+ var hotspotHotSpotFullName = string.Empty;
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(pagedDto.CaseTypeID))
|
|
|
+ {
|
|
|
+ var type = await _CaseTypeRepository.GetAsync(x => x.Id == pagedDto.CaseTypeID);
|
|
|
+ typeSpliceName = type?.SpliceName;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(pagedDto.HotspotId))
|
|
|
+ {
|
|
|
+ var hotspot = await _hotspotTypeRepository.GetAsync(x => x.Id == pagedDto.HotspotId);
|
|
|
+ hotspotHotSpotFullName = hotspot?.HotSpotFullName;
|
|
|
+ }
|
|
|
+
|
|
|
+ //单表分页
|
|
|
+ var (total, temp) = await _CaseListRepository.Queryable()
|
|
|
+ .Includes(x => x.CaseTypes)
|
|
|
+ .Includes(x => x.HotspotType)
|
|
|
+ .Where(x => x.IsDeleted == false)
|
|
|
+ .Where(x => (x.Status == ECaseStatus.Drafts && x.CreatorId == _sessionContext.UserId) || (x.Status != ECaseStatus.Drafts))
|
|
|
+ .WhereIF(OrgSeedData.CenterId != pagedDto.CreateOrgId && !string.IsNullOrEmpty(pagedDto.CreateOrgId), x => x.CreatorOrgId != null && x.CreatorOrgId.StartsWith(pagedDto.CreateOrgId!))
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(pagedDto.Attribution), x => x.Attribution == pagedDto.Attribution)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(pagedDto.Title), x => x.Title.Contains(pagedDto.Title))
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(pagedDto.Keyword), x => x.Title.Contains(pagedDto.Keyword!) ||
|
|
|
+ x.CreatorName!.Contains(pagedDto.Keyword!) ||
|
|
|
+ x.CreatorOrgName!.Contains(pagedDto.Keyword!))
|
|
|
+ .WhereIF(pagedDto.Status.HasValue && pagedDto.Status != ECaseStatus.OffShelf &&
|
|
|
+ pagedDto.Status != ECaseStatus.NewDrafts &&
|
|
|
+ pagedDto.Status != ECaseStatus.All,
|
|
|
+ x => x.Status == pagedDto.Status && ((x.ExpiredTime != null && x.ExpiredTime > DateTime.Now) || x.ExpiredTime == null))
|
|
|
+ .WhereIF(pagedDto.Status.HasValue && pagedDto.Status == ECaseStatus.OffShelf, x => x.Status == pagedDto.Status || (x.ExpiredTime != null && x.ExpiredTime < DateTime.Now && x.Status != ECaseStatus.Drafts))
|
|
|
+ .WhereIF(pagedDto.Status.HasValue && pagedDto.Status == ECaseStatus.NewDrafts, x => x.Status == ECaseStatus.Drafts || x.Status == ECaseStatus.Revert)
|
|
|
+ .WhereIF(pagedDto.IsPublic.HasValue, x => x.IsPublic == pagedDto.IsPublic)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(typeSpliceName), x => x.CaseTypes.Any(t => t.CaseTypeSpliceName.StartsWith(typeSpliceName)))
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(hotspotHotSpotFullName), x => x.HotspotType.HotSpotFullName.EndsWith(hotspotHotSpotFullName!))
|
|
|
+
|
|
|
+ .WhereIF(pagedDto.CreationTimeStart.HasValue, x => x.CreationTime >= pagedDto.CreationTimeStart)
|
|
|
+ .WhereIF(pagedDto.CreationTimeEnd.HasValue, x => x.CreationTime <= pagedDto.CreationTimeEnd)
|
|
|
+
|
|
|
+ .WhereIF(pagedDto.OnShelfTimeStart.HasValue, x => x.OnShelfTime >= pagedDto.OnShelfTimeStart)
|
|
|
+ .WhereIF(pagedDto.OnShelfTimeEnd.HasValue, x => x.OnShelfTime <= pagedDto.OnShelfTimeEnd)
|
|
|
+
|
|
|
+ .WhereIF(pagedDto.OffShelfTimeStart.HasValue, x => x.OffShelfTime >= pagedDto.OffShelfTimeStart)
|
|
|
+ .WhereIF(pagedDto.OffShelfTimeEnd.HasValue, x => x.OffShelfTime <= pagedDto.OffShelfTimeEnd)
|
|
|
+
|
|
|
+ .WhereIF(pagedDto.UpdateTimeStart.HasValue, x => x.UpdateTime >= pagedDto.UpdateTimeStart)
|
|
|
+ .WhereIF(pagedDto.UpdateTimeEnd.HasValue, x => x.UpdateTime <= pagedDto.UpdateTimeEnd)
|
|
|
+
|
|
|
+ .WhereIF(pagedDto.ExaminTimeStart.HasValue, x => x.ExaminTime >= pagedDto.ExaminTimeStart)
|
|
|
+ .WhereIF(pagedDto.ExaminTimeEnd.HasValue, x => x.ExaminTime <= pagedDto.ExaminTimeEnd)
|
|
|
+
|
|
|
+ .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<CaseDataDto>>(temp));
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 案例库 - 新增
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<string> AddCaseAsync(AddCaseListDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var pList = _mapper.Map<CaseList>(dto);
|
|
|
+
|
|
|
+ var any = await _CaseListRepository.Queryable().Where(x => x.Status == ECaseStatus.OnShelf && x.Title == dto.Title).AnyAsync();
|
|
|
+ if (any)
|
|
|
+ throw UserFriendlyException.SameMessage("当前案例标题存在重复标题!");
|
|
|
+
|
|
|
+ if (dto.Files != null && dto.Files.Count > 0)
|
|
|
+ pList.FileJson = await _fileRepository.AddFileAsync(dto.Files, pList.Id, "", cancellationToken);
|
|
|
+ await _CaseListRepository.AddAsync(pList, cancellationToken);
|
|
|
+
|
|
|
+ if (dto.CaseType.Any())
|
|
|
+ {
|
|
|
+ List<CaseRelationType> types = _mapper.Map<List<CaseRelationType>>(dto.CaseType);
|
|
|
+ types.ForEach(x => x.CaseId = pList.Id);
|
|
|
+ await _CaseRelationTypeRepository.AddRangeAsync(types, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ return pList.Id;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 案例库 - 修改
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 修改
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task UpdateCaseAsync(UpdateCaseListDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var Case = await _CaseListRepository.GetAsync(dto.Id);
|
|
|
+
|
|
|
+ if (Case == null)
|
|
|
+ throw UserFriendlyException.SameMessage("案例库查询失败");
|
|
|
+
|
|
|
+ if ((Case.Status == ECaseStatus.OnShelf || Case.Status == ECaseStatus.Auditing) && (Case.ExpiredTime.HasValue && Case.ExpiredTime.Value > DateTime.Now))
|
|
|
+ throw UserFriendlyException.SameMessage("案例库数据不可修改");
|
|
|
+
|
|
|
+ var any = await _CaseListRepository.Queryable().Where(x => x.Status == ECaseStatus.OnShelf && x.Title == dto.Title && x.Id != dto.Id).AnyAsync();
|
|
|
+ if (any)
|
|
|
+ throw UserFriendlyException.SameMessage("当前案例标题存在重复标题!");
|
|
|
+
|
|
|
+ _mapper.Map(dto, Case);
|
|
|
+
|
|
|
+ Case.HotspotId = dto.HotspotId;
|
|
|
+
|
|
|
+ if (dto.Files != null && dto.Files.Count > 0)
|
|
|
+ Case.FileJson = await _fileRepository.AddFileAsync(dto.Files, Case.Id, "", cancellationToken);
|
|
|
+ else
|
|
|
+ Case.FileJson = new List<Share.Dtos.File.FileJson>();
|
|
|
+
|
|
|
+ await _CaseListRepository.UpdateNullAsync(Case, cancellationToken);
|
|
|
+ if (dto.CaseType.Any())
|
|
|
+ {
|
|
|
+ var anyRelationTypes = await _CaseRelationTypeRepository.Queryable().Where(x => x.CaseId == Case.Id).ToListAsync();
|
|
|
+ if (anyRelationTypes.Any())
|
|
|
+ await _CaseRelationTypeRepository.RemoveRangeAsync(anyRelationTypes);
|
|
|
+ List<CaseRelationType> types = _mapper.Map<List<CaseRelationType>>(dto.CaseType);
|
|
|
+ types.ForEach(x => x.CaseId = dto.Id);
|
|
|
+ await _CaseRelationTypeRepository.AddRangeAsync(types, cancellationToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 案例库 - 下架审核
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 下架审核
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task AuditCaseAsync(UpdateCaseListDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var Case = await _CaseListRepository.GetAsync(dto.Id);
|
|
|
+
|
|
|
+ if (Case == null)
|
|
|
+ throw UserFriendlyException.SameMessage("案例库查询失败");
|
|
|
+
|
|
|
+ Case.Status = (ECaseStatus)dto.Status!;
|
|
|
+ Case.ApplyStatus = (ECaseApplyStatus)dto.ApplyStatus!;
|
|
|
+ Case.ExaminTime = dto.ExaminTime;
|
|
|
+ Case.ExaminManId = dto.ExaminManId;
|
|
|
+ Case.ExaminOrganizeId = dto.ExaminOrganizeId;
|
|
|
+ Case.UpdateTime = dto.UpdateTime;
|
|
|
+
|
|
|
+ await _CaseListRepository.UpdateNullAsync(Case, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 案例库 - 详情
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 详情
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="Id"></param>
|
|
|
+ /// <param name="IsAddPv">默认不增加,false不增加,true增加浏览量</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<CaseInfoDto> GetCaseAsync(string Id, bool? IsAddPv, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var Case = await _CaseListRepository.GetAsync(Id);
|
|
|
+ if (Case == null)
|
|
|
+ throw UserFriendlyException.SameMessage("案例库查询失败");
|
|
|
+ ;
|
|
|
+ //转化
|
|
|
+ var CaseInfoDto = _mapper.Map<CaseInfoDto>(Case);
|
|
|
+
|
|
|
+ if (Case != null && !string.IsNullOrEmpty(Case.Content))
|
|
|
+ CaseInfoDto.Content = _bulletinApplication.GetSiteUrls(Case.Content);
|
|
|
+
|
|
|
+ // 热点
|
|
|
+ //var hot = await _hotspotTypeRepository.GetAsync(Case.HotspotId, cancellationToken);
|
|
|
+ //if (hot != null)
|
|
|
+ // CaseDto.HotspotId = hot.HotSpotFullName;
|
|
|
+
|
|
|
+ if (CaseInfoDto.FileJson != null && CaseInfoDto.FileJson.Any())
|
|
|
+ {
|
|
|
+ var ids = CaseInfoDto.FileJson.Select(x => x.Id).ToList();
|
|
|
+ CaseInfoDto.Files = await _fileRepository.GetFilesAsync(ids, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新浏览量
|
|
|
+ if (IsAddPv == true)
|
|
|
+ {
|
|
|
+ //修改浏览量
|
|
|
+ Case.PageView++;
|
|
|
+ //修改点击量
|
|
|
+ await _CaseListRepository.UpdateAsync(Case, cancellationToken);
|
|
|
+ }
|
|
|
+ return CaseInfoDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 案例库 - 批量导出
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 案例库 - 批量导出
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<Dictionary<string, Stream>> CaseInfoListExportAsync(CaseInfoExportDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var streamList = new Dictionary<string, Stream>();
|
|
|
+ var knowList = await _CaseListRepository.Queryable()
|
|
|
+ .Where(m => dto.Ids.Contains(m.Id))
|
|
|
+ .Select(m => new { m.Title, m.Content })
|
|
|
+ .ToListAsync(cancellationToken);
|
|
|
+
|
|
|
+ var tasks = knowList.Select(async item =>
|
|
|
+ {
|
|
|
+ var stream = await Task.Run(() => item.Content.HtmlToStream(dto.FileType), cancellationToken);
|
|
|
+ return new KeyValuePair<string, Stream>(
|
|
|
+ item.Title + dto.FileType.GetFileExtension(),
|
|
|
+ stream
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ var results = await Task.WhenAll(tasks);
|
|
|
+
|
|
|
+ foreach (var kvp in results)
|
|
|
+ {
|
|
|
+ if (!streamList.ContainsKey(kvp.Key))
|
|
|
+ {
|
|
|
+ streamList.Add(kvp.Key, kvp.Value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return streamList;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 私有方法
|
|
|
+
|
|
|
+ #region 查询所有子级
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询所有子级
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="treeDatas">分类数据</param>
|
|
|
+ /// <param name="ID">需要查询哪级下面的分类</param>
|
|
|
+ /// <param name="checkId">选中的数据ID</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private List<TreeListDto> GetChildren(List<CaseType> 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,
|
|
|
+ ParentID = dr.ParentId,
|
|
|
+ value = dr.Id,
|
|
|
+ IsEnable = dr.IsEnable
|
|
|
+ };
|
|
|
+ //是否选中
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 获取全称
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取全称
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="Id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task<string> GetFullName(string? Id)
|
|
|
+ {
|
|
|
+ //获取全部父级名称
|
|
|
+ var list = await GetParentNode(Id);
|
|
|
+ //倒叙
|
|
|
+ list.Reverse();
|
|
|
+ //拆分
|
|
|
+ return string.Join("-", list.ToArray());
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询父级名称
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="Id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task<List<string>> GetParentNode(string? Id)
|
|
|
+ {
|
|
|
+ List<string> list = new();
|
|
|
+ //查询父级数据
|
|
|
+ var type = await _CaseTypeRepository.GetAsync(p => p.Id == Id);
|
|
|
+ if (type != null)
|
|
|
+ {
|
|
|
+ //添加名称
|
|
|
+ list.Add(type.Name);
|
|
|
+ list.AddRange(await GetParentNode(type.ParentId));
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 修改子级分类全称
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 修改子级分类全称
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="Id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task UpdateChildNode(string Id)
|
|
|
+ {
|
|
|
+ //查询子分类
|
|
|
+ var list = await GetChildNode(Id);
|
|
|
+ if (list is not null && list.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ //获取全称
|
|
|
+ string FullName = await GetFullName(item.ParentId);
|
|
|
+ item.SpliceName = string.IsNullOrEmpty(FullName) ? item.Name : FullName + "-" + item.Name;
|
|
|
+ //修改全称
|
|
|
+ await _CaseTypeRepository.UpdateAsync(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询子级节点数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="Id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task<List<CaseType>> GetChildNode(string Id)
|
|
|
+ {
|
|
|
+ List<CaseType> list = new();
|
|
|
+ //查询数据
|
|
|
+ var typelist = await _CaseTypeRepository.QueryAsync(p => p.ParentId == Id);
|
|
|
+ if (typelist != null)
|
|
|
+ {
|
|
|
+ //处理数据
|
|
|
+ foreach (var item in typelist)
|
|
|
+ {
|
|
|
+ list.Add(item);
|
|
|
+ list.AddRange(await GetChildNode(item.Id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ }
|
|
|
+}
|