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