This commit is contained in:
王炜翔 2024-10-26 22:19:56 +08:00
parent d7fbbc77e0
commit 47af2cbfd0

View File

@ -164,7 +164,6 @@ namespace asg_form.Controllers.Team
[Route("api/v2/form/all")] [Route("api/v2/form/all")]
[HttpGet] [HttpGet]
[Authorize]
public List<team> Getform(short page, short page_long, string sort, string eventsname) public List<team> Getform(short page, short page_long, string sort, string eventsname)
{ {
using (TestDbContext ctx = new TestDbContext()) using (TestDbContext ctx = new TestDbContext())
@ -209,13 +208,17 @@ namespace asg_form.Controllers.Team
public class TeamFind public class TeamFind
{ {
public List<string> roleId { get; set; }
public long formId { get; set; }
public string teamName { get; set; } public string teamName { get; set; }
public List<string> roles { get; set; } public List<string> roles { get; set; }
public int voteOfLikes { get; set; }
public List<string>? roleLin { get; set; }
public List<string>? commonRoles { get; set; }
} }
[Route("api/v3/form/all")] [Route("api/v3/form/all")]
[HttpGet] [HttpGet]
[Authorize]
public async Task<ActionResult<object>> GetFormById(short page, short limit, int sort, int eventId) public async Task<ActionResult<object>> GetFormById(short page, short limit, int sort, int eventId)
{ {
using (var db = new TestDbContext()) using (var db = new TestDbContext())
@ -228,11 +231,15 @@ namespace asg_form.Controllers.Team
select new select new
{ {
m.team_name, m.team_name,
r.role_id,
r.role_name, r.role_name,
r.role_lin,
r.Common_Roles,
m.piaoshu, m.piaoshu,
m.time m.time,
m.Id
}; };
switch (sort) switch (sort)
{ {
case 0: case 0:
query = query.OrderByDescending(m => m.piaoshu).ThenByDescending(m => m.time); query = query.OrderByDescending(m => m.piaoshu).ThenByDescending(m => m.time);
@ -253,11 +260,16 @@ namespace asg_form.Controllers.Team
break; break;
} }
var results = await query var results = await query
.GroupBy(m => new { m.team_name, m.piaoshu, m.time }) .GroupBy(m => new { m.team_name, m.Id,m.piaoshu, m.time })
.Select(g => new TeamFind .Select(g => new TeamFind
{ {
formId = g.Key.Id,
teamName = g.Key.team_name, teamName = g.Key.team_name,
roles = g.Select(x => x.role_name).ToList() roles = g.Select(x => x.role_name).ToList(),
voteOfLikes = g.Key.piaoshu,
roleLin = g.Select(x => x.role_lin).ToList(), // 选择第一个roleLin
commonRoles = g.Select(x => x.Common_Roles).ToList(), // 选择第一个commonRoles
roleId = g.Select(x => x.role_id).ToList(), // 选择第一个roleId
}) })
.Skip((page - 1) * limit) .Skip((page - 1) * limit)
.Take(limit) .Take(limit)