|
@@ -31,7 +31,7 @@ namespace GxPress.Repository.Implement
|
|
|
private readonly string _connectionString;
|
|
|
private readonly string _databaseTypeStr;
|
|
|
private readonly Repository<GroupUser> _groupUserRepository;
|
|
|
-
|
|
|
+ private readonly Repository<Entity.Middle.Middle> middleRepository;
|
|
|
public GroupRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper,
|
|
|
IWebHostEnvironment environment)
|
|
|
{
|
|
@@ -42,6 +42,7 @@ namespace GxPress.Repository.Implement
|
|
|
var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
|
|
|
_repository = new Repository<Entity.Group>(database);
|
|
|
_groupUserRepository = new Repository<GroupUser>(database);
|
|
|
+ middleRepository = new Repository<Entity.Middle.Middle>(database);
|
|
|
_environment = environment;
|
|
|
_mapper = mapper;
|
|
|
}
|
|
@@ -148,105 +149,112 @@ namespace GxPress.Repository.Implement
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<PagedList<GroupUserFindResult>> FindGroupByGroupFolderId(GroupSearchRequest request)
|
|
|
+ public async Task<IEnumerable<GroupUserFindResult>> FindGroupByGroupFolderId(GroupSearchRequest request)
|
|
|
{
|
|
|
- var pagedList = new PagedList<GroupUserFindResult>();
|
|
|
+ //var pagedList = new PagedList<GroupUserFindResult>();
|
|
|
var groupConst = AllTypeConst.Group.GetHashCode();
|
|
|
- var sqlStr = string.Empty;
|
|
|
+ var query = new SqlKata.Query("tede_Middle");
|
|
|
+ query.LeftJoin("tede_group", "tede_group.Id", "tede_Middle.MiddleId");
|
|
|
if (request.GroupFolderId > 0)
|
|
|
- sqlStr += $" AND a.ParentId = {request.GroupFolderId}";
|
|
|
+ query.Where("tede_Middle.ParentId", request.GroupFolderId);
|
|
|
if (!string.IsNullOrEmpty(request.Key))
|
|
|
- sqlStr = $" and (a.FolderName like '%{request.Key}%' or b.Name like '%{request.Key}%')";
|
|
|
+ query.Where(n => n.OrWhereLike("tede_Middle.FolderName", $"%request.Key%").OrWhereLike("tede_group.Name", $"%{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
|
|
|
- WHERE
|
|
|
- groupId = b.Id
|
|
|
- AND LastModifiedDate > (SELECT
|
|
|
- ReadDate
|
|
|
- FROM
|
|
|
- tede_group_user
|
|
|
- WHERE
|
|
|
- groupId = b.Id AND userId = {request.UserId})) 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.IsTop DESC ,a.LastModifiedDate DESC,a.Sort 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>(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 {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;
|
|
|
+ query.Where("tede_Middle.ParentId", request.GroupFolderId);
|
|
|
+ query.Where("tede_Middle.UserId", request.UserId);
|
|
|
+ query.Where("tede_Middle.IsDelete", false);
|
|
|
+ query.Where("tede_Middle.FolderType", groupConst);
|
|
|
+ query.Where("tede_Middle.IsTop", true);
|
|
|
+ query.OrderByDesc("tede_Middle.IsTop");
|
|
|
+ query.OrderByDesc("tede_Middle.LastModifiedDate");
|
|
|
+ var topicSharingCountQuery = new SqlKata.Query("tede_group_user");
|
|
|
+ topicSharingCountQuery.WhereColumns("tede_group_user.GroupId", "=", "tede_Middle.MiddleId");
|
|
|
+ topicSharingCountQuery.AsCount();
|
|
|
+ query.Select(topicSharingCountQuery, "TopicSharingCount");
|
|
|
+ var topicAllCountQuery = new SqlKata.Query("tede_topic");
|
|
|
+ topicAllCountQuery.WhereColumns("tede_topic.GroupId", "=", "tede_Middle.MiddleId");
|
|
|
+ topicAllCountQuery.Where("tede_topic.IsDraft", false);
|
|
|
+ topicAllCountQuery.AsCount();
|
|
|
+ query.Select(topicAllCountQuery, "TopicAllCount");
|
|
|
+ var groupCountQuery = new SqlKata.Query("tede_middle as a");
|
|
|
+ groupCountQuery.WhereColumns("a.parentId", "=", "tede_Middle.Id");
|
|
|
+ groupCountQuery.AsCount();
|
|
|
+ query.Select(groupCountQuery, "GroupCount");
|
|
|
+ var uReadTopicCountQuery = new SqlKata.Query("tede_topic");
|
|
|
+ uReadTopicCountQuery.WhereColumns("tede_topic.groupId", "=", "tede_group.Id");
|
|
|
+ var groupUserQuery = new SqlKata.Query("tede_group_user");
|
|
|
+ groupUserQuery.WhereColumns("tede_group_user.groupId", "=", "tede_group.Id");
|
|
|
+ groupUserQuery.Where("tede_group_user.userId", request.UserId);
|
|
|
+ groupUserQuery.Select("ReadDate");
|
|
|
+ uReadTopicCountQuery.Where("tede_topic.LastModifiedDate", ">", groupUserQuery);
|
|
|
+ uReadTopicCountQuery.AsCount();
|
|
|
+ query.Select(uReadTopicCountQuery, "UReadTopicCount");
|
|
|
+ var categoryNameQuery = new SqlKata.Query("tede_middle as a");
|
|
|
+ categoryNameQuery.WhereColumns("a.Id", "=", "tede_Middle.ParentId");
|
|
|
+ categoryNameQuery.Select("a.FolderName");
|
|
|
+ query.Select(categoryNameQuery, "CategoryName");
|
|
|
+ var fileCountQuery = new SqlKata.Query("tede_group");
|
|
|
+ var middleQuery = new SqlKata.Query("tede_Middle as a");
|
|
|
+ middleQuery.WhereColumns("a.ParentId", "=", "tede_Middle.Id");
|
|
|
+ middleQuery.Select("a.MiddleId");
|
|
|
+ fileCountQuery.WhereIn("tede_group.Id", middleQuery);
|
|
|
+ fileCountQuery.AsCount();
|
|
|
+ query.Select(fileCountQuery, "FileCount");
|
|
|
+ query.Select("tede_Middle.{Id,IsTop,FolderName,AttributeValue}",
|
|
|
+ "tede_group.{Id as GroupId,AvatarUrl,Name as GroupName}");
|
|
|
+ var result = new List<GroupUserFindResult>();
|
|
|
+ result.AddRange(await middleRepository.GetAllAsync<GroupUserFindResult>(query));
|
|
|
+
|
|
|
+ query = new SqlKata.Query("tede_Middle");
|
|
|
+ query.LeftJoin("tede_group", "tede_group.Id", "tede_Middle.MiddleId");
|
|
|
+ if (request.GroupFolderId > 0)
|
|
|
+ query.Where("tede_Middle.ParentId", request.GroupFolderId);
|
|
|
+ if (!string.IsNullOrEmpty(request.Key))
|
|
|
+ query.Where(n => n.OrWhereLike("tede_Middle.FolderName", $"%request.Key%").OrWhereLike("tede_group.Name", $"%{request.Key}%"));
|
|
|
+ if (string.IsNullOrEmpty(request.Key) && request.GroupFolderId == 0)
|
|
|
+ query.Where("tede_Middle.ParentId", request.GroupFolderId);
|
|
|
+ query.Where("tede_Middle.UserId", request.UserId);
|
|
|
+ query.Where("tede_Middle.IsDelete", false);
|
|
|
+ query.Where("tede_Middle.FolderType", groupConst);
|
|
|
+ query.Where("tede_Middle.IsTop", false);
|
|
|
+ query.OrderByDesc("tede_group.LastModifiedDate");
|
|
|
+ topicSharingCountQuery = new SqlKata.Query("tede_group_user");
|
|
|
+ topicSharingCountQuery.WhereColumns("tede_group_user.GroupId", "=", "tede_Middle.MiddleId");
|
|
|
+ topicSharingCountQuery.AsCount();
|
|
|
+ query.Select(topicSharingCountQuery, "TopicSharingCount");
|
|
|
+ topicAllCountQuery = new SqlKata.Query("tede_topic");
|
|
|
+ topicAllCountQuery.WhereColumns("tede_topic.GroupId", "=", "tede_Middle.MiddleId");
|
|
|
+ topicAllCountQuery.Where("tede_topic.IsDraft", false);
|
|
|
+ topicAllCountQuery.AsCount();
|
|
|
+ query.Select(topicAllCountQuery, "TopicAllCount");
|
|
|
+ groupCountQuery = new SqlKata.Query("tede_middle as a");
|
|
|
+ groupCountQuery.WhereColumns("a.parentId", "=", "tede_Middle.Id");
|
|
|
+ groupCountQuery.AsCount();
|
|
|
+ query.Select(groupCountQuery, "GroupCount");
|
|
|
+ uReadTopicCountQuery = new SqlKata.Query("tede_topic");
|
|
|
+ uReadTopicCountQuery.WhereColumns("tede_topic.groupId", "=", "tede_group.Id");
|
|
|
+ groupUserQuery = new SqlKata.Query("tede_group_user");
|
|
|
+ groupUserQuery.WhereColumns("tede_group_user.groupId", "=", "tede_group.Id");
|
|
|
+ groupUserQuery.Where("tede_group_user.userId", request.UserId);
|
|
|
+ groupUserQuery.Select("ReadDate");
|
|
|
+ uReadTopicCountQuery.Where("tede_topic.LastModifiedDate", ">", groupUserQuery);
|
|
|
+ uReadTopicCountQuery.AsCount();
|
|
|
+ query.Select(uReadTopicCountQuery, "UReadTopicCount");
|
|
|
+ categoryNameQuery = new SqlKata.Query("tede_middle as a");
|
|
|
+ categoryNameQuery.WhereColumns("a.Id", "=", "tede_Middle.ParentId");
|
|
|
+ categoryNameQuery.Select("a.FolderName");
|
|
|
+ query.Select(categoryNameQuery, "CategoryName");
|
|
|
+ fileCountQuery = new SqlKata.Query("tede_group");
|
|
|
+ middleQuery = new SqlKata.Query("tede_Middle as a");
|
|
|
+ middleQuery.WhereColumns("a.ParentId", "=", "tede_Middle.Id");
|
|
|
+ middleQuery.Select("a.MiddleId");
|
|
|
+ fileCountQuery.WhereIn("tede_group.Id", middleQuery);
|
|
|
+ fileCountQuery.AsCount();
|
|
|
+ query.Select(fileCountQuery, "FileCount");
|
|
|
+ query.Select("tede_Middle.{Id,IsTop,FolderName,AttributeValue}",
|
|
|
+ "tede_group.{Id as GroupId,AvatarUrl,Name as GroupName}");
|
|
|
+ result.AddRange(await middleRepository.GetAllAsync<GroupUserFindResult>(query));
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|