46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
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 IBalanceService _balanceService;
|
|
|
|
public MiddleService(IDbContext dbContext, IBalanceService balanceService)
|
|
{
|
|
_dbContext = dbContext;
|
|
_balanceService = balanceService;
|
|
}
|
|
|
|
/// <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 _balanceService.ReCalcAsync(entity.UserCode);
|
|
}
|
|
|
|
//获取人员余额
|
|
return await _dbContext.Queryable<GainfoMealEntity>()
|
|
.LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
|
|
.LeftJoin<DepartmentEntity>((x, ga, department) => ga.DepartmentNo == department.No)
|
|
.Where(x => x.UserNo == entity.UserNo)
|
|
.Select((x, ga, department) => new OrderResultResponse
|
|
{
|
|
UserCode = ga.Code,
|
|
UserName = ga.Name,
|
|
DepartmentNo = ga.DepartmentNo,
|
|
DepartmentName = department.Name,
|
|
CurrentBalance = x.Balance
|
|
})
|
|
.SingleAsync();
|
|
}
|
|
} |