feat 菜品/菜单配置
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.Core.CustomClass;
|
||||
|
||||
namespace Dlhis.Basic.BusinessShift.Request;
|
||||
@@ -13,9 +14,10 @@ public class BusinessPlaceShiftSaveMealShiftRequest : IValidatableObject
|
||||
public Guid ShiftCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// mealshift
|
||||
/// 餐次 ShiftEnumType
|
||||
/// </summary>
|
||||
public string ShiftType { get; set; }
|
||||
[EnumDataType(typeof(ShiftEnumType))]
|
||||
public ShiftEnumType ShiftType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 序号
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace Dlhis.Basic.BusinessShift.Response
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.BusinessShift.Response
|
||||
{
|
||||
public class MealShiftResponse
|
||||
{
|
||||
@@ -6,9 +9,9 @@
|
||||
|
||||
public Guid ShiftCode { get; set; }
|
||||
|
||||
public string ShiftType { get; set; }
|
||||
public ShiftEnumType ShiftType { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Name => ShiftType.GetDescription();
|
||||
|
||||
public TimeOnly Start { get; set; }
|
||||
|
||||
|
||||
@@ -38,14 +38,12 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
|
||||
|
||||
//下级就餐时间段
|
||||
var mealShifts = await _dbContext.Queryable<BusinessShiftMealRelationshipEntity>()
|
||||
.LeftJoin<BasicTypeEntity>((x, bt) => x.ShiftType == bt.Code)
|
||||
.Where(x => shiftCodes.Contains(x.ShiftCode))
|
||||
.Select((x, bt) => new MealShiftResponse
|
||||
.Select((x) => new MealShiftResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
ShiftCode = x.ShiftCode,
|
||||
ShiftType = bt.Code,
|
||||
Name = bt.Display,
|
||||
ShiftType = x.ShiftType,
|
||||
Start = x.Start,
|
||||
End = x.End,
|
||||
})
|
||||
@@ -95,14 +93,11 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
|
||||
|
||||
public async Task SaveMealShiftsAsync(List<BusinessPlaceShiftSaveMealShiftRequest> requests)
|
||||
{
|
||||
var mealShifts = await GetMealShiftAsync();
|
||||
|
||||
foreach (var request in requests)
|
||||
{
|
||||
var shift = await CheckExistsShiftAsync(request.ShiftCode);
|
||||
await CheckExistsMealShiftAsync(request);
|
||||
await DuplicateTimePeriodAsync(request);
|
||||
mealShifts.Contains(request.ShiftType).ThrowIfFalse($"{request.ShiftType}不存在");
|
||||
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
@@ -312,11 +307,6 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
|
||||
return shift;
|
||||
}
|
||||
|
||||
private async Task<List<string>> GetMealShiftAsync()
|
||||
{
|
||||
return await _dbContext.Queryable<BasicTypeEntity>().Where(x => x.Type == "mealshift").Select(x => x.Code).ToListAsync();
|
||||
}
|
||||
|
||||
private async Task CheckExistsMealShiftAsync(BusinessPlaceShiftSaveMealShiftRequest request)
|
||||
{
|
||||
var exists = await _dbContext.Queryable<BusinessShiftMealRelationshipEntity>()
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Kurisu.AspNetCore.EventBus.Abstractions;
|
||||
using Kurisu.AspNetCore.Scope;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -48,19 +48,19 @@ public class DeviceService : IDeviceService
|
||||
var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var balanceInfos = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceInfo))
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Select(x => new
|
||||
{
|
||||
x.DeviceInfo,
|
||||
x.DeviceUniqueNo,
|
||||
Amount = SqlFunc.AggregateSum(x.Amount),
|
||||
UserCount = SqlFunc.AggregateDistinctCount(x.UserCode)
|
||||
})
|
||||
.GroupBy(x => x.DeviceInfo)
|
||||
.GroupBy(x => x.DeviceUniqueNo)
|
||||
.ToListAsync();
|
||||
|
||||
page.Data.ForEach(device =>
|
||||
{
|
||||
var info = balanceInfos.FirstOrDefault(x => x.DeviceInfo == device.UniqueNo);
|
||||
var info = balanceInfos.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
||||
if (info != null)
|
||||
{
|
||||
device.Amount = info.Amount;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using Dlhis.Basic.Dishes.Request;
|
||||
using Dlhis.Basic.Dishes.Response;
|
||||
using Dlhis.Canteen.Dishes.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Controller;
|
||||
|
||||
/// <summary>
|
||||
/// 菜品分类
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class DishesCategoriesController : ControllerBase
|
||||
{
|
||||
private readonly IDishesCategoryService _dishesCategoryService;
|
||||
|
||||
public DishesCategoriesController(IDishesCategoryService dishesCategoryService)
|
||||
{
|
||||
_dishesCategoryService = dishesCategoryService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取分类树
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("tree")]
|
||||
public async Task<List<DishesCategoryTreeResponse>> TreeAsync()
|
||||
{
|
||||
return await _dishesCategoryService.TreeAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存分类
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("save")]
|
||||
public async Task SaveAsync(DishesCategorySaveRequest request)
|
||||
{
|
||||
await _dishesCategoryService.SaveAsync(request);
|
||||
}
|
||||
}
|
||||
84
Src/Dlhis.Basic/Dishes/Controller/DishesMenuController.cs
Normal file
84
Src/Dlhis.Basic/Dishes/Controller/DishesMenuController.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using Dlhis.Basic.Dishes.Request;
|
||||
using Dlhis.Basic.Dishes.Response;
|
||||
using Dlhis.Canteen.Dishes.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Controller;
|
||||
|
||||
/// <summary>
|
||||
/// 菜单菜品控制器
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class DishesMenuController : ControllerBase
|
||||
{
|
||||
private readonly IDishesMenuService _dishesMenuService;
|
||||
private readonly IDishesService _dishesService;
|
||||
|
||||
public DishesMenuController(IDishesMenuService dishesMenuService, IDishesService dishesService)
|
||||
{
|
||||
_dishesMenuService = dishesMenuService;
|
||||
_dishesService = dishesService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 菜单分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("page")]
|
||||
public async Task<Pagination<DishesMenuPageResponse>> GetDishesMenuPageAsync([FromQuery] DisheMenuPageRequest request)
|
||||
{
|
||||
return await _dishesMenuService.GetDishesMenuPageAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 菜单保存/更改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("save")]
|
||||
[Transactional]
|
||||
public async Task SaveDishesMenuAsync(DishesMenuSaveRequest request)
|
||||
{
|
||||
await _dishesMenuService.SaveDishesMenuAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 菜品分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("dishes/page")]
|
||||
public async Task<Pagination<DishesResponse>> GetDishesAsync([FromQuery] DishesPageRequest request)
|
||||
{
|
||||
return await _dishesService.GetDishesPageAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 菜品保存/更改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("dishes/save")]
|
||||
public async Task SaveDishesAsync(DishesSaveRequest request)
|
||||
{
|
||||
await _dishesService.SaveDishesAsync(request);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取预定送餐配置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("setting")]
|
||||
public async Task GetDishesMenusBookingSetting()
|
||||
{
|
||||
//todo
|
||||
}
|
||||
}
|
||||
|
||||
18
Src/Dlhis.Basic/Dishes/Dto/DishesMenuDetailDto.cs
Normal file
18
Src/Dlhis.Basic/Dishes/Dto/DishesMenuDetailDto.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace Dlhis.Basic.Dishes.Dto;
|
||||
|
||||
public class DishesMenuDetailDto
|
||||
{
|
||||
public long MenuId { get; set; }
|
||||
|
||||
public long DishesId { get; set; }
|
||||
|
||||
public string DishesCode { get; set; }
|
||||
|
||||
public string DishesName { get; set; }
|
||||
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public int Number { get; set; }
|
||||
|
||||
public int Version { get; set; }
|
||||
}
|
||||
17
Src/Dlhis.Basic/Dishes/Request/DisheMenuPageRequest.cs
Normal file
17
Src/Dlhis.Basic/Dishes/Request/DisheMenuPageRequest.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Request;
|
||||
|
||||
public class DisheMenuPageRequest : PageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 餐次
|
||||
/// </summary>
|
||||
public List<ShiftEnumType> ShiftTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分类
|
||||
/// </summary>
|
||||
public Guid? CategoryCode { get; set; }
|
||||
}
|
||||
24
Src/Dlhis.Basic/Dishes/Request/DishesCategorySaveRequest.cs
Normal file
24
Src/Dlhis.Basic/Dishes/Request/DishesCategorySaveRequest.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Request;
|
||||
|
||||
public class DishesCategorySaveRequest
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PCode
|
||||
/// </summary>
|
||||
public Guid? PCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分类名称
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 序号
|
||||
/// </summary>
|
||||
public int Sequence { get; set; } = 100;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Request;
|
||||
|
||||
public class DishesMenuNameDateSaveRequest : IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单编码
|
||||
/// </summary>
|
||||
public string CustomCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单日期
|
||||
/// </summary>
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 餐次数据
|
||||
/// </summary>
|
||||
public List<DishesMenuShiftTypeSaveRequest> ShiftTypes { get; set; }
|
||||
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (Date < DateTime.Today)
|
||||
{
|
||||
yield return new ValidationResult("菜单日期不能小于当天");
|
||||
}
|
||||
|
||||
//格式化
|
||||
Date = Date.Date;
|
||||
|
||||
if (CustomCode.IsEmpty())
|
||||
{
|
||||
CustomCode = Date.ToString("yyyy-MM-dd");
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Src/Dlhis.Basic/Dishes/Request/DishesMenuSaveRequest.cs
Normal file
18
Src/Dlhis.Basic/Dishes/Request/DishesMenuSaveRequest.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Request;
|
||||
|
||||
public class DishesMenuSaveRequest : IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 营业点code
|
||||
/// </summary>
|
||||
public Guid BusinessPlaceCode { get; set; }
|
||||
|
||||
public List<DishesMenuNameDateSaveRequest> Items { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Request;
|
||||
|
||||
public class DishesMenuShiftTypeSaveRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 餐次段
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(ShiftEnumType))]
|
||||
public ShiftEnumType ShiftType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜品
|
||||
/// </summary>
|
||||
public List<MenuDishesSaveRequest> Dishes { get; set; }
|
||||
}
|
||||
8
Src/Dlhis.Basic/Dishes/Request/DishesPageRequest.cs
Normal file
8
Src/Dlhis.Basic/Dishes/Request/DishesPageRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Request;
|
||||
|
||||
public class DishesPageRequest : PageDto
|
||||
{
|
||||
|
||||
}
|
||||
47
Src/Dlhis.Basic/Dishes/Request/DishesSaveRequest.cs
Normal file
47
Src/Dlhis.Basic/Dishes/Request/DishesSaveRequest.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Request;
|
||||
|
||||
public class DishesSaveRequest
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分类
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Guid CategoryCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜品名称
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单编码
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string CustomCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单价
|
||||
/// </summary>
|
||||
[Range(0, 10000)]
|
||||
public decimal Price { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图片
|
||||
/// </summary>
|
||||
public string ImageUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
public bool Enable { get; set; }
|
||||
}
|
||||
24
Src/Dlhis.Basic/Dishes/Request/MenuDishesSaveRequest.cs
Normal file
24
Src/Dlhis.Basic/Dishes/Request/MenuDishesSaveRequest.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Request;
|
||||
|
||||
public class MenuDishesSaveRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜品编码
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string DishesCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单价
|
||||
/// </summary>
|
||||
[Range(0, double.MaxValue)]
|
||||
public decimal? Price { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 售额
|
||||
/// </summary>
|
||||
[Range(0, int.MaxValue)]
|
||||
public int Number { get; set; }
|
||||
}
|
||||
15
Src/Dlhis.Basic/Dishes/Response/DishesCategoryResponse.cs
Normal file
15
Src/Dlhis.Basic/Dishes/Response/DishesCategoryResponse.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Dlhis.Basic.Dishes.Response;
|
||||
|
||||
public class DishesCategoryTreeResponse
|
||||
{
|
||||
public Guid? PCode { get; set; }
|
||||
|
||||
public Guid Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分类名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<DishesCategoryTreeResponse> Next { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Dlhis.Basic.Dishes.Response;
|
||||
|
||||
public class DishesMenuPageResponse
|
||||
{
|
||||
|
||||
}
|
||||
67
Src/Dlhis.Basic/Dishes/Response/DishesResponse.cs
Normal file
67
Src/Dlhis.Basic/Dishes/Response/DishesResponse.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Response;
|
||||
|
||||
public class DishesResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 大类
|
||||
/// </summary>
|
||||
public string Categories { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 小类
|
||||
/// </summary>
|
||||
public string SubCategories { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜品编码
|
||||
/// </summary>
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜品名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜品类型
|
||||
/// </summary>
|
||||
public CanteenMenuEnumType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜品类型描述
|
||||
/// </summary>
|
||||
public string TypeDescription => Type.GetDescription();
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单价
|
||||
/// </summary>
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单位
|
||||
/// </summary>
|
||||
public string Unit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图片
|
||||
/// </summary>
|
||||
public string Image { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
public bool Enable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 限售份数
|
||||
/// </summary>
|
||||
public int? RestrictedNum { get; set; } = null;
|
||||
}
|
||||
11
Src/Dlhis.Basic/Dishes/Services/IDishesCategoryService.cs
Normal file
11
Src/Dlhis.Basic/Dishes/Services/IDishesCategoryService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Dlhis.Basic.Dishes.Request;
|
||||
using Dlhis.Basic.Dishes.Response;
|
||||
|
||||
namespace Dlhis.Canteen.Dishes.Services;
|
||||
|
||||
public interface IDishesCategoryService : IScopeDependency
|
||||
{
|
||||
Task<List<DishesCategoryTreeResponse>> TreeAsync();
|
||||
|
||||
Task SaveAsync(DishesCategorySaveRequest request);
|
||||
}
|
||||
16
Src/Dlhis.Basic/Dishes/Services/IDishesMenuService.cs
Normal file
16
Src/Dlhis.Basic/Dishes/Services/IDishesMenuService.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Dlhis.Basic.Dishes.Request;
|
||||
using Dlhis.Basic.Dishes.Dto;
|
||||
using Dlhis.Basic.Dishes.Response;
|
||||
|
||||
namespace Dlhis.Canteen.Dishes.Services;
|
||||
|
||||
public interface IDishesMenuService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<DishesMenuPageResponse>> GetDishesMenuPageAsync(DisheMenuPageRequest request);
|
||||
|
||||
Task SaveDishesMenuAsync(DishesMenuSaveRequest request);
|
||||
|
||||
Task<DishesMenuDetailDto> CheckBookingAsync(DateTime date, Guid businessPlaceCode, ShiftEnumType shiftType, string dishesCustomCode);
|
||||
}
|
||||
12
Src/Dlhis.Basic/Dishes/Services/IDishesService.cs
Normal file
12
Src/Dlhis.Basic/Dishes/Services/IDishesService.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Dlhis.Basic.Dishes.Request;
|
||||
using Dlhis.Basic.Dishes.Response;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Canteen.Dishes.Services;
|
||||
|
||||
public interface IDishesService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<DishesResponse>> GetDishesPageAsync(DishesPageRequest request);
|
||||
|
||||
Task SaveDishesAsync(DishesSaveRequest request);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using Dlhis.Basic.Dishes.Request;
|
||||
using Dlhis.Basic.Dishes.Response;
|
||||
using Dlhis.Canteen.Dishes.Services;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Basic.Dishes.Services.Implements;
|
||||
|
||||
public class DishesCategoryService : IDishesCategoryService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public DishesCategoryService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<List<DishesCategoryTreeResponse>> TreeAsync()
|
||||
{
|
||||
var categories = await _dbContext.Queryable<DishesCategoryEntity>().Select<DishesCategoryTreeResponse>().ToListAsync();
|
||||
var tops = categories.Where(x => !x.PCode.HasValue).ToList();
|
||||
|
||||
tops.ForEach(x =>
|
||||
{
|
||||
RecursionGetNext(x, categories);
|
||||
});
|
||||
|
||||
return tops;
|
||||
}
|
||||
|
||||
public async Task SaveAsync(DishesCategorySaveRequest request)
|
||||
{
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var entity = request.Adapt<DishesCategoryEntity>();
|
||||
entity.Code = Guid.NewGuid();
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<DishesCategoryEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||
entity.ThrowIfNull("分类不存在,无法更新");
|
||||
request.Adapt(entity);
|
||||
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************************************************************
|
||||
|
||||
private static void RecursionGetNext(DishesCategoryTreeResponse current, List<DishesCategoryTreeResponse> data)
|
||||
{
|
||||
var next = data.Where(x => x.PCode == current.Code).ToList();
|
||||
if (next.Any())
|
||||
{
|
||||
current.Next = next;
|
||||
foreach (var item in next)
|
||||
{
|
||||
RecursionGetNext(item, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
131
Src/Dlhis.Basic/Dishes/Services/Implements/DishesMenuService.cs
Normal file
131
Src/Dlhis.Basic/Dishes/Services/Implements/DishesMenuService.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
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;
|
||||
|
||||
namespace Dlhis.Canteen.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>()
|
||||
.Select<DishesMenuPageResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
public async Task SaveDishesMenuAsync(DishesMenuSaveRequest request)
|
||||
{
|
||||
//检验数据
|
||||
CheckDuplicateData(request);
|
||||
|
||||
//检验权限
|
||||
var myBps = await _businessPlacePermissionsService.GetMyAsync();
|
||||
myBps.Contains(request.BusinessPlaceCode).ThrowIfFalse("当前经营营业点,无法保存菜单");
|
||||
|
||||
var entities = request.Items.SelectMany(item =>
|
||||
{
|
||||
var customCode = item.CustomCode;
|
||||
var date = item.Date;
|
||||
|
||||
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,
|
||||
Date = date,
|
||||
ShiftType = shiftType,
|
||||
DishesCode = dishesCode,
|
||||
Number = number,
|
||||
Price = price,
|
||||
|
||||
Type = CanteenMenuEnumType.Booking,
|
||||
Version = 0,
|
||||
Enable = false,
|
||||
};
|
||||
});
|
||||
});
|
||||
}).ToList();
|
||||
|
||||
var keys = entities.DistinctBy(x => new { x.Date, x.ShiftType }).Select(x => new { x.Date, x.ShiftType }).ToList();
|
||||
var where = LinqExpressionExtension.False<DishesMenuEntity>();
|
||||
keys.ForEach(x =>
|
||||
{
|
||||
where = where.Or(item => item.Date == x.Date && item.ShiftType == x.ShiftType);
|
||||
});
|
||||
|
||||
await _dbContext.Client.Deleteable<DishesMenuEntity>().Where(where).ExecuteCommandAsync();
|
||||
await _dbContext.InsertAsync(entities);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<DishesMenuDetailDto> CheckBookingAsync(DateTime date, Guid businessPlaceCode, ShiftEnumType shiftType, string dishesCustomCode)
|
||||
{
|
||||
var detail = await _dbContext.Queryable<DishesMenuEntity>()
|
||||
.LeftJoin<DishesEntity>((x, d) => x.DishesCode == d.CustomCode)
|
||||
.Where(x => x.Date == date)
|
||||
.Where(x => x.BusinessPlaceCode == businessPlaceCode)
|
||||
.Where(x => x.ShiftType == shiftType)
|
||||
.Where(x => x.DishesCode == dishesCustomCode)
|
||||
.Where((x, d) => d.Enable)
|
||||
.Select((x, d) => new DishesMenuDetailDto
|
||||
{
|
||||
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.Date }).Count() != request.Items.Count).ThrowIfTrue("菜单不可重复");
|
||||
|
||||
foreach (var item in request.Items)
|
||||
{
|
||||
var u = item.Date.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()}下菜品不可重复");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
51
Src/Dlhis.Basic/Dishes/Services/Implements/DishesService.cs
Normal file
51
Src/Dlhis.Basic/Dishes/Services/Implements/DishesService.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Dlhis.Basic.Dishes.Request;
|
||||
using Dlhis.Basic.Dishes.Response;
|
||||
using Dlhis.Canteen.Dishes.Services;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Canteen.Dishes.Services.Implements;
|
||||
|
||||
public class DishesService : IDishesService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public DishesService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<Pagination<DishesResponse>> GetDishesPageAsync(DishesPageRequest request)
|
||||
{
|
||||
//todo 营业点权限
|
||||
|
||||
return await _dbContext.Queryable<DishesEntity>()
|
||||
.WhereIF(request.Search.IsPresent(), x => x.CustomCode == request.Search || x.Name.Contains(request.Search))
|
||||
.OrderBy(x => x.CreateTime, SqlSugar.OrderByType.Desc)
|
||||
.Select<DishesResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
|
||||
public async Task SaveDishesAsync(DishesSaveRequest request)
|
||||
{
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var dishers = request.Adapt<DishesEntity>();
|
||||
dishers.CustomCode = request.CustomCode;
|
||||
await _dbContext.InsertAsync(dishers);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<DishesEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||
entity.ThrowIfNull("菜品不存在,无法更新");
|
||||
|
||||
request.Adapt(entity);
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,19 +119,19 @@ public class GainfoPermissions : IGainfoPermissions
|
||||
var deviceUniqueNos = page.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var balanceInfos = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceInfo))
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Select(x => new
|
||||
{
|
||||
x.DeviceInfo,
|
||||
x.DeviceUniqueNo,
|
||||
Amount = SqlFunc.AggregateSum(x.Amount),
|
||||
UserCount = SqlFunc.AggregateDistinctCount(x.UserCode)
|
||||
})
|
||||
.GroupBy(x => x.DeviceInfo)
|
||||
.GroupBy(x => x.DeviceUniqueNo)
|
||||
.ToListAsync();
|
||||
|
||||
page.ForEach(device =>
|
||||
{
|
||||
var info = balanceInfos.FirstOrDefault(x => x.DeviceInfo == device.UniqueNo);
|
||||
var info = balanceInfos.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
||||
if (info != null)
|
||||
{
|
||||
device.Amount = info.Amount;
|
||||
@@ -172,19 +172,19 @@ public class GainfoPermissions : IGainfoPermissions
|
||||
var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var balanceInfos = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceInfo))
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Select(x => new
|
||||
{
|
||||
x.DeviceInfo,
|
||||
x.DeviceUniqueNo,
|
||||
Amount = SqlFunc.AggregateSum(x.Amount),
|
||||
UserCount = SqlFunc.AggregateDistinctCount(x.UserCode)
|
||||
})
|
||||
.GroupBy(x => x.DeviceInfo)
|
||||
.GroupBy(x => x.DeviceUniqueNo)
|
||||
.ToListAsync();
|
||||
|
||||
page.Data.ForEach(device =>
|
||||
{
|
||||
var info = balanceInfos.FirstOrDefault(x => x.DeviceInfo == device.UniqueNo);
|
||||
var info = balanceInfos.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
||||
if (info != null)
|
||||
{
|
||||
device.Amount = info.Amount;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.SqlSugar;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
|
||||
@@ -8,22 +10,22 @@ namespace Dlhis.Entity.Basic.Entity;
|
||||
public class BusinessShiftMealRelationshipEntity : SugarBaseEntity, ITenantId
|
||||
{
|
||||
/// <summary>
|
||||
/// 餐次组合Code
|
||||
/// 餐别Code
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "餐次组合Code", UniqueGroupNameList = new[] { "idx_CanteenBusinessShiftRelationship_shiftcode_shifttype" })]
|
||||
[SugarColumn(ColumnDescription = "餐别Code", UniqueGroupNameList = new[] { "idx_CanteenBusinessShiftRelationship_shiftcode_shifttype" })]
|
||||
public Guid ShiftCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 餐次组合手工号
|
||||
/// 餐别手工号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "餐次组合手工号")]
|
||||
[SugarColumn(ColumnDescription = "餐别编码")]
|
||||
public string ShiftCustomCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 餐次
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "餐次", UniqueGroupNameList = new[] { "idx_CanteenBusinessShiftRelationship_shiftcode_shifttype" })]
|
||||
public string ShiftType { get; set; }
|
||||
[SugarColumn(ColumnDescription = "餐次", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert), UniqueGroupNameList = new[] { "idx_CanteenBusinessShiftRelationship_shiftcode_shifttype" })]
|
||||
public ShiftEnumType ShiftType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 经营开始时间
|
||||
|
||||
@@ -68,16 +68,16 @@ public class BalanceRecordEntity : SugarBaseEntity, ITenantId
|
||||
public Guid? BusinessPlaceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 餐次
|
||||
/// 餐别
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "餐次", IsNullable = true)]
|
||||
[SugarColumn(ColumnDescription = "餐别", IsNullable = true)]
|
||||
public Guid? BusinessShiftCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 餐次段
|
||||
/// 餐次
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "餐次段", IsNullable = true)]
|
||||
public string ShiftType { get; set; }
|
||||
[SugarColumn(ColumnDescription = "餐次", ColumnDataType = "varchar(50)", IsNullable = true, SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public ShiftEnumType? ShiftType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属成本日期
|
||||
@@ -89,7 +89,7 @@ public class BalanceRecordEntity : SugarBaseEntity, ITenantId
|
||||
/// 消费机器唯一信息
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "消费机器唯一信息", IsNullable = true)]
|
||||
public string DeviceInfo { get; set; }
|
||||
public string DeviceUniqueNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 餐补月份
|
||||
|
||||
@@ -9,14 +9,14 @@ namespace Dlhis.Entity.Canteen.Entities;
|
||||
/// <summary>
|
||||
/// 菜单表
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "CanteenMenu", TableDescription = "菜单表")]
|
||||
public class CanteenMenuEntity : SugarBaseEntity, ITenantId, IVersion
|
||||
[SugarTable(TableName = "DishesMenu", TableDescription = "菜单表")]
|
||||
public class DishesMenuEntity : SugarBaseEntity, ITenantId, IVersion
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单名称
|
||||
/// 菜单编码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "菜单名称")]
|
||||
public string Name { get; set; }
|
||||
[SugarColumn(ColumnDescription = "菜单编码")]
|
||||
public string CustomCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单类型
|
||||
@@ -28,7 +28,7 @@ public class CanteenMenuEntity : SugarBaseEntity, ITenantId, IVersion
|
||||
/// 所属营业点
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "所属营业点")]
|
||||
public Guid PlaceCode { get; set; }
|
||||
public Guid BusinessPlaceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 营业日期
|
||||
@@ -54,6 +54,12 @@ public class CanteenMenuEntity : SugarBaseEntity, ITenantId, IVersion
|
||||
/// </summary>
|
||||
public int Number { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 单价
|
||||
/// </summary>
|
||||
public decimal? Price { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
@@ -81,7 +81,7 @@ namespace Dlhis.Entity.Canteen.Entities
|
||||
/// <summary>
|
||||
/// 用餐日期
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "用餐日期")]
|
||||
[SugarColumn(ColumnDescription = "用餐日期", IsNullable = true)]
|
||||
public DateTime UseDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -12,7 +12,7 @@ public enum CanteenMenuEnumType
|
||||
/// 订餐
|
||||
/// </summary>
|
||||
[Description("订餐")]
|
||||
Order = 1,
|
||||
Booking = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 扫码点餐
|
||||
|
||||
@@ -14,6 +14,12 @@ public enum CanteenSettingItemEnumType
|
||||
[Description("营业点切换时间(HH:00:00)")]
|
||||
BusinessSwitchTime = 100,
|
||||
|
||||
/// <summary>
|
||||
/// 订餐最晚时间
|
||||
/// </summary>
|
||||
[Description("订餐最晚时间(HH:mm:00)")]
|
||||
BookingDeadline = 101,
|
||||
|
||||
|
||||
//----------------------------------------------------------------[200,300)--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user