diff --git a/AxibugEmuOnline.Web/Controllers/ApiController.cs b/AxibugEmuOnline.Web/Controllers/ApiController.cs index a0f0472..b35c20f 100644 --- a/AxibugEmuOnline.Web/Controllers/ApiController.cs +++ b/AxibugEmuOnline.Web/Controllers/ApiController.cs @@ -14,14 +14,32 @@ namespace AxibugEmuOnline.Web.Controllers } [HttpGet] - public JsonResult NesRomList(string SearchKey,int Page, int PageSize) + public JsonResult NesRomList(string SearchKey,int Ptype,int GType,int Page, int PageSize) { string searchPattern = $"%{SearchKey}%"; Resp_GameList resp = new Resp_GameList(); - resp.GameList = new List(); - using (MySqlConnection conn = Haoyue_SQLPoolManager.DequeueSQLConn("NesRomList")) + resp.gameList = new List(); + MySqlConnection conn = Haoyue_SQLPoolManager.DequeueSQLConn("NesRomList"); { - string query = "SELECT count(id) FROM romlist_nes where `Name` like ?searchPattern "; + + GameType SearchGType = (GameType)GType; + + string GameTypeCond = ""; + switch (SearchGType) + { + case GameType.NONE: + GameTypeCond = string.Empty; + break; + case GameType.ALLINONE: + GameTypeCond = $" and GameType = '合卡' "; + break; + default: + GameTypeCond = $" and GameType = '{SearchGType.ToString()}' "; + break; + } + + + string query = "SELECT count(id) FROM romlist_nes where `Name` like ?searchPattern " + GameTypeCond; using (var command = new MySqlCommand(query, conn)) { // 设置参数值 @@ -31,14 +49,14 @@ namespace AxibugEmuOnline.Web.Controllers { while (reader.Read()) { - resp.ResultAllCount = reader.GetInt32(0); - resp.Page = Page; - resp.MaxPage = resp.ResultAllCount / PageSize; + resp.resultAllCount = reader.GetInt32(0); + resp.page = Page; + resp.maxPage = (int)Math.Ceiling((float)resp.resultAllCount / PageSize); } } } - query = "SELECT id,`Name`,RomUrl,ImgUrl FROM romlist_nes where `Name` like ?searchPattern LIMIT ?offset, ?pageSize;"; + query = $"SELECT id,`Name`,GameType,Note,RomUrl,ImgUrl,`Hash` FROM romlist_nes where `Name` like ?searchPattern {GameTypeCond} LIMIT ?offset, ?pageSize;"; using (var command = new MySqlCommand(query, conn)) { // 设置参数值 @@ -50,12 +68,16 @@ namespace AxibugEmuOnline.Web.Controllers { while (reader.Read()) { - resp.GameList.Add(new Resp_RomInfo() { - ID = reader.GetInt32(0), - RomName = reader.GetString(1), - Hash = string.Empty, - ImgUrl = reader.GetString(2), - Url = reader.GetString(3), + resp.gameList.Add(new Resp_RomInfo() + { + id = reader.GetInt32(0), + romName = !reader.IsDBNull(1) ? reader.GetString(1) : string.Empty, + gType = !reader.IsDBNull(2) ? reader.GetString(2) : string.Empty, + desc = !reader.IsDBNull(3) ? reader.GetString(3) : string.Empty, + url = !reader.IsDBNull(4) ? reader.GetString(4) : string.Empty, + imgUrl = !reader.IsDBNull(5) ? reader.GetString(5) : string.Empty, + hash = !reader.IsDBNull(6) ? reader.GetString(6) : string.Empty, + stars = 0, }); } } @@ -65,22 +87,52 @@ namespace AxibugEmuOnline.Web.Controllers return new JsonResult(resp); } + enum PlatformType : byte + { + All = 0, + Nes, + } + + enum GameType : byte + { + NONE = 0, + ACT, + ARPG, + AVG, + ETC, + FTG, + PUZ, + RAC, + RPG, + SLG, + SPG, + SRPG, + STG, + TAB, + /// + /// 合卡 + /// + ALLINONE, + } class Resp_GameList { - public int Page { get; set; } - public int MaxPage { get; set; } - public int ResultAllCount { get; set; } - public List GameList { get; set; } + public int page { get; set; } + public int maxPage { get; set; } + public int resultAllCount { get; set; } + public List gameList { get; set; } } public class Resp_RomInfo { - public int ID { get; set; } - public string Hash { get; set; } - public string RomName { get; set;} - public string Url { get; set; } - public string ImgUrl { get; set; } + public int id { get; set; } + public string romName { get; set;} + public string gType { get; set; } + public string desc { get; set; } + public string url { get; set; } + public string imgUrl { get; set; } + public string hash { get; set; } + public int stars { get; set; } } } }