Files
jinko.yikatong/Src/Dlhis.Basic/Dishes/Services/Implements/DishesMenuService.cs
liguoyang 3ea432943f Squashed commit of the following:
commit afdd9e6f14
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:48:05 2024 +0800

    fix 价格默认获取菜单中的设置

commit a3cfc472c8
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:40:04 2024 +0800

    fix 时间范围逻辑

commit 83f8906f12
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:32:55 2024 +0800

    fix 时间范围逻辑

commit 35660b1d0c
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:29:36 2024 +0800

    fix 数据范围罗逻辑修改

commit 7407955bc5
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:14:06 2024 +0800

    fix 分类树增加营业点参数

commit ed5196d1a1
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:02:52 2024 +0800

    feat 用户创建

commit d25909a235
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 20:51:20 2024 +0800

    fix 菜单明细调整

commit 8915f9ff0f
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 20:42:08 2024 +0800

    fix 判断提前

commit 45aa52aa2a
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 20:34:22 2024 +0800

    fix 逻辑取反

commit 89904fead1
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 20:23:20 2024 +0800

    fix 菜单时效范围

commit 573911f907
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 19:13:33 2024 +0800

    fix 订单聚合返回状态

commit 93c38be18a
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 18:40:12 2024 +0800

    fix 订单查询

commit e256d18d36
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 18:14:33 2024 +0800

    fix 订单取消接口,分页权限控制

commit 1218aec811
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 17:32:45 2024 +0800

    fix 营业点权限控制优化

commit 226c61ee41
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 17:09:42 2024 +0800

    fix tenantId赋值

commit 28d2c1d8d4
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 17:05:37 2024 +0800

    fix ignoretenant

commit 5ae6dd97b4
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 16:53:40 2024 +0800

    fix ignoretenant

commit 4c866eaf3f
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 16:40:24 2024 +0800

    feat 获取所有地址

commit 2ca8f2db49
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 16:22:47 2024 +0800

    fix 优化查询

commit 212a1fa073
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 16:01:49 2024 +0800

    fix 临时数据模拟

commit 0eb76e878c
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 15:48:59 2024 +0800

    fix 处理删除缺少判断

commit c582fb40c0
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 15:40:22 2024 +0800

    fix 查询优化

commit 6d3a19b283
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 11:48:45 2024 +0800

    fix 错误值修改

commit c39f77008d
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 11:31:50 2024 +0800

    fix 营业点控制(admin),unit返回

commit a5dcab1d07
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 11:16:23 2024 +0800

    fix 营业点分页控制

commit 02084be82b
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 11:01:14 2024 +0800

    fix 分类控制菜品获取

commit 96c5c5feba
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 10:39:58 2024 +0800

    fix DI

commit 367ede2eeb
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 10:35:24 2024 +0800

    fix 订餐返回当前信息,增加数量入参和响应

commit 0e1f6cb4a0
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 16:40:10 2024 +0800

    fix 餐补查询代码调整

commit 21fc2f78d3
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 15:52:46 2024 +0800

    fix 支付批量操作

commit 878b44a146
Merge: a90d4e6 bf5c937
Author: cheche <717840555@qq.com>
Date:   Wed Mar 20 15:27:39 2024 +0800

    Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development

commit a90d4e66a7
Author: cheche <717840555@qq.com>
Date:   Wed Mar 20 15:27:37 2024 +0800

    fix 餐补查询及日志删除

commit bf5c937037
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 15:12:30 2024 +0800

    fix 补充营业点分配权限接口

commit 07672f1d32
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 13:56:33 2024 +0800

    fix 优化changeDb

commit 7090ee4a33
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 13:41:25 2024 +0800

    fix 敏感信息混淆

commit 4366b68831
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 12:42:48 2024 +0800

    fix 代码优化

commit 03b73515b5
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 10:59:08 2024 +0800

    fix tree返回营业点

commit 1ce60bedc2
Merge: aba4fa7 2d83930
Author: cheche <717840555@qq.com>
Date:   Wed Mar 20 09:55:17 2024 +0800

    Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development

commit aba4fa7ee9
Author: cheche <717840555@qq.com>
Date:   Wed Mar 20 09:55:13 2024 +0800

    fix 删除日志优化

commit 2d8393068f
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 20:53:16 2024 +0800

    feat 订单聚合接口

