From 002aa92d0b8b96433f8b139e1386bdc3a0cf615a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=AF=85?= <2667210109@qq.com> Date: Mon, 27 Jan 2025 20:32:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Packages.props | 40 ++++++ .../asg_form.ServiceDefaults.csproj | 20 ++- asg_form/Controllers/AssignmentController.cs | 3 + asg_form/Controllers/BlackController.cs | 3 + .../Controllers/Budget/BgCountController.cs | 2 + asg_form/Controllers/Champion.cs | 3 + asg_form/Controllers/Com.cs | 62 +++++++-- asg_form/Controllers/Events.cs | 3 + asg_form/Controllers/InviteReferee.cs | 3 + asg_form/Controllers/OAuthController.cs | 3 + asg_form/Controllers/Store/Storehttp.cs | 5 +- .../Teamregistration/RegisterController.cs | 3 + asg_form/Controllers/admin.cs | 2 + .../Controllers/auditAndFilingController.cs | 3 + asg_form/Controllers/chatgpt.cs | 3 + asg_form/Controllers/comform.cs | 3 + asg_form/Controllers/excel.cs | 3 + asg_form/Controllers/form_cs.cs | 131 +----------------- .../Controllers/idvrole/RoleController.cs | 2 - asg_form/Controllers/login.cs | 7 +- asg_form/Controllers/menuAssignController.cs | 3 + asg_form/Controllers/new1.cs | 3 + asg_form/Controllers/news.cs | 3 + asg_form/Controllers/schedule.cs | 5 +- asg_form/Controllers/user_form.cs | 3 + asg_form/Controllers/webhook.cs | 3 + asg_form/Program.cs | 22 +-- asg_form/asg_form.csproj | 61 ++++---- 28 files changed, 205 insertions(+), 202 deletions(-) create mode 100644 Directory.Packages.props diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..cc09d2d --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,40 @@ + + + true + true + $(NoWarn);NU1507 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/asg_form.ServiceDefaults/asg_form.ServiceDefaults.csproj b/asg_form.ServiceDefaults/asg_form.ServiceDefaults.csproj index 34c4b0b..d6e6a1a 100644 --- a/asg_form.ServiceDefaults/asg_form.ServiceDefaults.csproj +++ b/asg_form.ServiceDefaults/asg_form.ServiceDefaults.csproj @@ -1,22 +1,18 @@ - net8.0 enable enable true - - - - - - - - - + + + + + + + - - + \ No newline at end of file diff --git a/asg_form/Controllers/AssignmentController.cs b/asg_form/Controllers/AssignmentController.cs index 4f43b94..15894ec 100644 --- a/asg_form/Controllers/AssignmentController.cs +++ b/asg_form/Controllers/AssignmentController.cs @@ -15,6 +15,9 @@ using Flandre.Core.Common; namespace asg_form.Controllers { + + + [ApiController] public class TaskDB { public long id { get; set; } diff --git a/asg_form/Controllers/BlackController.cs b/asg_form/Controllers/BlackController.cs index d045600..811bc41 100644 --- a/asg_form/Controllers/BlackController.cs +++ b/asg_form/Controllers/BlackController.cs @@ -12,6 +12,9 @@ namespace asg_form.Controllers public string user_name { get; set; } //..... } + + + [ApiController] public class BlackController : ControllerBase { [Route("api/v1/blackTable")] diff --git a/asg_form/Controllers/Budget/BgCountController.cs b/asg_form/Controllers/Budget/BgCountController.cs index 880f5ef..8a1df1f 100644 --- a/asg_form/Controllers/Budget/BgCountController.cs +++ b/asg_form/Controllers/Budget/BgCountController.cs @@ -29,6 +29,8 @@ namespace asg_form.Controllers.Budget } + + [ApiController] public class BgCountController : ControllerBase { private readonly RoleManager roleManager; diff --git a/asg_form/Controllers/Champion.cs b/asg_form/Controllers/Champion.cs index 6a81e6b..6cfcf98 100644 --- a/asg_form/Controllers/Champion.cs +++ b/asg_form/Controllers/Champion.cs @@ -7,6 +7,9 @@ using System.Security.Claims; namespace asg_form.Controllers { + + + [ApiController] public class Champion : ControllerBase { private readonly RoleManager roleManager; diff --git a/asg_form/Controllers/Com.cs b/asg_form/Controllers/Com.cs index 228c0f0..11abd57 100644 --- a/asg_form/Controllers/Com.cs +++ b/asg_form/Controllers/Com.cs @@ -15,6 +15,9 @@ using static asg_form.Controllers.schedule; namespace asg_form.Controllers { + + + [ApiController] public class Com : ControllerBase { @@ -90,7 +93,17 @@ namespace asg_form.Controllers } return BadRequest(new error_mb { code = 400, message = $"你是{user.officium},你不是解说,无法操作" }); } + public static long cut_value(long value) + { + long _value = value; + value = value - 5; + if (value < 0) + { + throw new ArgumentException("你已经没钱啦!"); + } + return value; + } public static int[] ConvertStringToIntArray(string input) { var cleanedInput = input.Trim('[', ']').Replace("'", ""); @@ -101,6 +114,38 @@ namespace asg_form.Controllers return result; } + //写一个api,获取选班数前十的名单 + [Route("api/v1/com/Integral/ranking")] + [HttpPost] + [Authorize] + [ResponseCache(Duration = 500)] + public async Task> ranking() + { + using(TestDbContext testDb = new TestDbContext()) { + var user = await userManager.FindByNameAsync(this.User.Identity!.Name!); + if (user.officium != "Anchor") + { + return Ok(new error_mb { code = 401, message = $"你是{user.officium},你不是导播,无法操作" }); + } + else + { + //对testDb.team_Games.commentary中出现最多的十个解说名称进行排名 + var ranking = testDb.team_Games.SelectMany(g => JsonConvert.DeserializeObject>(g.commentary).Select(c => c.chinaname)) + .GroupBy(c => c) + .OrderByDescending(g => g.Count()) + .Take(10) + .Select(g => new { Name = g.Key, Count = g.Count() }) + .ToList(); + + return ranking; + + } + } + } + + + + /// /// 导播选定场次 /// @@ -288,27 +333,17 @@ namespace asg_form.Controllers } - [Route("api/v1/com/Integral/ranking")] + [Route("api/v1/com/Integral/ranking1")] [HttpPost] [Authorize] [ResponseCache(Duration = 60)] - public async Task> ranking() + public async Task> ranking1() { object user= await userManager.Users.OrderByDescending(a => a.Integral).Select(a=>new{a.Id,a.chinaname,a.Integral}).Take(10).ToListAsync(); return user; } - public long cut_value(long value) - { - long _value = value; - value = value - 5; - if (value < 0) - { - throw new ArgumentException("你已经没钱啦!"); - - } - return value; - } + [Route("api/v1/com/")] [HttpGet] @@ -328,6 +363,7 @@ namespace asg_form.Controllers } } + } diff --git a/asg_form/Controllers/Events.cs b/asg_form/Controllers/Events.cs index a37dcda..da02bde 100644 --- a/asg_form/Controllers/Events.cs +++ b/asg_form/Controllers/Events.cs @@ -7,6 +7,9 @@ using static asg_form.Controllers.excel; namespace asg_form.Controllers { + + + [ApiController] public class Events : ControllerBase { private readonly RoleManager roleManager; diff --git a/asg_form/Controllers/InviteReferee.cs b/asg_form/Controllers/InviteReferee.cs index 92cab4d..9340ea0 100644 --- a/asg_form/Controllers/InviteReferee.cs +++ b/asg_form/Controllers/InviteReferee.cs @@ -17,6 +17,9 @@ using static System.Runtime.InteropServices.JavaScript.JSType; namespace asg_form.Controllers { + + + [ApiController] public class InviteReferee : ControllerBase { private readonly RoleManager roleManager; diff --git a/asg_form/Controllers/OAuthController.cs b/asg_form/Controllers/OAuthController.cs index 4e4f521..4e918a2 100644 --- a/asg_form/Controllers/OAuthController.cs +++ b/asg_form/Controllers/OAuthController.cs @@ -11,6 +11,9 @@ using System.Text; namespace asg_form.Controllers { + + + [ApiController] public class OAuthController : Controller { diff --git a/asg_form/Controllers/Store/Storehttp.cs b/asg_form/Controllers/Store/Storehttp.cs index 2d4c7ca..da9ec00 100644 --- a/asg_form/Controllers/Store/Storehttp.cs +++ b/asg_form/Controllers/Store/Storehttp.cs @@ -7,6 +7,9 @@ using System.Security.Claims; namespace asg_form.Controllers.Store { + + + [ApiController] public class Storehttp : ControllerBase { private readonly RoleManager roleManager; @@ -72,7 +75,7 @@ namespace asg_form.Controllers.Store return Ok(storeinfo); } } - public long cut_value(long value,long money) + public static long cut_value(long value,long money) { long _value = value; value = value - money; diff --git a/asg_form/Controllers/Teamregistration/RegisterController.cs b/asg_form/Controllers/Teamregistration/RegisterController.cs index bab0d25..361ef0c 100644 --- a/asg_form/Controllers/Teamregistration/RegisterController.cs +++ b/asg_form/Controllers/Teamregistration/RegisterController.cs @@ -48,6 +48,9 @@ namespace asg_form.Controllers.Teamregistration public string reqRole { get; set; } public string introUrl { get; set; } } + + + [ApiController] public class RegisterController : ControllerBase { private readonly RoleManager roleManager; diff --git a/asg_form/Controllers/admin.cs b/asg_form/Controllers/admin.cs index 677d5f2..9f4c000 100644 --- a/asg_form/Controllers/admin.cs +++ b/asg_form/Controllers/admin.cs @@ -32,6 +32,8 @@ using System.Net; namespace asg_form.Controllers { + + [ApiController] public class admin : ControllerBase { private readonly RoleManager roleManager; diff --git a/asg_form/Controllers/auditAndFilingController.cs b/asg_form/Controllers/auditAndFilingController.cs index b79fad6..3c1ab4c 100644 --- a/asg_form/Controllers/auditAndFilingController.cs +++ b/asg_form/Controllers/auditAndFilingController.cs @@ -61,6 +61,9 @@ namespace asg_form.Controllers { public string flowConfig { get; set; } } + + + [ApiController] public class auditAndFilingController : ControllerBase { private readonly RoleManager roleManager; diff --git a/asg_form/Controllers/chatgpt.cs b/asg_form/Controllers/chatgpt.cs index 7046c4b..426075a 100644 --- a/asg_form/Controllers/chatgpt.cs +++ b/asg_form/Controllers/chatgpt.cs @@ -7,6 +7,9 @@ using static asg_form.Controllers.login; namespace asg_form.Controllers { + + + [ApiController] public class chatgpt : ControllerBase { List allchatgpt=new List(); diff --git a/asg_form/Controllers/comform.cs b/asg_form/Controllers/comform.cs index 43f1098..773f1e3 100644 --- a/asg_form/Controllers/comform.cs +++ b/asg_form/Controllers/comform.cs @@ -9,6 +9,9 @@ using System.Threading.Tasks; namespace asg_form.Controllers { + + + [ApiController] public class comform : ControllerBase { private readonly RoleManager roleManager; diff --git a/asg_form/Controllers/excel.cs b/asg_form/Controllers/excel.cs index bbc0359..5b4c285 100644 --- a/asg_form/Controllers/excel.cs +++ b/asg_form/Controllers/excel.cs @@ -12,6 +12,9 @@ using static System.Runtime.InteropServices.JavaScript.JSType; namespace asg_form.Controllers { + + + [ApiController] public class excel : ControllerBase { diff --git a/asg_form/Controllers/form_cs.cs b/asg_form/Controllers/form_cs.cs index b5ab351..f1c0bc1 100644 --- a/asg_form/Controllers/form_cs.cs +++ b/asg_form/Controllers/form_cs.cs @@ -29,6 +29,8 @@ using System.Security.Claims; namespace asg_form.Controllers { + + [ApiController] public class form_cs : ControllerBase { [Route("api/v3/form/all")] @@ -173,32 +175,14 @@ namespace asg_form.Controllers } } + + + [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - } - // [Route("api/updateform/")] public class ύ : ControllerBase { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; + public static void WriteFile(String str) { @@ -307,85 +291,6 @@ namespace asg_form.Controllers } - /// - /// ύ - /// - /// Ϣ - /// ȸ˻֤֤ - /// - [Route("api/v1/form/")] - [HttpPost] - public async Task> PostAsync([FromBody] form_get for1,string captoken) - { - - var client = new RestClient($"https://www.recaptcha.net/recaptcha/api/siteverify?secret=6LcdXUEmAAAAAJLICuxBgtMsDiMSCm5XpB0z-fzK&response={captoken}"); - - var request = new RestRequest(Method.POST); - IRestResponse response = client.Execute(request); - string tokenjson = response.Content; - JObject d = tokenjson.ToJObject(); - string ok = d["success"].ToString(); - - - if (ok == "True") - { - - TestDbContext ctx = new TestDbContext(); - if (ctx.Forms.Include(a=>a.events).Where(a=>a.events.name==for1.events_name).Any(e => e.team_name == for1.team_name)) - { - return BadRequest(new error_mb { code = 400, message = "" }); - } - else - { - base64toimg(for1.logo_base64, $@"{AppDomain.CurrentDomain.BaseDirectory}loge\{for1.events_name}\{for1.team_name}.png"); - var events= await ctx.events.FirstAsync(ctx => ctx.name == for1.events_name); - - - form form1 = new form(); - form1.logo_uri = $"https://124.223.35.239/loge/{for1.events_name}/{for1.team_name}.png"; - form1.team_name = for1.team_name; - form1.team_password = for1.team_password; - form1.team_tel = for1.team_tel; - form1.events = events; - List role = new List(); - foreach (role_get a in for1.role_get) - { - role.Add(new role { role_id = a.role_id, role_lin = a.role_lin, role_name = a.role_name,Common_Roles=a.Common_Roles,Historical_Ranks=a.Historical_Ranks,Id_Card=a.Id_Card,Game_Name=a.Game_Name,Phone_Number=a.Phone_Number,Id_Card_Name=a.Id_Card_Name }); - } - form1.role = role; - - ctx.Forms.Add(form1); - await ctx.SaveChangesAsync(); - int nownumber = ctx.Forms.Count(); - //ChatRoomHub chat = new ChatRoomHub(); - // await chat.formok(nownumber, for1.team_name); - try - { - await hubContext.Clients.All.SendAsync("formok", $"{for1.team_name}Ѿɹʣ{ctx.Forms.Count()}/32"); - - } - catch - { - - - } - logger.Info($"¶鱨ƣ{for1.team_name} "); - } - - - return "ok!"; - - } - else - { - - return BadRequest(new error_mb { code = 400, message = "˻֤δͨ" }); - - } - - - } - @@ -482,29 +387,7 @@ namespace asg_form.Controllers - public void base64toimg(string base64,string path) - { - - // Ƴbase64ַͷdata URIʶ֣磺data:image/png;base64 - if (base64.Contains(",")) - base64 = base64.Split(',')[1]; - - byte[] imageBytes = Convert.FromBase64String(base64); - - using (MemoryStream ms = new MemoryStream(imageBytes)) - { - System.Drawing.Image image = System.Drawing.Image.FromStream(ms); - - // ñ·ļ - string savePath = path; - - // ļչͼʽ - image.Save(savePath); - } - - - } - + /// /// ϴlogo /// diff --git a/asg_form/Controllers/idvrole/RoleController.cs b/asg_form/Controllers/idvrole/RoleController.cs index 963ef4b..cc71829 100644 --- a/asg_form/Controllers/idvrole/RoleController.cs +++ b/asg_form/Controllers/idvrole/RoleController.cs @@ -2,7 +2,5 @@ namespace asg_form.Controllers.idvrole { - //帮我写一个刚刚那个角色数据库的增删改查类 - } diff --git a/asg_form/Controllers/login.cs b/asg_form/Controllers/login.cs index 3ac9a5d..5356615 100644 --- a/asg_form/Controllers/login.cs +++ b/asg_form/Controllers/login.cs @@ -22,6 +22,9 @@ using Manganese.Array; namespace asg_form.Controllers { + + + [ApiController] public class login : ControllerBase { @@ -262,7 +265,7 @@ namespace asg_form.Controllers } // 验证用户输入的验证码 - public bool ValidateCaptcha(string uid,string userInput) + public static bool ValidateCaptcha(string uid,string userInput) { using (var db = new TestDbContext()) { @@ -281,7 +284,7 @@ namespace asg_form.Controllers } } - public void moveOutTimeData(string uid) + public static void moveOutTimeData(string uid) { using (var db = new TestDbContext()) { diff --git a/asg_form/Controllers/menuAssignController.cs b/asg_form/Controllers/menuAssignController.cs index bba5151..63760fd 100644 --- a/asg_form/Controllers/menuAssignController.cs +++ b/asg_form/Controllers/menuAssignController.cs @@ -8,6 +8,9 @@ using static asg_form.Controllers.menuAssignController; namespace asg_form.Controllers { + + + [ApiController] public class menuAssignController : ControllerBase { public class menuDB diff --git a/asg_form/Controllers/new1.cs b/asg_form/Controllers/new1.cs index a636939..83b5176 100644 --- a/asg_form/Controllers/new1.cs +++ b/asg_form/Controllers/new1.cs @@ -8,6 +8,9 @@ using System.Collections.Generic; namespace asg_form.Controllers { + + + [ApiController] public class 查询是否重名 : ControllerBase { private readonly Logger _logger = LogManager.GetCurrentClassLogger(); diff --git a/asg_form/Controllers/news.cs b/asg_form/Controllers/news.cs index 0a92754..1bbd9b0 100644 --- a/asg_form/Controllers/news.cs +++ b/asg_form/Controllers/news.cs @@ -10,6 +10,9 @@ using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace asg_form.Controllers { + + + [ApiController] public class news : ControllerBase { diff --git a/asg_form/Controllers/schedule.cs b/asg_form/Controllers/schedule.cs index 59d7874..5dd5512 100644 --- a/asg_form/Controllers/schedule.cs +++ b/asg_form/Controllers/schedule.cs @@ -14,6 +14,9 @@ using Mirai.Net.Data.Shared; namespace asg_form.Controllers { + + + [ApiController] public class schedule:ControllerBase { private readonly RoleManager roleManager; @@ -206,7 +209,7 @@ namespace asg_form.Controllers } } - public byte[] GetPictureData(string imagePath) + public static byte[] GetPictureData(string imagePath) { FileStream fs = new FileStream(imagePath, FileMode.Open); byte[] byteData = new byte[fs.Length]; diff --git a/asg_form/Controllers/user_form.cs b/asg_form/Controllers/user_form.cs index bb25023..5ee4ff3 100644 --- a/asg_form/Controllers/user_form.cs +++ b/asg_form/Controllers/user_form.cs @@ -8,6 +8,9 @@ using static asg_form.blog; namespace asg_form.Controllers { + + + [ApiController] public class user_form : ControllerBase { private readonly RoleManager roleManager; diff --git a/asg_form/Controllers/webhook.cs b/asg_form/Controllers/webhook.cs index 2015093..303386b 100644 --- a/asg_form/Controllers/webhook.cs +++ b/asg_form/Controllers/webhook.cs @@ -15,6 +15,9 @@ namespace asg_form.Controllers { + + + [ApiController] public class WebsiteScreenshot { public static async Task CaptureWebsiteAsync(string url) diff --git a/asg_form/Program.cs b/asg_form/Program.cs index 0dd75db..65c92bf 100644 --- a/asg_form/Program.cs +++ b/asg_form/Program.cs @@ -5,7 +5,6 @@ using Flandre.Adapters.OneBot.Extensions; using Flandre.Framework; using IGeekFan.AspNetCore.Knife4jUI; using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; @@ -58,7 +57,7 @@ builder.Services.AddSwaggerGen(c => var path = Path.Combine(AppContext.BaseDirectory, file); c.IncludeXmlComments(path, true); c.OrderActionsBy(o => o.RelativePath); - + var scheme = new OpenApiSecurityScheme() { Description = "Authorization header. \r\nExample: 'Bearer 12345abcdef'", @@ -80,7 +79,7 @@ builder.Services.AddSwaggerGen(c => -string[] urls = new[] { "https://idvasg.cn", "https://nocdn.idvasg.cn", "http://localhost:8080" , "https://commentary.idvasg.cn", "https://admin.idvasg.cn", "https://www.idvasg.cn" }; +string[] urls = new[] { "https://idvasg.cn", "https://nocdn.idvasg.cn", "http://localhost:8080", "https://commentary.idvasg.cn", "https://admin.idvasg.cn", "https://www.idvasg.cn" }; builder.Services.AddCors(options => options.AddDefaultPolicy(builder => builder.WithOrigins(urls) .AllowAnyMethod().AllowAnyHeader().AllowCredentials())); @@ -159,12 +158,13 @@ var app = builder.Build(); app.UseCors(); // Configure the HTTP request pipeline. -app.MapScalarApiReference(); // scalar/v1 -app.MapOpenApi(); -app.UseKnife4UI(c => +app.UseSwagger(); +//app.UseSwaggerUI(); +app.MapScalarApiReference(options => { - c.RoutePrefix = string.Empty; - c.SwaggerEndpoint($"/swagger/v1/swagger.json", "h.swagger.webapi v1"); + options.WithOpenApiRoutePattern("/swagger/v1/swagger.json"); + // or + options.OpenApiRoutePattern = "/swagger/v1/swagger.json"; }); app.UseStaticFiles(); @@ -193,7 +193,7 @@ app.UseStaticFiles(new StaticFileOptions //发布时服务器注册静态资源 string fileUpload2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "doc"); if (!Directory.Exists(fileUpload2)) -{ Directory.CreateDirectory(fileUpload2+"/rule"); } +{ Directory.CreateDirectory(fileUpload2 + "/rule"); } app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(fileUpload2), @@ -244,7 +244,7 @@ new Thread(o => runbot.runbotr = app1.Bots.First(); app1.Run(); } - catch(Exception ex) + catch (Exception ex) { //输出详细全部信息 Console.WriteLine(ex.ToString()); @@ -252,7 +252,7 @@ new Thread(o => } - + }) diff --git a/asg_form/asg_form.csproj b/asg_form/asg_form.csproj index b570a3c..96f4309 100644 --- a/asg_form/asg_form.csproj +++ b/asg_form/asg_form.csproj @@ -1,5 +1,4 @@  - net9.0 enable @@ -14,67 +13,57 @@ True mcr.microsoft.com/dotnet/aspnet:8.0 - True - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - PreserveNewest - - + \ No newline at end of file