32
This commit is contained in:
parent
fdfceec731
commit
db8c230511
|
|
@ -27,6 +27,10 @@ namespace ZR.LiveForum.Model.Liveforum.Dto
|
|||
[ExcelColumnName("用户ID")]
|
||||
public long UserId { get; set; }
|
||||
|
||||
[ExcelColumn(Name = "用户昵称")]
|
||||
[ExcelColumnName("用户昵称")]
|
||||
public string? NickName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "标题不能为空")]
|
||||
[ExcelColumn(Name = "标题")]
|
||||
[ExcelColumnName("标题")]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using Infrastructure;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Extensions;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
|
|
|
|||
|
|
@ -22,13 +22,103 @@ namespace ZR.Service.Liveforum
|
|||
{
|
||||
var predicate = QueryExp(parm);
|
||||
|
||||
var response = Queryable()
|
||||
//.OrderBy("Id desc")
|
||||
var query = Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.ToPage<T_Posts, T_PostsDto>(parm);
|
||||
.LeftJoin<T_Users>((p, u) => p.UserId == u.Id);
|
||||
|
||||
return response;
|
||||
// 在 Select 之前进行排序,使用表别名
|
||||
if (parm.Sort.IsNotEmpty())
|
||||
{
|
||||
var orderType = parm.SortType.Contains("desc") ? OrderByType.Desc : OrderByType.Asc;
|
||||
query = ApplyOrderBy(query, parm.Sort, orderType);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 默认排序
|
||||
query = query.OrderBy((p, u) => p.Id, OrderByType.Desc);
|
||||
}
|
||||
|
||||
var response = query.Select((p, u) => new T_PostsDto()
|
||||
{
|
||||
Id = p.Id,
|
||||
UserId = p.UserId,
|
||||
NickName = u.NickName,
|
||||
Title = p.Title,
|
||||
CoverImage = p.CoverImage,
|
||||
Content = p.Content,
|
||||
CategoryId = p.CategoryId,
|
||||
ViewCount = p.ViewCount,
|
||||
LikeCount = p.LikeCount,
|
||||
CommentCount = p.CommentCount,
|
||||
ShareCount = p.ShareCount,
|
||||
IsTop = p.IsTop,
|
||||
IsHot = p.IsHot,
|
||||
IsEssence = p.IsEssence,
|
||||
Status = p.Status,
|
||||
PublishTime = p.PublishTime,
|
||||
IsDeleted = p.IsDeleted,
|
||||
DeletedAt = p.DeletedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
UpdatedAt = p.UpdatedAt,
|
||||
}, true);
|
||||
|
||||
var resp = ToPage(response, parm);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用排序(在 Join 查询中使用表别名)
|
||||
/// </summary>
|
||||
private ISugarQueryable<T_Posts, T_Users> ApplyOrderBy(ISugarQueryable<T_Posts, T_Users> query, string sortField, OrderByType orderType)
|
||||
{
|
||||
// 将 DTO 属性名映射到表字段表达式
|
||||
return sortField.ToLower() switch
|
||||
{
|
||||
"id" => query.OrderBy((p, u) => p.Id, orderType),
|
||||
"userid" => query.OrderBy((p, u) => p.UserId, orderType),
|
||||
"nickname" => query.OrderBy((p, u) => u.NickName, orderType),
|
||||
"title" => query.OrderBy((p, u) => p.Title, orderType),
|
||||
"coverimage" => query.OrderBy((p, u) => p.CoverImage, orderType),
|
||||
"content" => query.OrderBy((p, u) => p.Content, orderType),
|
||||
"categoryid" => query.OrderBy((p, u) => p.CategoryId, orderType),
|
||||
"viewcount" => query.OrderBy((p, u) => p.ViewCount, orderType),
|
||||
"likecount" => query.OrderBy((p, u) => p.LikeCount, orderType),
|
||||
"commentcount" => query.OrderBy((p, u) => p.CommentCount, orderType),
|
||||
"sharecount" => query.OrderBy((p, u) => p.ShareCount, orderType),
|
||||
"istop" => query.OrderBy((p, u) => p.IsTop, orderType),
|
||||
"ishot" => query.OrderBy((p, u) => p.IsHot, orderType),
|
||||
"isessence" => query.OrderBy((p, u) => p.IsEssence, orderType),
|
||||
"status" => query.OrderBy((p, u) => p.Status, orderType),
|
||||
"publishtime" => query.OrderBy((p, u) => p.PublishTime, orderType),
|
||||
"isdeleted" => query.OrderBy((p, u) => p.IsDeleted, orderType),
|
||||
"deletedat" => query.OrderBy((p, u) => p.DeletedAt, orderType),
|
||||
"createdat" => query.OrderBy((p, u) => p.CreatedAt, orderType),
|
||||
"updatedat" => query.OrderBy((p, u) => p.UpdatedAt, orderType),
|
||||
_ => query.OrderBy((p, u) => p.Id, OrderByType.Desc) // 默认排序
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取列表
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="source">查询表单式</param>
|
||||
/// <param name="parm">分页参数</param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<T> ToPage<T>(ISugarQueryable<T> source, PagerInfo parm)
|
||||
{
|
||||
var page = new PagedInfo<T>();
|
||||
var total = 0;
|
||||
page.PageSize = parm.PageSize;
|
||||
page.PageIndex = parm.PageNum;
|
||||
// 注意:排序已经在 Select 之前完成了,这里不再需要排序
|
||||
page.Result = source
|
||||
.ToPageList(parm.PageNum, parm.PageSize, ref total);
|
||||
page.TotalNum = total;
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -76,16 +166,41 @@ namespace ZR.Service.Liveforum
|
|||
parm.PageSize = 100000;
|
||||
var predicate = QueryExp(parm);
|
||||
|
||||
var response = Queryable()
|
||||
var query = Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.Select((it) => new T_PostsDto()
|
||||
{
|
||||
//IsTopLabel = it.IsTop.GetConfigValue<Model.System.SysDictData>("liveforum_action_bool"),
|
||||
//StatusLabel = it.Status.GetConfigValue<Model.System.SysDictData>("liveforum_posts_status"),
|
||||
}, true)
|
||||
.ToPage(parm);
|
||||
.LeftJoin<T_Users>((p, u) => p.UserId == u.Id);
|
||||
|
||||
return response;
|
||||
// 导出时使用默认排序
|
||||
query = query.OrderBy((p, u) => p.Id, OrderByType.Desc);
|
||||
|
||||
var response = query.Select((p, u) => new T_PostsDto()
|
||||
{
|
||||
Id = p.Id,
|
||||
UserId = p.UserId,
|
||||
NickName = u.NickName,
|
||||
Title = p.Title,
|
||||
CoverImage = p.CoverImage,
|
||||
Content = p.Content,
|
||||
CategoryId = p.CategoryId,
|
||||
ViewCount = p.ViewCount,
|
||||
LikeCount = p.LikeCount,
|
||||
CommentCount = p.CommentCount,
|
||||
ShareCount = p.ShareCount,
|
||||
IsTop = p.IsTop,
|
||||
IsHot = p.IsHot,
|
||||
IsEssence = p.IsEssence,
|
||||
Status = p.Status,
|
||||
PublishTime = p.PublishTime,
|
||||
IsDeleted = p.IsDeleted,
|
||||
DeletedAt = p.DeletedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
UpdatedAt = p.UpdatedAt,
|
||||
//IsTopLabel = p.IsTop.GetConfigValue<Model.System.SysDictData>("liveforum_action_bool"),
|
||||
//StatusLabel = p.Status.GetConfigValue<Model.System.SysDictData>("liveforum_posts_status"),
|
||||
}, true);
|
||||
var resp = ToPage(response, parm);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -98,7 +213,7 @@ namespace ZR.Service.Liveforum
|
|||
var predicate = Expressionable.Create<T_Posts>();
|
||||
|
||||
predicate = predicate.AndIF(parm.UserId != null, it => it.UserId == parm.UserId);
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Title), it => it.Title == parm.Title);
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Title), it => it.Title == parm.Title || it.Content.Contains(parm.Title));
|
||||
predicate = predicate.AndIF(parm.Status != null, it => it.Status == parm.Status);
|
||||
predicate = predicate.AndIF(parm.IsDeleted != null, it => it.IsDeleted == parm.IsDeleted);
|
||||
return predicate;
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@
|
|||
<el-table-column type="selection" width="50" align="center"/>
|
||||
<el-table-column prop="id" label="id" align="center" v-if="columns.showColumn('id')"/>
|
||||
<el-table-column prop="userId" label="用户ID" align="center" v-if="columns.showColumn('userId')"/>
|
||||
<el-table-column prop="nickName" label="用户昵称" align="center" :show-overflow-tooltip="true" v-if="columns.showColumn('nickName')"/>
|
||||
<el-table-column prop="title" label="标题" align="center" :show-overflow-tooltip="true" v-if="columns.showColumn('title')"/>
|
||||
<el-table-column prop="coverImage" label="封面图片" align="center" v-if="columns.showColumn('coverImage')">
|
||||
<template #default="scope">
|
||||
|
|
@ -249,6 +250,7 @@ const queryParams = reactive({
|
|||
const columns = ref([
|
||||
{ visible: true, align: 'center', type: '', prop: 'id', label: 'id' },
|
||||
{ visible: true, align: 'center', type: '', prop: 'userId', label: '用户ID' },
|
||||
{ visible: true, align: 'center', type: '', prop: 'nickName', label: '用户昵称' ,showOverflowTooltip: true },
|
||||
{ visible: true, align: 'center', type: '', prop: 'title', label: '标题' ,showOverflowTooltip: true },
|
||||
{ visible: true, align: 'center', type: 'img', prop: 'coverImage', label: '封面图片' ,showOverflowTooltip: true },
|
||||
{ visible: true, align: 'center', type: '', prop: 'content', label: '正文内容' ,showOverflowTooltip: true },
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user