commit 0cde1d3d92
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 20:03:06 2024 +0800

    fix 表名称调整

commit f003e30169
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 19:51:56 2024 +0800

    fix 订餐null异常处理

commit f427338715
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 18:43:19 2024 +0800

    feat 获取菜品

commit 3a65d95701
Merge: 9a7091b 7432fae
Author: cheche <717840555@qq.com>
Date:   Tue Mar 19 18:36:16 2024 +0800

    Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development

commit 9a7091b4e0
Author: cheche <717840555@qq.com>
Date:   Tue Mar 19 18:36:14 2024 +0800

    fix 删除日志try

commit 7432fae103
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 18:02:31 2024 +0800

    fix 配送点增加

commit ecd162c7af
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 17:51:15 2024 +0800

    fix 预定就餐送货地点

commit 1c7a054ed4
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 15:53:22 2024 +0800

    feat 获取所有营业点接口

commit 84398a566e
Merge: 217d9f7 84b4025
Author: cheche <717840555@qq.com>
Date:   Tue Mar 19 15:26:42 2024 +0800

    Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development

commit 217d9f7770
Author: cheche <717840555@qq.com>
Date:   Tue Mar 19 15:26:40 2024 +0800

    feat  配送点管理

commit 84b402538e
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 14:59:21 2024 +0800

    fix 菜单分页响应调整,增加详情接口

commit 098d7c7e9d
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 14:26:24 2024 +0800

    fix 代码优化
2024-03-21 22:04:52 +08:00

236 lines
9.5 KiB
C#

