From 372b2760ce5d20150a10b99ab04146aab54acc8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=82=9C=E7=BF=94?= <2307953404@qq.com> Date: Fri, 4 Oct 2024 21:23:38 +0800 Subject: [PATCH] 123 --- .../Controllers/Budget/BgCountController.cs | 41 +++++++++++++++++++ asg_form/Controllers/Champion.cs | 2 +- asg_form/Controllers/Dbset.cs | 3 ++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/asg_form/Controllers/Budget/BgCountController.cs b/asg_form/Controllers/Budget/BgCountController.cs index 65c6398..6ab19e0 100644 --- a/asg_form/Controllers/Budget/BgCountController.cs +++ b/asg_form/Controllers/Budget/BgCountController.cs @@ -196,5 +196,46 @@ namespace asg_form.Controllers.Budget public int UsePersonId { get; set; } } + [Route("api/v1/admin/countBudgetTotal")] + [HttpGet] + [Authorize] + public async Task> cntBg(int sourceEventId) + { + if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) + { + return Ok(new { code = 401, message = "您没有权限" }); + } + + try + { + using (var db = new TestDbContext()) + { + var budgetTotals = await db.budgetDetails + .Where(b => b.source_event_id == sourceEventId) + .GroupBy(b => new + { + b.source_event_id, + b.source_event_name + }) + .Select(g => new + { + sourceEventId = g.Key.source_event_id, + sourceEventName = g.Key.source_event_name, + budgetTotalMoney = g.Sum(b => b.budget_money) + }) + .ToListAsync(); + return Ok(new + { + code = 200, + data = budgetTotals + }); + } + } + catch (Exception ex) + { + return Ok(new { code = 500, message = "服务器错误", details = ex.Message }); + } + } + } } diff --git a/asg_form/Controllers/Champion.cs b/asg_form/Controllers/Champion.cs index c01afe4..6a81e6b 100644 --- a/asg_form/Controllers/Champion.cs +++ b/asg_form/Controllers/Champion.cs @@ -75,7 +75,7 @@ namespace asg_form.Controllers } } - return BadRequest(new error_mb { code = 400, message = "你没有管理员呢~" }); + return Ok(new error_mb { code = 400, message = "你没有管理员呢~" }); } /// diff --git a/asg_form/Controllers/Dbset.cs b/asg_form/Controllers/Dbset.cs index 56e54e2..b47fb98 100644 --- a/asg_form/Controllers/Dbset.cs +++ b/asg_form/Controllers/Dbset.cs @@ -11,6 +11,7 @@ using Microsoft.EntityFrameworkCore.DataEncryption.Providers; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System.Security.Cryptography; using System.Text; +using static asg_form.Controllers.Budget.BgCountController; namespace asg_form.Controllers { @@ -243,6 +244,8 @@ namespace asg_form.Controllers public DbSet T_Comform { get; set; } public DbSet budgetDetails { get; set; } + public DbSet totBg { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { string connStr = @"Host=localhost;Port=2345;Database=asg;Username=postgres;Password=luolan12323;";