using Competition.Common.Util; using CompetitionAPI.Util; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Text; namespace CompetitionAPI.Controllers.back.room { [Route("api/[controller]")] [ApiController] public class GetRoomIPListController : Controller { Competition.Mysql.BLL.admin_ip ip_bll = new Competition.Mysql.BLL.admin_ip(); public GetRoomIPListController() { } /// /// 获取考场IP列表接口 /// /// IP /// 页码/param> /// 每页数量/param> /// [Authorize] [HttpGet] [APIFilter] public JsonResult Index(int PageIndex, int PageSize, string IP = "") { try { var query = new StringBuilder(" 1=1 "); var total_query = new StringBuilder(" 1=1 "); if (!string.IsNullOrWhiteSpace(IP)) { query.AppendFormat(" AND IP LIKE '%{0}%' ", IP); total_query.AppendFormat(" AND IP LIKE '%{0}%' ", IP); } var offset = (PageIndex - 1) * PageSize; query.AppendFormat(" order by CreateTime desc LIMIT {0} OFFSET {1} ", PageSize, offset); var total = ip_bll.GetRecordCount(total_query.ToString()); var list = ip_bll.GetModelList(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, "发生错误,请联系管理员。")); } } } }