feat: 添加bbs等级及用户限制功能
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
|
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser
|
||||||
|
{
|
||||||
|
public class BbsUserGetListOutputDto: UserGetListOutputDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户等级
|
||||||
|
/// </summary>
|
||||||
|
public int Level { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户限制
|
||||||
|
/// </summary>
|
||||||
|
public UserLimitEnum UserLimit { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
|
using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser;
|
||||||
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
||||||
@@ -47,7 +48,7 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
|||||||
|
|
||||||
public List<Guid>? PermissionUserIds { get; set; }
|
public List<Guid>? PermissionUserIds { get; set; }
|
||||||
|
|
||||||
public UserGetListOutputDto User { get; set; }
|
public BbsUserGetListOutputDto User { get; set; }
|
||||||
|
|
||||||
public void SetBan()
|
public void SetBan()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
|
using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser;
|
||||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
||||||
|
|
||||||
@@ -35,6 +36,6 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
|||||||
public DiscussPermissionTypeEnum PermissionType { get; set; }
|
public DiscussPermissionTypeEnum PermissionType { get; set; }
|
||||||
|
|
||||||
public List<Guid>? PermissionUserIds { get; set; }
|
public List<Guid>? PermissionUserIds { get; set; }
|
||||||
public UserGetListOutputDto User { get; set; }
|
public BbsUserGetListOutputDto User { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
using Volo.Abp.Domain.Repositories;
|
||||||
|
using Volo.Abp.EventBus;
|
||||||
|
using Yi.Framework.Bbs.Domain.Entities;
|
||||||
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
|
using Yi.Framework.Rbac.Domain.Shared.Etos;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Rbac.Application.EventHandlers
|
||||||
|
{
|
||||||
|
public class UserCreateEventHandler : ILocalEventHandler<UserCreateEventArgs>, ITransientDependency
|
||||||
|
{
|
||||||
|
private IRepository<BbsUserExtraInfoEntity> _repository;
|
||||||
|
public UserCreateEventHandler(IRepository<BbsUserExtraInfoEntity> repository)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
}
|
||||||
|
public async Task HandleEventAsync(UserCreateEventArgs eventData)
|
||||||
|
{
|
||||||
|
//创建主表
|
||||||
|
var bbsUser = new BbsUserExtraInfoEntity(eventData.UserId)
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
await _repository.InsertAsync(bbsUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ using Volo.Abp;
|
|||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
using Volo.Abp.EventBus.Local;
|
using Volo.Abp.EventBus.Local;
|
||||||
using Volo.Abp.Users;
|
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.Discuss;
|
||||||
using Yi.Framework.Bbs.Application.Contracts.IServices;
|
using Yi.Framework.Bbs.Application.Contracts.IServices;
|
||||||
using Yi.Framework.Bbs.Domain.Entities;
|
using Yi.Framework.Bbs.Domain.Entities;
|
||||||
@@ -55,10 +56,20 @@ namespace Yi.Framework.Bbs.Application.Services
|
|||||||
|
|
||||||
//查询主题发布 浏览主题 事件,浏览数+1
|
//查询主题发布 浏览主题 事件,浏览数+1
|
||||||
var item = await _forumManager._discussRepository._DbQueryable.LeftJoin<UserEntity>((discuss, user) => discuss.CreatorId == user.Id)
|
var item = await _forumManager._discussRepository._DbQueryable.LeftJoin<UserEntity>((discuss, user) => discuss.CreatorId == user.Id)
|
||||||
.Select((discuss, user) => new DiscussGetOutputDto
|
.LeftJoin<BbsUserExtraInfoEntity>((discuss, user, info) => user.Id == info.UserId)
|
||||||
|
.Select((discuss, user, info) => new DiscussGetOutputDto
|
||||||
{
|
{
|
||||||
User = new UserGetListOutputDto() { UserName = user.UserName, Nick = user.Nick, Icon = user.Icon ,Id=user.Id}
|
User = new BbsUserGetListOutputDto()
|
||||||
}, true).SingleAsync(discuss => discuss.Id == id);
|
{
|
||||||
|
UserName = user.UserName,
|
||||||
|
Nick = user.Nick,
|
||||||
|
Icon = user.Icon,
|
||||||
|
Id = user.Id,
|
||||||
|
Level = info.Level,
|
||||||
|
UserLimit = info.UserLimit
|
||||||
|
}
|
||||||
|
}, true)
|
||||||
|
.SingleAsync(discuss => discuss.Id == id);
|
||||||
|
|
||||||
if (item is not null)
|
if (item is not null)
|
||||||
{
|
{
|
||||||
@@ -87,18 +98,26 @@ namespace Yi.Framework.Bbs.Application.Services
|
|||||||
.WhereIF(input.IsTop == true, x => x.IsTop == input.IsTop)
|
.WhereIF(input.IsTop == true, x => x.IsTop == input.IsTop)
|
||||||
|
|
||||||
.LeftJoin<UserEntity>((discuss, user) => discuss.CreatorId == user.Id)
|
.LeftJoin<UserEntity>((discuss, user) => discuss.CreatorId == user.Id)
|
||||||
|
.LeftJoin<BbsUserExtraInfoEntity>((discuss, user, info) => user.Id == info.UserId)
|
||||||
|
|
||||||
.OrderByDescending(discuss => discuss.OrderNum)
|
.OrderByDescending(discuss => discuss.OrderNum)
|
||||||
.OrderByIF(input.Type == QueryDiscussTypeEnum.New, discuss => discuss.CreationTime, OrderByType.Desc)
|
.OrderByIF(input.Type == QueryDiscussTypeEnum.New, discuss => discuss.CreationTime, OrderByType.Desc)
|
||||||
.OrderByIF(input.Type == QueryDiscussTypeEnum.Host, discuss => discuss.SeeNum, OrderByType.Desc)
|
.OrderByIF(input.Type == QueryDiscussTypeEnum.Host, discuss => discuss.SeeNum, OrderByType.Desc)
|
||||||
.OrderByIF(input.Type == QueryDiscussTypeEnum.Suggest, discuss => discuss.AgreeNum, OrderByType.Desc)
|
.OrderByIF(input.Type == QueryDiscussTypeEnum.Suggest, discuss => discuss.AgreeNum, OrderByType.Desc)
|
||||||
|
|
||||||
.Select((discuss, user) => new DiscussGetListOutputDto
|
.Select((discuss, user,info) => new DiscussGetListOutputDto
|
||||||
{
|
{
|
||||||
Id = discuss.Id,
|
Id = discuss.Id,
|
||||||
IsAgree = SqlFunc.Subqueryable<AgreeEntity>().WhereIF(CurrentUser.Id != null, x => x.CreatorId == CurrentUser.Id && x.DiscussId == discuss.Id).Any(),
|
IsAgree = SqlFunc.Subqueryable<AgreeEntity>().WhereIF(CurrentUser.Id != null, x => x.CreatorId == CurrentUser.Id && x.DiscussId == discuss.Id).Any(),
|
||||||
|
|
||||||
User = new UserGetListOutputDto() { Id = user.Id, UserName = user.UserName, Nick = user.Nick, Icon = user.Icon }
|
User = new BbsUserGetListOutputDto() {
|
||||||
|
Id = user.Id,
|
||||||
|
UserName = user.UserName,
|
||||||
|
Nick = user.Nick,
|
||||||
|
Icon = user.Icon,
|
||||||
|
Level = info.Level,
|
||||||
|
UserLimit = info.UserLimit
|
||||||
|
}
|
||||||
|
|
||||||
}, true)
|
}, true)
|
||||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.Domain.Shared.Enums
|
||||||
|
{
|
||||||
|
|
||||||
|
public enum UserLimitEnum
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 正常
|
||||||
|
/// </summary>
|
||||||
|
Normal,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 危险
|
||||||
|
/// </summary>
|
||||||
|
Dangerous,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 已禁止
|
||||||
|
/// </summary>
|
||||||
|
Ban
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SqlSugar;
|
||||||
|
using Volo.Abp.Domain.Entities;
|
||||||
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.Domain.Entities
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 评论表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("BbsUserExtraInfo")]
|
||||||
|
public class BbsUserExtraInfoEntity : Entity<Guid>
|
||||||
|
{
|
||||||
|
public BbsUserExtraInfoEntity() { }
|
||||||
|
|
||||||
|
public BbsUserExtraInfoEntity(Guid userId) { this.UserId = userId; }
|
||||||
|
|
||||||
|
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
|
||||||
|
public override Guid Id { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户id
|
||||||
|
/// </summary>
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户等级
|
||||||
|
/// </summary>
|
||||||
|
public int Level { get; set; } = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户限制
|
||||||
|
/// </summary>
|
||||||
|
public UserLimitEnum UserLimit { get; set; } = UserLimitEnum.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Volo.Abp.Data;
|
||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
using Volo.Abp.Domain.Repositories;
|
||||||
|
using Yi.Framework.Bbs.Domain.Entities;
|
||||||
|
using Yi.Framework.Rbac.Domain.Entities;
|
||||||
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.SqlSugarCore.DataSeeds
|
||||||
|
{
|
||||||
|
public class BbsUserInfoDataSeed : IDataSeedContributor, ITransientDependency
|
||||||
|
{
|
||||||
|
private ISqlSugarRepository<BbsUserExtraInfoEntity> _repository;
|
||||||
|
private ISqlSugarRepository<UserEntity> _userRepository;
|
||||||
|
public BbsUserInfoDataSeed(ISqlSugarRepository<BbsUserExtraInfoEntity> repository, ISqlSugarRepository<UserEntity> userReponse)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
_userRepository = userReponse;
|
||||||
|
}
|
||||||
|
public async Task SeedAsync(DataSeedContext context)
|
||||||
|
{
|
||||||
|
//如果没有bbs的用户额外数据,自动插入
|
||||||
|
if (!await _repository.IsAnyAsync(x => true))
|
||||||
|
{
|
||||||
|
var userList = await _userRepository.GetListAsync(x => true);
|
||||||
|
var userInfoList = userList.Select(x => new BbsUserExtraInfoEntity(x.Id)).ToList();
|
||||||
|
await _repository.InsertManyAsync(userInfoList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -298,6 +298,8 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
{
|
{
|
||||||
await _userManager.GiveUserSetRoleAsync(new List<Guid> { entity.Id }, new List<Guid> { role.Id });
|
await _userManager.GiveUserSetRoleAsync(new List<Guid> { entity.Id }, new List<Guid> { role.Id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await _localEventBus.PublishAsync(new UserCreateEventArgs(entity.Id));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
|
using Volo.Abp.EventBus.Local;
|
||||||
using Volo.Abp.Uow;
|
using Volo.Abp.Uow;
|
||||||
using Volo.Abp.Users;
|
using Volo.Abp.Users;
|
||||||
using Yi.Framework.Ddd.Application;
|
using Yi.Framework.Ddd.Application;
|
||||||
@@ -12,6 +13,7 @@ using Yi.Framework.Rbac.Domain.Entities;
|
|||||||
using Yi.Framework.Rbac.Domain.Managers;
|
using Yi.Framework.Rbac.Domain.Managers;
|
||||||
using Yi.Framework.Rbac.Domain.Repositories;
|
using Yi.Framework.Rbac.Domain.Repositories;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
||||||
|
using Yi.Framework.Rbac.Domain.Shared.Etos;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.OperLog;
|
using Yi.Framework.Rbac.Domain.Shared.OperLog;
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
@@ -23,10 +25,10 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
public class UserService : YiCrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, Guid, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>
|
public class UserService : YiCrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, Guid, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>
|
||||||
//IUserService
|
//IUserService
|
||||||
{
|
{
|
||||||
public UserService(ISqlSugarRepository<UserEntity, Guid> repository, UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser, IDeptService deptService) : base(repository)
|
public UserService(ISqlSugarRepository<UserEntity, Guid> repository, UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser, IDeptService deptService, ILocalEventBus localEventBus) : base(repository)
|
||||||
=>
|
=>
|
||||||
(_userManager, _userRepository, _currentUser, _deptService, _repository) =
|
(_userManager, _userRepository, _currentUser, _deptService, _repository, _localEventBus) =
|
||||||
(userManager, userRepository, currentUser, deptService, repository);
|
(userManager, userRepository, currentUser, deptService, repository, localEventBus);
|
||||||
private UserManager _userManager { get; set; }
|
private UserManager _userManager { get; set; }
|
||||||
private ISqlSugarRepository<UserEntity, Guid> _repository;
|
private ISqlSugarRepository<UserEntity, Guid> _repository;
|
||||||
private IUserRepository _userRepository { get; set; }
|
private IUserRepository _userRepository { get; set; }
|
||||||
@@ -34,6 +36,7 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
|
|
||||||
private ICurrentUser _currentUser { get; set; }
|
private ICurrentUser _currentUser { get; set; }
|
||||||
|
|
||||||
|
private ILocalEventBus _localEventBus;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询用户
|
/// 查询用户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -102,6 +105,9 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
//uow.Commit();
|
//uow.Commit();
|
||||||
|
|
||||||
var result = await MapToGetOutputDtoAsync(returnEntity);
|
var result = await MapToGetOutputDtoAsync(returnEntity);
|
||||||
|
|
||||||
|
|
||||||
|
await _localEventBus.PublishAsync(new UserCreateEventArgs(returnEntity.Id));
|
||||||
return result;
|
return result;
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Rbac.Domain.Shared.Etos
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户创建的id
|
||||||
|
/// </summary>
|
||||||
|
public class UserCreateEventArgs
|
||||||
|
{
|
||||||
|
public UserCreateEventArgs(Guid userId)
|
||||||
|
{
|
||||||
|
UserId = userId;
|
||||||
|
}
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user