using Competition.Common.Util; using CompetitionAPI.Util; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Drawing.Printing; using System.Text; namespace CompetitionAPI.Controllers.back { [Route("api/[controller]")] [ApiController] public class GetExamListController : Controller { Competition.Mysql.BLL.pow_exam exam_bll = new Competition.Mysql.BLL.pow_exam(); public GetExamListController() { } /// /// 获取考试列表接口 /// /// 考试名称 /// 考试状态 未发布、已发布、已结束 /// 类型 考试、实训 /// 页码/param> /// 每页数量/param> /// [Authorize] [HttpGet] [APIFilter] public JsonResult Index(int PageIndex, int PageSize, string ExamName = "", string Status = "", string Type = "") { try { var query = new StringBuilder(" 1 = 1 "); var total_query = new StringBuilder(" 1 = 1 "); if (!string.IsNullOrWhiteSpace(ExamName)) { query.AppendFormat(" AND T1.ExamName LIKE '%{0}%' ", ExamName); total_query.AppendFormat(" AND ExamName LIKE '%{0}%' ", ExamName); } if (!string.IsNullOrWhiteSpace(Status)) { query.AppendFormat(" AND T1.Status = '{0}' ", Status); total_query.AppendFormat(" AND Status = '{0}' ", Status); } if (!string.IsNullOrWhiteSpace(Type)) { query.AppendFormat(" AND T1.Type = '{0}' ", Type); total_query.AppendFormat(" AND Type = '{0}' ", Type); } var offset = (PageIndex - 1) * PageSize; query.AppendFormat(" order by T1.CreateTime desc LIMIT {0} OFFSET {1} ", PageSize, offset); var total = exam_bll.GetRecordCount(total_query.ToString()); var list = exam_bll.GetAllList(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, "发生错误,请联系管理员。")); } } } }