fix 菜单时效范围
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Kurisu.Core.CustomClass;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Dishes.Request;
|
namespace Dlhis.Basic.Dishes.Request;
|
||||||
|
|
||||||
@@ -11,29 +12,26 @@ public class DishesMenuNameDateSaveRequest : IValidatableObject
|
|||||||
public string CustomCode { get; set; }
|
public string CustomCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 菜单日期
|
/// 时间段
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime Date { get; set; }
|
[Required(ErrorMessage = "时间段不可为空")]
|
||||||
|
public DateTimePeriod Period { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 餐次数据
|
/// 餐次数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<DishesMenuShiftTypeSaveRequest> ShiftTypes { get; set; }
|
public List<DishesMenuShiftTypeSaveRequest> ShiftTypes { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
if (Date < DateTime.Today)
|
if (Period.Start < Period.End)
|
||||||
{
|
{
|
||||||
yield return new ValidationResult("菜单日期不能小于当天");
|
yield return new ValidationResult("时间范围有误", new[] { nameof(Period) });
|
||||||
}
|
}
|
||||||
|
|
||||||
//格式化
|
|
||||||
Date = Date.Date;
|
|
||||||
|
|
||||||
if (CustomCode.IsEmpty())
|
if (CustomCode.IsEmpty())
|
||||||
{
|
{
|
||||||
CustomCode = Date.ToString("yyyy-MM-dd");
|
CustomCode = Period.Start.Value.ToString("yyyy-MM-dd") + "." + Period.End.Value.ToString("yyyy-MM-dd");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,12 @@ public class DishesMenuPageResponse
|
|||||||
public Guid BusinessPlaceCode { get; set; }
|
public Guid BusinessPlaceCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 营业日期
|
/// 营业日期 开始
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime Date { get; set; }
|
public DateTime StartDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 营业日期 结束
|
||||||
|
/// </summary>
|
||||||
|
public DateTime EndDate { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ using Dlhis.Basic.Dishes.Request;
|
|||||||
using Dlhis.Basic.Dishes.Response;
|
using Dlhis.Basic.Dishes.Response;
|
||||||
using Dlhis.Basic.BusinessPlace.Services;
|
using Dlhis.Basic.BusinessPlace.Services;
|
||||||
using Dlhis.Basic.Dishes.Dto;
|
using Dlhis.Basic.Dishes.Dto;
|
||||||
using Mapster;
|
using Kurisu.Core.CustomClass;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Dishes.Services.Implements;
|
namespace Dlhis.Basic.Dishes.Services.Implements;
|
||||||
|
|
||||||
@@ -28,12 +29,13 @@ public class DishesMenuService : IDishesMenuService
|
|||||||
{
|
{
|
||||||
return await _dbContext.Queryable<DishesMenuEntity>()
|
return await _dbContext.Queryable<DishesMenuEntity>()
|
||||||
.Where(x => x.BusinessPlaceCode == request.BusinessPlaceCode)
|
.Where(x => x.BusinessPlaceCode == request.BusinessPlaceCode)
|
||||||
.GroupBy(x => new { x.BusinessPlaceCode, x.CustomCode, x.Date })
|
.GroupBy(x => new { x.BusinessPlaceCode, x.CustomCode, x.StartDate, x.EndDate })
|
||||||
.Select(x => new DishesMenuPageResponse
|
.Select(x => new DishesMenuPageResponse
|
||||||
{
|
{
|
||||||
BusinessPlaceCode = x.BusinessPlaceCode,
|
BusinessPlaceCode = x.BusinessPlaceCode,
|
||||||
CustomCode = x.CustomCode,
|
CustomCode = x.CustomCode,
|
||||||
Date = x.Date,
|
StartDate = x.StartDate,
|
||||||
|
EndDate = x.EndDate,
|
||||||
})
|
})
|
||||||
.ToPageListAsync(request);
|
.ToPageListAsync(request);
|
||||||
}
|
}
|
||||||
@@ -42,6 +44,8 @@ public class DishesMenuService : IDishesMenuService
|
|||||||
{
|
{
|
||||||
var data = await _dbContext.Queryable<DishesMenuEntity>()
|
var data = await _dbContext.Queryable<DishesMenuEntity>()
|
||||||
.Where(x => x.BusinessPlaceCode == businessPlaceCode)
|
.Where(x => x.BusinessPlaceCode == businessPlaceCode)
|
||||||
|
.Where(x => x.CustomCode == customCode)
|
||||||
|
.Where(x => x.StartDate >= date && x.EndDate <= date)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
return new DishesMenuSaveRequest
|
return new DishesMenuSaveRequest
|
||||||
@@ -52,7 +56,11 @@ public class DishesMenuService : IDishesMenuService
|
|||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
CustomCode = customCode,
|
CustomCode = customCode,
|
||||||
Date = date,
|
Period = new DateTimePeriod
|
||||||
|
{
|
||||||
|
Start = data[0].StartDate,
|
||||||
|
End = data[0].EndDate,
|
||||||
|
},
|
||||||
ShiftTypes = data.GroupBy(x => x.ShiftType).Select(item =>
|
ShiftTypes = data.GroupBy(x => x.ShiftType).Select(item =>
|
||||||
{
|
{
|
||||||
var shiftType = item.Key;
|
var shiftType = item.Key;
|
||||||
@@ -79,7 +87,7 @@ public class DishesMenuService : IDishesMenuService
|
|||||||
var data = await _dbContext.Queryable<DishesMenuEntity>()
|
var data = await _dbContext.Queryable<DishesMenuEntity>()
|
||||||
.LeftJoin<DishesEntity>((x, dishes) => x.DishesCode == dishes.CustomCode)
|
.LeftJoin<DishesEntity>((x, dishes) => x.DishesCode == dishes.CustomCode)
|
||||||
.Where(x => x.BusinessPlaceCode == businessPlaceCode)
|
.Where(x => x.BusinessPlaceCode == businessPlaceCode)
|
||||||
.Where(x => SqlFunc.DateIsSame(x.Date, date, DateType.Day))
|
.Where(x => x.StartDate >= date && x.EndDate <= date)
|
||||||
.Where((x, dishes) => dishes.Enable)
|
.Where((x, dishes) => dishes.Enable)
|
||||||
.WhereIF(shiftType.HasValue, x => x.ShiftType == shiftType)
|
.WhereIF(shiftType.HasValue, x => x.ShiftType == shiftType)
|
||||||
.Where((x, dishes) => dishes.CategoryCode == categoryCode)
|
.Where((x, dishes) => dishes.CategoryCode == categoryCode)
|
||||||
@@ -114,7 +122,7 @@ public class DishesMenuService : IDishesMenuService
|
|||||||
var entities = request.Items.SelectMany(item =>
|
var entities = request.Items.SelectMany(item =>
|
||||||
{
|
{
|
||||||
var customCode = item.CustomCode;
|
var customCode = item.CustomCode;
|
||||||
var date = item.Date;
|
var period = item.Period;
|
||||||
|
|
||||||
return item.ShiftTypes.SelectMany(shiftTypeItem =>
|
return item.ShiftTypes.SelectMany(shiftTypeItem =>
|
||||||
{
|
{
|
||||||
@@ -130,7 +138,8 @@ public class DishesMenuService : IDishesMenuService
|
|||||||
{
|
{
|
||||||
BusinessPlaceCode = request.BusinessPlaceCode,
|
BusinessPlaceCode = request.BusinessPlaceCode,
|
||||||
CustomCode = customCode,
|
CustomCode = customCode,
|
||||||
Date = date,
|
StartDate = period.Start.Value,
|
||||||
|
EndDate = period.End.Value,
|
||||||
ShiftType = shiftType,
|
ShiftType = shiftType,
|
||||||
DishesCode = dishesCode,
|
DishesCode = dishesCode,
|
||||||
Number = number,
|
Number = number,
|
||||||
@@ -143,31 +152,44 @@ public class DishesMenuService : IDishesMenuService
|
|||||||
});
|
});
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var keys = entities.DistinctBy(x => new { x.Date, x.ShiftType }).Select(x => new { x.Date, x.ShiftType }).ToList();
|
var keys = entities.DistinctBy(x => new { x.StartDate, x.EndDate, x.ShiftType }).Select(x => new { x.StartDate, x.EndDate, x.ShiftType }).ToList();
|
||||||
var where = LinqExpressionExtension.False<DishesMenuEntity>();
|
var where = LinqExpressionExtension.False<DishesMenuEntity>();
|
||||||
keys.ForEach(x =>
|
keys.ForEach(x =>
|
||||||
{
|
{
|
||||||
where = where.Or(item => item.BusinessPlaceCode == request.BusinessPlaceCode
|
where = where.Or(item => item.BusinessPlaceCode == request.BusinessPlaceCode
|
||||||
&& SqlFunc.DateIsSame(item.Date, x.Date, DateType.Day)
|
&& SqlFunc.DateIsSame(item.StartDate, x.StartDate, DateType.Day)
|
||||||
|
&& SqlFunc.DateIsSame(item.EndDate, x.EndDate, DateType.Day)
|
||||||
&& item.ShiftType == x.ShiftType);
|
&& item.ShiftType == x.ShiftType);
|
||||||
});
|
});
|
||||||
|
|
||||||
await _dbContext.Client.Deleteable<DishesMenuEntity>().Where(where).ExecuteCommandAsync();
|
await _dbContext.Client.Deleteable<DishesMenuEntity>().Where(where).ExecuteCommandAsync();
|
||||||
await _dbContext.InsertAsync(entities);
|
await _dbContext.InsertAsync(entities);
|
||||||
|
|
||||||
|
if (request.Items.Any())
|
||||||
|
{
|
||||||
|
Expression<Func<DishesMenuEntity, bool>> whereCheck = LinqExpressionExtension.False<DishesMenuEntity>();
|
||||||
|
request.Items.ForEach(p =>
|
||||||
|
{
|
||||||
|
whereCheck = where.Or(x => !(x.EndDate < p.Period.Start || x.StartDate > p.Period.End));
|
||||||
|
});
|
||||||
|
|
||||||
|
var duplicate = await _dbContext.Queryable<DishesMenuEntity>().Where(whereCheck).AnyAsync();
|
||||||
|
duplicate.ThrowIfTrue("菜单时效冲突");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DishesMenuDetailDto> GetBookingDishesDetailAsync(DateTime date, Guid businessPlaceCode, ShiftEnumType shiftType, string dishesCode)
|
public async Task<DishesMenuDetailDto> GetBookingDishesDetailAsync(DateTime date, Guid businessPlaceCode, ShiftEnumType shiftType, string dishesCode)
|
||||||
{
|
{
|
||||||
var detail = await _dbContext.Queryable<DishesMenuEntity>()
|
var detail = await _dbContext.Queryable<DishesMenuEntity>()
|
||||||
.LeftJoin<DishesEntity>((x, d) => x.DishesCode == d.CustomCode)
|
.LeftJoin<DishesEntity>((x, d) => x.DishesCode == d.CustomCode)
|
||||||
.Where(x => SqlFunc.DateIsSame(x.Date, date, DateType.Day))
|
.Where(x => x.StartDate >= date && x.EndDate <= date)
|
||||||
.Where(x => x.BusinessPlaceCode == businessPlaceCode)
|
.Where(x => x.BusinessPlaceCode == businessPlaceCode)
|
||||||
.Where(x => x.ShiftType == shiftType)
|
.Where(x => x.ShiftType == shiftType)
|
||||||
.Where(x => x.DishesCode == dishesCode)
|
.Where(x => x.DishesCode == dishesCode)
|
||||||
.Where((x, d) => d.Enable)
|
.Where((x, d) => d.Enable)
|
||||||
.Select((x, d) => new DishesMenuDetailDto
|
.Select((x, d) => new DishesMenuDetailDto
|
||||||
{
|
{
|
||||||
Date = x.Date,
|
Date = date,
|
||||||
MenuId = x.Id,
|
MenuId = x.Id,
|
||||||
DishesId = d.Id,
|
DishesId = d.Id,
|
||||||
DishesCode = d.CustomCode,
|
DishesCode = d.CustomCode,
|
||||||
@@ -185,11 +207,11 @@ public class DishesMenuService : IDishesMenuService
|
|||||||
|
|
||||||
private static void CheckDuplicateData(DishesMenuSaveRequest request)
|
private static void CheckDuplicateData(DishesMenuSaveRequest request)
|
||||||
{
|
{
|
||||||
(request.Items.DistinctBy(x => new { x.CustomCode, x.Date }).Count() != request.Items.Count).ThrowIfTrue("菜单不可重复");
|
(request.Items.DistinctBy(x => new { x.CustomCode, x.Period.Start, x.Period.End }).Count() != request.Items.Count).ThrowIfTrue("菜单不可重复");
|
||||||
|
|
||||||
foreach (var item in request.Items)
|
foreach (var item in request.Items)
|
||||||
{
|
{
|
||||||
var u = item.Date.ToString("yyyy-MM-dd") + ". " + item.CustomCode;
|
var u = item.Period.Start.Value.ToString("yyyy-MM-dd") + "." + item.Period.End.Value.ToString("yyyy-MM-dd") + "." + item.CustomCode;
|
||||||
|
|
||||||
(item.ShiftTypes.DistinctBy(x => x.ShiftType).Count() != item.ShiftTypes.Count).ThrowIfTrue($"{u}的餐次不可重复添加");
|
(item.ShiftTypes.DistinctBy(x => x.ShiftType).Count() != item.ShiftTypes.Count).ThrowIfTrue($"{u}的餐次不可重复添加");
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ using Dlhis.Basic.Api;
|
|||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using MySqlX.XDevAPI.Relational;
|
|
||||||
|
|
||||||
namespace Dlhis.Canteen.Order.Services.Implements;
|
namespace Dlhis.Canteen.Order.Services.Implements;
|
||||||
|
|
||||||
@@ -134,7 +133,7 @@ public class BookingOrderService : BaseOrderService, IBookingOrderService
|
|||||||
.SetColumns(x => x.Number == menuDetail.Number)
|
.SetColumns(x => x.Number == menuDetail.Number)
|
||||||
.SetColumns(x => x.Version == x.Version + 1)
|
.SetColumns(x => x.Version == x.Version + 1)
|
||||||
.SetColumns(x => x.ModifiedTime == now)
|
.SetColumns(x => x.ModifiedTime == now)
|
||||||
.Where(x => x.Date == menuDetail.Date
|
.Where(x => x.StartDate >= menuDetail.Date && x.EndDate <= menuDetail.Date
|
||||||
&& x.ShiftType == request.ShiftType
|
&& x.ShiftType == request.ShiftType
|
||||||
&& x.BusinessPlaceCode == request.BusinessPlaceCode
|
&& x.BusinessPlaceCode == request.BusinessPlaceCode
|
||||||
&& x.DishesCode == request.DishesCode
|
&& x.DishesCode == request.DishesCode
|
||||||
|
|||||||
@@ -31,11 +31,16 @@ public class DishesMenuEntity : SugarBaseEntity, ITenantId, IVersion
|
|||||||
public Guid BusinessPlaceCode { get; set; }
|
public Guid BusinessPlaceCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 营业日期
|
/// 营业日期-开始
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDataType = "date", ColumnDescription = "营业日期")]
|
[SugarColumn(ColumnDescription = "营业日期开始")]
|
||||||
public DateTime Date { get; set; }
|
public DateTime StartDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 营业日期-结束
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "营业日期结束")]
|
||||||
|
public DateTime EndDate { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 餐次
|
/// 餐次
|
||||||
|
|||||||
Reference in New Issue
Block a user