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