fix log
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
using Dlhis.Entity.Basic.Entity;
|
using System.Diagnostics;
|
||||||
using Dlhis.Entity.Canteen.Entities;
|
|
||||||
using Dlhis.Entity.Canteen.Enums;
|
using Dlhis.Entity.Canteen.Enums;
|
||||||
using Dlhis.Entity.Device.Entities;
|
|
||||||
using Dlhis.Middle.Entities;
|
using Dlhis.Middle.Entities;
|
||||||
using Kurisu.AspNetCore.Utils;
|
using Kurisu.AspNetCore.Utils;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
@@ -19,6 +17,7 @@ public class OrderService : IOrderService
|
|||||||
{
|
{
|
||||||
private readonly ICanteenSettingService _canteenSettingService;
|
private readonly ICanteenSettingService _canteenSettingService;
|
||||||
private readonly IRemoteOrderService _remoteOrderService;
|
private readonly IRemoteOrderService _remoteOrderService;
|
||||||
|
private readonly ILogger<OrderService> _logger;
|
||||||
private readonly string _factory;
|
private readonly string _factory;
|
||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
private Dictionary<CanteenSettingItemEnumType, string> _settings;
|
private Dictionary<CanteenSettingItemEnumType, string> _settings;
|
||||||
@@ -26,78 +25,89 @@ public class OrderService : IOrderService
|
|||||||
public OrderService(ICanteenSettingService canteenSettingService,
|
public OrderService(ICanteenSettingService canteenSettingService,
|
||||||
IRemoteOrderService remoteOrderService,
|
IRemoteOrderService remoteOrderService,
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
|
ILogger<OrderService> logger,
|
||||||
IDbContext dbContext)
|
IDbContext dbContext)
|
||||||
{
|
{
|
||||||
_canteenSettingService = canteenSettingService;
|
_canteenSettingService = canteenSettingService;
|
||||||
_remoteOrderService = remoteOrderService;
|
_remoteOrderService = remoteOrderService;
|
||||||
|
_logger = logger;
|
||||||
_factory = configuration.GetSection("Factory").Value;
|
_factory = configuration.GetSection("Factory").Value;
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DefaultApiResult<OrderResultResponse>> AddAsync(OrderAddRequest request)
|
public async Task<DefaultApiResult<OrderResultResponse>> AddAsync(OrderAddRequest request)
|
||||||
{
|
{
|
||||||
if (await _remoteOrderService.AbleRemoteCallAsync())
|
var sw = Stopwatch.StartNew();
|
||||||
{
|
|
||||||
var remoteResult = await _remoteOrderService.AddAsync(request);
|
|
||||||
if (remoteResult.Code == ApiStateCode.Success)
|
|
||||||
{
|
|
||||||
var d = remoteResult.Data;
|
|
||||||
await _dbContext.Updateable<LocalGainfoMealEntity>()
|
|
||||||
.SetColumns(x => x.Balance == d.Balance)
|
|
||||||
.Where(x => x.UserCode == d.UserCode)
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
remoteResult.Msg = "在线消费:" + remoteResult.Msg;
|
|
||||||
|
|
||||||
return remoteResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
//根据档案号
|
|
||||||
var gainfo = await _dbContext.Queryable<LocalGainfoEntity>()
|
|
||||||
.Where(x => x.Code == request.UserUniqueNo || x.CardNo == request.UserUniqueNo)
|
|
||||||
.FirstAsync();
|
|
||||||
|
|
||||||
var message = "离线消费:";
|
|
||||||
|
|
||||||
gainfo.ThrowIfNull("无消费权限");
|
|
||||||
|
|
||||||
var isError = false;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
(await _dbContext.Queryable<LocalGainfoMealEntity>().Where(x => x.UserNo == gainfo.No).AnyAsync())
|
if (await _remoteOrderService.AbleRemoteCallAsync())
|
||||||
.ThrowIfFalse("余额不足,无法消费");
|
|
||||||
|
|
||||||
await ConsumeAsync(request.Adapt<ConsumeRequest>(), gainfo);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
message += ex.Message;
|
|
||||||
isError = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//获取人员余额
|
|
||||||
var data = await _dbContext.Queryable<LocalGainfoEntity>()
|
|
||||||
.LeftJoin<LocalDepartmentEntity>((ga, department) => ga.DepartmentNo == department.No)
|
|
||||||
.LeftJoin<LocalGainfoMealEntity>((ga, department, mealUser) => ga.No == mealUser.UserNo)
|
|
||||||
.Where(ga => ga.Id == gainfo.Id)
|
|
||||||
.Select((ga, department, mealUser) => new OrderResultResponse
|
|
||||||
{
|
{
|
||||||
UserCode = ga.Code,
|
var remoteResult = await _remoteOrderService.AddAsync(request);
|
||||||
UserName = ga.Name,
|
if (remoteResult.Code == ApiStateCode.Success)
|
||||||
DepartmentNo = ga.DepartmentNo,
|
{
|
||||||
DepartmentName = department.Name,
|
var d = remoteResult.Data;
|
||||||
Balance = mealUser.Balance
|
await _dbContext.Updateable<LocalGainfoMealEntity>()
|
||||||
})
|
.SetColumns(x => x.Balance == d.Balance)
|
||||||
.SingleAsync();
|
.Where(x => x.UserCode == d.UserCode)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
|
||||||
return new DefaultApiResult<OrderResultResponse>
|
remoteResult.Msg = "在线消费:" + remoteResult.Msg;
|
||||||
|
|
||||||
|
return remoteResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据档案号
|
||||||
|
var gainfo = await _dbContext.Queryable<LocalGainfoEntity>()
|
||||||
|
.Where(x => x.Code == request.UserUniqueNo || x.CardNo == request.UserUniqueNo)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
var message = "离线消费:";
|
||||||
|
|
||||||
|
gainfo.ThrowIfNull("无消费权限");
|
||||||
|
|
||||||
|
var isError = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
(await _dbContext.Queryable<LocalGainfoMealEntity>().Where(x => x.UserNo == gainfo.No).AnyAsync())
|
||||||
|
.ThrowIfFalse("余额不足,无法消费");
|
||||||
|
|
||||||
|
await ConsumeAsync(request.Adapt<ConsumeRequest>(), gainfo);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
message += ex.Message;
|
||||||
|
isError = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//获取人员余额
|
||||||
|
var data = await _dbContext.Queryable<LocalGainfoEntity>()
|
||||||
|
.LeftJoin<LocalDepartmentEntity>((ga, department) => ga.DepartmentNo == department.No)
|
||||||
|
.LeftJoin<LocalGainfoMealEntity>((ga, department, mealUser) => ga.No == mealUser.UserNo)
|
||||||
|
.Where(ga => ga.Id == gainfo.Id)
|
||||||
|
.Select((ga, department, mealUser) => new OrderResultResponse
|
||||||
|
{
|
||||||
|
UserCode = ga.Code,
|
||||||
|
UserName = ga.Name,
|
||||||
|
DepartmentNo = ga.DepartmentNo,
|
||||||
|
DepartmentName = department.Name,
|
||||||
|
Balance = mealUser.Balance
|
||||||
|
})
|
||||||
|
.SingleAsync();
|
||||||
|
|
||||||
|
return new DefaultApiResult<OrderResultResponse>
|
||||||
|
{
|
||||||
|
Code = isError ? ApiStateCode.Error : ApiStateCode.Success,
|
||||||
|
Data = data,
|
||||||
|
Msg = message
|
||||||
|
};
|
||||||
|
}
|
||||||
|
finally
|
||||||
{
|
{
|
||||||
Code = isError ? ApiStateCode.Error : ApiStateCode.Success,
|
_logger.LogInformation("消费请求:{json}. 耗时:{time}", request.ToJson(), sw.ElapsedMilliseconds);
|
||||||
Data = data,
|
}
|
||||||
Msg = message
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user