75 lines
2.8 KiB
C#
75 lines
2.8 KiB
C#
using Competition.Common.Util;
|
|
using CompetitionAPI.Util;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NPOI.SS.Formula.Functions;
|
|
using System.Text;
|
|
|
|
namespace CompetitionAPI.Controllers.back.study
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class GetStudyListController : Controller
|
|
{
|
|
Competition.Mysql.BLL.pow_study study_bll = new Competition.Mysql.BLL.pow_study();
|
|
|
|
public GetStudyListController()
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取学习列表接口
|
|
/// </summary>
|
|
/// <param name="StudyName">学习名称</param>
|
|
/// <param name="StudyClassId">学习分类id</param>
|
|
/// <param name="Status">状态 未发布、已发布/param>
|
|
/// <param name="PageIndex">页码/param>
|
|
/// <param name="PageSize">每页数量/param>
|
|
/// <returns></returns>
|
|
[Authorize]
|
|
[HttpGet]
|
|
[APIFilter]
|
|
public JsonResult Index(int PageIndex, int PageSize, string StudyName = "", string StudyClassId = "", string Status = "")
|
|
{
|
|
try
|
|
{
|
|
var query = new StringBuilder(" 1 = 1 ");
|
|
var total_query = new StringBuilder(" 1 = 1 ");
|
|
|
|
//学习名称
|
|
if (!string.IsNullOrWhiteSpace(StudyName))
|
|
{
|
|
query.AppendFormat(" AND T1.StudyName LIKE '%{0}%'", StudyName);
|
|
total_query.AppendFormat(" AND T1.StudyName LIKE '%{0}%' ", StudyName);
|
|
}
|
|
|
|
//学习分类
|
|
if (!string.IsNullOrWhiteSpace(StudyClassId))
|
|
{
|
|
query.AppendFormat(" AND T1.StudyClassId='{0}' ", StudyClassId);
|
|
total_query.AppendFormat(" AND T1.StudyClassId='{0}' ", StudyClassId);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(Status))
|
|
{
|
|
query.AppendFormat(" AND T1.Status='{0}' ", Status);
|
|
total_query.AppendFormat(" AND T1.Status='{0}' ", Status);
|
|
}
|
|
|
|
var offset = (PageIndex - 1) * PageSize;
|
|
query.AppendFormat(" order by T1.CreateTime desc LIMIT {0} OFFSET {1} ", PageSize, offset);
|
|
|
|
var total = study_bll.GetClassRecordCount(total_query.ToString());
|
|
var list = study_bll.GetClassList(query.ToString());
|
|
return Json(Tool.GetJsonWithCode(APICode.Success, new { total = total, list = list }));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。"));
|
|
}
|
|
}
|
|
}
|
|
}
|