From 74912c2efc0a68663e5b9c54d76ec7538b2177a8 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 12 Nov 2024 16:08:49 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E9=92=B1=E5=8C=85=E5=92=8C=E9=92=B1?= =?UTF-8?q?=E5=8C=85=E4=BD=99=E9=A2=9D=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Controllers/BalancesController.cs | 7 +-- .../Setting/Controllers/WalletsController.cs | 50 +++++++++++++++++++ .../Setting/Response/WalletResponse.cs | 19 +++++++ .../Setting/Services/IWalletService.cs | 8 +++ .../Services/Implements/WalletService.cs | 30 +++++++++++ .../Canteen/Entities/WalletEntity.cs | 2 +- 6 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs create mode 100644 Src/Dlhis.Canteen/Setting/Response/WalletResponse.cs create mode 100644 Src/Dlhis.Canteen/Setting/Services/IWalletService.cs create mode 100644 Src/Dlhis.Canteen/Setting/Services/Implements/WalletService.cs diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index baa4deb1..00b9eae8 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -1,16 +1,11 @@ -using System.ComponentModel.DataAnnotations; -using System.Data; +using System.Data; using Dlhis.Canteen.Order.Request; using Dlhis.Canteen.Order.Response; using Dlhis.Canteen.Order.Services; -using Dlhis.Entity.Canteen.Entities; -using Kurisu.AspNetCore; using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; -using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using SqlSugar; namespace Dlhis.Canteen.Order.Controllers; diff --git a/Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs b/Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs new file mode 100644 index 00000000..2bcbf0dc --- /dev/null +++ b/Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs @@ -0,0 +1,50 @@ +using Dlhis.Canteen.Order.Repository; +using Dlhis.Canteen.Setting.Response; +using Dlhis.Canteen.Setting.Services; +using Kurisu.AspNetCore.Authentication.Abstractions; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.Canteen.Setting.Controllers; + +/// +/// 钱包 +/// +[Authorize] +[Route("api/[controller]")] +[ApiController] +public class WalletsController : ControllerBase +{ + private readonly IWalletService _walletService; + private readonly IBalanceRepository _balanceRepository; + private readonly ICurrentUser _currentUser; + + public WalletsController(IWalletService walletService, IBalanceRepository balanceRepository, ICurrentUser currentUser) + { + _walletService = walletService; + _balanceRepository = balanceRepository; + _currentUser = currentUser; + } + + /// + /// 钱包列表 + /// + /// + [HttpGet("list")] + public async Task> GetListAsync() + { + return await _walletService.GetListAsync(); + } + + /// + /// 余额 + /// + /// + /// + [HttpGet("balance")] + public async Task GetBalanceAsync(string factory) + { + var code = _currentUser.GetUserClaim("jinko-code"); + return await _balanceRepository.GetBalanceAsync(code, factory); + } +} \ No newline at end of file diff --git a/Src/Dlhis.Canteen/Setting/Response/WalletResponse.cs b/Src/Dlhis.Canteen/Setting/Response/WalletResponse.cs new file mode 100644 index 00000000..6e4879a3 --- /dev/null +++ b/Src/Dlhis.Canteen/Setting/Response/WalletResponse.cs @@ -0,0 +1,19 @@ +namespace Dlhis.Canteen.Setting.Response; + +public class WalletResponse +{ + /// + /// 钱包编码 + /// + public string Code { get; set; } + + /// + /// 钱包名称 + /// + public string Name { get; set; } + + /// + /// 厂区 + /// + public List Factories { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Canteen/Setting/Services/IWalletService.cs b/Src/Dlhis.Canteen/Setting/Services/IWalletService.cs new file mode 100644 index 00000000..614c7c1f --- /dev/null +++ b/Src/Dlhis.Canteen/Setting/Services/IWalletService.cs @@ -0,0 +1,8 @@ +using Dlhis.Canteen.Setting.Response; + +namespace Dlhis.Canteen.Setting.Services; + +public interface IWalletService : IScopeDependency +{ + Task> GetListAsync(); +} \ No newline at end of file diff --git a/Src/Dlhis.Canteen/Setting/Services/Implements/WalletService.cs b/Src/Dlhis.Canteen/Setting/Services/Implements/WalletService.cs new file mode 100644 index 00000000..819cfabe --- /dev/null +++ b/Src/Dlhis.Canteen/Setting/Services/Implements/WalletService.cs @@ -0,0 +1,30 @@ +using Dlhis.Canteen.Setting.Response; +using Dlhis.Entity.Canteen.Entities; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; +using SqlSugar; + +namespace Dlhis.Canteen.Setting.Services.Implements; + +public class WalletService : IWalletService +{ + private readonly IDbContext _dbContext; + + public WalletService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + /// + public async Task> GetListAsync() + { + return await _dbContext.Queryable() + .GroupBy(x => new { x.Code, x.Name }) + .Select(x => new WalletResponse + { + Code = x.Code, + Name = x.Name, + Factories = SqlFunc.Subqueryable().Where(p => p.Code == x.Code).ToList(p => p.Factory) + }) + .ToListAsync(); + } +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Canteen/Entities/WalletEntity.cs b/Src/Dlhis.Entity/Canteen/Entities/WalletEntity.cs index 8f698195..f396b88a 100644 --- a/Src/Dlhis.Entity/Canteen/Entities/WalletEntity.cs +++ b/Src/Dlhis.Entity/Canteen/Entities/WalletEntity.cs @@ -24,6 +24,6 @@ public class WalletEntity : SugarBaseEntity /// /// 厂区 /// - [SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "idx_wallets_facotry" })] + [SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "idx_wallets_factry" })] public string Factory { get; set; } } \ No newline at end of file