|
@@ -284,38 +284,45 @@ namespace GxPress.Repository.Implement.Collection
|
|
|
/// <returns></returns>
|
|
|
public async Task<PagedList<CollectionNoFolderResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
|
|
|
{
|
|
|
+ return await GetNewCollectionNoFolderPageListAsync(request);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 收藏无文件夹分页列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<PagedList<CollectionNoFolderResult>> GetNewCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
|
|
|
+ {
|
|
|
+ var folderNameQuery = new SqlKata.Query("tede_middle");
|
|
|
+ folderNameQuery.WhereColumns("Id","=","a.ParentId");
|
|
|
+ folderNameQuery.Select("FolderName");
|
|
|
var result = new PagedList<CollectionNoFolderResult>();
|
|
|
var collectionContsValue = GxPress.EnumConst.AllTypeConst.Collect.GetHashCode();
|
|
|
- var sqlStr = string.Empty;
|
|
|
+ var query = new SqlKata.Query("tede_collection");
|
|
|
+ query.Join("tede_middle as a", "a.MiddleId", "tede_collection.Id");
|
|
|
if (!string.IsNullOrEmpty(request.SearchKey))
|
|
|
- sqlStr += $" and a.Title like '%{request.SearchKey}%' ";
|
|
|
- var sql = $@"SELECT
|
|
|
- a.Id,a.UserId,a.Title,a.CollectionType,a.CollectionDataId,a.SourceUserId,a.IsTop,(select FolderName from tede_middle where id=b.ParentId) as FolderName,b.Id,b.MiddleId, b.ParentId
|
|
|
- FROM
|
|
|
- tede_collection a
|
|
|
- INNER JOIN
|
|
|
- tede_middle b ON a.Id = b.MiddleId AND b.FolderType ={collectionContsValue} {sqlStr}
|
|
|
- AND a.UserId ={request.UserId} and b.IsDelete=0 order by 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();
|
|
|
- result.Items = await connection.QueryAsync<CollectionNoFolderResult, Entity.Middle.Middle, CollectionNoFolderResult>(sql,
|
|
|
- (result, middle) =>
|
|
|
- {
|
|
|
- result.MiddleId = middle.MiddleId;
|
|
|
- result.Id = middle.Id;
|
|
|
- result.FolderId = middle != null ? middle.ParentId : 0;
|
|
|
- return result;
|
|
|
- },
|
|
|
- splitOn: "Id");
|
|
|
- sql = $@"SELECT
|
|
|
- count(1)
|
|
|
- FROM
|
|
|
- tede_collection a
|
|
|
- INNER JOIN
|
|
|
- tede_middle b ON a.Id = b.MiddleId AND b.FolderType ={collectionContsValue} {sqlStr}
|
|
|
- AND a.UserId ={request.UserId} and b.IsDelete=0";
|
|
|
- result.Total = await connection.ExecuteScalarAsync<int>(sql);
|
|
|
+ query.WhereLike("tede_collection.Title", $"%{request.SearchKey}%");
|
|
|
+ query.Where("a.FolderType", collectionContsValue);
|
|
|
+ query.Where("tede_collection.UserId", request.UserId);
|
|
|
+ query.Where("a.IsDelete", false);
|
|
|
+ query.OrderByDesc("a.IsTop");
|
|
|
+ query.OrderByDesc("a.LastModifiedDate");
|
|
|
+ query.ForPage(request.Page, request.PerPage);
|
|
|
+ query.Select(
|
|
|
+ "tede_collection.{UserId,Title,CollectionType,CollectionDataId,SourceUserId}",
|
|
|
+ "a.{IsTop,Id,Title,MiddleId,ParentId as FolderId}"
|
|
|
+ );
|
|
|
+ query.Select(folderNameQuery, "FolderName");
|
|
|
+ result.Items = await _repository.GetAllAsync<CollectionNoFolderResult>(query);
|
|
|
+ query = new SqlKata.Query("tede_collection");
|
|
|
+ query.Join("tede_middle as a", "a.MiddleId", "tede_collection.Id");
|
|
|
+ if (!string.IsNullOrEmpty(request.SearchKey))
|
|
|
+ query.WhereLike("tede_collection.Title", $"%{request.SearchKey}%");
|
|
|
+ query.Where("a.FolderType", collectionContsValue);
|
|
|
+ query.Where("tede_collection.UserId", request.UserId);
|
|
|
+ query.Where("a.IsDelete", false);
|
|
|
+ result.Total = await _repository.CountAsync(query);
|
|
|
return result;
|
|
|
}
|
|
|
}
|