请教,是不是像下面黑体部分这样添加? 前端如何调用? LabelIds添加到了一个基础参数BaseParameter里 public string LabelIds { get; set; }
#region 根据频道名称获取指定数量列表
/// <summary>
/// 根据频道名称获取指定数量列表
/// 示例:/client/article/view/channel/news/10?categoryId=1
/// </summary>
[HttpGet("/client/article/view/channel/{channelName}/{top}")]
public async Task<IActionResult> ClientGetList([FromRoute] string channelName, [FromRoute] int top, [FromQuery] ArticleParameter searchParam)
{
searchParam.Fields = "Id,SiteId,ChannelId,CallIndex,Title,Source,Author," +
"LinkUrl,ImgUrl,SeoTitle,SeoKeyword,SeoDescription,Zhaiyao," +
"Content,SortId,Click,Status,IsComment,CommentCount,LikeCount,AddTime,CategoryTitle," +
"LabelTitle,ArticleFields,ArticleAlbums,ArticleAttachs,ArticleLabelRelations,ArticleCategoryRelations";
//检测参数是否合法
if (searchParam.OrderBy.IsNotNullOrEmpty()
&& !searchParam.OrderBy.Replace("-", "").IsPropertyExists<ArticlesDto>())
{
return BadRequest(ResponseMessage.Error("请输入正确的排序参数"));
}
if (!searchParam.Fields.IsPropertyExists<ArticlesDto>())
{
return BadRequest(ResponseMessage.Error("请输入正确的属性参数"));
}
if (string.IsNullOrWhiteSpace(channelName))
{
return BadRequest(ResponseMessage.Error("请传入频道名称"));
}
//获得频道实体
SiteChannel channelModel = await _siteChannelService.QueryAsync(t => t.Name.Equals(channelName) && t.SiteId.Equals(searchParam.SiteId));
if (channelModel == null)
{
return BadRequest(ResponseMessage.Error("频道不存在"));
}
if (searchParam.LabelIds == null)
{
return BadRequest(ResponseMessage.Error("传输参数不可为空"));
}
//将ID列表转换成IEnumerable
var labelIds = searchParam.LabelIds.ToIEnumerable<long>();
if (labelIds == null)
{
return BadRequest(ResponseMessage.Error("传输参数不符合规范"));
}
//获取数据库列表
var resultFrom = await _articleService.QueryListAsync(top,
x => (searchParam.CategoryId > 0 ? x.ArticleCategoryRelations.Any(t => t.CategoryId == searchParam.CategoryId) : true)//查询分类
&& (searchParam.Keyword.IsNotNullOrEmpty() ? x.Title.Contains(searchParam.Keyword) : true)//查询关键字
&& (searchParam.LabelId > 0 ? x.ArticleLabelRelations.Any(t => t.LabelId == searchParam.LabelId) : true)
&& (searchParam.LabelIds == null || x.ArticleLabelRelations.Any(l => labelIds.Contains(l.LabelId)))
&& (searchParam.StartDate != null ? DateTime.Compare(x.AddTime, searchParam.StartDate.GetValueOrDefault()) >= 0 : true)
&& (searchParam.EndDate != null ? DateTime.Compare(x.AddTime, searchParam.EndDate.GetValueOrDefault()) <= 0 : true)
&& x.ChannelId == channelModel.Id,//频道查询
searchParam.OrderBy.IsNotNullOrWhiteSpace() ? searchParam.OrderBy : "SortId,-Id");
//映射成DTO,根据字段进行塑形
var resultDto = _mapper.Map<IEnumerable<ArticlesClientDto>>(resultFrom).ShapeData(searchParam.Fields);
//返回成功200
return Ok(resultDto);
}
#endregion