using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using AutoMapper; using GxPress.Common.AppOptions; using GxPress.Common.Tools; using GxPress.Entity; using GxPress.Repository.Interface; using GxPress.Request.BlacklistUser; using Microsoft.Extensions.Options; using Datory; namespace GxPress.Repository.Implement { public class BlacklistUserRepository : IBlacklistUserRepository { private readonly Repository _repository; private readonly Repository _userRepository; private readonly IMapper _mapper; public BlacklistUserRepository(IOptionsMonitor dbOptionsAccessor, IMapper mapper) { var databaseType = StringUtils.ToEnum(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql); var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString); _repository = new Repository(database); _userRepository = new Repository(database); _mapper = mapper; } public IDatabase Database => _repository.Database; public string TableName => _repository.TableName; public List TableColumns => _repository.TableColumns; /// /// 获取黑名单 /// /// /// public async Task> GetBlacklistUserAsync(BlacklistUserSearchRequest request) { var result= await _repository.GetAllAsync(Q.Where(nameof(BlacklistUser.UserId), request.UserId)); foreach (var item in result) item.AvatarUrl=StringUtils.AddDomainMin(item.AvatarUrl); return result; } /// /// 根据ID获取 /// /// /// public async Task GetAsync(int id) { return await _repository.GetAsync(id); } /// /// 根据用户ID查询黑名单 /// /// /// /// public async Task GetBlackUserAsync(int userId, int blackUserId) { return await _repository.GetAsync(Q.Where(nameof(BlacklistUser.UserId), userId).Where(nameof(BlacklistUser.BlackUserId), blackUserId)); } /// /// 添加 /// /// /// /// public async Task InsertAsync(int userId, BlacklistUserInRequest request) { var user = await _userRepository.GetAsync(request.UserId); var blacklistUser = new BlacklistUser { UserId = userId, AvatarUrl = user.AvatarUrl, BlackUserName = user.Name, ImId = user.ImId, BlackUserId = request.UserId }; //修改聊天界面黑名单 return await _repository.InsertAsync(blacklistUser) > 0; } public async Task InsertAsync(BlacklistUser request) { return await _repository.InsertAsync(request) > 0; } /// /// 删除 /// /// /// public async Task DeleteAsync(int id) { return await _repository.DeleteAsync(id); } /// /// 查询该用户是否是黑名单 /// /// /// /// public async Task FindUserIsBlack(int userId, int blackUserId) { var count = await _repository.CountAsync(Q.Where(nameof(BlacklistUser.UserId), userId) .Where(nameof(BlacklistUser.BlackUserId), blackUserId)); return count > 0; } } }