/***********************************************************************
|
* Project: baifenBinfa
|
* ProjectName: 百分兵法管理系统
|
* Web: http://chuanyin.com
|
* Author:
|
* Email:
|
* CreateTime: 202403/02
|
* Description: 暂无
|
***********************************************************************/
|
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using CoreCms.Net.IServices;
|
using CoreCms.Net.Model.Entities;
|
using CoreCms.Net.Model.Entities.Expression;
|
using CoreCms.Net.Model.FromBody;
|
using CoreCms.Net.Model.ViewModels.UI;
|
using Microsoft.AspNetCore.Mvc;
|
using SqlSugar;
|
|
namespace CoreCms.Net.Web.WebApi.Controllers
|
{
|
/// <summary>
|
/// 文章api控制器
|
/// </summary>
|
[Route("api/[controller]/[action]")]
|
[ApiController]
|
public class ArticleController : ControllerBase
|
{
|
private readonly ICoreCmsArticleServices _articleServices;
|
private readonly ICoreCmsArticleTypeServices _articleTypeServices;
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="articleServices"></param>
|
/// <param name="articleTypeServices"></param>
|
public ArticleController(ICoreCmsArticleServices articleServices, ICoreCmsArticleTypeServices articleTypeServices)
|
{
|
_articleServices = articleServices;
|
_articleTypeServices = articleTypeServices;
|
}
|
|
#region 获取通知列表
|
/// <summary>
|
/// 获取通知列表
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<WebApiCallBack> NoticeList([FromBody] FMPageByIntId entity)
|
{
|
var jm = new WebApiCallBack();
|
|
var list = await _articleServices.QueryPageAsync(p => p.isDel == false, p => p.createTime, OrderByType.Desc,
|
entity.page, entity.limit);
|
jm.status = true;
|
jm.data = list;
|
|
return jm;
|
}
|
|
#endregion
|
|
#region 获取文章栏目
|
/// <summary>
|
/// 获取文章列表
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<WebApiCallBack> GetArticleClassify()
|
{
|
var jm = new WebApiCallBack
|
{
|
status = true,
|
data = await _articleTypeServices.QueryListByClauseAsync(p => p.id > 0, p => p.sort, OrderByType.Desc, true, true)
|
};
|
return jm;
|
}
|
|
#endregion
|
|
#region 获取最新文章
|
/// <summary>
|
/// 获取最新文章
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<WebApiCallBack> GetNewArticle([FromBody] FMGetNewArticle entity)
|
{
|
var jm = new WebApiCallBack
|
{
|
status = true,
|
data = await _articleServices.QueryListAsync(p => p.isPub == true, p => p.createTime, OrderByType.Desc, entity.num)
|
};
|
return jm;
|
}
|
|
#endregion
|
|
#region 获取文章列表
|
/// <summary>
|
/// 获取文章列表
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<WebApiCallBack> GetArticleList([FromBody] FMPageByIntId entity)
|
{
|
var jm = new WebApiCallBack();
|
|
var articleType = await _articleTypeServices.QueryListByClauseAsync(p => p.id > 0, p => p.sort, OrderByType.Asc, true, true);
|
if (articleType.Any())
|
{
|
var where = PredicateBuilder.True<CoreCmsArticle>();
|
if (entity.id > 0)
|
{
|
where = where.And(p => p.isDel == false && p.typeId == entity.id);
|
}
|
else
|
{
|
var typeId = articleType.FirstOrDefault()!.id;
|
where = where.And(p => p.isDel == false && p.typeId == typeId);
|
}
|
var list = await _articleServices.QueryPageAsync(where, p => p.createTime, OrderByType.Desc, entity.page, entity.limit);
|
jm.data = new
|
{
|
list,
|
articleType,
|
count = list.TotalCount,
|
list.HasNextPage,
|
list.HasPreviousPage,
|
list.TotalPages
|
};
|
}
|
else
|
{
|
jm.data = new
|
{
|
list = new List<CoreCmsArticle>(),
|
articleType,
|
count = 0
|
};
|
}
|
jm.status = true;
|
return jm;
|
}
|
|
#endregion
|
|
#region 获取单个文章内容
|
/// <summary>
|
/// 获取单个文章内容
|
/// </summary>
|
/// <param name="entity"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<WebApiCallBack> GetArticleDetail([FromBody] FMIntId entity)
|
{
|
var jm = new WebApiCallBack();
|
|
var model = await _articleServices.ArticleDetail(entity.id);
|
if (model == null)
|
{
|
jm.msg = "数据获取失败";
|
return jm;
|
}
|
jm.status = true;
|
jm.data = model;
|
return jm;
|
|
}
|
#endregion
|
}
|
}
|