fix 增加image记录,移除balance负数处理
This commit is contained in:
@@ -25,10 +25,5 @@ public class MealSupplementInitImportRequest : IValidatableObject
|
||||
{
|
||||
yield return new ValidationResult($"工号{Code}姓名不能为空", new[] { nameof(Name) });
|
||||
}
|
||||
|
||||
if (Balance <= 0)
|
||||
{
|
||||
yield return new ValidationResult($"工号{Code}余额有误", new[] { nameof(Balance) });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,4 +25,9 @@ public class BalanceRecordPageByDeviceUniqueNoRequest : PageDto
|
||||
/// 查询时间段(结束)
|
||||
/// </summary>
|
||||
public DateTime? End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工号
|
||||
/// </summary>
|
||||
public string UserCode { get; set; }
|
||||
}
|
||||
@@ -101,4 +101,9 @@ public class BalanceRecordDeviceResponse
|
||||
/// 厂区名称
|
||||
/// </summary>
|
||||
public string TenantName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// image
|
||||
/// </summary>
|
||||
public string Image { get; set; }
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Dlhis.Canteen.Setting.Services;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Dlhis.Entity.Device;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Sys.Api;
|
||||
@@ -137,11 +138,13 @@ public class BalanceService : IBalanceService
|
||||
.LeftJoin<GainfoEntity>((record, ga) => record.UserNo == ga.No)
|
||||
.LeftJoin<DepartmentEntity>((record, ga, department) => ga.DepartmentNo == department.No)
|
||||
.LeftJoin<BusinessPlaceEntity>((record, ga, department, bPlace) => record.BusinessPlaceCode == bPlace.Code)
|
||||
.LeftJoin<ImageRecordEntity>((record, ga, department, bPlace, imageRecord) => imageRecord.No == record.No)
|
||||
.WhereIF(request.UserCode.IsPresent(), record => record.UserCode == request.UserCode)
|
||||
.Where(record => record.CostDate >= request.Start && record.CostDate <= request.End)
|
||||
.Where(record => record.DeviceUniqueNo == device.UniqueNo || record.DeviceUniqueNo == device.Code.ToString())
|
||||
.Where(record => record.Type == BalanceRecordTypeEnumType.Out && record.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.OrderBy(record => record.CreateTime, OrderByType.Desc)
|
||||
.Select((record, ga, department, bPlace) => new BalanceRecordDeviceResponse
|
||||
.Select((record, ga, department, bPlace, imageRecord) => new BalanceRecordDeviceResponse
|
||||
{
|
||||
Id = record.Id,
|
||||
Amount = SqlFunc.Abs(record.Amount),
|
||||
@@ -159,6 +162,7 @@ public class BalanceService : IBalanceService
|
||||
ShiftType = record.ShiftType,
|
||||
CostDateTime = record.CostDateTime,
|
||||
TenantId = record.TenantId,
|
||||
Image = imageRecord.Image
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
|
||||
@@ -225,6 +229,7 @@ public class BalanceService : IBalanceService
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
|
||||
|
||||
@@ -631,7 +636,7 @@ public class BalanceService : IBalanceService
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var OnlineDevices = deviceRegistries
|
||||
var onlineDevices = deviceRegistries
|
||||
.Where(x =>
|
||||
{
|
||||
if (x.HeartbeatInterval <= 0)
|
||||
@@ -647,7 +652,7 @@ public class BalanceService : IBalanceService
|
||||
})
|
||||
.ToList();
|
||||
var onlineUniqueNos = new List<string>();
|
||||
OnlineDevices.ForEach(x => onlineUniqueNos.Add(x.UniqueNo));
|
||||
onlineDevices.ForEach(x => onlineUniqueNos.Add(x.UniqueNo));
|
||||
|
||||
var offUniqueNos = deviceUniqueNos.Except(onlineUniqueNos).ToList();
|
||||
var list = devices.Where(x => offUniqueNos.Contains(x.UniqueNo)).ToList();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Data;
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Canteen.Setting.Services;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
@@ -600,40 +599,40 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
|
||||
var allowNoBalance = await GetSettingAsync<bool>(order.TenantId, CanteenSettingItemEnumType.AllowNoBalance);
|
||||
|
||||
//降级到读已提交
|
||||
await DbContext.Client.Ado.BeginTranAsync(IsolationLevel.ReadCommitted);
|
||||
try
|
||||
////降级到读已提交
|
||||
// await DbContext.Client.Ado.BeginTranAsync(IsolationLevel.ReadCommitted);
|
||||
// try
|
||||
// {
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
if (!allowNoBalance)
|
||||
{
|
||||
if (!allowNoBalance)
|
||||
{
|
||||
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).SingleAsync();
|
||||
//金额+-
|
||||
gainfoMeal.Balance += order.Amount;
|
||||
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).SingleAsync();
|
||||
//金额+-
|
||||
gainfoMeal.Balance += order.Amount;
|
||||
|
||||
(gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||
(gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||
|
||||
await DbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == gainfoMeal.Balance)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}
|
||||
await DbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == gainfoMeal.Balance)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}
|
||||
|
||||
//写入记录
|
||||
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||
await DbContext.InsertAsync(balanceRecord);
|
||||
}, 5);
|
||||
//写入记录
|
||||
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||
await DbContext.InsertAsync(balanceRecord);
|
||||
}, 5);
|
||||
|
||||
await DbContext.Client.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await DbContext.Client.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
// await DbContext.Client.Ado.CommitTranAsync();
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// await DbContext.Client.Ado.RollbackTranAsync();
|
||||
// throw;
|
||||
// }
|
||||
}
|
||||
|
||||
public async Task ReCalcOfflineAsync(ReCalcOfflineRequest request)
|
||||
|
||||
Reference in New Issue
Block a user