48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using Dlhis.Canteen.Order.Repository;
|
|
using Dlhis.Canteen.Order.Response;
|
|
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Canteen.Entities;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
|
|
|
namespace Dlhis.Canteen.Order.Services.Implements;
|
|
|
|
public class MiddleService : IMiddleService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
private readonly IBalanceRepository _balanceRepository;
|
|
|
|
public MiddleService(IDbContext dbContext, IBalanceRepository balanceRepository)
|
|
{
|
|
_dbContext = dbContext;
|
|
_balanceRepository = balanceRepository;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<OrderResultResponse> MiddleUploadAsync(BalanceRecordEntity entity)
|
|
{
|
|
entity.Id = 0;
|
|
entity.Amount = -Math.Abs(entity.Amount);
|
|
entity.Remark = "离线消费提交";
|
|
if (!await _dbContext.Queryable<BalanceRecordEntity>().AnyAsync(x => x.No == entity.No))
|
|
{
|
|
await _dbContext.InsertAsync(entity);
|
|
await _balanceRepository.CalculateBalanceAsync(entity.UserCode);
|
|
}
|
|
|
|
var balance = await _balanceRepository.GetBalanceAsync(entity.UserCode);
|
|
|
|
//获取人员余额
|
|
return await _dbContext.Queryable<GainfoEntity>()
|
|
.LeftJoin<DepartmentEntity>((x, department) => x.DepartmentNo == department.No)
|
|
.Where(x => x.Code == entity.UserCode)
|
|
.Select((x, department) => new OrderResultResponse
|
|
{
|
|
UserCode = x.Code,
|
|
UserName = x.Name,
|
|
DepartmentNo = x.DepartmentNo,
|
|
DepartmentName = department.Name,
|
|
CurrentBalance = balance
|
|
})
|
|
.SingleAsync();
|
|
}
|
|
} |