using Dlhis.Entity.Canteen.Entities;
using Dlhis.Entity.Canteen.Enums;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
using SqlSugar;
using Dlhis.Basic.Dishes.Request;
using Dlhis.Basic.Dishes.Response;
using Dlhis.Basic.BusinessPlace.Services;
using Dlhis.Basic.Dishes.Dto;
using Kurisu.Core.CustomClass;
using System.Linq.Expressions;
namespace Dlhis.Basic.Dishes.Services.Implements;
public class DishesMenuService : IDishesMenuService
{
private readonly IDbContext _dbContext;
private readonly IBusinessPlacePermissionsService _businessPlacePermissionsService;
public DishesMenuService(IDbContext dbContext, IBusinessPlacePermissionsService businessPlacePermissionsService)
{
_dbContext = dbContext;
_businessPlacePermissionsService = businessPlacePermissionsService;
}
public async Task<Pagination<DishesMenuPageResponse>> GetDishesMenuPageAsync(DisheMenuPageRequest request)
{
return await _dbContext.Queryable<DishesMenuEntity>()
.Where(x => x.BusinessPlaceCode == request.BusinessPlaceCode)
.GroupBy(x => new { x.BusinessPlaceCode, x.CustomCode, x.StartDate, x.EndDate })
.Select(x => new DishesMenuPageResponse
{
BusinessPlaceCode = x.BusinessPlaceCode,
CustomCode = x.CustomCode,
StartDate = x.StartDate,
EndDate = x.EndDate,
})
.ToPageListAsync(request);
}
public async Task<DishesMenuSaveRequest> GetDishesMenuDetailAsync(Guid businessPlaceCode, string customCode, DateTime startDate, DateTime endDate)
{
var data = await _dbContext.Queryable<DishesMenuEntity>()
.Where(x => x.BusinessPlaceCode == businessPlaceCode)
.Where(x => x.CustomCode == customCode)
.Where(x => x.StartDate == startDate)
.Where(x => x.EndDate == endDate)
.ToListAsync();
if (data.IsEmpty())
{
return new DishesMenuSaveRequest
{
BusinessPlaceCode = businessPlaceCode,
Items = new List<DishesMenuNameDateSaveRequest> { }
};
}
return new DishesMenuSaveRequest
{
BusinessPlaceCode = businessPlaceCode,
Items = new List<DishesMenuNameDateSaveRequest>
{
new()
{
CustomCode = customCode,
Period = new DateTimePeriod
{
Start = data[0].StartDate,
End = data[0].EndDate,
},
ShiftTypes = data.GroupBy(x => x.ShiftType).Select(item =>
{
var shiftType = item.Key;
return new DishesMenuShiftTypeSaveRequest
{
ShiftType = shiftType,
Dishes = item.Select(x => new MenuDishesSaveRequest
{
DishesCode = x.DishesCode,
Number = x.Number,
Price = x.Price,
}).ToList()
};
}).ToList()
}
}
};
}
public async Task<List<DishesDetailResponse>> GetDishesUnderCurrentMenuAsync(Guid businessPlaceCode, DateTime date, ShiftEnumType? shiftType, Guid categoryCode)
{
var data = await _dbContext.Queryable<DishesMenuEntity>()
.LeftJoin<DishesEntity>((x, dishes) => x.DishesCode == dishes.CustomCode)
.Where(x => x.BusinessPlaceCode == businessPlaceCode)
.Where(x => x.StartDate <= date && date <= x.EndDate)
.Where((x, dishes) => dishes.Enable)
.WhereIF(shiftType.HasValue, x => x.ShiftType == shiftType)
.Where((x, dishes) => dishes.CategoryCode == categoryCode)
.Select((x, dishes) => new DishesDetailResponse
{
BusinessPlaceCode = x.BusinessPlaceCode,
CategoryCode = dishes.CategoryCode,
CustomCode = dishes.CustomCode,
Description = dishes.Description,
ImageUrl = dishes.ImageUrl,
Price = SqlFunc.IIF(x.Price > 0, x.Price, dishes.Price),
Name = dishes.Name,
Number = x.Number,
CurrentUnits = dishes.Units.ToString()
})
.ToListAsync();
return data;
}
public async Task SaveDishesMenuAsync(DishesMenuSaveRequest request)
{
//检验数据
CheckDuplicateData(request);
//检验权限
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;
var period = item.Period;
return item.ShiftTypes.SelectMany(shiftTypeItem =>
{
var shiftType = shiftTypeItem.ShiftType;
return shiftTypeItem.Dishes.Select(dishesItem =>
{
var dishesCode = dishesItem.DishesCode;
var number = dishesItem.Number;
var price = dishesItem.Price;
return new DishesMenuEntity
{
BusinessPlaceCode = request.BusinessPlaceCode,
CustomCode = customCode,
StartDate = period.Start.Value,
EndDate = period.End.Value,
ShiftType = shiftType,
DishesCode = dishesCode,
Number = number,
Price = price,
Type = CanteenApplicaitonTypeEnumType.Booking,
Version = 0,
};
});
});
}).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>();
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)
&& item.ShiftType == x.ShiftType);
});
await _dbContext.Client.Deleteable<DishesMenuEntity>().Where(where).ExecuteCommandAsync();
await _dbContext.InsertAsync(entities);
}
public async Task<DishesMenuDetailDto> GetBookingDishesDetailAsync(DateTime date, Guid businessPlaceCode, ShiftEnumType shiftType, string dishesCode)
{
var detail = await _dbContext.Queryable<DishesMenuEntity>()
.LeftJoin<DishesEntity>((x, d) => x.DishesCode == d.CustomCode)
.Where(x => x.StartDate <= date && date <= x.EndDate)
.Where(x => x.BusinessPlaceCode == businessPlaceCode)
.Where(x => x.ShiftType == shiftType)
.Where(x => x.DishesCode == dishesCode)
.Where((x, d) => d.Enable)
.Select((x, d) => new DishesMenuDetailDto
{
Date = date,
MenuId = x.Id,
DishesId = d.Id,
DishesCode = d.CustomCode,
DishesName = d.Name,
Price = x.Price == null || x.Price == 0 ? d.Price : x.Price.Value,
Number = x.Number,
Version = x.Version,
})
.SingleAsync();
return detail;
}
//*********************************************************help methods**********************************************************************
private static void CheckDuplicateData(DishesMenuSaveRequest request)
{
(request.Items.DistinctBy(x => new { x.CustomCode, x.Period.Start, x.Period.End }).Count() != request.Items.Count).ThrowIfTrue("菜单不可重复");
foreach (var item in request.Items)
{
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}的餐次不可重复添加");
foreach (var shiftTypeItem in item.ShiftTypes)
{
(shiftTypeItem.Dishes.DistinctBy(x => x.DishesCode).Count() != shiftTypeItem.Dishes.Count)
.ThrowIfTrue($"{u}的{shiftTypeItem.ShiftType.GetDescription()}下菜品不可重复");
}
}
}
}