This commit is contained in:
pivotqwq 2025-04-29 22:58:16 +08:00
parent 2b15e68017
commit 3bb3bf5e3a

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System.Buffers.Text;
using System.Data;
using System.Security.Claims;
@ -190,9 +191,16 @@ namespace asg_form.Controllers
public string username { get; set; }
public string joinTime { get; set; }
public string base64 { get; set; }
public int joinCount { get; set; }
public int count { get; set; }
}
public class Item
{
public int id { get; set; }
public string chinaname { get; set; }
}
/// <summary>
/// 解说排行榜
/// </summary>
@ -204,23 +212,44 @@ namespace asg_form.Controllers
try
{
DateTime currentTime = DateTime.Now;
Dictionary<string, int> comCount = new Dictionary<string, int>();
comCount.Add("默认",0);
TestDbContext db = new TestDbContext();
var gameAll = db.team_Games.Select(g => g.commentary).ToList();
foreach (var game in gameAll)
{
if (game == null) continue;
List<Item> items = JsonConvert.DeserializeObject<List<Item>>(game);
foreach (var item in items)
{
if (comCount.ContainsKey(item.chinaname))
{
comCount.Add(item.chinaname, 1);
}
else
{
comCount[item.chinaname] += 1;
}
}
}
var rankings = userManager.Users
.Where(u => u.joinTime != null && u.officium == "Commentator")
.AsEnumerable()
.OrderByDescending(u => (currentTime - u.joinTime.ToDateTime()).TotalSeconds)
.Skip((page - 1) * limit)
.Take(limit)
.Select(u => new userRanking
{
userId = u.Id,
username = u.chinaname,
joinTime = u.joinTime,
base64 = u.UserBase64,
//count = (int)((currentTime - u.joinTime.ToDateTime()).TotalSeconds/ 86400),
joinCount = (int)((currentTime - u.joinTime.ToDateTime()).TotalSeconds / 86400),
count = comCount[u.chinaname == null ? "默认" : u.chinaname]
})
.OrderByDescending(u => u.count)
.Skip((page - 1) * limit)
.Take(limit)
.ToList();
return Ok(new { code = 200, message = "", rankings });
}
catch (Exception ex)