|
@@ -152,74 +152,100 @@ namespace GxPress.Repository.Implement
|
|
|
{
|
|
|
var pagedList = new PagedList<GroupUserFindResult>();
|
|
|
var groupConst = AllTypeConst.Group.GetHashCode();
|
|
|
- //根据文件夹ID查询成员
|
|
|
- var sqlValue = "";
|
|
|
- // if (!string.IsNullOrEmpty(request.Key))
|
|
|
- // sqlValue += $"and b.Name like '%{request.Key}%'";
|
|
|
- //共享数量
|
|
|
- var topicSharingCount = "(select count(1) from tede_group_user where GroupId=a.MiddleId) as TopicSharingCount";
|
|
|
- //总话题数量
|
|
|
- var topicAllCount = "(select count(1) from tede_topic where GroupId=a.MiddleId) as TopicAllCount";
|
|
|
- //未读话题数量
|
|
|
- var uReadTopicCount = $"(select count(1) from tede_topic_addressee where TopicId in (select Id from tede_topic where GroupId=a.MiddleId) and UserId={request.UserId} and IsRead=0) as UReadTopicCount";
|
|
|
- var categoryName = "(select FolderName from tede_middle where id=a.ParentId) as CategoryName";
|
|
|
- var sql =
|
|
|
- $@"SELECT a.*,{topicSharingCount},{topicAllCount},{uReadTopicCount},{categoryName},
|
|
|
- (SELECT
|
|
|
- COUNT(1)
|
|
|
- FROM
|
|
|
- tede_group
|
|
|
- WHERE
|
|
|
- id IN (SELECT
|
|
|
- MiddleId
|
|
|
- FROM
|
|
|
- tede_middle
|
|
|
- WHERE
|
|
|
- ParentId = a.Id)) AS FileCount,b.Id, b.AvatarUrl, b.Name FROM tede_Middle a LEFT JOIN tede_group b ON a.MiddleId = b.Id WHERE 1=1 ";
|
|
|
- if (request.GroupFolderId == 0 && string.IsNullOrEmpty(request.Key))
|
|
|
- sql += $"and a.ParentId = @groupFolderId ";
|
|
|
- else if (request.GroupFolderId > 0 && !string.IsNullOrEmpty(request.Key))
|
|
|
- sql += $"and a.ParentId = @groupFolderId and (a.FolderName like '%{request.Key}%' or b.Name like '%{request.Key}%')";
|
|
|
- else if (request.GroupFolderId > 0 && string.IsNullOrEmpty(request.Key))
|
|
|
- sql += $"and a.ParentId = @groupFolderId ";
|
|
|
- else
|
|
|
- sql += $" and (a.FolderName like '%{request.Key}%' or b.Name like '%{request.Key}%')";
|
|
|
- sql +=
|
|
|
- $@" and a.UserId=@userId and a.FolderType={groupConst} and a.IsDelete=0 {sqlValue} and (b.id>0 or a.AttributeValue=2) ORDER BY a.AttributeValue DESC,a.IsTop DESC, a.LastModifiedDate DESC LIMIT @page , @pageSize";
|
|
|
+ var sqlStr = string.Empty;
|
|
|
+ if (request.GroupFolderId > 0)
|
|
|
+ sqlStr += $" AND a.ParentId = {request.GroupFolderId}";
|
|
|
+ if (!string.IsNullOrEmpty(request.Key))
|
|
|
+ sqlStr = $" and (a.FolderName like '%{request.Key}%' or b.Name like '%{request.Key}%')";
|
|
|
+ if (string.IsNullOrEmpty(request.Key) && request.GroupFolderId == 0)
|
|
|
+ sqlStr += $" AND a.ParentId = {request.GroupFolderId}";
|
|
|
+ string sql = $@"SELECT
|
|
|
+ a.Id,
|
|
|
+ a.IsTop,
|
|
|
+ a.FolderName,
|
|
|
+ a.AttributeValue,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_group_user
|
|
|
+ WHERE
|
|
|
+ GroupId = a.MiddleId) AS TopicSharingCount,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_topic
|
|
|
+ WHERE
|
|
|
+ GroupId = a.MiddleId AND IsDraft = 0) AS TopicAllCount,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_middle
|
|
|
+ WHERE
|
|
|
+ parentId = a.Id) AS GroupCount,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_topic_addressee
|
|
|
+ WHERE
|
|
|
+ TopicId IN (SELECT
|
|
|
+ Id
|
|
|
+ FROM
|
|
|
+ tede_topic
|
|
|
+ WHERE
|
|
|
+ GroupId = a.MiddleId)
|
|
|
+ AND UserId = 17
|
|
|
+ AND IsRead = 0) AS UReadTopicCount,
|
|
|
+ (SELECT
|
|
|
+ FolderName
|
|
|
+ FROM
|
|
|
+ tede_middle
|
|
|
+ WHERE
|
|
|
+ id = a.ParentId) AS CategoryName,
|
|
|
+ (SELECT
|
|
|
+ COUNT(1)
|
|
|
+ FROM
|
|
|
+ tede_group
|
|
|
+ WHERE
|
|
|
+ id IN (SELECT
|
|
|
+ MiddleId
|
|
|
+ FROM
|
|
|
+ tede_middle
|
|
|
+ WHERE
|
|
|
+ ParentId = a.Id)) AS FileCount,
|
|
|
+ b.Id AS GroupId,
|
|
|
+ b.AvatarUrl,
|
|
|
+ b.Name AS GroupName
|
|
|
+ FROM
|
|
|
+ tede_Middle a
|
|
|
+ LEFT JOIN
|
|
|
+ tede_group b ON a.MiddleId = b.Id
|
|
|
+ WHERE
|
|
|
+ 1 = 1 {sqlStr}
|
|
|
+ AND a.UserId = {request.UserId}
|
|
|
+ AND a.FolderType = {groupConst}
|
|
|
+ AND a.IsDelete = 0
|
|
|
+ AND (b.id > 0 OR a.AttributeValue = 2)
|
|
|
+ ORDER BY a.AttributeValue DESC , a.IsTop DESC , a.LastModifiedDate DESC
|
|
|
+ LIMIT {(request.Page - 1) * request.PerPage} , {request.PerPage}";
|
|
|
var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
|
|
|
var database = new Database(databaseType, _connectionString);
|
|
|
var connection = database.GetConnection();
|
|
|
- var result =
|
|
|
- await connection
|
|
|
- .QueryAsync<GroupUserFindResult, Entity.Group, GroupUserFindResult>(sql,
|
|
|
- (groupUserFindResult, group) =>
|
|
|
- {
|
|
|
- groupUserFindResult.GroupName = group == null ? "" : group.Name;
|
|
|
- groupUserFindResult.AvatarUrl = group == null ? "" : StringUtils.AddDomainMin(group.AvatarUrl);
|
|
|
- groupUserFindResult.GroupId = group?.Id ?? 0;
|
|
|
- return groupUserFindResult;
|
|
|
- },
|
|
|
- new
|
|
|
- {
|
|
|
- groupFolderId = request.GroupFolderId,
|
|
|
- userId = request.UserId,
|
|
|
- page = (request.Page - 1) * request.PerPage,
|
|
|
- pageSize = request.PerPage * request.Page
|
|
|
- }, splitOn: "Id");
|
|
|
-
|
|
|
+ var result = await connection.QueryAsync<GroupUserFindResult>(sql);
|
|
|
pagedList.Items = result;
|
|
|
+ foreach (var item in pagedList.Items)
|
|
|
+ item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
|
|
|
var sqlCount =
|
|
|
- @"SELECT count(1) FROM tede_Middle a LEFT JOIN tede_group b ON a.MiddleId = b.Id WHERE 1=1 ";
|
|
|
- if (request.GroupFolderId == 0 && string.IsNullOrEmpty(request.Key))
|
|
|
- sqlCount += $"and a.ParentId = {request.GroupFolderId} ";
|
|
|
- else if (request.GroupFolderId > 0 && !string.IsNullOrEmpty(request.Key))
|
|
|
- sqlCount += $"and a.ParentId = {request.GroupFolderId} and (a.FolderName like '%{request.Key}%' or b.Name like '%{request.Key}%')";
|
|
|
- else if (request.GroupFolderId > 0 && string.IsNullOrEmpty(request.Key))
|
|
|
- sqlCount += $"and a.ParentId = {request.GroupFolderId} ";
|
|
|
- else
|
|
|
- sql += $" and (a.FolderName like '%{request.Key}%' or b.Name like '%{request.Key}%')";
|
|
|
- sqlCount +=
|
|
|
- $" and a.UserId={request.UserId} and a.FolderType={groupConst} and a.IsDelete=0 {sqlValue} and (b.id>0 or a.AttributeValue=2)";
|
|
|
+ $@"SELECT count(1)
|
|
|
+ FROM
|
|
|
+ tede_Middle a
|
|
|
+ LEFT JOIN
|
|
|
+ tede_group b ON a.MiddleId = b.Id
|
|
|
+ WHERE
|
|
|
+ 1 = 1 {sqlStr}
|
|
|
+ AND a.UserId = {request.UserId}
|
|
|
+ AND a.FolderType = {groupConst}
|
|
|
+ AND a.IsDelete = 0
|
|
|
+ AND (b.id > 0 OR a.AttributeValue = 2)";
|
|
|
pagedList.Total = await FindGroupByGroupFolderIdCountAsync(sqlCount);
|
|
|
return pagedList;
|
|
|
}
|