2023-12-25 21:41:37 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
using Volo.Abp.Application.Dtos;
|
|
|
|
|
|
using Volo.Abp.Application.Services;
|
|
|
|
|
|
using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser;
|
|
|
|
|
|
using Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss;
|
|
|
|
|
|
using Yi.Framework.Bbs.Domain.Entities;
|
2024-01-11 18:51:53 +08:00
|
|
|
|
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
2023-12-25 21:41:37 +08:00
|
|
|
|
using Yi.Framework.Bbs.Domain.Managers;
|
|
|
|
|
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
|
|
|
|
|
using Yi.Framework.Rbac.Domain.Entities;
|
|
|
|
|
|
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
|
|
|
|
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.Bbs.Application.Services.Analyses
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BbsForumAnalyseService : ApplicationService, IApplicationService
|
|
|
|
|
|
{
|
|
|
|
|
|
private ForumManager _forumManager;
|
2024-10-04 00:00:44 +08:00
|
|
|
|
private ISqlSugarRepository<AgreeEntity> _agreeRepository;
|
|
|
|
|
|
public BbsForumAnalyseService(ForumManager forumManager, ISqlSugarRepository<AgreeEntity> agreeRepository)
|
2023-12-25 21:41:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
_forumManager = forumManager;
|
2024-10-04 00:00:44 +08:00
|
|
|
|
_agreeRepository = agreeRepository;
|
2023-12-25 21:41:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 推荐主题,随机返回主题列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet("analyse/bbs-discuss/random")]
|
|
|
|
|
|
public async Task<List<DiscussGetListOutputDto>> GetRandomDiscussAsync([FromQuery] PagedResultRequestDto input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var output = await _forumManager._discussRepository._DbQueryable
|
|
|
|
|
|
.Where(discuss=>discuss.PermissionType== DiscussPermissionTypeEnum.Public)
|
2024-05-22 14:35:08 +08:00
|
|
|
|
.LeftJoin<UserAggregateRoot>((discuss, user) => discuss.CreatorId == user.Id)
|
2023-12-25 21:41:37 +08:00
|
|
|
|
.LeftJoin<BbsUserExtraInfoEntity>((discuss, user, info) => user.Id == info.UserId)
|
|
|
|
|
|
|
2023-12-25 21:43:09 +08:00
|
|
|
|
.OrderBy(discuss => SqlFunc.GetRandom())
|
2023-12-25 21:41:37 +08:00
|
|
|
|
.Select((discuss, user, info) => new DiscussGetListOutputDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = discuss.Id,
|
2024-10-04 00:00:44 +08:00
|
|
|
|
// IsAgree = SqlFunc.Subqueryable<AgreeEntity>().WhereIF(CurrentUser.Id != null, x => x.CreatorId == CurrentUser.Id && x.DiscussId == discuss.Id).Any(),
|
2023-12-25 21:41:37 +08:00
|
|
|
|
|
|
|
|
|
|
User = new BbsUserGetListOutputDto()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = user.Id,
|
|
|
|
|
|
UserName = user.UserName,
|
|
|
|
|
|
Nick = user.Nick,
|
|
|
|
|
|
Icon = user.Icon,
|
|
|
|
|
|
Level = info.Level,
|
|
|
|
|
|
UserLimit = info.UserLimit
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}, true)
|
|
|
|
|
|
.ToPageListAsync(input.SkipCount, input.MaxResultCount);
|
2024-10-04 00:00:44 +08:00
|
|
|
|
var discussId = output.Select(x => x.Id);
|
|
|
|
|
|
//点赞字典,key为主题id,y为用户ids
|
|
|
|
|
|
var agreeDic =
|
|
|
|
|
|
(await _agreeRepository._DbQueryable.Where(x => discussId.Contains(x.DiscussId)).ToListAsync())
|
|
|
|
|
|
.GroupBy(x => x.DiscussId)
|
|
|
|
|
|
.ToDictionary(x => x.Key, y => y.Select(y => y.CreatorId).ToList());
|
|
|
|
|
|
|
|
|
|
|
|
//等级、是否点赞赋值
|
|
|
|
|
|
output?.ForEach(x =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CurrentUser.Id is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//默认fasle
|
|
|
|
|
|
if (agreeDic.TryGetValue(x.Id,out var userIds))
|
|
|
|
|
|
{
|
|
|
|
|
|
x.IsAgree = userIds.Contains(CurrentUser.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2023-12-25 21:41:37 +08:00
|
|
|
|
return output;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|