|
@@ -296,6 +296,123 @@ namespace GxPress.Repository.Implement
|
|
|
connection.Dispose();
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ public async Task<PagedList<TopicListPageResult>> GetTopicByGroupAsync(TopicPageSearchRequest request)
|
|
|
+ {
|
|
|
+ var sql = $@"SELECT
|
|
|
+ a.*,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_analyze
|
|
|
+ WHERE
|
|
|
+ TypeValue = 3 AND SourceId = a.Id
|
|
|
+ AND AnalyzeType = 1) AS PraiseCount,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_analyze
|
|
|
+ WHERE
|
|
|
+ UserId = {request.UserId} AND TypeValue = 3
|
|
|
+ AND SourceId = a.Id
|
|
|
+ AND AnalyzeType = 1
|
|
|
+ LIMIT 0 , 1) AS IsPraise,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_comment
|
|
|
+ WHERE
|
|
|
+ ArticleId = a.Id AND TypeValue = 3
|
|
|
+ AND Pid = 0) AS CommentCount,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_analyze
|
|
|
+ WHERE
|
|
|
+ UserId = {request.UserId} AND TypeValue = 3
|
|
|
+ AND SourceId = a.Id
|
|
|
+ AND AnalyzeType = 4) AS RetransmissionCount,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_analyze
|
|
|
+ WHERE
|
|
|
+ UserId = {request.UserId} AND TypeValue = 3
|
|
|
+ AND SourceId = a.Id
|
|
|
+ AND AnalyzeType = 4
|
|
|
+ LIMIT 0 , 1) AS IsRetransmission,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_analyze
|
|
|
+ WHERE
|
|
|
+ UserId = {request.UserId} AND TypeValue = 3
|
|
|
+ AND SourceId = a.Id
|
|
|
+ AND AnalyzeType = 3
|
|
|
+ LIMIT 0 , 1) AS IsCollect,
|
|
|
+ b.Id as GroupId,
|
|
|
+ b.Name,
|
|
|
+ c.Name,
|
|
|
+ c.AvatarUrl
|
|
|
+ FROM
|
|
|
+ tede_topic a
|
|
|
+ INNER JOIN
|
|
|
+ tede_group b ON a.GroupId = b.id
|
|
|
+ INNER JOIN
|
|
|
+ tede_user c ON a.UserId = c.Id
|
|
|
+ WHERE
|
|
|
+ a.GroupId > 0
|
|
|
+ AND b.Id IN (SELECT
|
|
|
+ GroupId
|
|
|
+ FROM
|
|
|
+ tede_group_user
|
|
|
+ WHERE
|
|
|
+ UserId = {request.UserId})";
|
|
|
+ if (!string.IsNullOrWhiteSpace(request.Keyword))
|
|
|
+ {
|
|
|
+ sql += $@" AND (c.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}";
|
|
|
+
|
|
|
+ var result = new PagedList<TopicListPageResult>();
|
|
|
+ var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
|
|
|
+ var database = new Database(databaseType, _connectionString);
|
|
|
+ var connection = database.GetConnection();
|
|
|
+ result.Items = await connection.QueryAsync<TopicListPageResult, Entity.Group, User, TopicListPageResult>(sql, (topicListPageResult, group, user) =>
|
|
|
+ {
|
|
|
+ topicListPageResult.AvatarUrl = user != null ? StringUtils.AddDomainMin(user.AvatarUrl) : "";
|
|
|
+ topicListPageResult.GroupName = group != null ? group.Name : "";
|
|
|
+ topicListPageResult.UserName = user != null ? user.Name : "";
|
|
|
+ return topicListPageResult;
|
|
|
+ }, splitOn: "Id,GroupId,Name");
|
|
|
+ sql = $@"SELECT
|
|
|
+ count(1)
|
|
|
+ FROM
|
|
|
+ tede_topic a
|
|
|
+ INNER JOIN
|
|
|
+ tede_group b ON a.GroupId = b.id
|
|
|
+ INNER JOIN
|
|
|
+ tede_user c ON a.UserId = c.Id
|
|
|
+ WHERE
|
|
|
+ a.GroupId > 0
|
|
|
+ AND b.Id IN (SELECT
|
|
|
+ GroupId
|
|
|
+ FROM
|
|
|
+ tede_group_user
|
|
|
+ WHERE
|
|
|
+ UserId = {request.UserId})";
|
|
|
+ if (!string.IsNullOrWhiteSpace(request.Keyword))
|
|
|
+ {
|
|
|
+ sql += $@" AND (c.Name LIKE '%{request.Keyword}%'
|
|
|
+ OR a.Title LIKE '%{request.Keyword}%'
|
|
|
+ OR a.HtmlContent LIKE '%{request.Keyword}%')";
|
|
|
+ }
|
|
|
+ result.Total = await connection.ExecuteScalarAsync<int>(sql);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
public string AssembleSql(TopicPageSearchRequest request)
|
|
|
{
|
|
|
var sql = $@"SELECT
|