feat: 完善标签分类功能
This commit is contained in:
@@ -35,6 +35,6 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
/// <summary>
|
||||
/// 标签
|
||||
/// </summary>
|
||||
public HashSet<Guid>? DiscussLables { get; set; }
|
||||
public List<Guid>? DiscussLables { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.DiscussLable;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
||||
@@ -49,7 +50,8 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
public List<Guid>? PermissionUserIds { get; set; }
|
||||
|
||||
public BbsUserGetListOutputDto User { get; set; }
|
||||
|
||||
public List<Guid>? DiscussLables { get; set; } = new List<Guid>();
|
||||
public List<DiscussLableGetOutputDto> Lables { get; set; } = new List<DiscussLableGetOutputDto>();
|
||||
public void SetBan()
|
||||
{
|
||||
Title = DiscussConst.Privacy;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.DiscussLable;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.Plate;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
||||
@@ -9,7 +10,7 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
public class DiscussGetOutputDto : EntityDto<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD>۴<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// 是否禁止评论创建功能
|
||||
/// </summary>
|
||||
public bool IsDisableCreateComment { get; set; }
|
||||
public string Title { get; set; }
|
||||
@@ -21,17 +22,17 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
public string? Color { get; set; }
|
||||
|
||||
public Guid PlateId { get; set; }
|
||||
//<EFBFBD>Ƿ<EFBFBD><EFBFBD>ö<EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><EFBFBD>false
|
||||
//是否置顶,默认false
|
||||
public bool IsTop { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// 封面
|
||||
/// </summary>
|
||||
public string? Cover { get; set; }
|
||||
//<EFBFBD>Ƿ<EFBFBD>˽<EFBFBD>У<EFBFBD>Ĭ<EFBFBD><EFBFBD>false
|
||||
//是否私有,默认false
|
||||
public bool IsPrivate { get; set; }
|
||||
|
||||
//˽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ж<EFBFBD>codeȨ<EFBFBD><EFBFBD>
|
||||
//私有需要判断code权限
|
||||
public string? PrivateCode { get; set; }
|
||||
public DateTime CreationTime { get; set; }
|
||||
public DiscussPermissionTypeEnum PermissionType { get; set; }
|
||||
@@ -40,5 +41,8 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
public BbsUserGetListOutputDto User { get; set; }
|
||||
|
||||
public PlateGetOutputDto Plate { get; set; }
|
||||
|
||||
public List<Guid>? DiscussLables { get; set; } = new List<Guid>();
|
||||
public List<DiscussLableGetOutputDto> Lables { get; set; } =new List<DiscussLableGetOutputDto>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,20 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
public DiscussPermissionTypeEnum PermissionType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// 封面
|
||||
/// </summary>
|
||||
public string? Cover { get; set; }
|
||||
|
||||
public int OrderNum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD>۴<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// 是否禁止评论创建功能
|
||||
/// </summary>
|
||||
public bool IsDisableCreateComment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标签
|
||||
/// </summary>
|
||||
public List<Guid>? DiscussLables { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using Volo.Abp.Application.Dtos;
|
||||
|
||||
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.DiscussLable;
|
||||
|
||||
public class DiscussLableGetOutputDto:EntityDto<Guid>
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Color { get; set; }
|
||||
public string? BackgroundColor { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
@@ -9,10 +10,12 @@ using Volo.Abp.EventBus.Local;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.DiscussLable;
|
||||
using Yi.Framework.Bbs.Application.Contracts.IServices;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
||||
using Yi.Framework.Bbs.Domain.Managers;
|
||||
using Yi.Framework.Bbs.Domain.Repositories;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Etos;
|
||||
@@ -36,16 +39,17 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
private ISqlSugarRepository<DiscussTopEntity> _discussTopRepository;
|
||||
private ISqlSugarRepository<AgreeEntity> _agreeRepository;
|
||||
private BbsUserManager _bbsUserManager;
|
||||
|
||||
private IDiscussLableRepository _discussLableRepository;
|
||||
public DiscussService(BbsUserManager bbsUserManager, ForumManager forumManager,
|
||||
ISqlSugarRepository<DiscussTopEntity> discussTopRepository,
|
||||
ISqlSugarRepository<PlateAggregateRoot> plateEntityRepository, ILocalEventBus localEventBus,
|
||||
ISqlSugarRepository<AgreeEntity> agreeRepository) : base(forumManager._discussRepository)
|
||||
ISqlSugarRepository<AgreeEntity> agreeRepository, IDiscussLableRepository discussLableRepository) : base(forumManager._discussRepository)
|
||||
{
|
||||
_forumManager = forumManager;
|
||||
_plateEntityRepository = plateEntityRepository;
|
||||
_localEventBus = localEventBus;
|
||||
_agreeRepository = agreeRepository;
|
||||
_discussLableRepository = discussLableRepository;
|
||||
_discussTopRepository = discussTopRepository;
|
||||
_bbsUserManager = bbsUserManager;
|
||||
}
|
||||
@@ -57,6 +61,8 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
private ISqlSugarRepository<PlateAggregateRoot> _plateEntityRepository { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 单查
|
||||
/// </summary>
|
||||
@@ -65,7 +71,7 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
public async override Task<DiscussGetOutputDto> GetAsync(Guid id)
|
||||
{
|
||||
//查询主题发布 浏览主题 事件,浏览数+1
|
||||
var item = await _forumManager._discussRepository._DbQueryable
|
||||
var output = await _forumManager._discussRepository._DbQueryable
|
||||
.LeftJoin<UserAggregateRoot>((discuss, user) => discuss.CreatorId == user.Id)
|
||||
.LeftJoin<BbsUserExtraInfoEntity>((discuss, user, info) => user.Id == info.UserId)
|
||||
.LeftJoin<PlateAggregateRoot>((discuss, user, info, plate) => plate.Id == discuss.PlateId)
|
||||
@@ -95,24 +101,34 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
}, true)
|
||||
.FirstAsync(discuss => discuss.Id == id);
|
||||
|
||||
if (item is null)
|
||||
if (output is null)
|
||||
{
|
||||
throw new UserFriendlyException("该主题不存在", "404");
|
||||
}
|
||||
|
||||
//组装点赞
|
||||
var agreeCreatorList =
|
||||
(await _agreeRepository._DbQueryable.Where(x => x.DiscussId == item.Id).Select(x=>x.CreatorId).ToListAsync());
|
||||
(await _agreeRepository._DbQueryable.Where(x => x.DiscussId == output.Id).Select(x=>x.CreatorId).ToListAsync());
|
||||
//已登录
|
||||
if (CurrentUser.Id is not null)
|
||||
{
|
||||
item.IsAgree = agreeCreatorList.Contains(CurrentUser.Id);
|
||||
output.IsAgree = agreeCreatorList.Contains(CurrentUser.Id);
|
||||
}
|
||||
|
||||
await _forumManager.VerifyDiscussPermissionAsync(item.Id,CurrentUser.Id);
|
||||
|
||||
//组装标签
|
||||
var lableDic=await _discussLableRepository.GetDiscussLableCacheMapAsync();
|
||||
foreach (var lableId in output.DiscussLables)
|
||||
{
|
||||
if (lableDic.TryGetValue(lableId,out var item))
|
||||
{
|
||||
output.Lables.Add(item.Adapt<DiscussLableGetOutputDto>());
|
||||
}
|
||||
}
|
||||
|
||||
await _forumManager.VerifyDiscussPermissionAsync(output.Id,CurrentUser.Id);
|
||||
await _localEventBus.PublishAsync(new SeeDiscussEventArgs
|
||||
{ DiscussId = item.Id, OldSeeNum = item.SeeNum });
|
||||
return item;
|
||||
{ DiscussId = output.Id, OldSeeNum = output.SeeNum });
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +184,9 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
items.ApplyPermissionTypeFilter(CurrentUser.Id ?? Guid.Empty);
|
||||
|
||||
var levelCacheDic= await _bbsUserManager.GetLevelCacheMapAsync();
|
||||
//等级、是否点赞赋值
|
||||
var lableDic=await _discussLableRepository.GetDiscussLableCacheMapAsync();
|
||||
|
||||
//组装等级、是否点赞赋值、标签
|
||||
items?.ForEach(x =>
|
||||
{
|
||||
x.User.LevelName = levelCacheDic[x.User.Level].Name;
|
||||
@@ -180,6 +198,15 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
x.IsAgree = userIds.Contains(CurrentUser.Id);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var lableId in x.DiscussLables)
|
||||
{
|
||||
if (lableDic.TryGetValue(lableId,out var item))
|
||||
{
|
||||
x.Lables.Add(item.Adapt<DiscussLableGetOutputDto>());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
return new PagedResultDto<DiscussGetListOutputDto>(total, items);
|
||||
}
|
||||
@@ -223,7 +250,19 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
}, true)
|
||||
.ToListAsync();
|
||||
var levelCacheDic= await _bbsUserManager.GetLevelCacheMapAsync();
|
||||
output?.ForEach(x => x.User.LevelName = levelCacheDic[x.User.Level].Name);
|
||||
var lableDic=await _discussLableRepository.GetDiscussLableCacheMapAsync();
|
||||
|
||||
output?.ForEach(x =>
|
||||
{
|
||||
x.User.LevelName = levelCacheDic[x.User.Level].Name;
|
||||
foreach (var lableId in x.DiscussLables)
|
||||
{
|
||||
if (lableDic.TryGetValue(lableId,out var item))
|
||||
{
|
||||
x.Lables.Add(item.Adapt<DiscussLableGetOutputDto>());
|
||||
}
|
||||
}
|
||||
});
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -260,5 +299,11 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
var entity = await _forumManager.CreateDiscussAsync(await MapToEntityAsync(input));
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
|
||||
|
||||
public override Task<DiscussGetOutputDto> UpdateAsync(Guid id, DiscussUpdateInputVo input)
|
||||
{
|
||||
return base.UpdateAsync(id, input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Yi.Framework.Bbs.Domain.Shared.Caches;
|
||||
|
||||
public class DiscussLableCacheItem
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Color { get; set; }
|
||||
public string? BackgroundColor { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||
|
||||
public class DiscussLableConst
|
||||
{
|
||||
public const string DiscussLableCacheKey="DiscussLable:All";
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace Yi.Framework.Bbs.Domain.Entities.Forum
|
||||
public List<Guid>? PermissionUserIds { get; set; }
|
||||
|
||||
[SugarColumn(IsJson = true)]//使用json处理
|
||||
public HashSet<Guid>? DiscussLables{ get; set; }
|
||||
public List<Guid>? DiscussLables{ get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否禁止评论创建功能
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Caches;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Repositories;
|
||||
|
||||
public interface IDiscussLableRepository: ISqlSugarRepository<DiscussLableAggregateRoot,Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有分类的字典
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<Guid, DiscussLableCacheItem>> GetDiscussLableCacheMapAsync();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Mapster;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
||||
using Yi.Framework.Bbs.Domain.Repositories;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Caches;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
using Yi.Framework.SqlSugarCore.Repositories;
|
||||
|
||||
namespace Yi.Framework.Bbs.SqlSugarCore.Repositories;
|
||||
|
||||
public class DiscussLableRepository : SqlSugarRepository<DiscussLableAggregateRoot, Guid>, IDiscussLableRepository,
|
||||
ITransientDependency
|
||||
{
|
||||
private readonly IDistributedCache<List<DiscussLableCacheItem>> _lableCache;
|
||||
|
||||
public DiscussLableRepository(ISugarDbContextProvider<ISqlSugarDbContext> sugarDbContextProvider,
|
||||
IDistributedCache<List<DiscussLableCacheItem>> lableCache) : base(sugarDbContextProvider)
|
||||
{
|
||||
_lableCache = lableCache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有分类的字典
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<Dictionary<Guid, DiscussLableCacheItem>> GetDiscussLableCacheMapAsync()
|
||||
{
|
||||
var cahce = await _lableCache.GetOrAddAsync(DiscussLableConst.DiscussLableCacheKey, async () =>
|
||||
{
|
||||
var entities = await _DbQueryable.ToListAsync();
|
||||
return entities.Adapt<List<DiscussLableCacheItem>>();
|
||||
});
|
||||
return cahce.ToDictionary(x => x.Id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user