fix 判断冲突
This commit is contained in:
@@ -126,21 +126,8 @@ public class DishesMenuService : IDishesMenuService
|
||||
//检验权限
|
||||
var res = await _businessPlacePermissionsService.GetMyAsync();
|
||||
var myBps = res.Select(x => x.Code).ToList();
|
||||
|
||||
myBps.Contains(request.BusinessPlaceCode).ThrowIfFalse("非经营营业点,无法保存菜单");
|
||||
|
||||
if (request.Items.Any())
|
||||
{
|
||||
Expression<Func<DishesMenuEntity, bool>> whereCheck = LinqExpressionExtension.False<DishesMenuEntity>();
|
||||
request.Items.ForEach(p =>
|
||||
{
|
||||
whereCheck = whereCheck.Or(x => !(x.EndDate < p.Period.Start || x.StartDate > p.Period.End));
|
||||
});
|
||||
|
||||
var duplicate = await _dbContext.Queryable<DishesMenuEntity>().Where(whereCheck).AnyAsync();
|
||||
duplicate.ThrowIfTrue("菜单时效冲突");
|
||||
}
|
||||
|
||||
var entities = request.Items.SelectMany(item =>
|
||||
{
|
||||
var customCode = item.CustomCode;
|
||||
@@ -174,17 +161,35 @@ public class DishesMenuService : IDishesMenuService
|
||||
});
|
||||
}).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 keys = entities.DistinctBy(x => new { x.CustomCode, x.StartDate, x.EndDate, x.ShiftType })
|
||||
.Select(x => new { x.CustomCode, x.StartDate, x.EndDate, x.ShiftType })
|
||||
.ToList();
|
||||
var deleteWhere = LinqExpressionExtension.False<DishesMenuEntity>();
|
||||
keys.ForEach(x =>
|
||||
{
|
||||
where = where.Or(item => item.BusinessPlaceCode == request.BusinessPlaceCode
|
||||
&& SqlFunc.DateIsSame(item.StartDate, x.StartDate, DateType.Day)
|
||||
&& SqlFunc.DateIsSame(item.EndDate, x.EndDate, DateType.Day)
|
||||
deleteWhere = deleteWhere.Or(item => item.BusinessPlaceCode == request.BusinessPlaceCode
|
||||
&& item.CustomCode == x.CustomCode
|
||||
//&& SqlFunc.DateIsSame(item.StartDate, x.StartDate, DateType.Day)
|
||||
//&& SqlFunc.DateIsSame(item.EndDate, x.EndDate, DateType.Day)
|
||||
&& item.ShiftType == x.ShiftType);
|
||||
});
|
||||
|
||||
await _dbContext.Client.Deleteable<DishesMenuEntity>().Where(where).ExecuteCommandAsync();
|
||||
await _dbContext.Client.Deleteable<DishesMenuEntity>().Where(deleteWhere).ExecuteCommandAsync();
|
||||
|
||||
if (request.Items.Any())
|
||||
{
|
||||
Expression<Func<DishesMenuEntity, bool>> whereCheck = LinqExpressionExtension.False<DishesMenuEntity>();
|
||||
request.Items.ForEach(p =>
|
||||
{
|
||||
whereCheck = whereCheck.Or(x => x.BusinessPlaceCode == request.BusinessPlaceCode
|
||||
&& !(x.EndDate < p.Period.Start || x.StartDate > p.Period.End)
|
||||
);
|
||||
});
|
||||
|
||||
var duplicate = await _dbContext.Queryable<DishesMenuEntity>().Where(whereCheck).AnyAsync();
|
||||
duplicate.ThrowIfTrue("菜单时效冲突");
|
||||
}
|
||||
|
||||
await _dbContext.InsertAsync(entities);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ public class UserService : IUserService
|
||||
{
|
||||
UserName = request.Username,
|
||||
NormalizedUserName = request.Username.ToUpper(),
|
||||
ConcurrencyStamp = Guid.NewGuid().ToString(),
|
||||
SecurityStamp = Guid.NewGuid().ToString(),
|
||||
};
|
||||
request.Password = hasher.HashPassword(user, request.Password);
|
||||
user.PasswordHash = request.Password;
|
||||
|
||||
Reference in New Issue
Block a user