|
@@ -20,15 +20,16 @@ using Newtonsoft.Json;
|
|
|
using GxPress.Repository.Interface.Visit;
|
|
|
using GxPress.Service.Interface.Visit;
|
|
|
using GxPress.Service.Interface.Analyze;
|
|
|
+using GxPress.Repository.Interface.DepartmentUser;
|
|
|
using GxPress.EnumConst;
|
|
|
|
|
|
namespace GxPress.Service.Implement.Topic
|
|
|
{
|
|
|
public partial class TopicService : ITopicService
|
|
|
{
|
|
|
-
|
|
|
private readonly ITopicRepository _topicRepository;
|
|
|
private readonly IUserRepository _userRepository;
|
|
|
+ private readonly IDepartmentUserRepository departmentUserRepository;
|
|
|
private readonly ITopicAddresseeRepository _topicAddresseeRepository;
|
|
|
private readonly IDepartmentRepository _departmentRepository;
|
|
|
private readonly ITopicGroupRepository _topicGroupRepository;
|
|
@@ -49,7 +50,7 @@ namespace GxPress.Service.Implement.Topic
|
|
|
ITopicGroupUserRepository topicGroupUserRepository, IAnalyzeService analyzeService,
|
|
|
ICommentRepository commentRepository, IMapper mapper, IDepartmentRepository departmentRepository,
|
|
|
IGroupUserRepository groupUserRepository, IFolderUserRepository folderUserRepository,
|
|
|
- INoteService noteService, IMiddleRepository middleRepository, IVisitRepository visitRepository, IVisitService visitService)
|
|
|
+ INoteService noteService, IMiddleRepository middleRepository, IVisitRepository visitRepository, IVisitService visitService, IDepartmentUserRepository departmentUserRepository)
|
|
|
{
|
|
|
_topicRepository = topicRepository;
|
|
|
_userRepository = userRepository;
|
|
@@ -66,6 +67,7 @@ namespace GxPress.Service.Implement.Topic
|
|
|
_middleRepository = middleRepository;
|
|
|
_visitRepository = visitRepository;
|
|
|
_visitService = visitService;
|
|
|
+ this.departmentUserRepository = departmentUserRepository;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -224,6 +226,248 @@ namespace GxPress.Service.Implement.Topic
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+ public async Task<string> GetTopicPageSqlAsync(TopicPageSearchRequest request)
|
|
|
+ {
|
|
|
+ var topicTypeValue = GxPress.EnumConst.AllTypeConst.Note.GetHashCode();
|
|
|
+ var sql = $@"SELECT
|
|
|
+ a.*,
|
|
|
+ (SELECT
|
|
|
+ FolderName
|
|
|
+ FROM
|
|
|
+ tede_middle
|
|
|
+ WHERE
|
|
|
+ id = a.FolderId) AS FolderName,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_analyze
|
|
|
+ WHERE
|
|
|
+ TypeValue = {topicTypeValue}
|
|
|
+ AND SourceId = a.Id
|
|
|
+ AND AnalyzeType = 1) AS PraiseCount,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_analyze
|
|
|
+ WHERE
|
|
|
+ UserId = {request.UserId} AND TypeValue = {topicTypeValue}
|
|
|
+ AND SourceId = a.Id
|
|
|
+ AND AnalyzeType = 1
|
|
|
+ LIMIT 0 , 1) AS IsPraise,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_comment
|
|
|
+ WHERE
|
|
|
+ ArticleId = a.Id AND TypeValue = {topicTypeValue}
|
|
|
+ AND Pid = 0) AS CommentCount,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_analyze
|
|
|
+ WHERE
|
|
|
+ UserId = {request.UserId} AND TypeValue = {topicTypeValue}
|
|
|
+ AND SourceId = a.Id
|
|
|
+ AND AnalyzeType = 4) AS RetransmissionCount,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_analyze
|
|
|
+ WHERE
|
|
|
+ UserId = {request.UserId} AND TypeValue = {topicTypeValue}
|
|
|
+ AND SourceId = a.Id
|
|
|
+ AND AnalyzeType = 4
|
|
|
+ LIMIT 0 , 1) AS IsRetransmission,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_analyze
|
|
|
+ WHERE
|
|
|
+ UserId = {request.UserId} AND TypeValue = {topicTypeValue}
|
|
|
+ AND SourceId = a.Id
|
|
|
+ AND AnalyzeType = 3
|
|
|
+ LIMIT 0 , 1) AS IsCollect,
|
|
|
+ b.Name, b.AvatarUrl
|
|
|
+ FROM
|
|
|
+ tede_note a
|
|
|
+ INNER JOIN
|
|
|
+ tede_user b ON a.UserId = b.Id
|
|
|
+ INNER JOIN
|
|
|
+ tede_middle c ON c.MiddleId = a.Id
|
|
|
+ WHERE
|
|
|
+ c.FolderType = {topicTypeValue} AND a.IsTopic = 1
|
|
|
+ AND (a.FolderId IN (SELECT
|
|
|
+ MiddleId
|
|
|
+ FROM
|
|
|
+ tede_folder_user
|
|
|
+ WHERE
|
|
|
+ MiddleId = a.FolderId AND UserId = {request.UserId})
|
|
|
+ OR a.UserId IN (SELECT
|
|
|
+ Id
|
|
|
+ FROM
|
|
|
+ tede_user
|
|
|
+ WHERE
|
|
|
+ 1 = (SELECT
|
|
|
+ RoleId
|
|
|
+ FROM
|
|
|
+ tede_middle
|
|
|
+ WHERE
|
|
|
+ id = a.FolderId) and Id=a.UserId
|
|
|
+ ))";
|
|
|
+
|
|
|
+ if (request.TopicGroupIds.Count > 0)
|
|
|
+ {
|
|
|
+ var topicGroupId = "";
|
|
|
+ foreach (var item in request.TopicGroupIds)
|
|
|
+ {
|
|
|
+ if (item <= 0)
|
|
|
+ continue;
|
|
|
+ topicGroupId += $"{item},";
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(topicGroupId))
|
|
|
+ {
|
|
|
+ topicGroupId = topicGroupId.Remove(topicGroupId.Length - 1, 1);
|
|
|
+ sql += $@" AND a.UserId IN (SELECT
|
|
|
+ UserId
|
|
|
+ FROM
|
|
|
+ tede_topic_group_user
|
|
|
+ WHERE
|
|
|
+ TopicGroupId IN ({topicGroupId}))";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (request.TopicGroupIds.Count > 0)
|
|
|
+ {
|
|
|
+ //我的
|
|
|
+ if (request.TopicGroupIds.Contains(TopicNotoGropConst.My.GetHashCode()))
|
|
|
+ {
|
|
|
+ sql += $" and a.UserId={request.UserId} ";
|
|
|
+ }
|
|
|
+ //同单位
|
|
|
+ if (request.TopicGroupIds.Contains(TopicNotoGropConst.Work.GetHashCode()))
|
|
|
+ {
|
|
|
+ if (request.UserId > 0)
|
|
|
+ {
|
|
|
+ var departmentIds = await departmentUserRepository.GetDepartmentIdsAsync(request.UserId);
|
|
|
+ var departments = new List<Entity.Department>();
|
|
|
+ foreach (var departmentId in departmentIds)
|
|
|
+ {
|
|
|
+ await _departmentRepository.GetDepartmentById(departmentId, departments);
|
|
|
+ }
|
|
|
+ if (departments.Count > 0)
|
|
|
+ {
|
|
|
+ var userIds = await departmentUserRepository.GetUserIdsByDepartmentIdsAsync(departments.Select(n => n.Id));
|
|
|
+ if (userIds.Count() > 0)
|
|
|
+ {
|
|
|
+ var str = "";
|
|
|
+ foreach (var item in userIds)
|
|
|
+ str += $"{item},";
|
|
|
+ str = str.Remove(str.Length - 1, 1);
|
|
|
+ sql += $" and a.UserId in({str})";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(request.Keyword))
|
|
|
+ {
|
|
|
+ sql += $@" AND (b.Name LIKE '%{request.Keyword}%'
|
|
|
+ OR a.Title LIKE '%{request.Keyword}%'
|
|
|
+ OR a.HtmlContent LIKE '%{request.Keyword}%')";
|
|
|
+ }
|
|
|
+ sql += $@" ORDER BY a.CreatedDate DESC
|
|
|
+ LIMIT {(request.Page - 1) * request.PerPage} , {request.PerPage}";
|
|
|
+ return sql;
|
|
|
+ }
|
|
|
+ public async Task<string> AssembleSqlCount(TopicPageSearchRequest request)
|
|
|
+ {
|
|
|
+ var sql = $@"SELECT count(1) FROM
|
|
|
+ tede_note a
|
|
|
+ INNER JOIN
|
|
|
+ tede_user b ON a.UserId = b.Id
|
|
|
+ INNER JOIN
|
|
|
+ tede_middle c ON c.MiddleId = a.Id
|
|
|
+ WHERE
|
|
|
+ c.FolderType = 4 AND a.IsTopic = 1
|
|
|
+ AND (a.FolderId IN (SELECT
|
|
|
+ MiddleId
|
|
|
+ FROM
|
|
|
+ tede_folder_user
|
|
|
+ WHERE
|
|
|
+ MiddleId = a.FolderId AND UserId = {request.UserId})
|
|
|
+ OR a.UserId IN (SELECT
|
|
|
+ Id
|
|
|
+ FROM
|
|
|
+ tede_user
|
|
|
+ WHERE
|
|
|
+ 1 = (SELECT
|
|
|
+ RoleId
|
|
|
+ FROM
|
|
|
+ tede_middle
|
|
|
+ WHERE
|
|
|
+ id = a.FolderId)
|
|
|
+ AND id = a.UserId))";
|
|
|
+
|
|
|
+ if (request.TopicGroupIds.Count > 0)
|
|
|
+ {
|
|
|
+ var topicGroupId = "";
|
|
|
+ foreach (var item in request.TopicGroupIds)
|
|
|
+ {
|
|
|
+ if (item <= 0)
|
|
|
+ continue;
|
|
|
+ topicGroupId += $"{item},";
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(topicGroupId))
|
|
|
+ {
|
|
|
+ topicGroupId = topicGroupId.Remove(topicGroupId.Length - 1, 1);
|
|
|
+ sql += $@" AND a.UserId IN (SELECT
|
|
|
+ UserId
|
|
|
+ FROM
|
|
|
+ tede_topic_group_user
|
|
|
+ WHERE
|
|
|
+ TopicGroupId IN ({topicGroupId}))";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (request.TopicGroupIds.Count > 0)
|
|
|
+ {
|
|
|
+ //我的
|
|
|
+ if (request.TopicGroupIds.Contains(TopicNotoGropConst.My.GetHashCode()))
|
|
|
+ {
|
|
|
+ sql += $" and a.UserId={request.UserId} ";
|
|
|
+ }
|
|
|
+ //同单位
|
|
|
+ if (request.TopicGroupIds.Contains(TopicNotoGropConst.Work.GetHashCode()))
|
|
|
+ {
|
|
|
+ if (request.UserId > 0)
|
|
|
+ {
|
|
|
+ var departmentIds = await departmentUserRepository.GetDepartmentIdsAsync(request.UserId);
|
|
|
+ var departments = new List<Entity.Department>();
|
|
|
+ foreach (var departmentId in departmentIds)
|
|
|
+ {
|
|
|
+ await _departmentRepository.GetDepartmentById(departmentId, departments);
|
|
|
+ }
|
|
|
+ if (departments.Count > 0)
|
|
|
+ {
|
|
|
+ var userIds = await departmentUserRepository.GetUserIdsByDepartmentIdsAsync(departments.Select(n => n.Id));
|
|
|
+ if (userIds.Count() > 0)
|
|
|
+ {
|
|
|
+ var str = "";
|
|
|
+ foreach (var item in userIds)
|
|
|
+ str += $"{item},";
|
|
|
+ str = str.Remove(str.Length - 1, 1);
|
|
|
+ sql += $" and a.UserId in({str})";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(request.Keyword))
|
|
|
+ {
|
|
|
+ sql += $@" AND (b.Name LIKE '%{request.Keyword}%'
|
|
|
+ OR a.Title LIKE '%{request.Keyword}%'
|
|
|
+ OR a.HtmlContent LIKE '%{request.Keyword}%')";
|
|
|
+ }
|
|
|
+ return sql;
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 新版 获取笔记话题列表
|
|
|
/// </summary>
|
|
@@ -231,7 +475,7 @@ namespace GxPress.Service.Implement.Topic
|
|
|
/// <returns></returns>
|
|
|
public async Task<PagedList<TopicListPageResult>> GetTopicPageAsync(TopicPageSearchRequest request)
|
|
|
{
|
|
|
- var result = await _topicRepository.GetTopicPage(request);
|
|
|
+ var result = await _topicRepository.GetTopicPage(request, await GetTopicPageSqlAsync(request), await AssembleSqlCount(request));
|
|
|
//获取数量
|
|
|
// result.Total = 10;
|
|
|
foreach (var item in result.Items)
|