|
@@ -20,6 +20,7 @@ using Hotline.KnowledgeBase;
|
|
|
using Hotline.Share.Enums.Planlibrary;
|
|
|
using System.Numerics;
|
|
|
using Hotline.Share.Dtos.Planlibrary;
|
|
|
+using Hotline.Planlibrary;
|
|
|
|
|
|
namespace Hotline.Application.Caselibrary
|
|
|
{
|
|
@@ -32,7 +33,6 @@ namespace Hotline.Application.Caselibrary
|
|
|
#region 注册
|
|
|
|
|
|
private readonly IRepository<CaseList> _caseListRepository; //案例库列表
|
|
|
- private readonly IRepository<CaseRelationType> _caseRelationTypeRepository; //案例库关联类型
|
|
|
private readonly IRepository<CaseType> _caseTypeRepository; //案例库分类管理
|
|
|
private readonly IRepository<CaseTypeOrg> _caseTypeOrgRepository; //案例库分类关联机构
|
|
|
private readonly IRepository<CaseCollect> _caseCollectRepository; //案例库收藏评分
|
|
@@ -46,7 +46,6 @@ namespace Hotline.Application.Caselibrary
|
|
|
|
|
|
public CaseApplication(
|
|
|
IRepository<CaseList> caseListRepository,
|
|
|
- IRepository<CaseRelationType> caseRelationTypeRepository,
|
|
|
IRepository<CaseType> caseTypeRepository,
|
|
|
IRepository<CaseTypeOrg> caseTypeOrgRepository,
|
|
|
IRepository<CaseCollect> caseCollectRepository,
|
|
@@ -59,7 +58,6 @@ namespace Hotline.Application.Caselibrary
|
|
|
IBulletinApplication bulletinApplication)
|
|
|
{
|
|
|
_caseListRepository = caseListRepository;
|
|
|
- _caseRelationTypeRepository = caseRelationTypeRepository;
|
|
|
_caseTypeRepository = caseTypeRepository;
|
|
|
_caseTypeOrgRepository = caseTypeOrgRepository;
|
|
|
_caseCollectRepository = caseCollectRepository;
|
|
@@ -175,7 +173,7 @@ namespace Hotline.Application.Caselibrary
|
|
|
throw UserFriendlyException.SameMessage("存在子级分类!");
|
|
|
|
|
|
//查询是否有案例分类
|
|
|
- var checkKnowledge = await _caseListRepository.CountAsync(p => p.CaseTypes.Any(t => t.CaseId == Id), cancellationToken);
|
|
|
+ var checkKnowledge = await _caseListRepository.CountAsync(p => p.CaseTypes.Any(t => t.Id == Id), cancellationToken);
|
|
|
if (checkKnowledge > 0)
|
|
|
throw UserFriendlyException.SameMessage("分类存在案例!");
|
|
|
|
|
@@ -251,7 +249,7 @@ namespace Hotline.Application.Caselibrary
|
|
|
(x.Status == ECaseStatus.Revert && x.CreatorId == _sessionContext.UserId) ||
|
|
|
(x.Status == ECaseStatus.NewDrafts && x.CreatorId == _sessionContext.UserId))
|
|
|
|
|
|
- .WhereIF(!string.IsNullOrEmpty(typeSpliceName), x => x.CaseTypes.Any(t => t.CaseTypeSpliceName.StartsWith(typeSpliceName)))
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(typeSpliceName), x => x.CaseTypes.Any(t => t.SpliceName.StartsWith(typeSpliceName)))
|
|
|
|
|
|
.WhereIF(pagedDto.CreationTimeStart.HasValue, x => x.CreationTime >= pagedDto.CreationTimeStart)
|
|
|
.WhereIF(pagedDto.CreationTimeEnd.HasValue, x => x.CreationTime <= pagedDto.CreationTimeEnd)
|
|
@@ -296,26 +294,32 @@ namespace Hotline.Application.Caselibrary
|
|
|
/// <returns></returns>
|
|
|
public async Task<string> AddCaseAsync(AddCaseListDto dto, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- var pList = _mapper.Map<CaseList>(dto);
|
|
|
+ var cList = _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("当前案例标题存在重复标题!");
|
|
|
|
|
|
- pList.InitId();
|
|
|
+ cList.InitId();
|
|
|
|
|
|
if (dto.Files != null && dto.Files.Count > 0)
|
|
|
- pList.FileJson = await _fileRepository.AddFileAsync(dto.Files, pList.Id, "", cancellationToken);
|
|
|
- await _caseListRepository.AddAsync(pList, cancellationToken);
|
|
|
+ cList.FileJson = await _fileRepository.AddFileAsync(dto.Files, cList.Id, "", cancellationToken);
|
|
|
|
|
|
if (dto.CaseTypes.Any())
|
|
|
{
|
|
|
- List<CaseRelationType> types = _mapper.Map<List<CaseRelationType>>(dto.CaseTypes);
|
|
|
- types.ForEach(x => x.CaseId = pList.Id);
|
|
|
- await _caseRelationTypeRepository.AddRangeAsync(types, cancellationToken);
|
|
|
+ cList.CaseTypes = dto.CaseTypes.Select(d => new CaseType
|
|
|
+ {
|
|
|
+ Id = d.Id,
|
|
|
+ Name = d.Name,
|
|
|
+ SpliceName = d.SpliceName
|
|
|
+ }).ToList();
|
|
|
}
|
|
|
|
|
|
- return pList.Id;
|
|
|
+ await _caseListRepository.AddNav(cList)
|
|
|
+ .Include(d => d.CaseTypes)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ return cList.Id;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
@@ -359,20 +363,32 @@ namespace Hotline.Application.Caselibrary
|
|
|
Case.FileJson = new List<Share.Dtos.File.FileJson>();
|
|
|
}
|
|
|
|
|
|
- await _caseListRepository.UpdateNullAsync(Case, cancellationToken);
|
|
|
|
|
|
if (dto.ApplyStatus != ECaseApplyStatus.Delete)
|
|
|
{
|
|
|
if (dto.CaseTypes.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.CaseTypes);
|
|
|
- types.ForEach(x => x.CaseId = dto.Id);
|
|
|
- await _caseRelationTypeRepository.AddRangeAsync(types, cancellationToken);
|
|
|
+ Case.CaseTypes = dto.CaseTypes.Select(d => new CaseType
|
|
|
+ {
|
|
|
+ Id = d.Id
|
|
|
+ }).ToList();
|
|
|
+
|
|
|
+ await _caseListRepository.UpdateNav(Case)
|
|
|
+ .Include(d => d.CaseTypes, new UpdateNavOptions
|
|
|
+ {
|
|
|
+ ManyToManyIsUpdateA = true
|
|
|
+ })
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await _caseListRepository.UpdateAsync(Case, cancellationToken);
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await _caseListRepository.UpdateAsync(Case, cancellationToken);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#endregion
|