feat 钱包和钱包余额查询

This commit is contained in:
2024-11-12 16:08:49 +08:00
parent 1a0ba28249
commit 74912c2efc
6 changed files with 109 additions and 7 deletions

View File

@@ -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;

View File

@@ -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;
/// <summary>
/// 钱包
/// </summary>
[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;
}
/// <summary>
/// 钱包列表
/// </summary>
/// <returns></returns>
[HttpGet("list")]
public async Task<List<WalletResponse>> GetListAsync()
{
return await _walletService.GetListAsync();
}
/// <summary>
/// 余额
/// </summary>
/// <param name="factory"></param>
/// <returns></returns>
[HttpGet("balance")]
public async Task<decimal> GetBalanceAsync(string factory)
{
var code = _currentUser.GetUserClaim("jinko-code");
return await _balanceRepository.GetBalanceAsync(code, factory);
}
}

View File

@@ -0,0 +1,19 @@
namespace Dlhis.Canteen.Setting.Response;
public class WalletResponse
{
/// <summary>
/// 钱包编码
/// </summary>
public string Code { get; set; }
/// <summary>
/// 钱包名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 厂区
/// </summary>
public List<string> Factories { get; set; }
}

View File

@@ -0,0 +1,8 @@
using Dlhis.Canteen.Setting.Response;
namespace Dlhis.Canteen.Setting.Services;
public interface IWalletService : IScopeDependency
{
Task<List<WalletResponse>> GetListAsync();
}

View File

@@ -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;
}
/// <inheritdoc />
public async Task<List<WalletResponse>> GetListAsync()
{
return await _dbContext.Queryable<WalletEntity>()
.GroupBy(x => new { x.Code, x.Name })
.Select(x => new WalletResponse
{
Code = x.Code,
Name = x.Name,
Factories = SqlFunc.Subqueryable<WalletEntity>().Where(p => p.Code == x.Code).ToList(p => p.Factory)
})
.ToListAsync();
}
}