feat 菜品/菜单配置
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user