45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using Dlhis.Canteen.Order.Repository;
|
|
using Dlhis.Canteen.Setting.Response;
|
|
using Dlhis.Entity.Canteen.Entities;
|
|
using Kurisu.AspNetCore.Authentication.Abstractions;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
|
using SqlSugar;
|
|
|
|
namespace Dlhis.Canteen.Setting.Services.Implements;
|
|
|
|
public class WalletService : IWalletService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
private readonly ICurrentUser _currentUser;
|
|
private readonly IBalanceRepository _balanceRepository;
|
|
|
|
public WalletService(IDbContext dbContext, ICurrentUser currentUser, IBalanceRepository balanceRepository)
|
|
{
|
|
_dbContext = dbContext;
|
|
_currentUser = currentUser;
|
|
_balanceRepository = balanceRepository;
|
|
}
|
|
|
|
/// <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();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<decimal> GetBalanceAsync(string walletCode)
|
|
{
|
|
var userCode = _currentUser.GetUserClaim("jinko-code");
|
|
var factory = await _dbContext.Queryable<WalletEntity>().Where(x => x.Code == walletCode).Select(x => x.Factory).FirstAsync();
|
|
|
|
return await _balanceRepository.GetBalanceAsync(userCode, factory);
|
|
}
|
|
} |