fix 优化代码
This commit is contained in:
@@ -27,7 +27,7 @@ public class DeviceSaveRequest : IValidatableObject
|
||||
public string Supplier { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备功能
|
||||
/// 设备功能 DeviceFuncEnumType
|
||||
/// </summary>
|
||||
[MinLength(1, ErrorMessage = "设备功能不能为空")]
|
||||
[Required(ErrorMessage = "设备功能不能为空")]
|
||||
|
||||
@@ -182,25 +182,7 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
|
||||
}.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 costDate = await GetCostDateAsync(shift, request.CostDateTime);
|
||||
|
||||
var order = new CanteenOrderEntity
|
||||
{
|
||||
@@ -334,25 +316,7 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
}.IsPresent1(request.CostDateTime));
|
||||
shift.ThrowIfNull("非就餐时间,无法消费");
|
||||
|
||||
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 costDate = await GetCostDateAsync(shift, request.CostDateTime);
|
||||
|
||||
var order = new CanteenOrderEntity
|
||||
{
|
||||
@@ -395,7 +359,7 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
var orderId = await DbContext.InsertReturnIdentityAsync(order);
|
||||
try
|
||||
{
|
||||
await GenerateConsumeRecordAsync(orderId, shifts, request.CostDateTime);
|
||||
await GenerateConsumeRecordAsync(orderId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -416,7 +380,6 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
|
||||
public async Task<Pagination<OrderAggregationResponse>> GetOrdersAggregationAsync(PageDto page)
|
||||
{
|
||||
var subjectId = CurrentUser.GetIntSubjectId();
|
||||
@@ -511,25 +474,7 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
|
||||
}.IsPresent1(request.CostDateTime));
|
||||
|
||||
var switchTime = await GetSettingAsync<TimeOnly?>(businessPlaceInfo.TenantId, CanteenSettingItemEnumType.BusinessSwitchTime);
|
||||
|
||||
//计算成本日期 todo 优化
|
||||
var costDate = request.CostDateTime.Date;
|
||||
if (shift == null)
|
||||
{
|
||||
costDate = request.CostDateTime.Date;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (switchTime.HasValue)
|
||||
{
|
||||
var beginOfDay = request.CostDateTime.Date;
|
||||
|
||||
var setTime = beginOfDay.Add(switchTime.Value.ToTimeSpan());
|
||||
if (request.CostDateTime < setTime)
|
||||
costDate = request.CostDateTime.Date.AddDays(-1);
|
||||
}
|
||||
}
|
||||
var costDate = await GetCostDateAsync(shift, request.CostDateTime);
|
||||
|
||||
var shiftType = shift?.ShiftType;
|
||||
|
||||
@@ -553,26 +498,40 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
|
||||
//******************************************************* help methods ************************************************************/
|
||||
|
||||
/// <summary>
|
||||
/// 获取成本日期
|
||||
/// </summary>
|
||||
/// <param name="shift"></param>
|
||||
/// <param name="costDateTime"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<DateTime> GetCostDateAsync(BusinessShiftMealRelationshipEntity shift, DateTime costDateTime)
|
||||
{
|
||||
var switchTime = await GetSettingAsync<TimeOnly?>(shift.TenantId, CanteenSettingItemEnumType.BusinessSwitchTime);
|
||||
|
||||
var costDate = costDateTime.Date;
|
||||
|
||||
if (shift != null && switchTime.HasValue)
|
||||
{
|
||||
var beginOfDay = costDateTime.Date;
|
||||
|
||||
var setTime = beginOfDay.Add(switchTime.Value.ToTimeSpan());
|
||||
if (costDateTime < setTime)
|
||||
costDate = costDateTime.Date.AddDays(-1);
|
||||
}
|
||||
|
||||
return costDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 验证参数
|
||||
/// </summary>
|
||||
/// <param name="shifts"></param>
|
||||
/// <param name="costDateTime"></param>
|
||||
/// <param name="order"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
private async Task Verify(List<BusinessShiftMealRelationshipEntity> shifts, DateTime costDateTime, CanteenOrderEntity order)
|
||||
private async Task Verify(CanteenOrderEntity order)
|
||||
{
|
||||
shifts.FirstOrDefault(x => new TimePeriod()
|
||||
{
|
||||
Start = x.Start,
|
||||
End = x.End,
|
||||
|
||||
}.IsPresent1(costDateTime)).ThrowIfNull("当前非就餐时间,无法消费");
|
||||
|
||||
var beginOfDay = DateTime.Today;
|
||||
var endOfDay = beginOfDay.AddDays(1).AddSeconds(-1);
|
||||
|
||||
@@ -637,16 +596,14 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
/// 生成充值记录
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <param name="shifts"></param>
|
||||
/// <param name="costDateTime"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
/// <exception cref="VersionExceptions"></exception>
|
||||
private async Task GenerateConsumeRecordAsync(long orderId, List<BusinessShiftMealRelationshipEntity> shifts, DateTime costDateTime)
|
||||
private async Task GenerateConsumeRecordAsync(long orderId)
|
||||
{
|
||||
var order = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.Id == orderId).FirstAsync();
|
||||
//校验
|
||||
await Verify(shifts, costDateTime, order);
|
||||
await Verify(order);
|
||||
|
||||
var allowNoBalance = await GetSettingAsync<bool>(order.TenantId, CanteenSettingItemEnumType.AllowNoBalance);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using Dlhis.ScheduledTask.Common.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Scheduled;
|
||||
using Kurisu.Scheduled.Attributes;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
@@ -13,7 +14,7 @@ namespace Dlhis.ScheduledTask.Jobs;
|
||||
/// <summary>
|
||||
/// 上传考勤记录
|
||||
/// </summary>
|
||||
[RecurringJob(nameof(SyncOriginCardInfoJob), "0/20 * * * * ?", Name = "上传考勤记录")]
|
||||
[RecurringJob(nameof(SyncOriginCardInfoJob), "0 0/15 * * * ?", Name = "上传考勤记录")]
|
||||
public class SyncOriginCardInfoJob : BaseJob
|
||||
{
|
||||
private readonly IJinkoJIPService _jinkoJIPService;
|
||||
@@ -51,21 +52,31 @@ public class SyncOriginCardInfoJob : BaseJob
|
||||
|
||||
}).Where(x => x.ZWORKCODE.IsPresent()).ToList();
|
||||
|
||||
var ids = requests.Select(x => x.Id).ToList();
|
||||
if (ids.Any())
|
||||
if (requests.Any())
|
||||
{
|
||||
var r = await _jinkoJIPService.UploadAttendancesAsync(requests);
|
||||
if (r.OLX == "0")
|
||||
foreach (var items in requests.Chunk(500))
|
||||
{
|
||||
await DbContext.Updateable<DeviceUploadLogEntity>()
|
||||
.SetColumns(x => x.Sync == true)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => ids.Contains(x.Id))
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError(r.OMS);
|
||||
try
|
||||
{
|
||||
var ids = items.Select(x => x.Id).ToList();
|
||||
var r = await _jinkoJIPService.UploadAttendancesAsync(items.ToList());
|
||||
if (r.OLX == "0")
|
||||
{
|
||||
await DbContext.Updateable<DeviceUploadLogEntity>()
|
||||
.SetColumns(x => x.Sync == true)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => ids.Contains(x.Id))
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError(r.OMS);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "考勤分配上传异常:{message}", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user