fix 尝试清洗数据
This commit is contained in:
@@ -46,6 +46,13 @@ public class OrdersController : ControllerBase
|
||||
await _orderService.ReCalcOfflineAsync(request);
|
||||
}
|
||||
|
||||
[IgnoreTenant]
|
||||
[HttpPost("UpdateOffline")]
|
||||
public async Task UpdateOffline(UpdateOfflineRequest outRequest)
|
||||
{
|
||||
await _orderService.UpdateOffline(outRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设备发起订单
|
||||
/// </summary>
|
||||
|
||||
@@ -50,8 +50,7 @@ public class OrderAddRequest : IValidatableObject
|
||||
//处理金额
|
||||
Amount = -Math.Abs(Amount);
|
||||
|
||||
//在线就以API时间为准
|
||||
if (!IsOffline)
|
||||
if (!CostDateTime.HasValue)
|
||||
{
|
||||
CostDateTime = DateTime.Now;
|
||||
}
|
||||
|
||||
7
Src/Dlhis.Canteen/Order/Request/UpdateOfflineRequest.cs
Normal file
7
Src/Dlhis.Canteen/Order/Request/UpdateOfflineRequest.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Dlhis.Canteen.Order.Request
|
||||
{
|
||||
public class UpdateOfflineRequest
|
||||
{
|
||||
public string No { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ public interface IOrderService : IScopeDependency
|
||||
|
||||
Task ReCalcOfflineAsync(ReCalcOfflineRequest request);
|
||||
|
||||
Task UpdateOffline(UpdateOfflineRequest outRequest);
|
||||
|
||||
/// <summary>
|
||||
/// 设备消费
|
||||
/// </summary>
|
||||
|
||||
@@ -184,12 +184,6 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
|
||||
var switchTime = await GetSettingAsync<TimeOnly?>(businessPlaceInfo.TenantId, CanteenSettingItemEnumType.BusinessSwitchTime);
|
||||
|
||||
var shiftTimePeriod = new TimePeriod()
|
||||
{
|
||||
Start = shift?.Start,
|
||||
End = shift?.End
|
||||
};
|
||||
|
||||
//计算成本日期 todo 优化
|
||||
var costDate = DateTime.Now;
|
||||
if (shift == null)
|
||||
@@ -235,7 +229,6 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
OriginTenantId = gainfo.Factory,
|
||||
Werks = gainfo.Werks,
|
||||
|
||||
//餐别异常处理
|
||||
Status = BalanceRecordStatusEnumType.Valid,
|
||||
|
||||
OrderStatus = CanteenOrderStatusEnumType.Success,
|
||||
@@ -475,6 +468,88 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
}
|
||||
|
||||
|
||||
public async Task UpdateOffline(UpdateOfflineRequest outRequest)
|
||||
{
|
||||
var orders = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.IsOffline)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.Where(x => x.OrderStatus == CanteenOrderStatusEnumType.Success)
|
||||
.Where(x => x.ApplicationType == CanteenApplicaitonTypeEnumType.Device)
|
||||
.WhereIF(outRequest.No.IsPresent(), x => x.No == outRequest.No)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var item in orders)
|
||||
{
|
||||
var request = item.RequestJson.ToObject<ConsumeRequest>();
|
||||
var device = await DbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.UniqueNo == request.DeviceUniqueNo)
|
||||
.FirstAsync();
|
||||
|
||||
var registry = await DbContext.Queryable<DeviceRegistryEntity>()
|
||||
.Where(x => x.DeviceUniqueNo == request.DeviceUniqueNo)
|
||||
.FirstAsync();
|
||||
|
||||
var businessPlaceInfo = await DbContext.Queryable<BusinessPlaceEntity>()
|
||||
.LeftJoin<BusinessPlaceShiftRelationshipEntity>((x, sr) => x.Code == sr.PlaceCode)
|
||||
.Where(x => x.Code == registry.BusinessPlaceCode)
|
||||
.Select((x, sr) => new
|
||||
{
|
||||
x.Code,
|
||||
sr.ShiftCode,
|
||||
x.TenantId
|
||||
})
|
||||
.FirstAsync();
|
||||
|
||||
|
||||
//获取当前消费餐次
|
||||
var shifts = await DbContext.Queryable<BusinessShiftMealRelationshipEntity>().Where(x => x.ShiftCode == businessPlaceInfo.ShiftCode).ToListAsync();
|
||||
|
||||
var shift = shifts.FirstOrDefault(x => new TimePeriod()
|
||||
{
|
||||
Start = x.Start,
|
||||
End = x.End
|
||||
|
||||
}.IsPresent1(request.CostDateTime));
|
||||
|
||||
var switchTime = await GetSettingAsync<TimeOnly?>(businessPlaceInfo.TenantId, CanteenSettingItemEnumType.BusinessSwitchTime);
|
||||
|
||||
//计算成本日期 todo 优化
|
||||
var costDate = DateTime.Now;
|
||||
if (shift == null)
|
||||
{
|
||||
costDate = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (switchTime.HasValue)
|
||||
{
|
||||
var beginOfDay = DateTime.Today;
|
||||
|
||||
var setTime = beginOfDay.Add(switchTime.Value.ToTimeSpan());
|
||||
if (DateTime.Now < setTime)
|
||||
costDate = DateTime.Now.AddDays(-1);
|
||||
}
|
||||
}
|
||||
|
||||
var shiftType = shift?.ShiftType;
|
||||
|
||||
await DbContext.Updateable<CanteenOrderEntity>()
|
||||
.SetColumns(x => x.BusinessShiftCode == businessPlaceInfo.ShiftCode)
|
||||
.SetColumns(x => x.CostDate == costDate)
|
||||
.SetColumns(x => x.CostDateTime == request.CostDateTime)
|
||||
.SetColumns(x => x.ShiftType == shiftType)
|
||||
.Where(x => x.No == item.No)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
await DbContext.Updateable<BalanceRecordEntity>()
|
||||
.SetColumns(x => x.BusinessShiftCode == businessPlaceInfo.ShiftCode)
|
||||
.SetColumns(x => x.CostDate == costDate)
|
||||
.SetColumns(x => x.CostDateTime == request.CostDateTime)
|
||||
.SetColumns(x => x.ShiftType == shiftType)
|
||||
.Where(x => x.No == item.No)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
//******************************************************* help methods ************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -16,26 +16,25 @@ public static class TimePeriodExtensions
|
||||
if (period.IsCrossDay())
|
||||
{
|
||||
//period = [22:00:00,03:00:00]
|
||||
var currentStart = DateTime.Today.Add(period.Start.Value.ToTimeSpan());
|
||||
var endOfDay = DateTime.Today.AddDays(1).AddSeconds(-1);
|
||||
var currentStart = dateTime.Date.Add(period.Start.Value.ToTimeSpan());
|
||||
var endOfDay = dateTime.Date.AddDays(1).AddSeconds(-1);
|
||||
|
||||
//assume is left range . then currentStart is 2024-04-16 22:00:00 and endOfDay is 2024-04-16 23:59:59
|
||||
if (dateTime >= currentStart && dateTime <= endOfDay)
|
||||
{
|
||||
start = currentStart; //2024-04-16 22:00:00
|
||||
end = DateTime.Today.AddDays(1).Add(period.End.Value.ToTimeSpan());//2024-04-17 03:00:00
|
||||
end = dateTime.Date.AddDays(1).Add(period.End.Value.ToTimeSpan());//2024-04-17 03:00:00
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
start = DateTime.Today.AddDays(-1).Add(period.Start.Value.ToTimeSpan());
|
||||
end = DateTime.Today.Add(period.End.Value.ToTimeSpan());
|
||||
start = dateTime.Date.AddDays(-1).Add(period.Start.Value.ToTimeSpan());
|
||||
end = dateTime.Date.Add(period.End.Value.ToTimeSpan());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
start = DateTime.Today.Add(period.Start.Value.ToTimeSpan());
|
||||
end = DateTime.Today.Add(period.End.Value.ToTimeSpan());
|
||||
start = dateTime.Date.Add(period.Start.Value.ToTimeSpan());
|
||||
end = dateTime.Date.Add(period.End.Value.ToTimeSpan());
|
||||
}
|
||||
|
||||
return dateTime >= start && dateTime <= end;
|
||||
|
||||
Reference in New Issue
Block a user