feat 钱包和钱包余额查询
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
50
Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs
Normal file
50
Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
19
Src/Dlhis.Canteen/Setting/Response/WalletResponse.cs
Normal file
19
Src/Dlhis.Canteen/Setting/Response/WalletResponse.cs
Normal 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; }
|
||||
}
|
||||
8
Src/Dlhis.Canteen/Setting/Services/IWalletService.cs
Normal file
8
Src/Dlhis.Canteen/Setting/Services/IWalletService.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Dlhis.Canteen.Setting.Response;
|
||||
|
||||
namespace Dlhis.Canteen.Setting.Services;
|
||||
|
||||
public interface IWalletService : IScopeDependency
|
||||
{
|
||||
Task<List<WalletResponse>> GetListAsync();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,6 @@ public class WalletEntity : SugarBaseEntity
|
||||
/// <summary>
|
||||
/// 厂区
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "idx_wallets_facotry" })]
|
||||
[SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "idx_wallets_factry" })]
|
||||
public string Factory { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user